From 0a20f73829d9d53e060927f23c2777f10347ac65 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期三, 29 十二月 2021 13:43:59 +0800
Subject: [PATCH] add Klink Dll project

---
 MTerm2/MTerm2View.cpp |  123 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 113 insertions(+), 10 deletions(-)

diff --git a/MTerm2/MTerm2View.cpp b/MTerm2/MTerm2View.cpp
index 54b99ed..067a778 100644
--- a/MTerm2/MTerm2View.cpp
+++ b/MTerm2/MTerm2View.cpp
@@ -16,7 +16,7 @@
 #include "DialogSetCoil.h"
 #include "DialogSetData.h"
 #include "DialogIoComment.h"
-
+#include "KDefine.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -209,6 +209,34 @@
 	return 0;
 }
 
+int CMTerm2View::ScrollToCell(int nRow, int nCol)
+{
+	int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
+
+	CSize sizeTotal;
+	// TODO: 璁$畻姝よ鍥剧殑鍚堣澶у皬
+	sizeTotal.cx = m_LeftMargin + m_CellWidth * m_CellPerLine + m_CellWidth * 2;
+	sizeTotal.cy = m_TopMargin + CellTotalHeight * (m_nTotalRow );
+	CSize sizeSb;
+	GetScrollBarSizes(sizeSb);
+	POINT pt1;
+	pt1.x = 0;
+	pt1.y = nRow * CellTotalHeight;
+	ScrollToPosition(pt1);
+	return 0;
+}
+
+int CMTerm2View::ScrollCellIntoView(int nRow, int nCol)
+{
+	int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
+	return 0;
+}
+
+int CMTerm2View::isCellInView(int nRow, int nCol)
+{
+	int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
+	return 0;
+}
 
 int CMTerm2View::DrawLDSGraph(CDC* pDC)
 {
@@ -2265,6 +2293,7 @@
 int CMTerm2View::TransLDSToProg()
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	CMTerm2Doc * pDoc = GetDocument();
 	CString s1;
 	s1.Format(_T("Trans LDS to PRrog"));
 	DbgLog(s1);
@@ -2292,6 +2321,7 @@
 			nDivCount++;
 		}
 	}
+	stProgSection allprogs;
 	//姣忔鍗曠嫭澶勭悊
 	for (int i = 0; i < nDivCount; i++)	{
 		int nStartLine, nEndLine;
@@ -2342,25 +2372,54 @@
 		nCurPosX = 0;
 		CString sProg;
 		int nAllSteps=0;
+		stProgSection Progsec;
 		for (int i = nStartLine; i <= nEndLine; i++){
-			CString ProgSec;
+			CString sProgSec;
 			int nSteps = 0;;
 			nCurPosY = i;
+			stProgSection thisprogsec;
 			if (Cells[i][0].nType)
-			ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, ProgSec,nSteps);
-			sProg += ProgSec;
+			ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec,nSteps);
+			sProg += sProgSec;
 			nAllSteps += nSteps;
+			Progsec += thisprogsec;
 		}
 		DbgLog(_T("\r\n")+ sProg);
+		int n = Progsec.Progs.size();
+		s1.Format(_T("progSec steps %d "), n);
+		DbgLog(s1);
+		for (int i = 0; i < n; i++) {
+			int optype = Progsec.Progs[i].nOpType1;
+			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);
+			DbgLog(s1);
+		}
+		allprogs += Progsec;
 	}
 	//杈撳嚭绋嬪簭
-
-
-
+	int n=allprogs.Progs.size();
+	s1.Format(_T("all prog steps %d "), n);
+	DbgLog(s1);
+	for (int i = 0; i < n; i++)	{
+		int optype=allprogs.Progs[i].nOpType1;
+		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);
+		DbgLog(s1);
+	}
 	return 0;
 }
 
-int CMTerm2View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, CString & sProgSec, int &nSteps)
+int CMTerm2View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps)
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
 	CString s1;
@@ -2374,14 +2433,20 @@
 		//鍏堝鐞嗗綋鍓嶅崟鍏�;
 		int nType = Cells[nCurPosY][nCurPosX].nType;
 		CString sCellName = Cells[nCurPosY][nCurPosX].sCoilName;
+		CMTerm2Doc::stProg theprog;
+
 		if (nType == typeNO) {
 			if (j==0) {
 				s1.Format(_T("%d %d ST %s"), nCurPosY, nCurPosX,sCellName);
 				sProgSec.AppendFormat(_T("ST %s\r\n"),sCellName);
+				theprog.nOpType1 = OP_ST;
+				progsec.Append(theprog);
 			}
 			else {
 				s1.Format(_T("%d %d AN %s"), nCurPosY, nCurPosX, sCellName);
 				sProgSec.AppendFormat(_T("NO %s\r\n"), sCellName);
+				theprog.nOpType1 = OP_AN;
+				progsec.Append(theprog);
 			}
 			nSteps += 1;
 			DbgLog(s1);
@@ -2391,11 +2456,16 @@
 			if (j == 0) {
 				s1.Format(_T("%d %d ST/ %s"), nCurPosY, nCurPosX, sCellName);
 				sProgSec.AppendFormat(_T("ST/ %s\r\n"), sCellName);
+				theprog.nOpType1 = OP_ST_;
+				progsec.Append(theprog);
+
 			}
 			else
 			{
 				s1.Format(_T("%d %d AN/ %s"), nCurPosY, nCurPosX, sCellName);
 				sProgSec.AppendFormat(_T("AN/ %s\r\n"), sCellName);
+				theprog.nOpType1 = OP_AN_;
+				progsec.Append(theprog);
 			}
 			DbgLog(s1);
 			nSteps += 1;
@@ -2404,6 +2474,7 @@
 		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;
@@ -2411,6 +2482,7 @@
 		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;
@@ -2419,6 +2491,8 @@
 			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 
@@ -2426,6 +2500,8 @@
 			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 
@@ -2433,6 +2509,8 @@
 			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 
@@ -2440,6 +2518,8 @@
 			s1.Format(_T("%d %d OUT %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("OUT %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_OUT;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2447,6 +2527,8 @@
 			s1.Format(_T("%d %d SET %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("SET %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_SET;
+			progsec.Append(theprog);
 			nSteps += 1;
 			nNextX =  1;
 		}else 
@@ -2454,12 +2536,16 @@
 			s1.Format(_T("%d %d RESET %s"), nCurPosY, nCurPosX, sCellName);
 			DbgLog(s1);
 			sProgSec.AppendFormat(_T("RESET %s\r\n"), sCellName);
+			theprog.nOpType1 = OP_RESET;
+			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;
+			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;
@@ -2467,6 +2553,8 @@
 		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;
+			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;
@@ -2474,6 +2562,8 @@
 		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;
@@ -2481,6 +2571,8 @@
 		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;
@@ -2488,6 +2580,8 @@
 		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;
@@ -2495,12 +2589,15 @@
 			nNextX =  1;
 			//continue;
 		}
+
 		if (j + nNextX >= m_CellPerLine) continue;
 		if (Cells[nCurPosY][j + nNextX].bLeftLineUp || Cells[nCurPosY][j + nNextX].bLeftLineDn) {	// 鍙戠幇绔栫嚎
 			//鍏堢湅寰�涓婇潰鏈夋病鏈夎繛鎺�
 			if (Cells[nCurPosY][j + nNextX].bLeftLineUp) { // 寰�涓婇潰鏈夎繛鎺�
 				s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX);
 				DbgLog(s1);
+				theprog.nOpType1 = OP_ORS;
+				progsec.Append(theprog);
 				sProgSec.AppendFormat(_T("ORS \r\n"));
 				nSteps += 1;
 				nLevel -= 1;
@@ -2524,6 +2621,8 @@
 					if ( nPosX >0 || nLevel > 0) {
 					s1.Format(_T("%d %d ANS "), nCurPosY, nCurPosX);
 					DbgLog(s1);
+					theprog.nOpType1 = OP_ANS;
+					progsec.Append(theprog);
 					sProgSec.AppendFormat(_T("ANS \r\n"));
 					nSteps += 1;
 					nLevel -= 1;
@@ -2552,9 +2651,11 @@
 					DbgLog(s1);
 					CString ProgSec;
 					int theSteps = 0;
-					int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel,ProgSec,theSteps);
+					stProgSection thisprogsec;
+					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);
 				}
@@ -2576,9 +2677,11 @@
 							CString ProgSec;
 							int theSteps = 0;
 							nLevel += 1;
-							res[nRightCount] = ScanLDSCells(nStartLine, nEndLine, k, j + nNextX, nLevel ,ProgSecs[nRightCount],theSteps);
+							stProgSection thisprogsec;
+							res[nRightCount] = ScanLDSCells(nStartLine, nEndLine, k, j + nNextX, nLevel ,thisprogsec,ProgSecs[nRightCount],theSteps);
 							nLastResult = res[nRightCount];
 							nSteps += theSteps;
+							progsec += thisprogsec;
 							//if (res[nRightCount] > 0) nLevel += 1;
 							sProgSec += ProgSec;
 							s1.Format(_T(" <<< Re %d : %d , Result %d Steps %d Last %d"), k, j + nNextX, res[nRightCount],theSteps,nLastSteps);

--
Gitblit v1.9.1