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