| | |
| | |
|
| | | IMPLEMENT_DYNCREATE(CMTerm1View, CScrollView)
|
| | |
|
| | | /// <summary>
|
| | | /// 消息映射
|
| | | /// 是 MFC 中用于将 Windows 消息(如鼠标点击、按键等)映射到成员函数的机制。
|
| | | /// </summary>
|
| | | BEGIN_MESSAGE_MAP(CMTerm1View, CScrollView)
|
| | | // 标准打印命令
|
| | | ON_COMMAND(ID_FILE_PRINT, &CScrollView::OnFilePrint)
|
| | |
| | | return CScrollView::PreCreateWindow(cs);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// MFC 中的一个函数,它在视图首次显示之前被调用
|
| | | /// </summary>
|
| | | void CMTerm1View::OnInitialUpdate()
|
| | | {
|
| | | CScrollView::OnInitialUpdate();
|
| | |
|
| | | //创建了三种不同的字体
|
| | | TextFont.CreateFont(13, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, _T("宋体"));
|
| | | MonTextFont.CreateFont(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, _T("宋体"));
|
| | | AnnoFont.CreateFont(12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, _T("宋体"));
|
| | | |
| | | //获取了状态栏的引用并存储在 m_pStatusBar 成员变量中
|
| | | m_pStatusBar = ((CChildFrame *)GetParentFrame())->GetStatusBar();
|
| | |
|
| | | CSize sizeTotal;
|
| | | // TODO: 计算此视图的合计大小
|
| | | sizeTotal.cx = m_LeftMargin + m_CellWidth* m_CellPerLine + m_CellWidth *2;
|
| | | sizeTotal.cy = 2000;
|
| | | //设置了滚动大小
|
| | | SetScrollSizes(MM_TEXT, sizeTotal);
|
| | | CString s1;
|
| | |
|
| | | CString s1;//没啥用
|
| | |
|
| | | //设置了两个定时器,一个间隔为50毫秒,另一个为10毫秒。
|
| | | SetTimer(1, 50,NULL);
|
| | | SetTimer(2, 10, NULL);
|
| | |
|
| | |
| | | return;
|
| | |
|
| | | // TODO: 在此处为本机数据添加绘制代码
|
| | | CString s1;
|
| | | CString s1;//没啥用
|
| | |
|
| | | needReDraw = 1;
|
| | | DrawLDSGraph(pDC);
|
| | | needReDraw = 0;
|
| | | }
|
| | |
|
| | | // CMTerm1View 打印
|
| | |
|
| | | // CMTerm1View 打印,MFC 函数,用于准备打印。
|
| | | BOOL CMTerm1View::OnPreparePrinting(CPrintInfo* pInfo)
|
| | | {
|
| | | // 默认准备
|
| | | return DoPreparePrinting(pInfo);
|
| | | }
|
| | |
|
| | | // MFC 函数,用于在打印开始之前进行初始化。
|
| | | void CMTerm1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
| | | {
|
| | | // TODO: 添加额外的打印前进行的初始化过程
|
| | | }
|
| | |
|
| | | //MFC 函数,用于在打印结束后进行清理。
|
| | | void CMTerm1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
| | | {
|
| | | // TODO: 添加打印后进行的清理过程
|
| | |
| | | // CMTerm1View 诊断
|
| | |
|
| | | #ifdef _DEBUG
|
| | | //函数用于验证对象的有效性。
|
| | | void CMTerm1View::AssertValid() const
|
| | | {
|
| | | CScrollView::AssertValid();
|
| | | }
|
| | | }
|
| | |
|
| | | // 函数用于将对象的内容转储到指定的上下文。
|
| | | void CMTerm1View::Dump(CDumpContext& dc) const
|
| | | {
|
| | | CScrollView::Dump(dc);
|
| | | }
|
| | |
|
| | | //函数返回与此视图关联的文档对象。
|
| | | CMTerm1Doc* CMTerm1View::GetDocument() const // 非调试版本是内联的
|
| | | {
|
| | | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMTerm1Doc)));
|
| | |
| | | }
|
| | | #endif //_DEBUG
|
| | |
|
| | | //MFC 函数,用于处理视图的创建事件。
|
| | | int CMTerm1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
| | | {
|
| | | if (CScrollView::OnCreate(lpCreateStruct) == -1)
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 用于重新绘制视图。
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::DoReDraw()
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
|
| | | CPoint scroll1;
|
| | | scroll1 = this->GetScrollPosition();
|
| | |
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 滚动到特定单元格
|
| | | /// 函数内部计算了单元格的总高度,考虑了是否显示注释
|
| | | /// </summary>
|
| | | /// <param name="nRow"></param>
|
| | | /// <param name="nCol"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::ScrollToCell(int nRow, int nCol)
|
| | | {
|
| | | int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 滚动单元格进入视图(未完成的功能)
|
| | | /// </summary>
|
| | | /// <param name="nRow"></param>
|
| | | /// <param name="nCol"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::ScrollCellIntoView(int nRow, int nCol)
|
| | | {
|
| | | int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检查单元格是否在视图中(未完成的功能)
|
| | | /// </summary>
|
| | | /// <param name="nRow"></param>
|
| | | /// <param name="nCol"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::isCellInView(int nRow, int nCol)
|
| | | {
|
| | | int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 用于在视图中绘制图形的主要函数
|
| | | /// </summary>
|
| | | /// <param name="pDC">文档</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::DrawLDSGraph(CDC* pDC)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | | CString s1;
|
| | | CString s1;//没啥用
|
| | |
|
| | | //验证文档引用
|
| | | CMTerm1Doc* pDoc = GetDocument();
|
| | | ASSERT_VALID(pDoc);
|
| | | if (!pDoc) return false;
|
| | |
|
| | | if (m_bMonitoring) {
|
| | | pDoc->DoPLCMonitor();
|
| | | }
|
| | |
|
| | | int x1, y1, x2, y2;
|
| | | // RECT rect1;
|
| | | int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
| | |
|
| | | int nDataType, nDataAddr;
|
| | | int nStat;
|
| | | CBrush br0(BkColor);
|
| | | CBrush br01(BkEditColor);
|
| | | CBrush br0(BkColor);//背景颜色
|
| | | CBrush br01(BkEditColor);//编辑(选中)状态下的背景颜色
|
| | | int nRow, nCol;
|
| | | CRect rect0;
|
| | | this->GetClientRect(&rect0);
|
| | |
| | | CPoint scroll1;
|
| | | scroll1 = this->GetScrollPosition();
|
| | |
|
| | | int nFirstVisibleLine;
|
| | | int nLastVisibleLine;
|
| | |
|
| | | int nFirstVisibleLine;//用于确定可见行范围-起始位置
|
| | | int nLastVisibleLine;//用于确定可见行范围-终止位置
|
| | | //通过滚动位置和视图的高度计算上述两个值
|
| | | nFirstVisibleLine = (scroll1.y - m_TopMargin) / CellTotalHeight;
|
| | | nLastVisibleLine = (rect0.Height() + scroll1.y - m_TopMargin) / CellTotalHeight + 1;
|
| | | if (nFirstVisibleLine < 0) { nFirstVisibleLine = 0; }
|
| | | if (nLastVisibleLine < 0) { nLastVisibleLine = 0; }
|
| | | if (nFirstVisibleLine < 0) |
| | | {
|
| | | nFirstVisibleLine = 0; |
| | | }
|
| | | if (nLastVisibleLine < 0)
|
| | | { |
| | | nLastVisibleLine = 0; |
| | | }
|
| | |
|
| | | //选择字体
|
| | | CFont *pOldFont;
|
| | | pOldFont = (CFont *)pDC->SelectObject(&TextFont);
|
| | | |
| | |
|
| | | for (int i = nFirstVisibleLine; i < nLastVisibleLine && i < 1000; i++) {
|
| | | for (int i = nFirstVisibleLine; i < nLastVisibleLine && i < 1000; i++) |
| | | {
|
| | | // 画一行 单元
|
| | | nRow = i;
|
| | | int x0, y0;
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | void CMTerm1View::DrawFocusRect(CDC* pDC)
|
| | | {
|
| | | // DrawCell(pDC, m_oldFocusRow, m_oldFocusCol);
|
| | |
| | | // pDC->SelectObject(poldBrush);
|
| | | }
|
| | |
|
| | |
|
| | | int CMTerm1View::DrawLeftRightLine(CDC* pDC, int x0, int y0, int size1, int size2)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | pDC->LineTo(x2, y2);
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | void CMTerm1View::DrawOT(CDC* pDC, int x0, int y0)
|
| | | {
|
| | |
| | | pDC->LineTo(x2, y2);
|
| | | return 0;
|
| | | }
|
| | |
|
| | | int CMTerm1View::DrawAngleBracket(CDC* pDC, int x0, int y0, int size1, int size2)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | DrawLeftRightLine(pDC, x0, y0, size1, size2);
|
| | | // 左尖括号
|
| | | x1 = x0 + size1 + 6;
|
| | | y1 = y0 + m_LinePosY -6;
|
| | | y1 = y0 + m_LinePosY -6; |
| | | x2 = x1 -6;
|
| | | y2 = y1 +6 ;
|
| | | pDC->MoveTo(x1, y1);
|
| | |
| | | int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
| | |
|
| | | rect1.left = m_LeftMargin + 1 + m_CellWidth * nCol;
|
| | | rect1.right = rect1.left + m_CellWidth;
|
| | | rect1.right = rect1.left + m_CellWidth; |
| | | rect1.top = m_TopMargin + CellTotalHeight * nRow;
|
| | | rect1.bottom = rect1.top + CellTotalHeight;
|
| | |
|
| | |
| | |
|
| | | CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 单元格焦点变化*选中点变化
|
| | | /// </summary>
|
| | | /// <param name="nRow"></param>
|
| | | /// <param name="nCol"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::CellFocusChg(int nRow, int nCol)
|
| | | {
|
| | | CString s1;
|
| | |
| | | auto p1 = (CMainFrame*)AfxGetMainWnd();
|
| | | auto p2 = p1->GetInputWnd();
|
| | | p2->SetCurCellPos(nRow,nCol,thecell);
|
| | |
|
| | |
|
| | |
|
| | | return 0;
|
| | | }
|
| | |
| | | int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
| | | nRow = (ty - m_TopMargin) / CellTotalHeight;
|
| | | nCol = (tx - m_LeftMargin) / m_CellWidth;
|
| | | if (nRow < 0) { nRow = 0; }
|
| | | if (nCol < 0) { nCol = 0; }
|
| | | if (nCol >= m_CellPerLine) { nCol = m_CellPerLine - 1; }
|
| | | s1.Format(_T("LD %d %d %02X Scroll %d %d Total %d %d Row %d Col %d"), point.x, point.y, nFlags, scroll1.x, scroll1.y, tx, ty, nRow, nCol);
|
| | | if (nRow < 0) |
| | | {
|
| | | nRow = 0; |
| | | }
|
| | | if (nCol < 0) |
| | | { |
| | | nCol = 0; |
| | | }
|
| | | if (nCol >= m_CellPerLine) |
| | | {
|
| | | nCol = m_CellPerLine - 1; |
| | | }
|
| | | s1.Format(_T("OnLButtonDown::zxd:: LD %d %d %02X Scroll %d %d Total %d %d Row %d Col %d"), point.x, point.y, nFlags, scroll1.x, scroll1.y, tx, ty, nRow, nCol);
|
| | | DbgLog(s1);//zxd add to test
|
| | |
|
| | | m_pStatusBar->SetPaneText(6, s1);
|
| | | m_FocusRow = nRow;
|
| | | m_FocusCol = nCol;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 程序数据转为梯形图
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::TransProgToLDS()
|
| | | {
|
| | | CString s1;
|
| | |
| | |
|
| | | int cx = 0, cy = 0;
|
| | | int maxy = 0;
|
| | | for (int i = 0; i < pDoc->m_nProgSteps; i++)
|
| | | try
|
| | | {
|
| | | int nOp = pDoc->Progs[i].nOpType1;
|
| | | int nParamCount = pDoc->Progs[i].nParamCount;
|
| | | CStringA OpName;
|
| | | CStringA ShowTxt;
|
| | | pDoc->OpToTxt(nOp, OpName);
|
| | | pDoc->OpToShowTxt(nOp, ShowTxt);
|
| | | int nPairTo = pDoc->Progs[i].PairTo;
|
| | | int nPairOp = 0;
|
| | | if (nPairTo) nPairOp = pDoc->Progs[nPairTo].nOpType1;
|
| | | int nCellType;
|
| | | switch (nOp)
|
| | | for (int i = 0; i < pDoc->m_nProgSteps; i++)
|
| | | {
|
| | | int nOp = pDoc->Progs[i].nOpType1;
|
| | | int nParamCount = pDoc->Progs[i].nParamCount;
|
| | | CStringA OpName;
|
| | | CStringA ShowTxt;
|
| | | pDoc->OpToTxt(nOp, OpName);
|
| | | pDoc->OpToShowTxt(nOp, ShowTxt);
|
| | | int nPairTo = pDoc->Progs[i].PairTo;
|
| | | int nPairOp = 0;
|
| | | if (nPairTo) nPairOp = pDoc->Progs[nPairTo].nOpType1;
|
| | | int nCellType;
|
| | | switch (nOp)
|
| | | {
|
| | |
|
| | | case OP_NOP:
|
| | | break;
|
| | | case OP_ST:
|
| | | case OP_ST_:
|
| | | if (i == 0) {
|
| | | case OP_NOP:
|
| | | break;
|
| | | case OP_ST:
|
| | | case OP_ST_:
|
| | | if (i == 0) {
|
| | |
|
| | | }
|
| | | else {
|
| | | //记录当前位置 |
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | nEndPts++;
|
| | | if (nPairOp == OP_ANS) {
|
| | | //继续前进 |
| | | //cx = 0, cy = nCurLine;
|
| | | //cx = StPts[nSts - 1].x;
|
| | | //nCurLine = cy + 1; //另起一行
|
| | | ///* |
| | | nCurLine=cy;
|
| | | int hasData = 1;
|
| | | while (hasData) {
|
| | | hasData = 0;
|
| | | for (int j = cx +1; j < m_CellPerLine; j++) {
|
| | | if (Cells[nCurLine][j].nType != 0) {
|
| | | nCurLine++; hasData = 1; break;
|
| | | }
|
| | | else {
|
| | | //记录当前位置 |
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | nEndPts++;
|
| | | if (nPairOp == OP_ANS) {
|
| | | //继续前进 |
| | | //cx = 0, cy = nCurLine;
|
| | | //cx = StPts[nSts - 1].x;
|
| | | //nCurLine = cy + 1; //另起一行
|
| | | ///* |
| | | nCurLine = cy;
|
| | | int hasData = 1;
|
| | | while (hasData) {
|
| | | hasData = 0;
|
| | | for (int j = cx + 1; j < m_CellPerLine; j++) {
|
| | | if (Cells[nCurLine][j].nType != 0) {
|
| | | nCurLine++; hasData = 1; break;
|
| | | }
|
| | | }
|
| | | }
|
| | | // nCurLine = maxy + 1; //另起一行
|
| | | 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;
|
| | | //*/
|
| | | }
|
| | | // nCurLine = maxy + 1; //另起一行
|
| | | 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;
|
| | | //*/
|
| | | }
|
| | | else if (nPairOp == OP_ORS) {
|
| | | 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;
|
| | | else if (nPairOp == OP_ORS) {
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | // nCurLine = maxy + 1; //另起一行
|
| | | 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;
|
| | | }
|
| | | // nCurLine = maxy + 1; //另起一行
|
| | | if (nCurLine > maxy) maxy = nCurLine;
|
| | | for (int j = cy; j < nCurLine; j++) {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | else if (nPairOp == 0) {
|
| | | nCurLine = maxy + 1; //另起一行
|
| | | maxy = nCurLine;
|
| | | cx = 0; cy = nCurLine;
|
| | | }
|
| | | cy = nCurLine;
|
| | | }
|
| | | else if (nPairOp == 0) {
|
| | | nCurLine = maxy + 1; //另起一行
|
| | | maxy = nCurLine;
|
| | | cx = 0; cy = nCurLine;
|
| | | }
|
| | | }
|
| | | stpos[nSts] = i;
|
| | | StPts[nSts] = POINT{ cx,cy };
|
| | | nSts++;
|
| | | Cells[cy][cx].nType = pDoc->Progs[i].nOpType1 == OP_ST ? typeNO : typeNC; //typeNC
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | cx++; //移到下一格
|
| | | break;
|
| | | case OP_ST_EQ:
|
| | | case OP_ST_NE:
|
| | | case OP_ST_LT:
|
| | | case OP_ST_GT:
|
| | | case OP_ST_LE:
|
| | | case OP_ST_GE:
|
| | | if (i == 0) {
|
| | | stpos[nSts] = i;
|
| | | StPts[nSts] = POINT{ cx,cy };
|
| | | nSts++;
|
| | | Cells[cy][cx].nType = pDoc->Progs[i].nOpType1 == OP_ST ? typeNO : typeNC; //typeNC
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | cx++; //移到下一格
|
| | | break;
|
| | | case OP_ST_EQ:
|
| | | case OP_ST_NE:
|
| | | case OP_ST_LT:
|
| | | case OP_ST_GT:
|
| | | case OP_ST_LE:
|
| | | case OP_ST_GE:
|
| | | if (i == 0) {
|
| | |
|
| | | }
|
| | | else {
|
| | | //记录当前位置 |
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | nEndPts++;
|
| | | if (nPairOp == OP_ANS) {
|
| | | //继续前进 |
| | | //cx = 0, cy = nCurLine;
|
| | | }
|
| | | else if (nPairOp == OP_ORS) {
|
| | | 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;
|
| | | else {
|
| | | //记录当前位置 |
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | nEndPts++;
|
| | | if (nPairOp == OP_ANS) {
|
| | | //继续前进 |
| | | //cx = 0, cy = nCurLine;
|
| | | }
|
| | | else if (nPairOp == OP_ORS) {
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | // nCurLine = maxy + 1; //另起一行
|
| | | 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;
|
| | | }
|
| | | else if (nPairOp == 0) {
|
| | | nCurLine = maxy + 1; //另起一行
|
| | | maxy = nCurLine;
|
| | | cx = 0; cy = nCurLine;
|
| | | }
|
| | | }
|
| | | stpos[nSts] = i;
|
| | | StPts[nSts] = POINT{ cx,cy };
|
| | | nSts++;
|
| | | Cells[cy][cx].nType = typeCMP;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sParam = OpName;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3; //移到下3格
|
| | | break;
|
| | |
|
| | | case OP_AN:
|
| | | case OP_AN_:
|
| | |
|
| | | Cells[cy][cx].nType = nOp == OP_AN ? typeNO : typeNC; //typeNC
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | cx++;
|
| | | break;
|
| | | case OP_AN_EQ:
|
| | | case OP_AN_NE:
|
| | | case OP_AN_LT:
|
| | | case OP_AN_GT:
|
| | | case OP_AN_LE:
|
| | | case OP_AN_GE:
|
| | | Cells[cy][cx].nType = typeCMP;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | break;
|
| | |
|
| | | case OP_OR:
|
| | | case OP_OR_:
|
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | 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;
|
| | | // nCurLine = maxy + 1; //另起一行
|
| | | 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;
|
| | | }
|
| | | else if (nPairOp == 0) {
|
| | | nCurLine = maxy + 1; //另起一行
|
| | | maxy = nCurLine;
|
| | | cx = 0; cy = nCurLine;
|
| | | }
|
| | | }
|
| | | }
|
| | | 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;
|
| | | 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;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | 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;
|
| | | }
|
| | | stpos[nSts] = i;
|
| | | StPts[nSts] = POINT{ cx,cy };
|
| | | nSts++;
|
| | | Cells[cy][cx].nType = typeCMP;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sParam = OpName;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3; //移到下3格
|
| | | break;
|
| | |
|
| | | }
|
| | | //连接上下线
|
| | | for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | | nEndPts--;
|
| | | case OP_AN:
|
| | | case OP_AN_:
|
| | |
|
| | | break;
|
| | | case OP_OR_EQ:
|
| | | case OP_OR_NE:
|
| | | case OP_OR_LT:
|
| | | case OP_OR_GT:
|
| | | case OP_OR_LE:
|
| | | case OP_OR_GE:
|
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | 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;
|
| | | Cells[cy][cx].nType = typeCMP;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | 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++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_NOT:
|
| | | Cells[cy][cx].nType = typeNOT;
|
| | | Cells[cy][cx].sCoilName = _T("NOT");
|
| | |
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | cx++;
|
| | | break;
|
| | | case OP_DF:
|
| | | case OP_DF_:
|
| | | Cells[cy][cx].nType = nOp == OP_DF ? typeDF : typeDF_;
|
| | | Cells[cy][cx].sCoilName = nOp == OP_DF ? _T("DF") : _T("DF/");
|
| | |
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | cx++;
|
| | | break;
|
| | | case OP_ANS:
|
| | | nSts--;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_ORS:
|
| | | // 当前序列与前面的序列合并。
|
| | | //当前序列的开始结束位置
|
| | | //EndPt[nEndPts] = POINT{ cx,cy };
|
| | | //nEndPts++;
|
| | | //StPts[nSts - 1]; EndPt[nEndPts - 1];
|
| | | //前一序列的开始结束位置
|
| | | StPts[nSts - 1]; EndPt[nEndPts - 1];
|
| | | //判断二者长度
|
| | | 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++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | | nSts--;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_PSHS:
|
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | nEndPts++;
|
| | | break;
|
| | | case OP_RDS:
|
| | | cx = EndPt[nEndPts - 1].x;
|
| | | for (int j = cx; j < m_CellPerLine; j++) {
|
| | | if (Cells[cy][j].nType != 0)
|
| | | {
|
| | | cy++; j = cx - 1; //break;
|
| | | }
|
| | | }
|
| | | for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | break;
|
| | | case OP_POPS:
|
| | | cx = EndPt[nEndPts - 1].x;
|
| | | for (int j = cx; j < m_CellPerLine; j++) {
|
| | | if (Cells[cy][j].nType != 0)
|
| | | {
|
| | | cy++; j = cx - 1; break;
|
| | | }
|
| | | }
|
| | | for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_OUT:
|
| | | case OP_SET:
|
| | | case OP_RESET:
|
| | | nCellType = nOp == OP_OUT ? typeOUT : nOp == OP_SET ? typeSET : typeRESET;
|
| | | nCurLine = cy;
|
| | | if (cx <= m_CellPerLine) {
|
| | |
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | //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;
|
| | | for (int j = cx; j < m_CellPerLine; j++)
|
| | | {
|
| | | Cells[cy][j].nType = typeLine1;
|
| | | }
|
| | | Cells[cy][m_CellPerLine - 1].nType = nCellType;
|
| | | Cells[cy][m_CellPerLine - 1].nProgStep = i;
|
| | | Cells[cy][m_CellPerLine - 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][m_CellPerLine - 1].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][m_CellPerLine - 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][m_CellPerLine - 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | |
| | | }
|
| | | else {
|
| | | Cells[cy][cx].nType = nCellType;
|
| | | Cells[cy][cx].nType = nOp == OP_AN ? typeNO : typeNC; //typeNC
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | cx++;
|
| | | break;
|
| | | case OP_AN_EQ:
|
| | | case OP_AN_NE:
|
| | | case OP_AN_LT:
|
| | | case OP_AN_GT:
|
| | | case OP_AN_LE:
|
| | | case OP_AN_GE:
|
| | | Cells[cy][cx].nType = typeCMP;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | break;
|
| | |
|
| | | case OP_OR:
|
| | | case OP_OR_:
|
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | 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;
|
| | | 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;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | 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;
|
| | | }
|
| | |
|
| | | }
|
| | | //连接上下线
|
| | | for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_OR_EQ:
|
| | | case OP_OR_NE:
|
| | | case OP_OR_LT:
|
| | | case OP_OR_GT:
|
| | | case OP_OR_LE:
|
| | | case OP_OR_GE:
|
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | 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;
|
| | | Cells[cy][cx].nType = typeCMP;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | 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++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_NOT:
|
| | | Cells[cy][cx].nType = typeNOT;
|
| | | Cells[cy][cx].sCoilName = _T("NOT");
|
| | |
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | cx++;
|
| | | break;
|
| | | case OP_DF:
|
| | | case OP_DF_:
|
| | | Cells[cy][cx].nType = nOp == OP_DF ? typeDF : typeDF_;
|
| | | Cells[cy][cx].sCoilName = nOp == OP_DF ? _T("DF") : _T("DF/");
|
| | |
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | cx++;
|
| | | break;
|
| | | case OP_ANS:
|
| | | nSts--;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_ORS:
|
| | | // 当前序列与前面的序列合并。
|
| | | //当前序列的开始结束位置
|
| | | //EndPt[nEndPts] = POINT{ cx,cy };
|
| | | //nEndPts++;
|
| | | //StPts[nSts - 1]; EndPt[nEndPts - 1];
|
| | | //前一序列的开始结束位置
|
| | | StPts[nSts - 1]; EndPt[nEndPts - 1];
|
| | | //判断二者长度
|
| | | 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++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | //光标位置, 前一结束点位置
|
| | | cy = EndPt[nEndPts - 1].y;
|
| | | nSts--;
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_PSHS:
|
| | | EndPt[nEndPts] = POINT{ cx,cy };
|
| | | nEndPts++;
|
| | | break;
|
| | | case OP_RDS:
|
| | | cx = EndPt[nEndPts - 1].x;
|
| | | for (int j = cx; j < m_CellPerLine; j++) {
|
| | | if (Cells[cy][j].nType != 0)
|
| | | {
|
| | | cy++; j = cx - 1; //break;
|
| | | }
|
| | | }
|
| | | for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | break;
|
| | | case OP_POPS:
|
| | | cx = EndPt[nEndPts - 1].x;
|
| | | for (int j = cx; j < m_CellPerLine; j++) {
|
| | | if (Cells[cy][j].nType != 0)
|
| | | {
|
| | | cy++; j = cx - 1; break;
|
| | | }
|
| | | }
|
| | | for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
| | | {
|
| | | Cells[j][cx].bLeftLineDn = 1;
|
| | | Cells[j + 1][cx].bLeftLineUp = 1;
|
| | | }
|
| | | nEndPts--;
|
| | |
|
| | | break;
|
| | | case OP_OUT:
|
| | | case OP_SET:
|
| | | case OP_RESET:
|
| | | nCellType = nOp == OP_OUT ? typeOUT : nOp == OP_SET ? typeSET : typeRESET;
|
| | | nCurLine = cy;
|
| | | if (cx <= m_CellPerLine) {
|
| | |
|
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | //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;
|
| | | for (int j = cx; j < m_CellPerLine; j++)
|
| | | {
|
| | | Cells[cy][j].nType = typeLine1;
|
| | | }
|
| | | Cells[cy][m_CellPerLine - 1].nType = nCellType;
|
| | | Cells[cy][m_CellPerLine - 1].nProgStep = i;
|
| | | Cells[cy][m_CellPerLine - 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][m_CellPerLine - 1].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][m_CellPerLine - 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][m_CellPerLine - 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | |
|
| | | }
|
| | | else {
|
| | | Cells[cy][cx].nType = nCellType;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | }
|
| | | if (cy > maxy) { maxy = cy; }
|
| | | //cy++;
|
| | | break;
|
| | |
|
| | | case OP_TML:
|
| | | case OP_TMR:
|
| | | case OP_TMX:
|
| | | case OP_TMY:
|
| | | Cells[cy][cx].nType = typeTM;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = KLDataTypeEV;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | break;
|
| | | case OP_INC:
|
| | | case OP_DEC:
|
| | | Cells[cy][cx].nType = typeFN1;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | cx += 2;
|
| | | break;
|
| | |
|
| | | case OP_MV:
|
| | | case OP_ADD2:
|
| | | case OP_SUB2:
|
| | | Cells[cy][cx].nType = typeFN2;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | break;
|
| | |
|
| | | case OP_ADD3:
|
| | | case OP_SUB3:
|
| | | case OP_MUL:
|
| | | case OP_DIV:
|
| | | Cells[cy][cx].nType = typeFN3;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | Cells[cy][cx + 3].nType = typeExt1;
|
| | | Cells[cy][cx + 3].sParam = pDoc->Progs[i].Params[2].sParamStr;
|
| | | Cells[cy][cx + 3].nDataType = pDoc->Progs[i].Params[2].nParamType;
|
| | | Cells[cy][cx + 3].nDataAddr = pDoc->Progs[i].Params[2].nParamAddr;
|
| | | cx += 4;
|
| | | break;
|
| | |
|
| | | default:
|
| | | break;
|
| | | }
|
| | | if (cy > maxy) { maxy = cy; }
|
| | | //cy++;
|
| | | break;
|
| | |
|
| | | case OP_TML:
|
| | | case OP_TMR:
|
| | | case OP_TMX:
|
| | | case OP_TMY:
|
| | | Cells[cy][cx].nType = typeTM;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = KLDataTypeEV;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | break;
|
| | | case OP_INC:
|
| | | case OP_DEC:
|
| | | Cells[cy][cx].nType = typeFN1;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | cx += 2;
|
| | | break;
|
| | |
|
| | | case OP_MV:
|
| | | case OP_ADD2:
|
| | | case OP_SUB2:
|
| | | Cells[cy][cx].nType = typeFN2;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | cx += 3;
|
| | | break;
|
| | |
|
| | | case OP_ADD3:
|
| | | case OP_SUB3:
|
| | | case OP_MUL:
|
| | | case OP_DIV:
|
| | | Cells[cy][cx].nType = typeFN3;
|
| | | Cells[cy][cx].nProgStep = i;
|
| | | Cells[cy][cx].sCoilName = ShowTxt;
|
| | | Cells[cy][cx + 1].nType = typeExt1;
|
| | | Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
| | | Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
| | | Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
| | | Cells[cy][cx + 2].nType = typeExt1;
|
| | | Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
| | | Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
| | | Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
| | | Cells[cy][cx + 3].nType = typeExt1;
|
| | | Cells[cy][cx + 3].sParam = pDoc->Progs[i].Params[2].sParamStr;
|
| | | Cells[cy][cx + 3].nDataType = pDoc->Progs[i].Params[2].nParamType;
|
| | | Cells[cy][cx + 3].nDataAddr = pDoc->Progs[i].Params[2].nParamAddr;
|
| | | cx += 4;
|
| | | break;
|
| | |
|
| | | default:
|
| | | break;
|
| | | }
|
| | | }
|
| | | catch (const std::exception&)
|
| | | {
|
| | | DbgLog(_T("无法绘制图形(程序不合理)"));
|
| | | }
|
| | |
|
| | | m_nTotalRow = maxy + 1;
|
| | | /*
|
| | | for (int i = 0; i < 25; i++)
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 梯形图转Prog
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | int CMTerm1View::TransLDSToProg()
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | nCurPosY = i;
|
| | | stProgSection thisprogsec;
|
| | | if (Cells[i][0].nType)
|
| | | ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec,nSteps);
|
| | | {
|
| | | //循环遍历单元格
|
| | | ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec, nSteps);
|
| | | }
|
| | | sProg += sProgSec;
|
| | | nAllSteps += nSteps;
|
| | | Progsec += thisprogsec;
|
| | | }
|
| | |
|
| | | DbgLog(_T("\r\n")+ sProg);
|
| | | int n = int(Progsec.Progs.size());
|
| | | s1.Format(_T("progSec steps %d "), n);
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// :绘制每个单元格的内容
|
| | | /// </summary>
|
| | | /// <param name="nStartLine"></param>
|
| | | /// <param name="nEndLine"></param>
|
| | | /// <param name="nPosY"></param>
|
| | | /// <param name="nPosX"></param>
|
| | | /// <param name="nLevel"></param>
|
| | | /// <param name="progsec"></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)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | CMTerm1Doc::stProg theprog;
|
| | | CStringA sCellNameA;
|
| | | sCellNameA = sCellName;
|
| | | if (nType == typeNO) {
|
| | | if (nType == typeNO) |
| | | {
|
| | | if (j==0) {
|
| | | s1.Format(_T("%d %d ST %s"), nCurPosY, nCurPosX,sCellName);
|
| | | sProgSec.AppendFormat(_T("ST %s\r\n"),sCellName);
|
| | |
| | | CString ProgSec;
|
| | | int theSteps = 0;
|
| | | stProgSection thisprogsec;
|
| | |
|
| | | //
|
| | | int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel,thisprogsec, ProgSec,theSteps);
|
| | |
|
| | | sProgSec += ProgSec;
|
| | | nSteps += theSteps;
|
| | | progsec += thisprogsec;
|