提交 | 用户 | age
|
0ed438
|
1 |
|
418cb3
|
2 |
// MultiTerminal2View.cpp: CMTerm1View 类的实现
|
0ed438
|
3 |
//
|
Q |
4 |
|
|
5 |
#include "pch.h"
|
|
6 |
#include "framework.h"
|
|
7 |
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
|
|
8 |
// ATL 项目中进行定义,并允许与该项目共享文档代码。
|
|
9 |
#ifndef SHARED_HANDLERS
|
|
10 |
#include "MTerm1.h"
|
|
11 |
#endif
|
|
12 |
|
|
13 |
#include "MTerm1Doc.h"
|
|
14 |
#include "MTerm1View.h"
|
418cb3
|
15 |
#include "ChildFrm.h"
|
Q |
16 |
#include "DialogSetCoil.h"
|
|
17 |
#include "DialogSetData.h"
|
|
18 |
#include "DialogIoComment.h"
|
|
19 |
#include "KDefine.h"
|
df0321
|
20 |
#include "MainFrm.h"
|
0ed438
|
21 |
|
Q |
22 |
#ifdef _DEBUG
|
|
23 |
#define new DEBUG_NEW
|
|
24 |
#endif
|
|
25 |
|
|
26 |
|
|
27 |
// CMTerm1View
|
|
28 |
|
418cb3
|
29 |
IMPLEMENT_DYNCREATE(CMTerm1View, CScrollView)
|
0ed438
|
30 |
|
d34256
|
31 |
/// <summary>
|
Z |
32 |
/// 消息映射
|
|
33 |
/// 是 MFC 中用于将 Windows 消息(如鼠标点击、按键等)映射到成员函数的机制。
|
|
34 |
/// </summary>
|
418cb3
|
35 |
BEGIN_MESSAGE_MAP(CMTerm1View, CScrollView)
|
0ed438
|
36 |
// 标准打印命令
|
418cb3
|
37 |
ON_COMMAND(ID_FILE_PRINT, &CScrollView::OnFilePrint)
|
Q |
38 |
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CScrollView::OnFilePrint)
|
|
39 |
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CScrollView::OnFilePrintPreview)
|
|
40 |
|
|
41 |
ON_WM_CREATE()
|
|
42 |
ON_WM_TIMER()
|
|
43 |
ON_WM_ERASEBKGND()
|
|
44 |
ON_WM_SIZE()
|
|
45 |
|
|
46 |
ON_WM_LBUTTONDOWN()
|
|
47 |
ON_WM_LBUTTONUP()
|
|
48 |
ON_WM_LBUTTONDBLCLK()
|
|
49 |
ON_WM_RBUTTONDOWN()
|
0ed438
|
50 |
ON_WM_RBUTTONUP()
|
418cb3
|
51 |
ON_WM_CONTEXTMENU()
|
Q |
52 |
ON_WM_INITMENUPOPUP()
|
|
53 |
|
|
54 |
ON_COMMAND(ID_RECT_SELECT, &CMTerm1View::OnRectSelect)
|
|
55 |
ON_UPDATE_COMMAND_UI(ID_RECT_SELECT, &CMTerm1View::OnUpdateRectSelect)
|
|
56 |
ON_COMMAND(ID_TEXT_FIRST, &CMTerm1View::OnTextFirst)
|
|
57 |
ON_UPDATE_COMMAND_UI(ID_TEXT_FIRST, &CMTerm1View::OnUpdateTextFirst)
|
|
58 |
ON_COMMAND(ID_INSERT_BLANK_LINE, &CMTerm1View::OnInsertBlankLine)
|
|
59 |
ON_UPDATE_COMMAND_UI(ID_INSERT_BLANK_LINE, &CMTerm1View::OnUpdateInsertBlankLine)
|
|
60 |
ON_COMMAND(ID_DELETE_BLANK_LINE, &CMTerm1View::OnDeleteBlankLine)
|
|
61 |
ON_UPDATE_COMMAND_UI(ID_DELETE_BLANK_LINE, &CMTerm1View::OnUpdateDeleteBlankLine)
|
|
62 |
ON_COMMAND(ID_DISPLAY_COMMENTS, &CMTerm1View::OnDisplayComments)
|
|
63 |
ON_UPDATE_COMMAND_UI(ID_DISPLAY_COMMENTS, &CMTerm1View::OnUpdateDisplayComments)
|
|
64 |
ON_COMMAND(ID_MONITOR, &CMTerm1View::OnMonitor)
|
|
65 |
ON_UPDATE_COMMAND_UI(ID_MONITOR, &CMTerm1View::OnUpdateMonitor)
|
|
66 |
ON_COMMAND(ID_PROG_CONVERT, &CMTerm1View::OnProgConvert)
|
|
67 |
ON_UPDATE_COMMAND_UI(ID_PROG_CONVERT, &CMTerm1View::OnUpdateProgConvert)
|
|
68 |
ON_COMMAND(ID_PROG_CANCEL_EDIT, &CMTerm1View::OnProgCancelEdit)
|
|
69 |
ON_UPDATE_COMMAND_UI(ID_PROG_CANCEL_EDIT, &CMTerm1View::OnUpdateProgCancelEdit)
|
|
70 |
ON_COMMAND(ID_INPUT_IO_COMMENT, &CMTerm1View::OnInputIoComment)
|
|
71 |
|
|
72 |
|
|
73 |
// ON_UPDATE_COMMAND_UI_RANGE(ID_INDICATOR_MACHINE_TYPE, ID_INDICATOR_INFO_DISPLAY, OnUpdateIndicators)
|
|
74 |
ON_COMMAND_RANGE(ID_INDICATOR_MACHINE_TYPE, ID_INDICATOR_INFO_DISPLAY, NULL)
|
|
75 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_MACHINE_TYPE, &CMTerm1View::OnUpdateMachineType)
|
|
76 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_PROGRAM_POS, &CMTerm1View::OnUpdateProgramPos)
|
|
77 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_CONNECTIVITY, &CMTerm1View::OnUpdateConnectivity)
|
|
78 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_RUN_STATUS, &CMTerm1View::OnUpdateRunStatus)
|
|
79 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnUpdateMonitorStatus)
|
|
80 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_TARGET_ADDRESS, &CMTerm1View::OnUpdateTargetAddress)
|
|
81 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_INFO_DISPLAY, &CMTerm1View::OnUpdateDisplayComments)
|
|
82 |
|
|
83 |
// ON_COMMAND(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnIndicatorMonitorStatus)
|
|
84 |
// ON_UPDATE_COMMAND_UI(ID_INDICATOR_MONITOR_STATUS, &CMTerm1View::OnUpdateIndicatorMonitorStatus)
|
|
85 |
ON_WM_KEYDOWN()
|
0ed438
|
86 |
END_MESSAGE_MAP()
|
418cb3
|
87 |
|
0ed438
|
88 |
|
Q |
89 |
// CMTerm1View 构造/析构
|
|
90 |
|
|
91 |
CMTerm1View::CMTerm1View() noexcept
|
|
92 |
{
|
|
93 |
// TODO: 在此处添加构造代码
|
|
94 |
|
|
95 |
}
|
|
96 |
|
|
97 |
CMTerm1View::~CMTerm1View()
|
|
98 |
{
|
|
99 |
}
|
|
100 |
|
|
101 |
BOOL CMTerm1View::PreCreateWindow(CREATESTRUCT& cs)
|
|
102 |
{
|
|
103 |
// TODO: 在此处通过修改
|
|
104 |
// CREATESTRUCT cs 来修改窗口类或样式
|
|
105 |
|
418cb3
|
106 |
return CScrollView::PreCreateWindow(cs);
|
Q |
107 |
}
|
|
108 |
|
d34256
|
109 |
/// <summary>
|
Z |
110 |
/// MFC 中的一个函数,它在视图首次显示之前被调用
|
|
111 |
/// </summary>
|
418cb3
|
112 |
void CMTerm1View::OnInitialUpdate()
|
Q |
113 |
{
|
|
114 |
CScrollView::OnInitialUpdate();
|
d34256
|
115 |
|
Z |
116 |
//创建了三种不同的字体
|
418cb3
|
117 |
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("宋体"));
|
Q |
118 |
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("宋体"));
|
|
119 |
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("宋体"));
|
d34256
|
120 |
|
Z |
121 |
//获取了状态栏的引用并存储在 m_pStatusBar 成员变量中
|
418cb3
|
122 |
m_pStatusBar = ((CChildFrame *)GetParentFrame())->GetStatusBar();
|
d34256
|
123 |
|
418cb3
|
124 |
CSize sizeTotal;
|
Q |
125 |
// TODO: 计算此视图的合计大小
|
|
126 |
sizeTotal.cx = m_LeftMargin + m_CellWidth* m_CellPerLine + m_CellWidth *2;
|
|
127 |
sizeTotal.cy = 2000;
|
d34256
|
128 |
//设置了滚动大小
|
418cb3
|
129 |
SetScrollSizes(MM_TEXT, sizeTotal);
|
d34256
|
130 |
|
Z |
131 |
CString s1;//没啥用
|
|
132 |
|
|
133 |
//设置了两个定时器,一个间隔为50毫秒,另一个为10毫秒。
|
418cb3
|
134 |
SetTimer(1, 50,NULL);
|
Q |
135 |
SetTimer(2, 10, NULL);
|
|
136 |
|
0ed438
|
137 |
}
|
Q |
138 |
|
|
139 |
// CMTerm1View 绘图
|
|
140 |
|
418cb3
|
141 |
void CMTerm1View::OnDraw(CDC* pDC)
|
0ed438
|
142 |
{
|
Q |
143 |
CMTerm1Doc* pDoc = GetDocument();
|
|
144 |
ASSERT_VALID(pDoc);
|
|
145 |
if (!pDoc)
|
|
146 |
return;
|
|
147 |
|
|
148 |
// TODO: 在此处为本机数据添加绘制代码
|
d34256
|
149 |
CString s1;//没啥用
|
Z |
150 |
|
418cb3
|
151 |
needReDraw = 1;
|
Q |
152 |
DrawLDSGraph(pDC);
|
|
153 |
needReDraw = 0;
|
0ed438
|
154 |
}
|
Q |
155 |
|
d34256
|
156 |
// CMTerm1View 打印,MFC 函数,用于准备打印。
|
0ed438
|
157 |
BOOL CMTerm1View::OnPreparePrinting(CPrintInfo* pInfo)
|
Q |
158 |
{
|
|
159 |
// 默认准备
|
|
160 |
return DoPreparePrinting(pInfo);
|
|
161 |
}
|
|
162 |
|
d34256
|
163 |
// MFC 函数,用于在打印开始之前进行初始化。
|
0ed438
|
164 |
void CMTerm1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
Q |
165 |
{
|
|
166 |
// TODO: 添加额外的打印前进行的初始化过程
|
|
167 |
}
|
|
168 |
|
d34256
|
169 |
//MFC 函数,用于在打印结束后进行清理。
|
0ed438
|
170 |
void CMTerm1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
|
Q |
171 |
{
|
|
172 |
// TODO: 添加打印后进行的清理过程
|
|
173 |
}
|
|
174 |
|
|
175 |
|
|
176 |
// CMTerm1View 诊断
|
|
177 |
|
|
178 |
#ifdef _DEBUG
|
d34256
|
179 |
//函数用于验证对象的有效性。
|
0ed438
|
180 |
void CMTerm1View::AssertValid() const
|
Q |
181 |
{
|
418cb3
|
182 |
CScrollView::AssertValid();
|
d34256
|
183 |
}
|
0ed438
|
184 |
|
d34256
|
185 |
// 函数用于将对象的内容转储到指定的上下文。
|
0ed438
|
186 |
void CMTerm1View::Dump(CDumpContext& dc) const
|
Q |
187 |
{
|
418cb3
|
188 |
CScrollView::Dump(dc);
|
0ed438
|
189 |
}
|
Q |
190 |
|
d34256
|
191 |
//函数返回与此视图关联的文档对象。
|
0ed438
|
192 |
CMTerm1Doc* CMTerm1View::GetDocument() const // 非调试版本是内联的
|
Q |
193 |
{
|
|
194 |
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMTerm1Doc)));
|
|
195 |
return (CMTerm1Doc*)m_pDocument;
|
|
196 |
}
|
|
197 |
#endif //_DEBUG
|
|
198 |
|
d34256
|
199 |
//MFC 函数,用于处理视图的创建事件。
|
418cb3
|
200 |
int CMTerm1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
Q |
201 |
{
|
|
202 |
if (CScrollView::OnCreate(lpCreateStruct) == -1)
|
|
203 |
return -1;
|
|
204 |
|
|
205 |
// TODO: 在此添加您专用的创建代码
|
|
206 |
|
|
207 |
return 0;
|
|
208 |
}
|
|
209 |
|
d34256
|
210 |
/// <summary>
|
Z |
211 |
/// 用于重新绘制视图。
|
|
212 |
/// </summary>
|
|
213 |
/// <returns></returns>
|
418cb3
|
214 |
int CMTerm1View::DoReDraw()
|
Q |
215 |
{
|
d34256
|
216 |
|
418cb3
|
217 |
CPoint scroll1;
|
Q |
218 |
scroll1 = this->GetScrollPosition();
|
|
219 |
|
|
220 |
CClientDC dc1(this);
|
|
221 |
XFORM xform1;
|
|
222 |
xform1.eM11 = 1;
|
|
223 |
xform1.eM12 = 0;
|
|
224 |
xform1.eM21 = 0;
|
|
225 |
xform1.eM22 = 1;
|
|
226 |
xform1.eDx = float(-scroll1.x);
|
|
227 |
xform1.eDy = float(-scroll1.y);
|
|
228 |
|
|
229 |
XFORM xform2 = { 1, 0, 0, 1, 0, 0 };
|
|
230 |
|
|
231 |
dc1.SetGraphicsMode(GM_ADVANCED);
|
|
232 |
dc1.SetWorldTransform(&xform1);
|
|
233 |
|
|
234 |
DrawLDSGraph(&dc1);
|
|
235 |
|
|
236 |
return 0;
|
|
237 |
}
|
|
238 |
|
d34256
|
239 |
/// <summary>
|
Z |
240 |
/// 滚动到特定单元格
|
|
241 |
/// 函数内部计算了单元格的总高度,考虑了是否显示注释
|
|
242 |
/// </summary>
|
|
243 |
/// <param name="nRow"></param>
|
|
244 |
/// <param name="nCol"></param>
|
|
245 |
/// <returns></returns>
|
418cb3
|
246 |
int CMTerm1View::ScrollToCell(int nRow, int nCol)
|
Q |
247 |
{
|
|
248 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
249 |
|
|
250 |
CSize sizeTotal;
|
|
251 |
// TODO: 计算此视图的合计大小
|
|
252 |
sizeTotal.cx = m_LeftMargin + m_CellWidth * m_CellPerLine + m_CellWidth * 2;
|
|
253 |
sizeTotal.cy = m_TopMargin + CellTotalHeight * (m_nTotalRow );
|
|
254 |
CSize sizeSb;
|
|
255 |
GetScrollBarSizes(sizeSb);
|
|
256 |
POINT pt1;
|
|
257 |
pt1.x = 0;
|
|
258 |
pt1.y = nRow * CellTotalHeight;
|
|
259 |
ScrollToPosition(pt1);
|
|
260 |
return 0;
|
|
261 |
}
|
|
262 |
|
d34256
|
263 |
/// <summary>
|
Z |
264 |
/// 滚动单元格进入视图(未完成的功能)
|
|
265 |
/// </summary>
|
|
266 |
/// <param name="nRow"></param>
|
|
267 |
/// <param name="nCol"></param>
|
|
268 |
/// <returns></returns>
|
418cb3
|
269 |
int CMTerm1View::ScrollCellIntoView(int nRow, int nCol)
|
Q |
270 |
{
|
|
271 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
272 |
return 0;
|
|
273 |
}
|
|
274 |
|
d34256
|
275 |
/// <summary>
|
Z |
276 |
/// 检查单元格是否在视图中(未完成的功能)
|
|
277 |
/// </summary>
|
|
278 |
/// <param name="nRow"></param>
|
|
279 |
/// <param name="nCol"></param>
|
|
280 |
/// <returns></returns>
|
418cb3
|
281 |
int CMTerm1View::isCellInView(int nRow, int nCol)
|
Q |
282 |
{
|
|
283 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
284 |
return 0;
|
|
285 |
}
|
|
286 |
|
d34256
|
287 |
/// <summary>
|
Z |
288 |
/// 用于在视图中绘制图形的主要函数
|
|
289 |
/// </summary>
|
|
290 |
/// <param name="pDC">文档</param>
|
|
291 |
/// <returns></returns>
|
418cb3
|
292 |
int CMTerm1View::DrawLDSGraph(CDC* pDC)
|
Q |
293 |
{
|
|
294 |
// TODO: 在此处添加实现代码.
|
d34256
|
295 |
CString s1;//没啥用
|
Z |
296 |
|
|
297 |
//验证文档引用
|
418cb3
|
298 |
CMTerm1Doc* pDoc = GetDocument();
|
Q |
299 |
ASSERT_VALID(pDoc);
|
|
300 |
if (!pDoc) return false;
|
d34256
|
301 |
|
418cb3
|
302 |
if (m_bMonitoring) {
|
Q |
303 |
pDoc->DoPLCMonitor();
|
|
304 |
}
|
d34256
|
305 |
|
418cb3
|
306 |
int x1, y1, x2, y2;
|
Q |
307 |
// RECT rect1;
|
|
308 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
309 |
|
|
310 |
int nDataType, nDataAddr;
|
|
311 |
int nStat;
|
d34256
|
312 |
CBrush br0(BkColor);//背景颜色
|
Z |
313 |
CBrush br01(BkEditColor);//编辑(选中)状态下的背景颜色
|
418cb3
|
314 |
int nRow, nCol;
|
Q |
315 |
CRect rect0;
|
|
316 |
this->GetClientRect(&rect0);
|
|
317 |
int viewWidth = rect0.Width();
|
|
318 |
CPoint scroll1;
|
|
319 |
scroll1 = this->GetScrollPosition();
|
|
320 |
|
d34256
|
321 |
int nFirstVisibleLine;//用于确定可见行范围-起始位置
|
Z |
322 |
int nLastVisibleLine;//用于确定可见行范围-终止位置
|
|
323 |
//通过滚动位置和视图的高度计算上述两个值
|
418cb3
|
324 |
nFirstVisibleLine = (scroll1.y - m_TopMargin) / CellTotalHeight;
|
Q |
325 |
nLastVisibleLine = (rect0.Height() + scroll1.y - m_TopMargin) / CellTotalHeight + 1;
|
d34256
|
326 |
if (nFirstVisibleLine < 0)
|
Z |
327 |
{
|
|
328 |
nFirstVisibleLine = 0;
|
|
329 |
}
|
|
330 |
if (nLastVisibleLine < 0)
|
|
331 |
{
|
|
332 |
nLastVisibleLine = 0;
|
|
333 |
}
|
418cb3
|
334 |
|
d34256
|
335 |
//选择字体
|
418cb3
|
336 |
CFont *pOldFont;
|
Q |
337 |
pOldFont = (CFont *)pDC->SelectObject(&TextFont);
|
|
338 |
|
d34256
|
339 |
for (int i = nFirstVisibleLine; i < nLastVisibleLine && i < 1000; i++)
|
Z |
340 |
{
|
418cb3
|
341 |
// 画一行 单元
|
Q |
342 |
nRow = i;
|
|
343 |
int x0, y0;
|
|
344 |
x0 = m_LeftMargin;
|
|
345 |
y0 = m_TopMargin + CellTotalHeight * i;
|
|
346 |
y2 = y0 + CellTotalHeight;
|
|
347 |
//画背景
|
|
348 |
if (needReDraw) {
|
|
349 |
// 左半部分
|
|
350 |
if (scroll1.x < x0) {
|
|
351 |
CRect rect1(scroll1.x, y0, x0, y2);
|
|
352 |
pDC->FillRect(&rect1, &br0);
|
|
353 |
}
|
|
354 |
//中间部分
|
|
355 |
x1 = max(scroll1.x, x0);
|
|
356 |
x2 = min(scroll1.x + viewWidth, x0 + m_CellPerLine * m_CellWidth);
|
|
357 |
CRect rect2(x1, y0, x2, y2);
|
|
358 |
//背景颜色
|
|
359 |
if (!Cells[nRow][0].bEditing){
|
|
360 |
pDC->FillRect(&rect2, &br0);
|
|
361 |
} else {
|
|
362 |
pDC->FillRect(&rect2, &br01);
|
|
363 |
}
|
|
364 |
// 右边部分
|
|
365 |
if (x2 < scroll1.x + viewWidth) {
|
|
366 |
CRect rect3(x2, y0, scroll1.x + viewWidth, y2);
|
|
367 |
pDC->FillRect(&rect3, &br0);
|
|
368 |
}
|
|
369 |
|
|
370 |
if (m_FocusRow == i) DrawFocusRect(pDC);
|
|
371 |
|
|
372 |
}
|
|
373 |
//*
|
|
374 |
// 画本行左侧母线
|
|
375 |
x1 = m_LeftMargin;
|
|
376 |
y1 = m_TopMargin + CellTotalHeight * i;
|
|
377 |
x2 = x1;
|
|
378 |
y2 = y1 + CellTotalHeight;
|
|
379 |
|
|
380 |
pDC->MoveTo(x1, y1);
|
|
381 |
pDC->LineTo(x2, y2);
|
|
382 |
//画左侧母线小短横线
|
|
383 |
|
|
384 |
|
|
385 |
x1 = m_LeftMargin;
|
|
386 |
y1 = m_TopMargin + CellTotalHeight * i + m_LinePosY;
|
|
387 |
x2 = x1 + 3;
|
|
388 |
y2 = y1;
|
|
389 |
pDC->MoveTo(x1, y1);
|
|
390 |
pDC->LineTo(x2, y2);
|
|
391 |
|
|
392 |
// 如果本行第一个ST是程序段的起始,输出程序步数
|
|
393 |
//*/
|
|
394 |
int nType = Cells[nRow][0].nType;
|
|
395 |
int nProgSetp = Cells[nRow][0].nProgStep;
|
|
396 |
if (nType == typeNO || nType == typeNC || nType == typeCMP) {
|
|
397 |
int nPairTo = pDoc->Progs[nProgSetp].PairTo;
|
|
398 |
int nPairOp = 0;
|
|
399 |
if (nPairTo) nPairOp = pDoc->Progs[nPairTo].nOpType1;
|
|
400 |
if (nPairOp == 0) { //程序段开始
|
|
401 |
//在当前行的左侧输出 当前 程序步数
|
|
402 |
s1.Format(_T(" %d"), nProgSetp);
|
|
403 |
CRect rect2(0, m_TopMargin + CellTotalHeight * i + m_LinePosY - 8, m_LeftMargin - 4, m_TopMargin + CellTotalHeight * i + m_LinePosY + 14);
|
|
404 |
pDC->DrawText(s1, &rect2, DT_RIGHT);
|
|
405 |
|
|
406 |
}
|
|
407 |
}
|
|
408 |
// 获取数据 并显示各单元
|
df0321
|
409 |
|
418cb3
|
410 |
for (int j = 0; j < m_CellPerLine; j++) {
|
Q |
411 |
nCol = j;
|
|
412 |
nDataType = Cells[nRow][nCol].nDataType;
|
|
413 |
nDataAddr = Cells[nRow][nCol].nDataAddr;
|
df0321
|
414 |
if (m_bMonitoring) {
|
Q |
415 |
if ((nDataType & TYPEDATA) == TYPEDATA) {
|
|
416 |
nStat = pDoc->GetVarData(nDataType, nDataAddr);
|
|
417 |
}
|
|
418 |
else {
|
|
419 |
nStat = pDoc->GetCoilValue(nDataType, nDataAddr);
|
|
420 |
}
|
|
421 |
Cells[nRow][nCol].nStat = nStat;
|
|
422 |
nType = Cells[nRow][nCol].nType;
|
|
423 |
if (nType == typeNO || nType == typeNC || nType == typeCMP || nType == typeTM)
|
|
424 |
{
|
|
425 |
int nProgStep = Cells[nRow][nCol].nProgStep;
|
|
426 |
int nBinProgStep = pDoc->Progs[nProgStep].nBinStep;
|
|
427 |
Cells[nRow][nCol].nTrace = pDoc->ProgTrace[nBinProgStep];
|
|
428 |
}
|
418cb3
|
429 |
}
|
Q |
430 |
else {
|
df0321
|
431 |
Cells[nRow][nCol].nStat = 0; Cells[nRow][nCol].nTrace = 0;
|
418cb3
|
432 |
}
|
df0321
|
433 |
|
418cb3
|
434 |
DrawCell(pDC, i, j);
|
Q |
435 |
}
|
|
436 |
|
|
437 |
|
|
438 |
// 画本行右侧母线
|
|
439 |
//*
|
|
440 |
x1 = m_LeftMargin + m_CellWidth * m_CellPerLine;
|
|
441 |
y1 = m_TopMargin + CellTotalHeight * i;
|
|
442 |
x2 = x1;
|
|
443 |
y2 = y1 + CellTotalHeight;
|
|
444 |
|
|
445 |
pDC->MoveTo(x1, y1);
|
|
446 |
pDC->LineTo(x2, y2);
|
|
447 |
// 画本行右侧母线小短横线
|
|
448 |
x1 = m_LeftMargin + m_CellWidth * m_CellPerLine;
|
|
449 |
y1 = m_TopMargin + CellTotalHeight * i + m_LinePosY;
|
|
450 |
x2 = x1 - 3;
|
|
451 |
y2 = y1;
|
|
452 |
pDC->MoveTo(x1, y1);
|
|
453 |
pDC->LineTo(x2, y2);
|
|
454 |
|
|
455 |
//*/
|
|
456 |
}
|
|
457 |
pDC->SelectObject(pOldFont);
|
|
458 |
CRect rect2(0, 30, 240, 100);
|
|
459 |
// pDC->DrawText(_T("这是测试字符串111,222,33,aa,bb,cc"), &rect2, 0);
|
|
460 |
s1.Format(_T("This is New Info.."));
|
|
461 |
needReDraw = 0;
|
|
462 |
return 0;
|
|
463 |
}
|
|
464 |
|
|
465 |
void CMTerm1View::DrawFocusRect(CDC* pDC)
|
|
466 |
{
|
|
467 |
// DrawCell(pDC, m_oldFocusRow, m_oldFocusCol);
|
|
468 |
CPen BluePen(PS_SOLID, 3, FocusColor);
|
|
469 |
CPen * pOldPen = pDC->SelectObject(&BluePen);
|
|
470 |
//CBrush * pOldBrush = ;
|
|
471 |
pDC->SelectStockObject(NULL_BRUSH);
|
|
472 |
int x0, y0;
|
|
473 |
// int x1, y1, x2, y2;
|
|
474 |
RECT rect1;
|
|
475 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
476 |
|
|
477 |
rect1.left = m_LeftMargin + 1 + m_CellWidth * m_FocusCol;
|
|
478 |
rect1.right = rect1.left + m_CellWidth - 4;
|
|
479 |
rect1.top = m_TopMargin + CellTotalHeight * m_FocusRow;
|
|
480 |
rect1.bottom = rect1.top + CellTotalHeight - 2;
|
|
481 |
|
|
482 |
x0 = rect1.left;
|
|
483 |
y0 = rect1.top;
|
|
484 |
//pDC->DrawFocusRect(&rect1);
|
|
485 |
pDC->Rectangle(&rect1);
|
|
486 |
m_oldFocusCol = m_FocusCol;
|
|
487 |
m_oldFocusRow = m_FocusRow;
|
|
488 |
|
|
489 |
pDC->SelectObject(pOldPen);
|
|
490 |
// pDC->SelectObject(poldBrush);
|
|
491 |
}
|
|
492 |
|
|
493 |
int CMTerm1View::DrawLeftRightLine(CDC* pDC, int x0, int y0, int size1, int size2)
|
|
494 |
{
|
|
495 |
// TODO: 在此处添加实现代码.
|
|
496 |
int x1, y1, x2, y2;
|
|
497 |
//画左侧横线
|
|
498 |
x1 = x0;
|
|
499 |
y1 = y0 + m_LinePosY;
|
|
500 |
x2 = x1 + size1;
|
|
501 |
y2 = y1;
|
|
502 |
pDC->MoveTo(x1, y1);
|
|
503 |
pDC->LineTo(x2, y2);
|
|
504 |
|
|
505 |
//画右侧横线
|
|
506 |
x1 = x0 + size1 +size2;
|
|
507 |
y1 = y0 + m_LinePosY;
|
|
508 |
x2 = x0 + m_CellWidth;
|
|
509 |
y2 = y1;
|
|
510 |
pDC->MoveTo(x1, y1);
|
|
511 |
pDC->LineTo(x2, y2);
|
|
512 |
return 0;
|
|
513 |
}
|
|
514 |
|
|
515 |
void CMTerm1View::DrawOT(CDC* pDC, int x0, int y0)
|
|
516 |
{
|
|
517 |
int x1, y1;
|
|
518 |
//画左右侧横线
|
|
519 |
DrawLeftRightLine(pDC, x0, y0);
|
|
520 |
|
|
521 |
x1 = x0 +16;
|
|
522 |
y1 = y0 + m_LinePosY;
|
|
523 |
|
|
524 |
pDC->MoveTo(x1 + 6 + 6, y1);
|
|
525 |
pDC->AngleArc(x1 + 6, y1, 6, 0, 360);
|
|
526 |
}
|
|
527 |
|
|
528 |
void CMTerm1View::DrawRelay(CDC* pDC, int x0, int y0)
|
|
529 |
{
|
|
530 |
int x1, y1, x2, y2;
|
|
531 |
//画左右侧横线
|
|
532 |
DrawLeftRightLine(pDC, x0, y0);
|
|
533 |
// 画左侧竖线
|
|
534 |
x1 = x0+16;
|
|
535 |
y1 = y0 + m_LinePosY - 6;
|
|
536 |
x2 = x1;
|
|
537 |
y2 = y1 + 12;
|
|
538 |
pDC->MoveTo(x1, y1);
|
|
539 |
pDC->LineTo(x2, y2);
|
|
540 |
// 画右侧竖线
|
|
541 |
x1 = x2 + 12;
|
|
542 |
y1 = y1;
|
|
543 |
x2 = x1;
|
|
544 |
y2 = y1 + 12;
|
|
545 |
pDC->MoveTo(x1, y1);
|
|
546 |
pDC->LineTo(x2, y2);
|
|
547 |
}
|
|
548 |
|
|
549 |
int CMTerm1View::DrawBracket(CDC* pDC, int x0, int y0, int sizex, int sty, int sizey)
|
|
550 |
{
|
|
551 |
// TODO: 在此处添加实现代码.
|
|
552 |
int x1, y1, x2, y2;
|
|
553 |
// 左边的短横线
|
|
554 |
x1 = x0 ;
|
|
555 |
y1 = y0 + m_LinePosY;
|
|
556 |
x2 = x0 + 3;
|
|
557 |
y2 = y1;
|
|
558 |
pDC->MoveTo(x1, y1);
|
|
559 |
pDC->LineTo(x2, y2);
|
|
560 |
|
|
561 |
// 左方括号
|
|
562 |
x1 = x0 + 9;
|
|
563 |
y1 = y0 + sty;
|
|
564 |
x2 = x0 + 3;
|
|
565 |
y2 = y1;
|
|
566 |
pDC->MoveTo(x1, y1);
|
|
567 |
pDC->LineTo(x2, y2);
|
|
568 |
x2 = x2;
|
|
569 |
y2 = y2 + sizey;
|
|
570 |
pDC->LineTo(x2, y2);
|
|
571 |
x2 = x2 + 6;
|
|
572 |
y2 = y2;
|
|
573 |
pDC->LineTo(x2, y2);
|
|
574 |
// 右方括号
|
|
575 |
x1 = x0 + sizex - 6 - 6;
|
|
576 |
y1 = y0 + sty;
|
|
577 |
x2 = x0 + sizex -6 ;
|
|
578 |
y2 = y1;
|
|
579 |
pDC->MoveTo(x1, y1);
|
|
580 |
pDC->LineTo(x2, y2);
|
|
581 |
x2 = x2;
|
|
582 |
y2 = y2 + sizey;
|
|
583 |
pDC->LineTo(x2, y2);
|
|
584 |
x2 = x2 - 6;
|
|
585 |
y2 = y2;
|
|
586 |
pDC->LineTo(x2, y2);
|
|
587 |
// 右边的短横线
|
|
588 |
x1 = x0 + sizex - 6;
|
|
589 |
y1 = y0 + m_LinePosY;
|
|
590 |
x2 = x0 + sizex ;
|
|
591 |
y2 = y1;
|
|
592 |
pDC->MoveTo(x1, y1);
|
|
593 |
pDC->LineTo(x2, y2);
|
|
594 |
return 0;
|
|
595 |
}
|
d34256
|
596 |
|
418cb3
|
597 |
int CMTerm1View::DrawAngleBracket(CDC* pDC, int x0, int y0, int size1, int size2)
|
Q |
598 |
{
|
|
599 |
// TODO: 在此处添加实现代码.
|
|
600 |
int x1,y1,x2, y2;
|
|
601 |
DrawLeftRightLine(pDC, x0, y0, size1, size2);
|
|
602 |
// 左尖括号
|
|
603 |
x1 = x0 + size1 + 6;
|
d34256
|
604 |
y1 = y0 + m_LinePosY -6;
|
418cb3
|
605 |
x2 = x1 -6;
|
Q |
606 |
y2 = y1 +6 ;
|
|
607 |
pDC->MoveTo(x1, y1);
|
|
608 |
pDC->LineTo(x2, y2);
|
|
609 |
x2 = x2 +6;
|
|
610 |
y2 = y2 + 6;
|
|
611 |
pDC->LineTo(x2, y2);
|
|
612 |
// 右尖括号
|
|
613 |
x1 = x0 + size1 + size2 - 6;
|
|
614 |
y1 = y0 + m_LinePosY - 6;
|
|
615 |
x2 = x1 + 6;
|
|
616 |
y2 = y1 + 6 ;
|
|
617 |
pDC->MoveTo(x1, y1);
|
|
618 |
pDC->LineTo(x2, y2);
|
|
619 |
x2 = x2 -6 ;
|
|
620 |
y2 = y2 + 6;
|
|
621 |
pDC->LineTo(x2, y2);
|
|
622 |
return 0;
|
|
623 |
}
|
|
624 |
|
|
625 |
int CMTerm1View::DrawCellStat1(CDC * pDC, int x1, int y1, int sizex, int sizey, int nStat)
|
|
626 |
{
|
|
627 |
// TODO: 在此处添加实现代码.
|
|
628 |
CRect rect1;
|
|
629 |
rect1.left = x1;
|
|
630 |
rect1.top = y1;
|
|
631 |
rect1.right = x1+sizex;
|
|
632 |
rect1.bottom = y1+sizey;
|
|
633 |
|
|
634 |
CBrush br0(BkColor);
|
|
635 |
CBrush br1(MonCoilColor);
|
|
636 |
if (m_bMonitoring) {
|
|
637 |
if (nStat) {
|
|
638 |
pDC->FillRect(&rect1, &br1);
|
|
639 |
}else{
|
|
640 |
pDC->FillRect(&rect1, &br0);
|
|
641 |
}
|
|
642 |
}
|
|
643 |
return 0;
|
|
644 |
}
|
|
645 |
|
|
646 |
int CMTerm1View::DrawCellStat2(CDC* pDC, int x1, int y1, int sizex, int sizey, int nStat)
|
|
647 |
{
|
|
648 |
// TODO: 在此处添加实现代码.
|
|
649 |
CRect rect1;
|
|
650 |
rect1.left = x1;
|
|
651 |
rect1.top = y1;
|
|
652 |
rect1.right = x1+sizex;
|
|
653 |
rect1.bottom = y1+sizey;
|
|
654 |
CBrush br2(TraceBkColor);
|
|
655 |
CBrush br3(TraceColor);
|
|
656 |
if (m_bMonitoring) {
|
|
657 |
if (nStat) {
|
|
658 |
pDC->FillRect(&rect1, &br3);
|
|
659 |
}else{
|
|
660 |
pDC->FillRect(&rect1, &br2);
|
|
661 |
}
|
|
662 |
}
|
|
663 |
return 0;
|
|
664 |
}
|
|
665 |
|
|
666 |
int CMTerm1View::DrawCellText1(CDC* pDC, CString sText, int x1, int y1, int sizex, int sizey, int nFormat)
|
|
667 |
{
|
|
668 |
// TODO: 在此处添加实现代码.
|
|
669 |
CRect rect1;
|
|
670 |
rect1.left = x1;
|
|
671 |
rect1.top = y1;
|
|
672 |
rect1.right = rect1.left + sizex;
|
|
673 |
rect1.bottom = rect1.top + sizey;
|
|
674 |
pDC->DrawText(sText, &rect1, nFormat);
|
|
675 |
return 0;
|
|
676 |
}
|
|
677 |
|
|
678 |
int CMTerm1View::DrawCellText2(CDC* pDC, CString sText, int x1, int y1, int sizex, int sizey, int nFormat, int nTextColor)
|
|
679 |
{
|
|
680 |
// TODO: 在此处添加实现代码.
|
|
681 |
COLORREF clrOld = pDC->SetTextColor(nTextColor);
|
|
682 |
CRect rect1;
|
|
683 |
rect1.left = x1;
|
|
684 |
rect1.top = y1;
|
|
685 |
rect1.right = rect1.left + sizex;
|
|
686 |
rect1.bottom = rect1.top + sizey;
|
|
687 |
pDC->DrawText(sText, &rect1, nFormat);
|
|
688 |
pDC->SetTextColor(clrOld);
|
|
689 |
return 0;
|
|
690 |
}
|
|
691 |
|
|
692 |
int CMTerm1View::DrawCellAnno(CDC * pDC, int nRow, int nCol, CString sAnno)
|
|
693 |
{
|
|
694 |
// TODO: 在此处添加实现代码.
|
|
695 |
if (!m_bShowComments) return 0;
|
|
696 |
if (!needReDraw) return 0;
|
|
697 |
CMTerm1Doc * pDoc = GetDocument();
|
|
698 |
int x0, y0;
|
|
699 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
700 |
x0 = m_LeftMargin + 1 + m_CellWidth * nCol;
|
|
701 |
y0 = m_TopMargin + CellTotalHeight * nRow;
|
|
702 |
|
|
703 |
int nType, nAddr;
|
|
704 |
nType = Cells[nRow][nCol].nDataType;
|
|
705 |
nAddr = Cells[nRow][nCol].nDataAddr;
|
|
706 |
CString s1;
|
|
707 |
if (pDoc->GetAnno(nType, nAddr, s1)) {
|
|
708 |
CFont *pOldFont;
|
|
709 |
pOldFont = (CFont *)pDC->SelectObject(&AnnoFont);
|
|
710 |
DrawCellText2(pDC, s1, x0 + 2, y0 + m_LinePosY + 6, m_CellWidth-10, 32, DT_WORDBREAK, AnnoColor);
|
|
711 |
pDC->SelectObject(pOldFont);
|
|
712 |
}
|
|
713 |
return 0;
|
|
714 |
}
|
|
715 |
|
|
716 |
void CMTerm1View::DrawCell(CDC* pDC, int nRow, int nCol)
|
|
717 |
{
|
|
718 |
|
|
719 |
//CMTerm1Doc * pDoc= GetDocument();
|
|
720 |
int x0, y0;
|
|
721 |
int x1, y1, x2, y2;
|
|
722 |
RECT rect1;
|
|
723 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
724 |
|
|
725 |
rect1.left = m_LeftMargin + 1 + m_CellWidth * nCol;
|
d34256
|
726 |
rect1.right = rect1.left + m_CellWidth;
|
418cb3
|
727 |
rect1.top = m_TopMargin + CellTotalHeight * nRow;
|
Q |
728 |
rect1.bottom = rect1.top + CellTotalHeight;
|
|
729 |
|
|
730 |
x0 = rect1.left;
|
|
731 |
y0 = rect1.top;
|
|
732 |
|
|
733 |
CString s1;
|
|
734 |
// pDC->DrawFocusRect(&rect1);
|
|
735 |
if (Cells[nRow][nCol].bLeftLineUp && nCol !=0)
|
|
736 |
{
|
|
737 |
if (needReDraw) {
|
|
738 |
pDC->MoveTo(x0, y0);
|
|
739 |
pDC->LineTo(x0, y0 + m_LinePosY);
|
ad1b4b
|
740 |
//画直竖线
|
Z |
741 |
//pDC->MoveTo(x0, y0 + (0.32 * CellTotalHeight));
|
|
742 |
//pDC->LineTo(x0, y0 - (0.69 * CellTotalHeight));
|
418cb3
|
743 |
}
|
Q |
744 |
}
|
|
745 |
if (Cells[nRow][nCol].bLeftLineDn && nCol != 0)
|
|
746 |
{
|
|
747 |
if (needReDraw) {
|
|
748 |
pDC->MoveTo(x0, y0 + m_LinePosY);
|
|
749 |
pDC->LineTo(x0, y0 + CellTotalHeight);
|
|
750 |
}
|
|
751 |
}
|
|
752 |
int nType = Cells[nRow][nCol].nType;
|
|
753 |
if (nType == typeNone)
|
|
754 |
{
|
|
755 |
|
|
756 |
}
|
|
757 |
else if (nType == typeLine1)
|
|
758 |
{ //Draw Line
|
|
759 |
//画直横线
|
|
760 |
if (needReDraw) {
|
|
761 |
pDC->MoveTo(x0, y0 + m_LinePosY);
|
|
762 |
pDC->LineTo(x0 + m_CellWidth, y0 + m_LinePosY);
|
|
763 |
}
|
|
764 |
}
|
|
765 |
else if (nType == typeLine2)
|
|
766 |
{ //Draw Line
|
ad1b4b
|
767 |
//画直竖线
|
Z |
768 |
pDC->MoveTo(x0, y0 + (0.32 * CellTotalHeight));
|
|
769 |
pDC->LineTo(x0, y0 - (0.69 * CellTotalHeight));
|
418cb3
|
770 |
}
|
Q |
771 |
else if (nType == typeNO)
|
|
772 |
{
|
|
773 |
// Draw Coil
|
|
774 |
if (needReDraw) {
|
|
775 |
DrawRelay(pDC, x0, y0);
|
|
776 |
//显示文字
|
|
777 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
778 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
779 |
}
|
|
780 |
if (m_bMonitoring){
|
|
781 |
//Draw Stat
|
|
782 |
DrawCellStat1(pDC, x0 + 16 + 2, y0 + m_LinePosY - 6, 8, 12, Cells[nRow][nCol].nStat);
|
|
783 |
// tracing
|
|
784 |
DrawCellStat2(pDC, x0 + 16 + 2 + 10 + 4, y0 + m_LinePosY - 4, 4, 4, Cells[nRow][nCol].nTrace);
|
|
785 |
}
|
|
786 |
}
|
|
787 |
else if (nType == typeNC)
|
|
788 |
{
|
|
789 |
if (needReDraw) {
|
|
790 |
DrawRelay(pDC, x0, y0);
|
|
791 |
//显示文字
|
|
792 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
793 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
794 |
//画常闭斜线
|
|
795 |
x1 = x0 + 16 + 12 - 3;
|
|
796 |
y1 = y0 + m_LinePosY - 6;
|
|
797 |
x2 = x0 + 16 + 2;
|
|
798 |
y2 = y1 + 12;
|
|
799 |
pDC->MoveTo(x1, y1);
|
|
800 |
pDC->LineTo(x2, y2);
|
|
801 |
}
|
|
802 |
if (m_bMonitoring)
|
|
803 |
{
|
|
804 |
//Draw Stat
|
|
805 |
DrawCellStat1(pDC, x0 + 16 + 2, y0 + m_LinePosY - 6, 8, 12, ! Cells[nRow][nCol].nStat);
|
|
806 |
// tracing
|
|
807 |
DrawCellStat2(pDC, x0 + 16 + 2 + 10 + 4, y0 + m_LinePosY - 4, 4, 4, Cells[nRow][nCol].nTrace);
|
|
808 |
//画常闭斜线
|
|
809 |
x1 = x0 + 16 + 12 - 3;
|
|
810 |
y1 = y0 + m_LinePosY - 6;
|
|
811 |
x2 = x0 + 16 + 2;
|
|
812 |
y2 = y1 + 12;
|
|
813 |
pDC->MoveTo(x1, y1);
|
|
814 |
pDC->LineTo(x2, y2);
|
|
815 |
}
|
|
816 |
}
|
|
817 |
else if (nType == typePP)
|
|
818 |
{
|
|
819 |
if (needReDraw) {
|
|
820 |
DrawRelay(pDC, x0, y0);
|
|
821 |
//画上升沿箭头
|
|
822 |
x1 = x0 + 16 + 6;
|
|
823 |
y1 = y0 + m_LinePosY - 5;
|
|
824 |
x2 = x1;
|
|
825 |
y2 = y1 + 10;
|
|
826 |
pDC->MoveTo(x1, y1);
|
|
827 |
pDC->LineTo(x2, y2);
|
|
828 |
//*
|
|
829 |
x2 = x1 - 3;
|
|
830 |
y2 = y1 + 4;
|
|
831 |
pDC->MoveTo(x1, y1);
|
|
832 |
pDC->LineTo(x2, y2);
|
|
833 |
x2 = x1 + 3;
|
|
834 |
y2 = y1 + 4;
|
|
835 |
pDC->MoveTo(x1, y1);
|
|
836 |
pDC->LineTo(x2, y2);
|
|
837 |
//*/
|
|
838 |
//显示文字
|
|
839 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
840 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
841 |
}
|
|
842 |
}
|
|
843 |
else if (nType == typePN)
|
|
844 |
{
|
|
845 |
if (needReDraw) {
|
|
846 |
DrawRelay(pDC, x0, y0);
|
|
847 |
//画下降沿箭头
|
|
848 |
x1 = x0 + 16 + 6;
|
|
849 |
y1 = y0 + m_LinePosY + 5;
|
|
850 |
x2 = x1;
|
|
851 |
y2 = y1 - 10;
|
|
852 |
pDC->MoveTo(x1, y1);
|
|
853 |
pDC->LineTo(x2, y2);
|
|
854 |
//*
|
|
855 |
x2 = x1 - 3;
|
|
856 |
y2 = y1 - 3;
|
|
857 |
pDC->MoveTo(x1, y1);
|
|
858 |
pDC->LineTo(x2, y2);
|
|
859 |
|
|
860 |
x2 = x1 + 3;
|
|
861 |
y2 = y1 - 3;
|
|
862 |
pDC->MoveTo(x1, y1);
|
|
863 |
pDC->LineTo(x2, y2);
|
|
864 |
//*/
|
|
865 |
//显示文字
|
|
866 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
867 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
868 |
}
|
|
869 |
}
|
|
870 |
else if (nType == typeNOT) {
|
|
871 |
if (needReDraw) {
|
|
872 |
DrawLeftRightLine(pDC, x0, y0);
|
|
873 |
//画常闭斜线
|
|
874 |
x1 = x0 + 16 + 12 - 3;
|
|
875 |
y1 = y0 + m_LinePosY - 6;
|
|
876 |
x2 = x0 + 16 + 2;
|
|
877 |
y2 = y1 + 12;
|
|
878 |
pDC->MoveTo(x1, y1);
|
|
879 |
pDC->LineTo(x2, y2);
|
|
880 |
//显示文字
|
|
881 |
// DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
882 |
}
|
|
883 |
}
|
|
884 |
else if (nType == typeDF) {
|
|
885 |
if (needReDraw) {
|
|
886 |
// DrawLeftRightLine(pDC, x0, y0);
|
|
887 |
DrawAngleBracket(pDC, x0, y0, 8, 32);
|
|
888 |
//显示文字
|
|
889 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 16, y0 + m_LinePosY - 8, 16, 14);
|
|
890 |
}
|
|
891 |
}
|
|
892 |
else if (nType == typeDF_) {
|
|
893 |
if (needReDraw) {
|
|
894 |
// DrawLeftRightLine(pDC, x0, y0);
|
|
895 |
DrawAngleBracket(pDC, x0, y0, 8, 40);
|
|
896 |
//显示文字
|
|
897 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 16, y0 + m_LinePosY - 8, 24, 14);
|
|
898 |
}
|
|
899 |
}
|
|
900 |
else if (nType == typeOUT) {
|
|
901 |
if (needReDraw) {
|
|
902 |
//显示外形
|
|
903 |
DrawOT(pDC, x0, y0);
|
|
904 |
//显示文字
|
|
905 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
906 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
907 |
}
|
|
908 |
if (m_bMonitoring) {
|
|
909 |
//Draw Stat
|
|
910 |
DrawCellStat1(pDC, x0 + 16 + 2, y0 + m_LinePosY - 6, 8, 12, Cells[nRow][nCol].nStat);
|
|
911 |
}
|
|
912 |
}
|
|
913 |
else if (nType == typeSET) {
|
|
914 |
|
|
915 |
if (needReDraw) {
|
|
916 |
//画左侧横线
|
|
917 |
//DrawLeftRightLine(pDC, x0, y0, 14, 18);
|
|
918 |
DrawAngleBracket(pDC, x0, y0, 8, 32);
|
|
919 |
DrawCellText1(pDC, _T("S"), x0 + 18, y0 + m_LinePosY - 8, 8, 14);
|
|
920 |
//显示文字
|
|
921 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
922 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
923 |
}
|
|
924 |
if (m_bMonitoring) {
|
|
925 |
//Draw Stat
|
|
926 |
DrawCellStat1(pDC, x0 + 14, y0 + m_LinePosY - 8, 16, 16, Cells[nRow][nCol].nStat);
|
|
927 |
DrawCellText1(pDC, _T("S"), x0 + 18, y0 + m_LinePosY - 8, 8, 14);
|
|
928 |
}
|
|
929 |
|
|
930 |
}
|
|
931 |
else if (nType == typeRESET) {
|
|
932 |
if (needReDraw) {
|
|
933 |
//画左右侧横线
|
|
934 |
//DrawLeftRightLine(pDC, x0, y0, 14, 18);
|
|
935 |
DrawAngleBracket(pDC, x0, y0, 8, 32);
|
|
936 |
DrawCellText1(pDC, _T("R"), x0 + 17, y0 + m_LinePosY - 8, 9, 14);
|
|
937 |
//显示文字
|
|
938 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 2, y0, m_CellWidth, 14);
|
|
939 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
940 |
}
|
|
941 |
if (m_bMonitoring) {
|
|
942 |
//Draw Stat
|
|
943 |
DrawCellStat1(pDC, x0 + 14, y0 + m_LinePosY - 8, 16, 16, Cells[nRow][nCol].nStat);
|
|
944 |
DrawCellText1(pDC, _T("R"), x0 + 17, y0 + m_LinePosY - 8, 9, 14);
|
|
945 |
}
|
|
946 |
}
|
|
947 |
else if (nType == typeCMP) {
|
|
948 |
if (needReDraw) {
|
|
949 |
// 画中括号
|
|
950 |
DrawBracket(pDC, x0, y0, m_CellWidth * 3);
|
|
951 |
//显示文字
|
|
952 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 12, y0, m_CellWidth, 14);
|
|
953 |
DrawCellText1(pDC, Cells[nRow][nCol + 1].sParam, x0 + m_CellWidth + 2, y0, m_CellWidth, 14);
|
|
954 |
DrawCellText1(pDC, Cells[nRow][nCol + 2].sParam, x0 + m_CellWidth * 2 + 2, y0, m_CellWidth, 14);
|
|
955 |
DrawCellAnno(pDC, nRow, nCol + 1, _T(""));
|
|
956 |
DrawCellAnno(pDC, nRow, nCol + 2, _T(""));
|
|
957 |
}
|
|
958 |
if (m_bMonitoring) {
|
|
959 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 1].nStat);
|
|
960 |
DrawCellText2(pDC, s1,x0+m_CellWidth+2,y0+m_LinePosY-6,m_CellWidth-10,14,DT_RIGHT, MonTextColor);
|
|
961 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 2].nStat);
|
|
962 |
DrawCellText2(pDC, s1, x0 + m_CellWidth*2 + 2, y0 + m_LinePosY - 6, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
963 |
// tracing
|
|
964 |
DrawCellStat2(pDC, x0 + m_CellWidth * 3 - 4, y0 + m_LinePosY - 8, 4, 4, Cells[nRow][nCol].nTrace);
|
|
965 |
}
|
|
966 |
}
|
|
967 |
else if (nType == typeTM) {
|
|
968 |
if (needReDraw) {
|
|
969 |
// 画中括号
|
|
970 |
DrawBracket(pDC, x0, y0, m_CellWidth * 3);
|
|
971 |
//显示文字
|
|
972 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 12, y0, m_CellWidth, 14);
|
|
973 |
DrawCellText1(pDC, Cells[nRow][nCol + 1].sParam, x0 + m_CellWidth + 2, y0, m_CellWidth, 14);
|
|
974 |
DrawCellText1(pDC, Cells[nRow][nCol + 2].sParam, x0 + m_CellWidth * 2 + 2, y0, m_CellWidth, 14);
|
|
975 |
DrawCellAnno(pDC, nRow, nCol, _T(""));
|
|
976 |
DrawCellAnno(pDC, nRow, nCol + 1, _T(""));
|
|
977 |
DrawCellAnno(pDC, nRow, nCol + 2, _T(""));
|
|
978 |
}
|
|
979 |
if (m_bMonitoring) {
|
|
980 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 1].nStat);
|
|
981 |
DrawCellText2(pDC, s1, x0 + m_CellWidth + 2, y0 + m_LinePosY - 6, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
982 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 2].nStat);
|
|
983 |
DrawCellText2(pDC, s1, x0 + m_CellWidth * 2 + 2, y0 + m_LinePosY - 6, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
984 |
// tracing
|
|
985 |
DrawCellStat2(pDC, x0 + m_CellWidth * 3 - 4, y0 + m_LinePosY - 8, 4, 4, Cells[nRow][nCol].nTrace);
|
|
986 |
}
|
|
987 |
}
|
|
988 |
else if (nType == typeFN1) {
|
|
989 |
if (needReDraw) {
|
|
990 |
|
|
991 |
// 画中括号
|
|
992 |
DrawBracket(pDC, x0, y0, m_CellWidth * 2, m_LinePosY - 8, 16);
|
|
993 |
//显示文字
|
|
994 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 12, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
995 |
DrawCellText1(pDC, Cells[nRow][nCol + 1].sParam, x0 + m_CellWidth + 2, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
996 |
DrawCellAnno(pDC, nRow, nCol + 1, _T(""));
|
|
997 |
}
|
|
998 |
if (m_bMonitoring) {
|
|
999 |
|
|
1000 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 1].nStat);
|
|
1001 |
DrawCellText2(pDC, s1, x0 + m_CellWidth + 2, y0 , m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
1002 |
// tracing
|
|
1003 |
DrawCellStat2(pDC, x0 + m_CellWidth * 2 - 4, y0 + m_LinePosY - 8, 4, 4, Cells[nRow][nCol].nTrace);
|
|
1004 |
}
|
|
1005 |
}
|
|
1006 |
else if (nType == typeFN2) {
|
|
1007 |
if (needReDraw) {
|
|
1008 |
// 画中括号
|
|
1009 |
DrawBracket(pDC, x0, y0, m_CellWidth * 3, m_LinePosY - 8, 16);
|
|
1010 |
//显示文字
|
|
1011 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 12, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1012 |
DrawCellText1(pDC, Cells[nRow][nCol + 1].sParam, x0 + m_CellWidth + 2, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1013 |
DrawCellText1(pDC, Cells[nRow][nCol + 2].sParam, x0 + m_CellWidth * 2 + 2, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1014 |
DrawCellAnno(pDC, nRow, nCol + 1, _T(""));
|
|
1015 |
DrawCellAnno(pDC, nRow, nCol + 2, _T(""));
|
|
1016 |
}
|
|
1017 |
if (m_bMonitoring) {
|
|
1018 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 1].nStat);
|
|
1019 |
DrawCellText2(pDC, s1, x0 + m_CellWidth + 2, y0, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
1020 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 2].nStat);
|
|
1021 |
DrawCellText2(pDC, s1, x0 + m_CellWidth * 2 + 2, y0, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
1022 |
// tracing
|
|
1023 |
DrawCellStat2(pDC, x0 + m_CellWidth * 3 - 4, y0 + m_LinePosY - 8, 4, 4, Cells[nRow][nCol].nTrace);
|
|
1024 |
}
|
|
1025 |
}
|
|
1026 |
else if (nType == typeFN3) {
|
|
1027 |
if (needReDraw) {
|
|
1028 |
// 画中括号
|
|
1029 |
DrawBracket(pDC, x0, y0, m_CellWidth * 4, m_LinePosY - 8, 16);
|
|
1030 |
//显示文字
|
|
1031 |
DrawCellText1(pDC, Cells[nRow][nCol].sCoilName, x0 + 12, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1032 |
DrawCellText1(pDC, Cells[nRow][nCol + 1].sParam, x0 + m_CellWidth + 2, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1033 |
DrawCellText1(pDC, Cells[nRow][nCol + 2].sParam, x0 + m_CellWidth * 2 + 2, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1034 |
DrawCellText1(pDC, Cells[nRow][nCol + 3].sParam, x0 + m_CellWidth * 3 + 2, y0 + m_LinePosY - 6, m_CellWidth, 14);
|
|
1035 |
DrawCellAnno(pDC, nRow, nCol + 1, _T(""));
|
|
1036 |
DrawCellAnno(pDC, nRow, nCol + 2, _T(""));
|
|
1037 |
DrawCellAnno(pDC, nRow, nCol + 3, _T(""));
|
|
1038 |
}
|
|
1039 |
if (m_bMonitoring) {
|
|
1040 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 1].nStat);
|
|
1041 |
DrawCellText2(pDC, s1, x0 + m_CellWidth + 2, y0, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
1042 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 2].nStat);
|
|
1043 |
DrawCellText2(pDC, s1, x0 + m_CellWidth * 2 + 2, y0, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
1044 |
s1.Format(_T(" %d"), Cells[nRow][nCol + 3].nStat);
|
|
1045 |
DrawCellText2(pDC, s1, x0 + m_CellWidth * 3 + 2, y0, m_CellWidth - 10, 14, DT_RIGHT, MonTextColor);
|
|
1046 |
// tracing
|
|
1047 |
DrawCellStat2(pDC, x0 + m_CellWidth * 4 - 4, y0 + m_LinePosY - 8, 4, 4, Cells[nRow][nCol].nTrace);
|
|
1048 |
}
|
|
1049 |
}
|
|
1050 |
else
|
|
1051 |
{
|
|
1052 |
}
|
|
1053 |
}
|
0ed438
|
1054 |
|
Q |
1055 |
// CMTerm1View 消息处理程序
|
418cb3
|
1056 |
|
Q |
1057 |
void CMTerm1View::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/)
|
|
1058 |
{
|
|
1059 |
// TODO: 在此添加专用代码和/或调用基类
|
|
1060 |
//初始化 cell 内容
|
|
1061 |
if (lHint == 0 || lHint == 1)
|
|
1062 |
{
|
|
1063 |
TransProgToLDS();
|
|
1064 |
CRect rect0;
|
|
1065 |
this->GetClientRect(&rect0);
|
|
1066 |
|
|
1067 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1068 |
|
|
1069 |
CSize sizeTotal;
|
|
1070 |
// TODO: 计算此视图的合计大小
|
|
1071 |
sizeTotal.cx = m_LeftMargin + m_CellWidth * m_CellPerLine + m_CellWidth * 2;
|
|
1072 |
sizeTotal.cy = m_TopMargin + CellTotalHeight * (m_nTotalRow - 1) + rect0.Height();
|
|
1073 |
SetScrollSizes(MM_TEXT, sizeTotal);
|
|
1074 |
needReDraw = 1;
|
|
1075 |
this->RedrawWindow();
|
|
1076 |
}
|
|
1077 |
else if (lHint == 2) {
|
|
1078 |
UpdateStatusBar();
|
|
1079 |
}
|
|
1080 |
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
BOOL CMTerm1View::OnEraseBkgnd(CDC* pDC)
|
|
1084 |
{
|
|
1085 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1086 |
return true;
|
|
1087 |
return CScrollView::OnEraseBkgnd(pDC);
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
void CMTerm1View::OnSize(UINT nType, int cx, int cy)
|
|
1091 |
{
|
|
1092 |
CScrollView::OnSize(nType, cx, cy);
|
|
1093 |
// CString s1;
|
|
1094 |
// s1.Format(_T("OnSize %d %d %d"), nType, cx, cy);
|
|
1095 |
// DbgLog(s1);
|
|
1096 |
|
|
1097 |
if (this->IsWindowVisible())
|
|
1098 |
{
|
|
1099 |
CRect rect0;
|
|
1100 |
this->GetClientRect(&rect0);
|
|
1101 |
|
|
1102 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1103 |
|
|
1104 |
CSize sizeTotal;
|
|
1105 |
// TODO: 计算此视图的合计大小
|
|
1106 |
sizeTotal.cx = m_LeftMargin + m_CellWidth * m_CellPerLine + m_CellWidth * 2;
|
|
1107 |
sizeTotal.cy = m_TopMargin + CellTotalHeight * (m_nTotalRow - 1) + rect0.Height();
|
|
1108 |
SetScrollSizes(MM_TEXT, sizeTotal);
|
|
1109 |
needReDraw = 1;
|
|
1110 |
this->RedrawWindow();
|
|
1111 |
}
|
|
1112 |
|
|
1113 |
needReDraw = 1;
|
|
1114 |
// TODO: 在此处添加消息处理程序代码
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
BOOL CMTerm1View::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
|
|
1118 |
{
|
|
1119 |
// TODO: 在此添加专用代码和/或调用基类
|
|
1120 |
needReDraw = 1;
|
|
1121 |
return CScrollView::OnScrollBy(sizeScroll, bDoScroll);
|
|
1122 |
}
|
|
1123 |
|
|
1124 |
void CMTerm1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
|
|
1125 |
{
|
|
1126 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1127 |
CString s1;
|
|
1128 |
// s1.Format(_T("KeyDown %d %d %d"), nChar, nRepCnt, nFlags);
|
|
1129 |
// DbgLog(s1);
|
|
1130 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1131 |
|
|
1132 |
CRect rect0;
|
|
1133 |
this->GetClientRect(&rect0);
|
|
1134 |
int viewWidth = rect0.Width();
|
|
1135 |
CPoint scroll1;
|
|
1136 |
scroll1 = this->GetScrollPosition();
|
|
1137 |
|
|
1138 |
int nFirstVisibleLine;
|
|
1139 |
int nLastVisibleLine;
|
|
1140 |
int nLinesinView;
|
|
1141 |
nFirstVisibleLine = (scroll1.y - m_TopMargin) / CellTotalHeight;
|
|
1142 |
nLastVisibleLine = (rect0.Height() + scroll1.y - m_TopMargin) / CellTotalHeight + 1;
|
|
1143 |
if (nFirstVisibleLine < 0) { nFirstVisibleLine = 0; }
|
|
1144 |
if (nLastVisibleLine < 0) { nLastVisibleLine = 0; }
|
|
1145 |
nLinesinView = nLastVisibleLine - 1 - nFirstVisibleLine;
|
|
1146 |
int nRow, nCol;
|
|
1147 |
nRow = m_FocusRow;
|
|
1148 |
nCol = m_FocusCol;
|
|
1149 |
if (nChar == VK_LEFT) {
|
|
1150 |
nCol -= 1;
|
|
1151 |
if (nCol < 0) {
|
|
1152 |
if (nRow > 0) {
|
|
1153 |
nRow -= 1; nCol += m_CellPerLine;
|
|
1154 |
}else {
|
|
1155 |
nCol = 0;
|
|
1156 |
}
|
|
1157 |
}
|
4ed7fc
|
1158 |
CellFocusChg(nRow, nCol);
|
418cb3
|
1159 |
}
|
Q |
1160 |
if (nChar == VK_RIGHT) {
|
|
1161 |
nCol += 1;
|
|
1162 |
if (nCol >= m_CellPerLine) {
|
|
1163 |
if (nRow < m_nTotalRow + nLinesinView - 1 ) {
|
|
1164 |
nCol -= m_CellPerLine;
|
|
1165 |
nRow += 1;
|
|
1166 |
}
|
|
1167 |
else {
|
|
1168 |
nCol = m_CellPerLine - 1;
|
|
1169 |
}
|
|
1170 |
}
|
4ed7fc
|
1171 |
CellFocusChg(nRow, nCol);
|
418cb3
|
1172 |
}
|
Q |
1173 |
if (nChar == VK_UP) {
|
|
1174 |
nRow -= 1;
|
|
1175 |
if (nRow < 0) { nRow = 0; }
|
4ed7fc
|
1176 |
CellFocusChg(nRow, nCol);
|
418cb3
|
1177 |
}
|
Q |
1178 |
if (nChar == VK_DOWN) {
|
|
1179 |
nRow += 1;
|
|
1180 |
if (nRow >= m_nTotalRow + nLinesinView) { nRow = m_nTotalRow + nLinesinView -1; }
|
4ed7fc
|
1181 |
CellFocusChg(nRow, nCol);
|
418cb3
|
1182 |
}
|
Q |
1183 |
m_FocusRow = nRow;
|
|
1184 |
m_FocusCol = nCol;
|
|
1185 |
if (Cells[nRow][nCol].nType) {
|
|
1186 |
m_nCurProgStep = Cells[nRow][nCol].nProgStep;
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
if (nRow < nFirstVisibleLine) {
|
|
1190 |
scroll1.y -= CellTotalHeight;
|
|
1191 |
ScrollToPosition(scroll1);
|
|
1192 |
}
|
|
1193 |
if (nRow > 0 && nRow >= nLastVisibleLine - 1 ) {
|
|
1194 |
scroll1.y += CellTotalHeight;
|
|
1195 |
ScrollToPosition(scroll1);
|
|
1196 |
}
|
|
1197 |
|
|
1198 |
// DrawFocusRect();
|
|
1199 |
GetDocument()->UpdateAllViews(this, m_FocusCol);
|
|
1200 |
needReDraw = 1;
|
|
1201 |
this->RedrawWindow();
|
|
1202 |
UpdateStatusBar();
|
|
1203 |
|
|
1204 |
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
|
|
1205 |
}
|
d34256
|
1206 |
|
Z |
1207 |
/// <summary>
|
|
1208 |
/// 单元格焦点变化*选中点变化
|
|
1209 |
/// </summary>
|
|
1210 |
/// <param name="nRow"></param>
|
|
1211 |
/// <param name="nCol"></param>
|
|
1212 |
/// <returns></returns>
|
df0321
|
1213 |
int CMTerm1View::CellFocusChg(int nRow, int nCol)
|
Q |
1214 |
{
|
|
1215 |
CString s1;
|
|
1216 |
stCell & thecell = Cells[nRow][nCol];
|
|
1217 |
s1.Format(_T("Cell %d %d Type %02X \r\n"), nRow, nCol, thecell.nType);
|
|
1218 |
s1.AppendFormat(_T(" sCoilName %s sParam %s \r\n"), thecell.sCoilName, thecell.sParam );
|
|
1219 |
s1.AppendFormat(_T("LeftUp %d leftDn %d "), thecell.bLeftLineUp, thecell.bLeftLineDn);
|
|
1220 |
DbgLog(s1);
|
|
1221 |
|
|
1222 |
auto p1 = (CMainFrame*)AfxGetMainWnd();
|
|
1223 |
auto p2 = p1->GetInputWnd();
|
ad1b4b
|
1224 |
p2->SetCurCellPos(nRow,nCol,thecell);
|
Z |
1225 |
p2->focusCell = thecell;
|
df0321
|
1226 |
return 0;
|
Q |
1227 |
}
|
ad1b4b
|
1228 |
//鼠标左键点击事件
|
418cb3
|
1229 |
void CMTerm1View::OnLButtonDown(UINT nFlags, CPoint point)
|
Q |
1230 |
{
|
|
1231 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1232 |
CString s1;
|
|
1233 |
CPoint scroll1;
|
|
1234 |
scroll1 = this->GetScrollPosition();
|
|
1235 |
int tx, ty;
|
|
1236 |
tx = point.x + scroll1.x;
|
|
1237 |
ty = point.y + scroll1.y;
|
|
1238 |
int nRow, nCol;
|
|
1239 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1240 |
nRow = (ty - m_TopMargin) / CellTotalHeight;
|
|
1241 |
nCol = (tx - m_LeftMargin) / m_CellWidth;
|
d34256
|
1242 |
if (nRow < 0)
|
Z |
1243 |
{
|
|
1244 |
nRow = 0;
|
|
1245 |
}
|
|
1246 |
if (nCol < 0)
|
|
1247 |
{
|
|
1248 |
nCol = 0;
|
|
1249 |
}
|
|
1250 |
if (nCol >= m_CellPerLine)
|
|
1251 |
{
|
|
1252 |
nCol = m_CellPerLine - 1;
|
|
1253 |
}
|
|
1254 |
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);
|
|
1255 |
DbgLog(s1);//zxd add to test
|
|
1256 |
|
418cb3
|
1257 |
m_pStatusBar->SetPaneText(6, s1);
|
Q |
1258 |
m_FocusRow = nRow;
|
|
1259 |
m_FocusCol = nCol;
|
|
1260 |
if (Cells[nRow][nCol].nType) {
|
|
1261 |
m_nCurProgStep = Cells[nRow][nCol].nProgStep;
|
|
1262 |
}
|
|
1263 |
|
|
1264 |
// DrawFocusRect();
|
df0321
|
1265 |
CellFocusChg(nRow, nCol);
|
418cb3
|
1266 |
GetDocument()->UpdateAllViews(this, m_FocusCol);
|
Q |
1267 |
needReDraw = 1;
|
|
1268 |
this->RedrawWindow();
|
|
1269 |
UpdateStatusBar();
|
|
1270 |
// m_pStatusBar->Set
|
|
1271 |
CScrollView::OnLButtonDown(nFlags, point);
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
void CMTerm1View::OnLButtonUp(UINT nFlags, CPoint point)
|
|
1275 |
{
|
|
1276 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1277 |
|
|
1278 |
CScrollView::OnLButtonUp(nFlags, point);
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
void CMTerm1View::OnLButtonDblClk(UINT nFlags, CPoint point)
|
|
1282 |
{
|
|
1283 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1284 |
CString s1;
|
|
1285 |
CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
|
|
1286 |
CPoint scroll1;
|
|
1287 |
scroll1 = this->GetScrollPosition();
|
|
1288 |
int tx, ty;
|
|
1289 |
tx = point.x + scroll1.x;
|
|
1290 |
ty = point.y + scroll1.y;
|
|
1291 |
|
|
1292 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1293 |
int nRow = (ty - m_TopMargin) / CellTotalHeight;
|
|
1294 |
int nCol = (tx - m_LeftMargin) / m_CellWidth;
|
|
1295 |
|
|
1296 |
if (nRow < 0) { nRow = 0; }
|
|
1297 |
if (nCol < 0) { nCol = 0; }
|
|
1298 |
if (nCol >= m_CellPerLine) { nCol = m_CellPerLine - 1; }
|
|
1299 |
s1.Format(_T("LD db Clk %d %d %02X Scroll %d %d Total %d %d Row %d Col %d"),
|
|
1300 |
point.x, point.y, nFlags, scroll1.x, scroll1.y, tx, ty, nRow, nCol);
|
|
1301 |
m_pStatusBar->SetPaneText(6, s1);
|
|
1302 |
m_pStatusBar->SetPaneBackgroundColor(6, RGB(255, 255, 0));
|
|
1303 |
m_pStatusBar->SetPaneTextColor(6, RGB(0, 0, 255));
|
|
1304 |
m_pStatusBar->EnablePaneProgressBar(6);
|
|
1305 |
m_pStatusBar->SetPaneProgress(6, 5);
|
|
1306 |
SysLog(s1);
|
|
1307 |
|
|
1308 |
m_FocusRow = nRow;
|
|
1309 |
m_FocusCol = nCol;
|
|
1310 |
if (Cells[nRow][nCol].nType) {
|
|
1311 |
m_nCurProgStep = Cells[nRow][nCol].nProgStep;
|
|
1312 |
}
|
|
1313 |
if (!pDoc->m_bOnline) return;
|
|
1314 |
//if (!m_bMonitoring) return;
|
|
1315 |
|
|
1316 |
CString sParam;
|
|
1317 |
sParam = Cells[nRow][nCol].sParam;
|
|
1318 |
int nDataType, nDataAddr, nStat;
|
|
1319 |
nDataType = Cells[nRow][nCol].nDataType;
|
|
1320 |
nDataAddr = Cells[nRow][nCol].nDataAddr;
|
|
1321 |
nStat = Cells[nRow][nCol].nStat;
|
|
1322 |
|
|
1323 |
s1.Format(_T("Name %s DataType %d DataAddr %d Stat %d"),
|
|
1324 |
sParam, nDataType, nDataAddr, nStat);
|
|
1325 |
SysLog(s1);
|
|
1326 |
if (Cells[m_FocusRow][m_FocusCol].sParam == _T("")) {
|
|
1327 |
return;
|
|
1328 |
}
|
|
1329 |
needReDraw = 1;
|
|
1330 |
if ((nDataType&TYPEDATA) == TYPEDATA) {
|
|
1331 |
CDialogSetData dialog2;
|
|
1332 |
|
|
1333 |
dialog2.m_strAddr = sParam;
|
|
1334 |
dialog2.m_nStat = nStat;
|
|
1335 |
|
|
1336 |
INT_PTR r = dialog2.DoModal();
|
|
1337 |
if (r == IDOK)
|
|
1338 |
{
|
|
1339 |
int s = dialog2.m_nStat;
|
|
1340 |
///
|
|
1341 |
pDoc->SetVarData(nDataType, nDataAddr, s);
|
|
1342 |
//Cells[nRow][nCol].nStat = s;
|
|
1343 |
s1.Format(_T("Set Data %s as %d "), sParam, s);
|
|
1344 |
SysLog(s1);
|
|
1345 |
this->RedrawWindow();
|
|
1346 |
}
|
|
1347 |
}
|
|
1348 |
else {
|
|
1349 |
CDialogSetCoil dialog1;
|
|
1350 |
|
|
1351 |
dialog1.m_strAddr = sParam;
|
|
1352 |
dialog1.m_nStat = nStat;
|
|
1353 |
|
|
1354 |
INT_PTR r = dialog1.DoModal();
|
|
1355 |
if (r == IDOK)
|
|
1356 |
{
|
|
1357 |
int s = dialog1.m_nStat;
|
|
1358 |
///
|
|
1359 |
pDoc->SetCoilValue(nDataType, nDataAddr, s);
|
|
1360 |
// Cells[nRow][nCol].nStat = nStat;
|
|
1361 |
|
|
1362 |
// Cells[m_FocusRow][m_FocusCol].nStat = s;
|
|
1363 |
// s1.Format(_T("Set Coild %s as %d "), sParam, s);
|
|
1364 |
// AfxMessageBox(s1);
|
|
1365 |
this->RedrawWindow();
|
|
1366 |
}
|
|
1367 |
}
|
|
1368 |
CScrollView::OnLButtonDblClk(nFlags, point);
|
|
1369 |
}
|
|
1370 |
|
|
1371 |
void CMTerm1View::OnRButtonDown(UINT nFlags, CPoint point)
|
|
1372 |
{
|
|
1373 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1374 |
CString s1;
|
|
1375 |
CPoint scroll1;
|
|
1376 |
scroll1 = this->GetScrollPosition();
|
|
1377 |
int tx, ty;
|
|
1378 |
tx = point.x + scroll1.x;
|
|
1379 |
ty = point.y + scroll1.y;
|
|
1380 |
|
|
1381 |
int nRow, nCol;
|
|
1382 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1383 |
nRow = (ty- m_TopMargin )/ CellTotalHeight;
|
|
1384 |
nCol = (tx - m_LeftMargin) / m_CellWidth;
|
|
1385 |
|
|
1386 |
if (nRow < 0) { nRow = 0; }
|
|
1387 |
if (nCol < 0) { nCol = 0; }
|
|
1388 |
if (nCol >= m_CellPerLine) { nCol = m_CellPerLine - 1; }
|
|
1389 |
s1.Format(_T("RD %d %d %02X Scroll %d %d Total %d %d Row %d Col %d"), point.x, point.y, nFlags, scroll1.x, scroll1.y, tx, ty, m_FocusRow, m_FocusCol);
|
|
1390 |
m_pStatusBar->SetPaneText(6, s1);
|
|
1391 |
m_FocusRow = nRow;
|
|
1392 |
m_FocusCol = nCol;
|
|
1393 |
// DrawFocusRect();
|
|
1394 |
GetDocument()->UpdateAllViews(this, m_FocusCol);
|
|
1395 |
needReDraw = 1;
|
|
1396 |
this->RedrawWindow();
|
|
1397 |
|
|
1398 |
CScrollView::OnRButtonDown(nFlags, point);
|
|
1399 |
}
|
|
1400 |
|
|
1401 |
void CMTerm1View::OnRButtonUp(UINT nFlags, CPoint point)
|
|
1402 |
{
|
|
1403 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1404 |
//CContextMenuManager
|
|
1405 |
CScrollView::OnRButtonUp(nFlags, point);
|
|
1406 |
}
|
|
1407 |
|
|
1408 |
void CMTerm1View::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
|
|
1409 |
{
|
|
1410 |
// TODO: 在此处添加消息处理程序代码
|
|
1411 |
CMenu menu1;
|
|
1412 |
menu1.LoadMenu(IDR_MENU1);
|
|
1413 |
CMenu *pContextMenu = menu1.GetSubMenu(0);
|
|
1414 |
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
|
|
1415 |
}
|
|
1416 |
|
|
1417 |
void CMTerm1View::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
|
|
1418 |
{
|
|
1419 |
CScrollView::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
|
|
1420 |
|
|
1421 |
// TODO: 在此处添加消息处理程序代码
|
|
1422 |
if (!bSysMenu && pPopupMenu)
|
|
1423 |
{
|
|
1424 |
CCmdUI cmdUI;
|
|
1425 |
cmdUI.m_pOther = NULL;
|
|
1426 |
cmdUI.m_pMenu = pPopupMenu;
|
|
1427 |
cmdUI.m_pSubMenu = NULL;
|
|
1428 |
|
|
1429 |
|
|
1430 |
UINT count = pPopupMenu->GetMenuItemCount();
|
|
1431 |
cmdUI.m_nIndexMax = count;
|
|
1432 |
for (UINT i = 0; i < count; i++)
|
|
1433 |
{
|
|
1434 |
UINT nID = pPopupMenu->GetMenuItemID(i);
|
|
1435 |
if (-1 == nID || 0 == nID)
|
|
1436 |
{
|
|
1437 |
continue;
|
|
1438 |
}
|
|
1439 |
cmdUI.m_nID = nID;
|
|
1440 |
cmdUI.m_nIndex = i;
|
|
1441 |
cmdUI.DoUpdate(this, FALSE);
|
|
1442 |
}
|
|
1443 |
}
|
|
1444 |
}
|
|
1445 |
|
|
1446 |
void CMTerm1View::OnTimer(UINT_PTR nIDEvent)
|
|
1447 |
{
|
|
1448 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
1449 |
CString s1;
|
|
1450 |
CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
|
|
1451 |
|
|
1452 |
if (nIDEvent == 0) {
|
|
1453 |
|
|
1454 |
}
|
|
1455 |
else if (nIDEvent == 1)
|
|
1456 |
{
|
|
1457 |
if (m_bMonitoring) {
|
|
1458 |
//this->RedrawWindow();
|
|
1459 |
DoReDraw();
|
|
1460 |
}
|
|
1461 |
}
|
|
1462 |
else if (nIDEvent == 2) {
|
|
1463 |
pDoc->OnTimer(2);
|
|
1464 |
}
|
|
1465 |
else {
|
|
1466 |
|
|
1467 |
}
|
|
1468 |
CScrollView::OnTimer(nIDEvent);
|
|
1469 |
}
|
|
1470 |
|
|
1471 |
void CMTerm1View::OnMonitor()
|
|
1472 |
{
|
|
1473 |
// TODO: 在此添加命令处理程序代码
|
|
1474 |
m_bMonitoring = !m_bMonitoring;
|
|
1475 |
this->RedrawWindow();
|
|
1476 |
UpdateStatusBar();
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
void CMTerm1View::OnUpdateMonitor(CCmdUI *pCmdUI)
|
|
1480 |
{
|
|
1481 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1482 |
pCmdUI->SetCheck(m_bMonitoring == true);
|
|
1483 |
}
|
|
1484 |
|
ad1b4b
|
1485 |
/// <summary>
|
Z |
1486 |
/// 程序转换按钮点击
|
|
1487 |
/// </summary>
|
418cb3
|
1488 |
void CMTerm1View::OnProgConvert()
|
Q |
1489 |
{
|
e55aec
|
1490 |
//转换前先对LDS的规则进行检验(检验规则与返回参数并未完全确定
|
4ed7fc
|
1491 |
// std::pair<int,CString> result = LDSCheckRule();
|
Z |
1492 |
//if (result.first == 111)
|
|
1493 |
//{
|
|
1494 |
// DbgLog(result.second);
|
|
1495 |
// return;
|
|
1496 |
//}
|
e55aec
|
1497 |
|
418cb3
|
1498 |
CString s1;
|
Q |
1499 |
s1.Format(_T("Prog Convert"));
|
4ed7fc
|
1500 |
SysLog(s1);
|
418cb3
|
1501 |
int r = TransLDSToProg();
|
Q |
1502 |
s1.Format(_T("LDS To Prog result %d"), r);
|
|
1503 |
SysLog(s1);
|
e55aec
|
1504 |
if (r==0)
|
Z |
1505 |
{
|
418cb3
|
1506 |
// m_bModified = 0;
|
Q |
1507 |
int j=TransProgToLDS();
|
|
1508 |
s1.Format(_T("Porg to LDS retuls %d"), j);
|
|
1509 |
SysLog(s1);
|
|
1510 |
needReDraw = 1;
|
|
1511 |
RedrawWindow();
|
|
1512 |
}
|
|
1513 |
else {
|
|
1514 |
s1.Format(_T("Error in Prog Convert"));
|
|
1515 |
SysLog(s1);
|
|
1516 |
}
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
void CMTerm1View::OnUpdateProgConvert(CCmdUI *pCmdUI)
|
|
1520 |
{
|
|
1521 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1522 |
pCmdUI->SetCheck(0);
|
|
1523 |
pCmdUI->Enable(m_bModified);
|
|
1524 |
}
|
|
1525 |
|
|
1526 |
void CMTerm1View::OnProgCancelEdit()
|
|
1527 |
{
|
|
1528 |
CString s1;
|
|
1529 |
s1.Format(_T("Prog Cancel Edit"));
|
|
1530 |
SysLog(s1);
|
|
1531 |
// TODO: 在此添加命令处理程序代码
|
|
1532 |
}
|
|
1533 |
|
|
1534 |
|
|
1535 |
void CMTerm1View::OnUpdateProgCancelEdit(CCmdUI *pCmdUI)
|
|
1536 |
{
|
|
1537 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1538 |
// pCmdUI->SetCheck(m_bModified);
|
|
1539 |
pCmdUI->Enable(m_bModified);
|
|
1540 |
}
|
|
1541 |
|
|
1542 |
|
|
1543 |
void CMTerm1View::OnInsertBlankLine()
|
|
1544 |
{
|
|
1545 |
// TODO: 在此添加命令处理程序代码
|
|
1546 |
CString s1;
|
|
1547 |
s1.Format(_T("Insert Blank Line"));
|
|
1548 |
SysLog(s1);
|
|
1549 |
m_FocusRow;
|
|
1550 |
//当前行之后的所有,下移一行
|
|
1551 |
for (int i = m_nTotalRow - 1; i >= m_FocusRow; i--) {
|
|
1552 |
for (int j = 0; j < m_CellPerLine; j++) {
|
|
1553 |
Cells[i + 1][j] = Cells[i][j];
|
|
1554 |
}
|
|
1555 |
}
|
|
1556 |
m_nTotalRow += 1;
|
|
1557 |
// 当前行灰色
|
|
1558 |
for (int j = 0; j < m_CellPerLine; j++) {
|
|
1559 |
Cells[m_FocusRow][j].clear();
|
|
1560 |
Cells[m_FocusRow][j].bEditing = 1;
|
|
1561 |
Cells[m_FocusRow][j].bModified = 1;
|
|
1562 |
if (Cells[m_FocusRow + 1][j].bLeftLineUp) {
|
|
1563 |
Cells[m_FocusRow][j].bLeftLineUp = 1;
|
|
1564 |
Cells[m_FocusRow][j].bLeftLineDn = 1;
|
|
1565 |
}
|
|
1566 |
}
|
|
1567 |
|
|
1568 |
// 当前行 加入 触点
|
|
1569 |
// m_FocusCol;
|
|
1570 |
// Cells[m_FocusRow][0].nType= typeNO;
|
|
1571 |
// Cells[m_FocusRow][0].nDataType = KLCoilTypeX;
|
|
1572 |
// Cells[m_FocusRow][0].nDataAddr = 15;
|
|
1573 |
// Cells[m_FocusRow][0].sCoilName = "ABCDEFG";
|
|
1574 |
|
|
1575 |
m_bModified = 1;
|
|
1576 |
needReDraw = 1;
|
|
1577 |
this->RedrawWindow();
|
|
1578 |
}
|
|
1579 |
int FindTypeIndex(CString str[], CString strType, int num)
|
|
1580 |
{
|
|
1581 |
for (int i = 0;i < num;i++)
|
|
1582 |
{
|
|
1583 |
if (strType == str[i])
|
|
1584 |
{
|
|
1585 |
return i;
|
|
1586 |
}
|
|
1587 |
}
|
|
1588 |
return -1;
|
|
1589 |
}
|
|
1590 |
|
ad1b4b
|
1591 |
/// <summary>
|
Z |
1592 |
/// 设置Cell到窗口视图
|
|
1593 |
/// </summary>
|
|
1594 |
/// <param name="cell1"></param>
|
|
1595 |
void CMTerm1View::SetCellToView(stCell cell1, int flag) //**************************************************************************************************//
|
418cb3
|
1596 |
{
|
4ed7fc
|
1597 |
bool changeVLine = false;
|
Z |
1598 |
if ((Cells[m_FocusRow][m_FocusCol].bLeftLineDn != cell1.bLeftLineDn)
|
|
1599 |
|| (Cells[m_FocusRow][m_FocusCol].bLeftLineUp != cell1.bLeftLineUp))
|
|
1600 |
{
|
|
1601 |
changeVLine = true;
|
|
1602 |
}
|
418cb3
|
1603 |
Cells[m_FocusRow][m_FocusCol] = cell1;
|
Q |
1604 |
m_bModified = 1;
|
|
1605 |
needReDraw = 1;
|
ad1b4b
|
1606 |
|
df0321
|
1607 |
Cells[m_FocusRow][0].bEditing = 1;
|
Q |
1608 |
|
ad1b4b
|
1609 |
if (m_nTotalRow < m_FocusRow + 1)
|
Z |
1610 |
{
|
df0321
|
1611 |
m_nTotalRow = m_FocusRow + 1;
|
Q |
1612 |
}
|
ad1b4b
|
1613 |
//单元格关联修改
|
Z |
1614 |
switch (flag)
|
|
1615 |
{
|
|
1616 |
case 1:
|
|
1617 |
{
|
|
1618 |
if(Cells[m_FocusRow - 1][m_FocusCol].nType == CMTerm1View::typeExt1)
|
|
1619 |
{
|
|
1620 |
//发送错误信息
|
|
1621 |
DbgLog(_T("插入纵线失败:光标位置错误!参数位置不允许添加纵线"));
|
|
1622 |
return;
|
|
1623 |
}
|
|
1624 |
//添加纵线时同步添加上一行
|
|
1625 |
Cells[m_FocusRow - 1][m_FocusCol].bLeftLineDn = 1;
|
4ed7fc
|
1626 |
|
ad1b4b
|
1627 |
}break;
|
Z |
1628 |
case 2:
|
|
1629 |
{
|
|
1630 |
if (Cells[m_FocusRow - 1][m_FocusCol].nType == CMTerm1View::typeExt1)
|
|
1631 |
{
|
|
1632 |
//发送错误信息
|
|
1633 |
DbgLog(_T("删除纵线失败:光标位置错误!参数位置不允许删除纵线"));
|
|
1634 |
return;
|
|
1635 |
}
|
|
1636 |
//删除纵线时同步删除上一行
|
|
1637 |
Cells[m_FocusRow - 1][m_FocusCol].bLeftLineDn = 0;
|
4ed7fc
|
1638 |
|
ad1b4b
|
1639 |
}break;
|
Z |
1640 |
default:
|
|
1641 |
break;
|
|
1642 |
}
|
4ed7fc
|
1643 |
//如果变化的是竖线,焦点不后移
|
Z |
1644 |
if (!changeVLine)
|
|
1645 |
{
|
|
1646 |
//单元格位置后移
|
|
1647 |
m_FocusCol += 1;
|
|
1648 |
}
|
|
1649 |
|
418cb3
|
1650 |
if (m_FocusCol >= 16)
|
ad1b4b
|
1651 |
{
|
Z |
1652 |
m_FocusCol = 0;
|
|
1653 |
m_FocusRow += 1;
|
|
1654 |
}
|
|
1655 |
|
418cb3
|
1656 |
this->RedrawWindow();
|
ad1b4b
|
1657 |
this->CellFocusChg(m_FocusRow, m_FocusCol);//改变焦点
|
418cb3
|
1658 |
}
|
Q |
1659 |
void CMTerm1View::OnUpdateInsertBlankLine(CCmdUI *pCmdUI)
|
|
1660 |
{
|
|
1661 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1662 |
}
|
|
1663 |
|
|
1664 |
void CMTerm1View::OnDeleteBlankLine()
|
|
1665 |
{
|
|
1666 |
// TODO: 在此添加命令处理程序代码
|
|
1667 |
CString s1;
|
|
1668 |
s1.Format(_T("Delete Blank Line"));
|
|
1669 |
SysLog(s1);
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
void CMTerm1View::OnUpdateDeleteBlankLine(CCmdUI *pCmdUI)
|
|
1673 |
{
|
|
1674 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1675 |
}
|
|
1676 |
|
|
1677 |
void CMTerm1View::OnRectSelect()
|
|
1678 |
{
|
|
1679 |
// TODO: 在此添加命令处理程序代码
|
|
1680 |
}
|
|
1681 |
|
|
1682 |
|
|
1683 |
void CMTerm1View::OnUpdateRectSelect(CCmdUI *pCmdUI)
|
|
1684 |
{
|
|
1685 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1686 |
}
|
|
1687 |
|
|
1688 |
|
|
1689 |
void CMTerm1View::OnTextFirst()
|
|
1690 |
{
|
|
1691 |
// TODO: 在此添加命令处理程序代码
|
|
1692 |
}
|
|
1693 |
|
|
1694 |
|
|
1695 |
void CMTerm1View::OnUpdateTextFirst(CCmdUI *pCmdUI)
|
|
1696 |
{
|
|
1697 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1698 |
}
|
|
1699 |
|
|
1700 |
void CMTerm1View::OnDisplayComments()
|
|
1701 |
{
|
|
1702 |
// TODO: 在此添加命令处理程序代码
|
|
1703 |
m_bShowComments = !m_bShowComments;
|
|
1704 |
int CellTotalHeight = m_CellHeight + (m_bShowComments ? m_CommentHeight : 0);
|
|
1705 |
CRect rect0;
|
|
1706 |
this->GetClientRect(&rect0);
|
|
1707 |
|
|
1708 |
CSize sizeTotal;
|
|
1709 |
// TODO: 计算此视图的合计大小
|
|
1710 |
sizeTotal.cx = m_LeftMargin + m_CellWidth * m_CellPerLine + m_CellWidth * 2;
|
|
1711 |
sizeTotal.cy = m_TopMargin + CellTotalHeight * (m_nTotalRow-1) + rect0.Height();
|
|
1712 |
SetScrollSizes(MM_TEXT, sizeTotal);
|
|
1713 |
needReDraw = 1;
|
|
1714 |
this->Invalidate();
|
|
1715 |
}
|
|
1716 |
|
|
1717 |
|
|
1718 |
void CMTerm1View::OnUpdateDisplayComments(CCmdUI *pCmdUI)
|
|
1719 |
{
|
|
1720 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1721 |
pCmdUI->SetCheck(m_bShowComments == true);
|
|
1722 |
}
|
|
1723 |
|
|
1724 |
|
|
1725 |
|
|
1726 |
int CMTerm1View::UpdateStatusBar(int nIndex)
|
|
1727 |
{
|
|
1728 |
// TODO: 在此处添加实现代码.
|
|
1729 |
CString s1;
|
|
1730 |
CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
|
|
1731 |
|
|
1732 |
if (nIndex == idxMachineType || nIndex == -1) { //机型代码
|
|
1733 |
s1 = pDoc->m_sMachineType;
|
|
1734 |
m_pStatusBar->SetPaneText(idxMachineType,s1);
|
|
1735 |
}
|
|
1736 |
if (nIndex == idxProgPos || nIndex == -1) { //程序位置/步数
|
|
1737 |
s1.Format(_T("%5d/%5d"), m_nCurProgStep,pDoc->m_nProgSteps);
|
|
1738 |
m_pStatusBar->SetPaneText(idxProgPos, s1);
|
|
1739 |
}
|
|
1740 |
if (nIndex == idxOnline || nIndex == -1) { //在线 /离线
|
|
1741 |
if (!pDoc->m_bOnline) {
|
|
1742 |
s1 = _T("离线");
|
|
1743 |
m_pStatusBar->SetPaneText(idxOnline, s1);
|
|
1744 |
m_pStatusBar->SetPaneBackgroundColor(idxOnline);
|
|
1745 |
}
|
|
1746 |
else if (pDoc->m_bOnline) {
|
|
1747 |
if (pDoc->m_bSimulate) {
|
|
1748 |
s1 = _T("在线(仿真)");
|
|
1749 |
m_pStatusBar->SetPaneText(2, s1);
|
|
1750 |
m_pStatusBar->SetPaneBackgroundColor(idxOnline, OnlineColor);
|
|
1751 |
}else{
|
|
1752 |
s1 = _T("在线");
|
|
1753 |
m_pStatusBar->SetPaneText(2, s1);
|
|
1754 |
m_pStatusBar->SetPaneBackgroundColor(idxOnline, OnlineColor);
|
|
1755 |
}
|
|
1756 |
}
|
|
1757 |
}
|
|
1758 |
if (nIndex == idxRunning || nIndex == -1) { // 运行 / 停止
|
|
1759 |
if (!pDoc->m_bOnline) {
|
|
1760 |
s1 = _T("");
|
|
1761 |
m_pStatusBar->SetPaneText(idxRunning, s1);
|
|
1762 |
m_pStatusBar->SetPaneBackgroundColor(idxRunning);
|
|
1763 |
m_pStatusBar->SetPaneWidth(idxRunning, 0);
|
|
1764 |
m_pStatusBar->SetPaneStyle(idxRunning, SBPS_DISABLED);
|
|
1765 |
|
|
1766 |
}else if (!pDoc->m_bPlcRunning) {
|
|
1767 |
s1 = _T("PROG");
|
|
1768 |
m_pStatusBar->SetPaneText(idxRunning, s1);
|
|
1769 |
m_pStatusBar->SetPaneWidth(idxRunning, s1.GetLength()*8);
|
|
1770 |
m_pStatusBar->SetPaneBackgroundColor(idxRunning, ProgColor);
|
|
1771 |
}else {
|
|
1772 |
s1 = _T("RUN");
|
|
1773 |
m_pStatusBar->SetPaneText(idxRunning, s1);
|
|
1774 |
m_pStatusBar->SetPaneWidth(idxRunning, s1.GetLength() * 8);
|
|
1775 |
m_pStatusBar->SetPaneBackgroundColor(idxRunning, RunningColor);
|
|
1776 |
}
|
|
1777 |
}
|
|
1778 |
if (nIndex == idxMonitor || nIndex == -1) { // 监控 //
|
|
1779 |
// s1 = pDoc->m_sMachineType;
|
|
1780 |
if (!m_bMonitoring) {
|
|
1781 |
s1 = _T("[监控停止]");
|
|
1782 |
m_pStatusBar->SetPaneText(idxMonitor, s1);
|
|
1783 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor);
|
|
1784 |
}else{
|
|
1785 |
s1 = _T("[正在监控]");
|
|
1786 |
m_pStatusBar->SetPaneText(idxMonitor, s1);
|
|
1787 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor, MonitorColor);
|
|
1788 |
}
|
|
1789 |
}
|
|
1790 |
if (nIndex == idxAddress || nIndex == -1) { // 地址,本站
|
|
1791 |
// s1 = pDoc->m_sMachineType;
|
|
1792 |
if (!pDoc->m_bOnline) {
|
|
1793 |
s1 = _T("本站");
|
|
1794 |
m_pStatusBar->SetPaneText(idxAddress, s1);
|
|
1795 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor);
|
|
1796 |
}else {
|
|
1797 |
s1 = _T("本站");
|
|
1798 |
m_pStatusBar->SetPaneText(idxAddress, s1);
|
|
1799 |
m_pStatusBar->SetPaneBackgroundColor(idxMonitor, AddressColor);
|
|
1800 |
}
|
|
1801 |
|
|
1802 |
}
|
|
1803 |
if (nIndex == idxInfoDisp || nIndex == -1) { // INFO DISPLAY
|
|
1804 |
// s1 = pDoc->m_sMachineType;
|
|
1805 |
m_pStatusBar->SetPaneText(idxInfoDisp, s1);
|
|
1806 |
}
|
|
1807 |
|
|
1808 |
return 0;
|
|
1809 |
}
|
|
1810 |
|
|
1811 |
|
|
1812 |
void CMTerm1View::OnUpdateIndicatorMonitorStatus(CCmdUI *pCmdUI)
|
|
1813 |
{
|
|
1814 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1815 |
|
|
1816 |
//pCmdUI->SetCheck(m_bMonitoring == true);
|
|
1817 |
if (!m_bMonitoring) pCmdUI->SetText(_T("[监控停止]"));
|
|
1818 |
else pCmdUI->SetText(_T("[正在监控]"));
|
|
1819 |
}
|
|
1820 |
|
|
1821 |
void CMTerm1View::OnUpdateIndicators(CCmdUI *pCmdUI)
|
|
1822 |
{
|
|
1823 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1824 |
CString s1;
|
|
1825 |
s1.Format(_T("pCmdUI nID %d "));
|
|
1826 |
DbgLog(s1);
|
|
1827 |
pCmdUI->m_nID;
|
|
1828 |
pCmdUI->SetText(_T("KL-D20N16"));
|
|
1829 |
}
|
|
1830 |
|
|
1831 |
void CMTerm1View::OnUpdateMachineType(CCmdUI *pCmdUI)
|
|
1832 |
{
|
|
1833 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1834 |
CString s1;
|
|
1835 |
s1.Format(_T("pCmdUI nID %d "));
|
|
1836 |
DbgLog(s1);
|
|
1837 |
pCmdUI->m_nID;
|
|
1838 |
pCmdUI->SetText(_T("KL-D20N16"));
|
|
1839 |
}
|
|
1840 |
|
|
1841 |
void CMTerm1View::OnUpdateProgramPos(CCmdUI *pCmdUI)
|
|
1842 |
{
|
|
1843 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1844 |
CString s1;
|
|
1845 |
s1.Format(_T("%5d/%5d"), 18, 55);
|
|
1846 |
pCmdUI->SetText(s1);
|
|
1847 |
}
|
|
1848 |
|
|
1849 |
void CMTerm1View::OnUpdateConnectivity(CCmdUI *pCmdUI)
|
|
1850 |
{
|
|
1851 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1852 |
CString s1;
|
|
1853 |
s1 = _T("离线");
|
|
1854 |
s1 = _T("在线");
|
|
1855 |
|
|
1856 |
pCmdUI->SetText(s1);
|
|
1857 |
}
|
|
1858 |
void CMTerm1View::OnUpdateRunStatus(CCmdUI *pCmdUI)
|
|
1859 |
{
|
|
1860 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1861 |
CString s1;
|
|
1862 |
CMTerm1Doc* pDoc = GetDocument();
|
|
1863 |
ASSERT_VALID(pDoc);
|
|
1864 |
if (!pDoc) return;
|
|
1865 |
if (pDoc->m_bPlcRunning) {
|
|
1866 |
s1 = _T("运行");
|
|
1867 |
m_pStatusBar->SetPaneText(3, s1);
|
|
1868 |
m_pStatusBar->SetPaneTextColor(3, RGB(0, 0, 0));
|
|
1869 |
}
|
|
1870 |
else {
|
|
1871 |
s1 = _T("停止");
|
|
1872 |
m_pStatusBar->SetPaneText(3, s1);
|
|
1873 |
m_pStatusBar->SetPaneTextColor(3, RGB(0, 0, 0));
|
|
1874 |
}
|
|
1875 |
s1.Format(_T("PCmdUI %d %d"), pCmdUI->m_nID, pCmdUI->m_nIndex);
|
|
1876 |
DbgLog(s1);
|
|
1877 |
|
|
1878 |
// pCmdUI->SetText(s1);
|
|
1879 |
}
|
|
1880 |
void CMTerm1View::OnUpdateMonitorStatus(CCmdUI *pCmdUI)
|
|
1881 |
{
|
|
1882 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1883 |
CString s1;
|
|
1884 |
s1 = _T("停止监控");
|
|
1885 |
s1 = _T("监控中");
|
|
1886 |
if (!m_bMonitoring) pCmdUI->SetText(_T("[监控停止]"));
|
|
1887 |
else pCmdUI->SetText(_T("[正在监控]"));
|
|
1888 |
|
|
1889 |
// pCmdUI->SetText(s1);
|
|
1890 |
}
|
|
1891 |
void CMTerm1View::OnUpdateTargetAddress(CCmdUI *pCmdUI)
|
|
1892 |
{
|
|
1893 |
// TODO: 在此添加命令更新用户界面处理程序代码
|
|
1894 |
CString s1;
|
|
1895 |
s1 = _T("远程");
|
|
1896 |
s1 = _T("本站");
|
|
1897 |
pCmdUI->SetText(s1);
|
|
1898 |
}
|
|
1899 |
|
|
1900 |
void CMTerm1View::OnInputIoComment()
|
|
1901 |
{
|
|
1902 |
// TODO: 在此添加命令处理程序代码
|
|
1903 |
CString s1;
|
|
1904 |
int nRow, nCol;
|
|
1905 |
nRow = m_FocusRow;
|
|
1906 |
nCol = m_FocusCol;
|
|
1907 |
if (nCol < 0) { nCol = 0; }
|
|
1908 |
if (nCol >= m_CellPerLine) { nCol = m_CellPerLine - 1; }
|
|
1909 |
|
|
1910 |
CString sParam;
|
|
1911 |
sParam = Cells[nRow][nCol].sParam;
|
|
1912 |
int nDataType, nDataAddr, nStat;
|
|
1913 |
nDataType = Cells[nRow][nCol].nDataType;
|
|
1914 |
nDataAddr = Cells[nRow][nCol].nDataAddr;
|
|
1915 |
nStat = Cells[nRow][nCol].nStat;
|
|
1916 |
|
|
1917 |
s1.Format(_T("Name %s DataType %d DataAddr %d Stat %d"),
|
|
1918 |
sParam, nDataType, nDataAddr, nStat);
|
|
1919 |
SysLog(s1);
|
|
1920 |
if (Cells[m_FocusRow][m_FocusCol].sParam == _T("")) {
|
|
1921 |
return;
|
|
1922 |
}
|
|
1923 |
|
|
1924 |
CMTerm1Doc * pDoc = GetDocument();
|
|
1925 |
CString sComment;
|
|
1926 |
pDoc->GetAnno(nDataType, nDataAddr, sComment);
|
|
1927 |
CDialogIoComment dialog1;
|
|
1928 |
dialog1.m_sIOName = sParam;
|
|
1929 |
dialog1.m_sComment = sComment;
|
|
1930 |
dialog1.m_nCoilType = nDataType;
|
|
1931 |
dialog1.m_nCoilAddr = nDataAddr;
|
|
1932 |
INT_PTR r = dialog1.DoModal();
|
|
1933 |
if (r == IDOK)
|
|
1934 |
{
|
|
1935 |
sComment = dialog1.m_sComment;
|
|
1936 |
pDoc->SetAnno(nDataType, nDataAddr, sParam, sComment);
|
|
1937 |
s1.Format(_T("Set %s %d %d comment -> %s"), sParam, nDataType, nDataAddr, sComment);
|
|
1938 |
SysLog(s1);
|
|
1939 |
//needReDraw = 1;
|
|
1940 |
this->RedrawWindow();
|
|
1941 |
}
|
|
1942 |
}
|
|
1943 |
|
d34256
|
1944 |
/// <summary>
|
Z |
1945 |
/// 程序数据转为梯形图
|
|
1946 |
/// </summary>
|
|
1947 |
/// <returns></returns>
|
418cb3
|
1948 |
int CMTerm1View::TransProgToLDS()
|
Q |
1949 |
{
|
|
1950 |
CString s1;
|
|
1951 |
CMTerm1Doc * pDoc = (CMTerm1Doc*)GetDocument();
|
|
1952 |
|
|
1953 |
// 先扫描分开的程序段
|
|
1954 |
int stpos[100] = { 0 };
|
|
1955 |
int nSts = 0;
|
|
1956 |
|
ad1b4b
|
1957 |
for (int i = 0; i < m_nTotalRow && i < 2000; i++)
|
Z |
1958 |
{
|
|
1959 |
for (int j = 0; j < 16; j++)
|
|
1960 |
{
|
418cb3
|
1961 |
Cells[i][j].clear();
|
aac3b3
|
1962 |
s1.Format(_T("%d:%d"), i, j);
|
418cb3
|
1963 |
Cells[i][j].sCoilName = s1;
|
Q |
1964 |
}
|
|
1965 |
}
|
|
1966 |
POINT StPts[100];
|
|
1967 |
// StPts[0] = POINT{ 0, 0 };
|
|
1968 |
POINT EndPt[100];
|
4ed7fc
|
1969 |
|
Z |
1970 |
POINT StrPt[100];
|
|
1971 |
int nStrPts = 0;
|
418cb3
|
1972 |
int nEndPts = 0;
|
Q |
1973 |
nSts = 0;
|
|
1974 |
int nCurLine = 0;
|
|
1975 |
|
|
1976 |
int cx = 0, cy = 0;
|
|
1977 |
int maxy = 0;
|
d34256
|
1978 |
try
|
418cb3
|
1979 |
{
|
d34256
|
1980 |
for (int i = 0; i < pDoc->m_nProgSteps; i++)
|
418cb3
|
1981 |
{
|
d34256
|
1982 |
int nOp = pDoc->Progs[i].nOpType1;
|
Z |
1983 |
int nParamCount = pDoc->Progs[i].nParamCount;
|
|
1984 |
CStringA OpName;
|
|
1985 |
CStringA ShowTxt;
|
|
1986 |
pDoc->OpToTxt(nOp, OpName);
|
|
1987 |
pDoc->OpToShowTxt(nOp, ShowTxt);
|
|
1988 |
int nPairTo = pDoc->Progs[i].PairTo;
|
|
1989 |
int nPairOp = 0;
|
e55aec
|
1990 |
if (nPairTo)
|
Z |
1991 |
{
|
|
1992 |
nPairOp = pDoc->Progs[nPairTo].nOpType1;
|
|
1993 |
}
|
d34256
|
1994 |
int nCellType;
|
Z |
1995 |
switch (nOp)
|
|
1996 |
{
|
|
1997 |
case OP_NOP:
|
|
1998 |
break;
|
|
1999 |
case OP_ST:
|
|
2000 |
case OP_ST_:
|
e55aec
|
2001 |
if (i == 0)
|
Z |
2002 |
{
|
418cb3
|
2003 |
|
d34256
|
2004 |
}
|
e55aec
|
2005 |
else
|
Z |
2006 |
{
|
d34256
|
2007 |
//记录当前位置
|
Z |
2008 |
EndPt[nEndPts] = POINT{ cx,cy };
|
|
2009 |
nEndPts++;
|
e55aec
|
2010 |
if (nPairOp == OP_ANS)
|
Z |
2011 |
{
|
d34256
|
2012 |
//继续前进
|
Z |
2013 |
//cx = 0, cy = nCurLine;
|
|
2014 |
//cx = StPts[nSts - 1].x;
|
|
2015 |
//nCurLine = cy + 1; //另起一行
|
e55aec
|
2016 |
///*
|
d34256
|
2017 |
nCurLine = cy;
|
Z |
2018 |
int hasData = 1;
|
|
2019 |
while (hasData) {
|
|
2020 |
hasData = 0;
|
e55aec
|
2021 |
for (int j = cx + 1; j < m_CellPerLine; j++)
|
Z |
2022 |
{
|
|
2023 |
if (Cells[nCurLine][j].nType != 0)
|
|
2024 |
{
|
d34256
|
2025 |
nCurLine++; hasData = 1; break;
|
Z |
2026 |
}
|
418cb3
|
2027 |
}
|
Q |
2028 |
}
|
e55aec
|
2029 |
//nCurLine = maxy + 1; //另起一行
|
Z |
2030 |
if (nCurLine > maxy)
|
|
2031 |
{
|
|
2032 |
maxy = nCurLine;
|
|
2033 |
}
|
|
2034 |
for (int j = cy; j < nCurLine; j++)
|
|
2035 |
{
|
d34256
|
2036 |
Cells[j][cx].bLeftLineDn = 1;
|
Z |
2037 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2038 |
}
|
|
2039 |
cy = nCurLine;
|
|
2040 |
//*/
|
418cb3
|
2041 |
}
|
e55aec
|
2042 |
else if (nPairOp == OP_ORS)
|
Z |
2043 |
{
|
d34256
|
2044 |
cx = StPts[nSts - 1].x;
|
Z |
2045 |
nCurLine = cy + 1; //另起一行
|
|
2046 |
int hasData = 1;
|
e55aec
|
2047 |
while (hasData)
|
Z |
2048 |
{
|
d34256
|
2049 |
hasData = 0;
|
e55aec
|
2050 |
for (int j = cx; j < m_CellPerLine; j++)
|
Z |
2051 |
{
|
|
2052 |
if (Cells[nCurLine][j].nType != 0)
|
|
2053 |
{
|
d34256
|
2054 |
nCurLine++; hasData = 1; break;
|
Z |
2055 |
}
|
418cb3
|
2056 |
}
|
Q |
2057 |
}
|
d34256
|
2058 |
// nCurLine = maxy + 1; //另起一行
|
Z |
2059 |
if (nCurLine > maxy) maxy = nCurLine;
|
e55aec
|
2060 |
for (int j = cy; j < nCurLine; j++)
|
Z |
2061 |
{
|
d34256
|
2062 |
Cells[j][cx].bLeftLineDn = 1;
|
Z |
2063 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2064 |
}
|
|
2065 |
cy = nCurLine;
|
418cb3
|
2066 |
}
|
e55aec
|
2067 |
else if (nPairOp == 0)
|
Z |
2068 |
{
|
4ed7fc
|
2069 |
if (i > 0 && nOp == pDoc->Progs[i-1].nOpType1)//如果前面也是ST,那就不换行
|
Z |
2070 |
{
|
|
2071 |
|
|
2072 |
}
|
|
2073 |
else
|
|
2074 |
{
|
|
2075 |
nCurLine = ++maxy;
|
|
2076 |
cx = 0;
|
|
2077 |
cy = nCurLine;
|
|
2078 |
}
|
418cb3
|
2079 |
}
|
Q |
2080 |
}
|
d34256
|
2081 |
stpos[nSts] = i;
|
Z |
2082 |
StPts[nSts] = POINT{ cx,cy };
|
|
2083 |
nSts++;
|
|
2084 |
Cells[cy][cx].nType = pDoc->Progs[i].nOpType1 == OP_ST ? typeNO : typeNC; //typeNC
|
|
2085 |
Cells[cy][cx].nProgStep = i;
|
|
2086 |
Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
|
2087 |
Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2088 |
Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2089 |
Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2090 |
cx++; //移到下一格
|
|
2091 |
break;
|
|
2092 |
case OP_ST_EQ:
|
|
2093 |
case OP_ST_NE:
|
|
2094 |
case OP_ST_LT:
|
|
2095 |
case OP_ST_GT:
|
|
2096 |
case OP_ST_LE:
|
|
2097 |
case OP_ST_GE:
|
|
2098 |
if (i == 0) {
|
418cb3
|
2099 |
|
Q |
2100 |
}
|
d34256
|
2101 |
else {
|
Z |
2102 |
//记录当前位置
|
|
2103 |
EndPt[nEndPts] = POINT{ cx,cy };
|
|
2104 |
nEndPts++;
|
|
2105 |
if (nPairOp == OP_ANS) {
|
|
2106 |
//继续前进
|
|
2107 |
//cx = 0, cy = nCurLine;
|
|
2108 |
}
|
|
2109 |
else if (nPairOp == OP_ORS) {
|
|
2110 |
cx = StPts[nSts - 1].x;
|
|
2111 |
nCurLine = cy + 1; //另起一行
|
|
2112 |
int hasData = 1;
|
|
2113 |
while (hasData) {
|
|
2114 |
hasData = 0;
|
|
2115 |
for (int j = cx; j < m_CellPerLine; j++) {
|
|
2116 |
if (Cells[nCurLine][j].nType != 0) {
|
|
2117 |
nCurLine++; hasData = 1; break;
|
|
2118 |
}
|
418cb3
|
2119 |
}
|
Q |
2120 |
}
|
d34256
|
2121 |
// nCurLine = maxy + 1; //另起一行
|
Z |
2122 |
if (nCurLine > maxy) maxy = nCurLine;
|
|
2123 |
for (int j = cy; j < nCurLine; j++) {
|
|
2124 |
Cells[j][cx].bLeftLineDn = 1;
|
|
2125 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
418cb3
|
2126 |
}
|
d34256
|
2127 |
cy = nCurLine;
|
Z |
2128 |
}
|
|
2129 |
else if (nPairOp == 0) {
|
|
2130 |
nCurLine = maxy + 1; //另起一行
|
|
2131 |
maxy = nCurLine;
|
|
2132 |
cx = 0; cy = nCurLine;
|
418cb3
|
2133 |
}
|
Q |
2134 |
}
|
d34256
|
2135 |
stpos[nSts] = i;
|
Z |
2136 |
StPts[nSts] = POINT{ cx,cy };
|
|
2137 |
nSts++;
|
|
2138 |
Cells[cy][cx].nType = typeCMP;
|
|
2139 |
Cells[cy][cx].nProgStep = i;
|
|
2140 |
Cells[cy][cx].sParam = OpName;
|
|
2141 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2142 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2143 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2144 |
Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2145 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2146 |
Cells[cy][cx + 2].nType = typeExt1;
|
|
2147 |
Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
|
2148 |
Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
|
2149 |
Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
|
2150 |
cx += 3; //移到下3格
|
|
2151 |
break;
|
418cb3
|
2152 |
|
d34256
|
2153 |
case OP_AN:
|
Z |
2154 |
case OP_AN_:
|
418cb3
|
2155 |
|
d34256
|
2156 |
Cells[cy][cx].nType = nOp == OP_AN ? typeNO : typeNC; //typeNC
|
418cb3
|
2157 |
Cells[cy][cx].nProgStep = i;
|
Q |
2158 |
Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2159 |
Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
|
2160 |
Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2161 |
Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
d34256
|
2162 |
cx++;
|
Z |
2163 |
break;
|
|
2164 |
case OP_AN_EQ:
|
|
2165 |
case OP_AN_NE:
|
|
2166 |
case OP_AN_LT:
|
|
2167 |
case OP_AN_GT:
|
|
2168 |
case OP_AN_LE:
|
|
2169 |
case OP_AN_GE:
|
|
2170 |
Cells[cy][cx].nType = typeCMP;
|
|
2171 |
Cells[cy][cx].nProgStep = i;
|
|
2172 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2173 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2174 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2175 |
Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2176 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2177 |
Cells[cy][cx + 2].nType = typeExt1;
|
|
2178 |
Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
|
2179 |
Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
|
2180 |
Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
|
2181 |
cx += 3;
|
|
2182 |
break;
|
|
2183 |
|
|
2184 |
case OP_OR:
|
|
2185 |
case OP_OR_:
|
|
2186 |
EndPt[nEndPts] = POINT{ cx,cy };
|
aac3b3
|
2187 |
nEndPts++;
|
d34256
|
2188 |
cx = StPts[nSts - 1].x;
|
Z |
2189 |
nCurLine = cy + 1; //另起一行
|
|
2190 |
{
|
|
2191 |
int hasData = 1;
|
aac3b3
|
2192 |
while (hasData)
|
Z |
2193 |
{
|
|
2194 |
hasData = 0;
|
|
2195 |
for (int j = cx; j < m_CellPerLine; j++)
|
|
2196 |
{
|
|
2197 |
if (Cells[nCurLine][j].nType != 0)
|
|
2198 |
{
|
|
2199 |
nCurLine++;
|
|
2200 |
hasData = 1;
|
|
2201 |
break;
|
d34256
|
2202 |
}
|
Z |
2203 |
}
|
|
2204 |
}
|
|
2205 |
}
|
aac3b3
|
2206 |
if (nCurLine > maxy)
|
Z |
2207 |
{
|
|
2208 |
maxy = nCurLine;
|
|
2209 |
}
|
|
2210 |
for (int j = cy; j < nCurLine; j++)
|
|
2211 |
{
|
d34256
|
2212 |
Cells[j][cx].bLeftLineDn = 1;
|
Z |
2213 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2214 |
}
|
|
2215 |
cy = nCurLine;
|
aac3b3
|
2216 |
StPts[nSts] = POINT{ cx,cy };//+++
|
d34256
|
2217 |
Cells[cy][cx].nProgStep = i;
|
Z |
2218 |
Cells[cy][cx].nType = nOp == OP_OR ? typeNO : typeNC; //typeNC
|
|
2219 |
Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
|
2220 |
Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2221 |
Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2222 |
Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2223 |
cx++;
|
aac3b3
|
2224 |
//if (cx <= EndPt[nEndPts - 1].x)
|
Z |
2225 |
//{ //本行补齐
|
|
2226 |
// for (int j = cx; j < EndPt[nEndPts - 1].x; j++)
|
|
2227 |
// {
|
|
2228 |
// Cells[cy][j].nType = typeLine1;
|
|
2229 |
// }
|
|
2230 |
// cx = EndPt[nEndPts - 1].x;
|
|
2231 |
//}
|
|
2232 |
//else {
|
|
2233 |
// //前一行补齐
|
|
2234 |
// for (int j = EndPt[nEndPts - 1].x; j < cx; j++)
|
|
2235 |
// {
|
|
2236 |
// Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1;
|
|
2237 |
// }
|
d34256
|
2238 |
|
aac3b3
|
2239 |
//}
|
d34256
|
2240 |
//连接上下线
|
Z |
2241 |
for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
|
2242 |
{
|
|
2243 |
Cells[j][cx].bLeftLineDn = 1;
|
|
2244 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2245 |
}
|
|
2246 |
//光标位置, 前一结束点位置
|
|
2247 |
cy = EndPt[nEndPts - 1].y;
|
aac3b3
|
2248 |
|
d34256
|
2249 |
nEndPts--;
|
Z |
2250 |
|
|
2251 |
break;
|
|
2252 |
case OP_OR_EQ:
|
|
2253 |
case OP_OR_NE:
|
|
2254 |
case OP_OR_LT:
|
|
2255 |
case OP_OR_GT:
|
|
2256 |
case OP_OR_LE:
|
|
2257 |
case OP_OR_GE:
|
|
2258 |
EndPt[nEndPts] = POINT{ cx,cy };
|
|
2259 |
nEndPts++;
|
|
2260 |
cx = StPts[nSts - 1].x;
|
|
2261 |
nCurLine = cy + 1; //另起一行
|
|
2262 |
{
|
|
2263 |
int hasData = 1;
|
|
2264 |
while (hasData) {
|
|
2265 |
hasData = 0;
|
|
2266 |
for (int j = cx; j < m_CellPerLine; j++) {
|
|
2267 |
if (Cells[nCurLine][j].nType != 0) {
|
|
2268 |
nCurLine++; hasData = 1; break;
|
|
2269 |
}
|
|
2270 |
}
|
|
2271 |
}
|
|
2272 |
}
|
|
2273 |
if (nCurLine > maxy) maxy = nCurLine;
|
|
2274 |
for (int j = cy; j < nCurLine; j++) {
|
|
2275 |
Cells[j][cx].bLeftLineDn = 1;
|
|
2276 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2277 |
}
|
|
2278 |
cy = nCurLine;
|
|
2279 |
Cells[cy][cx].nType = typeCMP;
|
|
2280 |
Cells[cy][cx].nProgStep = i;
|
|
2281 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2282 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2283 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2284 |
Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2285 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2286 |
Cells[cy][cx + 2].nType = typeExt1;
|
|
2287 |
Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
|
2288 |
Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
|
2289 |
Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
|
2290 |
cx += 3;
|
|
2291 |
if (cx < EndPt[nEndPts - 1].x)
|
|
2292 |
{ //本行补齐
|
|
2293 |
for (int j = cx; j < EndPt[nEndPts - 1].x; j++)
|
|
2294 |
{
|
|
2295 |
Cells[cy][j].nType = typeLine1;
|
|
2296 |
}
|
|
2297 |
cx = EndPt[nEndPts - 1].x;
|
|
2298 |
}
|
|
2299 |
else {
|
|
2300 |
//前一行补齐
|
|
2301 |
for (int j = EndPt[nEndPts - 1].x; j < cx; j++)
|
|
2302 |
{
|
|
2303 |
Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1;
|
|
2304 |
}
|
|
2305 |
|
|
2306 |
}
|
|
2307 |
//连接上下线
|
|
2308 |
for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
|
2309 |
{
|
|
2310 |
Cells[j][cx].bLeftLineDn = 1;
|
|
2311 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2312 |
}
|
|
2313 |
//光标位置, 前一结束点位置
|
|
2314 |
cy = EndPt[nEndPts - 1].y;
|
|
2315 |
nEndPts--;
|
|
2316 |
|
|
2317 |
break;
|
|
2318 |
case OP_NOT:
|
|
2319 |
Cells[cy][cx].nType = typeNOT;
|
|
2320 |
Cells[cy][cx].sCoilName = _T("NOT");
|
|
2321 |
|
|
2322 |
Cells[cy][cx].nProgStep = i;
|
|
2323 |
cx++;
|
|
2324 |
break;
|
|
2325 |
case OP_DF:
|
|
2326 |
case OP_DF_:
|
|
2327 |
Cells[cy][cx].nType = nOp == OP_DF ? typeDF : typeDF_;
|
|
2328 |
Cells[cy][cx].sCoilName = nOp == OP_DF ? _T("DF") : _T("DF/");
|
|
2329 |
|
|
2330 |
Cells[cy][cx].nProgStep = i;
|
|
2331 |
cx++;
|
|
2332 |
break;
|
|
2333 |
case OP_ANS:
|
4ed7fc
|
2334 |
//ANS说明是有环路,整行进行移动(向右)从后向前进行移动
|
Z |
2335 |
EndPt[nEndPts].y;
|
|
2336 |
for (int i = EndPt[nEndPts-1].x ; i > 0; i--)
|
|
2337 |
{
|
|
2338 |
for (int j = EndPt[nEndPts].x; j >= 0; j--)
|
|
2339 |
{
|
|
2340 |
if (j > 0
|
|
2341 |
&& Cells[cy + 1][j-1].nType == typeNone
|
|
2342 |
|| Cells[cy + 1][j - 1].nType == typeLine1
|
|
2343 |
|| Cells[cy + 1][j - 1].nType == typeLine2)
|
|
2344 |
{
|
|
2345 |
continue;
|
|
2346 |
}
|
|
2347 |
|
|
2348 |
Cells[cy + 1][j] = Cells[cy + 1][j - 1];
|
|
2349 |
}
|
|
2350 |
}
|
|
2351 |
|
|
2352 |
Cells[EndPt[nEndPts].y][EndPt[nEndPts-1].x].bLeftLineDn = 1;
|
|
2353 |
Cells[EndPt[nEndPts].y+1][EndPt[nEndPts-1].x].bLeftLineUp = 1;
|
|
2354 |
|
d34256
|
2355 |
nSts--;
|
Z |
2356 |
nEndPts--;
|
|
2357 |
|
|
2358 |
break;
|
|
2359 |
case OP_ORS:
|
4ed7fc
|
2360 |
|
e55aec
|
2361 |
if (nEndPts <= 0)
|
d34256
|
2362 |
{
|
e55aec
|
2363 |
break;
|
d34256
|
2364 |
}
|
e55aec
|
2365 |
|
4ed7fc
|
2366 |
//判断二者长度
|
Z |
2367 |
if (cx < EndPt[nEndPts - 1].x)
|
|
2368 |
{
|
|
2369 |
//本行补齐
|
|
2370 |
for (int j = cx; j < EndPt[nEndPts - 1].x; j++)
|
|
2371 |
{
|
|
2372 |
Cells[cy][j].nType = typeLine1;
|
|
2373 |
}
|
|
2374 |
cx = EndPt[nEndPts - 1].x;
|
|
2375 |
}
|
|
2376 |
else
|
|
2377 |
{
|
|
2378 |
//前一行补齐
|
|
2379 |
for (int j = EndPt[nEndPts - 1].x; j < cx; j++)
|
|
2380 |
{
|
|
2381 |
if (Cells[EndPt[nEndPts - 1].y][j].nType == typeNone)
|
|
2382 |
{
|
|
2383 |
Cells[EndPt[nEndPts - 1].y][j].nType = typeLine1;
|
|
2384 |
}
|
|
2385 |
}
|
|
2386 |
}
|
|
2387 |
//连接上下线
|
|
2388 |
|
|
2389 |
Cells[cy][cx].bLeftLineUp = 1;
|
|
2390 |
Cells[cy-1][cx].bLeftLineDn = 1;
|
|
2391 |
|
|
2392 |
//光标位置, 前一结束点位置
|
d34256
|
2393 |
nSts--;
|
Z |
2394 |
nEndPts--;
|
4ed7fc
|
2395 |
cy = EndPt[nEndPts].y;
|
Z |
2396 |
cx = EndPt[nEndPts].x;
|
d34256
|
2397 |
break;
|
Z |
2398 |
case OP_PSHS:
|
4ed7fc
|
2399 |
StrPt[nStrPts] = POINT{ EndPt[nEndPts].x,EndPt[nEndPts].y+1 };
|
Z |
2400 |
nStrPts++;
|
d34256
|
2401 |
break;
|
Z |
2402 |
case OP_RDS:
|
|
2403 |
cx = EndPt[nEndPts - 1].x;
|
|
2404 |
for (int j = cx; j < m_CellPerLine; j++) {
|
|
2405 |
if (Cells[cy][j].nType != 0)
|
|
2406 |
{
|
|
2407 |
cy++; j = cx - 1; //break;
|
|
2408 |
}
|
|
2409 |
}
|
|
2410 |
for (int j = EndPt[nEndPts - 1].y; j < cy; j++)
|
|
2411 |
{
|
|
2412 |
Cells[j][cx].bLeftLineDn = 1;
|
|
2413 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2414 |
}
|
|
2415 |
break;
|
|
2416 |
case OP_POPS:
|
4ed7fc
|
2417 |
nStrPts--;
|
Z |
2418 |
cy = StrPt[nStrPts].y;
|
|
2419 |
cx = StrPt[nStrPts].x;
|
d34256
|
2420 |
break;
|
Z |
2421 |
case OP_OUT:
|
|
2422 |
case OP_SET:
|
|
2423 |
case OP_RESET:
|
|
2424 |
nCellType = nOp == OP_OUT ? typeOUT : nOp == OP_SET ? typeSET : typeRESET;
|
|
2425 |
nCurLine = cy;
|
|
2426 |
if (cx <= m_CellPerLine) {
|
|
2427 |
|
|
2428 |
int hasData = 1;
|
|
2429 |
while (hasData) {
|
|
2430 |
hasData = 0;
|
|
2431 |
for (int j = cx; j < m_CellPerLine; j++) {
|
|
2432 |
if (Cells[nCurLine][j].nType != 0) {
|
|
2433 |
nCurLine++; hasData = 1; break;
|
|
2434 |
}
|
|
2435 |
}
|
|
2436 |
}
|
|
2437 |
//if (nCurLine > maxy) maxy = nCurLine;
|
|
2438 |
for (int j = cy; j < nCurLine; j++) {
|
|
2439 |
Cells[j][cx].bLeftLineDn = 1;
|
|
2440 |
Cells[j + 1][cx].bLeftLineUp = 1;
|
|
2441 |
}
|
|
2442 |
cy = nCurLine;
|
|
2443 |
for (int j = cx; j < m_CellPerLine; j++)
|
|
2444 |
{
|
|
2445 |
Cells[cy][j].nType = typeLine1;
|
|
2446 |
}
|
|
2447 |
Cells[cy][m_CellPerLine - 1].nType = nCellType;
|
|
2448 |
Cells[cy][m_CellPerLine - 1].nProgStep = i;
|
|
2449 |
Cells[cy][m_CellPerLine - 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2450 |
Cells[cy][m_CellPerLine - 1].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
|
2451 |
Cells[cy][m_CellPerLine - 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2452 |
Cells[cy][m_CellPerLine - 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2453 |
|
|
2454 |
}
|
|
2455 |
else {
|
|
2456 |
Cells[cy][cx].nType = nCellType;
|
|
2457 |
Cells[cy][cx].nProgStep = i;
|
|
2458 |
Cells[cy][cx].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2459 |
Cells[cy][cx].sCoilName = pDoc->Progs[i].Params[0].sParamStr;
|
|
2460 |
Cells[cy][cx].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2461 |
Cells[cy][cx].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2462 |
}
|
|
2463 |
if (cy > maxy) { maxy = cy; }
|
|
2464 |
//cy++;
|
|
2465 |
break;
|
|
2466 |
|
|
2467 |
case OP_TML:
|
|
2468 |
case OP_TMR:
|
|
2469 |
case OP_TMX:
|
|
2470 |
case OP_TMY:
|
|
2471 |
Cells[cy][cx].nType = typeTM;
|
|
2472 |
Cells[cy][cx].nProgStep = i;
|
|
2473 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2474 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2475 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2476 |
Cells[cy][cx + 1].nDataType = KLDataTypeEV;
|
|
2477 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2478 |
Cells[cy][cx + 2].nType = typeExt1;
|
|
2479 |
Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
|
2480 |
Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
|
2481 |
Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
|
2482 |
cx += 3;
|
|
2483 |
break;
|
|
2484 |
case OP_INC:
|
|
2485 |
case OP_DEC:
|
|
2486 |
Cells[cy][cx].nType = typeFN1;
|
|
2487 |
Cells[cy][cx].nProgStep = i;
|
|
2488 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2489 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2490 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2491 |
Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2492 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2493 |
cx += 2;
|
|
2494 |
break;
|
|
2495 |
|
|
2496 |
case OP_MV:
|
|
2497 |
case OP_ADD2:
|
|
2498 |
case OP_SUB2:
|
|
2499 |
Cells[cy][cx].nType = typeFN2;
|
|
2500 |
Cells[cy][cx].nProgStep = i;
|
|
2501 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2502 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2503 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2504 |
Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2505 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2506 |
Cells[cy][cx + 2].nType = typeExt1;
|
|
2507 |
Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
|
2508 |
Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
|
2509 |
Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
|
2510 |
cx += 3;
|
|
2511 |
break;
|
|
2512 |
|
|
2513 |
case OP_ADD3:
|
|
2514 |
case OP_SUB3:
|
|
2515 |
case OP_MUL:
|
|
2516 |
case OP_DIV:
|
|
2517 |
Cells[cy][cx].nType = typeFN3;
|
|
2518 |
Cells[cy][cx].nProgStep = i;
|
|
2519 |
Cells[cy][cx].sCoilName = ShowTxt;
|
|
2520 |
Cells[cy][cx + 1].nType = typeExt1;
|
|
2521 |
Cells[cy][cx + 1].sParam = pDoc->Progs[i].Params[0].sParamStr;
|
|
2522 |
Cells[cy][cx + 1].nDataType = pDoc->Progs[i].Params[0].nParamType;
|
|
2523 |
Cells[cy][cx + 1].nDataAddr = pDoc->Progs[i].Params[0].nParamAddr;
|
|
2524 |
Cells[cy][cx + 2].nType = typeExt1;
|
|
2525 |
Cells[cy][cx + 2].sParam = pDoc->Progs[i].Params[1].sParamStr;
|
|
2526 |
Cells[cy][cx + 2].nDataType = pDoc->Progs[i].Params[1].nParamType;
|
|
2527 |
Cells[cy][cx + 2].nDataAddr = pDoc->Progs[i].Params[1].nParamAddr;
|
|
2528 |
Cells[cy][cx + 3].nType = typeExt1;
|
|
2529 |
Cells[cy][cx + 3].sParam = pDoc->Progs[i].Params[2].sParamStr;
|
|
2530 |
Cells[cy][cx + 3].nDataType = pDoc->Progs[i].Params[2].nParamType;
|
|
2531 |
Cells[cy][cx + 3].nDataAddr = pDoc->Progs[i].Params[2].nParamAddr;
|
|
2532 |
cx += 4;
|
|
2533 |
break;
|
|
2534 |
|
|
2535 |
default:
|
|
2536 |
break;
|
418cb3
|
2537 |
}
|
Q |
2538 |
}
|
|
2539 |
}
|
d34256
|
2540 |
catch (const std::exception&)
|
Z |
2541 |
{
|
|
2542 |
DbgLog(_T("无法绘制图形(程序不合理)"));
|
|
2543 |
}
|
|
2544 |
|
418cb3
|
2545 |
m_nTotalRow = maxy + 1;
|
Q |
2546 |
/*
|
|
2547 |
for (int i = 0; i < 25; i++)
|
|
2548 |
{
|
|
2549 |
for (int j = 0; j < 16; j++)
|
|
2550 |
{
|
|
2551 |
Cells[i][j].nType = i;
|
|
2552 |
s1.Format(_T("%d:%d"), i, j);
|
|
2553 |
Cells[i][j].sCoilName = s1;
|
|
2554 |
}
|
|
2555 |
}
|
|
2556 |
*/
|
|
2557 |
needReDraw = 1;
|
|
2558 |
return 0;
|
|
2559 |
}
|
e55aec
|
2560 |
bool firstCoil = true;//本段第一个单元格
|
4ed7fc
|
2561 |
bool isPops = false;
|
d34256
|
2562 |
/// <summary>
|
Z |
2563 |
/// 梯形图转Prog
|
|
2564 |
/// </summary>
|
|
2565 |
/// <returns></returns>
|
418cb3
|
2566 |
int CMTerm1View::TransLDSToProg()
|
Q |
2567 |
{
|
|
2568 |
CMTerm1Doc * pDoc = GetDocument();
|
|
2569 |
CString s1;
|
|
2570 |
s1.Format(_T("Trans LDS to PRrog"));
|
|
2571 |
DbgLog(s1);
|
e55aec
|
2572 |
s1.Format(_T("将梯形图转成prog格式"));
|
Z |
2573 |
DbgLog(s1);
|
418cb3
|
2574 |
|
ad1b4b
|
2575 |
//梯形图 ROW数量
|
e55aec
|
2576 |
s1.Format(_T("总计行数 %d"), m_nTotalRow);
|
Z |
2577 |
DbgLog(s1);
|
418cb3
|
2578 |
s1.Format(_T("Total Lines %d"), m_nTotalRow);
|
Q |
2579 |
DbgLog(s1);
|
e55aec
|
2580 |
|
418cb3
|
2581 |
//分段
|
Q |
2582 |
int nDivCount = 0;
|
e55aec
|
2583 |
//分段 点集合
|
418cb3
|
2584 |
int Divs[100] = { 0 };
|
ad1b4b
|
2585 |
for (int i = 0; i < m_nTotalRow; i++)
|
Z |
2586 |
{
|
418cb3
|
2587 |
int nRow = i;
|
Q |
2588 |
int bConnected = 0;
|
aac3b3
|
2589 |
for (int j = 0; j < m_CellPerLine; j++)
|
ad1b4b
|
2590 |
{
|
418cb3
|
2591 |
int nCol = j;
|
ad1b4b
|
2592 |
if (Cells[nRow][nCol].bLeftLineDn)
|
Z |
2593 |
{
|
e55aec
|
2594 |
bConnected = 1;
|
Z |
2595 |
s1.Format(_T("row==%d col==%d 有左下竖线!!!"), nRow,nCol);
|
|
2596 |
DbgLog(s1);
|
|
2597 |
break;
|
418cb3
|
2598 |
}
|
ad1b4b
|
2599 |
}
|
Z |
2600 |
if (!bConnected)
|
|
2601 |
{
|
418cb3
|
2602 |
//找到一处分界点
|
Q |
2603 |
Divs[nDivCount] = i;
|
ad1b4b
|
2604 |
s1.Format(_T("Div at Line %d 是 ::::::::::::分界点"), nRow);
|
418cb3
|
2605 |
DbgLog(s1);
|
Q |
2606 |
nDivCount++;
|
|
2607 |
}
|
|
2608 |
}
|
ad1b4b
|
2609 |
|
aac3b3
|
2610 |
stProgSection allprogs;
|
418cb3
|
2611 |
//每段单独处理
|
ad1b4b
|
2612 |
for (int i = 0; i < nDivCount; i++)
|
Z |
2613 |
{
|
418cb3
|
2614 |
int nStartLine, nEndLine;
|
ad1b4b
|
2615 |
if (i == 0)
|
Z |
2616 |
{
|
e55aec
|
2617 |
nStartLine = 0;
|
Z |
2618 |
nEndLine = Divs[i];
|
4ed7fc
|
2619 |
}
|
ad1b4b
|
2620 |
else
|
Z |
2621 |
{
|
e55aec
|
2622 |
nStartLine = Divs[i - 1]+1;
|
Z |
2623 |
nEndLine = Divs[i];
|
ad1b4b
|
2624 |
}
|
e55aec
|
2625 |
s1.Format(_T("本段行号 起始-终止: %d - %d "), nStartLine, nEndLine);
|
Z |
2626 |
DbgLog(s1);
|
418cb3
|
2627 |
s1.Format(_T("Process Line %d - %d "), nStartLine, nEndLine);
|
Q |
2628 |
DbgLog(s1);
|
|
2629 |
int nCounts[20] = { 0 };
|
|
2630 |
int nCounts2[20] = { 0 };
|
|
2631 |
int nCounts3[20] = { 0 };
|
|
2632 |
|
|
2633 |
s1.Empty();
|
ad1b4b
|
2634 |
for (int j = 0; j < m_CellPerLine; j++)
|
Z |
2635 |
{
|
418cb3
|
2636 |
int nCount = 0;
|
Q |
2637 |
int nCount2 = 0;
|
|
2638 |
int nCount3 = 0;
|
ad1b4b
|
2639 |
for (int k = nStartLine; k <= nEndLine; k++)
|
Z |
2640 |
{
|
|
2641 |
if (Cells[k][j].nType)
|
|
2642 |
{
|
418cb3
|
2643 |
nCount += 1;
|
Q |
2644 |
nCount2 += 1;
|
|
2645 |
nCount3 += 1;
|
e55aec
|
2646 |
if (Cells[k][j].bLeftLineUp)
|
Z |
2647 |
{
|
|
2648 |
nCount2 -= 1;
|
|
2649 |
}
|
418cb3
|
2650 |
// if (Cells[k][j].bLeftLineDn) nCount2 -= 1;
|
ad1b4b
|
2651 |
|
Z |
2652 |
if (j != m_CellPerLine - 1)
|
|
2653 |
{
|
e55aec
|
2654 |
if (Cells[k][j + 1].bLeftLineUp)
|
Z |
2655 |
{
|
|
2656 |
nCount3 -= 1;
|
|
2657 |
}
|
418cb3
|
2658 |
// if (Cells[k][j + 1].bLeftLineDn) nCount3 -= 1;
|
Q |
2659 |
}
|
|
2660 |
}
|
|
2661 |
}
|
|
2662 |
nCounts[j] = nCount;
|
|
2663 |
nCounts2[j] = nCount2;
|
|
2664 |
nCounts3[j] = nCount3;
|
|
2665 |
}
|
ad1b4b
|
2666 |
|
418cb3
|
2667 |
s1.Empty();
|
ad1b4b
|
2668 |
for (int j = 0; j < m_CellPerLine; j++)
|
Z |
2669 |
{
|
418cb3
|
2670 |
s1.AppendFormat(_T(" %d(%d)"), nCounts[j],nCounts3[j]);
|
Q |
2671 |
}
|
e55aec
|
2672 |
DbgLog(_T(""));
|
ad1b4b
|
2673 |
|
418cb3
|
2674 |
DbgLog(s1);
|
Q |
2675 |
s1.Empty();
|
ad1b4b
|
2676 |
for (int j = 0; j < m_CellPerLine; j++)
|
Z |
2677 |
{
|
418cb3
|
2678 |
s1.AppendFormat(_T(" %d "), nCounts2[j]);
|
Q |
2679 |
}
|
|
2680 |
DbgLog(s1);
|
|
2681 |
//开始从左到右,从上到下扫描,主要关注 竖直连接线。
|
|
2682 |
int nCurPosX,nCurPosY;
|
|
2683 |
nCurPosY = nStartLine;
|
|
2684 |
nCurPosX = 0;
|
|
2685 |
CString sProg;
|
|
2686 |
int nAllSteps=0;
|
|
2687 |
stProgSection Progsec;
|
e55aec
|
2688 |
for (int i = nStartLine; i <= nEndLine; i++)
|
Z |
2689 |
{
|
418cb3
|
2690 |
CString sProgSec;
|
Q |
2691 |
int nSteps = 0;;
|
|
2692 |
nCurPosY = i;
|
|
2693 |
stProgSection thisprogsec;
|
|
2694 |
if (Cells[i][0].nType)
|
d34256
|
2695 |
{
|
e55aec
|
2696 |
firstCoil = true;
|
ad1b4b
|
2697 |
//循环遍历单元格(转换的逻辑在这个函数)
|
4ed7fc
|
2698 |
//ScanLDSCells(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec, nSteps);
|
Z |
2699 |
//ScanLDSCells2(nStartLine, nEndLine, nCurPosY, nCurPosX, 0, thisprogsec, sProgSec, nSteps);
|
d34256
|
2700 |
}
|
4ed7fc
|
2701 |
//sProg += sProgSec;
|
Z |
2702 |
// nAllSteps += nSteps;
|
|
2703 |
//Progsec += thisprogsec;
|
418cb3
|
2704 |
}
|
4ed7fc
|
2705 |
CString sProgSec;
|
Z |
2706 |
int nSteps = 0;;
|
|
2707 |
nCurPosY = i;
|
|
2708 |
stProgSection thisprogsec;
|
|
2709 |
ScanLDSCells2(nStartLine, nEndLine, nCurPosY, nCurPosX, 16,0, thisprogsec, sProgSec, nSteps);
|
|
2710 |
sProg += sProgSec;
|
|
2711 |
nAllSteps += nSteps;
|
|
2712 |
Progsec += thisprogsec;
|
418cb3
|
2713 |
DbgLog(_T("\r\n")+ sProg);
|
Q |
2714 |
int n = int(Progsec.Progs.size());
|
e55aec
|
2715 |
s1.Format(_T("程序段步数: %d "), n);
|
Z |
2716 |
DbgLog(s1);
|
418cb3
|
2717 |
s1.Format(_T("progSec steps %d "), n);
|
Q |
2718 |
DbgLog(s1);
|
ad1b4b
|
2719 |
for (int i = 0; i < n; i++)
|
Z |
2720 |
{
|
418cb3
|
2721 |
int optype = Progsec.Progs[i].nOpType1;
|
Q |
2722 |
CStringA OpTxtA, OpShowTxtA;
|
|
2723 |
CString OpTxt, OpShowTxt;
|
|
2724 |
pDoc->OpToTxt(optype, OpTxtA);
|
|
2725 |
pDoc->OpToShowTxt(optype, OpShowTxtA);
|
|
2726 |
OpTxt = OpTxtA;
|
|
2727 |
OpShowTxt = OpShowTxtA;
|
|
2728 |
s1.Format(_T("%d %s %s"), optype, OpTxt, OpShowTxt);
|
|
2729 |
DbgLog(s1);
|
|
2730 |
}
|
|
2731 |
allprogs += Progsec;
|
|
2732 |
}
|
ad1b4b
|
2733 |
|
418cb3
|
2734 |
//输出程序
|
Q |
2735 |
int n=(int)allprogs.Progs.size();
|
e55aec
|
2736 |
s1.Format(_T("总程序步数 %d "), n);
|
Z |
2737 |
DbgLog(s1);
|
418cb3
|
2738 |
s1.Format(_T("all prog steps %d "), n);
|
Q |
2739 |
DbgLog(s1);
|
ad1b4b
|
2740 |
for (int i = 0; i < n; i++)
|
Z |
2741 |
{
|
418cb3
|
2742 |
int optype=allprogs.Progs[i].nOpType1;
|
4ed7fc
|
2743 |
allprogs.Progs[i].PairTo = 0;//??????????
|
df0321
|
2744 |
allprogs.Progs[i].nBinStep = i;
|
418cb3
|
2745 |
CStringA OpTxtA,OpShowTxtA;
|
Q |
2746 |
CString OpTxt,OpShowTxt;
|
|
2747 |
pDoc->OpToTxt(optype, OpTxtA);
|
|
2748 |
pDoc->OpToShowTxt(optype, OpShowTxtA);
|
|
2749 |
OpTxt = OpTxtA;
|
|
2750 |
OpShowTxt = OpShowTxtA;
|
|
2751 |
s1.Format(_T("%d %s %s"), optype, OpTxt, OpShowTxt);
|
df0321
|
2752 |
pDoc->Progs[i] = allprogs.Progs[i];
|
418cb3
|
2753 |
// DbgLog(s1);
|
Q |
2754 |
}
|
df0321
|
2755 |
pDoc->m_nProgSteps = n;
|
418cb3
|
2756 |
return 0;
|
Q |
2757 |
}
|
|
2758 |
|
d34256
|
2759 |
|
Z |
2760 |
/// <summary>
|
|
2761 |
/// :绘制每个单元格的内容
|
|
2762 |
/// </summary>
|
|
2763 |
/// <param name="nStartLine"></param>
|
|
2764 |
/// <param name="nEndLine"></param>
|
aac3b3
|
2765 |
/// <param name="nPosY">行</param>
|
Z |
2766 |
/// <param name="nPosX">列</param>
|
|
2767 |
/// <param name="nLevel">层级</param>
|
e55aec
|
2768 |
/// <param name="progsec">prog格式的指令集</param>
|
Z |
2769 |
/// <param name="sProgSec">指令集</param>
|
|
2770 |
/// <param name="nSteps">程序步数</param>
|
d34256
|
2771 |
/// <returns></returns>
|
aac3b3
|
2772 |
int CMTerm1View::ScanLDSCells(int nStartLine, int nEndLine, int nPosY, int nPosX,
|
Z |
2773 |
int nLevel, stProgSection & progsec, CString & sProgSec, int &nSteps)
|
418cb3
|
2774 |
{
|
Q |
2775 |
CString s1;
|
|
2776 |
int nCurPosX, nCurPosY;
|
4ed7fc
|
2777 |
int nNextX = 1;//步长(下个起始点移动的距离)
|
418cb3
|
2778 |
nCurPosY = nPosY;
|
Q |
2779 |
nCurPosX = nPosX;
|
df0321
|
2780 |
int nCoilType, CoilAddr;
|
Q |
2781 |
CMTerm1Doc* pDoc = GetDocument();
|
ad1b4b
|
2782 |
for (int j = nPosX; j < m_CellPerLine; j += nNextX)
|
Z |
2783 |
{
|
418cb3
|
2784 |
nCurPosX = j;
|
4ed7fc
|
2785 |
//先处理当前单元基本信息;
|
418cb3
|
2786 |
int nType = Cells[nCurPosY][nCurPosX].nType;
|
Q |
2787 |
CString sCellName = Cells[nCurPosY][nCurPosX].sCoilName;
|
|
2788 |
CMTerm1Doc::stProg theprog;
|
df0321
|
2789 |
CStringA sCellNameA;
|
Q |
2790 |
sCellNameA = sCellName;
|
ad1b4b
|
2791 |
|
e55aec
|
2792 |
if (j + nNextX >= m_CellPerLine)
|
Z |
2793 |
{
|
|
2794 |
continue;
|
|
2795 |
}
|
|
2796 |
|
|
2797 |
//1.先获取此单元格右侧一格的竖线
|
|
2798 |
if (Cells[nCurPosY][j + nNextX].bLeftLineUp
|
|
2799 |
|| Cells[nCurPosY][j + nNextX].bLeftLineDn)
|
|
2800 |
{
|
|
2801 |
|
4ed7fc
|
2802 |
//先看往上面有没有连接
|
Z |
2803 |
if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
|
2804 |
{
|
|
2805 |
// 往上面有连接且有触点连接,才使用ORS
|
|
2806 |
s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX);
|
|
2807 |
DbgLog(s1);
|
|
2808 |
theprog.nOpType1 = OP_ORS;
|
|
2809 |
progsec.Append(theprog);
|
|
2810 |
sProgSec.AppendFormat(_T("ORS \r\n"));
|
|
2811 |
firstCoil = false;
|
|
2812 |
nSteps += 1;
|
|
2813 |
nLevel -= 1;
|
|
2814 |
}
|
|
2815 |
//右侧一格的左上是否有链接
|
e55aec
|
2816 |
int nLeftUpCon = 0;
|
Z |
2817 |
if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
|
2818 |
{
|
|
2819 |
nLeftUpCon = 1;
|
|
2820 |
}
|
4ed7fc
|
2821 |
//向下查找,看看竖线的右侧一格的左侧下面还有没有连接其他东西
|
Z |
2822 |
int nLeftDnCon = 0;//单元格右侧一格的左侧向下连接数
|
|
2823 |
for (int k = nCurPosY; k <= nEndLine; k++)
|
e55aec
|
2824 |
{
|
Z |
2825 |
if (Cells[k][j + nNextX].bLeftLineDn)
|
|
2826 |
{
|
|
2827 |
if (Cells[k][j + nNextX - 1].nType)
|
|
2828 |
{
|
|
2829 |
nLeftDnCon += 1;
|
|
2830 |
}
|
|
2831 |
}
|
|
2832 |
else
|
|
2833 |
{
|
|
2834 |
break; // 竖线到最下面的端点了。
|
|
2835 |
}
|
|
2836 |
}
|
|
2837 |
|
|
2838 |
s1.Format(_T("LeftUp %d LeftDn %d"), nLeftUpCon, nLeftDnCon);
|
|
2839 |
DbgLog(s1);
|
|
2840 |
|
4ed7fc
|
2841 |
//右侧一格的左侧下面有连接,那么扫描到这个竖线时返回,继续扫描左侧下面的内容。
|
e55aec
|
2842 |
if (nLeftDnCon)
|
Z |
2843 |
{
|
|
2844 |
return 1;
|
|
2845 |
}
|
4ed7fc
|
2846 |
//右侧一格的左侧下面没有连接,那么这个就是左面最后的单元,开始处理右面的单元。
|
e55aec
|
2847 |
else
|
Z |
2848 |
{
|
|
2849 |
if (nLeftUpCon)
|
|
2850 |
{
|
|
2851 |
if (nPosX > 0 || nLevel > 0)
|
|
2852 |
{
|
|
2853 |
s1.Format(_T("%d %d ANS "), nCurPosY, nCurPosX);
|
|
2854 |
DbgLog(s1);
|
|
2855 |
theprog.nOpType1 = OP_ANS;
|
|
2856 |
progsec.Append(theprog);
|
|
2857 |
sProgSec.AppendFormat(_T("ANS \r\n"));
|
|
2858 |
nSteps += 1;
|
|
2859 |
nLevel -= 1;
|
|
2860 |
}
|
|
2861 |
}
|
|
2862 |
//从头到尾处理, 查找此竖线的最高位置;
|
|
2863 |
int nLineTop = nCurPosY;
|
|
2864 |
int nLineBottom = nCurPosY;
|
|
2865 |
for (int k = nCurPosY; k >= nStartLine; k--)
|
|
2866 |
{
|
|
2867 |
if (!Cells[k][j + nNextX].bLeftLineUp)
|
|
2868 |
{
|
|
2869 |
break;
|
|
2870 |
}
|
|
2871 |
nLineTop = k - 1;
|
|
2872 |
}
|
|
2873 |
|
|
2874 |
// 查找右侧有几个连接
|
|
2875 |
int nRightCon = 0;//单元格右侧连接数
|
|
2876 |
for (int k = nLineTop; k <= nEndLine; k++)
|
|
2877 |
{
|
|
2878 |
if (Cells[k][j + nNextX].nType)
|
|
2879 |
{
|
|
2880 |
nRightCon += 1;
|
|
2881 |
}
|
|
2882 |
nLineBottom = k;
|
|
2883 |
if (!Cells[k][j + nNextX].bLeftLineDn)
|
|
2884 |
{
|
|
2885 |
break;
|
|
2886 |
}
|
|
2887 |
}
|
|
2888 |
s1.Format(_T("VLine %d - %d : %d , right = %d "), nLineTop, nLineBottom, j + nNextX, nRightCon);
|
|
2889 |
DbgLog(s1);
|
|
2890 |
|
|
2891 |
if (nRightCon == 1)
|
|
2892 |
{
|
4ed7fc
|
2893 |
s1.Format(_T(">>>> Go %d : %d , level %d "), nLineTop, j + nNextX, nLevel);
|
aac3b3
|
2894 |
DbgLog(s1);
|
Z |
2895 |
CString ProgSec;
|
|
2896 |
int theSteps = 0;
|
|
2897 |
stProgSection thisprogsec;
|
e55aec
|
2898 |
|
4ed7fc
|
2899 |
//这有问题,应该是在最高点的时候,单独进行一次转换?
|
aac3b3
|
2900 |
int r = ScanLDSCells(nStartLine, nEndLine, nLineTop, j + nNextX, nLevel, thisprogsec, ProgSec, theSteps);
|
e55aec
|
2901 |
|
aac3b3
|
2902 |
sProgSec += ProgSec;
|
Z |
2903 |
nSteps += theSteps;
|
|
2904 |
progsec += thisprogsec;
|
|
2905 |
s1.Format(_T("<<<< Re %d : %d , Result %d "), nLineTop, j + nNextX, 0);
|
|
2906 |
DbgLog(s1);
|
4ed7fc
|
2907 |
continue;
|
e55aec
|
2908 |
}
|
Z |
2909 |
else
|
|
2910 |
{
|
|
2911 |
int nLastResult = 0;
|
|
2912 |
int nRightCount = 0;
|
|
2913 |
CString sCons[100];
|
|
2914 |
CString ProgSecs[100];
|
|
2915 |
int res[100] = { 0 };
|
|
2916 |
int nLastSteps = 0;
|
|
2917 |
for (int k = nLineTop; k <= nLineBottom; k++)
|
|
2918 |
{
|
|
2919 |
//s1.Format(_T("VLine %d - %d : %d %d of %d "), nLineTop, nLineBottom, j + nNextX, k+1,nRightCon);
|
|
2920 |
//DbgLog(s1);
|
|
2921 |
if (Cells[k][j + nNextX].nType)
|
|
2922 |
{
|
|
2923 |
s1.Format(_T(" >>> Go %d : %d , level %d "), k, j + nNextX, nLevel + 1);
|
|
2924 |
DbgLog(s1);
|
|
2925 |
CString ProgSec;
|
|
2926 |
int theSteps = 0;
|
|
2927 |
nLevel += 1;
|
|
2928 |
stProgSection thisprogsec;
|
|
2929 |
res[nRightCount] = ScanLDSCells(nStartLine, nEndLine, k, j + nNextX, nLevel, thisprogsec, ProgSecs[nRightCount], theSteps);
|
|
2930 |
nLastResult = res[nRightCount];
|
|
2931 |
nSteps += theSteps;
|
|
2932 |
progsec += thisprogsec;
|
|
2933 |
//if (res[nRightCount] > 0) nLevel += 1;
|
|
2934 |
sProgSec += ProgSec;
|
|
2935 |
s1.Format(_T(" <<< Re %d : %d , Result %d Steps %d Last %d"), k, j + nNextX, res[nRightCount], theSteps, nLastSteps);
|
|
2936 |
DbgLog(s1);
|
|
2937 |
if (nRightCount == 0)
|
|
2938 |
{
|
4ed7fc
|
2939 |
//这里是不是应该做点什么
|
e55aec
|
2940 |
}
|
Z |
2941 |
else if (res[nRightCount - 1] == 0)
|
|
2942 |
{
|
|
2943 |
s1.Format(_T(" POPS"), k, j + nNextX, nLevel + 1);
|
|
2944 |
DbgLog(s1);
|
|
2945 |
//sProgSec.AppendFormat(_T("POPS \r\n"));
|
|
2946 |
if (nLastSteps > 1)
|
|
2947 |
{
|
|
2948 |
if (sCons[nRightCount - 1] == _T("POPS"))
|
|
2949 |
{
|
|
2950 |
sCons[nRightCount - 1] = _T("RDS");
|
|
2951 |
}
|
|
2952 |
else
|
|
2953 |
{
|
|
2954 |
sCons[nRightCount - 1] = _T("PSHS");
|
|
2955 |
}
|
|
2956 |
sCons[nRightCount] = _T("POPS");
|
|
2957 |
}
|
|
2958 |
}
|
|
2959 |
else
|
|
2960 |
{
|
|
2961 |
|
|
2962 |
}
|
|
2963 |
nLastSteps = theSteps;
|
|
2964 |
nRightCount++;
|
|
2965 |
}
|
|
2966 |
}
|
|
2967 |
nLastResult = 0;
|
|
2968 |
for (int k = 0; k < nRightCount; k++)
|
|
2969 |
{
|
|
2970 |
if (nLastResult || res[k])
|
|
2971 |
{
|
|
2972 |
s1 = _T("ST") + ProgSecs[k];
|
|
2973 |
|
|
2974 |
ProgSecs[k] = s1;
|
|
2975 |
}
|
|
2976 |
s1 = sCons[k] + _T("\r\n") + ProgSecs[k];
|
|
2977 |
sProgSec.Append(s1);
|
|
2978 |
nLastResult = res[k];
|
|
2979 |
}
|
|
2980 |
if (nLastResult)
|
|
2981 |
{
|
|
2982 |
sProgSec.Append(_T("ANS\r\n"));
|
|
2983 |
}
|
|
2984 |
return 0;
|
|
2985 |
}
|
|
2986 |
}
|
|
2987 |
}
|
4ed7fc
|
2988 |
//如果没有竖线直接翻译
|
Z |
2989 |
else
|
|
2990 |
{
|
|
2991 |
Translate2Prog(nType, j + nNextX, nLevel, sCellName, progsec, sProgSec, nSteps);
|
|
2992 |
}
|
|
2993 |
/*
|
e55aec
|
2994 |
#pragma region 根据单元格类型转换为指令和prog
|
Z |
2995 |
|
|
2996 |
if (nType == typeNO)
|
d34256
|
2997 |
{
|
ad1b4b
|
2998 |
if (firstCoil && nType != typeLine1 && nType != typeLine2)
|
Z |
2999 |
{
|
aac3b3
|
3000 |
//先看往上面有没有连接
|
Z |
3001 |
if (Cells[nCurPosY][j + nNextX].bLeftLineUp)
|
|
3002 |
{
|
|
3003 |
// 往上面有连接且有触点连接,才使用OR
|
|
3004 |
s1.Format(_T("%d %d OR %s"), nCurPosY, nCurPosX, sCellName);
|
|
3005 |
sProgSec.AppendFormat(_T("OR %s\r\n"), sCellName);
|
|
3006 |
theprog.nOpType1 = OP_OR;
|
|
3007 |
}
|
|
3008 |
else
|
|
3009 |
{
|
|
3010 |
s1.Format(_T("%d %d ST %s"), nCurPosY, nCurPosX, sCellName);
|
|
3011 |
sProgSec.AppendFormat(_T("ST %s\r\n"), sCellName);
|
|
3012 |
theprog.nOpType1 = OP_ST;
|
|
3013 |
}
|
df0321
|
3014 |
theprog.nParamCount = 1;
|
Q |
3015 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3016 |
theprog.Params[0].nParamType = nCoilType;
|
|
3017 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3018 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3019 |
progsec.Append(theprog);
|
ad1b4b
|
3020 |
firstCoil = false;
|
418cb3
|
3021 |
}
|
e55aec
|
3022 |
else
|
Z |
3023 |
{
|
418cb3
|
3024 |
s1.Format(_T("%d %d AN %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3025 |
sProgSec.AppendFormat(_T("NO %s\r\n"), sCellName);
|
|
3026 |
theprog.nOpType1 = OP_AN;
|
df0321
|
3027 |
theprog.nParamCount = 1;
|
Q |
3028 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3029 |
theprog.Params[0].nParamType = nCoilType;
|
|
3030 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3031 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3032 |
progsec.Append(theprog);
|
Q |
3033 |
}
|
|
3034 |
nSteps += 1;
|
|
3035 |
DbgLog(s1);
|
e55aec
|
3036 |
nNextX = 1;
|
ad1b4b
|
3037 |
}
|
e55aec
|
3038 |
else if (nType == typeNC)
|
ad1b4b
|
3039 |
{
|
Z |
3040 |
if (firstCoil && nType != typeLine1 && nType != typeLine2)
|
|
3041 |
{
|
418cb3
|
3042 |
s1.Format(_T("%d %d ST/ %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3043 |
sProgSec.AppendFormat(_T("ST/ %s\r\n"), sCellName);
|
|
3044 |
theprog.nOpType1 = OP_ST_;
|
df0321
|
3045 |
theprog.nParamCount = 1;
|
Q |
3046 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3047 |
theprog.Params[0].nParamType = nCoilType;
|
|
3048 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3049 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3050 |
progsec.Append(theprog);
|
ad1b4b
|
3051 |
firstCoil = false;
|
418cb3
|
3052 |
}
|
Q |
3053 |
else
|
|
3054 |
{
|
|
3055 |
s1.Format(_T("%d %d AN/ %s"), nCurPosY, nCurPosX, sCellName);
|
|
3056 |
sProgSec.AppendFormat(_T("AN/ %s\r\n"), sCellName);
|
|
3057 |
theprog.nOpType1 = OP_AN_;
|
df0321
|
3058 |
theprog.nParamCount = 1;
|
Q |
3059 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3060 |
theprog.Params[0].nParamType = nCoilType;
|
|
3061 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3062 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3063 |
progsec.Append(theprog);
|
Q |
3064 |
}
|
|
3065 |
DbgLog(s1);
|
|
3066 |
nSteps += 1;
|
e55aec
|
3067 |
nNextX = 1;
|
ad1b4b
|
3068 |
}
|
e55aec
|
3069 |
else if (nType == typePP)
|
ad1b4b
|
3070 |
{
|
418cb3
|
3071 |
s1.Format(_T("%d %d PP %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3072 |
DbgLog(s1);
|
|
3073 |
//progsec.Append(theprog);
|
|
3074 |
sProgSec.AppendFormat(_T("PP %s\r\n"), sCellName);
|
|
3075 |
nSteps += 1;
|
e55aec
|
3076 |
nNextX = 1;
|
ad1b4b
|
3077 |
}
|
e55aec
|
3078 |
else if (nType == typePN)
|
ad1b4b
|
3079 |
{
|
418cb3
|
3080 |
s1.Format(_T("%d %d PN %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3081 |
DbgLog(s1);
|
|
3082 |
//progsec.Append(theprog);
|
|
3083 |
sProgSec.AppendFormat(_T("PN %s\r\n"), sCellName, sCellName);
|
|
3084 |
nSteps += 1;
|
e55aec
|
3085 |
nNextX = 1;
|
ad1b4b
|
3086 |
}
|
e55aec
|
3087 |
else if (nType == typeNOT)
|
ad1b4b
|
3088 |
{
|
418cb3
|
3089 |
s1.Format(_T("%d %d NOT %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3090 |
DbgLog(s1);
|
|
3091 |
sProgSec.AppendFormat(_T("NOT %s\r\n"), sCellName);
|
|
3092 |
theprog.nOpType1 = OP_NOT;
|
|
3093 |
progsec.Append(theprog);
|
|
3094 |
nSteps += 1;
|
e55aec
|
3095 |
nNextX = 1;
|
ad1b4b
|
3096 |
}
|
Z |
3097 |
else if (nType == typeDF)
|
|
3098 |
{
|
418cb3
|
3099 |
s1.Format(_T("%d %d DF %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3100 |
DbgLog(s1);
|
|
3101 |
sProgSec.AppendFormat(_T("DF %s\r\n"), sCellName);
|
|
3102 |
theprog.nOpType1 = OP_DF;
|
|
3103 |
progsec.Append(theprog);
|
|
3104 |
nSteps += 1;
|
e55aec
|
3105 |
nNextX = 1;
|
ad1b4b
|
3106 |
}
|
Z |
3107 |
else if (nType == typeDF_)
|
|
3108 |
{
|
418cb3
|
3109 |
s1.Format(_T("%d %d DF/ %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3110 |
DbgLog(s1);
|
|
3111 |
sProgSec.AppendFormat(_T("DF/ %s\r\n"), sCellName);
|
|
3112 |
theprog.nOpType1 = OP_DF_;
|
|
3113 |
progsec.Append(theprog);
|
|
3114 |
nSteps += 1;
|
e55aec
|
3115 |
nNextX = 1;
|
ad1b4b
|
3116 |
}
|
Z |
3117 |
else if (nType == typeOUT)
|
|
3118 |
{
|
418cb3
|
3119 |
s1.Format(_T("%d %d OUT %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3120 |
DbgLog(s1);
|
|
3121 |
sProgSec.AppendFormat(_T("OUT %s\r\n"), sCellName);
|
|
3122 |
theprog.nOpType1 = OP_OUT;
|
df0321
|
3123 |
theprog.nParamCount = 1;
|
Q |
3124 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3125 |
theprog.Params[0].nParamType = nCoilType;
|
|
3126 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3127 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3128 |
progsec.Append(theprog);
|
Q |
3129 |
nSteps += 1;
|
e55aec
|
3130 |
nNextX = 1;
|
ad1b4b
|
3131 |
}
|
Z |
3132 |
else if (nType == typeSET)
|
|
3133 |
{
|
418cb3
|
3134 |
s1.Format(_T("%d %d SET %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3135 |
DbgLog(s1);
|
|
3136 |
sProgSec.AppendFormat(_T("SET %s\r\n"), sCellName);
|
|
3137 |
theprog.nOpType1 = OP_SET;
|
df0321
|
3138 |
theprog.nParamCount = 1;
|
Q |
3139 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3140 |
theprog.Params[0].nParamType = nCoilType;
|
|
3141 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3142 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3143 |
progsec.Append(theprog);
|
Q |
3144 |
nSteps += 1;
|
e55aec
|
3145 |
nNextX = 1;
|
ad1b4b
|
3146 |
}
|
Z |
3147 |
else if (nType == typeRESET)
|
|
3148 |
{
|
418cb3
|
3149 |
s1.Format(_T("%d %d RESET %s"), nCurPosY, nCurPosX, sCellName);
|
Q |
3150 |
DbgLog(s1);
|
|
3151 |
sProgSec.AppendFormat(_T("RESET %s\r\n"), sCellName);
|
|
3152 |
theprog.nOpType1 = OP_RESET;
|
df0321
|
3153 |
theprog.nParamCount = 1;
|
Q |
3154 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3155 |
theprog.Params[0].nParamType = nCoilType;
|
|
3156 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3157 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3158 |
progsec.Append(theprog);
|
Q |
3159 |
nSteps += 1;
|
e55aec
|
3160 |
nNextX = 1;
|
ad1b4b
|
3161 |
}
|
e55aec
|
3162 |
else if (nType == typeCMP)
|
ad1b4b
|
3163 |
{
|
e55aec
|
3164 |
s1.Format(_T("%d %d CMP %s %s %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
418cb3
|
3165 |
DbgLog(s1);
|
Q |
3166 |
theprog.nOpType1 = OP_ST_GT;
|
df0321
|
3167 |
theprog.nParamCount = 1;
|
418cb3
|
3168 |
progsec.Append(theprog);
|
Q |
3169 |
sProgSec.AppendFormat(_T("CMP %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
|
3170 |
nSteps += 1;
|
e55aec
|
3171 |
nNextX = 3;
|
ad1b4b
|
3172 |
}
|
e55aec
|
3173 |
else if (nType == typeTM)
|
ad1b4b
|
3174 |
{
|
e55aec
|
3175 |
s1.Format(_T("%d %d TM %s %d %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
418cb3
|
3176 |
DbgLog(s1);
|
Q |
3177 |
theprog.nOpType1 = OP_TMX;
|
df0321
|
3178 |
theprog.nParamCount = 1;
|
Q |
3179 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3180 |
theprog.Params[0].nParamType = nCoilType;
|
|
3181 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3182 |
theprog.Params[0].sParamStr = sCellNameA;
|
418cb3
|
3183 |
progsec.Append(theprog);
|
e55aec
|
3184 |
sProgSec.AppendFormat(_T("TM %s %d %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
418cb3
|
3185 |
nSteps += 1;
|
e55aec
|
3186 |
nNextX = 3;
|
ad1b4b
|
3187 |
}
|
e55aec
|
3188 |
else if (nType == typeFN1)
|
ad1b4b
|
3189 |
{
|
e55aec
|
3190 |
s1.Format(_T("%d %d FN1 %s %s"), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam);
|
418cb3
|
3191 |
DbgLog(s1);
|
Q |
3192 |
theprog.nOpType1 = OP_INC;
|
|
3193 |
progsec.Append(theprog);
|
|
3194 |
sProgSec.AppendFormat(_T("FN1 %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam);
|
|
3195 |
nSteps += 1;
|
e55aec
|
3196 |
nNextX = 2;
|
ad1b4b
|
3197 |
}
|
e55aec
|
3198 |
else if (nType == typeFN2)
|
ad1b4b
|
3199 |
{
|
418cb3
|
3200 |
s1.Format(_T("%d %d FN2 %s %s %s "), nCurPosY, nCurPosX, sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
Q |
3201 |
DbgLog(s1);
|
|
3202 |
theprog.nOpType1 = OP_MV;
|
|
3203 |
progsec.Append(theprog);
|
|
3204 |
sProgSec.AppendFormat(_T("FN2 %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
|
3205 |
nSteps += 1;
|
e55aec
|
3206 |
nNextX = 3;
|
ad1b4b
|
3207 |
}
|
e55aec
|
3208 |
else if (nType == typeFN3)
|
ad1b4b
|
3209 |
{
|
418cb3
|
3210 |
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);
|
Q |
3211 |
DbgLog(s1);
|
|
3212 |
theprog.nOpType1 = OP_ADD3;
|
|
3213 |
progsec.Append(theprog);
|
|
3214 |
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);
|
|
3215 |
nSteps += 1;
|
e55aec
|
3216 |
nNextX = 4;
|
ad1b4b
|
3217 |
}
|
e55aec
|
3218 |
else
|
ad1b4b
|
3219 |
{
|
e55aec
|
3220 |
nNextX = 1;
|
418cb3
|
3221 |
//continue;
|
Q |
3222 |
}
|
e55aec
|
3223 |
|
Z |
3224 |
#pragma endregion
|
4ed7fc
|
3225 |
*/
|
418cb3
|
3226 |
}
|
Q |
3227 |
return 0;
|
aac3b3
|
3228 |
}
|
4ed7fc
|
3229 |
// 记录y,x
|
Z |
3230 |
std::pair<int, int> popsPoint[100]; int nPSHS = -1;
|
|
3231 |
int CMTerm1View::ScanLDSCells2(int nStartLine, int nEndLine, int nPosY, int nPosX, int nSizeX,
|
|
3232 |
int nLevel, stProgSection& progsec, CString& sProgSec, int& nSteps)
|
|
3233 |
{
|
|
3234 |
CString s1;
|
|
3235 |
int nCurPosX, nCurPosY;
|
|
3236 |
int nNextX = 0;//步长(到下个线圈起始位置应移动距离
|
|
3237 |
nCurPosY = nStartLine;
|
|
3238 |
nCurPosX = nPosX;
|
|
3239 |
int nCoilType, CoilAddr;
|
|
3240 |
CMTerm1Doc* pDoc = GetDocument();
|
aac3b3
|
3241 |
|
4ed7fc
|
3242 |
for (int j = nPosX; j < nSizeX; j += nNextX)
|
Z |
3243 |
{
|
|
3244 |
nCurPosX = j;
|
|
3245 |
//先处理当前单元;
|
|
3246 |
int nType = Cells[nCurPosY][nCurPosX].nType;
|
|
3247 |
CString sCellName = Cells[nCurPosY][nCurPosX].sCoilName;
|
|
3248 |
CMTerm1Doc::stProg theprog;
|
|
3249 |
CStringA sCellNameA;
|
|
3250 |
sCellNameA = sCellName;
|
|
3251 |
CString ProgSec;
|
|
3252 |
int theSteps = 0;
|
aac3b3
|
3253 |
|
4ed7fc
|
3254 |
stProgSection thisprogsec;
|
Z |
3255 |
|
|
3256 |
//判断越界
|
89cd74
|
3257 |
if (j + nNextX > m_CellPerLine)
|
4ed7fc
|
3258 |
{
|
Z |
3259 |
continue;
|
|
3260 |
}
|
|
3261 |
//if (!firstCoil && Cells[nCurPosY][j].bLeftLineUp)
|
|
3262 |
//{
|
|
3263 |
// break;
|
|
3264 |
//}
|
|
3265 |
if (Cells[nCurPosY][nCurPosX].nType == typeNone)
|
|
3266 |
{
|
|
3267 |
nNextX = 1;
|
|
3268 |
continue;
|
|
3269 |
}
|
|
3270 |
//开始翻译单个单元格,并返回下个单元格位置
|
|
3271 |
nNextX = Translate2Prog(nType, nCurPosY, nCurPosX, sCellName, progsec, sProgSec, nSteps);
|
|
3272 |
//1.判断此单元格右侧一格是否有向下的竖线
|
|
3273 |
if (Cells[nCurPosY][j + nNextX].bLeftLineDn)
|
|
3274 |
{
|
|
3275 |
//1.1:有分支,直接开始读取下一行
|
|
3276 |
if (Cells[nCurPosY +1][j].nType == typeNone)
|
|
3277 |
{
|
|
3278 |
if (Cells[nCurPosY + 1][j + nNextX].nType != typeNone)
|
|
3279 |
{
|
|
3280 |
firstCoil = true;
|
|
3281 |
}
|
|
3282 |
continue;
|
|
3283 |
}
|
|
3284 |
|
|
3285 |
firstCoil = true;
|
|
3286 |
ScanLDSCells2(nCurPosY + 1, nCurPosY + 1, nCurPosY + 1, 0, j + nNextX, ++nLevel, thisprogsec, ProgSec, theSteps);
|
|
3287 |
|
|
3288 |
//有OR关系且不只一个节点
|
|
3289 |
if (theSteps > 1 && nLevel > 0)
|
|
3290 |
{
|
|
3291 |
// 步数大于1,是复合结果,才使用ORS
|
|
3292 |
s1.Format(_T("%d %d ORS "), nCurPosY, nCurPosX);
|
|
3293 |
DbgLog(s1);
|
|
3294 |
theprog.nOpType1 = OP_ORS;
|
|
3295 |
//progsec.Append(theprog);
|
|
3296 |
//sProgSec.AppendFormat(_T("ORS \r\n"));
|
|
3297 |
thisprogsec.Append(theprog);
|
|
3298 |
ProgSec.AppendFormat(_T("ORS \r\n"));
|
|
3299 |
firstCoil = false;
|
|
3300 |
nSteps += 1;
|
|
3301 |
}
|
|
3302 |
|
|
3303 |
//1.2:从后向前查找下一行是否还有向上的竖线(形成闭环)(ORS、ANS)
|
|
3304 |
for (int k = j; k >= 0; k--)
|
|
3305 |
{
|
|
3306 |
if (Cells[nCurPosY + 1][k].nType == typeNone)
|
|
3307 |
{
|
|
3308 |
//如果遇到空格,还没搜到,就结束搜索
|
|
3309 |
break;
|
|
3310 |
}
|
|
3311 |
if (Cells[nCurPosY+1][k].bLeftLineUp)
|
|
3312 |
{
|
|
3313 |
//如果有一条竖线,说明是形成了环,要用ANS
|
|
3314 |
if (theSteps >= 1 && nLevel > 0)
|
|
3315 |
{
|
|
3316 |
//步数大于1,是复合结果,使用ANS
|
|
3317 |
s1.Format(_T("%d %d ANS "), nCurPosY, nCurPosX);
|
|
3318 |
DbgLog(s1);
|
|
3319 |
theprog.nOpType1 = OP_ANS;
|
|
3320 |
//progsec.Append(theprog);
|
|
3321 |
//sProgSec.AppendFormat(_T("ANS \r\n"));
|
|
3322 |
thisprogsec.Append(theprog);
|
|
3323 |
ProgSec.AppendFormat(_T("ANS \r\n"));
|
|
3324 |
nSteps += 1;
|
|
3325 |
}
|
|
3326 |
}
|
|
3327 |
}
|
|
3328 |
|
|
3329 |
//将转换完成的部分加入到总集中
|
|
3330 |
nSteps += theSteps;
|
|
3331 |
progsec += thisprogsec;
|
|
3332 |
sProgSec += ProgSec;
|
|
3333 |
|
|
3334 |
//1.3:查询此分支下一级连接点左右均存在节点,存在就PSHS
|
|
3335 |
if (Cells[nCurPosY + 1][j].nType != typeNone
|
|
3336 |
&& Cells[nCurPosY + 1][j + 1].nType != typeNone)
|
|
3337 |
{
|
|
3338 |
++nPSHS;
|
|
3339 |
CString push = _T("PSHS \r\n");
|
|
3340 |
theprog.nOpType1 = OP_PSHS;
|
|
3341 |
progsec.Append(theprog);
|
|
3342 |
sProgSec.Append(push);
|
|
3343 |
popsPoint[nPSHS] = std::make_pair(nCurPosY + 1, j + 1);
|
|
3344 |
}
|
|
3345 |
}//end 1.判断此单元格右侧一格是否有向下的竖线
|
|
3346 |
|
|
3347 |
}
|
|
3348 |
nLevel--;
|
|
3349 |
//已回到起始层
|
|
3350 |
if (nLevel == 0)
|
|
3351 |
{
|
|
3352 |
CMTerm1Doc::stProg theprog;
|
|
3353 |
for (int i = nPSHS; i >= 0; i--)
|
|
3354 |
{
|
|
3355 |
//+POP
|
|
3356 |
CString pop = _T("POPS \r\n");
|
|
3357 |
theprog.nOpType1 = OP_POPS;
|
|
3358 |
progsec.Append(theprog);
|
|
3359 |
sProgSec.Append(pop);
|
|
3360 |
//+fanyi
|
|
3361 |
//开始翻译单个单元格,并返回下个单元格位置
|
|
3362 |
//firstCoil = true;
|
|
3363 |
ScanLDSCells2(popsPoint[nPSHS].first, popsPoint[nPSHS].first, popsPoint[nPSHS].first, popsPoint[nPSHS].second, 16, nLevel, progsec, sProgSec, nSteps);
|
|
3364 |
nPSHS--;
|
|
3365 |
|
|
3366 |
}
|
|
3367 |
if (nPSHS == -1)
|
|
3368 |
{
|
|
3369 |
fill(popsPoint, popsPoint + 100, std::make_pair(0, 0));
|
|
3370 |
}
|
|
3371 |
}
|
|
3372 |
|
|
3373 |
return 0;
|
418cb3
|
3374 |
}
|
4ed7fc
|
3375 |
|
Z |
3376 |
|
|
3377 |
int CMTerm1View::Translate2Prog(
|
|
3378 |
int nType, int nCurPosY, int nCurPosX, CString sCellName,
|
|
3379 |
stProgSection& progsec, CString& sProgSec, int& nSteps)
|
|
3380 |
{
|
|
3381 |
CString s1;
|
|
3382 |
int nNextX = 1;//步长
|
|
3383 |
int nCoilType, CoilAddr;
|
|
3384 |
CMTerm1Doc::stProg theprog;
|
|
3385 |
CMTerm1Doc* pDoc = GetDocument();
|
|
3386 |
CStringA sCellNameA;
|
|
3387 |
sCellNameA = sCellName;
|
|
3388 |
//if (nType == typeNone)
|
|
3389 |
//{
|
|
3390 |
// return 0;
|
|
3391 |
//}
|
|
3392 |
if (nType == typeNO)
|
|
3393 |
{
|
|
3394 |
if (firstCoil && nType != typeLine1 && nType != typeLine2)
|
|
3395 |
{
|
|
3396 |
//先看往上面有没有连接
|
|
3397 |
if (Cells[nCurPosY][nCurPosX + nNextX].bLeftLineUp)
|
|
3398 |
{
|
|
3399 |
// 往上面有连接,使用OR
|
|
3400 |
sProgSec.AppendFormat(_T("OR %s\r\n"), sCellName);
|
|
3401 |
theprog.nOpType1 = OP_OR;
|
|
3402 |
}
|
|
3403 |
else
|
|
3404 |
{
|
|
3405 |
sProgSec.AppendFormat(_T("ST %s\r\n"), sCellName);
|
|
3406 |
theprog.nOpType1 = OP_ST;
|
|
3407 |
}
|
|
3408 |
theprog.nParamCount = 1;
|
|
3409 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3410 |
theprog.Params[0].nParamType = nCoilType;
|
|
3411 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3412 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3413 |
progsec.Append(theprog);
|
|
3414 |
firstCoil = false;
|
|
3415 |
}
|
|
3416 |
else
|
|
3417 |
{
|
|
3418 |
sProgSec.AppendFormat(_T("AN %s\r\n"), sCellName);
|
|
3419 |
theprog.nOpType1 = OP_AN;
|
|
3420 |
theprog.nParamCount = 1;
|
|
3421 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3422 |
theprog.Params[0].nParamType = nCoilType;
|
|
3423 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3424 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3425 |
progsec.Append(theprog);
|
|
3426 |
}
|
|
3427 |
|
|
3428 |
nSteps += 1;
|
|
3429 |
nNextX = 1;
|
|
3430 |
}
|
|
3431 |
else if (nType == typeNC)
|
|
3432 |
{
|
|
3433 |
if (firstCoil && nType != typeLine1 && nType != typeLine2)
|
|
3434 |
{
|
|
3435 |
sProgSec.AppendFormat(_T("ST/ %s\r\n"), sCellName);
|
|
3436 |
theprog.nOpType1 = OP_ST_;
|
|
3437 |
theprog.nParamCount = 1;
|
|
3438 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3439 |
theprog.Params[0].nParamType = nCoilType;
|
|
3440 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3441 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3442 |
progsec.Append(theprog);
|
|
3443 |
firstCoil = false;
|
|
3444 |
}
|
|
3445 |
else
|
|
3446 |
{
|
|
3447 |
sProgSec.AppendFormat(_T("AN/ %s\r\n"), sCellName);
|
|
3448 |
theprog.nOpType1 = OP_AN_;
|
|
3449 |
theprog.nParamCount = 1;
|
|
3450 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3451 |
theprog.Params[0].nParamType = nCoilType;
|
|
3452 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3453 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3454 |
progsec.Append(theprog);
|
|
3455 |
}
|
|
3456 |
nSteps += 1;
|
|
3457 |
nNextX = 1;
|
|
3458 |
}
|
|
3459 |
else if (nType == typePP)
|
|
3460 |
{
|
|
3461 |
//progsec.Append(theprog);
|
|
3462 |
sProgSec.AppendFormat(_T("PP %s\r\n"), sCellName);
|
|
3463 |
nSteps += 1;
|
|
3464 |
nNextX = 1;
|
|
3465 |
}
|
|
3466 |
else if (nType == typePN)
|
|
3467 |
{
|
|
3468 |
//progsec.Append(theprog);
|
|
3469 |
sProgSec.AppendFormat(_T("PN %s\r\n"), sCellName, sCellName);
|
|
3470 |
nSteps += 1;
|
|
3471 |
nNextX = 1;
|
|
3472 |
}
|
|
3473 |
else if (nType == typeNOT)
|
|
3474 |
{
|
|
3475 |
sProgSec.AppendFormat(_T("NOT %s\r\n"), sCellName);
|
|
3476 |
theprog.nOpType1 = OP_NOT;
|
|
3477 |
progsec.Append(theprog);
|
|
3478 |
nSteps += 1;
|
|
3479 |
nNextX = 1;
|
|
3480 |
}
|
|
3481 |
else if (nType == typeDF)
|
|
3482 |
{
|
|
3483 |
sProgSec.AppendFormat(_T("DF %s\r\n"), sCellName);
|
|
3484 |
theprog.nOpType1 = OP_DF;
|
|
3485 |
progsec.Append(theprog);
|
|
3486 |
nSteps += 1;
|
|
3487 |
nNextX = 1;
|
|
3488 |
}
|
|
3489 |
else if (nType == typeDF_)
|
|
3490 |
{
|
|
3491 |
sProgSec.AppendFormat(_T("DF/ %s\r\n"), sCellName);
|
|
3492 |
theprog.nOpType1 = OP_DF_;
|
|
3493 |
progsec.Append(theprog);
|
|
3494 |
nSteps += 1;
|
|
3495 |
nNextX = 1;
|
|
3496 |
}
|
|
3497 |
else if (nType == typeOUT)
|
|
3498 |
{
|
|
3499 |
sProgSec.AppendFormat(_T("OUT %s\r\n"), sCellName);
|
|
3500 |
theprog.nOpType1 = OP_OUT;
|
|
3501 |
theprog.nParamCount = 1;
|
|
3502 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3503 |
theprog.Params[0].nParamType = nCoilType;
|
|
3504 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3505 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3506 |
progsec.Append(theprog);
|
|
3507 |
nSteps += 1;
|
|
3508 |
nNextX = 1;
|
|
3509 |
}
|
|
3510 |
else if (nType == typeSET)
|
|
3511 |
{
|
|
3512 |
sProgSec.AppendFormat(_T("SET %s\r\n"), sCellName);
|
|
3513 |
theprog.nOpType1 = OP_SET;
|
|
3514 |
theprog.nParamCount = 1;
|
|
3515 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3516 |
theprog.Params[0].nParamType = nCoilType;
|
|
3517 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3518 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3519 |
progsec.Append(theprog);
|
|
3520 |
nSteps += 1;
|
|
3521 |
nNextX = 1;
|
|
3522 |
}
|
|
3523 |
else if (nType == typeRESET)
|
|
3524 |
{
|
|
3525 |
sProgSec.AppendFormat(_T("RESET %s\r\n"), sCellName);
|
|
3526 |
theprog.nOpType1 = OP_RESET;
|
|
3527 |
theprog.nParamCount = 1;
|
|
3528 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3529 |
theprog.Params[0].nParamType = nCoilType;
|
|
3530 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3531 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3532 |
progsec.Append(theprog);
|
|
3533 |
nSteps += 1;
|
|
3534 |
nNextX = 1;
|
|
3535 |
}
|
|
3536 |
else if (nType == typeCMP)
|
|
3537 |
{
|
|
3538 |
theprog.nOpType1 = OP_ST_GT;
|
|
3539 |
theprog.nParamCount = 1;
|
|
3540 |
progsec.Append(theprog);
|
|
3541 |
sProgSec.AppendFormat(_T("CMP %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
|
3542 |
nSteps += 1;
|
|
3543 |
nNextX = 3;
|
|
3544 |
}
|
|
3545 |
else if (nType == typeTM)
|
|
3546 |
{
|
|
3547 |
theprog.nOpType1 = OP_TMX;
|
|
3548 |
theprog.nParamCount = 1;
|
|
3549 |
pDoc->TxtToCoilType(sCellNameA, &nCoilType, &CoilAddr);
|
|
3550 |
theprog.Params[0].nParamType = nCoilType;
|
|
3551 |
theprog.Params[0].nParamAddr = CoilAddr;
|
|
3552 |
theprog.Params[0].sParamStr = sCellNameA;
|
|
3553 |
progsec.Append(theprog);
|
|
3554 |
sProgSec.AppendFormat(_T("TM %s %d %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
|
3555 |
nSteps += 1;
|
|
3556 |
nNextX = 3;
|
|
3557 |
}
|
|
3558 |
else if (nType == typeFN1)
|
|
3559 |
{
|
|
3560 |
theprog.nOpType1 = OP_INC;
|
|
3561 |
progsec.Append(theprog);
|
|
3562 |
sProgSec.AppendFormat(_T("FN1 %s %s\r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam);
|
|
3563 |
nSteps += 1;
|
|
3564 |
nNextX = 2;
|
|
3565 |
}
|
|
3566 |
else if (nType == typeFN2)
|
|
3567 |
{
|
|
3568 |
theprog.nOpType1 = OP_MV;
|
|
3569 |
progsec.Append(theprog);
|
|
3570 |
sProgSec.AppendFormat(_T("FN2 %s %s %s \r\n"), sCellName, Cells[nCurPosY][nCurPosX + 1].sParam, Cells[nCurPosY][nCurPosX + 2].sParam);
|
|
3571 |
nSteps += 1;
|
|
3572 |
nNextX = 3;
|
|
3573 |
}
|
|
3574 |
else if (nType == typeFN3)
|
|
3575 |
{
|
|
3576 |
theprog.nOpType1 = OP_ADD3;
|
|
3577 |
progsec.Append(theprog);
|
|
3578 |
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);
|
|
3579 |
nSteps += 1;
|
|
3580 |
nNextX = 4;
|
|
3581 |
}
|
|
3582 |
else
|
|
3583 |
{
|
|
3584 |
nNextX = 1;
|
|
3585 |
//continue;
|
|
3586 |
}
|
|
3587 |
return nNextX;
|
|
3588 |
}
|
|
3589 |
|
418cb3
|
3590 |
|
ad1b4b
|
3591 |
/// <summary>
|
Z |
3592 |
/// 全部图形校验
|
|
3593 |
/// </summary>
|
|
3594 |
/// <returns></returns>
|
e55aec
|
3595 |
/// <remark>
|
Z |
3596 |
/// 计划在第一个返回值中使用不同的错误代码代表不同的错误类型,
|
|
3597 |
/// 并在第二个返回值中填充错误提示信息
|
|
3598 |
/// </remark>
|
4ed7fc
|
3599 |
std::pair<int, CString> CMTerm1View::LDSCheckRule()
|
Z |
3600 |
{
|
|
3601 |
CString message;
|
|
3602 |
int nDivCount = 0;
|
|
3603 |
int Divs[100] = { 0 };
|
|
3604 |
//以行为单位从上到下遍历(行遍历)
|
|
3605 |
for (int i = 0; i < m_nTotalRow; i++)
|
|
3606 |
{
|
|
3607 |
int nRow = i;
|
|
3608 |
int bConnected = 0;
|
|
3609 |
bool checkFlag = false;//0列检验结果
|
ad1b4b
|
3610 |
|
4ed7fc
|
3611 |
//本行的0列检查
|
Z |
3612 |
if (Cells[nRow][0].nType == 0)
|
|
3613 |
{
|
|
3614 |
checkFlag = true;
|
|
3615 |
}
|
ad1b4b
|
3616 |
|
4ed7fc
|
3617 |
//遍历此行的1-15列(确定单元格)
|
Z |
3618 |
for (int j = 1; j < m_CellPerLine; j++)
|
|
3619 |
{
|
|
3620 |
int nCol = j;
|
|
3621 |
//如果0列为空
|
|
3622 |
if (checkFlag)
|
|
3623 |
{
|
|
3624 |
//有左侧上竖线
|
|
3625 |
if (Cells[nRow][nCol].bLeftLineUp)
|
|
3626 |
{
|
|
3627 |
//如果上层为空单元格,无效竖线,直接删除-----可以单独判断
|
|
3628 |
if (nRow - 1 >= 0 && Cells[nRow - 1][nCol].nType == 0)
|
|
3629 |
{
|
|
3630 |
//清理单元格
|
|
3631 |
Cells[nRow][nCol].clear();
|
|
3632 |
}
|
|
3633 |
//如果是none,错误:短路或回路
|
|
3634 |
else if (Cells[nRow][nCol].nType == 0)
|
|
3635 |
{
|
|
3636 |
message.Format(_T("((%d,%d) 附近位置产生触点短路或回路!"), nRow, nCol);
|
|
3637 |
return std::make_pair(111, message);
|
|
3638 |
}
|
|
3639 |
//如果不为none。可以转换,但是提示:无法绘制图形(程序不合理)
|
|
3640 |
if (Cells[nRow][nCol].nType != 1)
|
|
3641 |
{
|
|
3642 |
message.Format(_T("((%d,%d) 无法绘制图形(程序不合理)"), nRow, nCol);
|
|
3643 |
return std::make_pair(111, message);
|
|
3644 |
}
|
ad1b4b
|
3645 |
|
4ed7fc
|
3646 |
}
|
Z |
3647 |
//没有左侧上竖线,且此单元格类型 不为空或线
|
|
3648 |
else if (Cells[nRow][nCol].nType > 2)
|
|
3649 |
{
|
|
3650 |
//此单元格为单独的线圈或指令单元,需要触点输入
|
|
3651 |
message.Format(_T("((%d,%d) 需要触点输入"), nRow, nCol);
|
|
3652 |
return std::make_pair(111, message);
|
|
3653 |
}
|
|
3654 |
//有左侧下竖线,且此单元格类型为空
|
|
3655 |
if (Cells[nRow][nCol].bLeftLineDn)
|
|
3656 |
{
|
|
3657 |
//不支持回路
|
|
3658 |
}
|
|
3659 |
}
|
|
3660 |
//如0列非空
|
|
3661 |
else
|
|
3662 |
{
|
ad1b4b
|
3663 |
|
4ed7fc
|
3664 |
}
|
Z |
3665 |
}
|
ad1b4b
|
3666 |
|
e55aec
|
3667 |
|
4ed7fc
|
3668 |
}
|
Z |
3669 |
return std::make_pair(0, message);
|
|
3670 |
}
|