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