From 61deef5cdf96cbfdd6ad45be49e80d597c00ca65 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期二, 24 十二月 2024 08:37:21 +0800 Subject: [PATCH] 2024-12-24 --- MTerm1/MTerm1View.cpp | 2152 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 1,739 insertions(+), 413 deletions(-) diff --git a/MTerm1/MTerm1View.cpp b/MTerm1/MTerm1View.cpp index 4abbea4..125279b 100644 --- a/MTerm1/MTerm1View.cpp +++ b/MTerm1/MTerm1View.cpp @@ -82,7 +82,7 @@ // ON_COMMAND(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnIndicatorMonitorStatus) // ON_UPDATE_COMMAND_UI(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnUpdateIndicatorMonitorStatus) -ON_WM_KEYDOWN() + ON_WM_KEYDOWN() END_MESSAGE_MAP() @@ -754,6 +754,15 @@ { } + else if (nType == typeEND) { + + if (needReDraw) { + //鐢诲乏渚фí绾� + //DrawLeftRightLine(pDC, x0, y0, 14, 18); + DrawAngleBracket(pDC, x0, y0, 8, 32); + DrawCellText1(pDC, _T("ED"), x0 + 16, y0 + m_LinePosY - 8, 24, 14); + } + } else if (nType == typeLine1) { //Draw Line //鐢荤洿妯嚎 @@ -765,8 +774,8 @@ else if (nType == typeLine2) { //Draw Line //鐢荤洿绔栫嚎 - pDC->MoveTo(x0, y0 + (0.32 * CellTotalHeight)); - pDC->LineTo(x0, y0 - (0.69 * CellTotalHeight)); + pDC->MoveTo(x0, y0 + int(0.32 * CellTotalHeight)); + pDC->LineTo(x0, y0 - int(0.69 * CellTotalHeight)); } else if (nType == typeNO) { @@ -1155,6 +1164,7 @@ nCol = 0; } } + CellFocusChg(nRow, nCol); } if (nChar == VK_RIGHT) { nCol += 1; @@ -1167,15 +1177,17 @@ nCol = m_CellPerLine - 1; } } + CellFocusChg(nRow, nCol); } if (nChar == VK_UP) { nRow -= 1; if (nRow < 0) { nRow = 0; } + CellFocusChg(nRow, nCol); } if (nChar == VK_DOWN) { nRow += 1; if (nRow >= m_nTotalRow + nLinesinView) { nRow = m_nTotalRow + nLinesinView -1; } - + CellFocusChg(nRow, nCol); } m_FocusRow = nRow; m_FocusCol = nCol; @@ -1211,7 +1223,7 @@ { CString s1; stCell & thecell = Cells[nRow][nCol]; - s1.Format(_T("Cell %d %d Type %02X \r\n"), nRow, nCol, thecell.nType); + s1.Format(_T("Cell %d %d Type %02X OpType %02X \r\n"), nRow, nCol, thecell.nType,thecell.nOpType); s1.AppendFormat(_T(" sCoilName %s sParam %s \r\n"), thecell.sCoilName, thecell.sParam ); s1.AppendFormat(_T("LeftUp %d leftDn %d "), thecell.bLeftLineUp, thecell.bLeftLineDn); DbgLog(s1); @@ -1308,8 +1320,10 @@ m_nCurProgStep = Cells[nRow][nCol].nProgStep; } if (!pDoc->m_bOnline) return; - //if (!m_bMonitoring) return; - + if (!m_bMonitoring || !pDoc->m_bOnline) { + + }; + CString sParam; sParam = Cells[nRow][nCol].sParam; int nDataType, nDataAddr, nStat; @@ -1445,13 +1459,14 @@ // TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ�� CString s1; CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument(); - + static int nCount = 0; if (nIDEvent == 0) { } else if (nIDEvent == 1) { - if (m_bMonitoring) { + nCount++; + if (m_bMonitoring && (nCount &1)) { //this->RedrawWindow(); DoReDraw(); } @@ -1485,22 +1500,25 @@ void CMTerm1View::OnProgConvert() { //杞崲鍓嶅厛瀵筁DS鐨勮鍒欒繘琛屾楠岋紙妫�楠岃鍒欎笌杩斿洖鍙傛暟骞舵湭瀹屽叏纭畾 - std::pair<int,CString> result = LDSCheckRule(); - if (result.first == 111) - { - DbgLog(result.second); - return; - } + // std::pair<int,CString> result = LDSCheckRule(); + //if (result.first == 111) + //{ + // DbgLog(result.second); + // return; + //} CString s1; s1.Format(_T("Prog Convert")); - SysLog(s1); - int r = TransLDSToProg(); + SysLog(s1); + int r = TransLDSToProgAOV(); //TransLDSToProg(); s1.Format(_T("LDS To Prog result %d"), r); SysLog(s1); +///* if (r==0) { // m_bModified = 0; + GetDocument()->FindProgPair(); + GetDocument()->TransProgToBin(); int j=TransProgToLDS(); s1.Format(_T("Porg to LDS retuls %d"), j); SysLog(s1); @@ -1511,6 +1529,7 @@ s1.Format(_T("Error in Prog Convert")); SysLog(s1); } +//*/ } void CMTerm1View::OnUpdateProgConvert(CCmdUI *pCmdUI) @@ -1591,6 +1610,12 @@ /// <param name="cell1"></param> void CMTerm1View::SetCellToView(stCell cell1, int flag) //**************************************************************************************************// { + bool changeVLine = false; + if ((Cells[m_FocusRow][m_FocusCol].bLeftLineDn != cell1.bLeftLineDn) + || (Cells[m_FocusRow][m_FocusCol].bLeftLineUp != cell1.bLeftLineUp)) + { + changeVLine = true; + } Cells[m_FocusRow][m_FocusCol] = cell1; m_bModified = 1; needReDraw = 1; @@ -1614,6 +1639,7 @@ } //娣诲姞绾电嚎鏃跺悓姝ユ坊鍔犱笂涓�琛� Cells[m_FocusRow - 1][m_FocusCol].bLeftLineDn = 1; + }break; case 2: { @@ -1625,13 +1651,18 @@ } //鍒犻櫎绾电嚎鏃跺悓姝ュ垹闄や笂涓�琛� Cells[m_FocusRow - 1][m_FocusCol].bLeftLineDn = 0; + }break; default: break; } - - //鍗曞厓鏍间綅缃悗绉� - m_FocusCol += 1; + //濡傛灉鍙樺寲鐨勬槸绔栫嚎锛岀劍鐐逛笉鍚庣Щ + if (!changeVLine) + { + //鍗曞厓鏍间綅缃悗绉� + m_FocusCol += 1; + } + if (m_FocusCol >= 16) { m_FocusCol = 0; @@ -1951,6 +1982,9 @@ POINT StPts[100]; // StPts[0] = POINT{ 0, 0 }; POINT EndPt[100]; + +// POINT StrPt[100]; +// int nStrPts = 0; int nEndPts = 0; nSts = 0; int nCurLine = 0; @@ -1977,6 +2011,34 @@ switch (nOp) { case OP_NOP: + break; + case OP_END: + nCellType = typeEND; + nCurLine = cy; + cx = 0; + if (cx <= m_CellPerLine) { + + int hasData = 1; + while (hasData) { + hasData = 0; + for (int j = 0; j < m_CellPerLine; j++) { + if (Cells[nCurLine][j].nType != 0) { + nCurLine++; hasData = 1; break; + } + } + } + cy = nCurLine; + for (int j = 0; j < m_CellPerLine; j++) + { + Cells[cy][j].nType = typeLine1; + } + Cells[cy][m_CellPerLine - 1].nType = nCellType; + Cells[cy][cx].nOpType = nOp; + Cells[cy][m_CellPerLine - 1].nProgStep = i; + } + if (cy > maxy) { maxy = cy; } + //cy++; + break; break; case OP_ST: case OP_ST_: @@ -2048,15 +2110,23 @@ } else if (nPairOp == 0) { - nCurLine = maxy + 1; //鍙﹁捣涓�琛� - maxy = nCurLine; - cx = 0; cy = nCurLine; +// if (i > 0 && nOp == pDoc->Progs[i-1].nOpType1)//濡傛灉鍓嶉潰涔熸槸ST锛岄偅灏变笉鎹㈣ +// { + +// } +// else +// { + nCurLine = ++maxy; + cx = 0; + cy = nCurLine; +// } } } stpos[nSts] = i; StPts[nSts] = POINT{ cx,cy }; nSts++; Cells[cy][cx].nType = pDoc->Progs[i].nOpType1 == OP_ST ? typeNO : typeNC; //typeNC + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr; Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr; @@ -2111,6 +2181,7 @@ StPts[nSts] = POINT{ cx,cy }; nSts++; Cells[cy][cx].nType = typeCMP; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sParam = OpName; Cells[cy][cx].sCoilName = ShowTxt; @@ -2129,6 +2200,7 @@ case OP_AN_: Cells[cy][cx].nType = nOp == OP_AN ? typeNO : typeNC; //typeNC + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr; Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr; @@ -2143,6 +2215,7 @@ case OP_AN_LE: case OP_AN_GE: Cells[cy][cx].nType = typeCMP; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = ShowTxt; Cells[cy][cx + 1].nType = typeExt1; @@ -2191,27 +2264,28 @@ StPts[nSts] = POINT{ cx,cy };//+++ Cells[cy][cx].nProgStep = i; Cells[cy][cx].nType = nOp == OP_OR ? typeNO : typeNC; //typeNC + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr; Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr; Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType; Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr; cx++; - //if (cx <= EndPt[nEndPts - 1].x) - //{ //鏈琛ラ綈 - // for (int j = cx; j < EndPt[nEndPts - 1].x; j++) - // { - // Cells[cy][j].nType = typeLine1; - // } - // cx = EndPt[nEndPts - 1].x; - //} - //else { - // //鍓嶄竴琛岃ˉ榻� - // for (int j = EndPt[nEndPts - 1].x; j < cx; j++) - // { - // Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1; - // } + if (cx <= EndPt[nEndPts - 1].x) + { //鏈琛ラ綈 + for (int j = cx; j < EndPt[nEndPts - 1].x; j++) + { + Cells[cy][j].nType = typeLine1; + } + cx = EndPt[nEndPts - 1].x; + } + else { + //鍓嶄竴琛岃ˉ榻� + for (int j = EndPt[nEndPts - 1].x; j < cx; j++) + { + Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1; + } - //} + } //杩炴帴涓婁笅绾� for (int j = EndPt[nEndPts - 1].y; j < cy; j++) { @@ -2252,6 +2326,7 @@ } cy = nCurLine; Cells[cy][cx].nType = typeCMP; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = ShowTxt; Cells[cy][cx + 1].nType = typeExt1; @@ -2292,6 +2367,7 @@ break; case OP_NOT: Cells[cy][cx].nType = typeNOT; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].sCoilName = _T("NOT"); Cells[cy][cx].nProgStep = i; @@ -2300,63 +2376,96 @@ case OP_DF: case OP_DF_: Cells[cy][cx].nType = nOp == OP_DF ? typeDF : typeDF_; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].sCoilName = nOp == OP_DF ? _T("DF") : _T("DF/"); Cells[cy][cx].nProgStep = i; cx++; break; case OP_ANS: + /* + //ANS璇存槑鏄湁鐜矾锛屾暣琛岃繘琛岀Щ鍔紙鍚戝彸锛変粠鍚庡悜鍓嶈繘琛岀Щ鍔� + EndPt[nEndPts].y; + for (int i = EndPt[nEndPts-1].x ; i > 0; i--) + { + for (int j = EndPt[nEndPts].x; j >= 0; j--) + { + if (j > 0 + && Cells[cy + 1][j-1].nType == typeNone + || Cells[cy + 1][j - 1].nType == typeLine1 + || Cells[cy + 1][j - 1].nType == typeLine2) + { + continue; + } + + Cells[cy + 1][j] = Cells[cy + 1][j - 1]; + } + } + + Cells[EndPt[nEndPts].y][EndPt[nEndPts-1].x].bLeftLineDn = 1; + Cells[EndPt[nEndPts].y+1][EndPt[nEndPts-1].x].bLeftLineUp = 1; + */ nSts--; nEndPts--; break; case OP_ORS: - //褰撳墠搴忓垪涓庡墠闈㈢殑搴忓垪鍚堝苟銆� + // 褰撳墠搴忓垪涓庡墠闈㈢殑搴忓垪鍚堝苟銆� //褰撳墠搴忓垪鐨勫紑濮嬬粨鏉熶綅缃� //EndPt[nEndPts] = POINT{ cx,cy }; //nEndPts++; //StPts[nSts - 1]; EndPt[nEndPts - 1]; //鍓嶄竴搴忓垪鐨勫紑濮嬬粨鏉熶綅缃� - StPts[nSts - 1]; - EndPt[nEndPts - 1]; + StPts[nSts - 1]; EndPt[nEndPts - 1]; + if (nEndPts <= 0) { break; } - ////鍒ゆ柇浜岃�呴暱搴� - //if (cx < EndPt[nEndPts - 1].x) - //{ - // //鏈琛ラ綈 - // for (int j = cx; j < EndPt[nEndPts - 1].x; j++) - // { - // Cells[cy][j].nType = typeLine1; - // } - // cx = EndPt[nEndPts - 1].x; - //} - //else - //{ - // //鍓嶄竴琛岃ˉ榻� - // for (int j = EndPt[nEndPts - 1].x; j < cx; j++) - // { - // Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1; - // } - //} - ////杩炴帴涓婁笅绾� - //for (int j = EndPt[nEndPts - 1].y; j < cy; j++) - //{ - // Cells[j][cx].bLeftLineDn = 1; - // Cells[j + 1][cx].bLeftLineUp = 1; - //} - ////鍏夋爣浣嶇疆, 鍓嶄竴缁撴潫鐐逛綅缃� - //cy = EndPt[nEndPts - 1].y; + //鍒ゆ柇浜岃�呴暱搴� + if (cx < EndPt[nEndPts - 1].x) + { + //鏈琛ラ綈 + for (int j = cx; j < EndPt[nEndPts - 1].x; j++) + { + Cells[cy][j].nType = typeLine1; + } + cx = EndPt[nEndPts - 1].x; + } + else + { + //鍓嶄竴琛岃ˉ榻� + for (int j = EndPt[nEndPts - 1].x; j < cx; j++) + { + //if (Cells[EndPt[nEndPts - 1].y][j].nType == typeNone) + { + Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1; + } + } + } + //杩炴帴涓婁笅绾� + for (int j = EndPt[nEndPts - 1].y; j < cy; j++) + { + Cells[j][cx].bLeftLineDn = 1; + Cells[j + 1][cx].bLeftLineUp = 1; + } + //Cells[cy][cx].bLeftLineUp = 1; + //Cells[cy-1][cx].bLeftLineDn = 1; + + //鍏夋爣浣嶇疆, 鍓嶄竴缁撴潫鐐逛綅缃� nSts--; nEndPts--; - + cy = EndPt[nEndPts].y; + // cx = EndPt[nEndPts].x; break; case OP_PSHS: EndPt[nEndPts] = POINT{ cx,cy }; nEndPts++; +/* + StrPt[nStrPts] = POINT{ EndPt[nEndPts].x,EndPt[nEndPts].y+1 }; + nStrPts++; +*/ break; case OP_RDS: cx = EndPt[nEndPts - 1].x; @@ -2386,7 +2495,11 @@ Cells[j + 1][cx].bLeftLineUp = 1; } nEndPts--; - +/* + nStrPts--; + cy = StrPt[nStrPts].y; + cx = StrPt[nStrPts].x; +*/ break; case OP_OUT: case OP_SET: @@ -2415,6 +2528,7 @@ Cells[cy][j].nType = typeLine1; } Cells[cy][m_CellPerLine - 1].nType = nCellType; + Cells[cy][cx].nOpType = nOp; Cells[cy][m_CellPerLine - 1].nProgStep = i; Cells[cy][m_CellPerLine - 1].sParam = pDoc->Progs[i].Params[0].sParamStr; Cells[cy][m_CellPerLine - 1].sCoilName = pDoc->Progs[i].Params[0].sParamStr; @@ -2424,6 +2538,7 @@ } else { Cells[cy][cx].nType = nCellType; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr; Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr; @@ -2438,7 +2553,26 @@ case OP_TMR: case OP_TMX: case OP_TMY: + nCurLine = cy; + { + int hasData = 1; + while (hasData) { + hasData = 0; + for (int j = cx; j < m_CellPerLine; j++) { + if (Cells[nCurLine][j].nType != 0) { + nCurLine++; hasData = 1; break; + } + } + } + //if (nCurLine > maxy) maxy = nCurLine; + for (int j = cy; j < nCurLine; j++) { + Cells[j][cx].bLeftLineDn = 1; + Cells[j + 1][cx].bLeftLineUp = 1; + } + } + cy = nCurLine; Cells[cy][cx].nType = typeTM; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = ShowTxt; Cells[cy][cx + 1].nType = typeExt1; @@ -2454,6 +2588,7 @@ case OP_INC: case OP_DEC: Cells[cy][cx].nType = typeFN1; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = ShowTxt; Cells[cy][cx + 1].nType = typeExt1; @@ -2467,6 +2602,7 @@ case OP_ADD2: case OP_SUB2: Cells[cy][cx].nType = typeFN2; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = ShowTxt; Cells[cy][cx + 1].nType = typeExt1; @@ -2485,6 +2621,7 @@ case OP_MUL: case OP_DIV: Cells[cy][cx].nType = typeFN3; + Cells[cy][cx].nOpType = nOp; Cells[cy][cx].nProgStep = i; Cells[cy][cx].sCoilName = ShowTxt; Cells[cy][cx + 1].nType = typeExt1; @@ -2505,6 +2642,7 @@ default: break; } + if (cy > maxy) { maxy = cy; } } } catch (const std::exception&) @@ -2527,7 +2665,1065 @@ needReDraw = 1; return 0; } -bool firstCoil = true;//鏈绗竴涓崟鍏冩牸 + + +int CMTerm1View::AddNode(int nType, int CellX, int CellY, CString sCoilName, int PrevNode) +{ + node& theNode = nodes[nNodeCount]; + + theNode.nId = nNodeCount; + + theNode.bEnable = 1; + theNode.nType = nType; + theNode.indegree = 0; + theNode.outdegree = 0; + theNode.firstOut = 0; + theNode.firstIn = 0; + theNode.input = 0; + theNode.result = 0; + theNode.nCellX = CellX; + theNode.nCellY = CellY; + theNode.CoilName = sCoilName; + theNode.InProcCount = 0; + theNode.OutProcCount = 0; + theNode.OutProcAllDone = 0; + theNode.prog1.Progs.clear(); + int nOp = Cells[CellY][CellX].nOpType; + int nCoilType, nCoilAddr; + if (nType == typeNO) + { + CMTerm1Doc::stProg prog0; + if (CellX == 0) { + prog0.nOpType1 = OP_ST; // OP_AN; + }else + if (nOp >= 1 && nOp <= 255) { + //prog0.nOpType1 = nOp; // OP_AN; + prog0.nOpType1 = OP_AN; // OP_AN; + } + else { + prog0.nOpType1 = OP_AN; // OP_AN; + } + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = sCoilName; + CStringA s2A; + s2A = sCoilName; + GetDocument()->TxtToCoilType(s2A,&nCoilType,&nCoilAddr); + + prog0.Params[0].nParamType = nCoilType; + prog0.Params[0].nParamAddr = nCoilAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeNC) { + CMTerm1Doc::stProg prog0; + if (CellX == 0) { + prog0.nOpType1 = OP_ST_; // OP_AN; + } + else if (nOp >= 1 && nOp <= 255) { + //prog0.nOpType1 = nOp; // OP_AN; + prog0.nOpType1 = OP_AN_; // OP_AN; + } + else { + prog0.nOpType1 = OP_AN_; // OP_AN; + } + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = Cells[CellY][CellX].sCoilName; + CStringA s2A; + s2A = sCoilName; + GetDocument()->TxtToCoilType(s2A, &nCoilType, &nCoilAddr); + + prog0.Params[0].nParamType = nCoilType; + prog0.Params[0].nParamAddr = nCoilAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeEND) { + theNode.prog1.Append(CMTerm1Doc::stProg(OP_END)); + } + else if (nType == typePP) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType; + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = sCoilName; + prog0.Params[0].nParamType = Cells[CellY][CellX].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX].nDataAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typePN) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType; + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = sCoilName; + prog0.Params[0].nParamType = Cells[CellY][CellX].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX].nDataAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeNOT) { + theNode.prog1.Append(CMTerm1Doc::stProg(OP_NOT)); + } + else if (nType == typeDF) { + theNode.prog1.Append(CMTerm1Doc::stProg(OP_DF)); + } + else if (nType == typeDF_) { + theNode.prog1.Append(CMTerm1Doc::stProg(OP_DF_)); + } + else if (nType == typeOUT) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = OP_OUT; + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = sCoilName; + CStringA s2A; + s2A = sCoilName; + GetDocument()->TxtToCoilType(s2A, &nCoilType, &nCoilAddr); + + prog0.Params[0].nParamType = nCoilType; + prog0.Params[0].nParamAddr = nCoilAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeSET) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = OP_SET; + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = sCoilName; + CStringA s2A; + s2A = sCoilName; + GetDocument()->TxtToCoilType(s2A, &nCoilType, &nCoilAddr); + + prog0.Params[0].nParamType = nCoilType; + prog0.Params[0].nParamAddr = nCoilAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeRESET) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = OP_RESET; + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = sCoilName; + CStringA s2A; + s2A = sCoilName; + GetDocument()->TxtToCoilType(s2A, &nCoilType, &nCoilAddr); + + prog0.Params[0].nParamType = nCoilType; + prog0.Params[0].nParamAddr = nCoilAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeCMP) { + CMTerm1Doc::stProg prog0; + Cells[CellY][CellX]; + prog0.nOpType1 = Cells[CellY][CellX].nOpType; + prog0.nParamCount = 2; + prog0.Params[0].sParamStr = Cells[CellY][CellX + 1].sParam; + prog0.Params[0].nParamType = Cells[CellY][CellX + 1].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX + 1].nDataAddr; + prog0.Params[1].sParamStr = Cells[CellY][CellX + 2].sParam; + prog0.Params[1].nParamType = Cells[CellY][CellX + 2].nDataType; + prog0.Params[1].nParamAddr = Cells[CellY][CellX + 2].nDataAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeTM) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType; + prog0.nParamCount = 2; + prog0.Params[0].sParamStr = Cells[CellY][CellX + 1].sParam; + prog0.Params[0].nParamType = Cells[CellY][CellX + 1].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX + 1].nDataAddr; + + prog0.Params[1].sParamStr = Cells[CellY][CellX + 2].sParam; + prog0.Params[1].nParamType = Cells[CellY][CellX + 2].nDataType; + prog0.Params[1].nParamAddr = Cells[CellY][CellX + 2].nDataAddr; + + theNode.prog1.Append(prog0); + } + else if (nType == typeFN1) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType;; + prog0.nParamCount = 1; + prog0.Params[0].sParamStr = Cells[CellY][CellX + 1].sParam; + prog0.Params[0].nParamType = Cells[CellY][CellX + 1].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX + 1].nDataAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeFN2) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType;; + prog0.nParamCount = 2; + prog0.Params[0].sParamStr = Cells[CellY][CellX + 1].sParam; + prog0.Params[0].nParamType = Cells[CellY][CellX + 1].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX + 1].nDataAddr; + prog0.Params[1].sParamStr = Cells[CellY][CellX + 2].sParam; + prog0.Params[1].nParamType = Cells[CellY][CellX + 2].nDataType; + prog0.Params[1].nParamAddr = Cells[CellY][CellX + 2].nDataAddr; + theNode.prog1.Append(prog0); + } + else if (nType == typeFN3) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType;; + prog0.nParamCount = 3; + prog0.Params[0].sParamStr = Cells[CellY][CellX + 1].sParam; + prog0.Params[0].nParamType = Cells[CellY][CellX + 1].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX + 1].nDataAddr; + prog0.Params[1].sParamStr = Cells[CellY][CellX + 2].sParam; + prog0.Params[1].nParamType = Cells[CellY][CellX + 2].nDataType; + prog0.Params[1].nParamAddr = Cells[CellY][CellX + 2].nDataAddr; + prog0.Params[2].sParamStr = Cells[CellY][CellX + 3].sParam; + prog0.Params[2].nParamType = Cells[CellY][CellX + 3].nDataType; + prog0.Params[2].nParamAddr = Cells[CellY][CellX + 3].nDataAddr; + + theNode.prog1.Append(prog0); + } + else if (nType == typeFN4) { + CMTerm1Doc::stProg prog0; + prog0.nOpType1 = Cells[CellY][CellX].nOpType;; + prog0.nParamCount = 4; + prog0.Params[0].sParamStr = Cells[CellY][CellX + 1].sParam; + prog0.Params[0].nParamType = Cells[CellY][CellX + 1].nDataType; + prog0.Params[0].nParamAddr = Cells[CellY][CellX + 1].nDataAddr; + prog0.Params[1].sParamStr = Cells[CellY][CellX + 2].sParam; + prog0.Params[1].nParamType = Cells[CellY][CellX + 2].nDataType; + prog0.Params[1].nParamAddr = Cells[CellY][CellX + 2].nDataAddr; + prog0.Params[2].sParamStr = Cells[CellY][CellX + 3].sParam; + prog0.Params[2].nParamType = Cells[CellY][CellX + 3].nDataType; + prog0.Params[2].nParamAddr = Cells[CellY][CellX + 3].nDataAddr; + prog0.Params[3].sParamStr = Cells[CellY][CellX + 4].sParam; + prog0.Params[3].nParamType = Cells[CellY][CellX + 4].nDataType; + prog0.Params[3].nParamAddr = Cells[CellY][CellX + 4].nDataAddr; + theNode.prog1.Append(prog0); + } + if (PrevNode > 0) { + AddArc(PrevNode, nNodeCount); + } + nNodeCount++; + return nNodeCount-1; +} + +int SearchLastInArc(int nNodeID) +{ + int ArcId = 0; + + return ArcId; +} + +int SearchLastOutArc(int nNodeID) +{ + int ArcId = 0; + + return ArcId; +} + +int CMTerm1View::AddArc(int nNodeID1, int nNodeID2) +{ + node& theNode1 = nodes[nNodeID1]; + node& theNode2 = nodes[nNodeID2]; + + arc& theArc = arcs[nArcCount]; + theArc.nId = nArcCount; + theArc.bEnable = 1; + theNode2.firstIn; + + + theArc.headNode = nNodeID2; + theArc.tailNode = nNodeID1; + theArc.hlinkId = 0; + theArc.tlinkId = 0; + + theArc.tailvex = &theNode1; + theArc.headvex = &theNode2; + theArc.tlink = 0; + theArc.hlink = 0; + + theNode1.outdegree++; + theNode2.indegree++; + + //濡傛灉椤剁偣宸茬粡鏈� 杩炴帴 锛屽皢鏂扮殑寮у姞鍒板凡鏈夊姬鐨勫悗闈€�� + + if (theNode1.firstOut == 0) { + theNode1.firstOut = &theArc; + }else { + arc * p1 = theNode1.firstOut; + for (; p1->tlink != 0;) { + p1 = p1->tlink; + } + p1->tlink = &theArc; + p1->tlinkId = nArcCount; + } + + if (theNode2.firstIn == 0) { + theNode2.firstIn = &theArc; + }else{ + arc* p1 = theNode2.firstIn; + for (; p1->hlink != 0;) { + p1 = p1->hlink; + } + p1->hlink = &theArc; + p1->hlinkId = nArcCount; + } + + nArcCount++; + return nArcCount; +} + +int CMTerm1View::MergeParallelNodeWithinVP(int nVPNodeId1, int nVPNodeId2) //鍚堝苟涓や釜涓茶仈鐨勮櫄鑺傜偣涔嬮棿鎵�鏈夌殑骞惰 Node锛屽苟琛屾暟閲忓彲鑳藉ぇ浜�2涓�� +{ + node& theNode1 = nodes[nVPNodeId1]; //铏氳妭鐐�1 + node& theNode2 = nodes[nVPNodeId2]; //铏氳妭鐐�2 + // 蹇呴』鍓嶈�� 涓� 鍚庤�� 涔嬮棿鏈変袱鏉′互涓� 涓旇繛缁紝鍏朵腑涓�鏂逛负鍙︿竴鏂圭殑瀛愰泦 鎵嶈兘鍚堝苟銆� + // 鍏堟壘鍒颁袱鑰呰繛鎺ョ殑寮� + if (!theNode1.bEnable || !theNode2.bEnable) return -1; + if (theNode1.outdegree < 2 || theNode2.indegree < 2 ) return -2; +// if (theNode1.firstOut != theNode2.firstIn) return -3; +// +// 鍏堟壘鍒扮涓�涓繛鎺� +// + CString s1; + //鍏堝垽鏂袱鑰呭ぇ灏� + int n1 = theNode1.outdegree; + int n2 = theNode2.indegree; + + if (n1 <= n2) { //鍓嶈�呮槸鍚庣殑鐨勫瓙闆� + int n = 0; + arc* ptheArc1 = theNode1.firstOut; + while (ptheArc1) + { // 鍙栧緱杩炴帴鐨勫疄鑺傜偣鍦板潃; + node* pThisNode1 = ptheArc1->headvex; + // 鍙栧緱瀹炶妭鐐硅繛鎺ョ殑寮�; + arc* ptheArc2 = pThisNode1->firstOut; + // 鍙栧嚭寮ц繛鎺ョ殑涓嬩竴涓妭鐐�, 鐩爣铏氳妭鐐� + node* pThatNode1 = ptheArc2->headvex; + // 鍒ゆ柇杩欎釜鐐规槸涓嶆槸鎸囧畾鐨勮櫄鑺傜偣 + if (pThatNode1 != &theNode2) { return -3; } // 娌¤繛鎺ュ埌绗簩涓櫄鑺傜偣 + n++; + // 缁х画涓嬩竴涓繛鎺ョ殑寮�; + ptheArc1 = ptheArc1->tlink; + } + if (theNode1.outdegree != n ) return -2; + + //node& theNode; + // 绗簩娆★紝閲嶆潵涓�閬嶏紝寮�濮嬪悎骞剁▼搴� + + stProgSection prog2; + ptheArc1 = theNode1.firstOut; + node* pThisNode1 = ptheArc1->headvex; // 绗竴涓疄鑺傜偣 + stProgSection prog1 = pThisNode1->prog1; + if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; } + else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; } + else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_ ){ + prog1.Prefix += 1; + s1.Format(_T(" <+1 %s"),prog1.ToText()); DbgLog(s1); + } + else { + prog1.Prefix += 0; + s1.Format(_T(" < +0 %s"),prog1.ToText()); DbgLog(s1); + } + prog2 = prog1; // 鍙栧緱绗竴涓疄鑺傜偣鐨勭▼搴� + ptheArc1 = ptheArc1->tlink; //涓嬩竴涓姬 + while (ptheArc1) + { + //鍙栧緱鐩歌繛鐨勫疄鑺傜偣鍦板潃 + node* pThisNode2 = ptheArc1->headvex; + stProgSection prog1 = pThisNode2->prog1; + if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; } + else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; } + else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_) { + prog1.Prefix += 1; + s1.Format(_T(" < 2 +1 %s"), prog1.ToText()); DbgLog(s1); + if (theNode1.nType == -1) { prog1.reduce(); } + } + else { + prog1.Prefix += 0; + s1.Format(_T(" < 2 +0 %s"),prog1.ToText()); DbgLog(s1); + } + + if (prog1.Progs.size() > 1) { + prog1.Append(CMTerm1Doc::stProg(OP_ORS)); + } + else { + if (pThisNode2->nType == typeNC) prog1.Progs[0].nOpType1 = OP_OR_; + else if (pThisNode2->nType == typeNO) prog1.Progs[0].nOpType1 = OP_OR; + else prog1.Progs[0].nOpType1 = OP_OR; + } + prog2 += prog1; + + // 鍙栧緱瀹炶妭鐐硅繛鎺ョ殑寮�; + + arc* ptheArc2 = pThisNode2->firstOut; + RemoveArc(ptheArc2->nId); //鍒犻櫎寮� + arc* pTheNextArc = ptheArc1->tlink; //鍙栧緱涓嬩竴涓姬骞朵繚瀛� + RemoveArc(ptheArc1->nId); //鍒犻櫎褰撳墠寮� + pThisNode2->bEnable = 0; //鍒犻櫎瀹炶妭鐐� + ptheArc1 = pTheNextArc; + } + if (theNode1.nType == -1 && theNode2.nType == -1) { prog2.Append(CMTerm1Doc::stProg(OP_ANS)); } + pThisNode1->prog1 = prog2; //灏嗘墍鏈夌▼搴忔眹鎬诲埌绗竴涓疄鑺傜偣 + // pThisNode1->prog1.reduce(); + // s1 = prog2.ToText(GetDocument()); + // DbgLog(_T("------ ") + s1); + } + else { // n1> n2 // 鍚庤�呮槸鍓嶈�呯殑瀛愰泦 + int n = 0; + arc* ptheArc1 = theNode2.firstIn; + while (ptheArc1) + { + + //鍙栧緱鐩歌繛鐨勮櫄鑺傜偣鍦板潃 + + // 鍙栧緱杩炴帴鐨勫疄鑺傜偣鍦板潃; + node* pThisNode1 = ptheArc1->tailvex; + // 鍙栧緱瀹炶妭鐐硅繛鎺ョ殑寮�; + arc* ptheArc2 = pThisNode1->firstIn; + // 鍙栧嚭寮ц繛鎺ョ殑涓嬩竴涓妭鐐� + node* pThatNode1 = ptheArc2->tailvex; + // 鍒ゆ柇杩欎釜鐐规槸涓嶆槸鎸囧畾鐨勮櫄鑺傜偣 + if (pThatNode1 != &theNode1) { return -3; } // 娌¤繛鎺ュ埌绗簩涓櫄鑺傜偣 + n++; + // 缁х画涓嬩竴涓繛鎺ョ殑寮�; + ptheArc1 = ptheArc1->hlink; + } + if (theNode2.indegree != n) return -1; + //node& theNode; + // 绗簩娆★紝閲嶆潵涓�閬嶏紝寮�濮嬪悎骞剁▼搴� + stProgSection prog2; + ptheArc1 = theNode2.firstIn; + node* pThisNode1 = ptheArc1->tailvex; // 绗竴涓疄鑺傜偣 + stProgSection prog1 = pThisNode1->prog1; + if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; } + else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; } + else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_) { + prog1.Prefix += 1; + s1.Format(_T(" > +1 %s"),prog1.ToText()); DbgLog(s1); + } + else { + prog1.Prefix += 0; + s1.Format(_T(" > +0 %s"), prog1.ToText()); DbgLog(s1); + } + prog2 = prog1; // 鍙栧緱绗竴涓疄鑺傜偣鐨勭▼搴� + + ptheArc1 = ptheArc1->hlink; + bool NeedANS = 0; + while (ptheArc1) + { + //鍙栧緱鐩歌繛鐨勮櫄鑺傜偣鍦板潃 + node* pThisNode2 = ptheArc1->tailvex; + + stProgSection prog1 = pThisNode2->prog1; + if (prog1.Progs[0].nOpType1 == OP_AN) { prog1.Progs[0].nOpType1 = OP_ST; } + else if (prog1.Progs[0].nOpType1 == OP_AN_) { prog1.Progs[0].nOpType1 = OP_ST_; } + else if (prog1.Progs[0].nOpType1 == OP_ST || prog1.Progs[0].nOpType1 == OP_ST_) { + prog1.Prefix += 1; + s1.Format(_T(" > 2 +1 %s"),prog1.ToText()); DbgLog(s1); + } + else { + prog1.Prefix += 0; + s1.Format(_T(" >2 +0 %s"),prog1.ToText()); DbgLog(s1); + } + if (prog1.Progs.size() > 1) { + prog1.Append(CMTerm1Doc::stProg(OP_ORS)); + NeedANS = 1; + } + else { + if (pThisNode2->nType == typeNC) prog1.Progs[0].nOpType1 = OP_OR_; + else if (pThisNode2->nType == typeNO) prog1.Progs[0].nOpType1 = OP_OR; + else prog1.Progs[0].nOpType1 = OP_OR; + NeedANS = 1; + } + prog2 += prog1; + + arc* ptheArc2 = pThisNode2->firstIn; + RemoveArc(ptheArc2->nId); //鍒犻櫎寮� + arc* pTheNextArc = ptheArc1->hlink; //鍙栧緱涓嬩竴涓姬骞朵繚瀛� + RemoveArc(ptheArc1->nId); //鍒犻櫎褰撳墠寮� + pThisNode2->bEnable = 0; //鍒犻櫎瀹炶妭鐐� + ptheArc1 = pTheNextArc; + } + if (theNode1.nType == -1 && theNode2.nType == -1 && NeedANS) { prog2.Append(CMTerm1Doc::stProg(OP_ANS)); } + pThisNode1->prog1 = prog2; //灏嗘墍鏈夌▼搴忔眹鎬诲埌绗竴涓疄鑺傜偣 + // pThisNode1->prog1.reduce(); + // s1 = prog2.ToText(GetDocument()); + // DbgLog(_T("------ ") + s1); + } + + return 0; +} + +int CMTerm1View::RemoveArc(int nArcId) +{ + arc& theArc = arcs[nArcId]; + node& theNode1 = *theArc.tailvex; + node& theNode2 = *theArc.headvex; + + // 鍏堢湅 Node1 杩欒竟锛� + // 棣栧姬 + if (theNode1.firstOut == &theArc) { + theNode1.firstOut = theArc.tlink; + } + else { + arc* thatArc = theNode1.firstOut; + while (thatArc->tlink !=0){ + if (thatArc->tlink == &theArc) { + thatArc->tlink = theArc.tlink; + break; + } + thatArc = thatArc->tlink; + } + } + + + // 鍐嶇湅 Node2 杩欒竟锛� + // 棣栧姬 + if (theNode2.firstIn == &theArc) { + theNode2.firstIn = theArc.hlink; + } + else { + arc* thatArc = theNode2.firstIn; + while (thatArc->hlink != 0) { + if (thatArc->hlink == &theArc) { + thatArc->hlink = theArc.hlink; + break; + } + thatArc = thatArc->hlink; + } + } + + theNode1.outdegree--; + theNode2.indegree--; + return nArcCount; +} + +int CMTerm1View::RemoveNode(int nNodeId) +{ + node& theNode = nodes[nNodeId]; + theNode.bEnable = 0; + if (theNode.indegree) { + + } + return nNodeCount; +} + +int CMTerm1View::MergeNode(int nNodeId1, int nNodeId2) //鍚堝苟涓や釜涓茶仈鐨� 瀹� Node +{ + node& theNode1 = nodes[nNodeId1]; + node& theNode2 = nodes[nNodeId2]; + // 蹇呴』鍓嶈�呭嚭搴� 涓�1 鍚庤�� 鍏ュ害 涓�1锛� 涓� 鐩歌繛锛� 鎵嶈兘鍚堝苟銆� + // 鍏堟壘鍒颁袱鑰呰繛鎺ョ殑寮� + if (!theNode1.bEnable || !theNode2.bEnable) return -1; + if (theNode1.outdegree != 1 || theNode2.indegree != 1) return -2; + if (theNode1.firstOut != theNode2.firstIn) return -3; + // 鍒犻櫎涓よ�呬箣闂寸殑寮с�� + RemoveArc(theNode1.firstOut->nId); + + theNode1.firstOut = 0; + theNode2.firstIn = 0; + + // 灏� Node2 鐨� 鍑� 寮э紝 杞Щ 鍒� node1 涓� + theNode1.CoilName += _T(" ") + theNode2.CoilName; + theNode1.firstOut = theNode2.firstOut; + theNode1.outdegree = theNode2.outdegree; + theNode1.prog1 += theNode2.prog1; // 娈电▼搴忓悎骞� + + arc* thatArc = theNode2.firstOut; + while (thatArc != 0) + { + thatArc->tailvex = &theNode1; + thatArc->tailNode = nNodeId1; + thatArc = thatArc->tlink; + theNode2.outdegree--; + } + // + // 鐜板湪 Node2 鐨勫叆搴﹀拰鍑哄害 鍧囦负 0锛� 鍒犻櫎 node2 + RemoveNode(nNodeId2); + return 0; +} + +// 鍚堝苟浠� nNodeId 铏氳妭鐐瑰彂鍑虹殑 鍚勪釜鍗曡 Nodes; 鐩村埌涓嬩竴涓杈撳嚭鐨勮櫄鑺傜偣 +int CMTerm1View::MergeVPSubSerialNodes(int nNodeId) +{ + node& theNode = nodes[nNodeId]; + + arc* theArc = theNode.firstOut; + while (theArc != 0) { + // 浠庡綋鍓嶅姬 鍙栧嚭涓�涓《鐐� + node * thisNode = theArc->headvex; + // 浠庤繖涓《鐐癸紝鎵惧埌涓嬩竴涓《鐐� + if (thisNode->outdegree == 1 && thisNode->firstOut != 0) { + node* thatNode = thisNode->firstOut->headvex; + while (thatNode->indegree == 1 && thatNode->outdegree <= 1 && thatNode->nType != -2) { + if (thatNode->nType == typeOUT || thatNode->nType == typeSET || thatNode->nType == typeRESET) { + //break; + } + MergeNode(thisNode->nId, thatNode->nId); + if (thatNode->firstOut) thatNode = thatNode->firstOut->headvex; + else break; + } + if (thatNode->nType == -1) { //鎵惧埌涓嬩竴涓櫄椤剁偣 + if (!thatNode->OutProcAllDone) { + MergeVPSubSerialNodes(thatNode->nId); //浠庤櫄椤剁偣缁х画 + } + } + } + // 鍚屼竴涓嚭鍙戠偣鐨� 涓嬩竴鏉″姬 + theArc = theArc->tlink; + }; + theNode.OutProcAllDone = 1; + + return 0; +} + +// 鍚堝苟浠� nNodeId 铏氳妭鐐瑰彂鍑虹殑 鍚勪釜鍗曡 Nodes; 鐩村埌涓嬩竴涓� 澶氳緭鍑虹殑铏氳妭鐐� +int CMTerm1View::MergeVPSerialNodes(int nNodeId) +{ + node& theNode = nodes[nNodeId]; + + arc* theArc = theNode.firstOut; + while (theArc != 0) { + // 浠庡綋鍓嶅姬 鍙栧嚭涓�涓《鐐� + node* thisNode = theArc->headvex; + // 浠庤繖涓《鐐癸紝鎵惧埌涓嬩竴涓《鐐� + if (thisNode->outdegree == 1 && thisNode->firstOut != 0) { + node* thatNode = thisNode->firstOut->headvex; + while (thatNode->nType != -2 && thatNode->indegree ==1 && thatNode->outdegree <= 1) { + if (thatNode->nType == typeOUT || thatNode->nType == typeSET || thatNode->nType == typeRESET) { + //break; + } + MergeNode(thisNode->nId, thatNode->nId); + if (thatNode->firstOut) thatNode = thatNode->firstOut->headvex; + else break; + } + if (thatNode->nType == -1) { //鎵惧埌涓嬩竴涓櫄椤剁偣 + if (!thatNode->OutProcAllDone) { + MergeVPSerialNodes(thatNode->nId); //浠庤櫄椤剁偣缁х画 + } + } + } + // 鍚屼竴涓嚭鍙戠偣鐨� 涓嬩竴鏉″姬 + theArc = theArc->tlink; + }; + theNode.OutProcAllDone = 1; + + return 0; +} + +//浠� X,Y 鐐癸紝鍚戜笂鏌ユ壘 铏氳妭鐐癸紝鏈�澶氱粓姝簬 endy; +int CMTerm1View::FindVPNode(int x, int y, int endy) +{ + int nNodeId = 0; + for (int i = nNodeCount -1 ; i>=1; i--) { + if (nodes[i].bEnable && nodes[i].nType == -1 && nodes[i].nCellX == x && nodes[i].nCellY <= y &&nodes[i].nCellY >=endy ) + { + nNodeId = i; break; + } + } + return nNodeId; +} + + +int CMTerm1View::ScanVPAOV(int nVPNodeId1, int nVPNodeId2) +{ + MergeParallelNodeWithinVP(nVPNodeId1, nVPNodeId2); + return 0; +} +int CMTerm1View::ScanAOV1(int nNodeId) +{ + node& theNode = nodes[nNodeId]; + CString s1; + int nInput = theNode.indegree; + int nOutput = theNode.outdegree; + // s1.Format(_T("%d type %d op %s coil %s in %d out %d"), theNode.nId, theNode.nType, theNode.Op, theNode.CoilName, theNode.indegree, theNode.outdegree); + // DbgLog(s1); + if (theNode.InProcCount < theNode.indegree) return 0; + // 铏氭嫙缁撶偣锛屽畬鎴愭墍鏈夎緭鍏ャ�� + + stProgSection prog2; + if (theNode.outdegree > 0) { + // 涓�鐩存悳绱笅鍘伙紝閬囧埌 杈撳叆涓嶄负0鐨� 铏氳妭鐐� 鏃� 鍋滄锛岃繘琛屼笅涓�涓凯浠� + arc* theArc = theNode.firstOut; + int allOutputMerged = 1; + int allOutputSimple = 1; + for (int i = 0; i < nOutput && theArc != 0; i++) { + node* thisNode = theArc->headvex; + thisNode->InProcCount++; + s1.Format(_T("- %d type %d op %s coil %s in %d out %d"), thisNode->nId, thisNode->nType, thisNode->Op, thisNode->CoilName, thisNode->indegree, thisNode->outdegree); + DbgLog(s1); + s1 = thisNode->prog1.ToText(); + DbgLog(_T("------ \r\n") + s1); + + arc* thisArc = thisNode->firstOut; + if (thisNode->outdegree > 0) { allOutputMerged = 0; } + if (thisNode->nType == typeOUT || thisNode->nType == typeSET || thisNode->nType == typeRESET) { + thisNode->prog1.bModifyVal = 0; + } + else { + allOutputSimple = 0; + thisNode->prog1.bModifyVal = 1; + } + while (thisArc) { + thisNode = thisArc->headvex; + thisNode->InProcCount++; + s1.Format(_T("-- %d type %d op %s coil %s in %d out %d"), thisNode->nId, thisNode->nType, thisNode->Op, thisNode->CoilName, thisNode->indegree, thisNode->outdegree); + DbgLog(s1); + if (thisNode->nType > 0) //thatNode.indegree == 1 && thatNode.outdegree == 1) + { + thisArc = thisNode->firstOut; + // node* thatNode = thisArc->headvex; + + } + else { + ScanVPAOV(nNodeId, thisNode->nId); + + if (thisNode->InProcCount >= thisNode->indegree) { + s1.Format(_T("-> %d type %d op %s coil %s in %d out %d"), thisNode->nId, thisNode->nType, thisNode->Op, thisNode->CoilName, thisNode->indegree, thisNode->outdegree); + DbgLog(s1); + + ScanAOV1(thisNode->nId); + } + break; + } + } + // if (thatNode.nType > 0) { + // prog2.Append(thatNode.prog1); + // } + //RemoveArc(theArc->nId); + // 鍚屼竴涓嚭鍙戠偣鐨� 涓嬩竴鏉″姬 + theArc = theArc->tlink; + } + if (theNode.outdegree >= 2 && allOutputMerged) { + s1.Format(_T(" Merge Output %d %d allsimple = %d "), nNodeId,theNode.outdegree,allOutputSimple); + DbgLog(s1); + if (allOutputSimple) { + arc * thisArc = theNode.firstOut; + node* thisNode = thisArc->headvex; + thisArc = thisArc->tlink; + for (int i = 1; i < nOutput && thisArc != 0; i++) { + node* thatNode = thisArc->headvex; + thisNode->prog1 += thatNode->prog1; + arc * tempArc = thisArc->tlink; + RemoveArc(thisArc->nId); + thisArc = tempArc; + RemoveNode(thatNode->nId); + } + } + else { + arc* thisArc = theNode.firstOut; + node* thisNode = thisArc->headvex; + stProgSection prog2; + prog2.Append(CMTerm1Doc::stProg(OP_PSHS)); + int bLastModify = 1; + prog2 += thisNode->prog1; + if (thisNode->prog1.bModifyVal == 0) { bLastModify = 0; s1.Format(_T(" ModifyVal = 0, %s"), thisNode->prog1.ToText()); } + thisArc = thisArc->tlink; + + for (int i = 1; i < nOutput && thisArc != 0; i++) { + node* thatNode = thisArc->headvex; + if (i == nOutput - 1) { // 鏈�鍚庝竴涓� + prog2.Append(CMTerm1Doc::stProg(OP_POPS)); + } + else { + if (bLastModify) { prog2.Append(CMTerm1Doc::stProg(OP_RDS)); } + } + if (thisNode->prog1.bModifyVal == 0) { bLastModify = 0;s1.Format(_T(" ModifyVal = 0, %s"), thisNode->prog1.ToText()); } + else { bLastModify = 1; } + prog2 += thatNode->prog1; + arc* tempArc = thisArc->tlink; + RemoveArc(thisArc->nId); + thisArc = tempArc; + RemoveNode(thatNode->nId); + } + thisNode->prog1 = prog2; + } + } + } + + return 0; + /* + node& theNode = nodes[nNodeId]; + + arc* theArc = theNode.firstOut; + while (theArc != 0) { + // 浠庡綋鍓嶅姬 鍙栧嚭涓�涓《鐐� + node* thisNode = theArc->headvex; + // 浠庤繖涓《鐐癸紝鎵惧埌涓嬩竴涓《鐐� + if (thisNode->outdegree == 1 && thisNode->firstOut != 0) { + node* thatNode = thisNode->firstOut->headvex; + while (thatNode->nType != -1) { + if (thatNode->nType == typeOUT || thatNode->nType == typeSET || thatNode->nType == typeRESET) { + break; + } + MergeNode(thisNode->nId, thatNode->nId); + if (thatNode->firstOut) thatNode = thatNode->firstOut->headvex; + else break; + } + if (thatNode->nType == -1) { //鎵惧埌涓嬩竴涓櫄椤剁偣 + if (!thatNode->OutProcAllDone) { + MergeSerialNodes(thatNode->nId); //浠庤櫄椤剁偣缁х画 + } + } + } + // 鍚屼竴涓嚭鍙戠偣鐨� 涓嬩竴鏉″姬 + theArc = theArc->tlink; + }; + theNode.OutProcAllDone = 1; + */ +} + +/// <summary> +/// 璇曠敤 AOV 鏂瑰紡 姊舰鍥捐浆Prog +/// </summary> +/// <returns></returns> +int CMTerm1View::TransLDSToProgAOV() +{ + CMTerm1Doc* pDoc = GetDocument(); + CString s1; + s1.Format(_T("Trans LDS to PRrog")); + DbgLog(s1); + s1.Format(_T("AOV 鏂瑰紡 灏嗘褰㈠浘杞垚prog鏍煎紡")); + DbgLog(s1); + + //姊舰鍥� ROW鏁伴噺 + s1.Format(_T("鎬昏琛屾暟 %d"), m_nTotalRow); + DbgLog(s1); + s1.Format(_T("Total Lines %d"), m_nTotalRow); + DbgLog(s1); + + //鍒嗘 + int nDivCount = 0; + //鍒嗘 鐐归泦鍚� + int Divs[100] = { 0 }; + for (int i = 0; i < m_nTotalRow+5 ; i++) + { + int nRow = i; + int bConnected = 0; + //鎵弿绋嬪簭锛屽缓绔嬪崄瀛楅摼琛紵 + for (int j = 0; j < m_CellPerLine; j++) + { + int nCol = j; + if (Cells[nRow][nCol].bLeftLineDn) + { + bConnected = 1; + //s1.Format(_T("row==%d col==%d 鏈夊乏涓嬬珫绾匡紒锛侊紒"), nRow, nCol); + //DbgLog(s1); + break; + } + } + if (!bConnected) + { + //鎵惧埌涓�澶勫垎鐣岀偣 + Divs[nDivCount] = i; + s1.Format(_T("Div at Line %d 鏄� 锛氾細锛氾細锛氾細锛氾細锛氾細锛氾細鍒嗙晫鐐�"), nRow); + DbgLog(s1); + nDivCount++; + } + } + stProgSection allprogs; + //姣忔鍗曠嫭澶勭悊 + for (int i = 0; i < nDivCount; i++) + { + int nStartLine, nEndLine; + nNodeCount = 0; + if (i == 0) + { + nStartLine = 0; + nEndLine = Divs[i]; + } + else + { + nStartLine = Divs[i - 1] + 1; + nEndLine = Divs[i]; + } + s1.Format(_T("鏈琛屽彿 璧峰-缁堟锛� %d - %d "), nStartLine, nEndLine); + DbgLog(s1); + //s1.Format(_T("Process Line %d - %d "), nStartLine, nEndLine); + //DbgLog(s1); + int nCounts[20] = { 0 }; + int nCounts2[20] = { 0 }; + int nCounts3[20] = { 0 }; + s1.Empty(); + stProgSection section1; + CString s2; + int PrevNode = 0; + nNodeCount = 1; //娓呯悊瀛樺偍鐨勯《鐐瑰拰寮ф暟鎹�� + nArcCount = 1; + AddNode(-2, 0, 0, _T("Mother")); //澧炲姞姣嶇嚎椤剁偣 + for (int j = nStartLine; j <= nEndLine; j++) { + int nPosX = 0; + PrevNode = 1; //浠庢瘝绾垮紑濮� + s1.Empty(); + for (int k = 0; k < m_CellPerLine; k++) { + stCell theCell = Cells[j][k]; + int nNextX = 1; + int nType; + int bRightLineUp = 0; + if (k < m_CellPerLine - 1) { bRightLineUp = Cells[j][k + 1].bLeftLineUp; } + nType = theCell.nType; + if (nType == typeNone) { PrevNode = 0; } // 涓嶈繛鎺ユ瘝绾�; + if (nType ) { + if (nType == typeLine1 && !theCell.bLeftLineUp && !theCell.bLeftLineDn && !bRightLineUp) continue; + if (nType == typeExt1 || nType == typeExt2 || nType == typeExt3 || nType == typeExt4) continue; + if (k!=0 && theCell.bLeftLineDn && !theCell.bLeftLineUp) { + PrevNode = AddNode(-1, k, j, _T("VP"),PrevNode); + } + if (k != 0 && theCell.bLeftLineUp) { + int VPNodeId = 0; + VPNodeId = FindVPNode(k , j, nStartLine); + PrevNode = VPNodeId; + } + + + switch (nType) { + case typeLine1: + + break; + case typeEND: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeNO: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeNC: + PrevNode = AddNode(nType, k, j, theCell.sCoilName +_T("/"), PrevNode); + break; + case typePP: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typePN: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeNOT: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeDF: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeDF_: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeOUT: + case typeSET: + case typeRESET: + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeCMP: + nNextX = 3; + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeExt1: + case typeExt2: + case typeExt3: + break; + case typeTM: + nNextX = 3; + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeFN1: + nNextX = 2; + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeFN2: + nNextX = 3; + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeFN3: + nNextX = 4; + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeFN4: + nNextX = 5; + PrevNode = AddNode(nType, k, j, theCell.sCoilName, PrevNode); + break; + case typeCoil: + break; + default: + break; + } + s2 = Cells[j][k].sCoilName; + //k += nStep - 1; + s1 += s2 + _T(" ") + intToString(nNextX) + _T(" "); + + if (bRightLineUp) { + int VPNodeId = 0; + VPNodeId = FindVPNode(k + 1, j, nStartLine); + AddArc(PrevNode, VPNodeId); + PrevNode = VPNodeId; + } + } + } + DbgLog(s1); + } + //杈撳嚭宸茬粡鐢熸垚鐨� AOV 鍥� 椤剁偣淇℃伅 + for (int j = 1; j < nNodeCount; j++) { + s1.Format(_T("%d %d %s %s in %d out %d %s "), j, nodes[j].nType,nodes[j].Op, nodes[j].CoilName,nodes[j].indegree,nodes[j].outdegree, nodes[j].prog1.ToText()); + DbgLog(s1); + } + //杈撳嚭AOV鍥剧殑 寮� 鏁版嵁 + for (int j = 1; j < nArcCount; j++) { + s1.Format(_T("%3d %2d - %2d "), j, arcs[j].tailNode, arcs[j].headNode); +// DbgLog(s1); + } + + for (int n = 1; n < 8; n++) { + s1.Format(_T("澶勭悊姝ラ %d "), n); + DbgLog(s1); + for (int j = 1; j < nNodeCount; j++) { + if (nodes[j].bEnable) nodes[j].OutProcAllDone = 0; + } + // 澶勭悊 AOV 鍥� + // 浠� 姣嶇嚎 寮�濮� + //涓茶仈褰掑苟 // 褰掑苟鍘熷垯锛� 鏅�氳妭鐐癸紝闈炶櫄鑺傜偣锛� 涓や釜铏氳妭鐐逛箣闂� 澶氫釜杩炵画鐨勶紝褰掑苟锛� 闈炶緭鍑恒�� + s1.Format(_T("鍚堝苟涓茶仈鐨勮妭鐐� %d "), n); + DbgLog(s1); + MergeVPSubSerialNodes(1); + // 澶勭悊铏氳妭鐐� + // 铏氳妭鐐圭殑澶氳緭鍏ュ鐞嗭紝 鍗� OR 鎴栬�� 澶� ORS銆� + // 铏氳妭鐐圭殑杈撳嚭澶勭悊锛� + // 瀵逛簬鍚庣画杩樻湁鍏卞悓铏氳妭鐐圭殑杈撳嚭锛� 绗竴涓笉澶勭悊锛� + // 绗簩涓紝鍗曚笉澶勭悊锛屽澶勭悊 ST锛� 鍚庨潰鐢辫櫄鑺傜偣鍐� ORS锛� ANS銆� + // 瀵逛簬鐩存帴杈撳嚭鐨勶紝濡傛灉鍚庨潰娌℃湁鏀瑰彉鐨勮緭鍑猴紝 鐩存帴杈撳嚭涓嶅鐞嗐�� + // 瀵逛簬鍚庨潰杩樻湁鏀瑰彉鐨勶紝 PSHS, RDS, POPS + // 鍙﹀锛屽彲浠ュ悗鏈熺畝鍖栵紝 ST 鍚庣揣璺� ORS 鐨勶紝 绠�鍖栦负 OR銆� + // PSHS RDS POPS 鍚庤窡涓嶆敼鍙樼殑銆� 绠�鍖� + s1.Format(_T("澶勭悊铏氳妭鐐圭殑杈撳嚭 %d "), n); + DbgLog(s1); + ScanAOV1(1); + if (nodes[2].outdegree == 0) break; + } + // 杈撳嚭澶勭悊瀹岀殑 AOV 鍥� + s1.Format(_T("澶勭悊瀹岀殑AOV鍥�")); + DbgLog(s1); + for (int j = 2; j < nNodeCount; j++) { + CStringA s2; + if (nodes[j].bEnable) { + s1.Format(_T("%d type %d op %s coil %s in %d out %d"), j, nodes[j].nType, nodes[j].Op, nodes[j].CoilName, nodes[j].indegree, nodes[j].outdegree); + DbgLog(s1); + s1 = nodes[j].prog1.ToText(); + DbgLog(s1); + } + } + allprogs += nodes[2].prog1; + nodes[2].prog1.Progs.clear(); + } + s1.Format(_T("瀹屾暣鐨凱LC绋嬪簭 \r\n")); + s1 += allprogs.ToText(); + DbgLog(s1); + // 鍒涘缓 AOV 鍥� + + //杈撳嚭绋嬪簭 + int n = (int)allprogs.Progs.size(); + s1.Format(_T("鎬荤▼搴忔鏁� %d "), n); + DbgLog(s1); + s1.Format(_T("all prog steps %d "), n); + DbgLog(s1); + for (int i = 0; i < n; i++) + { + int optype = allprogs.Progs[i].nOpType1; + allprogs.Progs[i].PairTo = 0;//?????????? + allprogs.Progs[i].nBinStep = i; + CStringA OpTxtA, OpShowTxtA; + CString OpTxt, OpShowTxt; + pDoc->OpToTxt(optype, OpTxtA); + pDoc->OpToShowTxt(optype, OpShowTxtA); + OpTxt = OpTxtA; + OpShowTxt = OpShowTxtA; + s1.Format(_T("%d %s %s"), optype, OpTxt, OpShowTxt); + pDoc->Progs[i] = allprogs.Progs[i]; + DbgLog(s1); + } + pDoc->m_nProgSteps = n; + return 0; +} /// <summary> /// 姊舰鍥捐浆Prog @@ -2586,7 +3782,7 @@ { nStartLine = 0; nEndLine = Divs[i]; - } + } else { nStartLine = Divs[i - 1]+1; @@ -2665,13 +3861,21 @@ { firstCoil = true; //寰幆閬嶅巻鍗曞厓鏍�(杞崲鐨勯�昏緫鍦ㄨ繖涓嚱鏁�) - ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec, nSteps); + //ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec, nSteps); + //ScanLDSCells2(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec, nSteps); } - sProg += sProgSec; - nAllSteps += nSteps; - Progsec += thisprogsec; + //sProg += sProgSec; + // nAllSteps += nSteps; + //Progsec += thisprogsec; } - + CString sProgSec; + int nSteps = 0;; + nCurPosY = i; + stProgSection thisprogsec; + ScanLDSCells2(nStartLine, nEndLine, nCurPosY, nCurPosX, 16,0, thisprogsec, sProgSec, nSteps); + sProg += sProgSec; + nAllSteps += nSteps; + Progsec += thisprogsec; DbgLog(_T("\r\n")+ sProg); int n = int(Progsec.Progs.size()); s1.Format(_T("绋嬪簭娈垫鏁帮細 %d "), n); @@ -2702,7 +3906,7 @@ for (int i = 0; i < n; i++) { int optype=allprogs.Progs[i].nOpType1; - allprogs.Progs[i].PairTo = 0; + allprogs.Progs[i].PairTo = 0;//?????????? allprogs.Progs[i].nBinStep = i; CStringA OpTxtA,OpShowTxtA; CString OpTxt,OpShowTxt; @@ -2712,7 +3916,7 @@ OpShowTxt = OpShowTxtA; s1.Format(_T("%d %s %s"), optype, OpTxt, OpShowTxt); pDoc->Progs[i] = allprogs.Progs[i]; -// DbgLog(s1); + DbgLog(s1); } pDoc->m_nProgSteps = n; return 0; @@ -2736,15 +3940,15 @@ { CString s1; int nCurPosX, nCurPosY; - int nNextX = 1;//姝ラ暱 + int nNextX = 1;//姝ラ暱(涓嬩釜璧峰鐐圭Щ鍔ㄧ殑璺濈) nCurPosY = nPosY; nCurPosX = nPosX; - int nCoilType, CoilAddr; +// int nCoilType, CoilAddr; CMTerm1Doc* pDoc = GetDocument(); for (int j = nPosX; j < m_CellPerLine; j += nNextX) { nCurPosX = j; - //鍏堝鐞嗗綋鍓嶅崟鍏�; + //鍏堝鐞嗗綋鍓嶅崟鍏冨熀鏈俊鎭�; int nType = Cells[nCurPosY][nCurPosX].nType; CString sCellName = Cells[nCurPosY][nCurPosX].sCoilName; CMTerm1Doc::stProg theprog; @@ -2761,30 +3965,28 @@ || Cells[nCurPosY][j + nNextX].bLeftLineDn) { - ////鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺� - //if (Cells[nCurPosY][j + nNextX].bLeftLineUp) - //{ - // // 寰�涓婇潰鏈夎繛鎺ヤ笖鏈夎Е鐐硅繛鎺ワ紝鎵嶄娇鐢∣RS - // s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX); - // DbgLog(s1); - // theprog.nOpType1 = OP_ORS; - // //theprog.nOpType1 = OP_ST; - // //theprog.PairTo = OP_ORS; - // progsec.Append(theprog); - // sProgSec.AppendFormat(_T("ORS \r\n")); - // firstCoil = false; - // nSteps += 1; - // nLevel -= 1; - //} - //宸︿笂鏄惁鏈夐摼鎺� + //鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺� + if (Cells[nCurPosY][j + nNextX].bLeftLineUp) + { + // 寰�涓婇潰鏈夎繛鎺ヤ笖鏈夎Е鐐硅繛鎺ワ紝鎵嶄娇鐢∣RS + s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX); + DbgLog(s1); + theprog.nOpType1 = OP_ORS; + progsec.Append(theprog); + sProgSec.AppendFormat(_T("ORS \r\n")); + firstCoil = false; + nSteps += 1; + nLevel -= 1; + } + //鍙充晶涓�鏍肩殑宸︿笂鏄惁鏈夐摼鎺� int nLeftUpCon = 0; if (Cells[nCurPosY][j + nNextX].bLeftLineUp) { nLeftUpCon = 1; } - //鍚戜笅鏌ユ壘锛岀湅鐪嬬珫绾跨殑宸︿晶涓嬮潰杩樻湁娌℃湁杩炴帴鍏朵粬涓滆タ - int nLeftDnCon = 0;//鍗曞厓鏍煎乏渚у悜涓嬭繛鎺ユ暟 - for (int k = nCurPosY + 1; k <= nEndLine; k++) + //鍚戜笅鏌ユ壘锛岀湅鐪嬬珫绾跨殑鍙充晶涓�鏍肩殑宸︿晶涓嬮潰杩樻湁娌℃湁杩炴帴鍏朵粬涓滆タ + int nLeftDnCon = 0;//鍗曞厓鏍煎彸渚т竴鏍肩殑宸︿晶鍚戜笅杩炴帴鏁� + for (int k = nCurPosY; k <= nEndLine; k++) { if (Cells[k][j + nNextX].bLeftLineDn) { @@ -2802,12 +4004,12 @@ s1.Format(_T("LeftUp %d LeftDn %d"), nLeftUpCon, nLeftDnCon); DbgLog(s1); - //宸︿晶涓嬮潰鏈夎繛鎺ワ紝閭d箞鎵弿鍒拌繖涓珫绾挎椂杩斿洖锛岀户缁壂鎻忓乏渚т笅闈㈢殑鍐呭銆� + //鍙充晶涓�鏍肩殑宸︿晶涓嬮潰鏈夎繛鎺ワ紝閭d箞鎵弿鍒拌繖涓珫绾挎椂杩斿洖锛岀户缁壂鎻忓乏渚т笅闈㈢殑鍐呭銆� if (nLeftDnCon) { return 1; } - // 宸︿晶涓嬮潰娌℃湁杩炴帴锛岄偅涔堣繖涓氨鏄乏闈㈡渶鍚庣殑鍗曞厓锛屽紑濮嬪鐞嗗彸闈㈢殑鍗曞厓銆� + //鍙充晶涓�鏍肩殑宸︿晶涓嬮潰娌℃湁杩炴帴锛岄偅涔堣繖涓氨鏄乏闈㈡渶鍚庣殑鍗曞厓锛屽紑濮嬪鐞嗗彸闈㈢殑鍗曞厓銆� else { if (nLeftUpCon) @@ -2854,13 +4056,13 @@ if (nRightCon == 1) { - s1.Format(_T(">>>> Go %d : %d , level %d "), nLineTop, j + nNextX, nLevel); + s1.Format(_T(">>>> Go %d : %d , level %d "), nLineTop, j + nNextX, nLevel); DbgLog(s1); CString ProgSec; int theSteps = 0; stProgSection thisprogsec; - // + //杩欐湁闂锛屽簲璇ユ槸鍦ㄦ渶楂樼偣鐨勬椂鍊欙紝鍗曠嫭杩涜涓�娆¤浆鎹紵 int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel, thisprogsec, ProgSec, theSteps); sProgSec += ProgSec; @@ -2868,6 +4070,7 @@ progsec += thisprogsec; s1.Format(_T("<<<< Re %d : %d , Result %d "), nLineTop, j + nNextX, 0); DbgLog(s1); + continue; } else { @@ -2899,7 +4102,7 @@ DbgLog(s1); if (nRightCount == 0) { - + //杩欓噷鏄笉鏄簲璇ュ仛鐐逛粈涔� } else if (res[nRightCount - 1] == 0) { @@ -2948,7 +4151,12 @@ } } } - + //濡傛灉娌℃湁绔栫嚎鐩存帴缈昏瘧 + else + { + Translate2Prog(nType, j + nNextX, nLevel, sCellName, progsec, sProgSec, nSteps); + } + /* #pragma region 鏍规嵁鍗曞厓鏍肩被鍨嬭浆鎹负鎸囦护鍜宲rog if (nType == typeNO) @@ -3180,253 +4388,371 @@ } #pragma endregion - + */ } return 0; } - /* - void CMTerm1View::chuansileitetoprog(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, stProgSection& progsec, CString& sProgSec, int& nSteps) - { - CString s1; - int nCurPosX, nCurPosY; - int nNextX = 1;//姝ラ暱 - nCurPosY = nPosY; - nCurPosX = nPosX; - int nCoilType, CoilAddr; - CMTerm1Doc* pDoc = GetDocument(); -#pragma region 鏍规嵁鍗曞厓鏍肩被鍨嬭浆鎹负鎸囦护鍜宲rog +// 璁板綍y,x - if (nType == typeNO) - { - if (firstCoil && nType != typeLine1 && nType != typeLine2) - { - //鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺� - if (Cells[nCurPosY][j + nNextX].bLeftLineUp) - { - // 寰�涓婇潰鏈夎繛鎺ヤ笖鏈夎Е鐐硅繛鎺ワ紝鎵嶄娇鐢∣R - s1.Format(_T("%d %d OR %s"), nCurPosY, nCurPosX, sCellName); - sProgSec.AppendFormat(_T("OR %s\r\n"), sCellName); - .nOpType1 = OP_OR; - } - else - { - s1.Format(_T("%d %d ST %s"), nCurPosY, nCurPosX, sCellName); - sProgSec.AppendFormat(_T("ST %s\r\n"), sCellName); - theprog.nOpType1 = OP_ST; - } - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - firstCoil = false; - } - else - { - s1.Format(_T("%d %d AN %s"), nCurPosY, nCurPosX, sCellName); - sProgSec.AppendFormat(_T("NO %s\r\n"), sCellName); - theprog.nOpType1 = OP_AN; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - } - nSteps += 1; - DbgLog(s1); - nNextX = 1; - } - else if (nType == typeNC) - { - if (firstCoil && nType != typeLine1 && nType != typeLine2) - { - s1.Format(_T("%d %d ST/ %s"), nCurPosY, nCurPosX, sCellName); - sProgSec.AppendFormat(_T("ST/ %s\r\n"), sCellName); - theprog.nOpType1 = OP_ST_; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - firstCoil = false; - } - else - { - s1.Format(_T("%d %d AN/ %s"), nCurPosY, nCurPosX, sCellName); - sProgSec.AppendFormat(_T("AN/ %s\r\n"), sCellName); - theprog.nOpType1 = OP_AN_; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - } - DbgLog(s1); - nSteps += 1; - nNextX = 1; - } - else if (nType == typePP) - { - s1.Format(_T("%d %d PP %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - //progsec.Append(theprog); - sProgSec.AppendFormat(_T("PP %s\r\n"), sCellName); - nSteps += 1; - nNextX = 1; - } - else if (nType == typePN) - { - s1.Format(_T("%d %d PN %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - //progsec.Append(theprog); - sProgSec.AppendFormat(_T("PN %s\r\n"), sCellName, sCellName); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeNOT) - { - s1.Format(_T("%d %d NOT %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - sProgSec.AppendFormat(_T("NOT %s\r\n"), sCellName); - theprog.nOpType1 = OP_NOT; - progsec.Append(theprog); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeDF) - { - s1.Format(_T("%d %d DF %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - sProgSec.AppendFormat(_T("DF %s\r\n"), sCellName); - theprog.nOpType1 = OP_DF; - progsec.Append(theprog); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeDF_) - { - s1.Format(_T("%d %d DF/ %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - sProgSec.AppendFormat(_T("DF/ %s\r\n"), sCellName); - theprog.nOpType1 = OP_DF_; - progsec.Append(theprog); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeOUT) - { - s1.Format(_T("%d %d OUT %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - sProgSec.AppendFormat(_T("OUT %s\r\n"), sCellName); - theprog.nOpType1 = OP_OUT; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeSET) - { - s1.Format(_T("%d %d SET %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - sProgSec.AppendFormat(_T("SET %s\r\n"), sCellName); - theprog.nOpType1 = OP_SET; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeRESET) - { - s1.Format(_T("%d %d RESET %s"), nCurPosY, nCurPosX, sCellName); - DbgLog(s1); - sProgSec.AppendFormat(_T("RESET %s\r\n"), sCellName); - theprog.nOpType1 = OP_RESET; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - nSteps += 1; - nNextX = 1; - } - else if (nType == typeCMP) - { - s1.Format(_T("%d %d CMP %s %s %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); - DbgLog(s1); - theprog.nOpType1 = OP_ST_GT; - theprog.nParamCount = 1; - progsec.Append(theprog); - sProgSec.AppendFormat(_T("CMP %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); - nSteps += 1; - nNextX = 3; - } - else if (nType == typeTM) - { - s1.Format(_T("%d %d TM %s %d %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); - DbgLog(s1); - theprog.nOpType1 = OP_TMX; - theprog.nParamCount = 1; - pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); - theprog.Params[0].nParamType = nCoilType; - theprog.Params[0].nParamAddr = CoilAddr; - theprog.Params[0].sParamStr = sCellNameA; - progsec.Append(theprog); - sProgSec.AppendFormat(_T("TM %s %d %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); - nSteps += 1; - nNextX = 3; - } - else if (nType == typeFN1) - { - s1.Format(_T("%d %d FN1 %s %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam); - DbgLog(s1); - theprog.nOpType1 = OP_INC; - progsec.Append(theprog); - sProgSec.AppendFormat(_T("FN1 %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam); - nSteps += 1; - nNextX = 2; - } - else if (nType == typeFN2) - { - s1.Format(_T("%d %d FN2 %s %s %s "), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); - DbgLog(s1); - theprog.nOpType1 = OP_MV; - progsec.Append(theprog); - sProgSec.AppendFormat(_T("FN2 %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); - nSteps += 1; - nNextX = 3; - } - else if (nType == typeFN3) - { - s1.Format(_T("%d %d FN3 %s %s %s %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam, Cells[nCurPosY][nCurPosX + 3].sParam); - DbgLog(s1); - theprog.nOpType1 = OP_ADD3; - progsec.Append(theprog); - sProgSec.AppendFormat(_T("FN3 %s %s %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam, Cells[nCurPosY][nCurPosX + 3].sParam); - nSteps += 1; - nNextX = 4; - } - else - { - nNextX = 1; - //continue; - } +int CMTerm1View::ScanLDSCells2(int nStartLine, int nEndLine, int nPosY, int nPosX, int nSizeX, + int nLevel, stProgSection& progsec, CString& sProgSec, int& nSteps) +{ + CString s1; + int nCurPosX, nCurPosY; + int nNextX = 0;//姝ラ暱锛堝埌涓嬩釜绾垮湀璧峰浣嶇疆搴旂Щ鍔ㄨ窛绂� + nCurPosY = nStartLine; + nCurPosX = nPosX; +// int nCoilType, CoilAddr; + CMTerm1Doc* pDoc = GetDocument(); -#pragma endregion + for (int j = nPosX; j < nSizeX; j += nNextX) + { + nCurPosX = j; + //鍏堝鐞嗗綋鍓嶅崟鍏�; + int nType = Cells[nCurPosY][nCurPosX].nType; + CString sCellName = Cells[nCurPosY][nCurPosX].sCoilName; + CMTerm1Doc::stProg theprog; + CStringA sCellNameA; + sCellNameA = sCellName; + CString ProgSec; + int theSteps = 0; + + stProgSection thisprogsec; + + //鍒ゆ柇瓒婄晫 + if (j + nNextX > m_CellPerLine) + { + continue; + } + //if (!firstCoil && Cells[nCurPosY][j].bLeftLineUp) + //{ + // break; + //} + if (Cells[nCurPosY][nCurPosX].nType == typeNone) + { + nNextX = 1; + continue; + } + //寮�濮嬬炕璇戝崟涓崟鍏冩牸锛屽苟杩斿洖涓嬩釜鍗曞厓鏍间綅缃� + nNextX = Translate2Prog(nType, nCurPosY, nCurPosX, sCellName, progsec, sProgSec, nSteps); + //1.鍒ゆ柇姝ゅ崟鍏冩牸鍙充晶涓�鏍兼槸鍚︽湁鍚戜笅鐨勭珫绾� + if (Cells[nCurPosY][j + nNextX].bLeftLineDn) + { + //1.1:鏈夊垎鏀紝鐩存帴寮�濮嬭鍙栦笅涓�琛� + if (Cells[nCurPosY +1][j].nType == typeNone) + { + if (Cells[nCurPosY + 1][j + nNextX].nType != typeNone) + { + firstCoil = true; + } + continue; + } + + firstCoil = true; + ScanLDSCells2(nCurPosY + 1, nCurPosY + 1, nCurPosY + 1, 0, j + nNextX, ++nLevel, thisprogsec, ProgSec, theSteps); + + //鏈塐R鍏崇郴涓斾笉鍙竴涓妭鐐� + if (theSteps > 1 && nLevel > 0) + { + // 姝ユ暟澶т簬1锛屾槸澶嶅悎缁撴灉锛屾墠浣跨敤ORS + s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX); + DbgLog(s1); + theprog.nOpType1 = OP_ORS; + //progsec.Append(theprog); + //sProgSec.AppendFormat(_T("ORS \r\n")); + thisprogsec.Append(theprog); + ProgSec.AppendFormat(_T("ORS \r\n")); + firstCoil = false; + nSteps += 1; + } + + //1.2:浠庡悗鍚戝墠鏌ユ壘涓嬩竴琛屾槸鍚﹁繕鏈夊悜涓婄殑绔栫嚎锛堝舰鎴愰棴鐜級锛圤RS銆丄NS锛� + for (int k = j; k >= 0; k--) + { + if (Cells[nCurPosY + 1][k].nType == typeNone) + { + //濡傛灉閬囧埌绌烘牸锛岃繕娌℃悳鍒帮紝灏辩粨鏉熸悳绱� + break; + } + if (Cells[nCurPosY+1][k].bLeftLineUp) + { + //濡傛灉鏈変竴鏉$珫绾匡紝璇存槑鏄舰鎴愪簡鐜紝瑕佺敤ANS + if (theSteps >= 1 && nLevel > 0) + { + //姝ユ暟澶т簬1锛屾槸澶嶅悎缁撴灉锛屼娇鐢ˋNS + s1.Format(_T("%d %d ANS "), nCurPosY, nCurPosX); + DbgLog(s1); + theprog.nOpType1 = OP_ANS; + //progsec.Append(theprog); + //sProgSec.AppendFormat(_T("ANS \r\n")); + thisprogsec.Append(theprog); + ProgSec.AppendFormat(_T("ANS \r\n")); + nSteps += 1; + } + } + } + + //灏嗚浆鎹㈠畬鎴愮殑閮ㄥ垎鍔犲叆鍒版�婚泦涓� + nSteps += theSteps; + progsec += thisprogsec; + sProgSec += ProgSec; + + //1.3:鏌ヨ姝ゅ垎鏀笅涓�绾ц繛鎺ョ偣宸﹀彸鍧囧瓨鍦ㄨ妭鐐癸紝瀛樺湪灏盤SHS + if (Cells[nCurPosY + 1][j].nType != typeNone + && Cells[nCurPosY + 1][j + 1].nType != typeNone) + { + ++nPSHS; + CString push = _T("PSHS \r\n"); + theprog.nOpType1 = OP_PSHS; + progsec.Append(theprog); + sProgSec.Append(push); + popsPoint[nPSHS] = std::make_pair(nCurPosY + 1, j + 1); + } + }//end 1.鍒ゆ柇姝ゅ崟鍏冩牸鍙充晶涓�鏍兼槸鍚︽湁鍚戜笅鐨勭珫绾� + + } + nLevel--; + //宸插洖鍒拌捣濮嬪眰 + if (nLevel == 0) + { + CMTerm1Doc::stProg theprog; + for (int i = nPSHS; i >= 0; i--) + { + //+POP + CString pop = _T("POPS \r\n"); + theprog.nOpType1 = OP_POPS; + progsec.Append(theprog); + sProgSec.Append(pop); + //+fanyi + //寮�濮嬬炕璇戝崟涓崟鍏冩牸锛屽苟杩斿洖涓嬩釜鍗曞厓鏍间綅缃� + //firstCoil = true; + ScanLDSCells2(popsPoint[nPSHS].first, popsPoint[nPSHS].first, popsPoint[nPSHS].first, popsPoint[nPSHS].second, 16, nLevel, progsec, sProgSec, nSteps); + nPSHS--; + + } + if (nPSHS == -1) + { + fill(popsPoint, popsPoint + 100, std::make_pair(0, 0)); + } + } + + return 0; } -*/ + + +int CMTerm1View::Translate2Prog( + int nType, int nCurPosY, int nCurPosX, CString sCellName, + stProgSection& progsec, CString& sProgSec, int& nSteps) +{ + CString s1; + int nNextX = 1;//姝ラ暱 + int nCoilType, CoilAddr; + CMTerm1Doc::stProg theprog; + CMTerm1Doc* pDoc = GetDocument(); + CStringA sCellNameA; + sCellNameA = sCellName; + //if (nType == typeNone) + //{ + // return 0; + //} + if (nType == typeNO) + { + if (firstCoil && nType != typeLine1 && nType != typeLine2) + { + //鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺� + if (Cells[nCurPosY][nCurPosX + nNextX].bLeftLineUp) + { + // 寰�涓婇潰鏈夎繛鎺ワ紝浣跨敤OR + sProgSec.AppendFormat(_T("OR %s\r\n"), sCellName); + theprog.nOpType1 = OP_OR; + } + else + { + sProgSec.AppendFormat(_T("ST %s\r\n"), sCellName); + theprog.nOpType1 = OP_ST; + } + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + firstCoil = false; + } + else + { + sProgSec.AppendFormat(_T("AN %s\r\n"), sCellName); + theprog.nOpType1 = OP_AN; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + } + + nSteps += 1; + nNextX = 1; + } + else if (nType == typeNC) + { + if (firstCoil && nType != typeLine1 && nType != typeLine2) + { + sProgSec.AppendFormat(_T("ST/ %s\r\n"), sCellName); + theprog.nOpType1 = OP_ST_; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + firstCoil = false; + } + else + { + sProgSec.AppendFormat(_T("AN/ %s\r\n"), sCellName); + theprog.nOpType1 = OP_AN_; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + } + nSteps += 1; + nNextX = 1; + } + else if (nType == typePP) + { + //progsec.Append(theprog); + sProgSec.AppendFormat(_T("PP %s\r\n"), sCellName); + nSteps += 1; + nNextX = 1; + } + else if (nType == typePN) + { + //progsec.Append(theprog); + sProgSec.AppendFormat(_T("PN %s\r\n"), sCellName, sCellName); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeNOT) + { + sProgSec.AppendFormat(_T("NOT %s\r\n"), sCellName); + theprog.nOpType1 = OP_NOT; + progsec.Append(theprog); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeDF) + { + sProgSec.AppendFormat(_T("DF %s\r\n"), sCellName); + theprog.nOpType1 = OP_DF; + progsec.Append(theprog); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeDF_) + { + sProgSec.AppendFormat(_T("DF/ %s\r\n"), sCellName); + theprog.nOpType1 = OP_DF_; + progsec.Append(theprog); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeOUT) + { + sProgSec.AppendFormat(_T("OUT %s\r\n"), sCellName); + theprog.nOpType1 = OP_OUT; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeSET) + { + sProgSec.AppendFormat(_T("SET %s\r\n"), sCellName); + theprog.nOpType1 = OP_SET; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeRESET) + { + sProgSec.AppendFormat(_T("RESET %s\r\n"), sCellName); + theprog.nOpType1 = OP_RESET; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + nSteps += 1; + nNextX = 1; + } + else if (nType == typeCMP) + { + theprog.nOpType1 = OP_ST_GT; + theprog.nParamCount = 1; + progsec.Append(theprog); + sProgSec.AppendFormat(_T("CMP %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); + nSteps += 1; + nNextX = 3; + } + else if (nType == typeTM) + { + theprog.nOpType1 = OP_TMX; + theprog.nParamCount = 1; + pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr); + theprog.Params[0].nParamType = nCoilType; + theprog.Params[0].nParamAddr = CoilAddr; + theprog.Params[0].sParamStr = sCellNameA; + progsec.Append(theprog); + sProgSec.AppendFormat(_T("TM %s %d %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); + nSteps += 1; + nNextX = 3; + } + else if (nType == typeFN1) + { + theprog.nOpType1 = OP_INC; + progsec.Append(theprog); + sProgSec.AppendFormat(_T("FN1 %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam); + nSteps += 1; + nNextX = 2; + } + else if (nType == typeFN2) + { + theprog.nOpType1 = OP_MV; + progsec.Append(theprog); + sProgSec.AppendFormat(_T("FN2 %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam); + nSteps += 1; + nNextX = 3; + } + else if (nType == typeFN3) + { + theprog.nOpType1 = OP_ADD3; + progsec.Append(theprog); + sProgSec.AppendFormat(_T("FN3 %s %s %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam, Cells[nCurPosY][nCurPosX + 3].sParam); + nSteps += 1; + nNextX = 4; + } + else + { + nNextX = 1; + //continue; + } + return nNextX; +} + /// <summary> /// 鍏ㄩ儴鍥惧舰鏍¢獙 @@ -3436,75 +4762,75 @@ /// 璁″垝鍦ㄧ涓�涓繑鍥炲�间腑浣跨敤涓嶅悓鐨勯敊璇唬鐮佷唬琛ㄤ笉鍚岀殑閿欒绫诲瀷锛� /// 骞跺湪绗簩涓繑鍥炲�间腑濉厖閿欒鎻愮ず淇℃伅 /// </remark> -std::pair<int, CString> CMTerm1View::LDSCheckRule() -{ - CString message; - int nDivCount = 0; - int Divs[100] = { 0 }; - //浠ヨ涓哄崟浣嶄粠涓婂埌涓嬮亶鍘嗭紙琛岄亶鍘嗭級 - for (int i = 0; i < m_nTotalRow; i++) - { - int nRow = i; - int bConnected = 0; - bool checkFlag = false;//0鍒楁楠岀粨鏋� + std::pair<int, CString> CMTerm1View::LDSCheckRule() + { + CString message; + int nDivCount = 0; + int Divs[100] = { 0 }; + //浠ヨ涓哄崟浣嶄粠涓婂埌涓嬮亶鍘嗭紙琛岄亶鍘嗭級 + for (int i = 0; i < m_nTotalRow; i++) + { + int nRow = i; + int bConnected = 0; + bool checkFlag = false;//0鍒楁楠岀粨鏋� - //鏈鐨�0鍒楁鏌� - if (Cells[nRow][0].nType == 0) - { - checkFlag = true; - } + //鏈鐨�0鍒楁鏌� + if (Cells[nRow][0].nType == 0) + { + checkFlag = true; + } - //閬嶅巻姝よ鐨�1-15鍒楋紙纭畾鍗曞厓鏍硷級 - for (int j = 1; j < m_CellPerLine; j++) - { - int nCol = j; - //濡傛灉0鍒椾负绌� - if (checkFlag) - { - //鏈夊乏渚т笂绔栫嚎 - if (Cells[nRow][nCol].bLeftLineUp) - { - //濡傛灉涓婂眰涓虹┖鍗曞厓鏍硷紝鏃犳晥绔栫嚎锛岀洿鎺ュ垹闄�-----鍙互鍗曠嫭鍒ゆ柇 - if (nRow - 1 >= 0 && Cells[nRow-1][nCol].nType == 0) - { - //娓呯悊鍗曞厓鏍� - Cells[nRow][nCol].clear(); - } - //濡傛灉鏄痭one锛岄敊璇細鐭矾鎴栧洖璺� - else if (Cells[nRow][nCol].nType == 0) - { - message.Format(_T("((%d,%d) 闄勮繎浣嶇疆浜х敓瑙︾偣鐭矾鎴栧洖璺紒"),nRow,nCol); - return std::make_pair(111, message); - } - //濡傛灉涓嶄负none銆傚彲浠ヨ浆鎹紝浣嗘槸鎻愮ず锛氭棤娉曠粯鍒跺浘褰紙绋嬪簭涓嶅悎鐞嗭級 - if (Cells[nRow][nCol].nType != 1) - { - message.Format(_T("((%d,%d) 鏃犳硶缁樺埗鍥惧舰锛堢▼搴忎笉鍚堢悊锛�"), nRow, nCol); - return std::make_pair(111, message); - } + //閬嶅巻姝よ鐨�1-15鍒楋紙纭畾鍗曞厓鏍硷級 + for (int j = 1; j < m_CellPerLine; j++) + { + int nCol = j; + //濡傛灉0鍒椾负绌� + if (checkFlag) + { + //鏈夊乏渚т笂绔栫嚎 + if (Cells[nRow][nCol].bLeftLineUp) + { + //濡傛灉涓婂眰涓虹┖鍗曞厓鏍硷紝鏃犳晥绔栫嚎锛岀洿鎺ュ垹闄�-----鍙互鍗曠嫭鍒ゆ柇 + if (nRow - 1 >= 0 && Cells[nRow - 1][nCol].nType == 0) + { + //娓呯悊鍗曞厓鏍� + Cells[nRow][nCol].clear(); + } + //濡傛灉鏄痭one锛岄敊璇細鐭矾鎴栧洖璺� + else if (Cells[nRow][nCol].nType == 0) + { + message.Format(_T("((%d,%d) 闄勮繎浣嶇疆浜х敓瑙︾偣鐭矾鎴栧洖璺紒"), nRow, nCol); + return std::make_pair(111, message); + } + //濡傛灉涓嶄负none銆傚彲浠ヨ浆鎹紝浣嗘槸鎻愮ず锛氭棤娉曠粯鍒跺浘褰紙绋嬪簭涓嶅悎鐞嗭級 + if (Cells[nRow][nCol].nType != 1) + { + message.Format(_T("((%d,%d) 鏃犳硶缁樺埗鍥惧舰锛堢▼搴忎笉鍚堢悊锛�"), nRow, nCol); + return std::make_pair(111, message); + } - } - //娌℃湁宸︿晶涓婄珫绾匡紝涓旀鍗曞厓鏍肩被鍨� 涓嶄负绌烘垨绾� - else if (Cells[nRow][nCol].nType > 2) - { - //姝ゅ崟鍏冩牸涓哄崟鐙殑绾垮湀鎴栨寚浠ゅ崟鍏冿紝闇�瑕佽Е鐐硅緭鍏� - message.Format(_T("((%d,%d) 闇�瑕佽Е鐐硅緭鍏�"), nRow, nCol); - return std::make_pair(111, message); - } - //鏈夊乏渚т笅绔栫嚎锛屼笖姝ゅ崟鍏冩牸绫诲瀷涓虹┖ - if (Cells[nRow][nCol].bLeftLineDn) - { - //涓嶆敮鎸佸洖璺� - } - } - //濡�0鍒楅潪绌� - else - { + } + //娌℃湁宸︿晶涓婄珫绾匡紝涓旀鍗曞厓鏍肩被鍨� 涓嶄负绌烘垨绾� + else if (Cells[nRow][nCol].nType > 2) + { + //姝ゅ崟鍏冩牸涓哄崟鐙殑绾垮湀鎴栨寚浠ゅ崟鍏冿紝闇�瑕佽Е鐐硅緭鍏� + message.Format(_T("((%d,%d) 闇�瑕佽Е鐐硅緭鍏�"), nRow, nCol); + return std::make_pair(111, message); + } + //鏈夊乏渚т笅绔栫嚎锛屼笖姝ゅ崟鍏冩牸绫诲瀷涓虹┖ + if (Cells[nRow][nCol].bLeftLineDn) + { + //涓嶆敮鎸佸洖璺� + } + } + //濡�0鍒楅潪绌� + else + { - } - } + } + } - } - return std::make_pair(0,message); -} + } + return std::make_pair(0, message); + } -- Gitblit v1.9.1