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