From aac3b319965967f465881f3a8961904d57b6f337 Mon Sep 17 00:00:00 2001 From: zxd <zxdvslxy@gmail.com> Date: 星期四, 28 九月 2023 17:01:41 +0800 Subject: [PATCH] 节前提交,包含部分图码的转换,提出单独函数专做转换 --- MTerm1/MTerm1Doc.cpp | 251 ++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 213 insertions(+), 38 deletions(-) diff --git a/MTerm1/MTerm1Doc.cpp b/MTerm1/MTerm1Doc.cpp index d9ed313..856ca5b 100644 --- a/MTerm1/MTerm1Doc.cpp +++ b/MTerm1/MTerm1Doc.cpp @@ -204,43 +204,65 @@ } */ +/// <summary> +/// 澶勭悊鏂版枃妗g殑鍒涘缓浜嬩欢 +/// </summary> +/// <returns></returns> BOOL CMTerm1Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) + { return FALSE; + + } // TODO: 鍦ㄦ娣诲姞閲嶆柊鍒濆鍖栦唬鐮� // (SDI 鏂囨。灏嗛噸鐢ㄨ鏂囨。) -// LoadFromFile(_T("0prog1.txt")); + //LoadFromFile(_T("0prog1.txt")); return TRUE; - + } + +/// <summary> +/// 澶勭悊鎵撳紑鐨勬枃妗� +/// </summary> +/// <param name="lpszPathName">鎸囧悜瑕佹墦寮�鐨勬枃浠惰矾寰勭殑鎸囬拡</param> +/// <returns></returns> BOOL CMTerm1Doc::OnOpenDocument(LPCTSTR lpszPathName) { // if (!CDocument::OnOpenDocument(lpszPathName)) // return FALSE; - // TODO: 鍦ㄦ娣诲姞鎮ㄤ笓鐢ㄧ殑鍒涘缓浠g爜 - CString s1; + CString s1;//鏃ュ織淇℃伅 s1.Format(_T("OnOpenDocument %s"), lpszPathName); SysLog(s1); + + //鍔犺浇鏂囦欢鍐呭 LoadFromFile(lpszPathName); return TRUE; } - +/// <summary> +/// 澶勭悊淇濆瓨鏂囨。鐨勪簨浠� +/// </summary> +/// <param name="lpszPathName">鎸囧悜瑕佹墦寮�鐨勬枃浠惰矾寰勭殑鎸囬拡</param> +/// <returns></returns> BOOL CMTerm1Doc::OnSaveDocument(LPCTSTR lpszPathName) { // TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫� CString s1; s1.Format(_T("OnSaveDocument %s"), lpszPathName); SysLog(s1); - SaveToFile(lpszPathName); - return TRUE; + + //0912-zxd-Modify + int result = SaveToFile(lpszPathName); + return result == 1 ? TRUE : FALSE; // return CDocument::OnSaveDocument(lpszPathName); } - +/// <summary> +/// 澶勭悊鍏抽棴鏂囨。鐨勪簨浠� +/// </summary> void CMTerm1Doc::OnCloseDocument() { // TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫� @@ -250,8 +272,10 @@ CDocument::OnCloseDocument(); } -// CMTerm1Doc 搴忓垪鍖� - +/// <summary> +/// CMTerm1Doc 搴忓垪鍖� +/// </summary> +/// <param name="ar"></param> void CMTerm1Doc::Serialize(CArchive& ar) { CString s1; @@ -304,6 +328,10 @@ SetSearchContent(strSearchContent); } +/// <summary> +/// 璁剧疆鏂囨。鐨勬悳绱㈠唴瀹� +/// </summary> +/// <param name="value">瑕佹悳绱㈠唴瀹圭殑瀛楃涓插��</param> void CMTerm1Doc::SetSearchContent(const CString& value) { if (value.IsEmpty()) @@ -327,11 +355,17 @@ // CMTerm1Doc 璇婃柇 #ifdef _DEBUG +/// <summary> +/// 楠岃瘉瀵硅薄鐨勬湁鏁堟�� +/// </summary> void CMTerm1Doc::AssertValid() const { CDocument::AssertValid(); } - +/// <summary> +/// 璇婃柇淇℃伅鐨勮緭鍑� +/// </summary> +/// <param name="dc"></param> void CMTerm1Doc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); @@ -339,11 +373,14 @@ #endif //_DEBUG -// CMTerm1Doc 鍛戒护 +/// <summary> +/// 鍔犺浇鎸囧畾鐨勬枃浠� +/// </summary> +/// <param name="sFilePathName">闇�瑕佸姞杞界殑鏂囦欢鐨勮矾寰勫悕</param> +/// <returns></returns> int CMTerm1Doc::LoadFromFile(CString sFilePathName) { - // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. - CFile file1; + CFile file1;//鎵撳紑鎸囧畾鐨勬枃浠� CFileException e; bool r = file1.Open(sFilePathName, CFile::modeRead, &e); if (r) @@ -353,64 +390,80 @@ file1.Read(s1A.GetBuffer(l + 2048), l); file1.Close(); s1A.ReleaseBuffer(l); - TransFileToProg(s1A); - UpdateAllViews(NULL); + + TransFileToProg(s1A);//鏂囦欢鍐呭杞崲涓篜rog鏍煎紡 + UpdateAllViews(NULL);//鏇存柊鎵�鏈夌殑瑙嗗浘锛屼互鍙嶆槧鏂板姞杞界殑鍐呭 } return 0; } - +/// <summary> +/// 淇濆瓨鏂囦欢 +/// </summary> +/// <param name="sFilePathName">闇�瑕佷繚瀛樼殑鏂囦欢鐨勮矾寰勫悕</param> +/// <returns></returns> int CMTerm1Doc::SaveToFile(CString sFilePathName) { - // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. CString s1; CFile file1; CFileException e; - bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e); + + bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e);//璇诲啓妯″紡鎵撳紑鏂囦欢 if (r) { - + CStringA s1A; CStringA sSectionNameA; //鍐欏叆绯荤粺閰嶇疆 - GetSectionTxt(SectionSysCfg, sSectionNameA); // + GetSectionTxt(SectionSysCfg, sSectionNameA); //鑾峰彇绯荤粺閰嶇疆鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; - file1.Write(s1A, s1A.GetLength()); + file1.Write(s1A, s1A.GetLength());//灏嗚幏鍙栧埌鐨勬枃鏈唴瀹瑰啓鍏ユ枃浠� //鍐欏叆绋嬪簭 - GetSectionTxt(SectionProg, sSectionNameA); // + GetSectionTxt(SectionProg, sSectionNameA); //鑾峰彇绋嬪簭鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; - file1.Write(s1A, s1A.GetLength()); + file1.Write(s1A, s1A.GetLength());//鑾峰彇鍒扮殑鏂囨湰鍐呭鍐欏叆鏂囦欢 - TransToTxt(s1A); - file1.Write(s1A, s1A.GetLength()); + TransToTxt(s1A);//灏嗙▼搴忓唴瀹硅浆鎹负鏂囨湰鏍煎紡 + file1.Write(s1A, s1A.GetLength());//灏嗚浆鎹㈠悗鐨勬枃鏈唴瀹瑰啓鍏ユ枃浠� //鍐欏叆娉ㄩ噴 - GetSectionTxt(SectionAnno, sSectionNameA); // + GetSectionTxt(SectionAnno, sSectionNameA); //鑾峰彇娉ㄩ噴鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength()); + //寰幆閬嶅巻鎵�鏈夋敞閲婏紝骞跺皢鍏跺啓鍏ユ枃浠� for (int i = 0; i < nCoilAnnoCount; i++) { if (mCoilAnnos[i].sAnno.IsEmpty()) { continue; } - s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno+ _T("\r\n"); + s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno + _T("\r\n"); s1A = s1; file1.Write(s1A, s1A.GetLength()); } //鍐欏叆瑙︾偣鐩戞帶鍒楄〃 - GetSectionTxt(SectionCoilList, sSectionNameA); // + GetSectionTxt(SectionCoilList, sSectionNameA); //鑾峰彇瑙︾偣鐩戞帶鍒楄〃鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength()); + //鍐欏叆鏁版嵁鐩戞帶鍒楄〃 - GetSectionTxt(SectionDataList, sSectionNameA); // + GetSectionTxt(SectionDataList, sSectionNameA); //鑾峰彇鏁版嵁鐩戞帶鍒楄〃鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength()); file1.Close(); + return 1; } - return 0; + else//鏂囦欢鎵撳紑澶辫触 + { + return 0; + } } +/// <summary> +/// 鏍规嵁鏂囨湰鍖归厤绫诲瀷鐨凨ey骞惰繑鍥� +/// </summary> +/// <param name="txt"></param> +/// <returns></returns> int CMTerm1Doc::TxtToSection(CStringA txt) { for (int i = 0; i < nSectionDefCount; i++) { @@ -421,6 +474,12 @@ return SectionNone; } +/// <summary> +/// 鏍规嵁Key鍖归厤绫诲瀷鐨勬枃鏈紝閫氳繃txt浼犻�掞紝杩斿洖鏌ヨ鎵ц缁撴灉 +/// </summary> +/// <param name="nSectionType"></param> +/// <param name="txt"></param> +/// <returns></returns> int CMTerm1Doc::GetSectionTxt(int nSectionType, CStringA & txt) { for (int i = 0; i < nSectionDefCount; i++) { @@ -432,6 +491,13 @@ return false; } +/// <summary> +/// +/// </summary> +/// <param name="nSectionType">Section绫诲瀷</param> +/// <param name="nSectionLine">琛屽彿</param> +/// <param name="nSectionLines">琛屾暟</param> +/// <returns></returns> int CMTerm1Doc::GetSectionPos(int nSectionType, int * nSectionLine, int * nSectionLines) { for (int i = 0; i < nSectionCount; i++) { @@ -444,6 +510,13 @@ return false; } +/// <summary> +/// 鏂囨湰琛ㄧず鐨勬搷浣滆浆鎹负鍏剁浉搴旂殑鎿嶄綔绫诲瀷銆佸弬鏁版暟閲忓拰鍙傛暟绫诲瀷 +/// </summary> +/// <param name="optxt">琛ㄧず鎿嶄綔鐨勫瓧绗︿覆</param> +/// <param name="ParamCount">杩斿洖涓庣粰瀹氭搷浣滅浉瀵瑰簲鐨勫弬鏁版暟閲�</param> +/// <param name="ParamType">杩斿洖涓庣粰瀹氭搷浣滅浉瀵瑰簲鐨勫弬鏁扮被鍨�</param> +/// <returns>-1锛氬尮閰嶅け璐�</returns> int CMTerm1Doc::TxtToOp(CStringA optxt, int* ParamCount, int* ParamType) { for (int i = 0; i < nOpDefCount; i++){ @@ -455,6 +528,13 @@ } return -1; } + +/// <summary> +/// 鎿嶄綔绫诲瀷杞崲涓哄叾鐩稿簲鐨勬枃鏈〃绀� +/// </summary> +/// <param name="nOp">鎿嶄綔绫诲瀷</param> +/// <param name="OpTxt">鎿嶄綔鏂囨湰</param> +/// <returns></returns> int CMTerm1Doc::OpToTxt(int nOp, CStringA & OpTxt) { for (int i = 0; i < nOpDefCount; i++){ @@ -466,6 +546,12 @@ return false; } +/// <summary> +/// 鎿嶄綔绫诲瀷杞崲涓哄叾鐩稿簲鐨勫墠鍙板睍绀烘枃鏈� +/// </summary> +/// <param name="nOp">鎿嶄綔绫诲瀷</param> +/// <param name="OpShowTxt">鍓嶅彴灞曠ず鏂囨湰</param> +/// <returns></returns> int CMTerm1Doc::OpToShowTxt(int nOp, CStringA & OpShowTxt) { for (int i = 0; i < nOpDefCount; i++) { @@ -477,6 +563,13 @@ return false; } +/// <summary> +/// 鏂囨湰杞嚎鍦堢被鍨� +/// </summary> +/// <param name="Typetxt">绾垮湀绫诲瀷</param> +/// <param name="nCoilType">绾垮湀绫诲瀷</param> +/// <param name="nCoilAddr">绾垮湀鍦板潃</param> +/// <returns></returns> int CMTerm1Doc::TxtToCoilType(CStringA Typetxt, int* nCoilType, int* nCoilAddr) { Typetxt.MakeUpper(); @@ -492,6 +585,12 @@ return false;; } +/// <summary> +/// 绾垮湀绫诲瀷杞枃鏈� +/// </summary> +/// <param name="nType">绾垮湀绫诲瀷</param> +/// <param name="typeTxt">绾垮湀鏂囨湰</param> +/// <returns></returns> int CMTerm1Doc::CoilTypeToTxt(int nType, CStringA & typeTxt) { for (int i = 0; i < nCoilTypeDefCount; i++) @@ -504,6 +603,13 @@ return false; } +/// <summary> +/// +/// </summary> +/// <param name="Typetxt"></param> +/// <param name="nDataType"></param> +/// <param name="nDataAddr"></param> +/// <returns></returns> int CMTerm1Doc::TxtToDataType(CStringA Typetxt, int * nDataType, int* nDataAddr) { Typetxt.MakeUpper(); @@ -521,6 +627,12 @@ } +/// <summary> +/// +/// </summary> +/// <param name="nType"></param> +/// <param name="typeTxt"></param> +/// <returns></returns> int CMTerm1Doc::DataTypeToTxt(int nType, CStringA & typeTxt) { for (int i = 0; i < nDataTypeDefCount; i++) @@ -533,6 +645,13 @@ return false; } +/// <summary> +/// 鑾峰彇涓庣壒瀹氱被鍨嬪拰鍦板潃鐩稿搴旂殑绾垮湀娉ㄩ噴 +/// </summary> +/// <param name="nType"></param> +/// <param name="nAddr"></param> +/// <param name="sAnno"></param> +/// <returns></returns> int CMTerm1Doc::GetAnno(unsigned short nType, unsigned short nAddr, CString & sAnno) { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. @@ -547,6 +666,12 @@ return 0; } +/// <summary> +/// 璁剧疆鎴栨洿鏂扮壒瀹氱嚎鍦堢殑娉ㄩ噴 +/// </summary> +/// <param name="sCoilName"></param> +/// <param name="sAnno"></param> +/// <returns></returns> int CMTerm1Doc::SetAnno(CString sCoilName, CString sAnno) { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. @@ -575,6 +700,14 @@ return 2; } +/// <summary> +/// 鐩存帴浣跨敤绫诲瀷鍜屽湴鍧�鍙傛暟鏉ヨ缃垨鏇存柊鐗瑰畾绾垮湀鐨勬敞閲� +/// </summary> +/// <param name="nType">绫诲瀷</param> +/// <param name="nAddr">鍦板潃</param> +/// <param name="sCoilName">绾垮湀鍚嶇О</param> +/// <param name="sAnno">绾垮湀娉ㄩ噴</param> +/// <returns></returns> int CMTerm1Doc::SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno) { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. @@ -593,6 +726,14 @@ nCoilAnnoCount++; return 0; } + +/// <summary> +/// 杞崲鏂囨湰琛屼负Prog鏍煎紡 +/// </summary> +/// <param name="txtLines">鏂囨湰琛岄泦鍚�</param> +/// <param name="StartLine">寮�濮嬭</param> +/// <param name="ProgLines">绋嬪簭琛�</param> +/// <returns></returns> int CMTerm1Doc::TransLinesToProg(const CStringArray & txtLines, int StartLine , int ProgLines) { CString s1; @@ -607,27 +748,41 @@ else nProgLines = ProgLines; int nProgPos = 0; + //閫愯璇诲彇骞惰浆鍖� for (int i = nProgStartLine; i < nProgStartLine + nProgLines; i++) { CString sLine; sLine = txtLines.GetAt(i); + //娓呴櫎绌烘牸鍜屽埗琛ㄧ sLine.Trim(); sLine.Replace(_T("\t"), _T(" ")); sLine.Replace(_T(" "), _T(" ")); sLine.Replace(_T(" "), _T(" ")); + + //浣跨敤绌烘牸鍒嗛殧瀛楃涓诧紝骞跺皢鍏跺瓨鍌ㄥ湪 strarr2 鏁扮粍涓� CStringArray strarr2; DivideStringToArray(sLine, _T(" "), strarr2); - if (strarr2.GetSize() == 0) continue; + + if (strarr2.GetSize() == 0) + { + continue; + } + + //浠庢暟缁勪腑鎻愬彇鎸囦护锛屽苟灏嗗叾杞崲涓哄ぇ鍐欏舰寮� CString sCmd; sCmd = strarr2.GetAt(0); sCmd.MakeUpper(); + + //浣跨敤 TxtToOp 鍑芥暟灏嗘寚浠ゆ枃鏈浆鎹负鎿嶄綔绫诲瀷銆� CStringA s1A; s1A = sCmd; int nParamCount, nParamType; int nType, nAddr; int k = TxtToOp(s1A, &nParamCount, &nParamType); + if (k >= 0) { + //鏍规嵁鍙傛暟绫诲瀷锛屼娇鐢� TxtToCoilType 鎴� TxtToDataType 鍑芥暟灏嗗弬鏁版枃鏈浆鎹负鍙傛暟绫诲瀷鍜屽湴鍧� Progs[nProgPos].nOpType1 = k; for (int j = 0; j < 3 && j < nParamCount && j < strarr2.GetSize() - 1; j++) { @@ -644,7 +799,7 @@ Progs[nProgPos].Params[j].nParamType = nType; Progs[nProgPos].Params[j].nParamAddr = nAddr; } - else { + else { } } @@ -653,6 +808,8 @@ nProgPos++; } } + + m_nProgSteps = nProgPos; // 鍏堟壂鎻忓垎寮�鐨勭▼搴忔 int stpos[100] = { 0 }; @@ -662,7 +819,10 @@ // 鏌ユ壘鍖归厤鎸囦护鍜屽湴鍧� s1.Format(_T("DOC::Trans to Prog ")); SysLog(s1); - for (int i = 0; i < m_nProgSteps; i++) { + + //鍖归厤鎸囦护锛堥敊璇紝姝ゅ鍖归厤鎸囦护浣跨敤鏁板瓧 + for (int i = 0; i < m_nProgSteps; i++) + { int nOpType = Progs[i].nOpType1; int nParamCount = Progs[i].nParamCount; switch (Progs[i].nOpType1) @@ -700,8 +860,10 @@ } StackDeeps[i] = nCurStackDeep; } + s1.Format(_T("Remaining STs %d"), nSts); SysLog(s1); + for (int i = 0; i < nSts; i++) { s1.Format(_T("[%d] %d "), i, stpos[i]); SysLog(s1); @@ -789,6 +951,11 @@ return 0; } +/// <summary> +/// 瑙f瀽鏂囦欢涓烘褰㈠浘 +/// </summary> +/// <param name="ProgTxtA">鏂囨湰</param> +/// <returns></returns> int CMTerm1Doc::TransFileToProg(CStringA ProgTxtA) { CString s1; @@ -798,6 +965,7 @@ sProg.Replace(_T("\r\n"), _T("\n")); sProg.Replace(_T("\r"), _T("\n")); + //鍒嗗壊鏂囨湰瀛楃涓� DivideStringToArray(sProg, _T("\n"), txtLines); nSectionCount = 0; @@ -811,7 +979,8 @@ int nRightBracket; if (sLine.Find(_T("[")) == 0 && (nRightBracket = sLine.Find(_T("]"))) > 1) { //鎵惧埌 [ ] 鏍囧織 - if (nSectionCount > 0) { + if (nSectionCount > 0) + { Sections[nSectionCount - 1].nLines = i - Sections[nSectionCount - 1].nSectionLineNo - 1; s1.Format(_T("- Line %d Section %d Ends, %d Lines"), i, nSectionCount -1 ,Sections[nSectionCount - 1].nLines); SysLog(s1); @@ -821,6 +990,7 @@ sSectionName = sLine.Mid(1, nRightBracket - 1); sSectionNameA = sSectionName; int theSection = TxtToSection(sSectionNameA); + s1.Format(_T("+ Line %d Section %d : [%s] type:%d "), i + 1, nSectionCount, sSectionName, theSection); SysLog(s1); Sections[nSectionCount].nSectionType = theSection; @@ -852,7 +1022,10 @@ int nAnnoLines = 0; int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines); - if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; } + if (bAnnoSection) + { + nAnnoStartLine = nAnnoSectionLine + 1; + } for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++) { @@ -886,6 +1059,8 @@ return 0; } + +//鏂囨湰娈靛湪姝ゅ缁勮 int CMTerm1Doc::TransToTxt(CStringA &ProgTxt) { CStringA s1, s2; @@ -1828,7 +2003,7 @@ } } //*/ - + void CMTerm1Doc::OnMenuShowConsole() { // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 @@ -1845,7 +2020,7 @@ ASSERT_VALID(theApp.m_pCtrlViewTemplate); CFrameWnd * pFrame = theApp.m_pCtrlViewTemplate->CreateNewFrame(this, NULL); ASSERT_KINDOF(CFrameWnd, pFrame); - theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this); + theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this); } } -- Gitblit v1.9.1