From aac3b319965967f465881f3a8961904d57b6f337 Mon Sep 17 00:00:00 2001
From: zxd <zxdvslxy@gmail.com>
Date: 星期四, 28 九月 2023 17:01:41 +0800
Subject: [PATCH] 节前提交,包含部分图码的转换,提出单独函数专做转换

---
 MTerm1/MTerm1View.cpp |  387 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 326 insertions(+), 61 deletions(-)

diff --git a/MTerm1/MTerm1View.cpp b/MTerm1/MTerm1View.cpp
index 86b37a3..4abbea4 100644
--- a/MTerm1/MTerm1View.cpp
+++ b/MTerm1/MTerm1View.cpp
@@ -1944,7 +1944,7 @@
 		for (int j = 0; j < 16; j++) 
 		{
 			Cells[i][j].clear();
-			s1.Format(_T("%d:%d"), i, j);
+ 			s1.Format(_T("%d:%d"), i, j);
 			Cells[i][j].sCoilName = s1;
 		}
 	}
@@ -2159,26 +2159,36 @@
 			case OP_OR:
 			case OP_OR_:
 				EndPt[nEndPts] = POINT{ cx,cy };
-				nEndPts++;
+ 				nEndPts++;
 				cx = StPts[nSts - 1].x;
 				nCurLine = cy + 1; //鍙﹁捣涓�琛�
 				{
 					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;
+					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++) {
+				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;
@@ -2186,22 +2196,22 @@
 				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++)
 				{
@@ -2210,6 +2220,7 @@
 				}
 				//鍏夋爣浣嶇疆, 鍓嶄竴缁撴潫鐐逛綅缃�
 				cy = EndPt[nEndPts - 1].y;
+
 				nEndPts--;
 
 				break;
@@ -2545,7 +2556,7 @@
 	{
 		int nRow = i;
 		int bConnected = 0;
-		for (int j = 0; j < m_CellPerLine; j++)		
+ 		for (int j = 0; j < m_CellPerLine; j++)		
 		{
 			int nCol = j;
 			if (Cells[nRow][nCol].bLeftLineDn) 
@@ -2566,7 +2577,7 @@
 		}
 	}
 
-	stProgSection allprogs;
+ 	stProgSection allprogs;
 	//姣忔鍗曠嫭澶勭悊
 	for (int i = 0; i < nDivCount; i++)	
 	{
@@ -2713,16 +2724,16 @@
 /// </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;//姝ラ暱
@@ -2750,21 +2761,21 @@
 			|| 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;
+			//	//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)
@@ -2843,20 +2854,20 @@
 
 				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
 				{
@@ -2944,9 +2955,20 @@
 		{
 			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;
+				//鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺�
+				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);
+					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;
@@ -3161,7 +3183,250 @@
 
 	}
 	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
+
+	 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;
+	 }
+
+#pragma endregion
 }
+*/
 
 /// <summary>
 /// 鍏ㄩ儴鍥惧舰鏍¢獙

--
Gitblit v1.9.1