| | |
| | | nCurLine = cy + 1; //另起一行
|
| | | {
|
| | | int hasData = 1;
|
| | | while (hasData) {
|
| | | while (hasData) |
| | | {
|
| | | hasData = 0;
|
| | | for (int j = cx; j < m_CellPerLine; j++) {
|
| | | if (Cells[nCurLine][j].nType != 0) {
|
| | | nCurLine++; hasData = 1; break;
|
| | | 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++) {
|
| | | 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;
|
| | | StPts[nSts] = POINT{ cx,cy };//+++
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].nType = nOp == OP_OR ? typeNO : typeNC; //typeNC
|
| | | Cells[cy][cx].sCoilName = 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++)
|
| | | {
|
| | |
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | |
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | |
| | | /// </summary>
|
| | | /// <param name="nStartLine"></param>
|
| | | /// <param name="nEndLine"></param>
|
| | | /// <param name="nPosY"></param>
|
| | | /// <param name="nPosX"></param>
|
| | | /// <param name="nLevel"></param>
|
| | | /// <param name="nPosY">行</param>
|
| | | /// <param name="nPosX">列</param>
|
| | | /// <param name="nLevel">层级</param>
|
| | | /// <param name="progsec">prog格式的指令集</param>
|
| | | /// <param name="sProgSec">指令集</param>
|
| | | /// <param name="nSteps">程序步数</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps)
|
| | | int CMTerm1View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX,
|
| | | int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | | CString s1;
|
| | | int nCurPosX, nCurPosY;
|
| | | int nNextX = 1;//步长
|
| | |
| | | || Cells[nCurPosY][j + nNextX].bLeftLineDn)
|
| | | {
|
| | |
|
| | | //先看往上面有没有连接
|
| | | if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
| | | {
|
| | | // 往上面有连接且有触点连接,才使用ORS
|
| | | 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)
|
| | | //{
|
| | | // // 往上面有连接且有触点连接,才使用ORS
|
| | | // 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;
|
| | | //}
|
| | | //左上是否有链接
|
| | | int nLeftUpCon = 0;
|
| | | if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
| | |
| | |
|
| | | if (nRightCon == 1)
|
| | | {
|
| | | //s1.Format(_T(">>>> Go %d : %d , level %d "), nLineTop, j + nNextX, nLevel);
|
| | | //DbgLog(s1);
|
| | | //CString ProgSec;
|
| | | //int theSteps = 0;
|
| | | //stProgSection thisprogsec;
|
| | | 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);
|
| | | //
|
| | | int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel, thisprogsec, ProgSec, theSteps);
|
| | |
|
| | | //sProgSec += ProgSec;
|
| | | //nSteps += theSteps;
|
| | | //progsec += thisprogsec;
|
| | | //s1.Format(_T("<<<< Re %d : %d , Result %d "), nLineTop, j + nNextX, r);
|
| | | //DbgLog(s1);
|
| | | sProgSec += ProgSec;
|
| | | nSteps += theSteps;
|
| | | progsec += thisprogsec;
|
| | | s1.Format(_T("<<<< Re %d : %d , Result %d "), nLineTop, j + nNextX, 0);
|
| | | DbgLog(s1);
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | {
|
| | | if (firstCoil && nType != typeLine1 && nType != typeLine2)
|
| | | {
|
| | | //先看往上面有没有连接
|
| | | if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
| | | {
|
| | | // 往上面有连接且有触点连接,才使用OR
|
| | | s1.Format(_T("%d %d OR %s"), nCurPosY, nCurPosX, sCellName);
|
| | | sProgSec.AppendFormat(_T("OR %s\r\n"), sCellName);
|
| | | theprog.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;
|
| | |
| | | }
|
| | | 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 根据单元格类型转换为指令和prog
|
| | |
|
| | | if (nType == typeNO)
|
| | | {
|
| | | if (firstCoil && nType != typeLine1 && nType != typeLine2)
|
| | | {
|
| | | //先看往上面有没有连接
|
| | | if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
| | | {
|
| | | // 往上面有连接且有触点连接,才使用OR
|
| | | 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;
|
| | | }
|
| | |
|
| | | #pragma endregion
|
| | | }
|
| | | */
|
| | |
|
| | | /// <summary>
|
| | | /// 全部图形校验
|