// MultiTerminal2View.h: CMTerm1View 类的接口 // #pragma once #include #include #include #include "MTerm1Doc.h" class CMTerm1View : public CScrollView { protected: // 仅从序列化创建 CMTerm1View() noexcept; DECLARE_DYNCREATE(CMTerm1View) // 特性 public: CMFCStatusBar * m_pStatusBar; CMTerm1Doc* GetDocument() const; //从文档获取程序 //文档变动通知 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 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 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(); /// /// Flag::是否需要重绘视图,默认为1=>true /// 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 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); // 实现 public: virtual ~CMTerm1View(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // 生成的消息映射函数 protected: 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 // MultiTerminal2View.cpp 中的调试版本 inline CMTerm1Doc* CMTerm1View::GetDocument() const { return reinterpret_cast(m_pDocument); } #endif