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.h |  386 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 380 insertions(+), 6 deletions(-)

diff --git a/MTerm1/MTerm1View.h b/MTerm1/MTerm1View.h
index cf0c9b4..773acd5 100644
--- a/MTerm1/MTerm1View.h
+++ b/MTerm1/MTerm1View.h
@@ -1,11 +1,15 @@
 锘�
-// MTerm1View.h: CMTerm1View 绫荤殑鎺ュ彛
+// MultiTerminal2View.h: CMTerm1View 绫荤殑鎺ュ彛
 //
 
 #pragma once
 
+#include <memory>
+#include <vector>
+#include <stack>
 
-class CMTerm1View : public CView
+#include "MTerm1Doc.h"
+class CMTerm1View : public CScrollView
 {
 protected: // 浠呬粠搴忓垪鍖栧垱寤�
 	CMTerm1View() noexcept;
@@ -13,16 +17,330 @@
 
 // 鐗规��
 public:
+	CMFCStatusBar * m_pStatusBar;
 	CMTerm1Doc* GetDocument() const;
+
+	//浠庢枃妗h幏鍙栫▼搴�
+
+	//鏂囨。鍙樺姩閫氱煡
+	enum enCellType{
+		typeNone=0,
+		typeLine1=1, //妯嚎
+		typeLine2,	 //绔栫嚎
+		typeLine3,
+		typeLine4,
+		typeLine5,
+		typeLine6,
+		typeLine7,
+		typeLine8,
+		typeLine9,
+		typeLine10,
+		typeLine11,
+
+		typeNO=12,
+		typeNC=13,
+		typePP=14,  //涓婂崌娌�
+		typePN=15,  //涓嬮檷娌�
+		typeNOT=16,
+		typeDF = 17,
+
+		typeDF_ = 18, 
+		typeOUT=19,
+		typeSET=20,
+		typeRESET=21,
+
+		typeCMP,
+		typeExt1,	//23 0x17	//琚墠闈㈢殑鎸囦护鍗犵敤鐨勭┖闂�
+		typeExt2,
+		typeExt3,
+		typeExt4,
+
+		typeTM = 30,		//瀹氭椂鍣�
+		typeFN1 = 40,		//1涓弬鏁扮殑鍑芥暟
+		typeFN2 = 50,		//2涓弬鏁扮殑鍑芥暟
+		typeFN3 = 60,		//3涓弬鏁扮殑鍑芥暟
+		typeFN4 = 70,		//3涓弬鏁扮殑鍑芥暟
+
+		typeCoil=99,
+		typeEND = 255,
+
+	};
+	struct stCell
+	{
+		int nType;				//鍗曞厓绫诲瀷銆�
+		int nOpType;			//鎸囦护鐮併��
+		int nProgStep;			//瀵瑰簲绋嬪簭鐨勬鏁�
+		int bFocused = 0;		//鐑偣閫変腑
+		int bSelected = 0;		//閫変腑
+		int bEditing = 0;		//缂栬緫涓�
+		int bModified = 0;		//琚慨鏀逛簡
+
+		int bErrFocus = 0;		//閿欒鐑偣
+
+		int bLeftLineUp = 0;	//宸︿晶鍚戜笂绔栫嚎
+		int bLeftLineDn = 0;	//宸︿晶鍚戜笅绔栫嚎
+		int nStat = 0;			//褰撳墠鐘舵��//   鐩戞帶鏃舵牴鎹姸鎬侊紝鏄剧ず鏁板�兼垨鑹插潡
+		int nTrace = 0;			//褰撳墠璺熻釜鐘舵��
+//		int nDataWidth = 0;
+		int nDataType=0;		//鍙傛暟鏁版嵁绫诲瀷
+		int nDataAddr=0;		//鍙傛暟鏁版嵁鍦板潃/鍊�
+		CString sParam;			//鍙傛暟鍚�
+		CString sCoilName;		//绾垮湀鍚�
+		void clear() { 
+			nType = 0; bFocused = 0; bSelected = 0; bEditing = 0; bModified = 0;
+			bLeftLineUp = 0; bLeftLineDn = 0; nStat = 0;
+			nDataType = 0; nDataAddr = 0;
+			sParam.Empty(); sCoilName.Empty();
+		}
+	};
+	stCell Cells[2000][16] = { 0 };
+	struct stProgSection
+	{
+		int Prefix = 0;
+		int Suffix = 0;
+		int bModifyVal = 1;
+		std::vector <CMTerm1Doc::stProg> Progs;
+		int Append(CMTerm1Doc::stProg prog) {
+			Progs.push_back(prog);
+			return 0;
+		};
+		int Append(struct stProgSection progsec) {
+			int n = (int)progsec.Progs.size();
+			for (int i = 0; i < n; i++) {
+				Progs.push_back(progsec.Progs[i]);
+			}
+			return 0;
+		};
+		int operator+=(const struct stProgSection progsec) {
+			Append(progsec);
+			bModifyVal = bModifyVal | progsec.bModifyVal;
+			return 0;
+		};
+
+		int Insert(CMTerm1Doc::stProg prog) {
+			Progs.insert(Progs.begin(), prog);
+			return 0;
+		}
+		CString ToText() {
+			CString s1;
+			CStringA s2A;
+			int n = (int)Progs.size();
+			s2A.Format(" +%d ", Prefix);
+			for (int k = 0; k < n; k++) {
+				CMTerm1Doc::stProg& prog0 = Progs.at(k);
+				s2A = prog0.ToText();
+				s1 += s2A;
+			}
+			return s1;
+		}
+		int reduce()
+		{
+			if (Prefix > 0) {
+				int level = 0;
+				int j = Progs.size();
+				for (int i = 0; i < j; i++) {
+					int nOp = Progs[i].nOpType1;
+					if (nOp == OP_ST || nOp == OP_ST_) {
+						level += 1;;
+					}
+					else if (nOp == OP_ORS) {
+						level -= 1;
+					}
+					if (nOp == OP_ANS) {
+						level -= 1;
+						if (level == 0) {
+							Progs.erase(Progs.begin() + i);
+							Prefix -= 1;
+							break;
+						}
+					}
+				}
+
+			}
+			return Prefix;
+		}
+	};
+	std::pair<int, int> popsPoint[100];
+
+	struct arc;
+	struct node {
+		int nId;
+		int bEnable;
+		int nType;
+		char input;
+		char result;
+		char indeep;		//杈撳叆 娣卞害
+		char outdeep;		//杈撳嚭 娣卞害
+
+		int indegree;		//鍏ュ害
+		int outdegree;		//鍑哄害 
+		int parameter1;
+		int parameter2;
+		struct arc *firstIn;
+		struct arc *firstOut;
+		int nCellX;
+		int nCellY;
+		CString Op;
+		CString CoilName;
+		int InProcCount;
+		int OutProcCount;
+		int OutProcAllDone;
+		stProgSection prog1;
+
+	};
+	struct arc {
+		int nId;
+		int bEnable;
+		int tailNode;
+		int headNode;
+		int hlinkId;
+		int tlinkId;
+		struct node* tailvex;
+		struct node* headvex;
+		struct arc* hlink;
+		struct arc* tlink;
+		//stProgSection prog1;
+	};
+
+	node nodes[1000];
+	arc arcs[1000];
+
+	node* rootnode;
+
+	int nNodeCount = 0;
+	int nArcCount = 0;
+	int AddNode(int nType, int CellX,int CellY, CString sCoilName, int PrevNode=0);
+	int AddArc(int nNodeID1, int nNodeID2);
+	int RemoveNode(int nIndex);
+	int RemoveArc(int nIndex);
+
+	int MergeNode(int nNodeId1, int nNodeId2);
+	int MergeVPSubSerialNodes(int nNodeId);
+	int MergeParallelNodeWithinVP(int nVPNodeId1, int nVPNodeId2);
+	
+
+	int FindVPNode(int x, int y,int endy);
+
+	int TransLDSToProg();
+	int TransLDSToProgAOV();
+
+	int ScanAOV1(int nNodeid);
+	int ScanVPAOV(int nVPNodeId1, int nVPNodeId2);
+
+	int MergeVPSerialNodes(int nNodeId);
+//	int ScanAOV2(int nNodeid);
+
+	int nPSHS = -1;
+	bool firstCoil = true;//鏈绗竴涓崟鍏冩牸
+
+	bool isPops = false;
+	int m_nTotalRow=0;
+	bool m_bMonitoring = false;		//鐩戞帶涓�
+	bool m_bShowComments = true;	//鏄剧ず娉ㄩ噴
+
+	bool m_bEditing = false;
+
+	int m_TopMargin = 0;		
+	int m_LeftMargin = 54;		//宸︿晶杈硅窛
+	int m_CellPerLine = 16;		//姣忚鍗曞厓鏁�
+ 	int m_CellWidth = 64;		//鍗曞厓瀹藉害
+	int m_CellHeight = 28;		//鍗曞厓楂樺害
+	int m_CommentHeight = 32;	//娉ㄩ噴楂樺害
+
+	int m_LinePosY = 20;		//鍏冧欢鏄剧ず浣嶇疆
+
+ 	int m_FocusRow = 0; 			//鐒︾偣琛屽垪浣嶇疆
+	int m_FocusCol = 0;
+
+	int m_oldFocusRow = 0;
+	int m_oldFocusCol = 0;
+	int m_nCurProgStep = 0;
+	int m_TextFontSize=13;
+	int m_nAnnoFontSize=12;
+
+	int m_bModified = 1;
+
+	COLORREF BkColor = RGB(255,255,255);		//Cell鑳屾櫙棰滆壊
+	COLORREF BkEditColor = RGB(192, 192, 192);	//Editing Cell 鑳屾櫙棰滆壊
+
+	COLORREF TextColor =RGB(0,0,0);
+	COLORREF FocusColor = RGB(128,255,128);
+	COLORREF SelectedColor;
+	COLORREF EditColor;
+	COLORREF AnnoColor = RGB(0,0,255);
+	COLORREF BlockAnnoColor;
+	COLORREF MonCoilColor= RGB(0,255,255);
+	COLORREF MonTextColor = RGB(0, 128, 255);
+
+	COLORREF TraceBkColor = RGB(204,204,204);
+	COLORREF TraceColor = RGB(0,255,255);
+	COLORREF ForceIOColor;
+
+	COLORREF OnlineColor = RGB(0, 255, 255);
+	COLORREF ProgColor = RGB(0, 255, 0);
+	COLORREF RunningColor = RGB(0, 255, 0);
+	COLORREF MonitorColor = RGB(0, 255, 255);
+	COLORREF AddressColor = RGB(0, 255, 255);
+
+	CFont TextFont;
+//	CFont * pOldFont;
+	CFont MonTextFont;
+	CFont AnnoFont;
+
+
+	enum StatusBarIndicators {
+		idxMachineType = 0,
+		idxProgPos = 1,
+		idxOnline = 2,
+		idxRunning = 3,
+		idxMonitor = 4,
+		idxAddress = 5,
+		idxInfoDisp = 6,
+	};
+
+//	CBrush brBkColor(BkColor);
+
 
 // 鎿嶄綔
 public:
+	void DrawFocusRect(CDC* pDC);
+	int DrawLeftRightLine(CDC* pDC, int x0, int y0, int size1=16, int size2=12);
+	void DrawRelay(CDC* pDC, int x0, int y0);
+	int DrawBracket(CDC* pDC, int x0, int y0, int sizex, int sty=0, int sizey = 24);
+	int DrawAngleBracket(CDC* pDC, int x0, int y0, int sizex, int size2);
+	void DrawOT(CDC* pDC, int x0, int y0);
+
+	int DrawCellStat1(CDC * pDC, int x1, int y1, int sizex, int sizey, int nStat);
+	int DrawCellStat2(CDC* pDC, int x1, int y1, int sizex, int sizey, int nStat);
+	int DrawCellText1(CDC* pDC, CString sText, int x1, int y1, int sizex, int sizey, int nFormat=0);
+	int DrawCellText2(CDC* pDC, CString sText, int x1, int y1, int sizex, int sizey, int nFormat, int nTextColor);
+	int DrawCellAnno(CDC * pDC, int nRow, int nCol, CString sAnno);
+
+	void DrawCell(CDC* pDC, int nRow, int nCol);
+	int TransProgToLDS();
+
+	/// <summary>
+	/// Flag::鏄惁闇�瑕侀噸缁樿鍥撅紝榛樿涓�1=>true
+	/// </summary>
+	int needReDraw = 1;
+
+	int DoReDraw();
+	int DrawLDSGraph(CDC* pDC);
+
+	int ScrollToCell(int nRow, int nCol);
+
+	int ScrollCellIntoView(int nRow, int nCol);
+	int isCellInView(int nRow, int nCol);
+	int CellFocusChg(int nRow, int nCol);
+
+	std::pair<int, CString> CMTerm1View::LDSCheckRule();
 
 // 閲嶅啓
 public:
 	virtual void OnDraw(CDC* pDC);  // 閲嶅啓浠ョ粯鍒惰瑙嗗浘
 	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
 protected:
+	virtual void OnInitialUpdate(); // 鏋勯�犲悗绗竴娆¤皟鐢�
 	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
 	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
 	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
@@ -33,19 +351,75 @@
 #ifdef _DEBUG
 	virtual void AssertValid() const;
 	virtual void Dump(CDumpContext& dc) const;
+
 #endif
 
 protected:
 
 // 鐢熸垚鐨勬秷鎭槧灏勫嚱鏁�
 protected:
-	afx_msg void OnFilePrintPreview();
-	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
-	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
 	DECLARE_MESSAGE_MAP()
+public:
+	afx_msg void OnMonitor();
+	afx_msg void OnUpdateMonitor(CCmdUI *pCmdUI);
+	afx_msg void OnProgConvert();
+	afx_msg void OnUpdateProgConvert(CCmdUI *pCmdUI);
+	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+	afx_msg void OnRectSelect();
+	afx_msg void OnUpdateRectSelect(CCmdUI *pCmdUI);
+	afx_msg void OnTextFirst();
+	afx_msg void OnUpdateTextFirst(CCmdUI *pCmdUI);
+	afx_msg void OnInsertBlankLine();
+	afx_msg void OnUpdateInsertBlankLine(CCmdUI *pCmdUI);
+	afx_msg void OnDeleteBlankLine();
+	afx_msg void OnUpdateDeleteBlankLine(CCmdUI *pCmdUI);
+	afx_msg void OnDisplayComments();
+	afx_msg void OnUpdateDisplayComments(CCmdUI *pCmdUI);
+
+	afx_msg void OnUpdateMachineType(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateProgramPos(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateConnectivity(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateRunStatus(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateMonitorStatus(CCmdUI *pCmdUI);
+	afx_msg void OnUpdateTargetAddress(CCmdUI *pCmdUI);
+
+	int UpdateStatusBar(int nIndex=-1);
+
+	virtual void OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/);
+	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
+	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
+	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
+	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
+	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
+
+	afx_msg void OnIndicatorMonitorStatus();
+	afx_msg void OnUpdateIndicators(CCmdUI *pCmdUI);
+
+	afx_msg void OnUpdateIndicatorMonitorStatus(CCmdUI *pCmdUI);
+	afx_msg void OnTimer(UINT_PTR nIDEvent);
+	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
+	afx_msg void OnSize(UINT nType, int cx, int cy);
+	virtual BOOL OnScrollBy(CSize sizeScroll, BOOL bDoScroll = TRUE);
+
+	afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);
+	afx_msg void OnProgCancelEdit();
+	afx_msg void OnUpdateProgCancelEdit(CCmdUI *pCmdUI);
+	afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
+
+
+
+	afx_msg void OnInputIoComment();
+	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
+	int ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX, int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps);
+	int ScanLDSCells2(int nStartLine, int nEndLine, int nPosY, int nPosX, int nSizeX, int nLevel, stProgSection& progsec, CString& sProgSec, int& nSteps);
+	int CMTerm1View::Translate2Prog(
+		int nType, int nCurPosY, int nCurPosX, CString sCellName,
+		stProgSection& progsec, CString& sProgSec, int& nSteps);
+	void SetCellToView(stCell cell1, int flag = 0);//modify0919zxd
+	
 };
 
-#ifndef _DEBUG  // MTerm1View.cpp 涓殑璋冭瘯鐗堟湰
+#ifndef _DEBUG  // MultiTerminal2View.cpp 涓殑璋冭瘯鐗堟湰
 inline CMTerm1Doc* CMTerm1View::GetDocument() const
    { return reinterpret_cast<CMTerm1Doc*>(m_pDocument); }
 #endif

--
Gitblit v1.9.1