author | lbessard |
Fri, 04 Jan 2008 17:49:17 +0100 | |
changeset 144 | b67a5de5a24a |
parent 122 | e6faee0c271b |
child 145 | 4fb225afddf4 |
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 |
elif self.Mode == MODE_WIRE: |
27 | 226 |
pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
227 |
wire = Wire(self, [wx.Point(pos.x, pos.y), SOUTH], [wx.Point(pos.x, pos.y), NORTH]) |
0 | 228 |
wire.oldPos = pos |
229 |
wire.Handle = (HANDLE_POINT, 0) |
|
230 |
wire.ProcessDragging(0, 0) |
|
231 |
wire.Handle = (HANDLE_POINT, 1) |
|
42 | 232 |
self.AddWire(wire) |
0 | 233 |
if self.SelectedElement: |
234 |
self.SelectedElement.SetSelected(False) |
|
235 |
self.SelectedElement = wire |
|
236 |
event.Skip() |
|
237 |
||
238 |
def OnViewerLeftUp(self, event): |
|
27 | 239 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
240 |
Viewer.OnViewerLeftUp(self, event) |
|
241 |
elif self.rubberBand.IsShown(): |
|
0 | 242 |
if self.Mode == MODE_SELECTION: |
243 |
elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
|
27 | 244 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
0 | 245 |
if len(elements) > 0: |
246 |
self.SelectedElement = Graphic_Group(self) |
|
247 |
self.SelectedElement.SetElements(elements) |
|
248 |
self.SelectedElement.SetSelected(True) |
|
249 |
elif self.Mode == MODE_COMMENT: |
|
250 |
bbox = self.rubberBand.GetCurrentExtent() |
|
27 | 251 |
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
|
252 |
wx.CallAfter(self.AddComment, bbox) |
27 | 253 |
elif self.Mode == MODE_INITIALSTEP: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
254 |
wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)) |
0 | 255 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
42 | 256 |
if self.IsWire(self.SelectedElement): |
0 | 257 |
self.SelectedElement.SetSelectedSegment(0) |
258 |
else: |
|
27 | 259 |
self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
144 | 260 |
self.SelectedElement.Refresh() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
261 |
wx.CallAfter(self.SetCursor, wx.NullCursor) |
0 | 262 |
elif self.Mode == MODE_WIRE and self.SelectedElement: |
263 |
self.SelectedElement.ResetPoints() |
|
27 | 264 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
0 | 265 |
self.SelectedElement.GeneratePoints() |
266 |
self.SelectedElement.RefreshModel() |
|
267 |
self.SelectedElement.SetSelected(True) |
|
268 |
event.Skip() |
|
269 |
||
270 |
def OnViewerRightUp(self, event): |
|
27 | 271 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
272 |
Viewer.OnViewerRightUp(self, event) |
|
273 |
else: |
|
274 |
dc = self.GetLogicalDC() |
|
275 |
pos = event.GetLogicalPosition(dc) |
|
276 |
element = self.FindElement(pos) |
|
277 |
if element: |
|
278 |
if self.SelectedElement and self.SelectedElement != element: |
|
279 |
self.SelectedElement.SetSelected(False) |
|
280 |
self.SelectedElement = element |
|
42 | 281 |
if self.IsWire(self.SelectedElement): |
27 | 282 |
self.SelectedElement.SetSelectedSegment(0) |
283 |
else: |
|
284 |
self.SelectedElement.SetSelected(True) |
|
285 |
self.SelectedElement.OnRightUp(event, dc, self.Scaling) |
|
144 | 286 |
self.SelectedElement.Refresh() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
287 |
wx.CallAfter(self.SetCursor, wx.NullCursor) |
0 | 288 |
event.Skip() |
289 |
||
290 |
def OnViewerLeftDClick(self, event): |
|
27 | 291 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
292 |
Viewer.OnViewerLeftDClick(self, event) |
|
293 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
294 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
0 | 295 |
self.Refresh() |
296 |
event.Skip() |
|
297 |
||
298 |
def OnViewerMotion(self, event): |
|
27 | 299 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
300 |
Viewer.OnViewerMotion(self, event) |
|
71 | 301 |
else: |
302 |
if self.rubberBand.IsShown(): |
|
303 |
self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
304 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
305 |
if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group): |
|
306 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
144 | 307 |
self.SelectedElement.Refresh() |
71 | 308 |
elif self.Mode == MODE_WIRE and self.SelectedElement: |
309 |
self.SelectedElement.ResetPoints() |
|
27 | 310 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
71 | 311 |
self.SelectedElement.GeneratePoints() |
144 | 312 |
self.SelectedElement.Refresh() |
71 | 313 |
self.UpdateScrollPos(event) |
0 | 314 |
event.Skip() |
315 |
||
316 |
#------------------------------------------------------------------------------- |
|
317 |
# Keyboard event functions |
|
318 |
#------------------------------------------------------------------------------- |
|
319 |
||
320 |
def OnChar(self, event): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
0 | 324 |
keycode = event.GetKeyCode() |
325 |
if self.Scaling: |
|
326 |
scaling = self.Scaling |
|
327 |
else: |
|
328 |
scaling = (8, 8) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
329 |
if keycode == wx.WXK_DELETE and self.SelectedElement: |
0 | 330 |
self.SelectedElement.Delete() |
331 |
self.SelectedElement = None |
|
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() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
334 |
self.Refresh() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
335 |
elif keycode == wx.WXK_LEFT: |
42 | 336 |
if event.ControlDown() and event.ShiftDown(): |
337 |
self.Scroll(0, 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() |
144 | 345 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0))) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
346 |
elif keycode == wx.WXK_RIGHT: |
42 | 347 |
if event.ControlDown() and event.ShiftDown(): |
348 |
self.Scroll(xmax, ypos) |
|
349 |
elif event.ControlDown(): |
|
112 | 350 |
event.Skip() |
42 | 351 |
elif self.SelectedElement: |
352 |
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
|
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() |
144 | 356 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0))) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
357 |
elif keycode == wx.WXK_UP: |
42 | 358 |
if event.ControlDown() and event.ShiftDown(): |
359 |
self.Scroll(xpos, 0) |
|
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() |
144 | 367 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1]))) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
368 |
elif keycode == wx.WXK_DOWN: |
42 | 369 |
if event.ControlDown() and event.ShiftDown(): |
370 |
self.Scroll(xpos, ymax) |
|
371 |
elif event.ControlDown(): |
|
112 | 372 |
event.Skip() |
42 | 373 |
elif self.SelectedElement: |
374 |
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
|
375 |
self.SelectedElement.RefreshModel() |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
376 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
377 |
self.RefreshScrollBars() |
144 | 378 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1]))) |
112 | 379 |
else: |
380 |
event.Skip() |
|
0 | 381 |
|
382 |
#------------------------------------------------------------------------------- |
|
383 |
# Adding element functions |
|
384 |
#------------------------------------------------------------------------------- |
|
385 |
||
386 |
def AddInitialStep(self, pos): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
387 |
dialog = StepNameDialog(self.ParentWindow, "Add a new initial step", "Please enter step name", "", wx.OK|wx.CANCEL) |
9 | 388 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
121 | 389 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
9 | 390 |
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
|
391 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 392 |
id = self.GetNewId() |
393 |
name = dialog.GetValue() |
|
394 |
step = SFC_Step(self, name, True, id) |
|
395 |
min_width, min_height = step.GetMinSize() |
|
396 |
step.SetPosition(pos.x, pos.y) |
|
397 |
width, height = step.GetSize() |
|
398 |
step.SetSize(max(min_width, width), max(min_height, height)) |
|
42 | 399 |
self.AddBlock(step) |
121 | 400 |
self.Controler.AddEditedElementStep(self.TagName, id) |
0 | 401 |
self.RefreshStepModel(step) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
402 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
403 |
self.RefreshScrollBars() |
0 | 404 |
self.Refresh() |
405 |
dialog.Destroy() |
|
406 |
||
407 |
def AddStep(self): |
|
408 |
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
|
409 |
dialog = StepNameDialog(self.ParentWindow, "Add a new step", "Please enter step name", "", wx.OK|wx.CANCEL) |
9 | 410 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
121 | 411 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
9 | 412 |
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
|
413 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 414 |
name = dialog.GetValue() |
42 | 415 |
if self.IsWire(self.SelectedElement): |
0 | 416 |
self.SelectedElement.SetSelectedSegment(None) |
417 |
previous = self.SelectedElement.EndConnected |
|
418 |
next = self.SelectedElement.StartConnected |
|
419 |
self.SelectedElement.Clean() |
|
42 | 420 |
self.RemoveWire(self.SelectedElement) |
0 | 421 |
else: |
422 |
connectors = self.SelectedElement.GetConnectors() |
|
423 |
if connectors["output"]: |
|
424 |
previous = connectors["output"] |
|
425 |
wires = previous.GetWires() |
|
426 |
if len(wires) != 1: |
|
427 |
return |
|
428 |
wire = wires[0][0] |
|
429 |
next = wire.StartConnected |
|
430 |
wire.Clean() |
|
42 | 431 |
self.RemoveWire(wire) |
0 | 432 |
else: |
433 |
self.SelectedElement.AddOutput() |
|
434 |
connectors = self.SelectedElement.GetConnectors() |
|
435 |
self.RefreshStepModel(self.SelectedElement) |
|
436 |
previous = connectors["output"] |
|
437 |
next = None |
|
438 |
previous_block = previous.GetParentBlock() |
|
439 |
if isinstance(previous_block, SFC_Step) or isinstance(previous_block, SFC_Divergence) and previous_block.GetType() in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
440 |
transition = self.CreateTransition(previous) |
|
441 |
transition_connectors = transition.GetConnectors() |
|
442 |
step = self.CreateStep(name, transition_connectors["output"], next) |
|
443 |
else: |
|
444 |
step = self.CreateStep(name, previous) |
|
445 |
step.AddOutput() |
|
446 |
step.RefreshModel() |
|
447 |
step_connectors = step.GetConnectors() |
|
448 |
transition = self.CreateTransition(step_connectors["output"], next) |
|
42 | 449 |
if self.IsWire(self.SelectedElement): |
0 | 450 |
self.SelectedElement = wire |
451 |
self.SelectedElement.SetSelectedSegment(0) |
|
452 |
else: |
|
453 |
self.SelectedElement.SetSelected(False) |
|
454 |
self.SelectedElement = step |
|
455 |
self.SelectedElement.SetSelected(True) |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
456 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
457 |
self.RefreshScrollBars() |
0 | 458 |
self.Refresh() |
459 |
dialog.Destroy() |
|
460 |
||
461 |
def AddStepAction(self): |
|
462 |
if isinstance(self.SelectedElement, SFC_Step): |
|
463 |
connectors = self.SelectedElement.GetConnectors() |
|
464 |
if not connectors["action"]: |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
465 |
dialog = ActionBlockDialog(self.ParentWindow) |
0 | 466 |
dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
121 | 467 |
dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName)) |
468 |
dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
469 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 470 |
actions = dialog.GetValues() |
471 |
self.SelectedElement.AddAction() |
|
472 |
self.RefreshStepModel(self.SelectedElement) |
|
473 |
connectors = self.SelectedElement.GetConnectors() |
|
474 |
pos = connectors["action"].GetPosition(False) |
|
475 |
id = self.GetNewId() |
|
476 |
actionblock = SFC_ActionBlock(self, [], id) |
|
477 |
actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2) |
|
478 |
actionblock_connector = actionblock.GetConnector() |
|
479 |
wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
480 |
wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) |
0 | 481 |
actionblock.SetActions(actions) |
42 | 482 |
self.AddBlock(actionblock) |
121 | 483 |
self.Controler.AddEditedElementActionBlock(self.TagName, id) |
0 | 484 |
self.RefreshActionBlockModel(actionblock) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
485 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
486 |
self.RefreshScrollBars() |
0 | 487 |
self.Refresh() |
488 |
dialog.Destroy() |
|
489 |
||
490 |
def AddDivergence(self): |
|
491 |
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
|
492 |
dialog = DivergenceCreateDialog(self.ParentWindow) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
493 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 494 |
value = dialog.GetValues() |
495 |
if value["type"] == SELECTION_DIVERGENCE: |
|
496 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step): |
|
497 |
self.SelectedElement.SetSelectedSegment(None) |
|
498 |
previous = self.SelectedElement.EndConnected |
|
499 |
next = self.SelectedElement.StartConnected |
|
500 |
self.SelectedElement.Clean() |
|
42 | 501 |
self.RemoveWire(self.SelectedElement) |
0 | 502 |
self.SelectedElement = None |
503 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
504 |
connectors = self.SelectedElement.GetConnectors() |
|
505 |
if connectors["output"]: |
|
506 |
previous = connectors["output"] |
|
507 |
wires = previous.GetWires() |
|
508 |
if len(wires) != 1: |
|
509 |
return |
|
510 |
wire = wires[0][0] |
|
511 |
next = wire.StartConnected |
|
512 |
wire.Clean() |
|
42 | 513 |
self.RemoveWire(wire) |
0 | 514 |
else: |
515 |
self.SelectedElement.AddOutput() |
|
516 |
connectors = self.SelectedElement.GetConnectors() |
|
517 |
self.RefreshStepModel(self.SelectedElement) |
|
518 |
previous = connectors["output"] |
|
519 |
next = None |
|
520 |
else: |
|
521 |
return |
|
522 |
id = self.GetNewId() |
|
523 |
divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id) |
|
524 |
pos = previous.GetPosition(False) |
|
525 |
previous_block = previous.GetParentBlock() |
|
526 |
wire_size = GetWireSize(previous_block) |
|
527 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
528 |
divergence_connectors = divergence.GetConnectors() |
|
529 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
530 |
previous_block.RefreshOutputPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
531 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
42 | 532 |
self.AddBlock(divergence) |
121 | 533 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
0 | 534 |
self.RefreshDivergenceModel(divergence) |
535 |
for index, connector in enumerate(divergence_connectors["outputs"]): |
|
536 |
if next: |
|
537 |
wire = self.ConnectConnectors(next, connector) |
|
538 |
pos = connector.GetPosition(False) |
|
539 |
next_pos = next.GetPosition(False) |
|
540 |
next_block = next.GetParentBlock() |
|
541 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
542 |
divergence.RefreshConnectedPosition(connector) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
543 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
0 | 544 |
next_block.RefreshModel() |
545 |
next = None |
|
546 |
else: |
|
547 |
transition = self.CreateTransition(connector) |
|
548 |
transition_connectors = transition.GetConnectors() |
|
549 |
step = self.CreateStep("Step", transition_connectors["output"]) |
|
550 |
elif value["type"] == SIMULTANEOUS_DIVERGENCE: |
|
551 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Transition): |
|
552 |
self.SelectedElement.SetSelectedSegment(None) |
|
553 |
previous = self.SelectedElement.EndConnected |
|
554 |
next = self.SelectedElement.StartConnected |
|
555 |
self.SelectedElement.Clean() |
|
42 | 556 |
self.RemoveWire(self.SelectedElement) |
0 | 557 |
self.SelectedElement = None |
558 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
559 |
connectors = self.SelectedElement.GetConnectors() |
|
560 |
if connectors["output"]: |
|
561 |
previous = connectors["output"] |
|
562 |
wires = previous.GetWires() |
|
563 |
if len(wires) != 1: |
|
564 |
return |
|
565 |
wire = wires[0][0] |
|
566 |
next = wire.StartConnected |
|
567 |
wire.Clean() |
|
42 | 568 |
self.RemoveWire(wire) |
0 | 569 |
else: |
570 |
self.SelectedElement.AddOutput() |
|
571 |
connectors = self.SelectedElement.GetConnectors() |
|
572 |
self.RefreshStepModel(self.SelectedElement) |
|
573 |
previous = connectors["output"] |
|
574 |
next = None |
|
575 |
transition = self.CreateTransition(previous) |
|
576 |
transition_connectors = transition.GetConnectors() |
|
577 |
previous = transition_connectors["output"] |
|
578 |
else: |
|
579 |
return |
|
580 |
id = self.GetNewId() |
|
581 |
divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id) |
|
582 |
pos = previous.GetPosition(False) |
|
583 |
previous_block = previous.GetParentBlock() |
|
584 |
wire_size = GetWireSize(previous_block) |
|
585 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
586 |
divergence_connectors = divergence.GetConnectors() |
|
587 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
588 |
previous_block.RefreshOutputPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
589 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
42 | 590 |
self.AddBlock(divergence) |
121 | 591 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
0 | 592 |
self.RefreshDivergenceModel(divergence) |
593 |
for index, connector in enumerate(divergence_connectors["outputs"]): |
|
594 |
if next: |
|
595 |
wire = self.ConnectConnectors(next, connector) |
|
596 |
pos = connector.GetPosition(False) |
|
597 |
next_pos = next.GetPosition(False) |
|
598 |
next_block = next.GetParentBlock() |
|
599 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
600 |
divergence.RefreshConnectedPosition(connector) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
601 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
0 | 602 |
next_block.RefreshModel() |
603 |
next = None |
|
604 |
else: |
|
605 |
step = self.CreateStep("Step", connector) |
|
606 |
elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1: |
|
607 |
next = None |
|
608 |
for element in self.SelectedElement.GetElements(): |
|
609 |
connectors = element.GetConnectors() |
|
610 |
if not isinstance(element, SFC_Step) or connectors["output"] and next: |
|
611 |
return |
|
612 |
elif connectors["output"] and not next: |
|
613 |
wires = connectors["output"].GetWires() |
|
614 |
if len(wires) != 1: |
|
615 |
return |
|
616 |
if value["type"] == SELECTION_CONVERGENCE: |
|
617 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
618 |
transition_connectors = transition.GetConnectors() |
|
619 |
wires = transition_connectors["output"].GetWires() |
|
620 |
if len(wires) != 1: |
|
621 |
return |
|
622 |
wire = wires[0][0] |
|
623 |
next = wire.StartConnected |
|
624 |
wire.Clean() |
|
42 | 625 |
self.RemoveWire(wire) |
0 | 626 |
inputs = [] |
627 |
for input in self.SelectedElement.GetElements(): |
|
628 |
input_connectors = input.GetConnectors() |
|
629 |
if not input_connectors["output"]: |
|
630 |
input.AddOutput() |
|
631 |
input.RefreshModel() |
|
632 |
input_connectors = input.GetConnectors() |
|
633 |
if value["type"] == SELECTION_CONVERGENCE: |
|
634 |
transition = self.CreateTransition(input_connectors["output"]) |
|
635 |
transition_connectors = transition.GetConnectors() |
|
636 |
inputs.append(transition_connectors["output"]) |
|
637 |
else: |
|
638 |
inputs.append(input_connectors["output"]) |
|
639 |
elif value["type"] == SELECTION_CONVERGENCE: |
|
640 |
wires = input_connectors["output"].GetWires() |
|
641 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
642 |
transition_connectors = transition.GetConnectors() |
|
643 |
inputs.append(transition_connectors["output"]) |
|
644 |
else: |
|
645 |
inputs.append(input_connectors["output"]) |
|
646 |
id = self.GetNewId() |
|
647 |
divergence = SFC_Divergence(self, value["type"], len(inputs), id) |
|
648 |
pos = inputs[0].GetPosition(False) |
|
649 |
divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
650 |
divergence_connectors = divergence.GetConnectors() |
|
651 |
for i, input in enumerate(inputs): |
|
652 |
pos = input.GetPosition(False) |
|
653 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input) |
|
654 |
wire_size = GetWireSize(input) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
655 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
0 | 656 |
input_block = input.GetParentBlock() |
657 |
input_block.RefreshOutputPosition() |
|
658 |
divergence.RefreshPosition() |
|
659 |
pos = divergence_connectors["outputs"][0].GetRelPosition() |
|
660 |
divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) |
|
42 | 661 |
self.AddBlock(divergence) |
121 | 662 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
0 | 663 |
self.RefreshDivergenceModel(divergence) |
664 |
if next: |
|
665 |
wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) |
|
666 |
pos = divergence_connectors["outputs"][0].GetPosition(False) |
|
667 |
next_pos = next.GetPosition(False) |
|
668 |
next_block = next.GetParentBlock() |
|
669 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
670 |
divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0]) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
671 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
0 | 672 |
next_block.RefreshModel() |
673 |
else: |
|
674 |
if value["type"] == SELECTION_CONVERGENCE: |
|
675 |
previous = divergence_connectors["outputs"][0] |
|
676 |
else: |
|
677 |
transition = self.CreateTransition(divergence_connectors["outputs"][0]) |
|
678 |
transition_connectors = transition.GetConnectors() |
|
679 |
previous = transition_connectors["output"] |
|
680 |
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 |
dialog.Destroy() |
|
685 |
||
686 |
def AddDivergenceBranch(self, divergence): |
|
687 |
if isinstance(divergence, SFC_Divergence): |
|
80 | 688 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
0 | 689 |
divergence.AddBranch() |
80 | 690 |
else: |
691 |
type = divergence.GetType() |
|
692 |
if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
693 |
divergence.AddBranch() |
|
694 |
divergence_connectors = divergence.GetConnectors() |
|
695 |
if type == SELECTION_DIVERGENCE: |
|
696 |
transition = self.CreateTransition(divergence_connectors["outputs"][-1]) |
|
697 |
transition_connectors = transition.GetConnectors() |
|
698 |
previous = transition_connectors["output"] |
|
699 |
else: |
|
700 |
previous = divergence_connectors["outputs"][-1] |
|
701 |
step = self.CreateStep("Step", previous) |
|
702 |
self.RefreshBuffer() |
|
703 |
self.RefreshScrollBars() |
|
704 |
self.Refresh() |
|
705 |
||
706 |
def RemoveDivergenceBranch(self, divergence): |
|
707 |
if isinstance(divergence, SFC_Divergence): |
|
708 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
709 |
divergence.RemoveHandledBranch() |
|
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 |
||
714 |
def AddJump(self): |
|
715 |
if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output: |
|
716 |
choices = [] |
|
717 |
for block in self.Blocks: |
|
718 |
if isinstance(block, SFC_Step): |
|
719 |
choices.append(block.GetName()) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
720 |
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
|
721 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 722 |
value = dialog.GetStringSelection() |
723 |
self.SelectedElement.AddOutput() |
|
724 |
self.RefreshStepModel(self.SelectedElement) |
|
725 |
step_connectors = self.SelectedElement.GetConnectors() |
|
726 |
transition = self.CreateTransition(step_connectors["output"]) |
|
727 |
transition_connectors = transition.GetConnectors() |
|
728 |
id = self.GetNewId() |
|
729 |
jump = SFC_Jump(self, value, id) |
|
730 |
pos = transition_connectors["output"].GetPosition(False) |
|
731 |
jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
42 | 732 |
self.AddBlock(jump) |
121 | 733 |
self.Controler.AddEditedElementJump(self.TagName, id) |
0 | 734 |
jump_connector = jump.GetConnector() |
735 |
wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) |
|
736 |
transition.RefreshOutputPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
737 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
0 | 738 |
self.RefreshJumpModel(jump) |
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
739 |
self.RefreshBuffer() |
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
45
diff
changeset
|
740 |
self.RefreshScrollBars() |
0 | 741 |
self.Refresh() |
742 |
dialog.Destroy() |
|
743 |
||
744 |
def EditStepContent(self, step): |
|
71 | 745 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
746 |
Viewer.EditStepContent(self, step) |
|
747 |
else: |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
748 |
dialog = StepNameDialog(self.ParentWindow, "Edit step name", "Please enter step name", step.GetName(), wx.OK|wx.CANCEL) |
71 | 749 |
dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
121 | 750 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
71 | 751 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
752 |
if dialog.ShowModal() == wx.ID_OK: |
|
753 |
value = dialog.GetValue() |
|
754 |
step.SetName(value) |
|
755 |
min_size = step.GetMinSize() |
|
756 |
size = step.GetSize() |
|
757 |
step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1])) |
|
758 |
step.RefreshModel() |
|
759 |
self.RefreshBuffer() |
|
760 |
self.RefreshScrollBars() |
|
761 |
self.Refresh() |
|
762 |
dialog.Destroy() |
|
0 | 763 |
|
764 |
#------------------------------------------------------------------------------- |
|
765 |
# Delete element functions |
|
766 |
#------------------------------------------------------------------------------- |
|
767 |
||
768 |
def DeleteStep(self, step): |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
769 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
770 |
Viewer.DeleteStep(self, step) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
771 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
772 |
step_connectors = step.GetConnectors() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
773 |
if not step.GetInitial() or not step_connectors["output"]: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
774 |
previous = step.GetPreviousConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
775 |
if previous: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
776 |
previous_block = previous.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
777 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
778 |
previous_block = None |
0 | 779 |
next = step.GetNextConnector() |
780 |
if next: |
|
781 |
next_block = next.GetParentBlock() |
|
782 |
else: |
|
783 |
next_block = None |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
784 |
if isinstance(next_block, SFC_Transition): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
785 |
self.RemoveTransition(next_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
786 |
next = step.GetNextConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
787 |
if next: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
788 |
next_block = next.GetParentBlock() |
0 | 789 |
else: |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
790 |
next_block = None |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
791 |
elif isinstance(previous_block, SFC_Transition): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
792 |
self.RemoveTransition(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
793 |
previous = step.GetPreviousConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
794 |
if previous: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
795 |
previous_block = previous.GetParentBlock() |
0 | 796 |
else: |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
797 |
previous_block = None |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
798 |
wire = self.RemoveStep(step) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
799 |
self.SelectedElement = None |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
800 |
if next_block: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
801 |
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
|
802 |
wire.Clean() |
42 | 803 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
804 |
next_block.RemoveBranch(next) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
805 |
if next_block.GetBranchNumber() < 2: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
806 |
self.DeleteDivergence(next_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
807 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
808 |
next_block.RefreshModel() |
0 | 809 |
previous_block.RemoveBranch(previous) |
810 |
if previous_block.GetBranchNumber() < 2: |
|
811 |
self.DeleteDivergence(previous_block) |
|
812 |
else: |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
813 |
previous_block.RefreshModel() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
814 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
815 |
pos = previous.GetPosition(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
816 |
next_pos = next.GetPosition(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
817 |
wire_size = GetWireSize(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
818 |
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
|
819 |
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
|
820 |
if isinstance(next_block, SFC_Divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
821 |
next_block.RefreshPosition() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
822 |
previous_block.RefreshOutputModel(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
823 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
824 |
if isinstance(previous_block, SFC_Step): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
825 |
previous_block.RemoveOutput() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
826 |
self.RefreshStepModel(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
827 |
elif isinstance(previous_block, SFC_Divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
828 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
829 |
self.DeleteDivergence(previous_block) |
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_block.RemoveBranch(previous) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
832 |
if previous_block.GetBranchNumber() < 2: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
833 |
self.DeleteDivergence(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
834 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
835 |
self.RefreshDivergenceModel(previous_block) |
0 | 836 |
|
837 |
def DeleteTransition(self, transition): |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
838 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
839 |
Viewer.DeleteTransition(self, transition) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
840 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
841 |
previous = transition.GetPreviousConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
842 |
previous_block = previous.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
843 |
next = transition.GetNextConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
844 |
next_block = next.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
845 |
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
|
846 |
wires = previous.GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
847 |
if len(wires) != 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
848 |
return |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
849 |
wire = wires[0][0] |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
850 |
wire.Clean() |
42 | 851 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
852 |
wires = next.GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
853 |
if len(wires) != 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
854 |
return |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
855 |
wire = wires[0][0] |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
856 |
wire.Clean() |
42 | 857 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
858 |
transition.Clean() |
44 | 859 |
self.RemoveBlock(transition) |
121 | 860 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
861 |
previous_block.RemoveBranch(previous) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
862 |
if previous_block.GetBranchNumber() < 2: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
863 |
self.DeleteDivergence(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
864 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
865 |
self.RefreshDivergenceModel(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
866 |
next_block.RemoveBranch(next) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
867 |
if next_block.GetBranchNumber() < 2: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
868 |
self.DeleteDivergence(next_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
869 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
870 |
self.RefreshDivergenceModel(next_block) |
80 | 871 |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
872 |
def DeleteDivergence(self, divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
873 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
874 |
Viewer.DeleteDivergence(self, divergence) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
875 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
876 |
connectors = divergence.GetConnectors() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
877 |
type = divergence.GetType() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
878 |
if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
879 |
wires = connectors["outputs"][0].GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
880 |
if len(wires) > 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
881 |
return |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
882 |
elif len(wires) == 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
883 |
next = wires[0][0].StartConnected |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
884 |
next_block = next.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
885 |
wire = wires[0][0] |
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 |
next = None |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
890 |
next_block = None |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
891 |
for index, connector in enumerate(connectors["inputs"]): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
892 |
if next and index == 0: |
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 = wires[0][0].EndConnected |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
896 |
wire.Clean() |
42 | 897 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
898 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
899 |
if type == SELECTION_CONVERGENCE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
900 |
wires = connector.GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
901 |
previous_block = wires[0][0].EndConnected.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
902 |
self.RemoveTransition(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
903 |
wires = connector.GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
904 |
wire = wires[0][0] |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
905 |
previous_connector = wire.EndConnected |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
906 |
previous_block = previous_connector.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
907 |
wire.Clean() |
42 | 908 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
909 |
if isinstance(previous_block, SFC_Step): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
910 |
previous_block.RemoveOutput() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
911 |
self.RefreshStepModel(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
912 |
elif isinstance(previous_block, SFC_Divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
913 |
if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
914 |
previous_block.RemoveBranch(previous_connector) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
915 |
if previous_block.GetBranchNumber() < 2: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
916 |
self.DeleteDivergence(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
917 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
918 |
self.RefreshDivergenceModel(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
919 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
920 |
self.DeleteDivergence(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
921 |
divergence.Clean() |
44 | 922 |
self.RemoveBlock(divergence) |
121 | 923 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
924 |
if next: |
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_block = previous.GetParentBlock() |
45 | 927 |
previous_pos = previous.GetPosition(False) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
928 |
next_pos = next.GetPosition(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
929 |
wire_size = GetWireSize(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
930 |
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
|
931 |
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
|
932 |
wx.Point(previous_pos.x, previous_pos.y)]) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
933 |
if isinstance(next_block, SFC_Divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
934 |
next_block.RefreshPosition() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
935 |
previous_block.RefreshOutputModel(True) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
936 |
elif divergence.GetBranchNumber() == 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
937 |
wires = connectors["inputs"][0].GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
938 |
if len(wires) != 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
939 |
return |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
940 |
wire = wires[0][0] |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
941 |
previous = wire.EndConnected |
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 |
wire.Clean() |
42 | 944 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
945 |
wires = connectors["outputs"][0].GetWires() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
946 |
if len(wires) != 1: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
947 |
return |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
948 |
wire = wires[0][0] |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
949 |
next = wire.StartConnected |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
950 |
next_block = next.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
951 |
wire.Clean() |
42 | 952 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
953 |
divergence.Clean() |
44 | 954 |
self.RemoveBlock(divergence) |
121 | 955 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
956 |
wire = self.ConnectConnectors(next, previous) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
957 |
previous_pos = previous.GetPosition(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
958 |
next_pos = next.GetPosition(False) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
959 |
wire_size = GetWireSize(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
960 |
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
|
961 |
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
|
962 |
wx.Point(previous_pos.x, previous_pos.y)]) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
963 |
if isinstance(next_block, SFC_Divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
964 |
next_block.RefreshPosition() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
965 |
previous_block.RefreshOutputModel(True) |
80 | 966 |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
967 |
def DeleteJump(self, jump): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
968 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
969 |
Viewer.DeleteJump(self, jump) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
970 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
971 |
previous = jump.GetPreviousConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
972 |
previous_block = previous.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
973 |
if isinstance(previous_block, SFC_Transition): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
974 |
self.RemoveTransition(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
975 |
previous = jump.GetPreviousConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
976 |
if previous: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
977 |
previous_block = previous.GetParentBlock() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
978 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
979 |
previous_block = None |
0 | 980 |
wires = previous.GetWires() |
981 |
if len(wires) != 1: |
|
982 |
return |
|
983 |
wire = wires[0][0] |
|
984 |
wire.Clean() |
|
42 | 985 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
986 |
jump.Clean() |
44 | 987 |
self.RemoveBlock(jump) |
121 | 988 |
self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
989 |
if isinstance(previous_block, SFC_Step): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
990 |
previous_block.RemoveOutput() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
991 |
self.RefreshStepModel(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
992 |
elif isinstance(previous_block, SFC_Divergence): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
993 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
994 |
self.DeleteDivergence(previous_block) |
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 |
previous_block.RemoveBranch(previous) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
997 |
if previous_block.GetBranchNumber() < 2: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
998 |
self.DeleteDivergence(previous_block) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
999 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1000 |
previous_block.RefreshModel() |
80 | 1001 |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1002 |
def DeleteActionBlock(self, actionblock): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1003 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1004 |
Viewer.DeleteActionBlock(self, actionblock) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1005 |
else: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1006 |
connector = actionblock.GetConnector() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1007 |
wires = connector.GetWires() |
0 | 1008 |
if len(wires) != 1: |
1009 |
return |
|
1010 |
wire = wires[0][0] |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1011 |
step = wire.EndConnected.GetParentBlock() |
0 | 1012 |
wire.Clean() |
42 | 1013 |
self.RemoveWire(wire) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1014 |
actionblock.Clean() |
44 | 1015 |
self.RemoveBlock(actionblock) |
121 | 1016 |
self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId()) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1017 |
step.RemoveAction() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1018 |
self.RefreshStepModel(step) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1019 |
step.RefreshOutputPosition() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1020 |
step.RefreshOutputModel(True) |
80 | 1021 |
|
0 | 1022 |
def DeleteWire(self, wire): |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1023 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
1024 |
Viewer.DeleteWire(self, wire) |
122
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1025 |
|
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1026 |
#------------------------------------------------------------------------------- |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1027 |
# Model update functions |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1028 |
#------------------------------------------------------------------------------- |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1029 |
|
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1030 |
def RefreshBlockModel(self, block): |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1031 |
blockid = block.GetId() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1032 |
infos = {} |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1033 |
infos["type"] = block.GetType() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1034 |
infos["name"] = block.GetName() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1035 |
infos["x"], infos["y"] = block.GetPosition() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1036 |
infos["width"], infos["height"] = block.GetSize() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1037 |
infos["connectors"] = block.GetConnectors() |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1038 |
self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos) |
e6faee0c271b
Adding support for Project Tree selected item following current item edited.
lbessard
parents:
121
diff
changeset
|
1039 |