author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Mon, 28 Nov 2016 16:12:27 +0300 | |
changeset 1579 | 418e6bac22e8 |
parent 1571 | 486f94a8032c |
child 1584 | 431f4ef34bde |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1567
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
from types import * |
|
26 |
||
27 |
import wx |
|
28 |
||
29 |
from Viewer import * |
|
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
30 |
from graphics.SFC_Objects import * |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
31 |
from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
32 |
SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE, EAST, NORTH, WEST, SOUTH |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
33 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
34 |
type = [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
35 |
divergence = dict(zip(type,["SELECTION_DIVERGENCE", "SELECTION_CONVERGENCE",\ |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
36 |
"SIMULTANEOUS_DIVERGENCE", "SIMULTANEOUS_CONVERGENCE"])) |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
37 |
SFC_Objects = (SFC_Step, SFC_ActionBlock, SFC_Transition, SFC_Divergence, SFC_Jump) |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
38 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
39 |
StandardRules = { |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
40 |
# The key of this dict is a block that user try to connect, |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
41 |
# and the value is a list of blocks, that can be connected with the current block. |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
42 |
"SFC_Step" : ["SFC_ActionBlock", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
43 |
"SFC_Transition", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
44 |
"SELECTION_DIVERGENCE", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
45 |
"SIMULTANEOUS_CONVERGENCE"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
46 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
47 |
"SFC_ActionBlock" : ["SFC_Step"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
48 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
49 |
"SFC_Transition" : ["SFC_Step", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
50 |
"SELECTION_CONVERGENCE", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
51 |
"SIMULTANEOUS_DIVERGENCE", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
52 |
"SFC_Jump", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
53 |
"FBD_Block", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
54 |
"FBD_Variable" |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
55 |
"LD_Contact", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
56 |
"LD_PowerRail", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
57 |
"LD_Coil"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
58 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
59 |
"SELECTION_DIVERGENCE" : ["SFC_Transition"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
60 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
61 |
"SELECTION_CONVERGENCE" : ["SFC_Step", |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
62 |
"SFC_Jump"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
63 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
64 |
"SIMULTANEOUS_DIVERGENCE" : ["SFC_Step"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
65 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
66 |
"SIMULTANEOUS_CONVERGENCE" : ["SFC_Transition"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
67 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
68 |
"SFC_Jump" : [], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
69 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
70 |
"FBD_Block" : ["SFC_Transition"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
71 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
72 |
"FBD_Variable" : ["SFC_Transition"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
73 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
74 |
"LD_Contact" : ["SFC_Transition"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
75 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
76 |
"LD_PowerRail" : ["SFC_Transition"], |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
77 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
78 |
"LD_Coil" : ["SFC_Transition"] |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
79 |
} |
814 | 80 |
|
81 |
class SFC_Viewer(Viewer): |
|
82 |
||
83 |
def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""): |
|
84 |
Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath) |
|
85 |
self.CurrentLanguage = "SFC" |
|
86 |
||
87 |
def ConnectConnectors(self, start, end): |
|
88 |
startpoint = [start.GetPosition(False), start.GetDirection()] |
|
89 |
endpoint = [end.GetPosition(False), end.GetDirection()] |
|
90 |
wire = Wire(self, startpoint, endpoint) |
|
91 |
self.AddWire(wire) |
|
92 |
start.Connect((wire, 0), False) |
|
93 |
end.Connect((wire, -1), False) |
|
94 |
wire.ConnectStartPoint(None, start) |
|
95 |
wire.ConnectEndPoint(None, end) |
|
96 |
return wire |
|
97 |
||
98 |
def CreateTransition(self, connector, next = None): |
|
99 |
previous = connector.GetParentBlock() |
|
100 |
id = self.GetNewId() |
|
101 |
transition = SFC_Transition(self, "reference", "", 0, id) |
|
102 |
pos = connector.GetPosition(False) |
|
103 |
transition.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
104 |
transition_connectors = transition.GetConnectors() |
|
105 |
wire = self.ConnectConnectors(transition_connectors["input"], connector) |
|
106 |
if isinstance(previous, SFC_Divergence): |
|
107 |
previous.RefreshConnectedPosition(connector) |
|
108 |
else: |
|
109 |
previous.RefreshOutputPosition() |
|
110 |
wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
|
111 |
self.AddBlock(transition) |
|
112 |
self.Controler.AddEditedElementTransition(self.TagName, id) |
|
113 |
self.RefreshTransitionModel(transition) |
|
114 |
if next: |
|
115 |
wire = self.ConnectConnectors(next, transition_connectors["output"]) |
|
116 |
pos = transition_connectors["output"].GetPosition(False) |
|
117 |
next_block = next.GetParentBlock() |
|
118 |
next_pos = next.GetPosition(False) |
|
119 |
transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
120 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
121 |
if isinstance(next_block, SFC_Divergence): |
|
122 |
next_block.RefreshPosition() |
|
123 |
transition.RefreshOutputModel(True) |
|
124 |
return transition |
|
125 |
||
126 |
def RemoveTransition(self, transition): |
|
127 |
connectors = transition.GetConnectors() |
|
128 |
input_wires = connectors["input"].GetWires() |
|
129 |
if len(input_wires) != 1: |
|
130 |
return |
|
131 |
input_wire = input_wires[0][0] |
|
132 |
previous = input_wire.EndConnected |
|
133 |
input_wire.Clean() |
|
134 |
self.RemoveWire(input_wire) |
|
135 |
output_wires = connectors["output"].GetWires() |
|
136 |
if len(output_wires) != 1: |
|
137 |
return |
|
138 |
output_wire = output_wires[0][0] |
|
139 |
next = output_wire.StartConnected |
|
140 |
output_wire.Clean() |
|
141 |
self.RemoveWire(output_wire) |
|
142 |
transition.Clean() |
|
143 |
self.RemoveBlock(transition) |
|
144 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
145 |
wire = self.ConnectConnectors(next, previous) |
|
146 |
return wire |
|
147 |
||
148 |
def CreateStep(self, name, connector, next = None): |
|
149 |
previous = connector.GetParentBlock() |
|
150 |
id = self.GetNewId() |
|
151 |
step = SFC_Step(self, name, False, id) |
|
152 |
if next: |
|
153 |
step.AddOutput() |
|
154 |
min_width, min_height = step.GetMinSize() |
|
155 |
pos = connector.GetPosition(False) |
|
156 |
step.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
157 |
step.SetSize(min_width, min_height) |
|
158 |
step_connectors = step.GetConnectors() |
|
159 |
wire = self.ConnectConnectors(step_connectors["input"], connector) |
|
160 |
if isinstance(previous, SFC_Divergence): |
|
161 |
previous.RefreshConnectedPosition(connector) |
|
162 |
else: |
|
163 |
previous.RefreshOutputPosition() |
|
164 |
wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)]) |
|
165 |
self.AddBlock(step) |
|
166 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
167 |
self.RefreshStepModel(step) |
|
168 |
if next: |
|
169 |
wire = self.ConnectConnectors(next, step_connectors["output"]) |
|
170 |
pos = step_connectors["output"].GetPosition(False) |
|
171 |
next_block = next.GetParentBlock() |
|
172 |
next_pos = next.GetPosition(False) |
|
173 |
step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
174 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
175 |
if isinstance(next_block, SFC_Divergence): |
|
176 |
next_block.RefreshPosition() |
|
177 |
step.RefreshOutputModel(True) |
|
178 |
return step |
|
179 |
||
180 |
def RemoveStep(self, step): |
|
181 |
connectors = step.GetConnectors() |
|
182 |
if connectors["input"]: |
|
183 |
input_wires = connectors["input"].GetWires() |
|
184 |
if len(input_wires) != 1: |
|
185 |
return |
|
186 |
input_wire = input_wires[0][0] |
|
187 |
previous = input_wire.EndConnected |
|
188 |
input_wire.Clean() |
|
189 |
self.RemoveWire(input_wire) |
|
190 |
else: |
|
191 |
previous = None |
|
192 |
if connectors["output"]: |
|
193 |
output_wires = connectors["output"].GetWires() |
|
194 |
if len(output_wires) != 1: |
|
195 |
return |
|
196 |
output_wire = output_wires[0][0] |
|
197 |
next = output_wire.StartConnected |
|
198 |
output_wire.Clean() |
|
199 |
self.RemoveWire(output_wire) |
|
200 |
else: |
|
201 |
next = None |
|
202 |
action = step.GetActionConnected() |
|
203 |
if action: |
|
204 |
self.DeleteActionBlock(action.GetParentBlock()) |
|
205 |
step.Clean() |
|
206 |
self.RemoveBlock(step) |
|
207 |
self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId()) |
|
208 |
if next and previous: |
|
209 |
wire = self.ConnectConnectors(next, previous) |
|
210 |
return wire |
|
211 |
else: |
|
212 |
return None |
|
213 |
||
214 |
#------------------------------------------------------------------------------- |
|
215 |
# Mouse event functions |
|
216 |
#------------------------------------------------------------------------------- |
|
217 |
||
218 |
def OnViewerLeftDown(self, event): |
|
219 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
220 |
Viewer.OnViewerLeftDown(self, event) |
|
221 |
elif self.Mode == MODE_SELECTION: |
|
222 |
if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None: |
|
223 |
element = self.FindElement(event, True) |
|
224 |
if element and not self.IsWire(element): |
|
225 |
if isinstance(self.SelectedElement, Graphic_Group): |
|
226 |
self.SelectedElement.SelectElement(element) |
|
227 |
else: |
|
228 |
group = Graphic_Group(self) |
|
229 |
self.SelectedElement.SetSelected(False) |
|
230 |
group.SelectElement(self.SelectedElement) |
|
231 |
group.SelectElement(element) |
|
232 |
self.SelectedElement = group |
|
233 |
elements = self.SelectedElement.GetElements() |
|
234 |
if len(elements) == 0: |
|
235 |
self.SelectedElement = element |
|
236 |
elif len(elements) == 1: |
|
237 |
self.SelectedElement = elements[0] |
|
238 |
self.SelectedElement.SetSelected(True) |
|
239 |
else: |
|
240 |
element = self.FindElement(event) |
|
241 |
if self.SelectedElement and self.SelectedElement != element: |
|
242 |
if self.IsWire(self.SelectedElement): |
|
243 |
self.SelectedElement.SetSelectedSegment(None) |
|
244 |
else: |
|
245 |
self.SelectedElement.SetSelected(False) |
|
246 |
self.SelectedElement = None |
|
247 |
if element: |
|
248 |
self.SelectedElement = element |
|
249 |
self.SelectedElement.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
250 |
self.SelectedElement.Refresh() |
|
251 |
else: |
|
252 |
self.rubberBand.Reset() |
|
253 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
254 |
elif self.Mode == MODE_COMMENT: |
|
255 |
self.rubberBand.Reset() |
|
256 |
self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling) |
|
257 |
event.Skip() |
|
258 |
||
259 |
def OnViewerLeftUp(self, event): |
|
260 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
261 |
Viewer.OnViewerLeftUp(self, event) |
|
262 |
elif self.rubberBand.IsShown(): |
|
263 |
if self.Mode == MODE_SELECTION: |
|
264 |
elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) |
|
265 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
266 |
if len(elements) > 0: |
|
267 |
self.SelectedElement = Graphic_Group(self) |
|
268 |
self.SelectedElement.SetElements(elements) |
|
269 |
self.SelectedElement.SetSelected(True) |
|
270 |
elif self.Mode == MODE_COMMENT: |
|
271 |
bbox = self.rubberBand.GetCurrentExtent() |
|
272 |
self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
273 |
wx.CallAfter(self.AddComment, bbox) |
|
274 |
elif self.Mode == MODE_INITIALSTEP: |
|
275 |
wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)) |
|
276 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
277 |
if self.IsWire(self.SelectedElement): |
|
278 |
self.SelectedElement.SetSelectedSegment(0) |
|
279 |
else: |
|
280 |
self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling) |
|
281 |
self.SelectedElement.Refresh() |
|
282 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
283 |
elif self.Mode == MODE_WIRE and self.SelectedElement: |
|
284 |
self.SelectedElement.ResetPoints() |
|
285 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
286 |
self.SelectedElement.GeneratePoints() |
|
287 |
self.SelectedElement.RefreshModel() |
|
288 |
self.SelectedElement.SetSelected(True) |
|
289 |
event.Skip() |
|
290 |
||
291 |
def OnViewerRightUp(self, event): |
|
292 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
293 |
Viewer.OnViewerRightUp(self, event) |
|
294 |
else: |
|
295 |
element = self.FindElement(event) |
|
296 |
if element: |
|
297 |
if self.SelectedElement and self.SelectedElement != element: |
|
298 |
self.SelectedElement.SetSelected(False) |
|
299 |
self.SelectedElement = element |
|
300 |
if self.IsWire(self.SelectedElement): |
|
301 |
self.SelectedElement.SetSelectedSegment(0) |
|
302 |
else: |
|
303 |
self.SelectedElement.SetSelected(True) |
|
304 |
self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling) |
|
305 |
self.SelectedElement.Refresh() |
|
306 |
wx.CallAfter(self.SetCurrentCursor, 0) |
|
307 |
event.Skip() |
|
308 |
||
309 |
def OnViewerLeftDClick(self, event): |
|
310 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
311 |
Viewer.OnViewerLeftDClick(self, event) |
|
312 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
313 |
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling) |
|
314 |
self.Refresh(False) |
|
315 |
event.Skip() |
|
316 |
||
317 |
def OnViewerMotion(self, event): |
|
318 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
319 |
Viewer.OnViewerMotion(self, event) |
|
320 |
else: |
|
321 |
if self.rubberBand.IsShown(): |
|
322 |
self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
323 |
elif self.Mode == MODE_SELECTION and self.SelectedElement: |
|
324 |
if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group): |
|
325 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
326 |
self.SelectedElement.Refresh() |
|
327 |
elif self.Mode == MODE_WIRE and self.SelectedElement: |
|
328 |
self.SelectedElement.ResetPoints() |
|
329 |
self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling) |
|
330 |
self.SelectedElement.GeneratePoints() |
|
331 |
self.SelectedElement.Refresh() |
|
332 |
self.UpdateScrollPos(event) |
|
333 |
event.Skip() |
|
334 |
||
1567
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
335 |
def GetBlockName(self, block): |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
336 |
blockName = block.__class__.__name__ |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
337 |
if blockName == "SFC_Divergence": |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
338 |
blockName = divergence[block.Type] |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
339 |
return blockName |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
340 |
|
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
341 |
# This method check the IEC 61131-3 compatibility between two SFC blocks |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
342 |
def BlockCompatibility(self,startblock = None, endblock = None, direction = None): |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
343 |
if startblock!= None and endblock != None and (isinstance(startblock,SFC_Objects)\ |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
344 |
or isinstance(endblock,SFC_Objects)): |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
345 |
# Full "StandardRules" table would be simmetrical and |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
346 |
# to avoid duplicate records and minimize the table only upper part is defined. |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
347 |
if (direction == SOUTH or direction == EAST): |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
348 |
startblock, endblock = endblock, startblock |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
349 |
start = self.GetBlockName(startblock) |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
350 |
end = self.GetBlockName(endblock) |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
351 |
return end in StandardRules[start] |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
352 |
return True |
a4bf874e4949
now only correct chart can be created in SFC Viewer
Sergey Surkov <surkovsv93@gmail.com>
parents:
1347
diff
changeset
|
353 |
|
814 | 354 |
#------------------------------------------------------------------------------- |
355 |
# Keyboard event functions |
|
356 |
#------------------------------------------------------------------------------- |
|
357 |
||
358 |
def OnChar(self, event): |
|
359 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
360 |
Viewer.OnChar(self, event) |
|
361 |
else: |
|
362 |
xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL) |
|
363 |
xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL) |
|
364 |
ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL) |
|
365 |
keycode = event.GetKeyCode() |
|
366 |
if self.Scaling: |
|
367 |
scaling = self.Scaling |
|
368 |
else: |
|
369 |
scaling = (8, 8) |
|
370 |
if keycode == wx.WXK_DELETE and self.SelectedElement: |
|
371 |
self.SelectedElement.Delete() |
|
372 |
self.SelectedElement = None |
|
373 |
self.RefreshBuffer() |
|
374 |
self.RefreshScrollBars() |
|
375 |
self.Refresh(False) |
|
376 |
elif keycode == wx.WXK_LEFT: |
|
377 |
if event.ControlDown() and event.ShiftDown(): |
|
378 |
self.Scroll(0, ypos) |
|
379 |
elif event.ControlDown(): |
|
380 |
event.Skip() |
|
381 |
elif self.SelectedElement: |
|
382 |
self.SelectedElement.Move(-scaling[0], 0) |
|
383 |
self.SelectedElement.RefreshModel() |
|
384 |
self.RefreshBuffer() |
|
385 |
self.RefreshScrollBars() |
|
386 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False) |
|
387 |
elif keycode == wx.WXK_RIGHT: |
|
388 |
if event.ControlDown() and event.ShiftDown(): |
|
389 |
self.Scroll(xmax, ypos) |
|
390 |
elif event.ControlDown(): |
|
391 |
event.Skip() |
|
392 |
elif self.SelectedElement: |
|
393 |
self.SelectedElement.Move(scaling[0], 0) |
|
394 |
self.SelectedElement.RefreshModel() |
|
395 |
self.RefreshBuffer() |
|
396 |
self.RefreshScrollBars() |
|
397 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False) |
|
398 |
elif keycode == wx.WXK_UP: |
|
399 |
if event.ControlDown() and event.ShiftDown(): |
|
400 |
self.Scroll(xpos, 0) |
|
401 |
elif event.ControlDown(): |
|
402 |
event.Skip() |
|
403 |
elif self.SelectedElement: |
|
404 |
self.SelectedElement.Move(0, -scaling[1]) |
|
405 |
self.SelectedElement.RefreshModel() |
|
406 |
self.RefreshBuffer() |
|
407 |
self.RefreshScrollBars() |
|
408 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False) |
|
409 |
elif keycode == wx.WXK_DOWN: |
|
410 |
if event.ControlDown() and event.ShiftDown(): |
|
411 |
self.Scroll(xpos, ymax) |
|
412 |
elif event.ControlDown(): |
|
413 |
event.Skip() |
|
414 |
elif self.SelectedElement: |
|
415 |
self.SelectedElement.Move(0, scaling[1]) |
|
416 |
self.SelectedElement.RefreshModel() |
|
417 |
self.RefreshBuffer() |
|
418 |
self.RefreshScrollBars() |
|
419 |
self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False) |
|
420 |
else: |
|
421 |
event.Skip() |
|
422 |
||
423 |
#------------------------------------------------------------------------------- |
|
424 |
# Adding element functions |
|
425 |
#------------------------------------------------------------------------------- |
|
426 |
||
427 |
def AddInitialStep(self, pos): |
|
428 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Please enter step name"), _("Add a new initial step"), "", wx.OK|wx.CANCEL) |
|
429 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
430 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 431 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
432 |
if dialog.ShowModal() == wx.ID_OK: |
|
433 |
id = self.GetNewId() |
|
434 |
name = dialog.GetValue() |
|
435 |
step = SFC_Step(self, name, True, id) |
|
436 |
min_width, min_height = step.GetMinSize() |
|
437 |
step.SetPosition(pos.x, pos.y) |
|
438 |
width, height = step.GetSize() |
|
439 |
step.SetSize(max(min_width, width), max(min_height, height)) |
|
440 |
self.AddBlock(step) |
|
441 |
self.Controler.AddEditedElementStep(self.TagName, id) |
|
442 |
self.RefreshStepModel(step) |
|
443 |
self.RefreshBuffer() |
|
444 |
self.RefreshScrollBars() |
|
445 |
self.Refresh(False) |
|
446 |
dialog.Destroy() |
|
447 |
||
448 |
def AddStep(self): |
|
449 |
if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): |
|
450 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Add a new step"), _("Please enter step name"), "", wx.OK|wx.CANCEL) |
|
451 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
452 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 453 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
454 |
if dialog.ShowModal() == wx.ID_OK: |
|
455 |
name = dialog.GetValue() |
|
456 |
if self.IsWire(self.SelectedElement): |
|
457 |
self.SelectedElement.SetSelectedSegment(None) |
|
458 |
previous = self.SelectedElement.EndConnected |
|
459 |
next = self.SelectedElement.StartConnected |
|
460 |
self.SelectedElement.Clean() |
|
461 |
self.RemoveWire(self.SelectedElement) |
|
462 |
else: |
|
463 |
connectors = self.SelectedElement.GetConnectors() |
|
464 |
if connectors["output"]: |
|
465 |
previous = connectors["output"] |
|
466 |
wires = previous.GetWires() |
|
467 |
if len(wires) != 1: |
|
468 |
return |
|
469 |
wire = wires[0][0] |
|
470 |
next = wire.StartConnected |
|
471 |
wire.Clean() |
|
472 |
self.RemoveWire(wire) |
|
473 |
else: |
|
474 |
self.SelectedElement.AddOutput() |
|
475 |
connectors = self.SelectedElement.GetConnectors() |
|
476 |
self.RefreshStepModel(self.SelectedElement) |
|
477 |
previous = connectors["output"] |
|
478 |
next = None |
|
479 |
previous_block = previous.GetParentBlock() |
|
480 |
if isinstance(previous_block, SFC_Step) or isinstance(previous_block, SFC_Divergence) and previous_block.GetType() in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
481 |
transition = self.CreateTransition(previous) |
|
482 |
transition_connectors = transition.GetConnectors() |
|
483 |
step = self.CreateStep(name, transition_connectors["output"], next) |
|
484 |
else: |
|
485 |
step = self.CreateStep(name, previous) |
|
486 |
step.AddOutput() |
|
487 |
step.RefreshModel() |
|
488 |
step_connectors = step.GetConnectors() |
|
489 |
transition = self.CreateTransition(step_connectors["output"], next) |
|
490 |
if self.IsWire(self.SelectedElement): |
|
491 |
self.SelectedElement = wire |
|
492 |
self.SelectedElement.SetSelectedSegment(0) |
|
493 |
else: |
|
494 |
self.SelectedElement.SetSelected(False) |
|
495 |
self.SelectedElement = step |
|
496 |
self.SelectedElement.SetSelected(True) |
|
497 |
self.RefreshBuffer() |
|
498 |
self.RefreshScrollBars() |
|
499 |
self.Refresh(False) |
|
500 |
dialog.Destroy() |
|
501 |
||
502 |
def AddStepAction(self): |
|
503 |
if isinstance(self.SelectedElement, SFC_Step): |
|
504 |
connectors = self.SelectedElement.GetConnectors() |
|
505 |
if not connectors["action"]: |
|
506 |
dialog = ActionBlockDialog(self.ParentWindow) |
|
507 |
dialog.SetQualifierList(self.Controler.GetQualifierTypes()) |
|
508 |
dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
509 |
dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 510 |
if dialog.ShowModal() == wx.ID_OK: |
511 |
actions = dialog.GetValues() |
|
512 |
self.SelectedElement.AddAction() |
|
513 |
self.RefreshStepModel(self.SelectedElement) |
|
514 |
connectors = self.SelectedElement.GetConnectors() |
|
515 |
pos = connectors["action"].GetPosition(False) |
|
516 |
id = self.GetNewId() |
|
517 |
actionblock = SFC_ActionBlock(self, [], id) |
|
518 |
actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2) |
|
519 |
actionblock_connector = actionblock.GetConnector() |
|
520 |
wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) |
|
521 |
wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)]) |
|
522 |
actionblock.SetActions(actions) |
|
523 |
self.AddBlock(actionblock) |
|
524 |
self.Controler.AddEditedElementActionBlock(self.TagName, id) |
|
525 |
self.RefreshActionBlockModel(actionblock) |
|
526 |
self.RefreshBuffer() |
|
527 |
self.RefreshScrollBars() |
|
528 |
self.Refresh(False) |
|
529 |
dialog.Destroy() |
|
530 |
||
531 |
def AddDivergence(self): |
|
532 |
if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step): |
|
533 |
dialog = SFCDivergenceDialog(self.ParentWindow) |
|
534 |
dialog.SetPreviewFont(self.GetFont()) |
|
535 |
if dialog.ShowModal() == wx.ID_OK: |
|
536 |
value = dialog.GetValues() |
|
537 |
if value["type"] == SELECTION_DIVERGENCE: |
|
538 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step): |
|
539 |
self.SelectedElement.SetSelectedSegment(None) |
|
540 |
previous = self.SelectedElement.EndConnected |
|
541 |
next = self.SelectedElement.StartConnected |
|
542 |
self.SelectedElement.Clean() |
|
543 |
self.RemoveWire(self.SelectedElement) |
|
544 |
self.SelectedElement = None |
|
545 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
546 |
connectors = self.SelectedElement.GetConnectors() |
|
547 |
if connectors["output"]: |
|
548 |
previous = connectors["output"] |
|
549 |
wires = previous.GetWires() |
|
550 |
if len(wires) != 1: |
|
551 |
return |
|
552 |
wire = wires[0][0] |
|
553 |
next = wire.StartConnected |
|
554 |
wire.Clean() |
|
555 |
self.RemoveWire(wire) |
|
556 |
else: |
|
557 |
self.SelectedElement.AddOutput() |
|
558 |
connectors = self.SelectedElement.GetConnectors() |
|
559 |
self.RefreshStepModel(self.SelectedElement) |
|
560 |
previous = connectors["output"] |
|
561 |
next = None |
|
562 |
else: |
|
563 |
return |
|
564 |
id = self.GetNewId() |
|
565 |
divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id) |
|
566 |
pos = previous.GetPosition(False) |
|
567 |
previous_block = previous.GetParentBlock() |
|
568 |
wire_size = GetWireSize(previous_block) |
|
569 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
570 |
divergence_connectors = divergence.GetConnectors() |
|
571 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
572 |
previous_block.RefreshOutputPosition() |
|
573 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
574 |
self.AddBlock(divergence) |
|
575 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
576 |
self.RefreshDivergenceModel(divergence) |
|
577 |
for index, connector in enumerate(divergence_connectors["outputs"]): |
|
578 |
if next: |
|
579 |
wire = self.ConnectConnectors(next, connector) |
|
580 |
pos = connector.GetPosition(False) |
|
581 |
next_pos = next.GetPosition(False) |
|
582 |
next_block = next.GetParentBlock() |
|
583 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
584 |
divergence.RefreshConnectedPosition(connector) |
|
585 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
586 |
next_block.RefreshModel() |
|
587 |
next = None |
|
588 |
else: |
|
589 |
transition = self.CreateTransition(connector) |
|
590 |
transition_connectors = transition.GetConnectors() |
|
591 |
step = self.CreateStep("Step", transition_connectors["output"]) |
|
592 |
elif value["type"] == SIMULTANEOUS_DIVERGENCE: |
|
593 |
if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Transition): |
|
594 |
self.SelectedElement.SetSelectedSegment(None) |
|
595 |
previous = self.SelectedElement.EndConnected |
|
596 |
next = self.SelectedElement.StartConnected |
|
597 |
self.SelectedElement.Clean() |
|
598 |
self.RemoveWire(self.SelectedElement) |
|
599 |
self.SelectedElement = None |
|
600 |
elif isinstance(self.SelectedElement, SFC_Step): |
|
601 |
connectors = self.SelectedElement.GetConnectors() |
|
602 |
if connectors["output"]: |
|
603 |
previous = connectors["output"] |
|
604 |
wires = previous.GetWires() |
|
605 |
if len(wires) != 1: |
|
606 |
return |
|
607 |
wire = wires[0][0] |
|
608 |
next = wire.StartConnected |
|
609 |
wire.Clean() |
|
610 |
self.RemoveWire(wire) |
|
611 |
else: |
|
612 |
self.SelectedElement.AddOutput() |
|
613 |
connectors = self.SelectedElement.GetConnectors() |
|
614 |
self.RefreshStepModel(self.SelectedElement) |
|
615 |
previous = connectors["output"] |
|
616 |
next = None |
|
617 |
transition = self.CreateTransition(previous) |
|
618 |
transition_connectors = transition.GetConnectors() |
|
619 |
previous = transition_connectors["output"] |
|
620 |
else: |
|
621 |
return |
|
622 |
id = self.GetNewId() |
|
623 |
divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id) |
|
624 |
pos = previous.GetPosition(False) |
|
625 |
previous_block = previous.GetParentBlock() |
|
626 |
wire_size = GetWireSize(previous_block) |
|
627 |
divergence.SetPosition(pos.x, pos.y + wire_size) |
|
628 |
divergence_connectors = divergence.GetConnectors() |
|
629 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) |
|
630 |
previous_block.RefreshOutputPosition() |
|
631 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
632 |
self.AddBlock(divergence) |
|
633 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
634 |
self.RefreshDivergenceModel(divergence) |
|
635 |
for index, connector in enumerate(divergence_connectors["outputs"]): |
|
636 |
if next: |
|
637 |
wire = self.ConnectConnectors(next, connector) |
|
638 |
pos = connector.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(connector) |
|
643 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
644 |
next_block.RefreshModel() |
|
645 |
next = None |
|
646 |
else: |
|
647 |
step = self.CreateStep("Step", connector) |
|
648 |
elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1: |
|
649 |
next = None |
|
650 |
for element in self.SelectedElement.GetElements(): |
|
651 |
connectors = element.GetConnectors() |
|
652 |
if not isinstance(element, SFC_Step) or connectors["output"] and next: |
|
653 |
return |
|
654 |
elif connectors["output"] and not next: |
|
655 |
wires = connectors["output"].GetWires() |
|
656 |
if len(wires) != 1: |
|
657 |
return |
|
658 |
if value["type"] == SELECTION_CONVERGENCE: |
|
659 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
660 |
transition_connectors = transition.GetConnectors() |
|
661 |
wires = transition_connectors["output"].GetWires() |
|
662 |
if len(wires) != 1: |
|
663 |
return |
|
664 |
wire = wires[0][0] |
|
665 |
next = wire.StartConnected |
|
666 |
wire.Clean() |
|
667 |
self.RemoveWire(wire) |
|
668 |
inputs = [] |
|
669 |
for input in self.SelectedElement.GetElements(): |
|
670 |
input_connectors = input.GetConnectors() |
|
671 |
if not input_connectors["output"]: |
|
672 |
input.AddOutput() |
|
673 |
input.RefreshModel() |
|
674 |
input_connectors = input.GetConnectors() |
|
675 |
if value["type"] == SELECTION_CONVERGENCE: |
|
676 |
transition = self.CreateTransition(input_connectors["output"]) |
|
677 |
transition_connectors = transition.GetConnectors() |
|
678 |
inputs.append(transition_connectors["output"]) |
|
679 |
else: |
|
680 |
inputs.append(input_connectors["output"]) |
|
681 |
elif value["type"] == SELECTION_CONVERGENCE: |
|
682 |
wires = input_connectors["output"].GetWires() |
|
683 |
transition = wires[0][0].StartConnected.GetParentBlock() |
|
684 |
transition_connectors = transition.GetConnectors() |
|
685 |
inputs.append(transition_connectors["output"]) |
|
686 |
else: |
|
687 |
inputs.append(input_connectors["output"]) |
|
688 |
id = self.GetNewId() |
|
689 |
divergence = SFC_Divergence(self, value["type"], len(inputs), id) |
|
690 |
pos = inputs[0].GetPosition(False) |
|
691 |
divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
692 |
divergence_connectors = divergence.GetConnectors() |
|
693 |
for i, input in enumerate(inputs): |
|
694 |
pos = input.GetPosition(False) |
|
695 |
wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input) |
|
696 |
wire_size = GetWireSize(input) |
|
697 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
698 |
input_block = input.GetParentBlock() |
|
699 |
input_block.RefreshOutputPosition() |
|
700 |
divergence.RefreshPosition() |
|
701 |
pos = divergence_connectors["outputs"][0].GetRelPosition() |
|
702 |
divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) |
|
703 |
self.AddBlock(divergence) |
|
704 |
self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"]) |
|
705 |
self.RefreshDivergenceModel(divergence) |
|
706 |
if next: |
|
707 |
wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) |
|
708 |
pos = divergence_connectors["outputs"][0].GetPosition(False) |
|
709 |
next_pos = next.GetPosition(False) |
|
710 |
next_block = next.GetParentBlock() |
|
711 |
divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) |
|
712 |
divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0]) |
|
713 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
714 |
next_block.RefreshModel() |
|
715 |
else: |
|
716 |
if value["type"] == SELECTION_CONVERGENCE: |
|
717 |
previous = divergence_connectors["outputs"][0] |
|
718 |
else: |
|
719 |
transition = self.CreateTransition(divergence_connectors["outputs"][0]) |
|
720 |
transition_connectors = transition.GetConnectors() |
|
721 |
previous = transition_connectors["output"] |
|
722 |
self.CreateStep("Step", previous) |
|
723 |
self.RefreshBuffer() |
|
724 |
self.RefreshScrollBars() |
|
725 |
self.Refresh(False) |
|
726 |
dialog.Destroy() |
|
727 |
||
728 |
def AddDivergenceBranch(self, divergence): |
|
729 |
if isinstance(divergence, SFC_Divergence): |
|
730 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
731 |
divergence.AddBranch() |
|
732 |
self.RefreshDivergenceModel(divergence) |
|
733 |
else: |
|
734 |
type = divergence.GetType() |
|
735 |
if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
736 |
divergence.AddBranch() |
|
737 |
divergence_connectors = divergence.GetConnectors() |
|
738 |
if type == SELECTION_DIVERGENCE: |
|
739 |
transition = self.CreateTransition(divergence_connectors["outputs"][-1]) |
|
740 |
transition_connectors = transition.GetConnectors() |
|
741 |
previous = transition_connectors["output"] |
|
742 |
else: |
|
743 |
previous = divergence_connectors["outputs"][-1] |
|
744 |
step = self.CreateStep("Step", previous) |
|
745 |
self.RefreshBuffer() |
|
746 |
self.RefreshScrollBars() |
|
747 |
self.Refresh(False) |
|
748 |
||
749 |
def RemoveDivergenceBranch(self, divergence): |
|
750 |
if isinstance(divergence, SFC_Divergence): |
|
751 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
752 |
divergence.RemoveHandledBranch() |
|
753 |
self.RefreshDivergenceModel(divergence) |
|
754 |
self.RefreshBuffer() |
|
755 |
self.RefreshScrollBars() |
|
756 |
self.Refresh(False) |
|
757 |
||
758 |
def AddJump(self): |
|
759 |
if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output: |
|
760 |
choices = [] |
|
761 |
for block in self.Blocks: |
|
762 |
if isinstance(block, SFC_Step): |
|
763 |
choices.append(block.GetName()) |
|
764 |
dialog = wx.SingleChoiceDialog(self.ParentWindow, |
|
765 |
_("Add a new jump"), _("Please choose a target"), |
|
766 |
choices, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
|
767 |
if dialog.ShowModal() == wx.ID_OK: |
|
768 |
value = dialog.GetStringSelection() |
|
769 |
self.SelectedElement.AddOutput() |
|
770 |
self.RefreshStepModel(self.SelectedElement) |
|
771 |
step_connectors = self.SelectedElement.GetConnectors() |
|
772 |
transition = self.CreateTransition(step_connectors["output"]) |
|
773 |
transition_connectors = transition.GetConnectors() |
|
774 |
id = self.GetNewId() |
|
775 |
jump = SFC_Jump(self, value, id) |
|
776 |
pos = transition_connectors["output"].GetPosition(False) |
|
777 |
jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) |
|
778 |
self.AddBlock(jump) |
|
779 |
self.Controler.AddEditedElementJump(self.TagName, id) |
|
780 |
jump_connector = jump.GetConnector() |
|
781 |
wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) |
|
782 |
transition.RefreshOutputPosition() |
|
783 |
wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)]) |
|
784 |
self.RefreshJumpModel(jump) |
|
785 |
self.RefreshBuffer() |
|
786 |
self.RefreshScrollBars() |
|
787 |
self.Refresh(False) |
|
788 |
dialog.Destroy() |
|
789 |
||
790 |
def EditStepContent(self, step): |
|
791 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
792 |
Viewer.EditStepContent(self, step) |
|
793 |
else: |
|
794 |
dialog = SFCStepNameDialog(self.ParentWindow, _("Edit step name"), _("Please enter step name"), step.GetName(), wx.OK|wx.CANCEL) |
|
795 |
dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug)) |
|
1347
533741e5075c
Fixed pou variables information loading stylesheet
Laurent Bessard
parents:
814
diff
changeset
|
796 |
dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, debug=self.Debug)) |
814 | 797 |
dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
798 |
if dialog.ShowModal() == wx.ID_OK: |
|
799 |
value = dialog.GetValue() |
|
800 |
step.SetName(value) |
|
801 |
min_size = step.GetMinSize() |
|
802 |
size = step.GetSize() |
|
803 |
step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1])) |
|
804 |
step.RefreshModel() |
|
805 |
self.RefreshBuffer() |
|
806 |
self.RefreshScrollBars() |
|
807 |
self.Refresh(False) |
|
808 |
dialog.Destroy() |
|
809 |
||
810 |
#------------------------------------------------------------------------------- |
|
811 |
# Delete element functions |
|
812 |
#------------------------------------------------------------------------------- |
|
813 |
||
814 |
def DeleteStep(self, step): |
|
815 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
816 |
Viewer.DeleteStep(self, step) |
|
817 |
else: |
|
818 |
step_connectors = step.GetConnectors() |
|
819 |
if not step.GetInitial() or not step_connectors["output"]: |
|
820 |
previous = step.GetPreviousConnector() |
|
821 |
if previous: |
|
822 |
previous_block = previous.GetParentBlock() |
|
823 |
else: |
|
824 |
previous_block = None |
|
825 |
next = step.GetNextConnector() |
|
826 |
if next: |
|
827 |
next_block = next.GetParentBlock() |
|
828 |
else: |
|
829 |
next_block = None |
|
830 |
if isinstance(next_block, SFC_Transition): |
|
831 |
self.RemoveTransition(next_block) |
|
832 |
next = step.GetNextConnector() |
|
833 |
if next: |
|
834 |
next_block = next.GetParentBlock() |
|
835 |
else: |
|
836 |
next_block = None |
|
837 |
elif isinstance(previous_block, SFC_Transition): |
|
838 |
self.RemoveTransition(previous_block) |
|
839 |
previous = step.GetPreviousConnector() |
|
840 |
if previous: |
|
841 |
previous_block = previous.GetParentBlock() |
|
842 |
else: |
|
843 |
previous_block = None |
|
844 |
wire = self.RemoveStep(step) |
|
845 |
self.SelectedElement = None |
|
846 |
if next_block: |
|
847 |
if isinstance(next_block, SFC_Divergence) and next_block.GetType() == SIMULTANEOUS_CONVERGENCE and isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SIMULTANEOUS_DIVERGENCE: |
|
848 |
wire.Clean() |
|
849 |
self.RemoveWire(wire) |
|
850 |
next_block.RemoveBranch(next) |
|
851 |
if next_block.GetBranchNumber() < 2: |
|
852 |
self.DeleteDivergence(next_block) |
|
853 |
else: |
|
854 |
next_block.RefreshModel() |
|
855 |
previous_block.RemoveBranch(previous) |
|
856 |
if previous_block.GetBranchNumber() < 2: |
|
857 |
self.DeleteDivergence(previous_block) |
|
858 |
else: |
|
859 |
previous_block.RefreshModel() |
|
860 |
else: |
|
861 |
pos = previous.GetPosition(False) |
|
862 |
next_pos = next.GetPosition(False) |
|
863 |
wire_size = GetWireSize(previous_block) |
|
864 |
previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y)) |
|
865 |
wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)]) |
|
866 |
if isinstance(next_block, SFC_Divergence): |
|
867 |
next_block.RefreshPosition() |
|
868 |
previous_block.RefreshOutputModel(True) |
|
869 |
else: |
|
870 |
if isinstance(previous_block, SFC_Step): |
|
871 |
previous_block.RemoveOutput() |
|
872 |
self.RefreshStepModel(previous_block) |
|
873 |
elif isinstance(previous_block, SFC_Divergence): |
|
874 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
875 |
self.DeleteDivergence(previous_block) |
|
876 |
else: |
|
877 |
previous_block.RemoveBranch(previous) |
|
878 |
if previous_block.GetBranchNumber() < 2: |
|
879 |
self.DeleteDivergence(previous_block) |
|
880 |
else: |
|
881 |
self.RefreshDivergenceModel(previous_block) |
|
882 |
||
883 |
def DeleteTransition(self, transition): |
|
884 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
885 |
Viewer.DeleteTransition(self, transition) |
|
886 |
else: |
|
887 |
previous = transition.GetPreviousConnector() |
|
888 |
previous_block = previous.GetParentBlock() |
|
889 |
next = transition.GetNextConnector() |
|
890 |
next_block = next.GetParentBlock() |
|
891 |
if isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SELECTION_DIVERGENCE and isinstance(next_block, SFC_Divergence) and next_block.GetType() == SELECTION_CONVERGENCE: |
|
892 |
wires = previous.GetWires() |
|
893 |
if len(wires) != 1: |
|
894 |
return |
|
895 |
wire = wires[0][0] |
|
896 |
wire.Clean() |
|
897 |
self.RemoveWire(wire) |
|
898 |
wires = next.GetWires() |
|
899 |
if len(wires) != 1: |
|
900 |
return |
|
901 |
wire = wires[0][0] |
|
902 |
wire.Clean() |
|
903 |
self.RemoveWire(wire) |
|
904 |
transition.Clean() |
|
905 |
self.RemoveBlock(transition) |
|
906 |
self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId()) |
|
907 |
previous_block.RemoveBranch(previous) |
|
908 |
if previous_block.GetBranchNumber() < 2: |
|
909 |
self.DeleteDivergence(previous_block) |
|
910 |
else: |
|
911 |
self.RefreshDivergenceModel(previous_block) |
|
912 |
next_block.RemoveBranch(next) |
|
913 |
if next_block.GetBranchNumber() < 2: |
|
914 |
self.DeleteDivergence(next_block) |
|
915 |
else: |
|
916 |
self.RefreshDivergenceModel(next_block) |
|
917 |
||
918 |
def DeleteDivergence(self, divergence): |
|
919 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
920 |
Viewer.DeleteDivergence(self, divergence) |
|
921 |
else: |
|
922 |
connectors = divergence.GetConnectors() |
|
923 |
type = divergence.GetType() |
|
924 |
if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
925 |
wires = connectors["outputs"][0].GetWires() |
|
926 |
if len(wires) > 1: |
|
927 |
return |
|
928 |
elif len(wires) == 1: |
|
929 |
next = wires[0][0].StartConnected |
|
930 |
next_block = next.GetParentBlock() |
|
931 |
wire = wires[0][0] |
|
932 |
wire.Clean() |
|
933 |
self.RemoveWire(wire) |
|
934 |
else: |
|
935 |
next = None |
|
936 |
next_block = None |
|
937 |
for index, connector in enumerate(connectors["inputs"]): |
|
938 |
if next and index == 0: |
|
939 |
wires = connector.GetWires() |
|
940 |
wire = wires[0][0] |
|
941 |
previous = wires[0][0].EndConnected |
|
942 |
wire.Clean() |
|
943 |
self.RemoveWire(wire) |
|
944 |
else: |
|
945 |
if type == SELECTION_CONVERGENCE: |
|
946 |
wires = connector.GetWires() |
|
947 |
previous_block = wires[0][0].EndConnected.GetParentBlock() |
|
948 |
self.RemoveTransition(previous_block) |
|
949 |
wires = connector.GetWires() |
|
950 |
wire = wires[0][0] |
|
951 |
previous_connector = wire.EndConnected |
|
952 |
previous_block = previous_connector.GetParentBlock() |
|
953 |
wire.Clean() |
|
954 |
self.RemoveWire(wire) |
|
955 |
if isinstance(previous_block, SFC_Step): |
|
956 |
previous_block.RemoveOutput() |
|
957 |
self.RefreshStepModel(previous_block) |
|
958 |
elif isinstance(previous_block, SFC_Divergence): |
|
959 |
if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
960 |
previous_block.RemoveBranch(previous_connector) |
|
961 |
if previous_block.GetBranchNumber() < 2: |
|
962 |
self.DeleteDivergence(previous_block) |
|
963 |
else: |
|
964 |
self.RefreshDivergenceModel(previous_block) |
|
965 |
else: |
|
966 |
self.DeleteDivergence(previous_block) |
|
967 |
divergence.Clean() |
|
968 |
self.RemoveBlock(divergence) |
|
969 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
970 |
if next: |
|
971 |
wire = self.ConnectConnectors(next, previous) |
|
972 |
previous_block = previous.GetParentBlock() |
|
973 |
previous_pos = previous.GetPosition(False) |
|
974 |
next_pos = next.GetPosition(False) |
|
975 |
wire_size = GetWireSize(previous_block) |
|
976 |
previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y)) |
|
977 |
wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), |
|
978 |
wx.Point(previous_pos.x, previous_pos.y)]) |
|
979 |
if isinstance(next_block, SFC_Divergence): |
|
980 |
next_block.RefreshPosition() |
|
981 |
previous_block.RefreshOutputModel(True) |
|
982 |
elif divergence.GetBranchNumber() == 1: |
|
983 |
wires = connectors["inputs"][0].GetWires() |
|
984 |
if len(wires) != 1: |
|
985 |
return |
|
986 |
wire = wires[0][0] |
|
987 |
previous = wire.EndConnected |
|
988 |
previous_block = previous.GetParentBlock() |
|
989 |
wire.Clean() |
|
990 |
self.RemoveWire(wire) |
|
991 |
wires = connectors["outputs"][0].GetWires() |
|
992 |
if len(wires) != 1: |
|
993 |
return |
|
994 |
wire = wires[0][0] |
|
995 |
next = wire.StartConnected |
|
996 |
next_block = next.GetParentBlock() |
|
997 |
wire.Clean() |
|
998 |
self.RemoveWire(wire) |
|
999 |
divergence.Clean() |
|
1000 |
self.RemoveBlock(divergence) |
|
1001 |
self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId()) |
|
1002 |
wire = self.ConnectConnectors(next, previous) |
|
1003 |
previous_pos = previous.GetPosition(False) |
|
1004 |
next_pos = next.GetPosition(False) |
|
1005 |
wire_size = GetWireSize(previous_block) |
|
1006 |
previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y)) |
|
1007 |
wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), |
|
1008 |
wx.Point(previous_pos.x, previous_pos.y)]) |
|
1009 |
if isinstance(next_block, SFC_Divergence): |
|
1010 |
next_block.RefreshPosition() |
|
1011 |
previous_block.RefreshOutputModel(True) |
|
1012 |
||
1013 |
def DeleteJump(self, jump): |
|
1014 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1015 |
Viewer.DeleteJump(self, jump) |
|
1016 |
else: |
|
1017 |
previous = jump.GetPreviousConnector() |
|
1018 |
previous_block = previous.GetParentBlock() |
|
1019 |
if isinstance(previous_block, SFC_Transition): |
|
1020 |
self.RemoveTransition(previous_block) |
|
1021 |
previous = jump.GetPreviousConnector() |
|
1022 |
if previous: |
|
1023 |
previous_block = previous.GetParentBlock() |
|
1024 |
else: |
|
1025 |
previous_block = None |
|
1026 |
wires = previous.GetWires() |
|
1027 |
if len(wires) != 1: |
|
1028 |
return |
|
1029 |
wire = wires[0][0] |
|
1030 |
wire.Clean() |
|
1031 |
self.RemoveWire(wire) |
|
1032 |
jump.Clean() |
|
1033 |
self.RemoveBlock(jump) |
|
1034 |
self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId()) |
|
1035 |
if isinstance(previous_block, SFC_Step): |
|
1036 |
previous_block.RemoveOutput() |
|
1037 |
self.RefreshStepModel(previous_block) |
|
1038 |
elif isinstance(previous_block, SFC_Divergence): |
|
1039 |
if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1040 |
self.DeleteDivergence(previous_block) |
|
1041 |
else: |
|
1042 |
previous_block.RemoveBranch(previous) |
|
1043 |
if previous_block.GetBranchNumber() < 2: |
|
1044 |
self.DeleteDivergence(previous_block) |
|
1045 |
else: |
|
1046 |
previous_block.RefreshModel() |
|
1047 |
||
1048 |
def DeleteActionBlock(self, actionblock): |
|
1049 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1050 |
Viewer.DeleteActionBlock(self, actionblock) |
|
1051 |
else: |
|
1052 |
connector = actionblock.GetConnector() |
|
1053 |
wires = connector.GetWires() |
|
1054 |
if len(wires) != 1: |
|
1055 |
return |
|
1056 |
wire = wires[0][0] |
|
1057 |
step = wire.EndConnected.GetParentBlock() |
|
1058 |
wire.Clean() |
|
1059 |
self.RemoveWire(wire) |
|
1060 |
actionblock.Clean() |
|
1061 |
self.RemoveBlock(actionblock) |
|
1062 |
self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId()) |
|
1063 |
step.RemoveAction() |
|
1064 |
self.RefreshStepModel(step) |
|
1065 |
step.RefreshOutputPosition() |
|
1066 |
step.RefreshOutputModel(True) |
|
1067 |
||
1068 |
def DeleteWire(self, wire): |
|
1069 |
if self.GetDrawingMode() == FREEDRAWING_MODE: |
|
1070 |
Viewer.DeleteWire(self, wire) |
|
1071 |
||
1072 |
#------------------------------------------------------------------------------- |
|
1073 |
# Model update functions |
|
1074 |
#------------------------------------------------------------------------------- |
|
1075 |
||
1076 |
def RefreshBlockModel(self, block): |
|
1077 |
blockid = block.GetId() |
|
1078 |
infos = {} |
|
1079 |
infos["type"] = block.GetType() |
|
1080 |
infos["name"] = block.GetName() |
|
1081 |
infos["x"], infos["y"] = block.GetPosition() |
|
1082 |
infos["width"], infos["height"] = block.GetSize() |
|
1083 |
infos["connectors"] = block.GetConnectors() |
|
1084 |
self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos) |
|
1085 |