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