From df03213660361b1c771f0a3f21b6ddaeaef7763a Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期二, 05 九月 2023 11:44:52 +0800
Subject: [PATCH] add ladder to prog 1

---
 MTerm1/MTerm1View.cpp |  109 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 93 insertions(+), 16 deletions(-)

diff --git a/MTerm1/MTerm1View.cpp b/MTerm1/MTerm1View.cpp
index bd3a8bd..a34e24c 100644
--- a/MTerm1/MTerm1View.cpp
+++ b/MTerm1/MTerm1View.cpp
@@ -17,6 +17,7 @@
 #include "DialogSetData.h"
 #include "DialogIoComment.h"
 #include "KDefine.h"
+#include "MainFrm.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -344,24 +345,31 @@
 			}
 		}
 		// 鑾峰彇鏁版嵁  骞舵樉绀哄悇鍗曞厓
+
 		for (int j = 0; j < m_CellPerLine; j++) {
 			nCol = j;
 			nDataType = Cells[nRow][nCol].nDataType;
 			nDataAddr = Cells[nRow][nCol].nDataAddr;
-			if ((nDataType&TYPEDATA) == TYPEDATA) {
-				nStat = pDoc->GetVarData(nDataType, nDataAddr);
+			if (m_bMonitoring) {
+				if ((nDataType & TYPEDATA) == TYPEDATA) {
+					nStat = pDoc->GetVarData(nDataType, nDataAddr);
+				}
+				else {
+					nStat = pDoc->GetCoilValue(nDataType, nDataAddr);
+				}
+				Cells[nRow][nCol].nStat = nStat;
+				nType = Cells[nRow][nCol].nType;
+				if (nType == typeNO || nType == typeNC || nType == typeCMP || nType == typeTM)
+				{
+					int nProgStep = Cells[nRow][nCol].nProgStep;
+					int nBinProgStep = pDoc->Progs[nProgStep].nBinStep;
+					Cells[nRow][nCol].nTrace = pDoc->ProgTrace[nBinProgStep];
+				}
 			}
 			else {
-				nStat = pDoc->GetCoilValue(nDataType, nDataAddr);
+				Cells[nRow][nCol].nStat = 0; Cells[nRow][nCol].nTrace = 0;
 			}
-			Cells[nRow][nCol].nStat = nStat;
-			nType = Cells[nRow][nCol].nType;
-			if (nType == typeNO || nType == typeNC || nType == typeCMP || nType == typeTM)
-			{
-				int nProgStep = Cells[nRow][nCol].nProgStep;
-				int nBinProgStep = pDoc->Progs[nProgStep].nBinStep;
-				Cells[nRow][nCol].nTrace = pDoc->ProgTrace[nBinProgStep];
-			}
+
 			DrawCell(pDC, i, j);
 		}
 
@@ -1130,6 +1138,23 @@
 
 	CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
 }
+int CMTerm1View::CellFocusChg(int nRow, int nCol)
+{
+	CString s1;
+	stCell & thecell = Cells[nRow][nCol];
+	s1.Format(_T("Cell %d %d Type %02X \r\n"), nRow, nCol, thecell.nType);
+	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);
+
+	auto p1 = (CMainFrame*)AfxGetMainWnd();
+	auto p2 = p1->GetInputWnd();
+	p2->SetCurCellPos(nRow,nCol,thecell);
+
+
+
+	return 0;
+}
 
 void CMTerm1View::OnLButtonDown(UINT nFlags, CPoint point)
 {
@@ -1156,6 +1181,7 @@
 	}
 
 	//	DrawFocusRect();
+	CellFocusChg(nRow, nCol);
 	GetDocument()->UpdateAllViews(this, m_FocusCol);
 	needReDraw = 1;
 	this->RedrawWindow();
@@ -1470,15 +1496,19 @@
 	return -1;
 }
 
-void CMTerm1View::GetIncToView(stCell cell1)               //**************************************************************************************************//
+void CMTerm1View::SetCellToView(stCell cell1)               //**************************************************************************************************//
 {
 
-
 	Cells[m_FocusRow][m_FocusCol] = cell1;
-
 	m_bModified = 1;
 	needReDraw = 1;
 	m_FocusCol += 1;
+	Cells[m_FocusRow][0].bEditing = 1;
+
+	if (m_nTotalRow < m_FocusRow + 1) {
+		m_nTotalRow = m_FocusRow + 1;
+	}
+
 	if (m_FocusCol >= 16) 
 	{ m_FocusCol = 0;m_FocusRow += 1; }
 	
@@ -2442,6 +2472,8 @@
 	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);
@@ -2449,8 +2481,10 @@
 		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;
 }
 
@@ -2462,25 +2496,37 @@
 	int nNextX = 1;
 	nCurPosY = nPosY;
 	nCurPosX = nPosX;
-
+	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;
-
+		CStringA sCellNameA;
+		sCellNameA = sCellName;
 		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;
+				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);
 			}
 			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;
@@ -2492,6 +2538,11 @@
 				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);
 
 			}
@@ -2500,6 +2551,11 @@
 				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);
@@ -2554,6 +2610,11 @@
 			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;
@@ -2563,6 +2624,11 @@
 			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;
@@ -2572,6 +2638,11 @@
 			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;
@@ -2580,6 +2651,7 @@
 			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;
@@ -2589,6 +2661,11 @@
 			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;

--
Gitblit v1.9.1