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