author | mjsousa |
Wed, 21 Oct 2015 15:00:32 +0100 | |
changeset 1475 | de4ee16f7c6c |
parent 1347 | 533741e5075c |
child 1567 | a4bf874e4949 |
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 |
from types import * |
|
26 |
||
27 |
import wx |
|
28 |
||
29 |
from Viewer import * |
|
30 |
||
31 |
class SFC_Viewer(Viewer): |
|
32 |
||
33 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
|
34 |
Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
|
35 |
self.CurrentLanguage = "SFC" |
|
36 |
||
37 |
def ConnectConnectors(self, start, end): |
|
38 |
startpoint = [start.GetPosition(False), start.GetDirection()] |
|
39 |
endpoint = [end.GetPosition(False), end.GetDirection()] |
|
40 |
wire = Wire(self, startpoint, endpoint) |
|
41 |
self.AddWire(wire) |
|
42 |
start.Connect((wire, 0), False) |
|
43 |
end.Connect((wire, -1), False) |
|
44 |
wire.ConnectStartPoint(None, start) |
|
45 |
wire.ConnectEndPoint(None, end) |
|
46 |
return wire |
|
47 |
||
48 |
def CreateTransition(self, connector, next = None): |
|
49 |
previous = connector.GetParentBlock() |
|
50 |
id = self.GetNewId() |
|
51 |
transition = SFC_Transition(self, "reference", "", 0, id) |
|
52 |
pos = connector.GetPosition(False) |
|
53 |
transition.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
54 |
transition_connectors = transition.GetConnectors() |
|
55 |
wire = self.ConnectConnectors(transition_connectors["input"], connector) |
|
56 |
if isinstance(previous, SFC_Divergence): |
|
57 |
previous.RefreshConnectedPosition(connector) |
|
58 |
else: |
|
59 |
previous.RefreshOutputPosition() |
|
60 |
wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
|
61 |
self.AddBlock(transition) |
|
62 |
self.Controler.AddEditedElementTransition(self.TagName, id) |
|
63 |
self.RefreshTransitionModel(transition) |
|
64 |
if next: |
|
65 |
wire = self.ConnectConnectors(next, transition_connectors["output"]) |
|
66 |
pos = transition_connectors["output"].GetPosition(False) |
|
67 |
next_block = next.GetParentBlock() |
|
68 |
next_pos = next.GetPosition(False) |
|
69 |
transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
70 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
71 |
if isinstance(next_block, SFC_Divergence): |
|
72 |
next_block.RefreshPosition() |
|
73 |
transition.RefreshOutputModel(True) |
|
74 |
return transition |
|
75 |
||
76 |
def RemoveTransition(self, transition): |
|
77 |
connectors = transition.GetConnectors() |
|
78 |
input_wires = connectors["input"].GetWires() |
|
79 |
if len(input_wires) != 1: |
|
80 |
return |
|
81 |
input_wire = input_wires[0][0] |
|
82 |
previous = input_wire.EndConnected |
|
83 |
input_wire.Clean() |
|
84 |
self.RemoveWire(input_wire) |
|
85 |
output_wires = connectors["output"].GetWires() |
|
86 |
if len(output_wires) != 1: |
|
87 |
return |
|
88 |
output_wire = output_wires[0][0] |
|
89 |
next = output_wire.StartConnected |
|
90 |
output_wire.Clean() |
|
91 |
self.RemoveWire(output_wire) |
|
92 |
transition.Clean() |
|
93 |
self.RemoveBlock(transition) |
|
94 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
95 |
wire = self.ConnectConnectors(next, previous) |
|
96 |
return wire |
|
97 |
||
98 |
def CreateStep(self, name, connector, next = None): |
|
99 |
previous = connector.GetParentBlock() |
|
100 |
id = self.GetNewId() |
|
101 |
step = SFC_Step(self, name, False, id) |
|
102 |
if next: |
|
103 |
step.AddOutput() |
|
104 |
min_width, min_height = step.GetMinSize() |
|
105 |
pos = connector.GetPosition(False) |
|
106 |
step.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
107 |
step.SetSize(min_width, min_height) |
|
108 |
step_connectors = step.GetConnectors() |
|
109 |
wire = self.ConnectConnectors(step_connectors["input"], connector) |
|
110 |
if isinstance(previous, SFC_Divergence): |
|
111 |
previous.RefreshConnectedPosition(connector) |
|
112 |
else: |
|
113 |
previous.RefreshOutputPosition() |
|
114 |
wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
|
115 |
self.AddBlock(step) |
|
116 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
117 |
self.RefreshStepModel(step) |
|
118 |
if next: |
|
119 |
wire = self.ConnectConnectors(next, step_connectors["output"]) |
|
120 |
pos = step_connectors["output"].GetPosition(False) |
|
121 |
next_block = next.GetParentBlock() |
|
122 |
next_pos = next.GetPosition(False) |
|
123 |
step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
124 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
125 |
if isinstance(next_block, SFC_Divergence): |
|
126 |
next_block.RefreshPosition() |
|
127 |
step.RefreshOutputModel(True) |
|
128 |
return step |
|
129 |
||
130 |
def RemoveStep(self, step): |
|
131 |
connectors = step.GetConnectors() |
|
132 |
if connectors["input"]: |
|
133 |
input_wires = connectors["input"].GetWires() |
|
134 |
if len(input_wires) != 1: |
|
135 |
return |
|
136 |
input_wire = input_wires[0][0] |
|
137 |
previous = input_wire.EndConnected |
|
138 |
input_wire.Clean() |
|
139 |
self.RemoveWire(input_wire) |
|
140 |
else: |
|
141 |
previous = None |
|
142 |
if connectors["output"]: |
|
143 |
output_wires = connectors["output"].GetWires() |
|
144 |
if len(output_wires) != 1: |
|
145 |
return |
|
146 |
output_wire = output_wires[0][0] |
|
147 |
next = output_wire.StartConnected |
|
148 |
output_wire.Clean() |
|
149 |
self.RemoveWire(output_wire) |
|
150 |
else: |
|
151 |
next = None |
|
152 |
action = step.GetActionConnected() |
|
153 |
if action: |
|
154 |
self.DeleteActionBlock(action.GetParentBlock()) |
|
155 |
step.Clean() |
|
156 |
self.RemoveBlock(step) |
|
157 |
self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId()) |
|
158 |
if next and previous: |
|
159 |
wire = self.ConnectConnectors(next, previous) |
|
160 |
return wire |
|
161 |
else: |
|
162 |
return None |
|
163 |
||
164 |
#------------------------------------------------------------------------------- |
|
165 |
# Mouse event functions |
|
166 |
#------------------------------------------------------------------------------- |
|
167 |
||
168 |
def OnViewerLeftDown(self, event): |
|
169 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
170 |
Viewer.OnViewerLeftDown(self, event) |
|
171 |
elif self.Mode == MODE_SELECTION: |
|
172 |
if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None: |
|
173 |
element = self.FindElement(event, True) |
|
174 |
if element and not self.IsWire(element): |
|
175 |
if isinstance(self.SelectedElement, Graphic_Group): |
|
176 |
self.SelectedElement.SelectElement(element) |
|
177 |
else: |
|
178 |
group = Graphic_Group(self) |
|
179 |
self.SelectedElement.SetSelected(False) |
|
180 |
group.SelectElement(self.SelectedElement) |
|
181 |
group.SelectElement(element) |
|
182 |
self.SelectedElement = group |
|
183 |
elements = self.SelectedElement.GetElements() |
|
184 |
if len(elements) == 0: |
|
185 |
self.SelectedElement = element |
|
186 |
elif len(elements) == 1: |
|
187 |
self.SelectedElement = elements[0] |
|
188 |
self.SelectedElement.SetSelected(True) |
|
189 |
else: |
|
190 |
element = self.FindElement(event) |
|
191 |
if self.SelectedElement and self.SelectedElement != element: |
|
192 |
if self.IsWire(self.SelectedElement): |
|
193 |
self.SelectedElement.SetSelectedSegment(None) |
|
194 |
else: |
|
195 |
self.SelectedElement.SetSelected(False) |
|
196 |
self.SelectedElement = None |
|
197 |
if element: |
|
198 |
self.SelectedElement = element |
|
199 |
self.SelectedElement.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
200 |
self.SelectedElement.Refresh() |
|
201 |
else: |
|
202 |
self.rubberBand.Reset() |
|
203 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
204 |
elif self.Mode == MODE_COMMENT: |
|
205 |
self.rubberBand.Reset() |
|
206 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
207 |
event.Skip() |
|
208 |
||
209 |
def OnViewerLeftUp(self, event): |
|
210 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
211 |
Viewer.OnViewerLeftUp(self, event) |
|
212 |
elif self.rubberBand.IsShown(): |
|
213 |
if self.Mode == MODE_SELECTION: |
|
214 |
elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
|
215 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
216 |
if len(elements) > 0: |
|
217 |
self.SelectedElement = Graphic_Group(self) |
|
218 |
self.SelectedElement.SetElements(elements) |
|
219 |
self.SelectedElement.SetSelected(True) |
|
220 |
elif self.Mode == MODE_COMMENT: |
|
221 |
bbox = self.rubberBand.GetCurrentExtent() |
|
222 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
223 |
wx.CallAfter(self.AddComment, bbox) |
|
224 |
elif self.Mode == MODE_INITIALSTEP: |
|
225 |
wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)) |
|
226 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
227 |
if self.IsWire(self.SelectedElement): |
|
228 |
self.SelectedElement.SetSelectedSegment(0) |
|
229 |
else: |
|
230 |
self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
231 |
self.SelectedElement.Refresh() |
|
232 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
233 |
elif self.Mode == MODE_WIRE and self.SelectedElement: |
|
234 |
self.SelectedElement.ResetPoints() |
|
235 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
236 |
self.SelectedElement.GeneratePoints() |
|
237 |
self.SelectedElement.RefreshModel() |
|
238 |
self.SelectedElement.SetSelected(True) |
|
239 |
event.Skip() |
|
240 |
||
241 |
def OnViewerRightUp(self, event): |
|
242 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
243 |
Viewer.OnViewerRightUp(self, event) |
|
244 |
else: |
|
245 |
element = self.FindElement(event) |
|
246 |
if element: |
|
247 |
if self.SelectedElement and self.SelectedElement != element: |
|
248 |
self.SelectedElement.SetSelected(False) |
|
249 |
self.SelectedElement = element |
|
250 |
if self.IsWire(self.SelectedElement): |
|
251 |
self.SelectedElement.SetSelectedSegment(0) |
|
252 |
else: |
|
253 |
self.SelectedElement.SetSelected(True) |
|
254 |
self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling) |
|
255 |
self.SelectedElement.Refresh() |
|
256 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
257 |
event.Skip() |
|
258 |
||
259 |
def OnViewerLeftDClick(self, event): |
|
260 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
261 |
Viewer.OnViewerLeftDClick(self, event) |
|
262 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
263 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
264 |
self.Refresh(False) |
|
265 |
event.Skip() |
|
266 |
||
267 |
def OnViewerMotion(self, event): |
|
268 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
269 |
Viewer.OnViewerMotion(self, event) |
|
270 |
else: |
|
271 |
if self.rubberBand.IsShown(): |
|
272 |
self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
273 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
274 |
if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group): |
|
275 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
276 |
self.SelectedElement.Refresh() |
|
277 |
elif self.Mode == MODE_WIRE and self.SelectedElement: |
|
278 |
self.SelectedElement.ResetPoints() |
|
279 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
280 |
self.SelectedElement.GeneratePoints() |
|
281 |
self.SelectedElement.Refresh() |
|
282 |
self.UpdateScrollPos(event) |
|
283 |
event.Skip() |
|
284 |
||
285 |
#------------------------------------------------------------------------------- |
|
286 |
# Keyboard event functions |
|
287 |
#------------------------------------------------------------------------------- |
|
288 |
||
289 |
def OnChar(self, event): |
|
290 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
291 |
Viewer.OnChar(self, event) |
|
292 |
else: |
|
293 |
xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
294 |
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
295 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
|
296 |
keycode = event.GetKeyCode() |
|
297 |
if self.Scaling: |
|
298 |
scaling = self.Scaling |
|
299 |
else: |
|
300 |
scaling = (8, 8) |
|
301 |
if keycode == wx.WXK_DELETE and self.SelectedElement: |
|
302 |
self.SelectedElement.Delete() |
|
303 |
self.SelectedElement = None |
|
304 |
self.RefreshBuffer() |
|
305 |
self.RefreshScrollBars() |
|
306 |
self.Refresh(False) |
|
307 |
elif keycode == wx.WXK_LEFT: |
|
308 |
if event.ControlDown() and event.ShiftDown(): |
|
309 |
self.Scroll(0, ypos) |
|
310 |
elif event.ControlDown(): |
|
311 |
event.Skip() |
|
312 |
elif self.SelectedElement: |
|
313 |
self.SelectedElement.Move(-scaling[0], 0) |
|
314 |
self.SelectedElement.RefreshModel() |
|
315 |
self.RefreshBuffer() |
|
316 |
self.RefreshScrollBars() |
|
317 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False) |
|
318 |
elif keycode == wx.WXK_RIGHT: |
|
319 |
if event.ControlDown() and event.ShiftDown(): |
|
320 |
self.Scroll(xmax, ypos) |
|
321 |
elif event.ControlDown(): |
|
322 |
event.Skip() |
|
323 |
elif self.SelectedElement: |
|
324 |
self.SelectedElement.Move(scaling[0], 0) |
|
325 |
self.SelectedElement.RefreshModel() |
|
326 |
self.RefreshBuffer() |
|
327 |
self.RefreshScrollBars() |
|
328 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False) |
|
329 |
elif keycode == wx.WXK_UP: |
|
330 |
if event.ControlDown() and event.ShiftDown(): |
|
331 |
self.Scroll(xpos, 0) |
|
332 |
elif event.ControlDown(): |
|
333 |
event.Skip() |
|
334 |
elif self.SelectedElement: |
|
335 |
self.SelectedElement.Move(0, -scaling[1]) |
|
336 |
self.SelectedElement.RefreshModel() |
|
337 |
self.RefreshBuffer() |
|
338 |
self.RefreshScrollBars() |
|
339 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False) |
|
340 |
elif keycode == wx.WXK_DOWN: |
|
341 |
if event.ControlDown() and event.ShiftDown(): |
|
342 |
self.Scroll(xpos, ymax) |
|
343 |
elif event.ControlDown(): |
|
344 |
event.Skip() |
|
345 |
elif self.SelectedElement: |
|
346 |
self.SelectedElement.Move(0, scaling[1]) |
|
347 |
self.SelectedElement.RefreshModel() |
|
348 |
self.RefreshBuffer() |
|
349 |
self.RefreshScrollBars() |
|
350 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False) |
|
351 |
else: |
|
352 |
event.Skip() |
|
353 |
||
354 |
#------------------------------------------------------------------------------- |
|
355 |
# Adding element functions |
|
356 |
#------------------------------------------------------------------------------- |
|
357 |
||
358 |
def AddInitialStep(self, pos): |
|
359 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Please enter step name"), _("Add a new initial step"), "", wx.OK|wx.CANCEL) |
|
360 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
361 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 362 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
363 |
if dialog.ShowModal() == wx.ID_OK: |
|
364 |
id = self.GetNewId() |
|
365 |
name = dialog.GetValue() |
|
366 |
step = SFC_Step(self, name, True, id) |
|
367 |
min_width, min_height = step.GetMinSize() |
|
368 |
step.SetPosition(pos.x, pos.y) |
|
369 |
width, height = step.GetSize() |
|
370 |
step.SetSize(max(min_width, width), max(min_height, height)) |
|
371 |
self.AddBlock(step) |
|
372 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
373 |
self.RefreshStepModel(step) |
|
374 |
self.RefreshBuffer() |
|
375 |
self.RefreshScrollBars() |
|
376 |
self.Refresh(False) |
|
377 |
dialog.Destroy() |
|
378 |
||
379 |
def AddStep(self): |
|
380 |
if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): |
|
381 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Add a new step"), _("Please enter step name"), "", wx.OK|wx.CANCEL) |
|
382 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
383 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 384 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
385 |
if dialog.ShowModal() == wx.ID_OK: |
|
386 |
name = dialog.GetValue() |
|
387 |
if self.IsWire(self.SelectedElement): |
|
388 |
self.SelectedElement.SetSelectedSegment(None) |
|
389 |
previous = self.SelectedElement.EndConnected |
|
390 |
next = self.SelectedElement.StartConnected |
|
391 |
self.SelectedElement.Clean() |
|
392 |
self.RemoveWire(self.SelectedElement) |
|
393 |
else: |
|
394 |
connectors = self.SelectedElement.GetConnectors() |
|
395 |
if connectors["output"]: |
|
396 |
previous = connectors["output"] |
|
397 |
wires = previous.GetWires() |
|
398 |
if len(wires) != 1: |
|
399 |
return |
|
400 |
wire = wires[0][0] |
|
401 |
next = wire.StartConnected |
|
402 |
wire.Clean() |
|
403 |
self.RemoveWire(wire) |
|
404 |
else: |
|
405 |
self.SelectedElement.AddOutput() |
|
406 |
connectors = self.SelectedElement.GetConnectors() |
|
407 |
self.RefreshStepModel(self.SelectedElement) |
|
408 |
previous = connectors["output"] |
|
409 |
next = None |
|
410 |
previous_block = previous.GetParentBlock() |
|
411 |
if isinstance(previous_block, SFC_Step) or isinstance(previous_block, SFC_Divergence) and previous_block.GetType() in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
412 |
transition = self.CreateTransition(previous) |
|
413 |
transition_connectors = transition.GetConnectors() |
|
414 |
step = self.CreateStep(name, transition_connectors["output"], next) |
|
415 |
else: |
|
416 |
step = self.CreateStep(name, previous) |
|
417 |
step.AddOutput() |
|
418 |
step.RefreshModel() |
|
419 |
step_connectors = step.GetConnectors() |
|
420 |
transition = self.CreateTransition(step_connectors["output"], next) |
|
421 |
if self.IsWire(self.SelectedElement): |
|
422 |
self.SelectedElement = wire |
|
423 |
self.SelectedElement.SetSelectedSegment(0) |
|
424 |
else: |
|
425 |
self.SelectedElement.SetSelected(False) |
|
426 |
self.SelectedElement = step |
|
427 |
self.SelectedElement.SetSelected(True) |
|
428 |
self.RefreshBuffer() |
|
429 |
self.RefreshScrollBars() |
|
430 |
self.Refresh(False) |
|
431 |
dialog.Destroy() |
|
432 |
||
433 |
def AddStepAction(self): |
|
434 |
if isinstance(self.SelectedElement, SFC_Step): |
|
435 |
connectors = self.SelectedElement.GetConnectors() |
|
436 |
if not connectors["action"]: |
|
437 |
dialog = ActionBlockDialog(self.ParentWindow) |
|
438 |
dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
|
439 |
dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
440 |
dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 441 |
if dialog.ShowModal() == wx.ID_OK: |
442 |
actions = dialog.GetValues() |
|
443 |
self.SelectedElement.AddAction() |
|
444 |
self.RefreshStepModel(self.SelectedElement) |
|
445 |
connectors = self.SelectedElement.GetConnectors() |
|
446 |
pos = connectors["action"].GetPosition(False) |
|
447 |
id = self.GetNewId() |
|
448 |
actionblock = SFC_ActionBlock(self, [], id) |
|
449 |
actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2) |
|
450 |
actionblock_connector = actionblock.GetConnector() |
|
451 |
wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) |
|
452 |
wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) |
|
453 |
actionblock.SetActions(actions) |
|
454 |
self.AddBlock(actionblock) |
|
455 |
self.Controler.AddEditedElementActionBlock(self.TagName, id) |
|
456 |
self.RefreshActionBlockModel(actionblock) |
|
457 |
self.RefreshBuffer() |
|
458 |
self.RefreshScrollBars() |
|
459 |
self.Refresh(False) |
|
460 |
dialog.Destroy() |
|
461 |
||
462 |
def AddDivergence(self): |
|
463 |
if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step): |
|
464 |
dialog = SFCDivergenceDialog(self.ParentWindow) |
|
465 |
dialog.SetPreviewFont(self.GetFont()) |
|
466 |
if dialog.ShowModal() == wx.ID_OK: |
|
467 |
value = dialog.GetValues() |
|
468 |
if value["type"] == SELECTION_DIVERGENCE: |
|
469 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step): |
|
470 |
self.SelectedElement.SetSelectedSegment(None) |
|
471 |
previous = self.SelectedElement.EndConnected |
|
472 |
next = self.SelectedElement.StartConnected |
|
473 |
self.SelectedElement.Clean() |
|
474 |
self.RemoveWire(self.SelectedElement) |
|
475 |
self.SelectedElement = None |
|
476 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
477 |
connectors = self.SelectedElement.GetConnectors() |
|
478 |
if connectors["output"]: |
|
479 |
previous = connectors["output"] |
|
480 |
wires = previous.GetWires() |
|
481 |
if len(wires) != 1: |
|
482 |
return |
|
483 |
wire = wires[0][0] |
|
484 |
next = wire.StartConnected |
|
485 |
wire.Clean() |
|
486 |
self.RemoveWire(wire) |
|
487 |
else: |
|
488 |
self.SelectedElement.AddOutput() |
|
489 |
connectors = self.SelectedElement.GetConnectors() |
|
490 |
self.RefreshStepModel(self.SelectedElement) |
|
491 |
previous = connectors["output"] |
|
492 |
next = None |
|
493 |
else: |
|
494 |
return |
|
495 |
id = self.GetNewId() |
|
496 |
divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id) |
|
497 |
pos = previous.GetPosition(False) |
|
498 |
previous_block = previous.GetParentBlock() |
|
499 |
wire_size = GetWireSize(previous_block) |
|
500 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
501 |
divergence_connectors = divergence.GetConnectors() |
|
502 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
503 |
previous_block.RefreshOutputPosition() |
|
504 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
505 |
self.AddBlock(divergence) |
|
506 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
507 |
self.RefreshDivergenceModel(divergence) |
|
508 |
for index, connector in enumerate(divergence_connectors["outputs"]): |
|
509 |
if next: |
|
510 |
wire = self.ConnectConnectors(next, connector) |
|
511 |
pos = connector.GetPosition(False) |
|
512 |
next_pos = next.GetPosition(False) |
|
513 |
next_block = next.GetParentBlock() |
|
514 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
515 |
divergence.RefreshConnectedPosition(connector) |
|
516 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
517 |
next_block.RefreshModel() |
|
518 |
next = None |
|
519 |
else: |
|
520 |
transition = self.CreateTransition(connector) |
|
521 |
transition_connectors = transition.GetConnectors() |
|
522 |
step = self.CreateStep("Step", transition_connectors["output"]) |
|
523 |
elif value["type"] == SIMULTANEOUS_DIVERGENCE: |
|
524 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Transition): |
|
525 |
self.SelectedElement.SetSelectedSegment(None) |
|
526 |
previous = self.SelectedElement.EndConnected |
|
527 |
next = self.SelectedElement.StartConnected |
|
528 |
self.SelectedElement.Clean() |
|
529 |
self.RemoveWire(self.SelectedElement) |
|
530 |
self.SelectedElement = None |
|
531 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
532 |
connectors = self.SelectedElement.GetConnectors() |
|
533 |
if connectors["output"]: |
|
534 |
previous = connectors["output"] |
|
535 |
wires = previous.GetWires() |
|
536 |
if len(wires) != 1: |
|
537 |
return |
|
538 |
wire = wires[0][0] |
|
539 |
next = wire.StartConnected |
|
540 |
wire.Clean() |
|
541 |
self.RemoveWire(wire) |
|
542 |
else: |
|
543 |
self.SelectedElement.AddOutput() |
|
544 |
connectors = self.SelectedElement.GetConnectors() |
|
545 |
self.RefreshStepModel(self.SelectedElement) |
|
546 |
previous = connectors["output"] |
|
547 |
next = None |
|
548 |
transition = self.CreateTransition(previous) |
|
549 |
transition_connectors = transition.GetConnectors() |
|
550 |
previous = transition_connectors["output"] |
|
551 |
else: |
|
552 |
return |
|
553 |
id = self.GetNewId() |
|
554 |
divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id) |
|
555 |
pos = previous.GetPosition(False) |
|
556 |
previous_block = previous.GetParentBlock() |
|
557 |
wire_size = GetWireSize(previous_block) |
|
558 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
559 |
divergence_connectors = divergence.GetConnectors() |
|
560 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
561 |
previous_block.RefreshOutputPosition() |
|
562 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
563 |
self.AddBlock(divergence) |
|
564 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
565 |
self.RefreshDivergenceModel(divergence) |
|
566 |
for index, connector in enumerate(divergence_connectors["outputs"]): |
|
567 |
if next: |
|
568 |
wire = self.ConnectConnectors(next, connector) |
|
569 |
pos = connector.GetPosition(False) |
|
570 |
next_pos = next.GetPosition(False) |
|
571 |
next_block = next.GetParentBlock() |
|
572 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
573 |
divergence.RefreshConnectedPosition(connector) |
|
574 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
575 |
next_block.RefreshModel() |
|
576 |
next = None |
|
577 |
else: |
|
578 |
step = self.CreateStep("Step", connector) |
|
579 |
elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1: |
|
580 |
next = None |
|
581 |
for element in self.SelectedElement.GetElements(): |
|
582 |
connectors = element.GetConnectors() |
|
583 |
if not isinstance(element, SFC_Step) or connectors["output"] and next: |
|
584 |
return |
|
585 |
elif connectors["output"] and not next: |
|
586 |
wires = connectors["output"].GetWires() |
|
587 |
if len(wires) != 1: |
|
588 |
return |
|
589 |
if value["type"] == SELECTION_CONVERGENCE: |
|
590 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
591 |
transition_connectors = transition.GetConnectors() |
|
592 |
wires = transition_connectors["output"].GetWires() |
|
593 |
if len(wires) != 1: |
|
594 |
return |
|
595 |
wire = wires[0][0] |
|
596 |
next = wire.StartConnected |
|
597 |
wire.Clean() |
|
598 |
self.RemoveWire(wire) |
|
599 |
inputs = [] |
|
600 |
for input in self.SelectedElement.GetElements(): |
|
601 |
input_connectors = input.GetConnectors() |
|
602 |
if not input_connectors["output"]: |
|
603 |
input.AddOutput() |
|
604 |
input.RefreshModel() |
|
605 |
input_connectors = input.GetConnectors() |
|
606 |
if value["type"] == SELECTION_CONVERGENCE: |
|
607 |
transition = self.CreateTransition(input_connectors["output"]) |
|
608 |
transition_connectors = transition.GetConnectors() |
|
609 |
inputs.append(transition_connectors["output"]) |
|
610 |
else: |
|
611 |
inputs.append(input_connectors["output"]) |
|
612 |
elif value["type"] == SELECTION_CONVERGENCE: |
|
613 |
wires = input_connectors["output"].GetWires() |
|
614 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
615 |
transition_connectors = transition.GetConnectors() |
|
616 |
inputs.append(transition_connectors["output"]) |
|
617 |
else: |
|
618 |
inputs.append(input_connectors["output"]) |
|
619 |
id = self.GetNewId() |
|
620 |
divergence = SFC_Divergence(self, value["type"], len(inputs), id) |
|
621 |
pos = inputs[0].GetPosition(False) |
|
622 |
divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
623 |
divergence_connectors = divergence.GetConnectors() |
|
624 |
for i, input in enumerate(inputs): |
|
625 |
pos = input.GetPosition(False) |
|
626 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input) |
|
627 |
wire_size = GetWireSize(input) |
|
628 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
629 |
input_block = input.GetParentBlock() |
|
630 |
input_block.RefreshOutputPosition() |
|
631 |
divergence.RefreshPosition() |
|
632 |
pos = divergence_connectors["outputs"][0].GetRelPosition() |
|
633 |
divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) |
|
634 |
self.AddBlock(divergence) |
|
635 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
636 |
self.RefreshDivergenceModel(divergence) |
|
637 |
if next: |
|
638 |
wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) |
|
639 |
pos = divergence_connectors["outputs"][0].GetPosition(False) |
|
640 |
next_pos = next.GetPosition(False) |
|
641 |
next_block = next.GetParentBlock() |
|
642 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
643 |
divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0]) |
|
644 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
645 |
next_block.RefreshModel() |
|
646 |
else: |
|
647 |
if value["type"] == SELECTION_CONVERGENCE: |
|
648 |
previous = divergence_connectors["outputs"][0] |
|
649 |
else: |
|
650 |
transition = self.CreateTransition(divergence_connectors["outputs"][0]) |
|
651 |
transition_connectors = transition.GetConnectors() |
|
652 |
previous = transition_connectors["output"] |
|
653 |
self.CreateStep("Step", previous) |
|
654 |
self.RefreshBuffer() |
|
655 |
self.RefreshScrollBars() |
|
656 |
self.Refresh(False) |
|
657 |
dialog.Destroy() |
|
658 |
||
659 |
def AddDivergenceBranch(self, divergence): |
|
660 |
if isinstance(divergence, SFC_Divergence): |
|
661 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
662 |
divergence.AddBranch() |
|
663 |
self.RefreshDivergenceModel(divergence) |
|
664 |
else: |
|
665 |
type = divergence.GetType() |
|
666 |
if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
667 |
divergence.AddBranch() |
|
668 |
divergence_connectors = divergence.GetConnectors() |
|
669 |
if type == SELECTION_DIVERGENCE: |
|
670 |
transition = self.CreateTransition(divergence_connectors["outputs"][-1]) |
|
671 |
transition_connectors = transition.GetConnectors() |
|
672 |
previous = transition_connectors["output"] |
|
673 |
else: |
|
674 |
previous = divergence_connectors["outputs"][-1] |
|
675 |
step = self.CreateStep("Step", previous) |
|
676 |
self.RefreshBuffer() |
|
677 |
self.RefreshScrollBars() |
|
678 |
self.Refresh(False) |
|
679 |
||
680 |
def RemoveDivergenceBranch(self, divergence): |
|
681 |
if isinstance(divergence, SFC_Divergence): |
|
682 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
683 |
divergence.RemoveHandledBranch() |
|
684 |
self.RefreshDivergenceModel(divergence) |
|
685 |
self.RefreshBuffer() |
|
686 |
self.RefreshScrollBars() |
|
687 |
self.Refresh(False) |
|
688 |
||
689 |
def AddJump(self): |
|
690 |
if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output: |
|
691 |
choices = [] |
|
692 |
for block in self.Blocks: |
|
693 |
if isinstance(block, SFC_Step): |
|
694 |
choices.append(block.GetName()) |
|
695 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, |
|
696 |
_("Add a new jump"), _("Please choose a target"), |
|
697 |
choices, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
|
698 |
if dialog.ShowModal() == wx.ID_OK: |
|
699 |
value = dialog.GetStringSelection() |
|
700 |
self.SelectedElement.AddOutput() |
|
701 |
self.RefreshStepModel(self.SelectedElement) |
|
702 |
step_connectors = self.SelectedElement.GetConnectors() |
|
703 |
transition = self.CreateTransition(step_connectors["output"]) |
|
704 |
transition_connectors = transition.GetConnectors() |
|
705 |
id = self.GetNewId() |
|
706 |
jump = SFC_Jump(self, value, id) |
|
707 |
pos = transition_connectors["output"].GetPosition(False) |
|
708 |
jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
709 |
self.AddBlock(jump) |
|
710 |
self.Controler.AddEditedElementJump(self.TagName, id) |
|
711 |
jump_connector = jump.GetConnector() |
|
712 |
wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) |
|
713 |
transition.RefreshOutputPosition() |
|
714 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
715 |
self.RefreshJumpModel(jump) |
|
716 |
self.RefreshBuffer() |
|
717 |
self.RefreshScrollBars() |
|
718 |
self.Refresh(False) |
|
719 |
dialog.Destroy() |
|
720 |
||
721 |
def EditStepContent(self, step): |
|
722 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
723 |
Viewer.EditStepContent(self, step) |
|
724 |
else: |
|
725 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Edit step name"), _("Please enter step name"), step.GetName(), wx.OK|wx.CANCEL) |
|
726 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
727 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 728 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
729 |
if dialog.ShowModal() == wx.ID_OK: |
|
730 |
value = dialog.GetValue() |
|
731 |
step.SetName(value) |
|
732 |
min_size = step.GetMinSize() |
|
733 |
size = step.GetSize() |
|
734 |
step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1])) |
|
735 |
step.RefreshModel() |
|
736 |
self.RefreshBuffer() |
|
737 |
self.RefreshScrollBars() |
|
738 |
self.Refresh(False) |
|
739 |
dialog.Destroy() |
|
740 |
||
741 |
#------------------------------------------------------------------------------- |
|
742 |
# Delete element functions |
|
743 |
#------------------------------------------------------------------------------- |
|
744 |
||
745 |
def DeleteStep(self, step): |
|
746 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
747 |
Viewer.DeleteStep(self, step) |
|
748 |
else: |
|
749 |
step_connectors = step.GetConnectors() |
|
750 |
if not step.GetInitial() or not step_connectors["output"]: |
|
751 |
previous = step.GetPreviousConnector() |
|
752 |
if previous: |
|
753 |
previous_block = previous.GetParentBlock() |
|
754 |
else: |
|
755 |
previous_block = None |
|
756 |
next = step.GetNextConnector() |
|
757 |
if next: |
|
758 |
next_block = next.GetParentBlock() |
|
759 |
else: |
|
760 |
next_block = None |
|
761 |
if isinstance(next_block, SFC_Transition): |
|
762 |
self.RemoveTransition(next_block) |
|
763 |
next = step.GetNextConnector() |
|
764 |
if next: |
|
765 |
next_block = next.GetParentBlock() |
|
766 |
else: |
|
767 |
next_block = None |
|
768 |
elif isinstance(previous_block, SFC_Transition): |
|
769 |
self.RemoveTransition(previous_block) |
|
770 |
previous = step.GetPreviousConnector() |
|
771 |
if previous: |
|
772 |
previous_block = previous.GetParentBlock() |
|
773 |
else: |
|
774 |
previous_block = None |
|
775 |
wire = self.RemoveStep(step) |
|
776 |
self.SelectedElement = None |
|
777 |
if next_block: |
|
778 |
if isinstance(next_block, SFC_Divergence) and next_block.GetType() == SIMULTANEOUS_CONVERGENCE and isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SIMULTANEOUS_DIVERGENCE: |
|
779 |
wire.Clean() |
|
780 |
self.RemoveWire(wire) |
|
781 |
next_block.RemoveBranch(next) |
|
782 |
if next_block.GetBranchNumber() < 2: |
|
783 |
self.DeleteDivergence(next_block) |
|
784 |
else: |
|
785 |
next_block.RefreshModel() |
|
786 |
previous_block.RemoveBranch(previous) |
|
787 |
if previous_block.GetBranchNumber() < 2: |
|
788 |
self.DeleteDivergence(previous_block) |
|
789 |
else: |
|
790 |
previous_block.RefreshModel() |
|
791 |
else: |
|
792 |
pos = previous.GetPosition(False) |
|
793 |
next_pos = next.GetPosition(False) |
|
794 |
wire_size = GetWireSize(previous_block) |
|
795 |
previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y)) |
|
796 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
797 |
if isinstance(next_block, SFC_Divergence): |
|
798 |
next_block.RefreshPosition() |
|
799 |
previous_block.RefreshOutputModel(True) |
|
800 |
else: |
|
801 |
if isinstance(previous_block, SFC_Step): |
|
802 |
previous_block.RemoveOutput() |
|
803 |
self.RefreshStepModel(previous_block) |
|
804 |
elif isinstance(previous_block, SFC_Divergence): |
|
805 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
806 |
self.DeleteDivergence(previous_block) |
|
807 |
else: |
|
808 |
previous_block.RemoveBranch(previous) |
|
809 |
if previous_block.GetBranchNumber() < 2: |
|
810 |
self.DeleteDivergence(previous_block) |
|
811 |
else: |
|
812 |
self.RefreshDivergenceModel(previous_block) |
|
813 |
||
814 |
def DeleteTransition(self, transition): |
|
815 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
816 |
Viewer.DeleteTransition(self, transition) |
|
817 |
else: |
|
818 |
previous = transition.GetPreviousConnector() |
|
819 |
previous_block = previous.GetParentBlock() |
|
820 |
next = transition.GetNextConnector() |
|
821 |
next_block = next.GetParentBlock() |
|
822 |
if isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SELECTION_DIVERGENCE and isinstance(next_block, SFC_Divergence) and next_block.GetType() == SELECTION_CONVERGENCE: |
|
823 |
wires = previous.GetWires() |
|
824 |
if len(wires) != 1: |
|
825 |
return |
|
826 |
wire = wires[0][0] |
|
827 |
wire.Clean() |
|
828 |
self.RemoveWire(wire) |
|
829 |
wires = next.GetWires() |
|
830 |
if len(wires) != 1: |
|
831 |
return |
|
832 |
wire = wires[0][0] |
|
833 |
wire.Clean() |
|
834 |
self.RemoveWire(wire) |
|
835 |
transition.Clean() |
|
836 |
self.RemoveBlock(transition) |
|
837 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
838 |
previous_block.RemoveBranch(previous) |
|
839 |
if previous_block.GetBranchNumber() < 2: |
|
840 |
self.DeleteDivergence(previous_block) |
|
841 |
else: |
|
842 |
self.RefreshDivergenceModel(previous_block) |
|
843 |
next_block.RemoveBranch(next) |
|
844 |
if next_block.GetBranchNumber() < 2: |
|
845 |
self.DeleteDivergence(next_block) |
|
846 |
else: |
|
847 |
self.RefreshDivergenceModel(next_block) |
|
848 |
||
849 |
def DeleteDivergence(self, divergence): |
|
850 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
851 |
Viewer.DeleteDivergence(self, divergence) |
|
852 |
else: |
|
853 |
connectors = divergence.GetConnectors() |
|
854 |
type = divergence.GetType() |
|
855 |
if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
856 |
wires = connectors["outputs"][0].GetWires() |
|
857 |
if len(wires) > 1: |
|
858 |
return |
|
859 |
elif len(wires) == 1: |
|
860 |
next = wires[0][0].StartConnected |
|
861 |
next_block = next.GetParentBlock() |
|
862 |
wire = wires[0][0] |
|
863 |
wire.Clean() |
|
864 |
self.RemoveWire(wire) |
|
865 |
else: |
|
866 |
next = None |
|
867 |
next_block = None |
|
868 |
for index, connector in enumerate(connectors["inputs"]): |
|
869 |
if next and index == 0: |
|
870 |
wires = connector.GetWires() |
|
871 |
wire = wires[0][0] |
|
872 |
previous = wires[0][0].EndConnected |
|
873 |
wire.Clean() |
|
874 |
self.RemoveWire(wire) |
|
875 |
else: |
|
876 |
if type == SELECTION_CONVERGENCE: |
|
877 |
wires = connector.GetWires() |
|
878 |
previous_block = wires[0][0].EndConnected.GetParentBlock() |
|
879 |
self.RemoveTransition(previous_block) |
|
880 |
wires = connector.GetWires() |
|
881 |
wire = wires[0][0] |
|
882 |
previous_connector = wire.EndConnected |
|
883 |
previous_block = previous_connector.GetParentBlock() |
|
884 |
wire.Clean() |
|
885 |
self.RemoveWire(wire) |
|
886 |
if isinstance(previous_block, SFC_Step): |
|
887 |
previous_block.RemoveOutput() |
|
888 |
self.RefreshStepModel(previous_block) |
|
889 |
elif isinstance(previous_block, SFC_Divergence): |
|
890 |
if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
891 |
previous_block.RemoveBranch(previous_connector) |
|
892 |
if previous_block.GetBranchNumber() < 2: |
|
893 |
self.DeleteDivergence(previous_block) |
|
894 |
else: |
|
895 |
self.RefreshDivergenceModel(previous_block) |
|
896 |
else: |
|
897 |
self.DeleteDivergence(previous_block) |
|
898 |
divergence.Clean() |
|
899 |
self.RemoveBlock(divergence) |
|
900 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
901 |
if next: |
|
902 |
wire = self.ConnectConnectors(next, previous) |
|
903 |
previous_block = previous.GetParentBlock() |
|
904 |
previous_pos = previous.GetPosition(False) |
|
905 |
next_pos = next.GetPosition(False) |
|
906 |
wire_size = GetWireSize(previous_block) |
|
907 |
previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y)) |
|
908 |
wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), |
|
909 |
wx.Point(previous_pos.x, previous_pos.y)]) |
|
910 |
if isinstance(next_block, SFC_Divergence): |
|
911 |
next_block.RefreshPosition() |
|
912 |
previous_block.RefreshOutputModel(True) |
|
913 |
elif divergence.GetBranchNumber() == 1: |
|
914 |
wires = connectors["inputs"][0].GetWires() |
|
915 |
if len(wires) != 1: |
|
916 |
return |
|
917 |
wire = wires[0][0] |
|
918 |
previous = wire.EndConnected |
|
919 |
previous_block = previous.GetParentBlock() |
|
920 |
wire.Clean() |
|
921 |
self.RemoveWire(wire) |
|
922 |
wires = connectors["outputs"][0].GetWires() |
|
923 |
if len(wires) != 1: |
|
924 |
return |
|
925 |
wire = wires[0][0] |
|
926 |
next = wire.StartConnected |
|
927 |
next_block = next.GetParentBlock() |
|
928 |
wire.Clean() |
|
929 |
self.RemoveWire(wire) |
|
930 |
divergence.Clean() |
|
931 |
self.RemoveBlock(divergence) |
|
932 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
933 |
wire = self.ConnectConnectors(next, previous) |
|
934 |
previous_pos = previous.GetPosition(False) |
|
935 |
next_pos = next.GetPosition(False) |
|
936 |
wire_size = GetWireSize(previous_block) |
|
937 |
previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y)) |
|
938 |
wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), |
|
939 |
wx.Point(previous_pos.x, previous_pos.y)]) |
|
940 |
if isinstance(next_block, SFC_Divergence): |
|
941 |
next_block.RefreshPosition() |
|
942 |
previous_block.RefreshOutputModel(True) |
|
943 |
||
944 |
def DeleteJump(self, jump): |
|
945 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
946 |
Viewer.DeleteJump(self, jump) |
|
947 |
else: |
|
948 |
previous = jump.GetPreviousConnector() |
|
949 |
previous_block = previous.GetParentBlock() |
|
950 |
if isinstance(previous_block, SFC_Transition): |
|
951 |
self.RemoveTransition(previous_block) |
|
952 |
previous = jump.GetPreviousConnector() |
|
953 |
if previous: |
|
954 |
previous_block = previous.GetParentBlock() |
|
955 |
else: |
|
956 |
previous_block = None |
|
957 |
wires = previous.GetWires() |
|
958 |
if len(wires) != 1: |
|
959 |
return |
|
960 |
wire = wires[0][0] |
|
961 |
wire.Clean() |
|
962 |
self.RemoveWire(wire) |
|
963 |
jump.Clean() |
|
964 |
self.RemoveBlock(jump) |
|
965 |
self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId()) |
|
966 |
if isinstance(previous_block, SFC_Step): |
|
967 |
previous_block.RemoveOutput() |
|
968 |
self.RefreshStepModel(previous_block) |
|
969 |
elif isinstance(previous_block, SFC_Divergence): |
|
970 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
971 |
self.DeleteDivergence(previous_block) |
|
972 |
else: |
|
973 |
previous_block.RemoveBranch(previous) |
|
974 |
if previous_block.GetBranchNumber() < 2: |
|
975 |
self.DeleteDivergence(previous_block) |
|
976 |
else: |
|
977 |
previous_block.RefreshModel() |
|
978 |
||
979 |
def DeleteActionBlock(self, actionblock): |
|
980 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
981 |
Viewer.DeleteActionBlock(self, actionblock) |
|
982 |
else: |
|
983 |
connector = actionblock.GetConnector() |
|
984 |
wires = connector.GetWires() |
|
985 |
if len(wires) != 1: |
|
986 |
return |
|
987 |
wire = wires[0][0] |
|
988 |
step = wire.EndConnected.GetParentBlock() |
|
989 |
wire.Clean() |
|
990 |
self.RemoveWire(wire) |
|
991 |
actionblock.Clean() |
|
992 |
self.RemoveBlock(actionblock) |
|
993 |
self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId()) |
|
994 |
step.RemoveAction() |
|
995 |
self.RefreshStepModel(step) |
|
996 |
step.RefreshOutputPosition() |
|
997 |
step.RefreshOutputModel(True) |
|
998 |
||
999 |
def DeleteWire(self, wire): |
|
1000 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1001 |
Viewer.DeleteWire(self, wire) |
|
1002 |
||
1003 |
#------------------------------------------------------------------------------- |
|
1004 |
# Model update functions |
|
1005 |
#------------------------------------------------------------------------------- |
|
1006 |
||
1007 |
def RefreshBlockModel(self, block): |
|
1008 |
blockid = block.GetId() |
|
1009 |
infos = {} |
|
1010 |
infos["type"] = block.GetType() |
|
1011 |
infos["name"] = block.GetName() |
|
1012 |
infos["x"], infos["y"] = block.GetPosition() |
|
1013 |
infos["width"], infos["height"] = block.GetSize() |
|
1014 |
infos["connectors"] = block.GetConnectors() |
|
1015 |
self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos) |
|
1016 |