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