author | Laurent Bessard |
Sun, 23 Sep 2012 23:56:53 +0200 | |
changeset 842 | 3c4c1e076a34 |
parent 832 | b2609a8e4cb6 |
child 852 | 1009f956d2ee |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import re |
|
26 |
import math |
|
27 |
import time |
|
28 |
from types import TupleType |
|
29 |
from threading import Lock |
|
30 |
||
31 |
import wx |
|
32 |
||
33 |
from plcopen.structures import * |
|
34 |
from PLCControler import ITEM_POU, ITEM_PROGRAM, ITEM_FUNCTIONBLOCK |
|
35 |
||
36 |
from dialogs import * |
|
37 |
from graphics import * |
|
38 |
from EditorPanel import EditorPanel |
|
39 |
||
40 |
SCROLLBAR_UNIT = 10 |
|
41 |
WINDOW_BORDER = 10 |
|
42 |
SCROLL_ZONE = 10 |
|
43 |
||
44 |
CURSORS = None |
|
45 |
||
46 |
def ResetCursors(): |
|
47 |
global CURSORS |
|
48 |
if CURSORS == None: |
|
49 |
CURSORS = [wx.NullCursor, |
|
50 |
wx.StockCursor(wx.CURSOR_HAND), |
|
51 |
wx.StockCursor(wx.CURSOR_SIZENWSE), |
|
52 |
wx.StockCursor(wx.CURSOR_SIZENESW), |
|
53 |
wx.StockCursor(wx.CURSOR_SIZEWE), |
|
54 |
wx.StockCursor(wx.CURSOR_SIZENS)] |
|
55 |
||
56 |
def AppendMenu(parent, help, id, kind, text): |
|
57 |
if wx.VERSION >= (2, 6, 0): |
|
58 |
parent.Append(help=help, id=id, kind=kind, text=text) |
|
59 |
else: |
|
60 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
|
61 |
||
62 |
if wx.Platform == '__WXMSW__': |
|
63 |
faces = { 'times': 'Times New Roman', |
|
64 |
'mono' : 'Courier New', |
|
65 |
'helv' : 'Arial', |
|
66 |
'other': 'Comic Sans MS', |
|
67 |
'size' : 10, |
|
68 |
} |
|
69 |
else: |
|
70 |
faces = { 'times': 'Times', |
|
71 |
'mono' : 'Courier', |
|
72 |
'helv' : 'Helvetica', |
|
73 |
'other': 'new century schoolbook', |
|
74 |
'size' : 12, |
|
75 |
} |
|
76 |
||
77 |
ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, 7)] |
|
78 |
||
79 |
def GetVariableCreationFunction(variable_type): |
|
80 |
def variableCreationFunction(viewer, id, specific_values): |
|
81 |
return FBD_Variable(viewer, variable_type, |
|
82 |
specific_values["name"], |
|
83 |
specific_values["value_type"], |
|
84 |
id, |
|
85 |
specific_values["executionOrder"]) |
|
86 |
return variableCreationFunction |
|
87 |
||
88 |
def GetConnectorCreationFunction(connector_type): |
|
89 |
def connectorCreationFunction(viewer, id, specific_values): |
|
90 |
return FBD_Connector(viewer, connector_type, |
|
91 |
specific_values["name"], id) |
|
92 |
return connectorCreationFunction |
|
93 |
||
94 |
def commentCreationFunction(viewer, id, specific_values): |
|
95 |
return Comment(viewer, specific_values["content"], id) |
|
96 |
||
97 |
def GetPowerRailCreationFunction(powerrail_type): |
|
98 |
def powerRailCreationFunction(viewer, id, specific_values): |
|
99 |
return LD_PowerRail(viewer, powerrail_type, id, |
|
100 |
specific_values["connectors"]) |
|
101 |
return powerRailCreationFunction |
|
102 |
||
103 |
CONTACT_TYPES = {(True, "none"): CONTACT_REVERSE, |
|
104 |
(False, "rising"): CONTACT_RISING, |
|
105 |
(False, "falling"): CONTACT_FALLING} |
|
106 |
||
107 |
def contactCreationFunction(viewer, id, specific_values): |
|
108 |
contact_type = CONTACT_TYPES.get((specific_values.get("negated", False), |
|
109 |
specific_values.get("edge", "none")), |
|
110 |
CONTACT_NORMAL) |
|
111 |
return LD_Contact(viewer, contact_type, specific_values["name"], id) |
|
112 |
||
113 |
COIL_TYPES = {(True, "none", "none"): COIL_REVERSE, |
|
114 |
(False, "none", "set"): COIL_SET, |
|
115 |
(False, "none", "reset"): COIL_RESET, |
|
116 |
(False, "rising", "none"): COIL_RISING, |
|
117 |
(False, "falling", "none"): COIL_FALLING} |
|
118 |
||
119 |
def coilCreationFunction(viewer, id, specific_values): |
|
120 |
coil_type = COIL_TYPES.get((specific_values.get("negated", False), |
|
121 |
specific_values.get("edge", "none"), |
|
122 |
specific_values.get("storage", "none")), |
|
123 |
COIL_NORMAL) |
|
124 |
return LD_Coil(viewer, coil_type, specific_values["name"], id) |
|
125 |
||
126 |
def stepCreationFunction(viewer, id, specific_values): |
|
127 |
step = SFC_Step(viewer, specific_values["name"], |
|
128 |
specific_values.get("initial", False), id) |
|
129 |
if specific_values.get("action", None): |
|
130 |
step.AddAction() |
|
131 |
connector = step.GetActionConnector() |
|
132 |
connector.SetPosition(wx.Point(*specific_values["action"]["position"])) |
|
133 |
return step |
|
134 |
||
135 |
def transitionCreationFunction(viewer, id, specific_values): |
|
136 |
transition = SFC_Transition(viewer, specific_values["condition_type"], |
|
137 |
specific_values.get("condition", None), |
|
138 |
specific_values["priority"], id) |
|
139 |
return transition |
|
140 |
||
141 |
def GetDivergenceCreationFunction(divergence_type): |
|
142 |
def divergenceCreationFunction(viewer, id, specific_values): |
|
143 |
return SFC_Divergence(viewer, divergence_type, |
|
144 |
specific_values["connectors"], id) |
|
145 |
return divergenceCreationFunction |
|
146 |
||
147 |
def jumpCreationFunction(viewer, id, specific_values): |
|
148 |
return SFC_Jump(viewer, specific_values["target"], id) |
|
149 |
||
150 |
def actionBlockCreationFunction(viewer, id, specific_values): |
|
151 |
return SFC_ActionBlock(viewer, specific_values["actions"], id) |
|
152 |
||
153 |
ElementCreationFunctions = { |
|
154 |
"input": GetVariableCreationFunction(INPUT), |
|
155 |
"output": GetVariableCreationFunction(OUTPUT), |
|
156 |
"inout": GetVariableCreationFunction(INOUT), |
|
157 |
"connector": GetConnectorCreationFunction(CONNECTOR), |
|
158 |
"continuation": GetConnectorCreationFunction(CONTINUATION), |
|
159 |
"comment": commentCreationFunction, |
|
160 |
"leftPowerRail": GetPowerRailCreationFunction(LEFTRAIL), |
|
161 |
"rightPowerRail": GetPowerRailCreationFunction(RIGHTRAIL), |
|
162 |
"contact": contactCreationFunction, |
|
163 |
"coil": coilCreationFunction, |
|
164 |
"step": stepCreationFunction, |
|
165 |
"transition": transitionCreationFunction, |
|
166 |
"selectionDivergence": GetDivergenceCreationFunction(SELECTION_DIVERGENCE), |
|
167 |
"selectionConvergence": GetDivergenceCreationFunction(SELECTION_CONVERGENCE), |
|
168 |
"simultaneousDivergence": GetDivergenceCreationFunction(SIMULTANEOUS_DIVERGENCE), |
|
169 |
"simultaneousConvergence": GetDivergenceCreationFunction(SIMULTANEOUS_CONVERGENCE), |
|
170 |
"jump": jumpCreationFunction, |
|
171 |
"actionBlock": actionBlockCreationFunction, |
|
172 |
} |
|
173 |
||
174 |
def sort_blocks(block_infos1, block_infos2): |
|
175 |
x1, y1 = block_infos1[0].GetPosition() |
|
176 |
x2, y2 = block_infos2[0].GetPosition() |
|
177 |
if y1 == y2: |
|
178 |
return cmp(x1, x2) |
|
179 |
else: |
|
180 |
return cmp(y1, y2) |
|
181 |
||
182 |
#------------------------------------------------------------------------------- |
|
183 |
# Graphic elements Viewer base class |
|
184 |
#------------------------------------------------------------------------------- |
|
185 |
||
186 |
# ID Constants for alignment menu items |
|
187 |
[ID_VIEWERALIGNMENTMENUITEMS0, ID_VIEWERALIGNMENTMENUITEMS1, |
|
188 |
ID_VIEWERALIGNMENTMENUITEMS2, ID_VIEWERALIGNMENTMENUITEMS4, |
|
189 |
ID_VIEWERALIGNMENTMENUITEMS5, ID_VIEWERALIGNMENTMENUITEMS6, |
|
190 |
] = [wx.NewId() for _init_coll_AlignmentMenu_Items in range(6)] |
|
191 |
||
192 |
# ID Constants for contextual menu items |
|
193 |
[ID_VIEWERCONTEXTUALMENUITEMS0, ID_VIEWERCONTEXTUALMENUITEMS1, |
|
194 |
ID_VIEWERCONTEXTUALMENUITEMS2, ID_VIEWERCONTEXTUALMENUITEMS3, |
|
195 |
ID_VIEWERCONTEXTUALMENUITEMS5, ID_VIEWERCONTEXTUALMENUITEMS6, |
|
196 |
ID_VIEWERCONTEXTUALMENUITEMS8, ID_VIEWERCONTEXTUALMENUITEMS9, |
|
197 |
ID_VIEWERCONTEXTUALMENUITEMS11, ID_VIEWERCONTEXTUALMENUITEMS12, |
|
198 |
ID_VIEWERCONTEXTUALMENUITEMS14, ID_VIEWERCONTEXTUALMENUITEMS16, |
|
199 |
ID_VIEWERCONTEXTUALMENUITEMS17, |
|
200 |
] = [wx.NewId() for _init_coll_ContextualMenu_Items in range(13)] |
|
201 |
||
202 |
||
203 |
class ViewerDropTarget(wx.TextDropTarget): |
|
204 |
||
205 |
def __init__(self, parent): |
|
206 |
wx.TextDropTarget.__init__(self) |
|
207 |
self.ParentWindow = parent |
|
208 |
||
209 |
def OnDropText(self, x, y, data): |
|
210 |
self.ParentWindow.Select() |
|
211 |
tagname = self.ParentWindow.GetTagName() |
|
212 |
pou_name, pou_type = self.ParentWindow.Controler.GetEditedElementType(tagname, self.ParentWindow.Debug) |
|
213 |
x, y = self.ParentWindow.CalcUnscrolledPosition(x, y) |
|
214 |
x = int(x / self.ParentWindow.ViewScale[0]) |
|
215 |
y = int(y / self.ParentWindow.ViewScale[1]) |
|
216 |
scaling = self.ParentWindow.Scaling |
|
217 |
message = None |
|
218 |
try: |
|
219 |
values = eval(data) |
|
220 |
except: |
|
221 |
message = _("Invalid value \"%s\" for viewer block")%data |
|
222 |
values = None |
|
223 |
if not isinstance(values, TupleType): |
|
224 |
message = _("Invalid value \"%s\" for viewer block")%data |
|
225 |
values = None |
|
226 |
if values is not None: |
|
227 |
if values[1] == "debug": |
|
228 |
pass |
|
229 |
elif values[1] == "program": |
|
230 |
message = _("Programs can't be used by other POUs!") |
|
231 |
elif values[1] in ["function", "functionBlock"]: |
|
232 |
words = tagname.split("::") |
|
233 |
if pou_name == values[0]: |
|
234 |
message = _("\"%s\" can't use itself!")%pou_name |
|
235 |
elif pou_type == "function" and values[1] != "function": |
|
236 |
message = _("Function Blocks can't be used in Functions!") |
|
237 |
elif self.ParentWindow.Controler.PouIsUsedBy(pou_name, values[0], self.ParentWindow.Debug): |
|
238 |
message = _("\"%s\" is already used by \"%s\"!")%(pou_name, values[0]) |
|
239 |
else: |
|
240 |
blockname = values[2] |
|
241 |
if len(values) > 3: |
|
242 |
blockinputs = values[3] |
|
243 |
else: |
|
244 |
blockinputs = None |
|
245 |
if values[1] != "function" and blockname == "": |
|
246 |
blockname = self.ParentWindow.GenerateNewName(blocktype=values[0]) |
|
247 |
if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: |
|
248 |
message = _("\"%s\" pou already exists!")%blockname |
|
249 |
elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
|
250 |
message = _("\"%s\" element for this pou already exists!")%blockname |
|
251 |
else: |
|
252 |
id = self.ParentWindow.GetNewId() |
|
253 |
block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs) |
|
254 |
width, height = block.GetMinSize() |
|
255 |
if scaling is not None: |
|
256 |
x = round(float(x) / float(scaling[0])) * scaling[0] |
|
257 |
y = round(float(y) / float(scaling[1])) * scaling[1] |
|
258 |
width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
259 |
height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
260 |
block.SetPosition(x, y) |
|
261 |
block.SetSize(width, height) |
|
262 |
self.ParentWindow.AddBlock(block) |
|
263 |
self.ParentWindow.Controler.AddEditedElementBlock(tagname, id, values[0], blockname) |
|
264 |
self.ParentWindow.RefreshBlockModel(block) |
|
265 |
self.ParentWindow.RefreshBuffer() |
|
266 |
self.ParentWindow.RefreshScrollBars() |
|
267 |
self.ParentWindow.RefreshVisibleElements() |
|
268 |
self.ParentWindow.RefreshVariablePanel() |
|
269 |
self.ParentWindow.Refresh(False) |
|
270 |
elif values[1] == "location": |
|
271 |
if pou_type == "program": |
|
272 |
location = values[0] |
|
273 |
if not location.startswith("%"): |
|
274 |
dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow, |
|
275 |
_("Select a variable class:"), _("Variable class"), |
|
276 |
["Input", "Output", "Memory"], |
|
277 |
wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
|
278 |
if dialog.ShowModal() == wx.ID_OK: |
|
279 |
selected = dialog.GetSelection() |
|
280 |
else: |
|
281 |
selected = None |
|
282 |
dialog.Destroy() |
|
283 |
if selected is None: |
|
284 |
return |
|
285 |
if selected == 0: |
|
286 |
location = "%I" + location |
|
287 |
elif selected == 1: |
|
288 |
location = "%Q" + location |
|
289 |
else: |
|
290 |
location = "%M" + location |
|
291 |
var_name = values[3] |
|
292 |
if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: |
|
293 |
message = _("\"%s\" pou already exists!")%var_name |
|
294 |
else: |
|
295 |
if location[1] == "Q": |
|
296 |
var_class = OUTPUT |
|
297 |
else: |
|
298 |
var_class = INPUT |
|
299 |
if values[2] is not None: |
|
300 |
var_type = values[2] |
|
301 |
else: |
|
302 |
var_type = LOCATIONDATATYPES.get(location[2], ["BOOL"])[0] |
|
303 |
if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
|
304 |
self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, location, values[4]) |
|
305 |
self.ParentWindow.RefreshVariablePanel() |
|
306 |
self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type) |
|
307 |
elif values[1] == "Global": |
|
308 |
var_name = values[0] |
|
309 |
if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]: |
|
310 |
message = _("\"%s\" pou already exists!")%var_name |
|
311 |
else: |
|
312 |
if not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]: |
|
313 |
self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name) |
|
314 |
self.ParentWindow.RefreshVariablePanel() |
|
315 |
self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2]) |
|
316 |
elif values[1] == "Constant": |
|
317 |
self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, values[0], None) |
|
318 |
elif values[3] == tagname: |
|
319 |
if values[1] == "Output": |
|
320 |
var_class = OUTPUT |
|
321 |
elif values[1] == "InOut": |
|
322 |
var_class = INPUT |
|
323 |
else: |
|
324 |
var_class = INPUT |
|
325 |
tree = dict([(var["Name"], var["Tree"]) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, self.ParentWindow.Debug)]).get(values[0], None) |
|
326 |
if tree is not None: |
|
327 |
if len(tree[0]) > 0: |
|
328 |
menu = wx.Menu(title='') |
|
329 |
self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)]) |
|
330 |
self.ParentWindow.PopupMenuXY(menu) |
|
331 |
else: |
|
332 |
self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, values[0], values[2]) |
|
333 |
else: |
|
334 |
message = _("Unknown variable \"%s\" for this POU!") % values[0] |
|
335 |
else: |
|
336 |
message = _("Variable don't belong to this POU!") |
|
337 |
if message is not None: |
|
338 |
wx.CallAfter(self.ShowMessage, message) |
|
339 |
||
340 |
def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree): |
|
341 |
for child_name, child_type, (child_tree, child_dimensions) in tree: |
|
342 |
if base_path: |
|
343 |
child_path = "%s.%s" % (base_path, child_name) |
|
344 |
else: |
|
345 |
child_path = child_name |
|
346 |
if len(child_dimensions) > 0: |
|
347 |
child_path += "[%s]" % ",".join([str(dimension[0]) for dimension in child_dimensions]) |
|
348 |
child_name += "[]" |
|
349 |
new_id = wx.NewId() |
|
350 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name) |
|
351 |
self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id) |
|
352 |
if len(child_tree) > 0: |
|
353 |
new_id = wx.NewId() |
|
354 |
child_menu = wx.Menu(title='') |
|
355 |
self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree) |
|
356 |
menu.AppendMenu(new_id, "%s." % child_name, child_menu) |
|
357 |
||
358 |
def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type): |
|
359 |
def AddVariableFunction(event): |
|
360 |
self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type) |
|
361 |
return AddVariableFunction |
|
362 |
||
363 |
def ShowMessage(self, message): |
|
364 |
message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
365 |
message.ShowModal() |
|
366 |
message.Destroy() |
|
367 |
||
368 |
""" |
|
369 |
Class that implements a Viewer based on a wx.ScrolledWindow for drawing and |
|
370 |
manipulating graphic elements |
|
371 |
""" |
|
372 |
||
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
373 |
class Viewer(EditorPanel, DebugViewer, DebugDataConsumer): |
814 | 374 |
|
375 |
if wx.VERSION < (2, 6, 0): |
|
376 |
def Bind(self, event, function, id = None): |
|
377 |
if id is not None: |
|
378 |
event(self, id, function) |
|
379 |
else: |
|
380 |
event(self, function) |
|
381 |
||
382 |
# Add list of menu items to the given menu |
|
383 |
def AddMenuItems(self, menu, items): |
|
384 |
for item in items: |
|
385 |
if item is None: |
|
386 |
menu.AppendSeparator() |
|
387 |
else: |
|
388 |
id, kind, text, help, callback = item |
|
389 |
AppendMenu(menu, help=help, id=id, kind=kind, text=text) |
|
390 |
# Link menu event to corresponding called functions |
|
391 |
self.Bind(wx.EVT_MENU, callback, id=id) |
|
392 |
||
393 |
# Add Block Pin Menu items to the given menu |
|
394 |
def AddBlockPinMenuItems(self, menu, connector): |
|
395 |
[ID_NO_MODIFIER, ID_NEGATED, ID_RISING_EDGE, |
|
396 |
ID_FALLING_EDGE] = [wx.NewId() for i in xrange(4)] |
|
397 |
||
398 |
# Create menu items |
|
399 |
self.AddMenuItems(menu, [ |
|
400 |
(ID_NO_MODIFIER, wx.ITEM_RADIO, _(u'No Modifier'), '', self.OnNoModifierMenu), |
|
401 |
(ID_NEGATED, wx.ITEM_RADIO, _(u'Negated'), '', self.OnNegatedMenu), |
|
402 |
(ID_RISING_EDGE, wx.ITEM_RADIO, _(u'Rising Edge'), '', self.OnRisingEdgeMenu), |
|
403 |
(ID_FALLING_EDGE, wx.ITEM_RADIO, _(u'Falling Edge'), '', self.OnFallingEdgeMenu)]) |
|
404 |
||
405 |
type = self.Controler.GetEditedElementType(self.TagName, self.Debug) |
|
406 |
menu.Enable(ID_RISING_EDGE, type != "function") |
|
407 |
menu.Enable(ID_FALLING_EDGE, type != "function") |
|
408 |
||
409 |
if connector.IsNegated(): |
|
410 |
menu.Check(ID_NEGATED, True) |
|
411 |
elif connector.GetEdge() == "rising": |
|
412 |
menu.Check(ID_RISING_EDGE, True) |
|
413 |
elif connector.GetEdge() == "falling": |
|
414 |
menu.Check(ID_FALLING_EDGE, True) |
|
415 |
else: |
|
416 |
menu.Check(ID_NO_MODIFIER, True) |
|
417 |
||
418 |
# Add Alignment Menu items to the given menu |
|
419 |
def AddAlignmentMenuItems(self, menu): |
|
420 |
[ID_ALIGN_LEFT, ID_ALIGN_CENTER, ID_ALIGN_RIGHT, |
|
421 |
ID_ALIGN_TOP, ID_ALIGN_MIDDLE, ID_ALIGN_BOTTOM, |
|
422 |
] = [wx.NewId() for i in xrange(6)] |
|
423 |
||
424 |
# Create menu items |
|
425 |
self.AddMenuItems(menu, [ |
|
426 |
(ID_ALIGN_LEFT, wx.ITEM_NORMAL, _(u'Left'), '', self.OnAlignLeftMenu), |
|
427 |
(ID_ALIGN_CENTER, wx.ITEM_NORMAL, _(u'Center'), '', self.OnAlignCenterMenu), |
|
428 |
(ID_ALIGN_RIGHT, wx.ITEM_NORMAL, _(u'Right'), '', self.OnAlignRightMenu), |
|
429 |
None, |
|
430 |
(ID_ALIGN_TOP, wx.ITEM_NORMAL, _(u'Top'), '', self.OnAlignTopMenu), |
|
431 |
(ID_ALIGN_MIDDLE, wx.ITEM_NORMAL, _(u'Middle'), '', self.OnAlignMiddleMenu), |
|
432 |
(ID_ALIGN_BOTTOM, wx.ITEM_NORMAL, _(u'Bottom'), '', self.OnAlignBottomMenu)]) |
|
433 |
||
434 |
# Add Wire Menu items to the given menu |
|
435 |
def AddWireMenuItems(self, menu, delete=False): |
|
436 |
[ID_ADD_SEGMENT, ID_DELETE_SEGMENT] = [wx.NewId() for i in xrange(2)] |
|
437 |
||
438 |
# Create menu items |
|
439 |
self.AddMenuItems(menu, [ |
|
440 |
(ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu), |
|
441 |
(ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu)]) |
|
442 |
||
443 |
menu.Enable(ID_DELETE_SEGMENT, delete) |
|
444 |
||
445 |
# Add Divergence Menu items to the given menu |
|
446 |
def AddDivergenceMenuItems(self, menu, delete=False): |
|
447 |
[ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for i in xrange(2)] |
|
448 |
||
449 |
# Create menu items |
|
450 |
self.AddMenuItems(menu, [ |
|
451 |
(ID_ADD_BRANCH, wx.ITEM_NORMAL, _(u'Add Divergence Branch'), '', self.OnAddBranchMenu), |
|
452 |
(ID_DELETE_BRANCH, wx.ITEM_NORMAL, _(u'Delete Divergence Branch'), '', self.OnDeleteBranchMenu)]) |
|
453 |
||
454 |
menu.Enable(ID_DELETE_BRANCH, delete) |
|
455 |
||
456 |
# Add Add Menu items to the given menu |
|
457 |
def AddAddMenuItems(self, menu): |
|
458 |
[ID_ADD_BLOCK, ID_ADD_VARIABLE, ID_ADD_CONNECTION, |
|
459 |
ID_ADD_COMMENT] = [wx.NewId() for i in xrange(4)] |
|
460 |
||
461 |
# Create menu items |
|
462 |
self.AddMenuItems(menu, [ |
|
463 |
(ID_ADD_BLOCK, wx.ITEM_NORMAL, _(u'Block'), '', self.GetAddMenuCallBack(self.AddNewBlock)), |
|
464 |
(ID_ADD_VARIABLE, wx.ITEM_NORMAL, _(u'Variable'), '', self.GetAddMenuCallBack(self.AddNewVariable)), |
|
465 |
(ID_ADD_CONNECTION, wx.ITEM_NORMAL, _(u'Connection'), '', self.GetAddMenuCallBack(self.AddNewConnection)), |
|
466 |
None]) |
|
467 |
||
468 |
if self.CurrentLanguage != "FBD": |
|
469 |
[ID_ADD_POWER_RAIL, ID_ADD_CONTACT, ID_ADD_COIL, |
|
470 |
] = [wx.NewId() for i in xrange(3)] |
|
471 |
||
472 |
# Create menu items |
|
473 |
self.AddMenuItems(menu, [ |
|
474 |
(ID_ADD_POWER_RAIL, wx.ITEM_NORMAL, _(u'Power Rail'), '', self.GetAddMenuCallBack(self.AddNewPowerRail)), |
|
475 |
(ID_ADD_CONTACT, wx.ITEM_NORMAL, _(u'Contact'), '', self.GetAddMenuCallBack(self.AddNewContact))]) |
|
476 |
||
477 |
if self.CurrentLanguage != "SFC": |
|
478 |
self.AddMenuItems(menu, [ |
|
479 |
(ID_ADD_COIL, wx.ITEM_NORMAL, _(u'Coil'), '', self.GetAddMenuCallBack(self.AddNewCoil))]) |
|
480 |
||
481 |
menu.AppendSeparator() |
|
482 |
||
483 |
if self.CurrentLanguage == "SFC": |
|
484 |
[ID_ADD_INITIAL_STEP, ID_ADD_STEP, ID_ADD_TRANSITION, |
|
485 |
ID_ADD_ACTION_BLOCK, ID_ADD_DIVERGENCE, ID_ADD_JUMP, |
|
486 |
] = [wx.NewId() for i in xrange(6)] |
|
487 |
||
488 |
# Create menu items |
|
489 |
self.AddMenuItems(menu, [ |
|
490 |
(ID_ADD_INITIAL_STEP, wx.ITEM_NORMAL, _(u'Initial Step'), '', self.GetAddMenuCallBack(self.AddNewStep, True)), |
|
491 |
(ID_ADD_STEP, wx.ITEM_NORMAL, _(u'Step'), '', self.GetAddMenuCallBack(self.AddNewStep)), |
|
492 |
(ID_ADD_TRANSITION, wx.ITEM_NORMAL, _(u'Transition'), '', self.GetAddMenuCallBack(self.AddNewTransition)), |
|
493 |
(ID_ADD_ACTION_BLOCK, wx.ITEM_NORMAL, _(u'Action Block'), '', self.GetAddMenuCallBack(self.AddNewActionBlock)), |
|
494 |
(ID_ADD_DIVERGENCE, wx.ITEM_NORMAL, _(u'Divergence'), '', self.GetAddMenuCallBack(self.AddNewDivergence)), |
|
495 |
(ID_ADD_JUMP, wx.ITEM_NORMAL, _(u'Jump'), '', self.GetAddMenuCallBack(self.AddNewJump)), |
|
496 |
None]) |
|
497 |
||
498 |
self.AddMenuItems(menu, [ |
|
499 |
(ID_ADD_COMMENT, wx.ITEM_NORMAL, _(u'Comment'), '', self.GetAddMenuCallBack(self.AddNewComment))]) |
|
500 |
||
501 |
# Add Default Menu items to the given menu |
|
502 |
def AddDefaultMenuItems(self, menu, edit=False, block=False): |
|
503 |
if block: |
|
504 |
[ID_EDIT_BLOCK, ID_DELETE] = [wx.NewId() for i in xrange(2)] |
|
505 |
||
506 |
# Create menu items |
|
507 |
self.AddMenuItems(menu, [ |
|
508 |
(ID_EDIT_BLOCK, wx.ITEM_NORMAL, _(u'Edit Block'), '', self.OnEditBlockMenu), |
|
509 |
(ID_DELETE, wx.ITEM_NORMAL, _(u'Delete'), '', self.OnDeleteMenu)]) |
|
510 |
||
511 |
menu.Enable(ID_EDIT_BLOCK, edit) |
|
512 |
||
513 |
else: |
|
514 |
[ID_CLEAR_EXEC_ORDER, ID_RESET_EXEC_ORDER] = [wx.NewId() for i in xrange(2)] |
|
515 |
||
516 |
# Create menu items |
|
517 |
self.AddMenuItems(menu, [ |
|
518 |
(ID_CLEAR_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Clear Execution Order'), '', self.OnClearExecutionOrderMenu), |
|
519 |
(ID_RESET_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Reset Execution Order'), '', self.OnResetExecutionOrderMenu)]) |
|
520 |
||
521 |
menu.AppendSeparator() |
|
522 |
||
523 |
add_menu = wx.Menu(title='') |
|
524 |
self.AddAddMenuItems(add_menu) |
|
525 |
menu.AppendMenu(-1, _(u'Add'), add_menu) |
|
526 |
||
527 |
menu.AppendSeparator() |
|
528 |
||
529 |
[ID_CUT, ID_COPY, ID_PASTE] = [wx.NewId() for i in xrange(3)] |
|
530 |
||
531 |
# Create menu items |
|
532 |
self.AddMenuItems(menu, [ |
|
533 |
(ID_CUT, wx.ITEM_NORMAL, _(u'Cut'), '', self.GetClipboardCallBack(self.Cut)), |
|
534 |
(ID_COPY, wx.ITEM_NORMAL, _(u'Copy'), '', self.GetClipboardCallBack(self.Copy)), |
|
535 |
(ID_PASTE, wx.ITEM_NORMAL, _(u'Paste'), '', self.GetAddMenuCallBack(self.Paste))]) |
|
536 |
||
537 |
menu.Enable(ID_CUT, block) |
|
538 |
menu.Enable(ID_COPY, block) |
|
539 |
menu.Enable(ID_PASTE, self.ParentWindow.GetCopyBuffer() is not None) |
|
540 |
||
541 |
def _init_Editor(self, prnt): |
|
542 |
self.Editor = wx.ScrolledWindow(prnt, name="Viewer", |
|
543 |
pos=wx.Point(0, 0), size=wx.Size(0, 0), |
|
544 |
style=wx.HSCROLL | wx.VSCROLL | wx.ALWAYS_SHOW_SB) |
|
545 |
self.Editor.ParentWindow = self |
|
546 |
||
547 |
# Create a new Viewer |
|
548 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
|
549 |
self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1]) |
|
550 |
||
551 |
EditorPanel.__init__(self, parent, tagname, window, controler, debug) |
|
552 |
DebugViewer.__init__(self, controler, debug) |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
553 |
DebugDataConsumer.__init__(self) |
814 | 554 |
|
555 |
# Adding a rubberband to Viewer |
|
556 |
self.rubberBand = RubberBand(viewer=self) |
|
557 |
self.Editor.SetBackgroundColour(wx.Colour(255,255,255)) |
|
558 |
self.Editor.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) |
|
559 |
self.ResetView() |
|
560 |
self.Scaling = None |
|
561 |
self.DrawGrid = True |
|
562 |
self.GridBrush = wx.TRANSPARENT_BRUSH |
|
563 |
self.PageSize = None |
|
564 |
self.PagePen = wx.TRANSPARENT_PEN |
|
565 |
self.DrawingWire = False |
|
566 |
self.current_id = 0 |
|
567 |
self.TagName = tagname |
|
568 |
self.Highlights = [] |
|
569 |
self.SearchParams = None |
|
570 |
self.SearchResults = None |
|
571 |
self.CurrentFindHighlight = None |
|
572 |
self.InstancePath = instancepath |
|
573 |
self.StartMousePos = None |
|
574 |
self.StartScreenPos = None |
|
575 |
self.Buffering = False |
|
576 |
||
577 |
# Initialize Cursors |
|
578 |
ResetCursors() |
|
579 |
self.CurrentCursor = 0 |
|
580 |
||
581 |
# Initialize Block, Wire and Comment numbers |
|
582 |
self.wire_id = 0 |
|
583 |
||
584 |
# Initialize Viewer mode to Selection mode |
|
585 |
self.Mode = MODE_SELECTION |
|
586 |
self.SavedMode = False |
|
587 |
self.CurrentLanguage = "FBD" |
|
588 |
||
589 |
if not self.Debug: |
|
590 |
self.Editor.SetDropTarget(ViewerDropTarget(self)) |
|
591 |
||
592 |
self.ElementRefreshList = [] |
|
593 |
self.ElementRefreshList_lock = Lock() |
|
594 |
||
595 |
dc = wx.ClientDC(self.Editor) |
|
596 |
font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"]) |
|
597 |
dc.SetFont(font) |
|
598 |
width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
|
599 |
while width > 260: |
|
600 |
faces["size"] -= 1 |
|
601 |
font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"]) |
|
602 |
dc.SetFont(font) |
|
603 |
width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
|
604 |
self.SetFont(font) |
|
605 |
self.MiniTextDC = wx.MemoryDC() |
|
606 |
self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])) |
|
607 |
||
608 |
self.CurrentScale = None |
|
609 |
self.SetScale(len(ZOOM_FACTORS) / 2, False) |
|
610 |
||
611 |
self.RefreshHighlightsTimer = wx.Timer(self, -1) |
|
612 |
self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) |
|
613 |
||
614 |
self.ResetView() |
|
615 |
||
616 |
# Link Viewer event to corresponding methods |
|
617 |
self.Editor.Bind(wx.EVT_PAINT, self.OnPaint) |
|
618 |
self.Editor.Bind(wx.EVT_LEFT_DOWN, self.OnViewerLeftDown) |
|
619 |
self.Editor.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp) |
|
620 |
self.Editor.Bind(wx.EVT_LEFT_DCLICK, self.OnViewerLeftDClick) |
|
621 |
self.Editor.Bind(wx.EVT_RIGHT_DOWN, self.OnViewerRightDown) |
|
622 |
self.Editor.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp) |
|
623 |
self.Editor.Bind(wx.EVT_MIDDLE_DOWN, self.OnViewerMiddleDown) |
|
624 |
self.Editor.Bind(wx.EVT_MIDDLE_UP, self.OnViewerMiddleUp) |
|
625 |
self.Editor.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer) |
|
626 |
self.Editor.Bind(wx.EVT_MOTION, self.OnViewerMotion) |
|
627 |
self.Editor.Bind(wx.EVT_CHAR, self.OnChar) |
|
628 |
self.Editor.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow) |
|
629 |
self.Editor.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.OnScrollStop) |
|
630 |
self.Editor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow) |
|
631 |
self.Editor.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
|
632 |
self.Editor.Bind(wx.EVT_MOUSE_EVENTS, self.OnViewerMouseEvent) |
|
633 |
||
634 |
# Destructor |
|
635 |
def __del__(self): |
|
636 |
DebugViewer.__del__(self) |
|
637 |
self.Flush() |
|
638 |
self.ResetView() |
|
639 |
self.RefreshHighlightsTimer.Stop() |
|
640 |
||
641 |
def SetCurrentCursor(self, cursor): |
|
642 |
if self.Mode != MODE_MOTION: |
|
643 |
global CURSORS |
|
644 |
if self.CurrentCursor != cursor: |
|
645 |
self.CurrentCursor = cursor |
|
646 |
self.Editor.SetCursor(CURSORS[cursor]) |
|
647 |
||
648 |
def GetScrolledRect(self, rect): |
|
649 |
rect.x, rect.y = self.Editor.CalcScrolledPosition(int(rect.x * self.ViewScale[0]), |
|
650 |
int(rect.y * self.ViewScale[1])) |
|
651 |
rect.width = int(rect.width * self.ViewScale[0]) + 2 |
|
652 |
rect.height = int(rect.height * self.ViewScale[1]) + 2 |
|
653 |
return rect |
|
654 |
||
655 |
def GetTitle(self): |
|
656 |
if self.Debug: |
|
657 |
if len(self.InstancePath) > 15: |
|
658 |
return "..." + self.InstancePath[-12:] |
|
659 |
return self.InstancePath |
|
660 |
return EditorPanel.GetTitle(self) |
|
661 |
||
662 |
def GetScaling(self): |
|
663 |
return self.Scaling |
|
664 |
||
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
665 |
def GetInstancePath(self, variable_base=False): |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
666 |
if variable_base: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
667 |
words = self.TagName.split("::") |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
668 |
if words[0] in ["A", "T"]: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
669 |
return ".".join(self.InstancePath.split(".")[:-1]) |
814 | 670 |
return self.InstancePath |
671 |
||
672 |
def IsViewing(self, tagname): |
|
673 |
if self.Debug: |
|
674 |
return self.InstancePath == tagname |
|
675 |
return EditorPanel.IsViewing(self, tagname) |
|
676 |
||
677 |
# Returns a new id |
|
678 |
def GetNewId(self): |
|
679 |
self.current_id += 1 |
|
680 |
return self.current_id |
|
681 |
||
682 |
def SetScale(self, scale_number, refresh=True, mouse_event=None): |
|
683 |
new_scale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1)) |
|
684 |
if self.CurrentScale != new_scale: |
|
685 |
if refresh: |
|
686 |
dc = self.GetLogicalDC() |
|
687 |
self.CurrentScale = new_scale |
|
688 |
self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale]) |
|
689 |
if refresh: |
|
690 |
self.Editor.Freeze() |
|
691 |
if mouse_event is None: |
|
692 |
client_size = self.Editor.GetClientSize() |
|
693 |
mouse_pos = wx.Point(client_size[0] / 2, client_size[1] / 2) |
|
694 |
mouse_event = wx.MouseEvent(wx.EVT_MOUSEWHEEL.typeId) |
|
695 |
mouse_event.m_x = mouse_pos.x |
|
696 |
mouse_event.m_y = mouse_pos.y |
|
697 |
else: |
|
698 |
mouse_pos = mouse_event.GetPosition() |
|
699 |
pos = mouse_event.GetLogicalPosition(dc) |
|
700 |
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
701 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
|
702 |
scrollx = max(0, round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT) |
|
703 |
scrolly = max(0, round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT) |
|
704 |
if scrollx > xmax or scrolly > ymax: |
|
705 |
self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax)) |
|
706 |
self.Scroll(scrollx, scrolly) |
|
707 |
else: |
|
708 |
self.Scroll(scrollx, scrolly) |
|
709 |
self.RefreshScrollBars() |
|
710 |
self.RefreshScaling(refresh) |
|
711 |
self.Editor.Thaw() |
|
712 |
||
713 |
def GetScale(self): |
|
714 |
return self.CurrentScale |
|
715 |
||
716 |
def GetViewScale(self): |
|
717 |
return self.ViewScale |
|
718 |
||
719 |
def GetState(self): |
|
720 |
return {"position": self.Editor.GetViewStart(), |
|
721 |
"zoom": self.CurrentScale} |
|
722 |
||
723 |
def SetState(self, state): |
|
724 |
if self: |
|
725 |
if state.has_key("zoom"): |
|
726 |
self.SetScale(state["zoom"]) |
|
727 |
if state.has_key("position"): |
|
728 |
self.Scroll(*state["position"]) |
|
729 |
self.RefreshVisibleElements() |
|
730 |
||
731 |
def GetLogicalDC(self, buffered=False): |
|
732 |
if buffered: |
|
733 |
bitmap = wx.EmptyBitmap(*self.Editor.GetClientSize()) |
|
734 |
dc = wx.MemoryDC(bitmap) |
|
735 |
else: |
|
736 |
dc = wx.ClientDC(self.Editor) |
|
737 |
dc.SetFont(self.GetFont()) |
|
738 |
if wx.VERSION >= (2, 6, 0): |
|
739 |
self.Editor.DoPrepareDC(dc) |
|
740 |
else: |
|
741 |
self.Editor.PrepareDC(dc) |
|
742 |
dc.SetUserScale(self.ViewScale[0], self.ViewScale[1]) |
|
743 |
return dc |
|
744 |
||
745 |
def RefreshRect(self, rect, eraseBackground=True): |
|
746 |
self.Editor.RefreshRect(rect, eraseBackground) |
|
747 |
||
748 |
def Scroll(self, x, y): |
|
749 |
self.Editor.Scroll(x, y) |
|
750 |
||
751 |
def GetScrollPos(self, orientation): |
|
752 |
return self.Editor.GetScrollPos(orientation) |
|
753 |
||
754 |
def GetScrollRange(self, orientation): |
|
755 |
return self.Editor.GetScrollRange(orientation) |
|
756 |
||
757 |
def GetScrollThumb(self, orientation): |
|
758 |
return self.Editor.GetScrollThumb(orientation) |
|
759 |
||
760 |
def CalcUnscrolledPosition(self, x, y): |
|
761 |
return self.Editor.CalcUnscrolledPosition(x, y) |
|
762 |
||
763 |
def GetViewStart(self): |
|
764 |
return self.Editor.GetViewStart() |
|
765 |
||
766 |
def GetTextExtent(self, text): |
|
767 |
return self.Editor.GetTextExtent(text) |
|
768 |
||
769 |
def GetFont(self): |
|
770 |
return self.Editor.GetFont() |
|
771 |
||
772 |
def GetMiniTextExtent(self, text): |
|
773 |
return self.MiniTextDC.GetTextExtent(text) |
|
774 |
||
775 |
def GetMiniFont(self): |
|
776 |
return self.MiniTextDC.GetFont() |
|
777 |
||
778 |
#------------------------------------------------------------------------------- |
|
779 |
# Element management functions |
|
780 |
#------------------------------------------------------------------------------- |
|
781 |
||
782 |
def AddBlock(self, block): |
|
783 |
self.Blocks[block.GetId()] = block |
|
784 |
||
785 |
def AddWire(self, wire): |
|
786 |
self.wire_id += 1 |
|
787 |
self.Wires[wire] = self.wire_id |
|
788 |
||
789 |
def AddComment(self, comment): |
|
790 |
self.Comments[comment.GetId()] = comment |
|
791 |
||
792 |
def IsBlock(self, block): |
|
793 |
return self.Blocks.get(block.GetId(), False) |
|
794 |
||
795 |
def IsWire(self, wire): |
|
796 |
return self.Wires.get(wire, False) |
|
797 |
||
798 |
def IsComment(self, comment): |
|
799 |
return self.Comments.get(comment.GetId(), False) |
|
800 |
||
801 |
def RemoveBlock(self, block): |
|
802 |
self.Blocks.pop(block.GetId()) |
|
803 |
||
804 |
def RemoveWire(self, wire): |
|
805 |
self.Wires.pop(wire) |
|
806 |
||
807 |
def RemoveComment(self, comment): |
|
808 |
self.Comments.pop(comment.GetId()) |
|
809 |
||
810 |
def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False): |
|
811 |
blocks = self.Blocks.values() |
|
812 |
wires = self.Wires.keys() |
|
813 |
comments = self.Comments.values() |
|
814 |
if sort_blocks: |
|
815 |
blocks.sort(lambda x, y: cmp(x.GetId(), y.GetId())) |
|
816 |
if sort_wires: |
|
817 |
wires.sort(lambda x, y: cmp(self.Wires[x], self.Wires[y])) |
|
818 |
if sort_comments: |
|
819 |
comments.sort(lambda x, y: cmp(x.GetId(), y.GetId())) |
|
820 |
return blocks + wires + comments |
|
821 |
||
822 |
def GetConnectorByName(self, name): |
|
823 |
for block in self.Blocks.itervalues(): |
|
824 |
if isinstance(block, FBD_Connector) and\ |
|
825 |
block.GetType() == CONNECTOR and\ |
|
826 |
block.GetName() == name: |
|
827 |
return block |
|
828 |
return None |
|
829 |
||
830 |
def RefreshVisibleElements(self, xp = None, yp = None): |
|
831 |
x, y = self.Editor.CalcUnscrolledPosition(0, 0) |
|
832 |
if xp is not None: |
|
833 |
x = xp * self.Editor.GetScrollPixelsPerUnit()[0] |
|
834 |
if yp is not None: |
|
835 |
y = yp * self.Editor.GetScrollPixelsPerUnit()[1] |
|
836 |
width, height = self.Editor.GetClientSize() |
|
837 |
screen = wx.Rect(int(x / self.ViewScale[0]), int(y / self.ViewScale[1]), |
|
838 |
int(width / self.ViewScale[0]), int(height / self.ViewScale[1])) |
|
839 |
for comment in self.Comments.itervalues(): |
|
840 |
comment.TestVisible(screen) |
|
841 |
for wire in self.Wires.iterkeys(): |
|
842 |
wire.TestVisible(screen) |
|
843 |
for block in self.Blocks.itervalues(): |
|
844 |
block.TestVisible(screen) |
|
845 |
||
846 |
def GetElementIECPath(self, element): |
|
847 |
iec_path = None |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
848 |
instance_path = self.GetInstancePath(True) |
814 | 849 |
if isinstance(element, Wire) and element.EndConnected is not None: |
850 |
block = element.EndConnected.GetParentBlock() |
|
851 |
if isinstance(block, FBD_Block): |
|
852 |
blockname = block.GetName() |
|
853 |
connectorname = element.EndConnected.GetName() |
|
854 |
if blockname != "": |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
855 |
iec_path = "%s.%s.%s"%(instance_path, blockname, connectorname) |
814 | 856 |
else: |
857 |
if connectorname == "": |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
858 |
iec_path = "%s.%s%d"%(instance_path, block.GetType(), block.GetId()) |
814 | 859 |
else: |
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
860 |
iec_path = "%s.%s%d_%s"%(instance_path, block.GetType(), block.GetId(), connectorname) |
814 | 861 |
elif isinstance(block, FBD_Variable): |
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
862 |
iec_path = "%s.%s"%(instance_path, block.GetName()) |
814 | 863 |
elif isinstance(block, FBD_Connector): |
864 |
connection = self.GetConnectorByName(block.GetName()) |
|
865 |
if connection is not None: |
|
866 |
connector = connection.GetConnector() |
|
867 |
if len(connector.Wires) == 1: |
|
868 |
iec_path = self.GetElementIECPath(connector.Wires[0][0]) |
|
869 |
elif isinstance(element, LD_Contact): |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
870 |
iec_path = "%s.%s"%(instance_path, element.GetName()) |
814 | 871 |
elif isinstance(element, SFC_Step): |
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
872 |
iec_path = "%s.%s.X"%(instance_path, element.GetName()) |
814 | 873 |
elif isinstance(element, SFC_Transition): |
874 |
connectors = element.GetConnectors() |
|
875 |
previous_steps = self.GetPreviousSteps(connectors["inputs"]) |
|
876 |
next_steps = self.GetNextSteps(connectors["outputs"]) |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
877 |
iec_path = "%s.%s->%s"%(instance_path, ",".join(previous_steps), ",".join(next_steps)) |
814 | 878 |
return iec_path |
879 |
||
880 |
#------------------------------------------------------------------------------- |
|
881 |
# Reset functions |
|
882 |
#------------------------------------------------------------------------------- |
|
883 |
||
884 |
# Resets Viewer lists |
|
885 |
def ResetView(self): |
|
886 |
self.Blocks = {} |
|
887 |
self.Wires = {} |
|
888 |
self.Comments = {} |
|
889 |
self.Subscribed = {} |
|
890 |
self.SelectedElement = None |
|
891 |
self.HighlightedElement = None |
|
892 |
self.ToolTipElement = None |
|
893 |
||
894 |
def Flush(self): |
|
895 |
self.DeleteDataConsumers() |
|
896 |
for block in self.Blocks.itervalues(): |
|
897 |
block.Flush() |
|
898 |
||
899 |
# Remove all elements |
|
900 |
def CleanView(self): |
|
901 |
for block in self.Blocks.itervalues(): |
|
902 |
block.Clean() |
|
903 |
self.ResetView() |
|
904 |
||
905 |
# Changes Viewer mode |
|
906 |
def SetMode(self, mode): |
|
907 |
if self.Mode != mode or mode == MODE_SELECTION: |
|
908 |
if self.Mode == MODE_MOTION: |
|
909 |
wx.CallAfter(self.Editor.SetCursor, wx.NullCursor) |
|
910 |
self.Mode = mode |
|
911 |
self.SavedMode = False |
|
912 |
else: |
|
913 |
self.SavedMode = True |
|
914 |
# Reset selection |
|
915 |
if self.Mode != MODE_SELECTION and self.SelectedElement: |
|
916 |
self.SelectedElement.SetSelected(False) |
|
917 |
self.SelectedElement = None |
|
918 |
if self.Mode == MODE_MOTION: |
|
919 |
wx.CallAfter(self.Editor.SetCursor, wx.StockCursor(wx.CURSOR_HAND)) |
|
920 |
self.SavedMode = True |
|
921 |
||
922 |
# Return current drawing mode |
|
923 |
def GetDrawingMode(self): |
|
924 |
return self.ParentWindow.GetDrawingMode() |
|
925 |
||
926 |
# Buffer the last model state |
|
927 |
def RefreshBuffer(self): |
|
928 |
self.Controler.BufferProject() |
|
929 |
if self.ParentWindow: |
|
930 |
self.ParentWindow.RefreshTitle() |
|
931 |
self.ParentWindow.RefreshFileMenu() |
|
932 |
self.ParentWindow.RefreshEditMenu() |
|
933 |
||
934 |
def StartBuffering(self): |
|
935 |
if not self.Buffering: |
|
936 |
self.Buffering = True |
|
937 |
self.Controler.StartBuffering() |
|
938 |
if self.ParentWindow: |
|
939 |
self.ParentWindow.RefreshTitle() |
|
940 |
self.ParentWindow.RefreshFileMenu() |
|
941 |
self.ParentWindow.RefreshEditMenu() |
|
942 |
||
943 |
def ResetBuffer(self): |
|
944 |
if self.Buffering: |
|
945 |
self.Controler.EndBuffering() |
|
946 |
self.Buffering = False |
|
947 |
||
948 |
def GetBufferState(self): |
|
949 |
if not self.Debug: |
|
950 |
return self.Controler.GetBufferState() |
|
951 |
return False, False |
|
952 |
||
953 |
def Undo(self): |
|
954 |
if not self.Debug: |
|
955 |
self.Controler.LoadPrevious() |
|
956 |
self.ParentWindow.CloseTabsWithoutModel() |
|
957 |
||
958 |
def Redo(self): |
|
959 |
if not self.Debug: |
|
960 |
self.Controler.LoadNext() |
|
961 |
self.ParentWindow.CloseTabsWithoutModel() |
|
962 |
||
963 |
def HasNoModel(self): |
|
964 |
if not self.Debug: |
|
965 |
return self.Controler.GetEditedElement(self.TagName) is None |
|
966 |
return False |
|
967 |
||
968 |
# Refresh the current scaling |
|
969 |
def RefreshScaling(self, refresh=True): |
|
970 |
properties = self.Controler.GetProjectProperties(self.Debug) |
|
971 |
scaling = properties["scaling"][self.CurrentLanguage] |
|
972 |
if scaling[0] != 0 and scaling[1] != 0: |
|
973 |
self.Scaling = scaling |
|
974 |
if self.DrawGrid: |
|
975 |
width = max(2, int(scaling[0] * self.ViewScale[0])) |
|
976 |
height = max(2, int(scaling[1] * self.ViewScale[1])) |
|
977 |
bitmap = wx.EmptyBitmap(width, height) |
|
978 |
dc = wx.MemoryDC(bitmap) |
|
979 |
dc.SetBackground(wx.Brush(self.Editor.GetBackgroundColour())) |
|
980 |
dc.Clear() |
|
981 |
dc.SetPen(MiterPen(wx.Colour(180, 180, 180))) |
|
982 |
dc.DrawPoint(0, 0) |
|
983 |
self.GridBrush = wx.BrushFromBitmap(bitmap) |
|
984 |
else: |
|
985 |
self.GridBrush = wx.TRANSPARENT_BRUSH |
|
986 |
else: |
|
987 |
self.Scaling = None |
|
988 |
self.GridBrush = wx.TRANSPARENT_BRUSH |
|
989 |
page_size = properties["pageSize"] |
|
990 |
if page_size != (0, 0): |
|
991 |
self.PageSize = map(int, page_size) |
|
992 |
self.PagePen = MiterPen(wx.Colour(180, 180, 180)) |
|
993 |
else: |
|
994 |
self.PageSize = None |
|
995 |
self.PagePen = wx.TRANSPARENT_PEN |
|
996 |
if refresh: |
|
997 |
self.RefreshVisibleElements() |
|
998 |
self.Refresh(False) |
|
999 |
||
1000 |
||
1001 |
#------------------------------------------------------------------------------- |
|
1002 |
# Refresh functions |
|
1003 |
#------------------------------------------------------------------------------- |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1004 |
|
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1005 |
VALUE_TRANSLATION = {True: _("Active"), False: _("Inactive")} |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1006 |
|
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1007 |
def SetValue(self, value): |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1008 |
if self.Value != value: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1009 |
self.Value = value |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1010 |
|
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1011 |
xstart, ystart = self.GetViewStart() |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1012 |
window_size = self.Editor.GetClientSize() |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1013 |
refresh_rect = self.GetRedrawRect() |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1014 |
if (xstart * SCROLLBAR_UNIT <= refresh_rect.x + refresh_rect.width and |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1015 |
xstart * SCROLLBAR_UNIT + window_size[0] >= refresh_rect.x and |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1016 |
ystart * SCROLLBAR_UNIT <= refresh_rect.y + refresh_rect.height and |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1017 |
ystart * SCROLLBAR_UNIT + window_size[1] >= refresh_rect.y): |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1018 |
self.ElementNeedRefresh(self) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1019 |
|
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1020 |
def GetRedrawRect(self): |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1021 |
dc = self.GetLogicalDC() |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1022 |
ipw, iph = dc.GetTextExtent(_("Debug: %s") % self.InstancePath) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1023 |
vw, vh = 0, 0 |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1024 |
for value in self.VALUE_TRANSLATION.itervalues(): |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1025 |
w, h = dc.GetTextExtent("(%s)" % value) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1026 |
vw = max(vw, w) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1027 |
vh = max(vh, h) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1028 |
return wx.Rect(ipw + 4, 2, vw, vh) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1029 |
|
814 | 1030 |
def ElementNeedRefresh(self, element): |
1031 |
self.ElementRefreshList_lock.acquire() |
|
1032 |
self.ElementRefreshList.append(element) |
|
1033 |
self.ElementRefreshList_lock.release() |
|
1034 |
||
1035 |
def RefreshNewData(self): |
|
1036 |
refresh_rect = None |
|
1037 |
self.ElementRefreshList_lock.acquire() |
|
1038 |
for element in self.ElementRefreshList: |
|
1039 |
if refresh_rect is None: |
|
1040 |
refresh_rect = element.GetRedrawRect() |
|
1041 |
else: |
|
1042 |
refresh_rect.Union(element.GetRedrawRect()) |
|
1043 |
self.ElementRefreshList = [] |
|
1044 |
self.ElementRefreshList_lock.release() |
|
1045 |
||
1046 |
if refresh_rect is not None: |
|
1047 |
self.RefreshRect(self.GetScrolledRect(refresh_rect), False) |
|
1048 |
else: |
|
1049 |
DebugViewer.RefreshNewData(self) |
|
1050 |
||
1051 |
# Refresh Viewer elements |
|
1052 |
def RefreshView(self, variablepanel=True, selection=None): |
|
1053 |
EditorPanel.RefreshView(self, variablepanel) |
|
1054 |
||
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1055 |
if self.TagName.split("::")[0] == "A": |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1056 |
self.AddDataConsumer("%s.Q" % self.InstancePath.upper(), self) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1057 |
|
814 | 1058 |
if self.ToolTipElement is not None: |
1059 |
self.ToolTipElement.ClearToolTip() |
|
1060 |
self.ToolTipElement = None |
|
1061 |
||
1062 |
self.Inhibit(True) |
|
1063 |
self.current_id = 0 |
|
1064 |
# Start by reseting Viewer |
|
1065 |
self.Flush() |
|
1066 |
self.ResetView() |
|
1067 |
self.ResetBuffer() |
|
1068 |
instance = {} |
|
1069 |
# List of ids of already loaded blocks |
|
1070 |
ids = [] |
|
1071 |
# Load Blocks until they are all loaded |
|
1072 |
while instance is not None: |
|
1073 |
instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, exclude = ids, debug = self.Debug) |
|
1074 |
if instance is not None: |
|
1075 |
self.loadInstance(instance, ids, selection) |
|
1076 |
self.RefreshScrollBars() |
|
1077 |
||
1078 |
for wire in self.Wires: |
|
1079 |
if not wire.IsConnectedCompatible(): |
|
1080 |
wire.SetValid(False) |
|
1081 |
if self.Debug: |
|
1082 |
iec_path = self.GetElementIECPath(wire) |
|
1083 |
if iec_path is None: |
|
1084 |
block = wire.EndConnected.GetParentBlock() |
|
1085 |
if isinstance(block, LD_PowerRail): |
|
1086 |
wire.SetValue(True) |
|
1087 |
elif self.AddDataConsumer(iec_path.upper(), wire) is None: |
|
1088 |
wire.SetValue("undefined") |
|
1089 |
||
1090 |
if self.Debug: |
|
1091 |
for block in self.Blocks.itervalues(): |
|
1092 |
block.SpreadCurrent() |
|
1093 |
iec_path = self.GetElementIECPath(block) |
|
1094 |
if iec_path is not None: |
|
1095 |
self.AddDataConsumer(iec_path.upper(), block) |
|
1096 |
||
1097 |
self.Inhibit(False) |
|
1098 |
self.RefreshVisibleElements() |
|
1099 |
self.ShowHighlights() |
|
1100 |
self.Refresh(False) |
|
1101 |
||
1102 |
def GetPreviousSteps(self, connectors): |
|
1103 |
steps = [] |
|
1104 |
for connector in connectors: |
|
1105 |
for wire, handle in connector.GetWires(): |
|
1106 |
previous = wire.GetOtherConnected(connector).GetParentBlock() |
|
1107 |
if isinstance(previous, SFC_Step): |
|
1108 |
steps.append(previous.GetName()) |
|
1109 |
elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]: |
|
1110 |
connectors = previous.GetConnectors() |
|
1111 |
steps.extend(self.GetPreviousSteps(connectors["inputs"])) |
|
1112 |
return steps |
|
1113 |
||
1114 |
def GetNextSteps(self, connectors): |
|
1115 |
steps = [] |
|
1116 |
for connector in connectors: |
|
1117 |
for wire, handle in connector.GetWires(): |
|
1118 |
next = wire.GetOtherConnected(connector).GetParentBlock() |
|
1119 |
if isinstance(next, SFC_Step): |
|
1120 |
steps.append(next.GetName()) |
|
1121 |
elif isinstance(next, SFC_Jump): |
|
1122 |
steps.append(next.GetTarget()) |
|
1123 |
elif isinstance(next, SFC_Divergence) and next.GetType() in [SIMULTANEOUS_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
1124 |
connectors = next.GetConnectors() |
|
1125 |
steps.extend(self.GetNextSteps(connectors["outputs"])) |
|
1126 |
return steps |
|
1127 |
||
1128 |
def GetMaxSize(self): |
|
1129 |
maxx = maxy = 0 |
|
1130 |
for element in self.GetElements(): |
|
1131 |
bbox = element.GetBoundingBox() |
|
1132 |
maxx = max(maxx, bbox.x + bbox.width) |
|
1133 |
maxy = max(maxy, bbox.y + bbox.height) |
|
1134 |
return maxx, maxy |
|
1135 |
||
1136 |
def RefreshScrollBars(self, width_incr=0, height_incr=0): |
|
1137 |
xstart, ystart = self.GetViewStart() |
|
1138 |
window_size = self.Editor.GetClientSize() |
|
1139 |
maxx, maxy = self.GetMaxSize() |
|
1140 |
maxx = max(maxx + WINDOW_BORDER, (xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[0]) |
|
1141 |
maxy = max(maxy + WINDOW_BORDER, (ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[1]) |
|
1142 |
if self.rubberBand.IsShown(): |
|
1143 |
extent = self.rubberBand.GetCurrentExtent() |
|
1144 |
maxx = max(maxx, extent.x + extent.width) |
|
1145 |
maxy = max(maxy, extent.y + extent.height) |
|
1146 |
maxx = int(maxx * self.ViewScale[0]) |
|
1147 |
maxy = int(maxy * self.ViewScale[1]) |
|
1148 |
self.Editor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
|
1149 |
round(maxx / SCROLLBAR_UNIT) + width_incr, round(maxy / SCROLLBAR_UNIT) + height_incr, |
|
1150 |
xstart, ystart, True) |
|
1151 |
||
1152 |
def EnsureVisible(self, block): |
|
1153 |
xstart, ystart = self.GetViewStart() |
|
1154 |
window_size = self.Editor.GetClientSize() |
|
1155 |
block_bbx = block.GetBoundingBox() |
|
1156 |
||
1157 |
screen_minx, screen_miny = xstart * SCROLLBAR_UNIT, ystart * SCROLLBAR_UNIT |
|
1158 |
screen_maxx, screen_maxy = screen_minx + window_size[0], screen_miny + window_size[1] |
|
1159 |
block_minx = int(block_bbx.x * self.ViewScale[0]) |
|
1160 |
block_miny = int(block_bbx.y * self.ViewScale[1]) |
|
1161 |
block_maxx = int(round((block_bbx.x + block_bbx.width) * self.ViewScale[0])) |
|
1162 |
block_maxy = int(round((block_bbx.y + block_bbx.height) * self.ViewScale[1])) |
|
1163 |
||
1164 |
xpos, ypos = xstart, ystart |
|
1165 |
if block_minx < screen_minx and block_maxx < screen_maxx: |
|
1166 |
xpos -= (screen_minx - block_minx) / SCROLLBAR_UNIT + 1 |
|
1167 |
elif block_maxx > screen_maxx and block_minx > screen_minx: |
|
1168 |
xpos += (block_maxx - screen_maxx) / SCROLLBAR_UNIT + 1 |
|
1169 |
if block_miny < screen_miny and block_maxy < screen_maxy: |
|
1170 |
ypos -= (screen_miny - block_miny) / SCROLLBAR_UNIT + 1 |
|
1171 |
elif block_maxy > screen_maxy and block_miny > screen_miny: |
|
1172 |
ypos += (block_maxy - screen_maxy) / SCROLLBAR_UNIT + 1 |
|
1173 |
self.Scroll(xpos, ypos) |
|
1174 |
||
1175 |
def SelectInGroup(self, element): |
|
1176 |
element.SetSelected(True) |
|
1177 |
if self.SelectedElement is None: |
|
1178 |
self.SelectedElement = element |
|
1179 |
elif isinstance(self.SelectedElement, Graphic_Group): |
|
1180 |
self.SelectedElement.SelectElement(element) |
|
1181 |
else: |
|
1182 |
group = Graphic_Group(self) |
|
1183 |
group.SelectElement(self.SelectedElement) |
|
1184 |
group.SelectElement(element) |
|
1185 |
self.SelectedElement = group |
|
1186 |
||
1187 |
# Load instance from given informations |
|
1188 |
def loadInstance(self, instance, ids, selection): |
|
1189 |
ids.append(instance["id"]) |
|
1190 |
self.current_id = max(self.current_id, instance["id"]) |
|
1191 |
creation_function = ElementCreationFunctions.get(instance["type"], None) |
|
1192 |
connectors = {"inputs" : [], "outputs" : []} |
|
1193 |
specific_values = instance["specific_values"] |
|
1194 |
if creation_function is not None: |
|
1195 |
element = creation_function(self, instance["id"], specific_values) |
|
1196 |
if isinstance(element, SFC_Step): |
|
1197 |
if len(instance["inputs"]) > 0: |
|
1198 |
element.AddInput() |
|
1199 |
else: |
|
1200 |
element.RemoveInput() |
|
1201 |
if len(instance["outputs"]) > 0: |
|
1202 |
element.AddOutput() |
|
1203 |
if isinstance(element, SFC_Transition) and specific_values["condition_type"] == "connection": |
|
1204 |
connector = element.GetConditionConnector() |
|
1205 |
self.CreateWires(connector, id, specific_values["connection"]["links"], ids, selection) |
|
1206 |
else: |
|
1207 |
executionControl = False |
|
1208 |
for input in instance["inputs"]: |
|
1209 |
if input["negated"]: |
|
1210 |
connectors["inputs"].append((input["name"], None, "negated")) |
|
1211 |
elif input["edge"]: |
|
1212 |
connectors["inputs"].append((input["name"], None, input["edge"])) |
|
1213 |
else: |
|
1214 |
connectors["inputs"].append((input["name"], None, "none")) |
|
1215 |
for output in instance["outputs"]: |
|
1216 |
if output["negated"]: |
|
1217 |
connectors["outputs"].append((output["name"], None, "negated")) |
|
1218 |
elif output["edge"]: |
|
1219 |
connectors["outputs"].append((output["name"], None, output["edge"])) |
|
1220 |
else: |
|
1221 |
connectors["outputs"].append((output["name"], None, "none")) |
|
1222 |
if len(connectors["inputs"]) > 0 and connectors["inputs"][0][0] == "EN": |
|
1223 |
connectors["inputs"].pop(0) |
|
1224 |
executionControl = True |
|
1225 |
if len(connectors["outputs"]) > 0 and connectors["outputs"][0][0] == "ENO": |
|
1226 |
connectors["outputs"].pop(0) |
|
1227 |
executionControl = True |
|
1228 |
if specific_values["name"] is None: |
|
1229 |
specific_values["name"] = "" |
|
1230 |
element = FBD_Block(self, instance["type"], specific_values["name"], |
|
1231 |
instance["id"], len(connectors["inputs"]), |
|
1232 |
connectors=connectors, executionControl=executionControl, |
|
1233 |
executionOrder=specific_values["executionOrder"]) |
|
1234 |
if isinstance(element, Comment): |
|
1235 |
self.AddComment(element) |
|
1236 |
else: |
|
1237 |
self.AddBlock(element) |
|
1238 |
connectors = element.GetConnectors() |
|
832
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1239 |
element.SetPosition(instance["x"], instance["y"]) |
814 | 1240 |
if isinstance(element, SFC_Divergence): |
1241 |
element.SetSize(instance["width"], instance["height"]) |
|
832
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1242 |
for i, output_connector in enumerate(instance["outputs"]): |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1243 |
if i < len(connectors["outputs"]): |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1244 |
connector = connectors["outputs"][i] |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1245 |
if output_connector.get("negated", False): |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1246 |
connector.SetNegated(True) |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1247 |
if output_connector.get("edge", "none") != "none": |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1248 |
connector.SetEdge(output_connector["edge"]) |
b2609a8e4cb6
Fix bug when loading FBD schema with a loop in block connections
laurent
parents:
828
diff
changeset
|
1249 |
connector.SetPosition(wx.Point(*output_connector["position"])) |
814 | 1250 |
for i, input_connector in enumerate(instance["inputs"]): |
1251 |
if i < len(connectors["inputs"]): |
|
1252 |
connector = connectors["inputs"][i] |
|
1253 |
connector.SetPosition(wx.Point(*input_connector["position"])) |
|
1254 |
if input_connector.get("negated", False): |
|
1255 |
connector.SetNegated(True) |
|
1256 |
if input_connector.get("edge", "none") != "none": |
|
1257 |
connector.SetEdge(input_connector["edge"]) |
|
1258 |
self.CreateWires(connector, instance["id"], input_connector["links"], ids, selection) |
|
1259 |
if not isinstance(element, SFC_Divergence): |
|
1260 |
element.SetSize(instance["width"], instance["height"]) |
|
1261 |
if selection is not None and selection[0].get(instance["id"], False): |
|
1262 |
self.SelectInGroup(element) |
|
1263 |
||
1264 |
def CreateWires(self, start_connector, id, links, ids, selection=None): |
|
1265 |
for link in links: |
|
1266 |
refLocalId = link["refLocalId"] |
|
1267 |
if refLocalId is not None: |
|
1268 |
if refLocalId not in ids: |
|
1269 |
new_instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, refLocalId, debug = self.Debug) |
|
1270 |
if new_instance is not None: |
|
1271 |
self.loadInstance(new_instance, ids, selection) |
|
1272 |
connected = self.FindElementById(refLocalId) |
|
1273 |
if connected is not None: |
|
1274 |
points = link["points"] |
|
1275 |
end_connector = connected.GetConnector(wx.Point(points[-1][0], points[-1][1]), link["formalParameter"]) |
|
1276 |
if end_connector is not None: |
|
1277 |
wire = Wire(self) |
|
1278 |
wire.SetPoints(points) |
|
1279 |
start_connector.Connect((wire, 0), False) |
|
1280 |
end_connector.Connect((wire, -1), False) |
|
1281 |
wire.ConnectStartPoint(None, start_connector) |
|
1282 |
wire.ConnectEndPoint(None, end_connector) |
|
1283 |
self.AddWire(wire) |
|
1284 |
if selection is not None and (\ |
|
1285 |
selection[1].get((id, refLocalId), False) or \ |
|
1286 |
selection[1].get((refLocalId, id), False)): |
|
1287 |
self.SelectInGroup(wire) |
|
1288 |
||
1289 |
def IsOfType(self, type, reference): |
|
1290 |
return self.Controler.IsOfType(type, reference, self.Debug) |
|
1291 |
||
1292 |
def IsEndType(self, type): |
|
1293 |
return self.Controler.IsEndType(type) |
|
1294 |
||
1295 |
def GetBlockType(self, type, inputs = None): |
|
1296 |
return self.Controler.GetBlockType(type, inputs, self.Debug) |
|
1297 |
||
1298 |
#------------------------------------------------------------------------------- |
|
1299 |
# Search Element functions |
|
1300 |
#------------------------------------------------------------------------------- |
|
1301 |
||
1302 |
def FindBlock(self, event): |
|
1303 |
dc = self.GetLogicalDC() |
|
1304 |
pos = event.GetLogicalPosition(dc) |
|
1305 |
for block in self.Blocks.itervalues(): |
|
1306 |
if block.HitTest(pos) or block.TestHandle(event) != (0, 0): |
|
1307 |
return block |
|
1308 |
return None |
|
1309 |
||
1310 |
def FindWire(self, event): |
|
1311 |
dc = self.GetLogicalDC() |
|
1312 |
pos = event.GetLogicalPosition(dc) |
|
1313 |
for wire in self.Wires: |
|
1314 |
if wire.HitTest(pos) or wire.TestHandle(event) != (0, 0): |
|
1315 |
return wire |
|
1316 |
return None |
|
1317 |
||
1318 |
def FindElement(self, event, exclude_group = False, connectors = True): |
|
1319 |
dc = self.GetLogicalDC() |
|
1320 |
pos = event.GetLogicalPosition(dc) |
|
1321 |
if self.SelectedElement and not (exclude_group and isinstance(self.SelectedElement, Graphic_Group)): |
|
1322 |
if self.SelectedElement.HitTest(pos, connectors) or self.SelectedElement.TestHandle(event) != (0, 0): |
|
1323 |
return self.SelectedElement |
|
1324 |
for element in self.GetElements(): |
|
1325 |
if element.HitTest(pos, connectors) or element.TestHandle(event) != (0, 0): |
|
1326 |
return element |
|
1327 |
return None |
|
1328 |
||
1329 |
def FindBlockConnector(self, pos, direction = None, exclude = None): |
|
1330 |
for block in self.Blocks.itervalues(): |
|
1331 |
result = block.TestConnector(pos, direction, exclude) |
|
1332 |
if result: |
|
1333 |
return result |
|
1334 |
return None |
|
1335 |
||
1336 |
def FindElementById(self, id): |
|
1337 |
block = self.Blocks.get(id, None) |
|
1338 |
if block is not None: |
|
1339 |
return block |
|
1340 |
comment = self.Comments.get(id, None) |
|
1341 |
if comment is not None: |
|
1342 |
return comment |
|
1343 |
return None |
|
1344 |
||
1345 |
def SearchElements(self, bbox): |
|
1346 |
elements = [] |
|
1347 |
for element in self.GetElements(): |
|
1348 |
if element.IsInSelection(bbox): |
|
1349 |
elements.append(element) |
|
1350 |
return elements |
|
1351 |
||
1352 |
def SelectAll(self): |
|
1353 |
if self.SelectedElement is not None: |
|
1354 |
self.SelectedElement.SetSelected(False) |
|
1355 |
self.SelectedElement = Graphic_Group(self) |
|
1356 |
for element in self.GetElements(): |
|
1357 |
self.SelectedElement.SelectElement(element) |
|
1358 |
self.SelectedElement.SetSelected(True) |
|
1359 |
||
1360 |
#------------------------------------------------------------------------------- |
|
1361 |
# Popup menu functions |
|
1362 |
#------------------------------------------------------------------------------- |
|
1363 |
||
1364 |
def GetForceVariableMenuFunction(self, iec_path, element): |
|
1365 |
iec_type = self.GetDataType(iec_path) |
|
1366 |
def ForceVariableFunction(event): |
|
1367 |
if iec_type is not None: |
|
1368 |
dialog = ForceVariableDialog(self.ParentWindow, iec_type, str(element.GetValue())) |
|
1369 |
if dialog.ShowModal() == wx.ID_OK: |
|
1370 |
self.ParentWindow.AddDebugVariable(iec_path) |
|
1371 |
self.ForceDataValue(iec_path, dialog.GetValue()) |
|
1372 |
return ForceVariableFunction |
|
1373 |
||
1374 |
def GetReleaseVariableMenuFunction(self, iec_path): |
|
1375 |
def ReleaseVariableFunction(event): |
|
1376 |
self.ReleaseDataValue(iec_path) |
|
1377 |
return ReleaseVariableFunction |
|
1378 |
||
1379 |
def PopupForceMenu(self): |
|
1380 |
iec_path = self.GetElementIECPath(self.SelectedElement) |
|
1381 |
if iec_path is not None: |
|
1382 |
menu = wx.Menu(title='') |
|
1383 |
new_id = wx.NewId() |
|
1384 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value")) |
|
1385 |
self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.SelectedElement), id=new_id) |
|
1386 |
new_id = wx.NewId() |
|
1387 |
AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value")) |
|
1388 |
self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id) |
|
1389 |
if self.SelectedElement.IsForced(): |
|
1390 |
menu.Enable(new_id, True) |
|
1391 |
else: |
|
1392 |
menu.Enable(new_id, False) |
|
1393 |
self.Editor.PopupMenu(menu) |
|
1394 |
menu.Destroy() |
|
1395 |
||
1396 |
def PopupBlockMenu(self, connector = None): |
|
1397 |
menu = wx.Menu(title='') |
|
1398 |
if connector is not None and connector.IsCompatible("BOOL"): |
|
1399 |
self.AddBlockPinMenuItems(menu, connector) |
|
1400 |
else: |
|
1401 |
edit = self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug) |
|
1402 |
self.AddDefaultMenuItems(menu, block=True, edit=edit) |
|
1403 |
self.Editor.PopupMenu(menu) |
|
1404 |
menu.Destroy() |
|
1405 |
||
1406 |
def PopupWireMenu(self, delete=True): |
|
1407 |
menu = wx.Menu(title='') |
|
1408 |
self.AddWireMenuItems(menu, delete) |
|
1409 |
menu.AppendSeparator() |
|
1410 |
self.AddDefaultMenuItems(menu, block=True) |
|
1411 |
self.Editor.PopupMenu(menu) |
|
1412 |
menu.Destroy() |
|
1413 |
||
1414 |
def PopupDivergenceMenu(self, connector): |
|
1415 |
menu = wx.Menu(title='') |
|
1416 |
self.AddDivergenceMenuItems(menu, connector) |
|
1417 |
menu.AppendSeparator() |
|
1418 |
self.AddDefaultMenuItems(menu, block=True) |
|
1419 |
self.Editor.PopupMenu(menu) |
|
1420 |
menu.Destroy() |
|
1421 |
||
1422 |
def PopupGroupMenu(self): |
|
1423 |
menu = wx.Menu(title='') |
|
1424 |
align_menu = wx.Menu(title='') |
|
1425 |
self.AddAlignmentMenuItems(align_menu) |
|
1426 |
menu.AppendMenu(-1, _(u'Alignment'), align_menu) |
|
1427 |
menu.AppendSeparator() |
|
1428 |
self.AddDefaultMenuItems(menu, block=True) |
|
1429 |
self.Editor.PopupMenu(menu) |
|
1430 |
menu.Destroy() |
|
1431 |
||
1432 |
def PopupDefaultMenu(self, block=True): |
|
1433 |
menu = wx.Menu(title='') |
|
1434 |
self.AddDefaultMenuItems(menu, block=block) |
|
1435 |
self.Editor.PopupMenu(menu) |
|
1436 |
menu.Destroy() |
|
1437 |
||
1438 |
#------------------------------------------------------------------------------- |
|
1439 |
# Menu items functions |
|
1440 |
#------------------------------------------------------------------------------- |
|
1441 |
||
1442 |
def OnAlignLeftMenu(self, event): |
|
1443 |
if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group): |
|
1444 |
self.SelectedElement.AlignElements(ALIGN_LEFT, None) |
|
1445 |
self.RefreshBuffer() |
|
1446 |
self.Refresh(False) |
|
1447 |
||
1448 |
def OnAlignCenterMenu(self, event): |
|
1449 |
if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group): |
|
1450 |
self.SelectedElement.AlignElements(ALIGN_CENTER, None) |
|
1451 |
self.RefreshBuffer() |
|
1452 |
self.Refresh(False) |
|
1453 |
||
1454 |
def OnAlignRightMenu(self, event): |
|
1455 |
if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group): |
|
1456 |
self.SelectedElement.AlignElements(ALIGN_RIGHT, None) |
|
1457 |
self.RefreshBuffer() |
|
1458 |
self.Refresh(False) |
|
1459 |
||
1460 |
def OnAlignTopMenu(self, event): |
|
1461 |
if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group): |
|
1462 |
self.SelectedElement.AlignElements(None, ALIGN_TOP) |
|
1463 |
self.RefreshBuffer() |
|
1464 |
self.Refresh(False) |
|
1465 |
||
1466 |
def OnAlignMiddleMenu(self, event): |
|
1467 |
if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group): |
|
1468 |
self.SelectedElement.AlignElements(None, ALIGN_MIDDLE) |
|
1469 |
self.RefreshBuffer() |
|
1470 |
self.Refresh(False) |
|
1471 |
||
1472 |
def OnAlignBottomMenu(self, event): |
|
1473 |
if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group): |
|
1474 |
self.SelectedElement.AlignElements(None, ALIGN_BOTTOM) |
|
1475 |
self.RefreshBuffer() |
|
1476 |
self.Refresh(False) |
|
1477 |
||
1478 |
def OnNoModifierMenu(self, event): |
|
1479 |
if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
|
1480 |
self.SelectedElement.SetConnectorNegated(False) |
|
1481 |
self.SelectedElement.Refresh() |
|
1482 |
self.RefreshBuffer() |
|
1483 |
||
1484 |
def OnNegatedMenu(self, event): |
|
1485 |
if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
|
1486 |
self.SelectedElement.SetConnectorNegated(True) |
|
1487 |
self.SelectedElement.Refresh() |
|
1488 |
self.RefreshBuffer() |
|
1489 |
||
1490 |
def OnRisingEdgeMenu(self, event): |
|
1491 |
if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
|
1492 |
self.SelectedElement.SetConnectorEdge("rising") |
|
1493 |
self.SelectedElement.Refresh() |
|
1494 |
self.RefreshBuffer() |
|
1495 |
||
1496 |
def OnFallingEdgeMenu(self, event): |
|
1497 |
if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
|
1498 |
self.SelectedElement.SetConnectorEdge("falling") |
|
1499 |
self.SelectedElement.Refresh() |
|
1500 |
self.RefreshBuffer() |
|
1501 |
||
1502 |
def OnAddSegmentMenu(self, event): |
|
1503 |
if self.SelectedElement is not None and self.IsWire(self.SelectedElement): |
|
1504 |
self.SelectedElement.AddSegment() |
|
1505 |
self.SelectedElement.Refresh() |
|
1506 |
||
1507 |
def OnDeleteSegmentMenu(self, event): |
|
1508 |
if self.SelectedElement is not None and self.IsWire(self.SelectedElement): |
|
1509 |
self.SelectedElement.DeleteSegment() |
|
1510 |
self.SelectedElement.Refresh() |
|
1511 |
||
1512 |
def OnAddBranchMenu(self, event): |
|
1513 |
if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
|
1514 |
self.AddDivergenceBranch(self.SelectedElement) |
|
1515 |
||
1516 |
def OnDeleteBranchMenu(self, event): |
|
1517 |
if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
|
1518 |
self.RemoveDivergenceBranch(self.SelectedElement) |
|
1519 |
||
1520 |
def OnEditBlockMenu(self, event): |
|
1521 |
if self.SelectedElement is not None: |
|
1522 |
self.ParentWindow.EditProjectElement(ITEM_POU, "P::%s"%self.SelectedElement.GetType()) |
|
1523 |
||
1524 |
def OnDeleteMenu(self, event): |
|
1525 |
if self.SelectedElement is not None: |
|
1526 |
self.SelectedElement.Delete() |
|
1527 |
self.SelectedElement = None |
|
1528 |
self.RefreshBuffer() |
|
1529 |
self.Refresh(False) |
|
1530 |
||
1531 |
def OnClearExecutionOrderMenu(self, event): |
|
1532 |
self.Controler.ClearEditedElementExecutionOrder(self.TagName) |
|
1533 |
self.RefreshBuffer() |
|
1534 |
self.RefreshView() |
|
1535 |
||
1536 |
def OnResetExecutionOrderMenu(self, event): |
|
1537 |
self.Controler.ResetEditedElementExecutionOrder(self.TagName) |
|
1538 |
self.RefreshBuffer() |
|
1539 |
self.RefreshView() |
|
1540 |
||
1541 |
def GetAddMenuCallBack(self, func, *args): |
|
1542 |
def AddMenuCallBack(event): |
|
1543 |
wx.CallAfter(func, self.rubberBand.GetCurrentExtent(), *args) |
|
1544 |
return AddMenuCallBack |
|
1545 |
||
1546 |
def GetClipboardCallBack(self, func): |
|
1547 |
def ClipboardCallback(event): |
|
1548 |
wx.CallAfter(func) |
|
1549 |
return ClipboardCallback |
|
1550 |
||
1551 |
#------------------------------------------------------------------------------- |
|
1552 |
# Mouse event functions |
|
1553 |
#------------------------------------------------------------------------------- |
|
1554 |
||
1555 |
def OnViewerMouseEvent(self, event): |
|
1556 |
if not event.Entering(): |
|
1557 |
self.ResetBuffer() |
|
1558 |
element = None |
|
1559 |
if not event.Leaving() and not event.LeftUp() and not event.LeftDClick(): |
|
1560 |
element = self.FindElement(event, True, False) |
|
1561 |
if self.ToolTipElement is not None: |
|
1562 |
self.ToolTipElement.ClearToolTip() |
|
1563 |
self.ToolTipElement = element |
|
1564 |
if self.ToolTipElement is not None: |
|
1565 |
tooltip_pos = self.Editor.ClientToScreen(event.GetPosition()) |
|
1566 |
tooltip_pos.x += 10 |
|
1567 |
tooltip_pos.y += 10 |
|
1568 |
self.ToolTipElement.CreateToolTip(tooltip_pos) |
|
1569 |
event.Skip() |
|
1570 |
||
1571 |
def OnViewerLeftDown(self, event): |
|
1572 |
self.Editor.CaptureMouse() |
|
1573 |
if self.Mode == MODE_SELECTION: |
|
1574 |
dc = self.GetLogicalDC() |
|
1575 |
pos = event.GetLogicalPosition(dc) |
|
1576 |
if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None: |
|
1577 |
element = self.FindElement(event, True) |
|
1578 |
if element is not None: |
|
1579 |
if isinstance(self.SelectedElement, Graphic_Group): |
|
1580 |
self.SelectedElement.SetSelected(False) |
|
1581 |
self.SelectedElement.SelectElement(element) |
|
1582 |
elif self.SelectedElement is not None: |
|
1583 |
group = Graphic_Group(self) |
|
1584 |
group.SelectElement(self.SelectedElement) |
|
1585 |
group.SelectElement(element) |
|
1586 |
self.SelectedElement = group |
|
1587 |
elements = self.SelectedElement.GetElements() |
|
1588 |
if len(elements) == 0: |
|
1589 |
self.SelectedElement = element |
|
1590 |
elif len(elements) == 1: |
|
1591 |
self.SelectedElement = elements[0] |
|
1592 |
self.SelectedElement.SetSelected(True) |
|
1593 |
else: |
|
1594 |
self.rubberBand.Reset() |
|
1595 |
self.rubberBand.OnLeftDown(event, dc, self.Scaling) |
|
1596 |
else: |
|
1597 |
element = self.FindElement(event) |
|
1598 |
if not self.Debug and (element is None or element.TestHandle(event) == (0, 0)): |
|
1599 |
connector = self.FindBlockConnector(pos) |
|
1600 |
else: |
|
1601 |
connector = None |
|
1602 |
if not self.Debug and self.DrawingWire: |
|
1603 |
self.DrawingWire = False |
|
1604 |
if self.SelectedElement is not None: |
|
1605 |
if element is None or element.TestHandle(event) == (0, 0): |
|
1606 |
connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection()) |
|
1607 |
if connector is not None: |
|
1608 |
event.Dragging = lambda : True |
|
1609 |
self.SelectedElement.OnMotion(event, dc, self.Scaling) |
|
1610 |
if self.SelectedElement.EndConnected is not None: |
|
1611 |
self.SelectedElement.ResetPoints() |
|
1612 |
self.SelectedElement.GeneratePoints() |
|
1613 |
self.SelectedElement.RefreshModel() |
|
1614 |
self.SelectedElement.SetSelected(True) |
|
1615 |
element = self.SelectedElement |
|
1616 |
self.RefreshBuffer() |
|
1617 |
else: |
|
1618 |
rect = self.SelectedElement.GetRedrawRect() |
|
1619 |
self.SelectedElement.Delete() |
|
1620 |
self.SelectedElement = None |
|
1621 |
element = None |
|
1622 |
self.RefreshRect(self.GetScrolledRect(rect), False) |
|
1623 |
elif not self.Debug and connector is not None and not event.ControlDown(): |
|
1624 |
self.DrawingWire = True |
|
1625 |
scaled_pos = GetScaledEventPosition(event, dc, self.Scaling) |
|
1626 |
if (connector.GetDirection() == EAST): |
|
1627 |
wire = Wire(self, [wx.Point(pos.x, pos.y), EAST], [wx.Point(scaled_pos.x, scaled_pos.y), WEST]) |
|
1628 |
else: |
|
1629 |
wire = Wire(self, [wx.Point(pos.x, pos.y), WEST], [wx.Point(scaled_pos.x, scaled_pos.y), EAST]) |
|
1630 |
wire.oldPos = scaled_pos |
|
1631 |
wire.Handle = (HANDLE_POINT, 0) |
|
1632 |
wire.ProcessDragging(0, 0, event, None) |
|
1633 |
wire.Handle = (HANDLE_POINT, 1) |
|
1634 |
self.AddWire(wire) |
|
1635 |
if self.SelectedElement is not None: |
|
1636 |
self.SelectedElement.SetSelected(False) |
|
1637 |
self.SelectedElement = wire |
|
1638 |
if self.HighlightedElement is not None: |
|
1639 |
self.HighlightedElement.SetHighlighted(False) |
|
1640 |
self.HighlightedElement = wire |
|
1641 |
self.RefreshVisibleElements() |
|
1642 |
self.SelectedElement.SetHighlighted(True) |
|
1643 |
else: |
|
1644 |
if self.SelectedElement is not None and self.SelectedElement != element: |
|
1645 |
self.SelectedElement.SetSelected(False) |
|
1646 |
self.SelectedElement = None |
|
1647 |
if element is not None: |
|
1648 |
self.SelectedElement = element |
|
1649 |
if self.Debug: |
|
1650 |
self.StartMousePos = event.GetPosition() |
|
1651 |
Graphic_Element.OnLeftDown(self.SelectedElement, event, dc, self.Scaling) |
|
1652 |
else: |
|
1653 |
self.SelectedElement.OnLeftDown(event, dc, self.Scaling) |
|
1654 |
self.SelectedElement.Refresh() |
|
1655 |
else: |
|
1656 |
self.rubberBand.Reset() |
|
1657 |
self.rubberBand.OnLeftDown(event, dc, self.Scaling) |
|
1658 |
elif self.Mode in [MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, |
|
1659 |
MODE_CONTACT, MODE_COIL, MODE_POWERRAIL, MODE_INITIALSTEP, |
|
1660 |
MODE_STEP, MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION]: |
|
1661 |
self.rubberBand.Reset() |
|
1662 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
1663 |
elif self.Mode == MODE_MOTION: |
|
1664 |
self.StartMousePos = event.GetPosition() |
|
1665 |
self.StartScreenPos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
1666 |
event.Skip() |
|
1667 |
||
1668 |
def OnViewerLeftUp(self, event): |
|
1669 |
self.StartMousePos = None |
|
1670 |
if self.rubberBand.IsShown(): |
|
1671 |
if self.Mode == MODE_SELECTION: |
|
1672 |
new_elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
|
1673 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
1674 |
if event.ShiftDown() and self.SelectedElement is not None: |
|
1675 |
if isinstance(self.SelectedElement, Graphic_Group): |
|
1676 |
elements = self.SelectedElement.GetElements() |
|
1677 |
else: |
|
1678 |
elements = [self.SelectedElement] |
|
1679 |
for element in elements: |
|
1680 |
if element not in new_elements: |
|
1681 |
new_elements.append(element) |
|
1682 |
if len(new_elements) == 1: |
|
1683 |
self.SelectedElement = new_elements[0] |
|
1684 |
self.SelectedElement.SetSelected(True) |
|
1685 |
elif len(new_elements) > 1: |
|
1686 |
self.SelectedElement = Graphic_Group(self) |
|
1687 |
self.SelectedElement.SetElements(new_elements) |
|
1688 |
self.SelectedElement.SetSelected(True) |
|
1689 |
else: |
|
1690 |
bbox = self.rubberBand.GetCurrentExtent() |
|
1691 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
1692 |
if self.Mode == MODE_BLOCK: |
|
1693 |
wx.CallAfter(self.AddNewBlock, bbox) |
|
1694 |
elif self.Mode == MODE_VARIABLE: |
|
1695 |
wx.CallAfter(self.AddNewVariable, bbox) |
|
1696 |
elif self.Mode == MODE_CONNECTION: |
|
1697 |
wx.CallAfter(self.AddNewConnection, bbox) |
|
1698 |
elif self.Mode == MODE_COMMENT: |
|
1699 |
wx.CallAfter(self.AddNewComment, bbox) |
|
1700 |
elif self.Mode == MODE_CONTACT: |
|
1701 |
wx.CallAfter(self.AddNewContact, bbox) |
|
1702 |
elif self.Mode == MODE_COIL: |
|
1703 |
wx.CallAfter(self.AddNewCoil, bbox) |
|
1704 |
elif self.Mode == MODE_POWERRAIL: |
|
1705 |
wx.CallAfter(self.AddNewPowerRail, bbox) |
|
1706 |
elif self.Mode == MODE_INITIALSTEP: |
|
1707 |
wx.CallAfter(self.AddNewStep, bbox, True) |
|
1708 |
elif self.Mode == MODE_STEP: |
|
1709 |
wx.CallAfter(self.AddNewStep, bbox, False) |
|
1710 |
elif self.Mode == MODE_TRANSITION: |
|
1711 |
wx.CallAfter(self.AddNewTransition, bbox) |
|
1712 |
elif self.Mode == MODE_DIVERGENCE: |
|
1713 |
wx.CallAfter(self.AddNewDivergence, bbox) |
|
1714 |
elif self.Mode == MODE_JUMP: |
|
1715 |
wx.CallAfter(self.AddNewJump, bbox) |
|
1716 |
elif self.Mode == MODE_ACTION: |
|
1717 |
wx.CallAfter(self.AddNewActionBlock, bbox) |
|
1718 |
elif self.Mode == MODE_SELECTION and self.SelectedElement is not None: |
|
1719 |
dc = self.GetLogicalDC() |
|
1720 |
if not self.Debug and self.DrawingWire: |
|
1721 |
pos = event.GetLogicalPosition(dc) |
|
1722 |
connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection()) |
|
1723 |
if self.SelectedElement.EndConnected is not None: |
|
1724 |
self.DrawingWire = False |
|
1725 |
self.SelectedElement.StartConnected.HighlightParentBlock(False) |
|
1726 |
self.SelectedElement.EndConnected.HighlightParentBlock(False) |
|
1727 |
self.SelectedElement.ResetPoints() |
|
1728 |
self.SelectedElement.OnMotion(event, dc, self.Scaling) |
|
1729 |
self.SelectedElement.GeneratePoints() |
|
1730 |
self.SelectedElement.RefreshModel() |
|
1731 |
self.SelectedElement.SetSelected(True) |
|
1732 |
self.SelectedElement.HighlightPoint(pos) |
|
1733 |
self.RefreshBuffer() |
|
1734 |
elif connector is None or self.SelectedElement.GetDragging(): |
|
1735 |
self.DrawingWire = False |
|
1736 |
rect = self.SelectedElement.GetRedrawRect() |
|
1737 |
wire = self.SelectedElement |
|
1738 |
self.SelectedElement = self.SelectedElement.StartConnected.GetParentBlock() |
|
1739 |
self.SelectedElement.SetSelected(True) |
|
1740 |
rect.Union(self.SelectedElement.GetRedrawRect()) |
|
1741 |
wire.Delete() |
|
1742 |
self.RefreshRect(self.GetScrolledRect(rect), False) |
|
1743 |
else: |
|
1744 |
if self.Debug: |
|
1745 |
Graphic_Element.OnLeftUp(self.SelectedElement, event, dc, self.Scaling) |
|
1746 |
else: |
|
1747 |
self.SelectedElement.OnLeftUp(event, dc, self.Scaling) |
|
1748 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
1749 |
elif self.Mode == MODE_MOTION: |
|
1750 |
self.StartMousePos = None |
|
1751 |
self.StartScreenPos = None |
|
1752 |
if self.Mode != MODE_SELECTION and not self.SavedMode: |
|
1753 |
wx.CallAfter(self.ParentWindow.ResetCurrentMode) |
|
1754 |
if self.Editor.HasCapture(): |
|
1755 |
self.Editor.ReleaseMouse() |
|
1756 |
event.Skip() |
|
1757 |
||
1758 |
def OnViewerMiddleDown(self, event): |
|
1759 |
self.Editor.CaptureMouse() |
|
1760 |
self.StartMousePos = event.GetPosition() |
|
1761 |
self.StartScreenPos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
1762 |
event.Skip() |
|
1763 |
||
1764 |
def OnViewerMiddleUp(self, event): |
|
1765 |
self.StartMousePos = None |
|
1766 |
self.StartScreenPos = None |
|
1767 |
if self.Editor.HasCapture(): |
|
1768 |
self.Editor.ReleaseMouse() |
|
1769 |
event.Skip() |
|
1770 |
||
1771 |
def OnViewerRightDown(self, event): |
|
1772 |
self.Editor.CaptureMouse() |
|
1773 |
if self.Mode == MODE_SELECTION: |
|
1774 |
element = self.FindElement(event) |
|
1775 |
if self.SelectedElement is not None and self.SelectedElement != element: |
|
1776 |
self.SelectedElement.SetSelected(False) |
|
1777 |
self.SelectedElement = None |
|
1778 |
if element is not None: |
|
1779 |
self.SelectedElement = element |
|
1780 |
if self.Debug: |
|
1781 |
Graphic_Element.OnRightDown(self.SelectedElement, event, self.GetLogicalDC(), self.Scaling) |
|
1782 |
else: |
|
1783 |
self.SelectedElement.OnRightDown(event, self.GetLogicalDC(), self.Scaling) |
|
1784 |
self.SelectedElement.Refresh() |
|
1785 |
event.Skip() |
|
1786 |
||
1787 |
def OnViewerRightUp(self, event): |
|
1788 |
dc = self.GetLogicalDC() |
|
1789 |
self.rubberBand.Reset() |
|
1790 |
self.rubberBand.OnLeftDown(event, dc, self.Scaling) |
|
1791 |
self.rubberBand.OnLeftUp(event, dc, self.Scaling) |
|
1792 |
if self.SelectedElement is not None: |
|
1793 |
if self.Debug: |
|
1794 |
Graphic_Element.OnRightUp(self.SelectedElement, event, self.GetLogicalDC(), self.Scaling) |
|
1795 |
else: |
|
1796 |
self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling) |
|
1797 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
1798 |
elif not self.Debug: |
|
1799 |
self.PopupDefaultMenu(False) |
|
1800 |
if self.Editor.HasCapture(): |
|
1801 |
self.Editor.ReleaseMouse() |
|
1802 |
event.Skip() |
|
1803 |
||
1804 |
def OnViewerLeftDClick(self, event): |
|
1805 |
element = self.FindElement(event, connectors=False) |
|
1806 |
if self.Mode == MODE_SELECTION and element is not None: |
|
1807 |
if self.SelectedElement is not None and self.SelectedElement != element: |
|
1808 |
self.SelectedElement.SetSelected(False) |
|
1809 |
if self.HighlightedElement is not None and self.HighlightedElement != element: |
|
1810 |
self.HighlightedElement.SetHighlighted(False) |
|
1811 |
||
1812 |
self.SelectedElement = element |
|
1813 |
self.HighlightedElement = element |
|
1814 |
self.SelectedElement.SetHighlighted(True) |
|
1815 |
||
1816 |
if self.Debug: |
|
820
d981fe154c36
Fix bug when Dclick on step and actionBlock in debug mode
laurent
parents:
814
diff
changeset
|
1817 |
if isinstance(self.SelectedElement, FBD_Block): |
814 | 1818 |
instance_type = self.SelectedElement.GetType() |
1819 |
pou_type = { |
|
1820 |
"program": ITEM_PROGRAM, |
|
1821 |
"functionBlock": ITEM_FUNCTIONBLOCK, |
|
1822 |
}.get(self.Controler.GetPouType(instance_type)) |
|
1823 |
if pou_type is not None and instance_type in self.Controler.GetProjectPouNames(self.Debug): |
|
1824 |
self.ParentWindow.OpenDebugViewer(pou_type, |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
1825 |
"%s.%s"%(self.GetInstancePath(True), self.SelectedElement.GetName()), |
814 | 1826 |
self.Controler.ComputePouName(instance_type)) |
1827 |
else: |
|
1828 |
iec_path = self.GetElementIECPath(self.SelectedElement) |
|
1829 |
if iec_path is not None: |
|
1830 |
if isinstance(self.SelectedElement, Wire): |
|
1831 |
if self.SelectedElement.EndConnected is not None: |
|
1832 |
var_type = self.SelectedElement.EndConnected.GetType() |
|
1833 |
if self.Controler.IsOfType(var_type, "ANY_NUM", self.Debug) or\ |
|
1834 |
self.Controler.IsOfType(var_type, "ANY_BIT", self.Debug): |
|
1835 |
self.ParentWindow.OpenGraphicViewer(iec_path) |
|
1836 |
else: |
|
1837 |
self.ParentWindow.OpenGraphicViewer(iec_path) |
|
1838 |
elif event.ControlDown() and not event.ShiftDown(): |
|
1839 |
instance_type = self.SelectedElement.GetType() |
|
1840 |
if self.IsBlock(self.SelectedElement) and instance_type in self.Controler.GetProjectPouNames(self.Debug): |
|
1841 |
self.ParentWindow.EditProjectElement(ITEM_POU, |
|
1842 |
self.Controler.ComputePouName(instance_type)) |
|
1843 |
else: |
|
1844 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
1845 |
elif event.ControlDown() and event.ShiftDown(): |
|
1846 |
movex, movey = self.SelectedElement.AdjustToScaling(self.Scaling) |
|
1847 |
self.SelectedElement.RefreshModel() |
|
1848 |
self.RefreshBuffer() |
|
1849 |
if movex != 0 or movey != 0: |
|
1850 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False) |
|
1851 |
else: |
|
1852 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
1853 |
event.Skip() |
|
1854 |
||
1855 |
def OnViewerMotion(self, event): |
|
1856 |
if self.Editor.HasCapture() and not event.Dragging(): |
|
1857 |
return |
|
1858 |
refresh = False |
|
1859 |
dc = self.GetLogicalDC() |
|
1860 |
pos = GetScaledEventPosition(event, dc, self.Scaling) |
|
1861 |
if event.MiddleIsDown() or self.Mode == MODE_MOTION: |
|
1862 |
if self.StartMousePos is not None and self.StartScreenPos is not None: |
|
1863 |
new_pos = event.GetPosition() |
|
1864 |
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
1865 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
|
1866 |
scrollx = max(0, self.StartScreenPos[0] - (new_pos[0] - self.StartMousePos[0]) / SCROLLBAR_UNIT) |
|
1867 |
scrolly = max(0, self.StartScreenPos[1] - (new_pos[1] - self.StartMousePos[1]) / SCROLLBAR_UNIT) |
|
1868 |
if scrollx > xmax or scrolly > ymax: |
|
1869 |
self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax)) |
|
1870 |
self.Scroll(scrollx, scrolly) |
|
1871 |
else: |
|
1872 |
self.Scroll(scrollx, scrolly) |
|
1873 |
self.RefreshScrollBars() |
|
1874 |
self.RefreshVisibleElements() |
|
1875 |
else: |
|
1876 |
if not event.Dragging(): |
|
1877 |
highlighted = self.FindElement(event, connectors=False) |
|
1878 |
if self.HighlightedElement is not None and self.HighlightedElement != highlighted: |
|
1879 |
self.HighlightedElement.SetHighlighted(False) |
|
1880 |
self.HighlightedElement = None |
|
1881 |
if highlighted is not None: |
|
1882 |
if isinstance(highlighted, (Wire, Graphic_Group)): |
|
1883 |
highlighted.HighlightPoint(pos) |
|
1884 |
if self.HighlightedElement != highlighted: |
|
1885 |
highlighted.SetHighlighted(True) |
|
1886 |
self.HighlightedElement = highlighted |
|
1887 |
if self.rubberBand.IsShown(): |
|
1888 |
self.rubberBand.OnMotion(event, dc, self.Scaling) |
|
1889 |
elif not self.Debug and self.Mode == MODE_SELECTION and self.SelectedElement is not None: |
|
1890 |
if self.DrawingWire: |
|
1891 |
connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection(), self.SelectedElement.EndConnected) |
|
1892 |
if not connector or self.SelectedElement.EndConnected == None: |
|
1893 |
self.SelectedElement.ResetPoints() |
|
1894 |
movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling) |
|
1895 |
self.SelectedElement.GeneratePoints() |
|
1896 |
if movex != 0 or movey != 0: |
|
1897 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False) |
|
1898 |
else: |
|
1899 |
self.SelectedElement.HighlightPoint(pos) |
|
1900 |
else: |
|
1901 |
movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling) |
|
1902 |
if movex != 0 or movey != 0: |
|
1903 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False) |
|
1904 |
elif self.Debug and self.StartMousePos is not None and event.Dragging(): |
|
1905 |
pos = event.GetPosition() |
|
1906 |
if abs(self.StartMousePos.x - pos.x) > 5 or abs(self.StartMousePos.y - pos.y) > 5: |
|
1907 |
iec_path = self.GetElementIECPath(self.SelectedElement) |
|
1908 |
if iec_path is not None: |
|
1909 |
self.StartMousePos = None |
|
1910 |
if self.HighlightedElement is not None: |
|
1911 |
self.HighlightedElement.SetHighlighted(False) |
|
1912 |
self.HighlightedElement = None |
|
1913 |
data = wx.TextDataObject(str((iec_path, "debug"))) |
|
1914 |
dragSource = wx.DropSource(self.Editor) |
|
1915 |
dragSource.SetData(data) |
|
1916 |
dragSource.DoDragDrop() |
|
1917 |
self.UpdateScrollPos(event) |
|
1918 |
event.Skip() |
|
1919 |
||
1920 |
def OnLeaveViewer(self, event): |
|
1921 |
if self.StartScreenPos is None: |
|
1922 |
self.StartMousePos = None |
|
1923 |
if self.SelectedElement is not None and self.SelectedElement.GetDragging(): |
|
1924 |
event.Skip() |
|
1925 |
elif self.HighlightedElement is not None: |
|
1926 |
self.HighlightedElement.SetHighlighted(False) |
|
1927 |
self.HighlightedElement = None |
|
1928 |
event.Skip() |
|
1929 |
||
1930 |
def UpdateScrollPos(self, event): |
|
1931 |
if (event.Dragging() and self.SelectedElement is not None) or self.rubberBand.IsShown(): |
|
1932 |
position = event.GetPosition() |
|
1933 |
move_window = wx.Point() |
|
1934 |
window_size = self.Editor.GetClientSize() |
|
1935 |
xstart, ystart = self.GetViewStart() |
|
1936 |
if position.x < SCROLL_ZONE and xstart > 0: |
|
1937 |
move_window.x = -1 |
|
1938 |
elif position.x > window_size[0] - SCROLL_ZONE: |
|
1939 |
move_window.x = 1 |
|
1940 |
if position.y < SCROLL_ZONE and ystart > 0: |
|
1941 |
move_window.y = -1 |
|
1942 |
elif position.y > window_size[1] - SCROLL_ZONE: |
|
1943 |
move_window.y = 1 |
|
1944 |
if move_window.x != 0 or move_window.y != 0: |
|
1945 |
self.RefreshVisibleElements(xp = xstart + move_window.x, yp = ystart + move_window.y) |
|
1946 |
self.Scroll(xstart + move_window.x, ystart + move_window.y) |
|
1947 |
self.RefreshScrollBars(move_window.x, move_window.y) |
|
1948 |
||
1949 |
#------------------------------------------------------------------------------- |
|
1950 |
# Keyboard event functions |
|
1951 |
#------------------------------------------------------------------------------- |
|
1952 |
||
1953 |
ARROW_KEY_MOVE = { |
|
1954 |
wx.WXK_LEFT: (-1, 0), |
|
1955 |
wx.WXK_RIGHT: (1, 0), |
|
1956 |
wx.WXK_UP: (0, -1), |
|
1957 |
wx.WXK_DOWN: (0, 1), |
|
1958 |
} |
|
1959 |
||
1960 |
def OnChar(self, event): |
|
1961 |
xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
1962 |
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
1963 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
|
1964 |
keycode = event.GetKeyCode() |
|
1965 |
if self.Scaling is not None: |
|
1966 |
scaling = self.Scaling |
|
1967 |
else: |
|
1968 |
scaling = (8, 8) |
|
1969 |
if not self.Debug and keycode == wx.WXK_DELETE and self.SelectedElement is not None: |
|
1970 |
rect = self.SelectedElement.GetRedrawRect(1, 1) |
|
1971 |
self.SelectedElement.Delete() |
|
1972 |
self.SelectedElement = None |
|
1973 |
self.RefreshBuffer() |
|
1974 |
self.RefreshScrollBars() |
|
1975 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
1976 |
self.RefreshRect(self.GetScrolledRect(rect), False) |
|
1977 |
elif not self.Debug and keycode == wx.WXK_RETURN and self.SelectedElement is not None: |
|
1978 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
1979 |
elif self.ARROW_KEY_MOVE.has_key(keycode): |
|
1980 |
move = self.ARROW_KEY_MOVE[keycode] |
|
1981 |
if event.ControlDown() and event.ShiftDown(): |
|
1982 |
self.Scroll({-1: 0, 0: xpos, 1: xmax}[move[0]], |
|
1983 |
{-1: 0, 0: ypos, 1: ymax}[move[1]]) |
|
1984 |
self.RefreshVisibleElements() |
|
1985 |
elif event.ControlDown(): |
|
1986 |
self.Scroll(xpos + move[0], ypos + move[1]) |
|
1987 |
self.RefreshScrollBars() |
|
1988 |
self.RefreshVisibleElements() |
|
1989 |
elif not self.Debug and self.SelectedElement is not None: |
|
1990 |
movex, movey = move |
|
1991 |
if not event.AltDown() or event.ShiftDown(): |
|
1992 |
movex *= scaling[0] |
|
1993 |
movey *= scaling[1] |
|
1994 |
if event.ShiftDown() and not event.AltDown(): |
|
1995 |
movex *= 10 |
|
1996 |
movey *= 10 |
|
1997 |
self.SelectedElement.Move(movex, movey) |
|
1998 |
self.StartBuffering() |
|
1999 |
self.SelectedElement.RefreshModel() |
|
2000 |
self.RefreshScrollBars() |
|
2001 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False) |
|
2002 |
elif not self.Debug and keycode == wx.WXK_SPACE and self.SelectedElement is not None and self.SelectedElement.Dragging: |
|
2003 |
if self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement): |
|
2004 |
block = self.CopyBlock(self.SelectedElement, wx.Point(*self.SelectedElement.GetPosition())) |
|
2005 |
event = wx.MouseEvent() |
|
2006 |
event.m_x, event.m_y = self.Editor.ScreenToClient(wx.GetMousePosition()) |
|
2007 |
dc = self.GetLogicalDC() |
|
2008 |
self.SelectedElement.OnLeftUp(event, dc, self.Scaling) |
|
2009 |
self.SelectedElement.SetSelected(False) |
|
2010 |
block.OnLeftDown(event, dc, self.Scaling) |
|
2011 |
self.SelectedElement = block |
|
2012 |
self.SelectedElement.SetSelected(True) |
|
2013 |
self.RefreshVariablePanel() |
|
2014 |
self.RefreshVisibleElements() |
|
2015 |
else: |
|
2016 |
event.Skip() |
|
2017 |
elif keycode == ord("+"): |
|
2018 |
self.SetScale(self.CurrentScale + 1) |
|
2019 |
self.ParentWindow.RefreshDisplayMenu() |
|
2020 |
elif keycode == ord("-"): |
|
2021 |
self.SetScale(self.CurrentScale - 1) |
|
2022 |
self.ParentWindow.RefreshDisplayMenu() |
|
2023 |
else: |
|
2024 |
event.Skip() |
|
2025 |
||
2026 |
#------------------------------------------------------------------------------- |
|
2027 |
# Model adding functions from Drop Target |
|
2028 |
#------------------------------------------------------------------------------- |
|
2029 |
||
2030 |
def AddVariableBlock(self, x, y, scaling, var_class, var_name, var_type): |
|
2031 |
id = self.GetNewId() |
|
2032 |
variable = FBD_Variable(self, var_class, var_name, var_type, id) |
|
2033 |
width, height = variable.GetMinSize() |
|
2034 |
if scaling is not None: |
|
2035 |
x = round(float(x) / float(scaling[0])) * scaling[0] |
|
2036 |
y = round(float(y) / float(scaling[1])) * scaling[1] |
|
2037 |
width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
|
2038 |
height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
2039 |
variable.SetPosition(x, y) |
|
2040 |
variable.SetSize(width, height) |
|
2041 |
self.AddBlock(variable) |
|
2042 |
self.Controler.AddEditedElementVariable(self.GetTagName(), id, var_class) |
|
2043 |
self.RefreshVariableModel(variable) |
|
2044 |
self.RefreshBuffer() |
|
2045 |
self.RefreshScrollBars() |
|
2046 |
self.RefreshVisibleElements() |
|
2047 |
self.Refresh(False) |
|
2048 |
||
2049 |
#------------------------------------------------------------------------------- |
|
2050 |
# Model adding functions |
|
2051 |
#------------------------------------------------------------------------------- |
|
2052 |
||
2053 |
def GetScaledSize(self, width, height): |
|
2054 |
if self.Scaling is not None: |
|
2055 |
width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0] |
|
2056 |
height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1] |
|
2057 |
return width, height |
|
2058 |
||
2059 |
def AddNewBlock(self, bbox): |
|
2060 |
dialog = FBDBlockDialog(self.ParentWindow, self.Controler) |
|
2061 |
dialog.SetPreviewFont(self.GetFont()) |
|
2062 |
dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug)) |
|
2063 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
2064 |
dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug)) |
|
2065 |
dialog.SetMinBlockSize((bbox.width, bbox.height)) |
|
2066 |
if dialog.ShowModal() == wx.ID_OK: |
|
2067 |
id = self.GetNewId() |
|
2068 |
values = dialog.GetValues() |
|
2069 |
values.setdefault("name", "") |
|
2070 |
block = FBD_Block(self, values["type"], values["name"], id, |
|
2071 |
values["extension"], values["inputs"], |
|
2072 |
executionControl = values["executionControl"], |
|
2073 |
executionOrder = values["executionOrder"]) |
|
2074 |
block.SetPosition(bbox.x, bbox.y) |
|
2075 |
block.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2076 |
self.AddBlock(block) |
|
2077 |
self.Controler.AddEditedElementBlock(self.TagName, id, values["type"], values.get("name", None)) |
|
2078 |
self.RefreshBlockModel(block) |
|
2079 |
self.RefreshBuffer() |
|
2080 |
self.RefreshScrollBars() |
|
2081 |
self.RefreshVisibleElements() |
|
2082 |
self.RefreshVariablePanel() |
|
2083 |
self.ParentWindow.RefreshPouInstanceVariablesPanel() |
|
2084 |
block.Refresh() |
|
2085 |
dialog.Destroy() |
|
2086 |
||
2087 |
def AddNewVariable(self, bbox): |
|
2088 |
words = self.TagName.split("::") |
|
2089 |
if words[0] == "T": |
|
2090 |
dialog = FBDVariableDialog(self.ParentWindow, self.Controler, words[2]) |
|
2091 |
else: |
|
2092 |
dialog = FBDVariableDialog(self.ParentWindow, self.Controler) |
|
2093 |
dialog.SetPreviewFont(self.GetFont()) |
|
2094 |
dialog.SetMinVariableSize((bbox.width, bbox.height)) |
|
2095 |
varlist = [] |
|
2096 |
vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
2097 |
if vars: |
|
2098 |
for var in vars: |
|
2099 |
if var["Edit"]: |
|
2100 |
varlist.append((var["Name"], var["Class"], var["Type"])) |
|
2101 |
returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
|
2102 |
if returntype: |
|
2103 |
varlist.append((self.Controler.GetEditedElementName(self.TagName), "Output", returntype)) |
|
2104 |
dialog.SetVariables(varlist) |
|
2105 |
if dialog.ShowModal() == wx.ID_OK: |
|
2106 |
id = self.GetNewId() |
|
2107 |
values = dialog.GetValues() |
|
2108 |
variable = FBD_Variable(self, values["type"], values["name"], values["value_type"], id) |
|
2109 |
variable.SetPosition(bbox.x, bbox.y) |
|
2110 |
variable.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2111 |
self.AddBlock(variable) |
|
2112 |
self.Controler.AddEditedElementVariable(self.TagName, id, values["type"]) |
|
2113 |
self.RefreshVariableModel(variable) |
|
2114 |
self.RefreshBuffer() |
|
2115 |
self.RefreshScrollBars() |
|
2116 |
self.RefreshVisibleElements() |
|
2117 |
variable.Refresh() |
|
2118 |
dialog.Destroy() |
|
2119 |
||
2120 |
def AddNewConnection(self, bbox): |
|
2121 |
dialog = ConnectionDialog(self.ParentWindow, self.Controler) |
|
2122 |
dialog.SetPreviewFont(self.GetFont()) |
|
2123 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
2124 |
dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug)) |
|
2125 |
dialog.SetMinConnectionSize((bbox.width, bbox.height)) |
|
2126 |
if dialog.ShowModal() == wx.ID_OK: |
|
2127 |
id = self.GetNewId() |
|
2128 |
values = dialog.GetValues() |
|
2129 |
connection = FBD_Connector(self, values["type"], values["name"], id) |
|
2130 |
connection.SetPosition(bbox.x, bbox.y) |
|
2131 |
connection.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2132 |
self.AddBlock(connection) |
|
2133 |
self.Controler.AddEditedElementConnection(self.TagName, id, values["type"]) |
|
2134 |
self.RefreshConnectionModel(connection) |
|
2135 |
self.RefreshBuffer() |
|
2136 |
self.RefreshScrollBars() |
|
2137 |
self.RefreshVisibleElements() |
|
2138 |
connection.Refresh() |
|
2139 |
dialog.Destroy() |
|
2140 |
||
2141 |
def AddNewComment(self, bbox): |
|
2142 |
if wx.VERSION >= (2, 5, 0): |
|
2143 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL|wx.TE_MULTILINE) |
|
2144 |
else: |
|
2145 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL) |
|
2146 |
dialog.SetClientSize(wx.Size(400, 200)) |
|
2147 |
if dialog.ShowModal() == wx.ID_OK: |
|
2148 |
value = dialog.GetValue() |
|
2149 |
id = self.GetNewId() |
|
2150 |
comment = Comment(self, value, id) |
|
2151 |
comment.SetPosition(bbox.x, bbox.y) |
|
2152 |
min_width, min_height = comment.GetMinSize() |
|
2153 |
comment.SetSize(*self.GetScaledSize(max(min_width,bbox.width),max(min_height,bbox.height))) |
|
2154 |
self.AddComment(comment) |
|
2155 |
self.Controler.AddEditedElementComment(self.TagName, id) |
|
2156 |
self.RefreshCommentModel(comment) |
|
2157 |
self.RefreshBuffer() |
|
2158 |
self.RefreshScrollBars() |
|
2159 |
self.RefreshVisibleElements() |
|
2160 |
comment.Refresh() |
|
2161 |
dialog.Destroy() |
|
2162 |
||
2163 |
def AddNewContact(self, bbox): |
|
2164 |
dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact") |
|
2165 |
dialog.SetPreviewFont(self.GetFont()) |
|
2166 |
varlist = [] |
|
2167 |
vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
2168 |
if vars: |
|
2169 |
for var in vars: |
|
2170 |
if var["Type"] == "BOOL": |
|
2171 |
varlist.append(var["Name"]) |
|
2172 |
dialog.SetVariables(varlist) |
|
2173 |
dialog.SetValues({"name":"","type":CONTACT_NORMAL}) |
|
2174 |
dialog.SetElementSize((bbox.width, bbox.height)) |
|
2175 |
if dialog.ShowModal() == wx.ID_OK: |
|
2176 |
id = self.GetNewId() |
|
2177 |
values = dialog.GetValues() |
|
2178 |
contact = LD_Contact(self, values["type"], values["name"], id) |
|
2179 |
contact.SetPosition(bbox.x, bbox.y) |
|
2180 |
contact.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2181 |
self.AddBlock(contact) |
|
2182 |
self.Controler.AddEditedElementContact(self.TagName, id) |
|
2183 |
self.RefreshContactModel(contact) |
|
2184 |
self.RefreshBuffer() |
|
2185 |
self.RefreshScrollBars() |
|
2186 |
self.RefreshVisibleElements() |
|
2187 |
contact.Refresh() |
|
2188 |
dialog.Destroy() |
|
2189 |
||
2190 |
def AddNewCoil(self, bbox): |
|
2191 |
dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil") |
|
2192 |
dialog.SetPreviewFont(self.GetFont()) |
|
2193 |
varlist = [] |
|
2194 |
vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
2195 |
if vars: |
|
2196 |
for var in vars: |
|
2197 |
if var["Class"] != "Input" and var["Type"] == "BOOL": |
|
2198 |
varlist.append(var["Name"]) |
|
2199 |
returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
|
2200 |
if returntype == "BOOL": |
|
2201 |
varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
|
2202 |
dialog.SetVariables(varlist) |
|
2203 |
dialog.SetValues({"name":"","type":COIL_NORMAL}) |
|
2204 |
dialog.SetElementSize((bbox.width, bbox.height)) |
|
2205 |
if dialog.ShowModal() == wx.ID_OK: |
|
2206 |
id = self.GetNewId() |
|
2207 |
values = dialog.GetValues() |
|
2208 |
coil = LD_Coil(self, values["type"], values["name"], id) |
|
2209 |
coil.SetPosition(bbox.x, bbox.y) |
|
2210 |
coil.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2211 |
self.AddBlock(coil) |
|
2212 |
self.Controler.AddEditedElementCoil(self.TagName, id) |
|
2213 |
self.RefreshCoilModel(coil) |
|
2214 |
self.RefreshBuffer() |
|
2215 |
self.RefreshScrollBars() |
|
2216 |
self.RefreshVisibleElements() |
|
2217 |
coil.Refresh() |
|
2218 |
dialog.Destroy() |
|
2219 |
||
2220 |
def AddNewPowerRail(self, bbox): |
|
2221 |
dialog = LDPowerRailDialog(self.ParentWindow, self.Controler) |
|
2222 |
dialog.SetPreviewFont(self.GetFont()) |
|
2223 |
dialog.SetMinSize((bbox.width, bbox.height)) |
|
2224 |
if dialog.ShowModal() == wx.ID_OK: |
|
2225 |
id = self.GetNewId() |
|
2226 |
values = dialog.GetValues() |
|
2227 |
powerrail = LD_PowerRail(self, values["type"], id, values["number"]) |
|
2228 |
powerrail.SetPosition(bbox.x, bbox.y) |
|
2229 |
powerrail.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2230 |
self.AddBlock(powerrail) |
|
2231 |
self.Controler.AddEditedElementPowerRail(self.TagName, id, values["type"]) |
|
2232 |
self.RefreshPowerRailModel(powerrail) |
|
2233 |
self.RefreshBuffer() |
|
2234 |
self.RefreshScrollBars() |
|
2235 |
self.RefreshVisibleElements() |
|
2236 |
powerrail.Refresh() |
|
2237 |
dialog.Destroy() |
|
2238 |
||
2239 |
def AddNewStep(self, bbox, initial = False): |
|
2240 |
dialog = SFCStepDialog(self.ParentWindow, self.Controler, initial) |
|
2241 |
dialog.SetPreviewFont(self.GetFont()) |
|
2242 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
2243 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)) |
|
2244 |
dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step)]) |
|
2245 |
dialog.SetMinStepSize((bbox.width, bbox.height)) |
|
2246 |
if dialog.ShowModal() == wx.ID_OK: |
|
2247 |
id = self.GetNewId() |
|
2248 |
values = dialog.GetValues() |
|
2249 |
step = SFC_Step(self, values["name"], initial, id) |
|
2250 |
if values["input"]: |
|
2251 |
step.AddInput() |
|
2252 |
else: |
|
2253 |
step.RemoveInput() |
|
2254 |
if values["output"]: |
|
2255 |
step.AddOutput() |
|
2256 |
else: |
|
2257 |
step.RemoveOutput() |
|
2258 |
if values["action"]: |
|
2259 |
step.AddAction() |
|
2260 |
else: |
|
2261 |
step.RemoveAction() |
|
2262 |
step.SetPosition(bbox.x, bbox.y) |
|
2263 |
min_width, min_height = step.GetMinSize() |
|
2264 |
step.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height))) |
|
2265 |
self.AddBlock(step) |
|
2266 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
2267 |
self.RefreshStepModel(step) |
|
2268 |
self.RefreshBuffer() |
|
2269 |
self.RefreshScrollBars() |
|
2270 |
self.RefreshVisibleElements() |
|
2271 |
step.Refresh() |
|
2272 |
dialog.Destroy() |
|
2273 |
||
2274 |
def AddNewTransition(self, bbox): |
|
2275 |
dialog = SFCTransitionDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE) |
|
2276 |
dialog.SetPreviewFont(self.GetFont()) |
|
2277 |
dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug)) |
|
2278 |
if dialog.ShowModal() == wx.ID_OK: |
|
2279 |
id = self.GetNewId() |
|
2280 |
values = dialog.GetValues() |
|
2281 |
transition = SFC_Transition(self, values["type"], values["value"], values["priority"], id) |
|
2282 |
transition.SetPosition(bbox.x, bbox.y) |
|
2283 |
min_width, min_height = transition.GetMinSize() |
|
2284 |
transition.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height))) |
|
2285 |
self.AddBlock(transition) |
|
2286 |
self.Controler.AddEditedElementTransition(self.TagName, id) |
|
2287 |
self.RefreshTransitionModel(transition) |
|
2288 |
self.RefreshBuffer() |
|
2289 |
self.RefreshScrollBars() |
|
2290 |
self.RefreshVisibleElements() |
|
2291 |
transition.Refresh() |
|
2292 |
dialog.Destroy() |
|
2293 |
||
2294 |
def AddNewDivergence(self, bbox): |
|
2295 |
dialog = SFCDivergenceDialog(self.ParentWindow, self.Controler) |
|
2296 |
dialog.SetPreviewFont(self.GetFont()) |
|
2297 |
dialog.SetMinSize((bbox.width, bbox.height)) |
|
2298 |
if dialog.ShowModal() == wx.ID_OK: |
|
2299 |
id = self.GetNewId() |
|
2300 |
values = dialog.GetValues() |
|
2301 |
divergence = SFC_Divergence(self, values["type"], values["number"], id) |
|
2302 |
divergence.SetPosition(bbox.x, bbox.y) |
|
2303 |
min_width, min_height = divergence.GetMinSize(True) |
|
2304 |
divergence.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height))) |
|
2305 |
self.AddBlock(divergence) |
|
2306 |
self.Controler.AddEditedElementDivergence(self.TagName, id, values["type"]) |
|
2307 |
self.RefreshDivergenceModel(divergence) |
|
2308 |
self.RefreshBuffer() |
|
2309 |
self.RefreshScrollBars() |
|
2310 |
self.RefreshVisibleElements() |
|
2311 |
divergence.Refresh() |
|
2312 |
dialog.Destroy() |
|
2313 |
||
2314 |
def AddNewJump(self, bbox): |
|
2315 |
choices = [] |
|
2316 |
for block in self.Blocks.itervalues(): |
|
2317 |
if isinstance(block, SFC_Step): |
|
2318 |
choices.append(block.GetName()) |
|
2319 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, |
|
2320 |
_("Add a new jump"), _("Please choose a target"), |
|
2321 |
choices, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
|
2322 |
if dialog.ShowModal() == wx.ID_OK: |
|
2323 |
id = self.GetNewId() |
|
2324 |
value = dialog.GetStringSelection() |
|
2325 |
jump = SFC_Jump(self, value, id) |
|
2326 |
jump.SetPosition(bbox.x, bbox.y) |
|
2327 |
min_width, min_height = jump.GetMinSize() |
|
2328 |
jump.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height))) |
|
2329 |
self.AddBlock(jump) |
|
2330 |
self.Controler.AddEditedElementJump(self.TagName, id) |
|
2331 |
self.RefreshJumpModel(jump) |
|
2332 |
self.RefreshBuffer() |
|
2333 |
self.RefreshScrollBars() |
|
2334 |
self.RefreshVisibleElements() |
|
2335 |
jump.Refresh() |
|
2336 |
dialog.Destroy() |
|
2337 |
||
2338 |
def AddNewActionBlock(self, bbox): |
|
2339 |
dialog = ActionBlockDialog(self.ParentWindow) |
|
2340 |
dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
|
2341 |
dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug)) |
|
2342 |
dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)) |
|
2343 |
if dialog.ShowModal() == wx.ID_OK: |
|
2344 |
actions = dialog.GetValues() |
|
2345 |
id = self.GetNewId() |
|
2346 |
actionblock = SFC_ActionBlock(self, actions, id) |
|
2347 |
actionblock.SetPosition(bbox.x, bbox.y) |
|
2348 |
min_width, min_height = actionblock.GetMinSize() |
|
2349 |
actionblock.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height))) |
|
2350 |
self.AddBlock(actionblock) |
|
2351 |
self.Controler.AddEditedElementActionBlock(self.TagName, id) |
|
2352 |
self.RefreshActionBlockModel(actionblock) |
|
2353 |
self.RefreshBuffer() |
|
2354 |
self.RefreshScrollBars() |
|
2355 |
self.RefreshVisibleElements() |
|
2356 |
actionblock.Refresh() |
|
2357 |
dialog.Destroy() |
|
2358 |
||
2359 |
#------------------------------------------------------------------------------- |
|
2360 |
# Edit element content functions |
|
2361 |
#------------------------------------------------------------------------------- |
|
2362 |
||
2363 |
def EditBlockContent(self, block): |
|
2364 |
dialog = FBDBlockDialog(self.ParentWindow, self.Controler) |
|
2365 |
dialog.SetPreviewFont(self.GetFont()) |
|
2366 |
dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug)) |
|
2367 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
2368 |
variable_names = self.Controler.GetEditedElementVariables(self.TagName, self.Debug) |
|
2369 |
if block.GetName() != "": |
|
2370 |
variable_names.remove(block.GetName()) |
|
2371 |
dialog.SetPouElementNames(variable_names) |
|
2372 |
dialog.SetMinBlockSize(block.GetSize()) |
|
2373 |
old_values = {"name" : block.GetName(), |
|
2374 |
"type" : block.GetType(), |
|
2375 |
"extension" : block.GetExtension(), |
|
2376 |
"inputs" : block.GetInputTypes(), |
|
2377 |
"executionControl" : block.GetExecutionControl(), |
|
2378 |
"executionOrder" : block.GetExecutionOrder()} |
|
2379 |
dialog.SetValues(old_values) |
|
2380 |
if dialog.ShowModal() == wx.ID_OK: |
|
2381 |
new_values = dialog.GetValues() |
|
2382 |
rect = block.GetRedrawRect(1, 1) |
|
2383 |
if "name" in new_values: |
|
2384 |
block.SetName(new_values["name"]) |
|
2385 |
else: |
|
2386 |
block.SetName("") |
|
2387 |
block.SetSize(*self.GetScaledSize(new_values["width"], new_values["height"])) |
|
2388 |
block.SetType(new_values["type"], new_values["extension"], executionControl = new_values["executionControl"]) |
|
2389 |
block.SetExecutionOrder(new_values["executionOrder"]) |
|
2390 |
rect = rect.Union(block.GetRedrawRect()) |
|
2391 |
self.RefreshBlockModel(block) |
|
2392 |
self.RefreshBuffer() |
|
2393 |
if old_values["executionOrder"] != new_values["executionOrder"]: |
|
2394 |
self.RefreshView(selection=({block.GetId(): True}, {})) |
|
2395 |
else: |
|
2396 |
self.RefreshScrollBars() |
|
2397 |
self.RefreshVisibleElements() |
|
2398 |
block.Refresh(rect) |
|
2399 |
self.RefreshVariablePanel() |
|
2400 |
self.ParentWindow.RefreshPouInstanceVariablesPanel() |
|
2401 |
dialog.Destroy() |
|
2402 |
||
2403 |
def EditVariableContent(self, variable): |
|
2404 |
words = self.TagName.split("::") |
|
2405 |
if words[0] == "T": |
|
2406 |
dialog = FBDVariableDialog(self.ParentWindow, self.Controler, words[2]) |
|
2407 |
else: |
|
2408 |
dialog = FBDVariableDialog(self.ParentWindow, self.Controler) |
|
2409 |
dialog.SetPreviewFont(self.GetFont()) |
|
2410 |
dialog.SetMinVariableSize(variable.GetSize()) |
|
2411 |
varlist = [] |
|
2412 |
vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
2413 |
if vars: |
|
2414 |
for var in vars: |
|
2415 |
if var["Edit"]: |
|
2416 |
varlist.append((var["Name"], var["Class"], var["Type"])) |
|
2417 |
returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
|
2418 |
if returntype: |
|
2419 |
varlist.append((self.Controler.GetEditedElementName(self.TagName), "Output", returntype)) |
|
2420 |
dialog.SetVariables(varlist) |
|
2421 |
old_values = {"name" : variable.GetName(), "type" : variable.GetType(), |
|
2422 |
"executionOrder" : variable.GetExecutionOrder()} |
|
2423 |
dialog.SetValues(old_values) |
|
2424 |
if dialog.ShowModal() == wx.ID_OK: |
|
2425 |
new_values = dialog.GetValues() |
|
2426 |
rect = variable.GetRedrawRect(1, 1) |
|
2427 |
variable.SetName(new_values["name"]) |
|
2428 |
variable.SetType(new_values["type"], new_values["value_type"]) |
|
2429 |
variable.SetSize(*self.GetScaledSize(new_values["width"], new_values["height"])) |
|
2430 |
variable.SetExecutionOrder(new_values["executionOrder"]) |
|
2431 |
rect = rect.Union(variable.GetRedrawRect()) |
|
2432 |
if old_values["type"] != new_values["type"]: |
|
2433 |
id = variable.GetId() |
|
2434 |
self.Controler.RemoveEditedElementInstance(self.TagName, id) |
|
2435 |
self.Controler.AddEditedElementVariable(self.TagName, id, new_values["type"]) |
|
2436 |
self.RefreshVariableModel(variable) |
|
2437 |
self.RefreshBuffer() |
|
2438 |
if old_values["executionOrder"] != new_values["executionOrder"]: |
|
2439 |
self.RefreshView(selection=({variable.GetId(): True}, {})) |
|
2440 |
else: |
|
2441 |
self.RefreshVisibleElements() |
|
2442 |
self.RefreshScrollBars() |
|
2443 |
variable.Refresh(rect) |
|
2444 |
dialog.Destroy() |
|
2445 |
||
2446 |
def EditConnectionContent(self, connection): |
|
2447 |
dialog = ConnectionDialog(self.ParentWindow, self.Controler) |
|
2448 |
dialog.SetPreviewFont(self.GetFont()) |
|
2449 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
2450 |
dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug)) |
|
2451 |
dialog.SetMinConnectionSize(connection.GetSize()) |
|
2452 |
values = {"name" : connection.GetName(), "type" : connection.GetType()} |
|
2453 |
dialog.SetValues(values) |
|
2454 |
if dialog.ShowModal() == wx.ID_OK: |
|
2455 |
old_type = connection.GetType() |
|
2456 |
old_name = connection.GetName() |
|
2457 |
values = dialog.GetValues() |
|
2458 |
rect = connection.GetRedrawRect(1, 1) |
|
2459 |
connection.SetName(values["name"]) |
|
2460 |
connection.SetType(values["type"]) |
|
2461 |
connection.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2462 |
rect = rect.Union(connection.GetRedrawRect()) |
|
2463 |
if old_type != values["type"]: |
|
2464 |
id = connection.GetId() |
|
2465 |
self.Controler.RemoveEditedElementInstance(self.TagName, id) |
|
2466 |
self.Controler.AddEditedElementConnection(self.TagName, id, values["type"]) |
|
2467 |
self.RefreshConnectionModel(connection) |
|
2468 |
self.RefreshBuffer() |
|
2469 |
if old_name != values["name"]: |
|
2470 |
self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_name, values["name"]) |
|
2471 |
self.RefreshView(selection=({connection.GetId(): True}, {})) |
|
2472 |
else: |
|
2473 |
self.RefreshScrollBars() |
|
2474 |
self.RefreshVisibleElements() |
|
2475 |
connection.Refresh(rect) |
|
2476 |
dialog.Destroy() |
|
2477 |
||
2478 |
def EditContactContent(self, contact): |
|
2479 |
dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact") |
|
2480 |
dialog.SetPreviewFont(self.GetFont()) |
|
2481 |
varlist = [] |
|
2482 |
vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
2483 |
if vars: |
|
2484 |
for var in vars: |
|
2485 |
if var["Type"] == "BOOL": |
|
2486 |
varlist.append(var["Name"]) |
|
2487 |
dialog.SetVariables(varlist) |
|
2488 |
values = {"name" : contact.GetName(), "type" : contact.GetType()} |
|
2489 |
dialog.SetValues(values) |
|
2490 |
dialog.SetElementSize(contact.GetSize()) |
|
2491 |
if dialog.ShowModal() == wx.ID_OK: |
|
2492 |
values = dialog.GetValues() |
|
2493 |
rect = contact.GetRedrawRect(1, 1) |
|
2494 |
contact.SetName(values["name"]) |
|
2495 |
contact.SetType(values["type"]) |
|
2496 |
contact.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2497 |
rect = rect.Union(contact.GetRedrawRect()) |
|
2498 |
self.RefreshContactModel(contact) |
|
2499 |
self.RefreshBuffer() |
|
2500 |
self.RefreshScrollBars() |
|
2501 |
self.RefreshVisibleElements() |
|
2502 |
contact.Refresh(rect) |
|
2503 |
dialog.Destroy() |
|
2504 |
||
2505 |
def EditCoilContent(self, coil): |
|
2506 |
dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil") |
|
2507 |
dialog.SetPreviewFont(self.GetFont()) |
|
2508 |
varlist = [] |
|
2509 |
vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug) |
|
2510 |
if vars: |
|
2511 |
for var in vars: |
|
2512 |
if var["Class"] != "Input" and var["Type"] == "BOOL": |
|
2513 |
varlist.append(var["Name"]) |
|
2514 |
returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug) |
|
2515 |
if returntype == "BOOL": |
|
2516 |
varlist.append(self.Controler.GetEditedElementName(self.TagName)) |
|
2517 |
dialog.SetVariables(varlist) |
|
2518 |
values = {"name" : coil.GetName(), "type" : coil.GetType()} |
|
2519 |
dialog.SetValues(values) |
|
2520 |
dialog.SetElementSize(coil.GetSize()) |
|
2521 |
if dialog.ShowModal() == wx.ID_OK: |
|
2522 |
values = dialog.GetValues() |
|
2523 |
rect = coil.GetRedrawRect(1, 1) |
|
2524 |
coil.SetName(values["name"]) |
|
2525 |
coil.SetType(values["type"]) |
|
2526 |
coil.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2527 |
rect = rect.Union(coil.GetRedrawRect()) |
|
2528 |
self.RefreshCoilModel(coil) |
|
2529 |
self.RefreshBuffer() |
|
2530 |
self.RefreshScrollBars() |
|
2531 |
self.RefreshVisibleElements() |
|
2532 |
coil.Refresh(rect) |
|
2533 |
dialog.Destroy() |
|
2534 |
||
2535 |
def EditPowerRailContent(self, powerrail): |
|
2536 |
connectors = powerrail.GetConnectors() |
|
2537 |
type = powerrail.GetType() |
|
2538 |
if type == LEFTRAIL: |
|
2539 |
pin_number = len(connectors["outputs"]) |
|
2540 |
else: |
|
2541 |
pin_number = len(connectors["inputs"]) |
|
2542 |
dialog = LDPowerRailDialog(self.ParentWindow, self.Controler, type, pin_number) |
|
2543 |
dialog.SetPreviewFont(self.GetFont()) |
|
2544 |
dialog.SetMinSize(powerrail.GetSize()) |
|
2545 |
if dialog.ShowModal() == wx.ID_OK: |
|
2546 |
old_type = powerrail.GetType() |
|
2547 |
values = dialog.GetValues() |
|
2548 |
rect = powerrail.GetRedrawRect(1, 1) |
|
2549 |
powerrail.SetType(values["type"], values["number"]) |
|
2550 |
powerrail.SetSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2551 |
rect = rect.Union(powerrail.GetRedrawRect()) |
|
2552 |
if old_type != values["type"]: |
|
2553 |
id = powerrail.GetId() |
|
2554 |
self.Controler.RemoveEditedElementInstance(self.TagName, id) |
|
2555 |
self.Controler.AddEditedElementPowerRail(self.TagName, id, values["type"]) |
|
2556 |
self.RefreshPowerRailModel(powerrail) |
|
2557 |
self.RefreshBuffer() |
|
2558 |
self.RefreshScrollBars() |
|
2559 |
self.RefreshVisibleElements() |
|
2560 |
powerrail.Refresh(rect) |
|
2561 |
dialog.Destroy() |
|
2562 |
||
2563 |
def EditStepContent(self, step): |
|
2564 |
dialog = SFCStepDialog(self.ParentWindow, self.Controler, step.GetInitial()) |
|
2565 |
dialog.SetPreviewFont(self.GetFont()) |
|
2566 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
2567 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)) |
|
2568 |
dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
|
2569 |
dialog.SetMinStepSize(step.GetSize()) |
|
2570 |
values = {"name" : step.GetName()} |
|
2571 |
connectors = step.GetConnectors() |
|
2572 |
values["input"] = len(connectors["inputs"]) > 0 |
|
2573 |
values["output"] = len(connectors["outputs"]) > 0 |
|
2574 |
values["action"] = step.GetActionConnector() != None |
|
2575 |
dialog.SetValues(values) |
|
2576 |
if dialog.ShowModal() == wx.ID_OK: |
|
2577 |
values = dialog.GetValues() |
|
2578 |
rect = step.GetRedrawRect(1, 1) |
|
2579 |
step.SetName(values["name"]) |
|
2580 |
if values["input"]: |
|
2581 |
step.AddInput() |
|
2582 |
else: |
|
2583 |
step.RemoveInput() |
|
2584 |
if values["output"]: |
|
2585 |
step.AddOutput() |
|
2586 |
else: |
|
2587 |
step.RemoveOutput() |
|
2588 |
if values["action"]: |
|
2589 |
step.AddAction() |
|
2590 |
else: |
|
2591 |
step.RemoveAction() |
|
2592 |
step.UpdateSize(*self.GetScaledSize(values["width"], values["height"])) |
|
2593 |
rect = rect.Union(step.GetRedrawRect()) |
|
2594 |
self.RefreshStepModel(step) |
|
2595 |
self.RefreshBuffer() |
|
2596 |
self.RefreshScrollBars() |
|
2597 |
self.RefreshVisibleElements() |
|
2598 |
step.Refresh(rect) |
|
2599 |
||
2600 |
def EditTransitionContent(self, transition): |
|
2601 |
dialog = SFCTransitionDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE) |
|
2602 |
dialog.SetPreviewFont(self.GetFont()) |
|
2603 |
dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug)) |
|
2604 |
dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()}) |
|
2605 |
dialog.SetElementSize(transition.GetSize()) |
|
2606 |
if dialog.ShowModal() == wx.ID_OK: |
|
2607 |
values = dialog.GetValues() |
|
2608 |
rect = transition.GetRedrawRect(1, 1) |
|
2609 |
transition.SetType(values["type"],values["value"]) |
|
2610 |
transition.SetPriority(values["priority"]) |
|
2611 |
rect = rect.Union(transition.GetRedrawRect()) |
|
2612 |
self.RefreshTransitionModel(transition) |
|
2613 |
self.RefreshBuffer() |
|
2614 |
self.RefreshScrollBars() |
|
2615 |
self.RefreshVisibleElements() |
|
2616 |
transition.Refresh(rect) |
|
2617 |
dialog.Destroy() |
|
2618 |
||
2619 |
def EditJumpContent(self, jump): |
|
2620 |
choices = [] |
|
2621 |
for block in self.Blocks.itervalues(): |
|
2622 |
if isinstance(block, SFC_Step): |
|
2623 |
choices.append(block.GetName()) |
|
2624 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, |
|
2625 |
_("Edit jump target"), _("Please choose a target"), |
|
2626 |
choices, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
|
2627 |
dialog.SetSelection(choices.index(jump.GetTarget())) |
|
2628 |
if dialog.ShowModal() == wx.ID_OK: |
|
2629 |
value = dialog.GetStringSelection() |
|
2630 |
rect = jump.GetRedrawRect(1, 1) |
|
2631 |
jump.SetTarget(value) |
|
2632 |
rect = rect.Union(jump.GetRedrawRect()) |
|
2633 |
self.RefreshJumpModel(jump) |
|
2634 |
self.RefreshBuffer() |
|
2635 |
self.RefreshScrollBars() |
|
2636 |
self.RefreshVisibleElements() |
|
2637 |
jump.Refresh(rect) |
|
2638 |
dialog.Destroy() |
|
2639 |
||
2640 |
def EditActionBlockContent(self, actionblock): |
|
2641 |
dialog = ActionBlockDialog(self.ParentWindow) |
|
2642 |
dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
|
2643 |
dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug)) |
|
2644 |
dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)) |
|
2645 |
dialog.SetValues(actionblock.GetActions()) |
|
2646 |
if dialog.ShowModal() == wx.ID_OK: |
|
2647 |
actions = dialog.GetValues() |
|
2648 |
rect = actionblock.GetRedrawRect(1, 1) |
|
2649 |
actionblock.SetActions(actions) |
|
2650 |
actionblock.SetSize(*self.GetScaledSize(*actionblock.GetSize())) |
|
2651 |
rect = rect.Union(actionblock.GetRedrawRect()) |
|
2652 |
self.RefreshActionBlockModel(actionblock) |
|
2653 |
self.RefreshBuffer() |
|
2654 |
self.RefreshScrollBars() |
|
2655 |
self.RefreshVisibleElements() |
|
2656 |
actionblock.Refresh(rect) |
|
2657 |
dialog.Destroy() |
|
2658 |
||
2659 |
def EditCommentContent(self, comment): |
|
2660 |
if wx.VERSION >= (2, 5, 0): |
|
2661 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE) |
|
2662 |
else: |
|
2663 |
dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL) |
|
2664 |
dialog.SetClientSize(wx.Size(400, 200)) |
|
2665 |
if dialog.ShowModal() == wx.ID_OK: |
|
2666 |
value = dialog.GetValue() |
|
2667 |
rect = comment.GetRedrawRect(1, 1) |
|
2668 |
comment.SetContent(value) |
|
2669 |
comment.SetSize(*self.GetScaledSize(*comment.GetSize())) |
|
2670 |
rect = rect.Union(comment.GetRedrawRect()) |
|
2671 |
self.RefreshCommentModel(comment) |
|
2672 |
self.RefreshBuffer() |
|
2673 |
self.RefreshScrollBars() |
|
2674 |
self.RefreshVisibleElements() |
|
2675 |
comment.Refresh(rect) |
|
2676 |
dialog.Destroy() |
|
2677 |
||
2678 |
#------------------------------------------------------------------------------- |
|
2679 |
# Model update functions |
|
2680 |
#------------------------------------------------------------------------------- |
|
2681 |
||
2682 |
def RefreshBlockModel(self, block): |
|
2683 |
blockid = block.GetId() |
|
2684 |
infos = {} |
|
2685 |
infos["type"] = block.GetType() |
|
2686 |
infos["name"] = block.GetName() |
|
2687 |
if self.CurrentLanguage == "FBD": |
|
2688 |
infos["executionOrder"] = block.GetExecutionOrder() |
|
2689 |
infos["x"], infos["y"] = block.GetPosition() |
|
2690 |
infos["width"], infos["height"] = block.GetSize() |
|
2691 |
infos["connectors"] = block.GetConnectors() |
|
2692 |
self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos) |
|
2693 |
||
2694 |
def RefreshVariableModel(self, variable): |
|
2695 |
variableid = variable.GetId() |
|
2696 |
infos = {} |
|
2697 |
infos["name"] = variable.GetName() |
|
2698 |
if self.CurrentLanguage == "FBD": |
|
2699 |
infos["executionOrder"] = variable.GetExecutionOrder() |
|
2700 |
infos["x"], infos["y"] = variable.GetPosition() |
|
2701 |
infos["width"], infos["height"] = variable.GetSize() |
|
2702 |
infos["connectors"] = variable.GetConnectors() |
|
2703 |
self.Controler.SetEditedElementVariableInfos(self.TagName, variableid, infos) |
|
2704 |
||
2705 |
def RefreshConnectionModel(self, connection): |
|
2706 |
connectionid = connection.GetId() |
|
2707 |
infos = {} |
|
2708 |
infos["name"] = connection.GetName() |
|
2709 |
infos["x"], infos["y"] = connection.GetPosition() |
|
2710 |
infos["width"], infos["height"] = connection.GetSize() |
|
2711 |
infos["connector"] = connection.GetConnector() |
|
2712 |
self.Controler.SetEditedElementConnectionInfos(self.TagName, connectionid, infos) |
|
2713 |
||
2714 |
def RefreshCommentModel(self, comment): |
|
2715 |
commentid = comment.GetId() |
|
2716 |
infos = {} |
|
2717 |
infos["content"] = comment.GetContent() |
|
2718 |
infos["x"], infos["y"] = comment.GetPosition() |
|
2719 |
infos["width"], infos["height"] = comment.GetSize() |
|
2720 |
self.Controler.SetEditedElementCommentInfos(self.TagName, commentid, infos) |
|
2721 |
||
2722 |
def RefreshPowerRailModel(self, powerrail): |
|
2723 |
powerrailid = powerrail.GetId() |
|
2724 |
infos = {} |
|
2725 |
infos["x"], infos["y"] = powerrail.GetPosition() |
|
2726 |
infos["width"], infos["height"] = powerrail.GetSize() |
|
2727 |
infos["connectors"] = powerrail.GetConnectors() |
|
2728 |
self.Controler.SetEditedElementPowerRailInfos(self.TagName, powerrailid, infos) |
|
2729 |
||
2730 |
def RefreshContactModel(self, contact): |
|
2731 |
contactid = contact.GetId() |
|
2732 |
infos = {} |
|
2733 |
infos["name"] = contact.GetName() |
|
2734 |
infos["type"] = contact.GetType() |
|
2735 |
infos["x"], infos["y"] = contact.GetPosition() |
|
2736 |
infos["width"], infos["height"] = contact.GetSize() |
|
2737 |
infos["connectors"] = contact.GetConnectors() |
|
2738 |
self.Controler.SetEditedElementContactInfos(self.TagName, contactid, infos) |
|
2739 |
||
2740 |
def RefreshCoilModel(self, coil): |
|
2741 |
coilid = coil.GetId() |
|
2742 |
infos = {} |
|
2743 |
infos["name"] = coil.GetName() |
|
2744 |
infos["type"] = coil.GetType() |
|
2745 |
infos["x"], infos["y"] = coil.GetPosition() |
|
2746 |
infos["width"], infos["height"] = coil.GetSize() |
|
2747 |
infos["connectors"] = coil.GetConnectors() |
|
2748 |
self.Controler.SetEditedElementCoilInfos(self.TagName, coilid, infos) |
|
2749 |
||
2750 |
def RefreshStepModel(self, step): |
|
2751 |
stepid = step.GetId() |
|
2752 |
infos = {} |
|
2753 |
infos["name"] = step.GetName() |
|
2754 |
infos["initial"] = step.GetInitial() |
|
2755 |
infos["x"], infos["y"] = step.GetPosition() |
|
2756 |
infos["width"], infos["height"] = step.GetSize() |
|
2757 |
infos["connectors"] = step.GetConnectors() |
|
2758 |
infos["action"] = step.GetActionConnector() |
|
2759 |
self.Controler.SetEditedElementStepInfos(self.TagName, stepid, infos) |
|
2760 |
||
2761 |
def RefreshTransitionModel(self, transition): |
|
2762 |
transitionid = transition.GetId() |
|
2763 |
infos = {} |
|
2764 |
infos["type"] = transition.GetType() |
|
2765 |
infos["priority"] = transition.GetPriority() |
|
2766 |
infos["condition"] = transition.GetCondition() |
|
2767 |
infos["x"], infos["y"] = transition.GetPosition() |
|
2768 |
infos["width"], infos["height"] = transition.GetSize() |
|
2769 |
infos["connectors"] = transition.GetConnectors() |
|
2770 |
infos["connection"] = transition.GetConditionConnector() |
|
2771 |
self.Controler.SetEditedElementTransitionInfos(self.TagName, transitionid, infos) |
|
2772 |
||
2773 |
def RefreshDivergenceModel(self, divergence): |
|
2774 |
divergenceid = divergence.GetId() |
|
2775 |
infos = {} |
|
2776 |
infos["x"], infos["y"] = divergence.GetPosition() |
|
2777 |
infos["width"], infos["height"] = divergence.GetSize() |
|
2778 |
infos["connectors"] = divergence.GetConnectors() |
|
2779 |
self.Controler.SetEditedElementDivergenceInfos(self.TagName, divergenceid, infos) |
|
2780 |
||
2781 |
def RefreshJumpModel(self, jump): |
|
2782 |
jumpid = jump.GetId() |
|
2783 |
infos = {} |
|
2784 |
infos["target"] = jump.GetTarget() |
|
2785 |
infos["x"], infos["y"] = jump.GetPosition() |
|
2786 |
infos["width"], infos["height"] = jump.GetSize() |
|
2787 |
infos["connector"] = jump.GetConnector() |
|
2788 |
self.Controler.SetEditedElementJumpInfos(self.TagName, jumpid, infos) |
|
2789 |
||
2790 |
def RefreshActionBlockModel(self, actionblock): |
|
2791 |
actionblockid = actionblock.GetId() |
|
2792 |
infos = {} |
|
2793 |
infos["actions"] = actionblock.GetActions() |
|
2794 |
infos["x"], infos["y"] = actionblock.GetPosition() |
|
2795 |
infos["width"], infos["height"] = actionblock.GetSize() |
|
2796 |
infos["connector"] = actionblock.GetConnector() |
|
2797 |
self.Controler.SetEditedElementActionBlockInfos(self.TagName, actionblockid, infos) |
|
2798 |
||
2799 |
||
2800 |
#------------------------------------------------------------------------------- |
|
2801 |
# Model delete functions |
|
2802 |
#------------------------------------------------------------------------------- |
|
2803 |
||
2804 |
||
2805 |
def DeleteBlock(self, block): |
|
2806 |
elements = [] |
|
2807 |
for output in block.GetConnectors()["outputs"]: |
|
2808 |
for element in output.GetConnectedBlocks(): |
|
2809 |
if element not in elements: |
|
2810 |
elements.append(element) |
|
2811 |
block.Clean() |
|
2812 |
self.RemoveBlock(block) |
|
2813 |
self.Controler.RemoveEditedElementInstance(self.TagName, block.GetId()) |
|
2814 |
for element in elements: |
|
2815 |
element.RefreshModel() |
|
2816 |
wx.CallAfter(self.RefreshVariablePanel) |
|
2817 |
wx.CallAfter(self.ParentWindow.RefreshPouInstanceVariablesPanel) |
|
2818 |
||
2819 |
def DeleteVariable(self, variable): |
|
2820 |
connectors = variable.GetConnectors() |
|
2821 |
if len(connectors["outputs"]) > 0: |
|
2822 |
elements = connectors["outputs"][0].GetConnectedBlocks() |
|
2823 |
else: |
|
2824 |
elements = [] |
|
2825 |
variable.Clean() |
|
2826 |
self.RemoveBlock(variable) |
|
2827 |
self.Controler.RemoveEditedElementInstance(self.TagName, variable.GetId()) |
|
2828 |
for element in elements: |
|
2829 |
element.RefreshModel() |
|
2830 |
||
2831 |
def DeleteConnection(self, connection): |
|
2832 |
if connection.GetType() == CONTINUATION: |
|
2833 |
elements = connection.GetConnector().GetConnectedBlocks() |
|
2834 |
else: |
|
2835 |
elements = [] |
|
2836 |
connection.Clean() |
|
2837 |
self.RemoveBlock(connection) |
|
2838 |
self.Controler.RemoveEditedElementInstance(self.TagName, connection.GetId()) |
|
2839 |
for element in elements: |
|
2840 |
element.RefreshModel() |
|
2841 |
||
2842 |
def DeleteComment(self, comment): |
|
2843 |
self.RemoveComment(comment) |
|
2844 |
self.Controler.RemoveEditedElementInstance(self.TagName, comment.GetId()) |
|
2845 |
||
2846 |
def DeleteWire(self, wire): |
|
2847 |
if wire in self.Wires: |
|
2848 |
connected = wire.GetConnected() |
|
2849 |
wire.Clean() |
|
2850 |
self.RemoveWire(wire) |
|
2851 |
for connector in connected: |
|
2852 |
connector.RefreshParentBlock() |
|
2853 |
||
2854 |
def DeleteContact(self, contact): |
|
2855 |
connectors = contact.GetConnectors() |
|
2856 |
elements = connectors["outputs"][0].GetConnectedBlocks() |
|
2857 |
contact.Clean() |
|
2858 |
self.RemoveBlock(contact) |
|
2859 |
self.Controler.RemoveEditedElementInstance(self.TagName, contact.GetId()) |
|
2860 |
for element in elements: |
|
2861 |
element.RefreshModel() |
|
2862 |
||
2863 |
def DeleteCoil(self, coil): |
|
2864 |
connectors = coil.GetConnectors() |
|
2865 |
elements = connectors["outputs"][0].GetConnectedBlocks() |
|
2866 |
coil.Clean() |
|
2867 |
self.RemoveBlock(coil) |
|
2868 |
self.Controler.RemoveEditedElementInstance(self.TagName, coil.GetId()) |
|
2869 |
for element in elements: |
|
2870 |
element.RefreshModel() |
|
2871 |
||
2872 |
def DeletePowerRail(self, powerrail): |
|
2873 |
elements = [] |
|
2874 |
if powerrail.GetType() == LEFTRAIL: |
|
2875 |
connectors = powerrail.GetConnectors() |
|
2876 |
for connector in connectors["outputs"]: |
|
2877 |
for element in connector.GetConnectedBlocks(): |
|
2878 |
if element not in elements: |
|
2879 |
elements.append(element) |
|
2880 |
powerrail.Clean() |
|
2881 |
self.RemoveBlock(powerrail) |
|
2882 |
self.Controler.RemoveEditedElementInstance(self.TagName, powerrail.GetId()) |
|
2883 |
for element in elements: |
|
2884 |
element.RefreshModel() |
|
2885 |
||
2886 |
def DeleteStep(self, step): |
|
2887 |
elements = [] |
|
2888 |
connectors = step.GetConnectors() |
|
2889 |
action_connector = step.GetActionConnector() |
|
2890 |
if len(connectors["outputs"]) > 0: |
|
2891 |
for element in connectors["outputs"][0].GetConnectedBlocks(): |
|
2892 |
if element not in elements: |
|
2893 |
elements.append(element) |
|
2894 |
if action_connector is not None: |
|
2895 |
for element in action_connector.GetConnectedBlocks(): |
|
2896 |
if element not in elements: |
|
2897 |
elements.append(element) |
|
2898 |
step.Clean() |
|
2899 |
self.RemoveBlock(step) |
|
2900 |
self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId()) |
|
2901 |
for element in elements: |
|
2902 |
element.RefreshModel() |
|
2903 |
||
2904 |
def DeleteTransition(self, transition): |
|
2905 |
elements = [] |
|
2906 |
connectors = transition.GetConnectors() |
|
2907 |
for element in connectors["outputs"][0].GetConnectedBlocks(): |
|
2908 |
if element not in elements: |
|
2909 |
elements.append(element) |
|
2910 |
transition.Clean() |
|
2911 |
self.RemoveBlock(transition) |
|
2912 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
2913 |
for element in elements: |
|
2914 |
element.RefreshModel() |
|
2915 |
||
2916 |
def DeleteDivergence(self, divergence): |
|
2917 |
elements = [] |
|
2918 |
connectors = divergence.GetConnectors() |
|
2919 |
for output in connectors["outputs"]: |
|
2920 |
for element in output.GetConnectedBlocks(): |
|
2921 |
if element not in elements: |
|
2922 |
elements.append(element) |
|
2923 |
divergence.Clean() |
|
2924 |
self.RemoveBlock(divergence) |
|
2925 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
2926 |
for element in elements: |
|
2927 |
element.RefreshModel() |
|
2928 |
||
2929 |
def DeleteJump(self, jump): |
|
2930 |
jump.Clean() |
|
2931 |
self.RemoveBlock(jump) |
|
2932 |
self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId()) |
|
2933 |
||
2934 |
def DeleteActionBlock(self, actionblock): |
|
2935 |
actionblock.Clean() |
|
2936 |
self.RemoveBlock(actionblock) |
|
2937 |
self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId()) |
|
2938 |
||
2939 |
||
2940 |
#------------------------------------------------------------------------------- |
|
2941 |
# Editing functions |
|
2942 |
#------------------------------------------------------------------------------- |
|
2943 |
||
2944 |
def Cut(self): |
|
2945 |
if not self.Debug and (self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement) or isinstance(self.SelectedElement, Graphic_Group)): |
|
2946 |
blocks, wires = self.SelectedElement.GetDefinition() |
|
2947 |
text = self.Controler.GetEditedElementInstancesCopy(self.TagName, blocks, wires, self.Debug) |
|
2948 |
self.ParentWindow.SetCopyBuffer(text) |
|
2949 |
rect = self.SelectedElement.GetRedrawRect(1, 1) |
|
2950 |
self.SelectedElement.Delete() |
|
2951 |
self.SelectedElement = None |
|
2952 |
self.RefreshBuffer() |
|
2953 |
self.RefreshScrollBars() |
|
2954 |
self.RefreshVariablePanel() |
|
2955 |
self.ParentWindow.RefreshPouInstanceVariablesPanel() |
|
2956 |
self.RefreshRect(self.GetScrolledRect(rect), False) |
|
2957 |
||
2958 |
def Copy(self): |
|
2959 |
if not self.Debug and (self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement) or isinstance(self.SelectedElement, Graphic_Group)): |
|
2960 |
blocks, wires = self.SelectedElement.GetDefinition() |
|
2961 |
text = self.Controler.GetEditedElementInstancesCopy(self.TagName, blocks, wires, self.Debug) |
|
2962 |
self.ParentWindow.SetCopyBuffer(text) |
|
2963 |
||
2964 |
def Paste(self, bbx=None): |
|
2965 |
if not self.Debug: |
|
2966 |
element = self.ParentWindow.GetCopyBuffer() |
|
2967 |
if bbx is None: |
|
2968 |
mouse_pos = self.Editor.ScreenToClient(wx.GetMousePosition()) |
|
2969 |
middle = wx.Rect(0, 0, *self.Editor.GetClientSize()).InsideXY(mouse_pos.x, mouse_pos.y) |
|
2970 |
if middle: |
|
2971 |
x, y = self.CalcUnscrolledPosition(mouse_pos.x, mouse_pos.y) |
|
2972 |
else: |
|
2973 |
x, y = self.CalcUnscrolledPosition(0, 0) |
|
2974 |
new_pos = [int(x / self.ViewScale[0]), int(y / self.ViewScale[1])] |
|
2975 |
else: |
|
2976 |
middle = True |
|
2977 |
new_pos = [bbx.x, bbx.y] |
|
2978 |
result = self.Controler.PasteEditedElementInstances(self.TagName, element, new_pos, middle, self.Debug) |
|
2979 |
if not isinstance(result, (StringType, UnicodeType)): |
|
2980 |
self.RefreshBuffer() |
|
2981 |
self.RefreshView(selection=result) |
|
2982 |
self.RefreshVariablePanel() |
|
2983 |
self.ParentWindow.RefreshPouInstanceVariablesPanel() |
|
2984 |
else: |
|
2985 |
message = wx.MessageDialog(self.Editor, result, "Error", wx.OK|wx.ICON_ERROR) |
|
2986 |
message.ShowModal() |
|
2987 |
message.Destroy() |
|
2988 |
||
2989 |
def CanAddElement(self, block): |
|
2990 |
if isinstance(block, Graphic_Group): |
|
2991 |
return block.CanAddBlocks(self) |
|
2992 |
elif self.CurrentLanguage == "SFC": |
|
2993 |
return True |
|
2994 |
elif self.CurrentLanguage == "LD" and not isinstance(block, (SFC_Step, SFC_Transition, SFC_Divergence, SFC_Jump, SFC_ActionBlock)): |
|
2995 |
return True |
|
2996 |
elif self.CurrentLanguage == "FBD" and isinstance(block, (FBD_Block, FBD_Variable, FBD_Connector, Comment)): |
|
2997 |
return True |
|
2998 |
return False |
|
2999 |
||
3000 |
def GenerateNewName(self, element=None, blocktype=None, exclude={}): |
|
3001 |
if element is not None and isinstance(element, SFC_Step): |
|
3002 |
format = "Step%d" |
|
3003 |
else: |
|
3004 |
if element is not None: |
|
3005 |
blocktype = element.GetType() |
|
3006 |
if blocktype is None: |
|
3007 |
blocktype = "Block" |
|
3008 |
format = "%s%%d" % blocktype |
|
3009 |
return self.Controler.GenerateNewName(self.TagName, None, format, exclude, self.Debug) |
|
3010 |
||
3011 |
def IsNamedElement(self, element): |
|
3012 |
return isinstance(element, FBD_Block) and element.GetName() != "" or isinstance(element, SFC_Step) |
|
3013 |
||
3014 |
def CopyBlock(self, element, pos): |
|
3015 |
id = self.GetNewId() |
|
3016 |
if isinstance(element, Graphic_Group): |
|
3017 |
block = element.Clone(self, pos=pos) |
|
3018 |
else: |
|
3019 |
if self.IsNamedElement(element): |
|
3020 |
name = self.GenerateNewName(element) |
|
3021 |
block = element.Clone(self, id, name, pos) |
|
3022 |
else: |
|
3023 |
name = None |
|
3024 |
block = element.Clone(self, id, pos=pos) |
|
3025 |
self.AddBlockInModel(block) |
|
3026 |
return block |
|
3027 |
||
3028 |
def AddBlockInModel(self, block): |
|
3029 |
if isinstance(block, Comment): |
|
3030 |
self.AddComment(block) |
|
3031 |
self.Controler.AddEditedElementComment(self.TagName, block.GetId()) |
|
3032 |
self.RefreshCommentModel(block) |
|
3033 |
else: |
|
3034 |
self.AddBlock(block) |
|
3035 |
if isinstance(block, FBD_Block): |
|
3036 |
self.Controler.AddEditedElementBlock(self.TagName, block.GetId(), block.GetType(), block.GetName()) |
|
3037 |
self.RefreshBlockModel(block) |
|
3038 |
elif isinstance(block, FBD_Variable): |
|
3039 |
self.Controler.AddEditedElementVariable(self.TagName, block.GetId(), block.GetType()) |
|
3040 |
self.RefreshVariableModel(block) |
|
3041 |
elif isinstance(block, FBD_Connector): |
|
3042 |
self.Controler.AddEditedElementConnection(self.TagName, block.GetId(), block.GetType()) |
|
3043 |
self.RefreshConnectionModel(block) |
|
3044 |
elif isinstance(block, LD_Contact): |
|
3045 |
self.Controler.AddEditedElementContact(self.TagName, block.GetId()) |
|
3046 |
self.RefreshContactModel(block) |
|
3047 |
elif isinstance(block, LD_Coil): |
|
3048 |
self.Controler.AddEditedElementCoil(self.TagName, block.GetId()) |
|
3049 |
self.RefreshCoilModel(block) |
|
3050 |
elif isinstance(block, LD_PowerRail): |
|
3051 |
self.Controler.AddEditedElementPowerRail(self.TagName, block.GetId(), block.GetType()) |
|
3052 |
self.RefreshPowerRailModel(block) |
|
3053 |
elif isinstance(block, SFC_Step): |
|
3054 |
self.Controler.AddEditedElementStep(self.TagName, block.GetId()) |
|
3055 |
self.RefreshStepModel(block) |
|
3056 |
elif isinstance(block, SFC_Transition): |
|
3057 |
self.Controler.AddEditedElementTransition(self.TagName, block.GetId()) |
|
3058 |
self.RefreshTransitionModel(block) |
|
3059 |
elif isinstance(block, SFC_Divergence): |
|
3060 |
self.Controler.AddEditedElementDivergence(self.TagName, block.GetId(), block.GetType()) |
|
3061 |
self.RefreshDivergenceModel(block) |
|
3062 |
elif isinstance(block, SFC_Jump): |
|
3063 |
self.Controler.AddEditedElementJump(self.TagName, block.GetId()) |
|
3064 |
self.RefreshJumpModel(block) |
|
3065 |
elif isinstance(block, SFC_ActionBlock): |
|
3066 |
self.Controler.AddEditedElementActionBlock(self.TagName, block.GetId()) |
|
3067 |
self.RefreshActionBlockModel(block) |
|
3068 |
||
3069 |
#------------------------------------------------------------------------------- |
|
3070 |
# Find and Replace functions |
|
3071 |
#------------------------------------------------------------------------------- |
|
3072 |
||
3073 |
def Find(self, direction, search_params): |
|
3074 |
if self.SearchParams != search_params: |
|
3075 |
self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) |
|
3076 |
||
3077 |
self.SearchParams = search_params |
|
3078 |
criteria = { |
|
3079 |
"raw_pattern": search_params["find_pattern"], |
|
3080 |
"pattern": re.compile(search_params["find_pattern"]), |
|
3081 |
"case_sensitive": search_params["case_sensitive"], |
|
3082 |
"regular_expression": search_params["regular_expression"], |
|
3083 |
"filter": "all"} |
|
3084 |
||
3085 |
self.SearchResults = [] |
|
3086 |
blocks = [] |
|
3087 |
for infos, start, end, text in self.Controler.SearchInPou(self.TagName, criteria, self.Debug): |
|
3088 |
if infos[1] in ["var_local", "var_input", "var_output", "var_inout"]: |
|
3089 |
self.SearchResults.append((infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)) |
|
3090 |
else: |
|
3091 |
block = self.Blocks.get(infos[2]) |
|
3092 |
if block is not None: |
|
3093 |
blocks.append((block, (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT))) |
|
3094 |
blocks.sort(sort_blocks) |
|
3095 |
self.SearchResults.extend([infos for block, infos in blocks]) |
|
3096 |
||
3097 |
if len(self.SearchResults) > 0: |
|
3098 |
if self.CurrentFindHighlight is not None: |
|
3099 |
old_idx = self.SearchResults.index(self.CurrentFindHighlight) |
|
3100 |
if self.SearchParams["wrap"]: |
|
3101 |
idx = (old_idx + direction) % len(self.SearchResults) |
|
3102 |
else: |
|
3103 |
idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) |
|
3104 |
if idx != old_idx: |
|
3105 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
3106 |
self.CurrentFindHighlight = self.SearchResults[idx] |
|
3107 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
3108 |
else: |
|
3109 |
self.CurrentFindHighlight = self.SearchResults[0] |
|
3110 |
self.AddHighlight(*self.CurrentFindHighlight) |
|
3111 |
||
3112 |
else: |
|
3113 |
if self.CurrentFindHighlight is not None: |
|
3114 |
self.RemoveHighlight(*self.CurrentFindHighlight) |
|
3115 |
self.CurrentFindHighlight = None |
|
3116 |
||
3117 |
#------------------------------------------------------------------------------- |
|
3118 |
# Highlights showing functions |
|
3119 |
#------------------------------------------------------------------------------- |
|
3120 |
||
3121 |
def OnRefreshHighlightsTimer(self, event): |
|
3122 |
self.RefreshView() |
|
3123 |
event.Skip() |
|
3124 |
||
3125 |
def ClearHighlights(self, highlight_type=None): |
|
3126 |
EditorPanel.ClearHighlights(self, highlight_type) |
|
3127 |
||
3128 |
if highlight_type is None: |
|
3129 |
self.Highlights = [] |
|
3130 |
else: |
|
3131 |
self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type] |
|
3132 |
self.RefreshView() |
|
3133 |
||
3134 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
3135 |
EditorPanel.AddHighlight(self, infos, start, end, highlight_type) |
|
3136 |
||
3137 |
self.Highlights.append((infos, start, end, highlight_type)) |
|
3138 |
if infos[0] not in ["var_local", "var_input", "var_output", "var_inout"]: |
|
3139 |
block = self.Blocks.get(infos[1]) |
|
3140 |
if block is not None: |
|
3141 |
self.EnsureVisible(block) |
|
3142 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
3143 |
||
3144 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
3145 |
EditorPanel.RemoveHighlight(self, infos, start, end, highlight_type) |
|
3146 |
||
3147 |
if (infos, start, end, highlight_type) in self.Highlights: |
|
3148 |
self.Highlights.remove((infos, start, end, highlight_type)) |
|
3149 |
self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) |
|
3150 |
||
3151 |
def ShowHighlights(self): |
|
3152 |
for infos, start, end, highlight_type in self.Highlights: |
|
3153 |
if infos[0] in ["comment", "io_variable", "block", "connector", "coil", "contact", "step", "transition", "jump", "action_block"]: |
|
3154 |
block = self.FindElementById(infos[1]) |
|
3155 |
if block is not None: |
|
3156 |
block.AddHighlight(infos[2:], start, end, highlight_type) |
|
3157 |
||
3158 |
#------------------------------------------------------------------------------- |
|
3159 |
# Drawing functions |
|
3160 |
#------------------------------------------------------------------------------- |
|
3161 |
||
3162 |
def OnScrollWindow(self, event): |
|
3163 |
if self.Editor.HasCapture() and self.StartMousePos: |
|
3164 |
return |
|
3165 |
if wx.Platform == '__WXMSW__': |
|
3166 |
wx.CallAfter(self.RefreshVisibleElements) |
|
3167 |
elif event.GetOrientation() == wx.HORIZONTAL: |
|
3168 |
self.RefreshVisibleElements(xp = event.GetPosition()) |
|
3169 |
else: |
|
3170 |
self.RefreshVisibleElements(yp = event.GetPosition()) |
|
3171 |
event.Skip() |
|
3172 |
||
3173 |
def OnScrollStop(self, event): |
|
3174 |
self.RefreshScrollBars() |
|
3175 |
event.Skip() |
|
3176 |
||
3177 |
def OnMouseWheelWindow(self, event): |
|
3178 |
if self.StartMousePos is None or self.StartScreenPos is None: |
|
3179 |
rotation = event.GetWheelRotation() / event.GetWheelDelta() |
|
3180 |
if event.ShiftDown(): |
|
3181 |
x, y = self.GetViewStart() |
|
3182 |
xp = max(0, min(x - rotation * 3, self.Editor.GetVirtualSize()[0] / self.Editor.GetScrollPixelsPerUnit()[0])) |
|
3183 |
self.RefreshVisibleElements(xp = xp) |
|
3184 |
self.Scroll(xp, y) |
|
3185 |
elif event.ControlDown(): |
|
3186 |
dc = self.GetLogicalDC() |
|
3187 |
self.SetScale(self.CurrentScale + rotation, mouse_event = event) |
|
3188 |
self.ParentWindow.RefreshDisplayMenu() |
|
3189 |
else: |
|
3190 |
x, y = self.GetViewStart() |
|
3191 |
yp = max(0, min(y - rotation * 3, self.Editor.GetVirtualSize()[1] / self.Editor.GetScrollPixelsPerUnit()[1])) |
|
3192 |
self.RefreshVisibleElements(yp = yp) |
|
3193 |
self.Scroll(x, yp) |
|
3194 |
||
3195 |
def OnMoveWindow(self, event): |
|
3196 |
self.RefreshScrollBars() |
|
3197 |
self.RefreshVisibleElements() |
|
3198 |
event.Skip() |
|
3199 |
||
3200 |
def DoDrawing(self, dc, printing = False): |
|
3201 |
if printing: |
|
3202 |
if getattr(dc, "printing", False): |
|
3203 |
font = wx.Font(self.GetFont().GetPointSize(), wx.MODERN, wx.NORMAL, wx.NORMAL) |
|
3204 |
dc.SetFont(font) |
|
3205 |
else: |
|
3206 |
dc.SetFont(self.GetFont()) |
|
3207 |
else: |
|
3208 |
dc.SetBackground(wx.Brush(self.Editor.GetBackgroundColour())) |
|
3209 |
dc.Clear() |
|
3210 |
dc.BeginDrawing() |
|
3211 |
if self.Scaling is not None and self.DrawGrid and not printing: |
|
3212 |
dc.SetPen(wx.TRANSPARENT_PEN) |
|
3213 |
dc.SetBrush(self.GridBrush) |
|
3214 |
xstart, ystart = self.GetViewStart() |
|
3215 |
window_size = self.Editor.GetClientSize() |
|
3216 |
width, height = self.Editor.GetVirtualSize() |
|
3217 |
width = int(max(width, xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[0]) |
|
3218 |
height = int(max(height, ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[1]) |
|
3219 |
dc.DrawRectangle(1, 1, width, height) |
|
3220 |
if self.PageSize is not None and not printing: |
|
3221 |
dc.SetPen(self.PagePen) |
|
3222 |
xstart, ystart = self.GetViewStart() |
|
3223 |
window_size = self.Editor.GetClientSize() |
|
3224 |
for x in xrange(self.PageSize[0] - (xstart * SCROLLBAR_UNIT) % self.PageSize[0], int(window_size[0] / self.ViewScale[0]), self.PageSize[0]): |
|
3225 |
dc.DrawLine(xstart * SCROLLBAR_UNIT + x + 1, int(ystart * SCROLLBAR_UNIT / self.ViewScale[0]), |
|
3226 |
xstart * SCROLLBAR_UNIT + x + 1, int((ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[0])) |
|
3227 |
for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], int(window_size[1] / self.ViewScale[1]), self.PageSize[1]): |
|
3228 |
dc.DrawLine(int(xstart * SCROLLBAR_UNIT / self.ViewScale[0]), ystart * SCROLLBAR_UNIT + y + 1, |
|
3229 |
int((xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[1]), ystart * SCROLLBAR_UNIT + y + 1) |
|
3230 |
||
3231 |
# Draw all elements |
|
3232 |
for comment in self.Comments.itervalues(): |
|
3233 |
if comment != self.SelectedElement and (comment.IsVisible() or printing): |
|
3234 |
comment.Draw(dc) |
|
3235 |
for wire in self.Wires.iterkeys(): |
|
3236 |
if wire != self.SelectedElement and (wire.IsVisible() or printing): |
|
3237 |
if not self.Debug or wire.GetValue() != True: |
|
3238 |
wire.Draw(dc) |
|
3239 |
if self.Debug: |
|
3240 |
for wire in self.Wires.iterkeys(): |
|
3241 |
if wire != self.SelectedElement and (wire.IsVisible() or printing) and wire.GetValue() == True: |
|
3242 |
wire.Draw(dc) |
|
3243 |
for block in self.Blocks.itervalues(): |
|
3244 |
if block != self.SelectedElement and (block.IsVisible() or printing): |
|
3245 |
block.Draw(dc) |
|
3246 |
||
3247 |
if self.SelectedElement is not None and (self.SelectedElement.IsVisible() or printing): |
|
3248 |
self.SelectedElement.Draw(dc) |
|
3249 |
||
3250 |
if not printing: |
|
3251 |
if self.Debug: |
|
828
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3252 |
is_action = self.TagName.split("::")[0] == "A" |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3253 |
text = _("Debug: %s") % self.InstancePath |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3254 |
if is_action and self.Value is not None: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3255 |
text += " (" |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3256 |
dc.DrawText(text, 2, 2) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3257 |
if is_action and self.Value is not None: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3258 |
value_text = self.VALUE_TRANSLATION[self.Value] |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3259 |
tw, th = dc.GetTextExtent(text) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3260 |
if self.Value: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3261 |
dc.SetTextForeground(wx.GREEN) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3262 |
dc.DrawText(value_text, tw + 2, 2) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3263 |
if self.Value: |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3264 |
dc.SetTextForeground(wx.BLACK) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3265 |
vw, vh = dc.GetTextExtent(value_text) |
319dac4c4fd3
Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents:
823
diff
changeset
|
3266 |
dc.DrawText(")", tw + vw + 4, 2) |
814 | 3267 |
if self.rubberBand.IsShown(): |
3268 |
self.rubberBand.Draw(dc) |
|
3269 |
dc.EndDrawing() |
|
3270 |
||
3271 |
def OnPaint(self, event): |
|
3272 |
dc = self.GetLogicalDC(True) |
|
3273 |
self.DoDrawing(dc) |
|
3274 |
wx.BufferedPaintDC(self.Editor, dc.GetAsBitmap()) |
|
3275 |
if self.Debug: |
|
3276 |
DebugViewer.RefreshNewData(self) |
|
3277 |
event.Skip() |
|
3278 |
||
3279 |