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.FBD_Objects import *
|
|
32 |
from Viewer import *
|
|
33 |
|
|
34 |
def ExtractNextBlocks(block, block_list):
|
|
35 |
current_list = [block]
|
|
36 |
while len(current_list) > 0:
|
|
37 |
next_list = []
|
|
38 |
for current in current_list:
|
|
39 |
connectors = current.GetConnectors()
|
|
40 |
input_connectors = []
|
|
41 |
if isinstance(current, LD_PowerRail) and current.GetType() == RIGHTRAIL:
|
|
42 |
input_connectors = connectors
|
|
43 |
else:
|
|
44 |
if "inputs" in connectors:
|
|
45 |
input_connectors = connectors["inputs"]
|
|
46 |
if "input" in connectors:
|
|
47 |
input_connectors = [connectors["input"]]
|
|
48 |
for connector in input_connectors:
|
|
49 |
for wire, handle in connector.GetWires():
|
|
50 |
next = wire.EndConnected.GetParentBlock()
|
|
51 |
if not isinstance(next, LD_PowerRail) and next not in block_list:
|
|
52 |
block_list.append(next)
|
|
53 |
next_list.append(next)
|
|
54 |
current_list = next_list
|
|
55 |
|
|
56 |
def CalcBranchSize(elements, stop):
|
|
57 |
branch_size = 0
|
|
58 |
stop_list = [stop]
|
|
59 |
ExtractNextBlocks(stop, stop_list)
|
|
60 |
element_tree = {}
|
|
61 |
for element in elements:
|
|
62 |
if element not in element_tree:
|
|
63 |
element_tree[element] = {"parents":["start"], "children":[], "weight":None}
|
|
64 |
GenerateTree(element, element_tree, stop_list)
|
|
65 |
elif element_tree[element]:
|
|
66 |
element_tree[element]["parents"].append("start")
|
|
67 |
for element, values in element_tree.items():
|
|
68 |
if values and values["children"] == ["stop"]:
|
|
69 |
CalcWeight(element, element_tree)
|
|
70 |
if values["weight"]:
|
|
71 |
branch_size += values["weight"]
|
|
72 |
else:
|
|
73 |
return 1
|
|
74 |
return branch_size
|
|
75 |
|
|
76 |
def RemoveElement(remove, element_tree):
|
|
77 |
if remove in element_tree and element_tree[remove]:
|
|
78 |
for child in element_tree[remove]["children"]:
|
|
79 |
if child != "stop":
|
|
80 |
RemoveElement(child, element_tree)
|
|
81 |
element_tree[remove] = None
|
|
82 |
|
|
83 |
def GenerateTree(element, element_tree, stop_list):
|
|
84 |
if element in element_tree:
|
|
85 |
connectors = element.GetConnectors()
|
|
86 |
input_connectors = []
|
|
87 |
if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL:
|
|
88 |
input_connectors = connectors
|
|
89 |
else:
|
|
90 |
if "inputs" in connectors:
|
|
91 |
input_connectors = connectors["inputs"]
|
|
92 |
if "input" in connectors:
|
|
93 |
input_connectors = [connectors["input"]]
|
|
94 |
for connector in input_connectors:
|
|
95 |
for wire, handle in connector.GetWires():
|
|
96 |
next = wire.EndConnected.GetParentBlock()
|
|
97 |
if isinstance(next, LD_PowerRail) and next.GetType() == LEFTRAIL or next in stop_list:
|
|
98 |
for remove in element_tree[element]["children"]:
|
|
99 |
RemoveElement(remove, element_tree)
|
|
100 |
element_tree[element]["children"] = ["stop"]
|
|
101 |
elif element_tree[element]["children"] == ["stop"]:
|
|
102 |
element_tree[next] = None
|
|
103 |
elif next not in element_tree or element_tree[next]:
|
|
104 |
element_tree[element]["children"].append(next)
|
|
105 |
if next in element_tree:
|
|
106 |
element_tree[next]["parents"].append(element)
|
|
107 |
else:
|
|
108 |
element_tree[next] = {"parents":[element], "children":[], "weight":None}
|
|
109 |
GenerateTree(next, element_tree, stop_list)
|
|
110 |
|
|
111 |
def CalcWeight(element, element_tree):
|
|
112 |
weight = 0
|
|
113 |
parts = None
|
|
114 |
if element in element_tree:
|
|
115 |
for parent in element_tree[element]["parents"]:
|
|
116 |
if parent == "start":
|
|
117 |
weight += 1
|
|
118 |
elif parent in element_tree:
|
|
119 |
if not parts:
|
|
120 |
parts = len(element_tree[parent]["children"])
|
|
121 |
else:
|
|
122 |
parts = min(parts, len(element_tree[parent]["children"]))
|
|
123 |
if not element_tree[parent]["weight"]:
|
|
124 |
CalcWeight(parent, element_tree)
|
|
125 |
if element_tree[parent]["weight"]:
|
|
126 |
weight += element_tree[parent]["weight"]
|
|
127 |
else:
|
|
128 |
element_tree[element]["weight"] = None
|
|
129 |
return
|
|
130 |
else:
|
|
131 |
element_tree[element]["weight"] = None
|
|
132 |
return
|
|
133 |
if not parts:
|
|
134 |
parts = 1
|
|
135 |
element_tree[element]["weight"] = max(1, weight / parts)
|
|
136 |
|
|
137 |
|
|
138 |
#-------------------------------------------------------------------------------
|
|
139 |
# Ladder Diagram Graphic elements Viewer class
|
|
140 |
#-------------------------------------------------------------------------------
|
|
141 |
|
|
142 |
"""
|
|
143 |
Class derived from Viewer class that implements a Viewer of Ladder Diagram
|
|
144 |
"""
|
|
145 |
|
|
146 |
class LD_Viewer(Viewer):
|
|
147 |
|
|
148 |
def __init__(self, parent, window, controler):
|
|
149 |
Viewer.__init__(self, parent, window, controler)
|
|
150 |
self.Rungs = []
|
|
151 |
self.Comments = []
|
|
152 |
|
|
153 |
#-------------------------------------------------------------------------------
|
|
154 |
# Refresh functions
|
|
155 |
#-------------------------------------------------------------------------------
|
|
156 |
|
|
157 |
def RefreshView(self):
|
|
158 |
Viewer.RefreshView(self)
|
|
159 |
for i, rung in enumerate(self.Rungs):
|
|
160 |
bbox = rung.GetBoundingBox()
|
|
161 |
if i < len(self.Comments):
|
|
162 |
pos = self.Comments[i].GetPosition()
|
|
163 |
if pos[1] > bbox.y:
|
|
164 |
self.Comment.insert(i, None)
|
|
165 |
else:
|
|
166 |
self.Comment.insert(i, None)
|
|
167 |
|
|
168 |
def loadInstance(self, instance, ids):
|
|
169 |
Viewer.loadInstance(self, instance, ids)
|
|
170 |
if instance["type"] == "leftPowerRail":
|
|
171 |
element = self.FindElementById(instance["id"])
|
|
172 |
rung = Graphic_Group(self)
|
|
173 |
rung.SelectElement(element)
|
|
174 |
self.Rungs.append(rung)
|
|
175 |
elif instance["type"] == "rightPowerRail":
|
|
176 |
rungs = []
|
|
177 |
for connector in instance["connectors"]:
|
|
178 |
for link in connector["links"]:
|
|
179 |
connected = self.FindElementById(link["refLocalId"])
|
|
180 |
rung = self.FindRung(connected)
|
|
181 |
if rung not in rungs:
|
|
182 |
rungs.append(rung)
|
|
183 |
if len(rungs) > 1:
|
|
184 |
raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"]
|
|
185 |
element = self.FindElementById(instance["id"])
|
|
186 |
self.Rungs[rungs[0]].SelectElement(element)
|
|
187 |
for connector in element.GetConnectors():
|
|
188 |
for wire, num in connector.GetWires():
|
|
189 |
self.Rungs[rungs[0]].SelectElement(wire)
|
|
190 |
self.RefreshPosition(element)
|
|
191 |
elif instance["type"] in ["contact", "coil"]:
|
|
192 |
rungs = []
|
|
193 |
for link in instance["connectors"]["input"]["links"]:
|
|
194 |
connected = self.FindElementById(link["refLocalId"])
|
|
195 |
rung = self.FindRung(connected)
|
|
196 |
if rung not in rungs:
|
|
197 |
rungs.append(rung)
|
|
198 |
if len(rungs) > 1:
|
|
199 |
raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"]
|
|
200 |
element = self.FindElementById(instance["id"])
|
|
201 |
self.Rungs[rungs[0]].SelectElement(element)
|
|
202 |
for wire, num in element.GetConnectors()["input"].GetWires():
|
|
203 |
self.Rungs[rungs[0]].SelectElement(wire)
|
|
204 |
self.RefreshPosition(element)
|
|
205 |
elif instance["type"] == "comment":
|
|
206 |
element = self.FindElementById(instance["id"])
|
|
207 |
pos = element.GetPosition()
|
|
208 |
i = 0
|
|
209 |
inserted = False
|
|
210 |
while i < len(self.Comments) and not inserted:
|
|
211 |
ipos = self.Comments[i].GetPosition()
|
|
212 |
if pos[1] < ipos[1]:
|
|
213 |
self.Comments.insert(i, element)
|
|
214 |
inserted = True
|
|
215 |
i += 1
|
|
216 |
if not inserted:
|
|
217 |
self.Comments.append(element)
|
|
218 |
|
|
219 |
#-------------------------------------------------------------------------------
|
|
220 |
# Search Element functions
|
|
221 |
#-------------------------------------------------------------------------------
|
|
222 |
|
|
223 |
def FindRung(self, element):
|
|
224 |
for i, rung in enumerate(self.Rungs):
|
|
225 |
if rung.IsElementIn(element):
|
|
226 |
return i
|
|
227 |
return None
|
|
228 |
|
|
229 |
def FindElement(self, pos):
|
|
230 |
elements = []
|
|
231 |
for element in self.Elements:
|
|
232 |
if element.HitTest(pos) or element.TestHandle(pos) != (0, 0):
|
|
233 |
elements.append(element)
|
|
234 |
if len(elements) == 1:
|
|
235 |
return elements[0]
|
|
236 |
elif len(elements) > 1:
|
|
237 |
group = Graphic_Group(self)
|
|
238 |
for element in elements:
|
|
239 |
if element in self.Blocks:
|
|
240 |
return element
|
|
241 |
group.SelectElement(element)
|
|
242 |
return group
|
|
243 |
return None
|
|
244 |
|
|
245 |
def SearchElements(self, bbox):
|
|
246 |
elements = []
|
|
247 |
for element in self.Blocks:
|
|
248 |
element_bbox = element.GetBoundingBox()
|
|
249 |
if element_bbox.x >= bbox.x and element_bbox.y >= bbox.y and element_bbox.x + element_bbox.width <= bbox.x + bbox.width and element_bbox.y + element_bbox.height <= bbox.y + bbox.height:
|
|
250 |
elements.append(element)
|
|
251 |
return elements
|
|
252 |
|
|
253 |
#-------------------------------------------------------------------------------
|
|
254 |
# Mouse event functions
|
|
255 |
#-------------------------------------------------------------------------------
|
|
256 |
|
|
257 |
def OnViewerLeftDown(self, event):
|
|
258 |
if self.Mode == MODE_SELECTION:
|
|
259 |
pos = event.GetPosition()
|
|
260 |
element = self.FindElement(pos)
|
|
261 |
if self.SelectedElement:
|
|
262 |
if self.SelectedElement in self.Elements:
|
|
263 |
if self.SelectedElement != element:
|
|
264 |
if self.SelectedElement in self.Wires:
|
|
265 |
self.SelectedElement.SetSelectedSegment(None)
|
|
266 |
else:
|
|
267 |
self.SelectedElement.SetSelected(False)
|
|
268 |
else:
|
|
269 |
self.SelectedElement = None
|
|
270 |
elif element and element not in self.Elements:
|
|
271 |
if self.SelectedElement.GetElements() != element.GetElements():
|
|
272 |
for elt in self.SelectedElement.GetElements():
|
|
273 |
if elt in self.Wires:
|
|
274 |
elt.SetSelectedSegment(None)
|
|
275 |
self.SelectedElement.SetSelected(False)
|
|
276 |
self.SelectedElement = None
|
|
277 |
else:
|
|
278 |
for elt in self.SelectedElement.GetElements():
|
|
279 |
if elt in self.Wires:
|
|
280 |
elt.SetSelectedSegment(None)
|
|
281 |
self.SelectedElement.SetSelected(False)
|
|
282 |
self.SelectedElement = None
|
|
283 |
self.Refresh()
|
|
284 |
if element:
|
|
285 |
self.SelectedElement = element
|
|
286 |
self.SelectedElement.OnLeftDown(event, self.Scaling)
|
|
287 |
self.Refresh()
|
|
288 |
else:
|
|
289 |
self.rubberBand.Reset()
|
|
290 |
self.rubberBand.OnLeftDown(event, self.Scaling)
|
|
291 |
event.Skip()
|
|
292 |
|
|
293 |
def OnViewerLeftUp(self, event):
|
|
294 |
if self.rubberBand.IsShown():
|
|
295 |
if self.Mode == MODE_SELECTION:
|
|
296 |
elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
|
|
297 |
self.rubberBand.OnLeftUp(event, self.Scaling)
|
|
298 |
if len(elements) > 0:
|
|
299 |
self.SelectedElement = Graphic_Group(self)
|
|
300 |
self.SelectedElement.SetElements(elements)
|
|
301 |
self.SelectedElement.SetSelected(True)
|
|
302 |
self.Refresh()
|
|
303 |
elif self.Mode == MODE_SELECTION and self.SelectedElement:
|
|
304 |
if self.SelectedElement in self.Elements:
|
|
305 |
if self.SelectedElement in self.Wires:
|
|
306 |
result = self.SelectedElement.TestSegment(event.GetPosition(), True)
|
|
307 |
if result and result[1] in [EAST, WEST]:
|
|
308 |
self.SelectedElement.SetSelectedSegment(result[0])
|
|
309 |
else:
|
|
310 |
self.SelectedElement.OnLeftUp(event, self.Scaling)
|
|
311 |
else:
|
|
312 |
for element in self.SelectedElement.GetElements():
|
|
313 |
if element in self.Wires:
|
|
314 |
result = element.TestSegment(event.GetPosition(), True)
|
|
315 |
if result and result[1] in [EAST, WEST]:
|
|
316 |
element.SetSelectedSegment(result[0])
|
|
317 |
else:
|
|
318 |
element.OnLeftUp(event, self.Scaling)
|
|
319 |
wxCallAfter(self.SetCursor, wxNullCursor)
|
|
320 |
self.ReleaseMouse()
|
|
321 |
self.Refresh()
|
|
322 |
event.Skip()
|
|
323 |
|
|
324 |
def OnViewerRightUp(self, event):
|
|
325 |
pos = event.GetPosition()
|
|
326 |
element = self.FindElement(pos)
|
|
327 |
if element:
|
|
328 |
if self.SelectedElement and self.SelectedElement != element:
|
|
329 |
self.SelectedElement.SetSelected(False)
|
|
330 |
self.SelectedElement = element
|
|
331 |
if self.SelectedElement in self.Wires:
|
|
332 |
self.SelectedElement.SetSelectedSegment(0)
|
|
333 |
else:
|
|
334 |
self.SelectedElement.SetSelected(True)
|
|
335 |
self.SelectedElement.OnRightUp(event, self.Scaling)
|
|
336 |
wxCallAfter(self.SetCursor, wxNullCursor)
|
|
337 |
self.ReleaseMouse()
|
|
338 |
self.Refresh()
|
|
339 |
event.Skip()
|
|
340 |
|
|
341 |
def OnViewerLeftDClick(self, event):
|
|
342 |
if self.Mode == MODE_SELECTION and self.SelectedElement:
|
|
343 |
self.SelectedElement.OnLeftDClick(event, self.Scaling)
|
|
344 |
self.Refresh()
|
|
345 |
event.Skip()
|
|
346 |
|
|
347 |
def OnViewerMotion(self, event):
|
|
348 |
if self.rubberBand.IsShown():
|
|
349 |
self.rubberBand.OnMotion(event, self.Scaling)
|
|
350 |
event.Skip()
|
|
351 |
|
|
352 |
#-------------------------------------------------------------------------------
|
|
353 |
# Keyboard event functions
|
|
354 |
#-------------------------------------------------------------------------------
|
|
355 |
|
|
356 |
def OnChar(self, event):
|
|
357 |
keycode = event.GetKeyCode()
|
|
358 |
if keycode == WXK_DELETE and self.SelectedElement:
|
|
359 |
if self.SelectedElement in self.Blocks:
|
|
360 |
self.SelectedElement.Delete()
|
|
361 |
elif self.SelectedElement in self.Wires:
|
|
362 |
self.DeleteWire(self.SelectedElement)
|
|
363 |
elif self.SelectedElement not in self.Elements:
|
|
364 |
all_wires = True
|
|
365 |
for element in self.SelectedElement.GetElements():
|
|
366 |
all_wires &= element in self.Wires
|
|
367 |
if all_wires:
|
|
368 |
self.DeleteWire(self.SelectedElement)
|
|
369 |
else:
|
|
370 |
self.SelectedElement.Delete()
|
|
371 |
self.Refresh()
|
|
372 |
event.Skip()
|
|
373 |
|
|
374 |
#-------------------------------------------------------------------------------
|
|
375 |
# Adding element functions
|
|
376 |
#-------------------------------------------------------------------------------
|
|
377 |
|
|
378 |
def AddRung(self):
|
|
379 |
dialog = LDElementDialog(self.Parent, "coil")
|
|
380 |
varlist = []
|
|
381 |
vars = self.Controler.GetCurrentElementEditingInterfaceVars()
|
|
382 |
if vars:
|
|
383 |
for var in vars:
|
6
|
384 |
if var["Class"] != "Input" and var["Type"] == "BOOL":
|
0
|
385 |
varlist.append(var["Name"])
|
|
386 |
returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
|
|
387 |
if returntype == "BOOL":
|
|
388 |
varlist.append(self.Controler.GetCurrentElementEditingName())
|
|
389 |
dialog.SetVariables(varlist)
|
|
390 |
dialog.SetValues({"name":"","type":COIL_NORMAL})
|
|
391 |
if dialog.ShowModal() == wxID_OK:
|
|
392 |
values = dialog.GetValues()
|
|
393 |
startx, starty = LD_OFFSET[0], 0
|
|
394 |
if len(self.Rungs) > 0:
|
|
395 |
bbox = self.Rungs[-1].GetBoundingBox()
|
|
396 |
starty = bbox.y + bbox.height
|
|
397 |
starty += LD_OFFSET[1]
|
|
398 |
rung = Graphic_Group(self)
|
|
399 |
# Create comment
|
|
400 |
id = self.GetNewId()
|
|
401 |
comment = Comment(self, "Commentaire", id)
|
|
402 |
comment.SetPosition(startx, starty)
|
|
403 |
comment.SetSize(LD_COMMENT_DEFAULTSIZE[0], LD_COMMENT_DEFAULTSIZE[1])
|
|
404 |
self.Elements.append(comment)
|
|
405 |
self.Comments.append(comment)
|
|
406 |
self.Controler.AddCurrentElementEditingComment(id)
|
|
407 |
self.RefreshCommentModel(comment)
|
|
408 |
starty += LD_COMMENT_DEFAULTSIZE[1] + LD_OFFSET[1]
|
|
409 |
# Create LeftPowerRail
|
|
410 |
id = self.GetNewId()
|
|
411 |
leftpowerrail = LD_PowerRail(self, LEFTRAIL, id)
|
|
412 |
leftpowerrail.SetPosition(startx, starty)
|
|
413 |
self.Elements.append(leftpowerrail)
|
|
414 |
self.Blocks.append(leftpowerrail)
|
|
415 |
rung.SelectElement(leftpowerrail)
|
|
416 |
self.Controler.AddCurrentElementEditingPowerRail(id, LEFTRAIL)
|
|
417 |
self.RefreshPowerRailModel(leftpowerrail)
|
|
418 |
# Create Coil
|
|
419 |
id = self.GetNewId()
|
|
420 |
coil = LD_Coil(self, values["type"], values["name"], id)
|
|
421 |
coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2)
|
|
422 |
self.Elements.append(coil)
|
|
423 |
self.Blocks.append(coil)
|
|
424 |
rung.SelectElement(coil)
|
|
425 |
self.Controler.AddCurrentElementEditingCoil(id)
|
|
426 |
# Create Wire between LeftPowerRail and Coil
|
|
427 |
wire = Wire(self)
|
|
428 |
start_connector = coil.GetConnectors()["input"]
|
|
429 |
end_connector = leftpowerrail.GetConnectors()[0]
|
|
430 |
start_connector.Connect((wire, 0), False)
|
|
431 |
end_connector.Connect((wire, -1), False)
|
|
432 |
wire.ConnectStartPoint(None, start_connector)
|
|
433 |
wire.ConnectEndPoint(None, end_connector)
|
|
434 |
self.Wires.append(wire)
|
|
435 |
self.Elements.append(wire)
|
|
436 |
rung.SelectElement(wire)
|
|
437 |
# Create RightPowerRail
|
|
438 |
id = self.GetNewId()
|
|
439 |
rightpowerrail = LD_PowerRail(self, RIGHTRAIL, id)
|
|
440 |
rightpowerrail.SetPosition(startx, starty)
|
|
441 |
self.Elements.append(rightpowerrail)
|
|
442 |
self.Blocks.append(rightpowerrail)
|
|
443 |
rung.SelectElement(rightpowerrail)
|
|
444 |
self.Controler.AddCurrentElementEditingPowerRail(id, RIGHTRAIL)
|
|
445 |
# Create Wire between LeftPowerRail and Coil
|
|
446 |
wire = Wire(self)
|
|
447 |
start_connector = rightpowerrail.GetConnectors()[0]
|
|
448 |
end_connector = coil.GetConnectors()["output"]
|
|
449 |
start_connector.Connect((wire, 0), False)
|
|
450 |
end_connector.Connect((wire, -1), False)
|
|
451 |
wire.ConnectStartPoint(None, start_connector)
|
|
452 |
wire.ConnectEndPoint(None, end_connector)
|
|
453 |
self.Wires.append(wire)
|
|
454 |
self.Elements.append(wire)
|
|
455 |
rung.SelectElement(wire)
|
|
456 |
self.RefreshPosition(coil)
|
|
457 |
self.Rungs.append(rung)
|
|
458 |
self.Refresh()
|
|
459 |
|
|
460 |
def AddContact(self):
|
|
461 |
wires = []
|
|
462 |
if self.SelectedElement in self.Wires:
|
|
463 |
left_element = self.SelectedElement.EndConnected
|
|
464 |
if not isinstance(left_element.GetParentBlock(), LD_Coil):
|
|
465 |
wires.append(self.SelectedElement)
|
|
466 |
elif self.SelectedElement and self.SelectedElement not in self.Elements:
|
|
467 |
if False not in [element in self.Wires for element in self.SelectedElement.GetElements()]:
|
|
468 |
for element in self.SelectedElement.GetElements():
|
|
469 |
wires.append(element)
|
|
470 |
if len(wires) > 0:
|
|
471 |
dialog = LDElementDialog(self.Parent, "contact")
|
|
472 |
varlist = []
|
|
473 |
vars = self.Controler.GetCurrentElementEditingInterfaceVars()
|
|
474 |
if vars:
|
|
475 |
for var in vars:
|
6
|
476 |
if var["Class"] != "Output" and var["Type"] == "BOOL":
|
0
|
477 |
varlist.append(var["Name"])
|
|
478 |
dialog.SetVariables(varlist)
|
|
479 |
dialog.SetValues({"name":"","type":CONTACT_NORMAL})
|
|
480 |
if dialog.ShowModal() == wxID_OK:
|
|
481 |
values = dialog.GetValues()
|
|
482 |
points = wires[0].GetSelectedSegmentPoints()
|
|
483 |
id = self.GetNewId()
|
|
484 |
contact = LD_Contact(self, values["type"], values["name"], id)
|
|
485 |
contact.SetPosition(0, points[0].y - (LD_ELEMENT_SIZE[1] + 1) / 2)
|
|
486 |
self.Elements.append(contact)
|
|
487 |
self.Blocks.append(contact)
|
|
488 |
self.Controler.AddCurrentElementEditingContact(id)
|
|
489 |
rungindex = self.FindRung(wires[0])
|
|
490 |
rung = self.Rungs[rungindex]
|
|
491 |
old_bbox = rung.GetBoundingBox()
|
|
492 |
rung.SelectElement(contact)
|
|
493 |
connectors = contact.GetConnectors()
|
|
494 |
left_elements = []
|
|
495 |
right_elements = []
|
|
496 |
left_index = []
|
|
497 |
right_index = []
|
|
498 |
for wire in wires:
|
|
499 |
if wire.EndConnected not in left_elements:
|
|
500 |
left_elements.append(wire.EndConnected)
|
|
501 |
left_index.append(wire.EndConnected.GetWireIndex(wire))
|
|
502 |
else:
|
|
503 |
idx = left_elements.index(wire.EndConnected)
|
|
504 |
left_index[idx] = min(left_index[idx], wire.EndConnected.GetWireIndex(wire))
|
|
505 |
if wire.StartConnected not in right_elements:
|
|
506 |
right_elements.append(wire.StartConnected)
|
|
507 |
right_index.append(wire.StartConnected.GetWireIndex(wire))
|
|
508 |
else:
|
|
509 |
idx = right_elements.index(wire.StartConnected)
|
|
510 |
right_index[idx] = min(right_index[idx], wire.StartConnected.GetWireIndex(wire))
|
|
511 |
wire.SetSelectedSegment(None)
|
|
512 |
wire.Clean()
|
|
513 |
rung.SelectElement(wire)
|
|
514 |
self.Wires.remove(wire)
|
|
515 |
self.Elements.remove(wire)
|
|
516 |
wires = []
|
|
517 |
right_wires = []
|
|
518 |
for i, left_element in enumerate(left_elements):
|
|
519 |
wire = Wire(self)
|
|
520 |
wires.append(wire)
|
|
521 |
connectors["input"].Connect((wire, 0), False)
|
|
522 |
left_element.InsertConnect(left_index[i], (wire, -1), False)
|
|
523 |
wire.ConnectStartPoint(None, connectors["input"])
|
|
524 |
wire.ConnectEndPoint(None, left_element)
|
|
525 |
for i, right_element in enumerate(right_elements):
|
|
526 |
wire = Wire(self)
|
|
527 |
wires.append(wire)
|
|
528 |
right_wires.append(wire)
|
|
529 |
right_element.InsertConnect(right_index[i], (wire, 0), False)
|
|
530 |
connectors["output"].Connect((wire, -1), False)
|
|
531 |
wire.ConnectStartPoint(None, right_element)
|
|
532 |
wire.ConnectEndPoint(None, connectors["output"])
|
|
533 |
right_wires.reverse()
|
|
534 |
for wire in wires:
|
|
535 |
self.Wires.append(wire)
|
|
536 |
self.Elements.append(wire)
|
|
537 |
rung.SelectElement(wire)
|
|
538 |
self.RefreshPosition(contact)
|
|
539 |
if len(right_wires) > 1:
|
|
540 |
group = Graphic_Group(self)
|
|
541 |
group.SetSelected(False)
|
|
542 |
for wire in right_wires:
|
|
543 |
wire.SetSelectedSegment(-1)
|
|
544 |
group.SelectElement(wire)
|
|
545 |
self.SelectedElement = group
|
|
546 |
else:
|
|
547 |
right_wires[0].SetSelectedSegment(-1)
|
|
548 |
self.SelectedElement = right_wires[0]
|
|
549 |
rung.RefreshBoundingBox()
|
|
550 |
new_bbox = rung.GetBoundingBox()
|
|
551 |
self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
|
|
552 |
self.Refresh()
|
7
|
553 |
else:
|
|
554 |
message = wxMessageDialog(self, "You must select the wire where a contact should be added!", "Error", wxOK|wxICON_ERROR)
|
|
555 |
message.ShowModal()
|
|
556 |
message.Destroy()
|
0
|
557 |
|
|
558 |
def AddBranch(self):
|
|
559 |
blocks = []
|
|
560 |
if self.SelectedElement in self.Blocks:
|
|
561 |
blocks = [self.SelectedElement]
|
|
562 |
elif self.SelectedElement not in self.Elements:
|
|
563 |
elements = self.SelectedElement.GetElements()
|
|
564 |
for element in elements:
|
|
565 |
blocks.append(element)
|
|
566 |
if len(blocks) > 0:
|
|
567 |
blocks_infos = []
|
|
568 |
left_elements = []
|
|
569 |
left_index = []
|
|
570 |
right_elements = []
|
|
571 |
right_index = []
|
|
572 |
for block in blocks:
|
|
573 |
connectors = block.GetConnectors()
|
|
574 |
block_infos = {"inputs":[],"outputs":[],"lefts":[],"rights":[]}
|
|
575 |
if "inputs" in connectors:
|
|
576 |
block_infos["inputs"] = connectors["inputs"]
|
|
577 |
if "outputs" in connectors:
|
|
578 |
block_infos["outputs"] = connectors["outputs"]
|
|
579 |
if "input" in connectors:
|
|
580 |
block_infos["inputs"] = [connectors["input"]]
|
|
581 |
if "output" in connectors:
|
|
582 |
block_infos["outputs"] = [connectors["output"]]
|
|
583 |
for connector in block_infos["inputs"]:
|
|
584 |
for wire, handle in connector.GetWires():
|
|
585 |
found = False
|
|
586 |
for infos in blocks_infos:
|
|
587 |
if wire.EndConnected in infos["outputs"]:
|
|
588 |
for left_element in infos["lefts"]:
|
|
589 |
if left_element not in block_infos["lefts"]:
|
|
590 |
block_infos["lefts"].append(left_element)
|
|
591 |
found = True
|
|
592 |
if not found and wire.EndConnected not in block_infos["lefts"]:
|
|
593 |
block_infos["lefts"].append(wire.EndConnected)
|
|
594 |
if wire.EndConnected not in left_elements:
|
|
595 |
left_elements.append(wire.EndConnected)
|
|
596 |
left_index.append(wire.EndConnected.GetWireIndex(wire))
|
|
597 |
else:
|
|
598 |
index = left_elements.index(wire.EndConnected)
|
|
599 |
left_index[index] = max(left_index[index], wire.EndConnected.GetWireIndex(wire))
|
|
600 |
for connector in block_infos["outputs"]:
|
|
601 |
for wire, handle in connector.GetWires():
|
|
602 |
found = False
|
|
603 |
for infos in blocks_infos:
|
|
604 |
if wire.StartConnected in infos["inputs"]:
|
|
605 |
for right_element in infos["rights"]:
|
|
606 |
if right_element not in block_infos["rights"]:
|
|
607 |
block_infos["rights"].append(right_element)
|
|
608 |
found = True
|
|
609 |
if not found and wire.StartConnected not in block_infos["rights"]:
|
|
610 |
block_infos["rights"].append(wire.StartConnected)
|
|
611 |
if wire.StartConnected not in right_elements:
|
|
612 |
right_elements.append(wire.StartConnected)
|
|
613 |
right_index.append(wire.StartConnected.GetWireIndex(wire))
|
|
614 |
else:
|
|
615 |
index = right_elements.index(wire.StartConnected)
|
|
616 |
right_index[index] = max(right_index[index], wire.StartConnected.GetWireIndex(wire))
|
|
617 |
for connector in block_infos["inputs"]:
|
|
618 |
for infos in blocks_infos:
|
|
619 |
if connector in infos["rights"]:
|
|
620 |
infos["rights"].remove(connector)
|
|
621 |
if connector in right_elements:
|
|
622 |
index = right_elements.index(connector)
|
|
623 |
right_elements.pop(index)
|
|
624 |
right_index.pop(index)
|
|
625 |
for right_element in block_infos["rights"]:
|
|
626 |
if right_element not in infos["rights"]:
|
|
627 |
infos["rights"].append(right_element)
|
|
628 |
for connector in block_infos["outputs"]:
|
|
629 |
for infos in blocks_infos:
|
|
630 |
if connector in infos["lefts"]:
|
|
631 |
infos["lefts"].remove(connector)
|
|
632 |
if connector in left_elements:
|
|
633 |
index = left_elements.index(connector)
|
|
634 |
left_elements.pop(index)
|
|
635 |
left_index.pop(index)
|
|
636 |
for left_element in block_infos["lefts"]:
|
|
637 |
if left_element not in infos["lefts"]:
|
|
638 |
infos["lefts"].append(left_element)
|
|
639 |
blocks_infos.append(block_infos)
|
|
640 |
for infos in blocks_infos:
|
|
641 |
left_elements = [element for element in infos["lefts"]]
|
|
642 |
for left_element in left_elements:
|
|
643 |
if isinstance(left_element.GetParentBlock(), LD_PowerRail):
|
|
644 |
infos["lefts"].remove(left_element)
|
|
645 |
if "LD_PowerRail" not in infos["lefts"]:
|
|
646 |
infos["lefts"].append("LD_PowerRail")
|
|
647 |
right_elements = [element for element in infos["rights"]]
|
|
648 |
for right_element in right_elements:
|
|
649 |
if isinstance(right_element.GetParentBlock(), LD_PowerRail):
|
7
|
650 |
infos["rights"].remove(right_element)
|
0
|
651 |
if "LD_PowerRail" not in infos["rights"]:
|
|
652 |
infos["rights"].append("LD_PowerRail")
|
|
653 |
infos["lefts"].sort()
|
|
654 |
infos["rights"].sort()
|
|
655 |
lefts = blocks_infos[0]["lefts"]
|
|
656 |
rights = blocks_infos[0]["rights"]
|
|
657 |
good = True
|
|
658 |
for infos in blocks_infos[1:]:
|
|
659 |
good &= infos["lefts"] == lefts
|
|
660 |
good &= infos["rights"] == rights
|
|
661 |
if good:
|
|
662 |
rungindex = self.FindRung(blocks[0])
|
|
663 |
rung = self.Rungs[rungindex]
|
|
664 |
old_bbox = rung.GetBoundingBox()
|
|
665 |
left_powerrail = True
|
|
666 |
right_powerrail = True
|
|
667 |
for element in left_elements:
|
|
668 |
left_powerrail &= isinstance(element.GetParentBlock(), LD_PowerRail)
|
|
669 |
for element in right_elements:
|
|
670 |
right_powerrail &= isinstance(element.GetParentBlock(), LD_PowerRail)
|
|
671 |
if not left_powerrail or not right_powerrail:
|
|
672 |
if left_powerrail:
|
|
673 |
powerrail = left_elements[0].GetParentBlock()
|
|
674 |
index = 0
|
|
675 |
for left_element in left_elements:
|
|
676 |
index = max(index, powerrail.GetConnectorIndex(left_element))
|
|
677 |
if powerrail.IsNullConnector(index + 1):
|
|
678 |
powerrail.DeleteConnector(index + 1)
|
|
679 |
powerrail.InsertConnector(index + 1)
|
|
680 |
powerrail.RefreshModel()
|
|
681 |
connectors = powerrail.GetConnectors()
|
|
682 |
for i, right_element in enumerate(right_elements):
|
|
683 |
new_wire = Wire(self)
|
|
684 |
right_element.InsertConnect(right_index[i] + 1, (new_wire, 0), False)
|
|
685 |
connectors[index + 1].Connect((new_wire, -1), False)
|
|
686 |
new_wire.ConnectStartPoint(None, right_element)
|
|
687 |
new_wire.ConnectEndPoint(None, connectors[index + 1])
|
|
688 |
self.Wires.append(new_wire)
|
|
689 |
self.Elements.append(new_wire)
|
|
690 |
rung.SelectElement(new_wire)
|
|
691 |
right_elements.reverse()
|
|
692 |
elif right_powerrail:
|
7
|
693 |
dialog = LDElementDialog(self.Parent, "coil")
|
|
694 |
varlist = []
|
|
695 |
vars = self.Controler.GetCurrentElementEditingInterfaceVars()
|
|
696 |
if vars:
|
|
697 |
for var in vars:
|
|
698 |
if var["Class"] != "Input" and var["Type"] == "BOOL":
|
|
699 |
varlist.append(var["Name"])
|
|
700 |
returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
|
|
701 |
if returntype == "BOOL":
|
|
702 |
varlist.append(self.Controler.GetCurrentElementEditingName())
|
|
703 |
dialog.SetVariables(varlist)
|
|
704 |
dialog.SetValues({"name":"","type":COIL_NORMAL})
|
|
705 |
if dialog.ShowModal() == wxID_OK:
|
|
706 |
values = dialog.GetValues()
|
|
707 |
powerrail = right_elements[0].GetParentBlock()
|
|
708 |
index = 0
|
|
709 |
for right_element in right_elements:
|
|
710 |
index = max(index, powerrail.GetConnectorIndex(right_element))
|
|
711 |
if powerrail.IsNullConnector(index + 1):
|
|
712 |
powerrail.DeleteConnector(index + 1)
|
|
713 |
powerrail.InsertConnector(index + 1)
|
|
714 |
powerrail.RefreshModel()
|
|
715 |
connectors = powerrail.GetConnectors()
|
|
716 |
# Create Coil
|
|
717 |
id = self.GetNewId()
|
|
718 |
coil = LD_Coil(self, values["type"], values["name"], id)
|
|
719 |
pos = blocks[0].GetPosition()
|
|
720 |
coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE)
|
|
721 |
self.Elements.append(coil)
|
|
722 |
self.Blocks.append(coil)
|
|
723 |
rung.SelectElement(coil)
|
|
724 |
self.Controler.AddCurrentElementEditingCoil(id)
|
|
725 |
coil_connectors = coil.GetConnectors()
|
|
726 |
# Create Wire between LeftPowerRail and Coil
|
|
727 |
wire = Wire(self)
|
|
728 |
connectors[index + 1].Connect((wire, 0), False)
|
|
729 |
coil_connectors["output"].Connect((wire, -1), False)
|
|
730 |
wire.ConnectStartPoint(None, connectors[index + 1])
|
|
731 |
wire.ConnectEndPoint(None, coil_connectors["output"])
|
|
732 |
self.Wires.append(wire)
|
|
733 |
self.Elements.append(wire)
|
|
734 |
rung.SelectElement(wire)
|
|
735 |
for i, left_element in enumerate(left_elements):
|
|
736 |
# Create Wire between LeftPowerRail and Coil
|
|
737 |
new_wire = Wire(self)
|
|
738 |
coil_connectors["input"].Connect((new_wire, 0), False)
|
|
739 |
left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False)
|
|
740 |
new_wire.ConnectStartPoint(None, coil_connectors["input"])
|
|
741 |
new_wire.ConnectEndPoint(None, left_element)
|
|
742 |
self.Wires.append(new_wire)
|
|
743 |
self.Elements.append(new_wire)
|
|
744 |
rung.SelectElement(new_wire)
|
|
745 |
left_elements.reverse()
|
|
746 |
self.RefreshPosition(coil)
|
0
|
747 |
else:
|
|
748 |
left_elements.reverse()
|
|
749 |
right_elements.reverse()
|
|
750 |
wires = []
|
|
751 |
for i, left_element in enumerate(left_elements):
|
|
752 |
for j, right_element in enumerate(right_elements):
|
|
753 |
exist = False
|
|
754 |
for wire, handle in right_element.GetWires():
|
|
755 |
exist |= wire.EndConnected == left_element
|
|
756 |
if not exist:
|
|
757 |
new_wire = Wire(self)
|
|
758 |
wires.append(new_wire)
|
|
759 |
right_element.InsertConnect(right_index[j] + 1, (new_wire, 0), False)
|
|
760 |
left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False)
|
|
761 |
new_wire.ConnectStartPoint(None, right_element)
|
|
762 |
new_wire.ConnectEndPoint(None, left_element)
|
|
763 |
wires.reverse()
|
|
764 |
for wire in wires:
|
|
765 |
self.Wires.append(wire)
|
|
766 |
self.Elements.append(wire)
|
|
767 |
rung.SelectElement(wire)
|
|
768 |
right_elements.reverse()
|
|
769 |
for block in blocks:
|
|
770 |
self.RefreshPosition(block)
|
|
771 |
for right_element in right_elements:
|
|
772 |
self.RefreshPosition(right_element.GetParentBlock())
|
|
773 |
self.SelectedElement.RefreshBoundingBox()
|
|
774 |
rung.RefreshBoundingBox()
|
|
775 |
new_bbox = rung.GetBoundingBox()
|
|
776 |
self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
|
|
777 |
self.Refresh()
|
7
|
778 |
else:
|
|
779 |
message = wxMessageDialog(self, "The group of block must be coherent!", "Error", wxOK|wxICON_ERROR)
|
|
780 |
message.ShowModal()
|
|
781 |
message.Destroy()
|
|
782 |
else:
|
|
783 |
message = wxMessageDialog(self, "You must select the block or group of blocks around which a branch should be added!", "Error", wxOK|wxICON_ERROR)
|
|
784 |
message.ShowModal()
|
|
785 |
message.Destroy()
|
|
786 |
|
|
787 |
|
|
788 |
def AddBlock(self):
|
|
789 |
message = wxMessageDialog(self, "This option isn't available yet!", "Warning", wxOK|wxICON_EXCLAMATION)
|
|
790 |
message.ShowModal()
|
|
791 |
message.Destroy()
|
0
|
792 |
|
|
793 |
#-------------------------------------------------------------------------------
|
|
794 |
# Delete element functions
|
|
795 |
#-------------------------------------------------------------------------------
|
|
796 |
|
|
797 |
def DeleteContact(self, contact):
|
|
798 |
rungindex = self.FindRung(contact)
|
|
799 |
rung = self.Rungs[rungindex]
|
|
800 |
old_bbox = rung.GetBoundingBox()
|
|
801 |
connectors = contact.GetConnectors()
|
|
802 |
input_wires = [wire for wire, handle in connectors["input"].GetWires()]
|
|
803 |
output_wires = [wire for wire, handle in connectors["output"].GetWires()]
|
|
804 |
left_elements = [(wire.EndConnected, wire.EndConnected.GetWireIndex(wire)) for wire in input_wires]
|
|
805 |
right_elements = [(wire.StartConnected, wire.StartConnected.GetWireIndex(wire)) for wire in output_wires]
|
|
806 |
for wire in input_wires:
|
|
807 |
wire.Clean()
|
|
808 |
rung.SelectElement(wire)
|
|
809 |
self.Wires.remove(wire)
|
|
810 |
self.Elements.remove(wire)
|
|
811 |
for wire in output_wires:
|
|
812 |
wire.Clean()
|
|
813 |
rung.SelectElement(wire)
|
|
814 |
self.Wires.remove(wire)
|
|
815 |
self.Elements.remove(wire)
|
|
816 |
rung.SelectElement(contact)
|
|
817 |
contact.Clean()
|
|
818 |
left_elements.reverse()
|
|
819 |
right_elements.reverse()
|
|
820 |
powerrail = len(left_elements) == 1 and isinstance(left_elements[0][0].GetParentBlock(), LD_PowerRail)
|
|
821 |
for left_element, left_index in left_elements:
|
|
822 |
for right_element, right_index in right_elements:
|
|
823 |
wire_removed = []
|
|
824 |
for wire, handle in right_element.GetWires():
|
|
825 |
if wire.EndConnected == left_element:
|
|
826 |
wire_removed.append(wire)
|
|
827 |
elif isinstance(wire.EndConnected.GetParentBlock(), LD_PowerRail) and powerrail:
|
|
828 |
left_powerrail = wire.EndConnected.GetParentBlock()
|
|
829 |
index = left_powerrail.GetConnectorIndex(wire.EndConnected)
|
|
830 |
left_powerrail.DeleteConnector(index)
|
|
831 |
wire_removed.append(wire)
|
|
832 |
for wire in wire_removed:
|
|
833 |
wire.Clean()
|
|
834 |
self.Wires.remove(wire)
|
|
835 |
self.Elements.remove(wire)
|
|
836 |
rung.SelectElement(wire)
|
|
837 |
wires = []
|
|
838 |
for left_element, left_index in left_elements:
|
|
839 |
for right_element, right_index in right_elements:
|
|
840 |
wire = Wire(self)
|
|
841 |
wires.append(wire)
|
|
842 |
right_element.InsertConnect(right_index, (wire, 0), False)
|
|
843 |
left_element.InsertConnect(left_index, (wire, -1), False)
|
|
844 |
wire.ConnectStartPoint(None, right_element)
|
|
845 |
wire.ConnectEndPoint(None, left_element)
|
|
846 |
wires.reverse()
|
|
847 |
for wire in wires:
|
|
848 |
self.Wires.append(wire)
|
|
849 |
self.Elements.append(wire)
|
|
850 |
rung.SelectElement(wire)
|
|
851 |
right_elements.reverse()
|
|
852 |
for right_element, right_index in right_elements:
|
|
853 |
self.RefreshPosition(right_element.GetParentBlock())
|
|
854 |
self.Blocks.remove(contact)
|
|
855 |
self.Elements.remove(contact)
|
|
856 |
self.Controler.RemoveCurrentElementEditingInstance(contact.GetId())
|
|
857 |
rung.RefreshBoundingBox()
|
|
858 |
new_bbox = rung.GetBoundingBox()
|
|
859 |
self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
|
|
860 |
self.SelectedElement = None
|
|
861 |
|
8
|
862 |
def RecursiveDeletion(self, element, rung):
|
|
863 |
connectors = element.GetConnectors()
|
|
864 |
input_wires = [wire for wire, handle in connectors["input"].GetWires()]
|
|
865 |
left_elements = [wire.EndConnected for wire in input_wires]
|
|
866 |
rung.SelectElement(element)
|
|
867 |
element.Clean()
|
|
868 |
for wire in input_wires:
|
|
869 |
wire.Clean()
|
|
870 |
self.Wires.remove(wire)
|
|
871 |
self.Elements.remove(wire)
|
|
872 |
rung.SelectElement(wire)
|
|
873 |
self.Blocks.remove(element)
|
|
874 |
self.Elements.remove(element)
|
|
875 |
self.Controler.RemoveCurrentElementEditingInstance(element.GetId())
|
|
876 |
for left_element in left_elements:
|
|
877 |
block = left_element.GetParentBlock()
|
|
878 |
if len(left_element.GetWires()) == 0:
|
|
879 |
self.RecursiveDeletion(block, rung)
|
|
880 |
else:
|
|
881 |
self.RefreshPosition(block)
|
|
882 |
|
0
|
883 |
def DeleteCoil(self, coil):
|
|
884 |
rungindex = self.FindRung(coil)
|
|
885 |
rung = self.Rungs[rungindex]
|
8
|
886 |
old_bbox = rung.GetBoundingBox()
|
|
887 |
nbcoils = 0
|
0
|
888 |
for element in rung.GetElements():
|
8
|
889 |
if isinstance(element, LD_Coil):
|
|
890 |
nbcoils += 1
|
|
891 |
if nbcoils > 1:
|
|
892 |
connectors = coil.GetConnectors()
|
|
893 |
output_wires = [wire for wire, handle in connectors["output"].GetWires()]
|
|
894 |
right_elements = [wire.StartConnected for wire in output_wires]
|
|
895 |
for wire in output_wires:
|
|
896 |
wire.Clean()
|
|
897 |
self.Wires.remove(wire)
|
|
898 |
self.Elements.remove(wire)
|
|
899 |
rung.SelectElement(wire)
|
|
900 |
for right_element in right_elements:
|
|
901 |
right_block = right_element.GetParentBlock()
|
|
902 |
if isinstance(right_block, LD_PowerRail):
|
|
903 |
if len(right_element.GetWires()) == 0:
|
|
904 |
index = right_block.GetConnectorIndex(right_element)
|
|
905 |
right_block.DeleteConnector(index)
|
|
906 |
powerrail_connectors = right_block.GetConnectors()
|
|
907 |
for connector in powerrail_connectors:
|
|
908 |
for wire, handle in connector.GetWires():
|
|
909 |
block = wire.EndConnected.GetParentBlock()
|
|
910 |
endpoint = wire.EndConnected.GetPosition(False)
|
|
911 |
startpoint = connector.GetPosition(False)
|
|
912 |
block.Move(0, startpoint.y - endpoint.y)
|
|
913 |
self.RefreshPosition(block)
|
|
914 |
self.RecursiveDeletion(coil, rung)
|
|
915 |
else:
|
|
916 |
for element in rung.GetElements():
|
|
917 |
if element in self.Wires:
|
|
918 |
element.Clean()
|
|
919 |
self.Wires.remove(element)
|
|
920 |
self.Elements.remove(element)
|
|
921 |
for element in rung.GetElements():
|
|
922 |
if element in self.Blocks:
|
|
923 |
self.Controler.RemoveCurrentElementEditingInstance(element.GetId())
|
|
924 |
self.Blocks.remove(element)
|
|
925 |
self.Elements.remove(element)
|
|
926 |
self.Controler.RemoveCurrentElementEditingInstance(self.Comments[rungindex].GetId())
|
|
927 |
self.Elements.remove(self.Comments[rungindex])
|
|
928 |
self.Comments.pop(rungindex)
|
|
929 |
self.Rungs.pop(rungindex)
|
|
930 |
if rungindex < len(self.Rungs):
|
|
931 |
next_bbox = self.Rungs[rungindex].GetBoundingBox()
|
|
932 |
self.RefreshRungs(old_bbox.y - next_bbox.y, rungindex)
|
0
|
933 |
self.SelectedElement = None
|
|
934 |
|
|
935 |
def DeleteWire(self, wire):
|
|
936 |
wires = []
|
|
937 |
left_elements = []
|
|
938 |
right_elements = []
|
|
939 |
if wire in self.Wires:
|
|
940 |
wires = [wire]
|
|
941 |
elif wire not in self.Elements:
|
|
942 |
for element in wire.GetElements():
|
|
943 |
if element in self.Wires:
|
|
944 |
wires.append(element)
|
|
945 |
else:
|
|
946 |
wires = []
|
|
947 |
break
|
|
948 |
if len(wires) > 0:
|
|
949 |
rungindex = self.FindRung(wires[0])
|
|
950 |
rung = self.Rungs[rungindex]
|
|
951 |
old_bbox = rung.GetBoundingBox()
|
|
952 |
for wire in wires:
|
|
953 |
connections = wire.GetSelectedSegmentConnections()
|
|
954 |
left_block = wire.EndConnected.GetParentBlock()
|
|
955 |
if wire.EndConnected not in left_elements:
|
|
956 |
left_elements.append(wire.EndConnected)
|
|
957 |
if wire.StartConnected not in right_elements:
|
|
958 |
right_elements.append(wire.StartConnected)
|
|
959 |
if connections == (False, False) or connections == (False, True) and isinstance(left_block, LD_PowerRail):
|
|
960 |
wire.Clean()
|
|
961 |
self.Wires.remove(wire)
|
|
962 |
self.Elements.remove(wire)
|
|
963 |
rung.SelectElement(wire)
|
|
964 |
for left_element in left_elements:
|
|
965 |
left_block = left_element.GetParentBlock()
|
|
966 |
if isinstance(left_block, LD_PowerRail):
|
|
967 |
if len(left_element.GetWires()) == 0:
|
|
968 |
index = left_block.GetConnectorIndex(left_element)
|
|
969 |
left_block.DeleteConnector(index)
|
|
970 |
else:
|
|
971 |
connectors = left_block.GetConnectors()
|
|
972 |
output_connectors = []
|
|
973 |
if "outputs" in connectors:
|
|
974 |
output_connectors = connectors["outputs"]
|
|
975 |
if "output" in connectors:
|
|
976 |
output_connectors = [connectors["output"]]
|
|
977 |
for connector in output_connectors:
|
|
978 |
for wire, handle in connector.GetWires():
|
|
979 |
self.RefreshPosition(wire.StartConnected.GetParentBlock())
|
|
980 |
for right_element in right_elements:
|
|
981 |
self.RefreshPosition(right_element.GetParentBlock())
|
|
982 |
rung.RefreshBoundingBox()
|
|
983 |
new_bbox = rung.GetBoundingBox()
|
|
984 |
self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
|
|
985 |
self.SelectedElement = None
|
|
986 |
|
|
987 |
#-------------------------------------------------------------------------------
|
|
988 |
# Refresh element position functions
|
|
989 |
#-------------------------------------------------------------------------------
|
|
990 |
|
8
|
991 |
def RefreshPosition(self, element, recursive=True):
|
0
|
992 |
if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL:
|
|
993 |
element.RefreshModel()
|
|
994 |
return
|
|
995 |
connectors = element.GetConnectors()
|
|
996 |
input_connectors = []
|
|
997 |
output_connectors = []
|
|
998 |
if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL:
|
|
999 |
input_connectors = connectors
|
8
|
1000 |
for i, connector in enumerate(input_connectors):
|
|
1001 |
for j, (wire, handle) in enumerate(connector.GetWires()):
|
|
1002 |
block = wire.EndConnected.GetParentBlock()
|
|
1003 |
self.RefreshPosition(block, False)
|
0
|
1004 |
else:
|
|
1005 |
if "inputs" in connectors:
|
|
1006 |
input_connectors = connectors["inputs"]
|
|
1007 |
if "outputs" in connectors:
|
|
1008 |
output_connectors = connectors["outputs"]
|
|
1009 |
if "input" in connectors:
|
|
1010 |
input_connectors = [connectors["input"]]
|
|
1011 |
if "output" in connectors:
|
|
1012 |
output_connectors = [connectors["output"]]
|
|
1013 |
position = element.GetPosition()
|
|
1014 |
minx = 0
|
|
1015 |
onlyone = []
|
|
1016 |
for connector in input_connectors:
|
|
1017 |
onlyone.append(len(connector.GetWires()) == 1)
|
|
1018 |
for wire, handle in connector.GetWires():
|
|
1019 |
onlyone[-1] &= len(wire.EndConnected.GetWires()) == 1
|
|
1020 |
leftblock = wire.EndConnected.GetParentBlock()
|
|
1021 |
pos = leftblock.GetPosition()
|
|
1022 |
size = leftblock.GetSize()
|
|
1023 |
minx = max(minx, pos[0] + size[0])
|
|
1024 |
if isinstance(element, LD_Coil):
|
|
1025 |
interval = LD_WIRECOIL_SIZE
|
|
1026 |
else:
|
|
1027 |
interval = LD_WIRE_SIZE
|
|
1028 |
if False in onlyone:
|
|
1029 |
interval += LD_WIRE_SIZE
|
|
1030 |
movex = minx + interval - position[0]
|
|
1031 |
element.Move(movex, 0)
|
8
|
1032 |
position = element.GetPosition()
|
0
|
1033 |
for i, connector in enumerate(input_connectors):
|
|
1034 |
startpoint = connector.GetPosition(False)
|
|
1035 |
previous_blocks = []
|
|
1036 |
block_list = []
|
|
1037 |
start_offset = 0
|
|
1038 |
if not onlyone[i]:
|
|
1039 |
middlepoint = minx + LD_WIRE_SIZE
|
|
1040 |
for j, (wire, handle) in enumerate(connector.GetWires()):
|
|
1041 |
block = wire.EndConnected.GetParentBlock()
|
8
|
1042 |
if isinstance(element, LD_PowerRail):
|
|
1043 |
pos = block.GetPosition()
|
|
1044 |
size = leftblock.GetSize()
|
|
1045 |
movex = position[0] - LD_WIRE_SIZE - size[0] - pos[0]
|
|
1046 |
block.Move(movex, 0)
|
0
|
1047 |
endpoint = wire.EndConnected.GetPosition(False)
|
|
1048 |
if j == 0:
|
|
1049 |
if not onlyone[i] and wire.EndConnected.GetWireIndex(wire) > 0:
|
|
1050 |
start_offset = endpoint.y - startpoint.y
|
|
1051 |
offset = start_offset
|
|
1052 |
else:
|
|
1053 |
offset = start_offset + LD_LINE_SIZE * CalcBranchSize(previous_blocks, block)
|
|
1054 |
if block in block_list:
|
|
1055 |
wires = wire.EndConnected.GetWires()
|
|
1056 |
endmiddlepoint = wires[0][0].StartConnected.GetPosition(False)[0] - LD_WIRE_SIZE
|
|
1057 |
points = [startpoint, wxPoint(middlepoint, startpoint.y),
|
|
1058 |
wxPoint(middlepoint, startpoint.y + offset),
|
|
1059 |
wxPoint(endmiddlepoint, startpoint.y + offset),
|
|
1060 |
wxPoint(endmiddlepoint, endpoint.y), endpoint]
|
|
1061 |
else:
|
|
1062 |
if startpoint.y + offset != endpoint.y:
|
8
|
1063 |
if isinstance(element, LD_PowerRail):
|
|
1064 |
diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE
|
|
1065 |
for k in xrange(abs(diff)):
|
|
1066 |
if diff < 0:
|
|
1067 |
element.DeleteConnector(i - 1 - k)
|
|
1068 |
else:
|
|
1069 |
element.InsertConnector(i + k, False)
|
|
1070 |
elif isinstance(block, LD_PowerRail):
|
0
|
1071 |
index = block.GetConnectorIndex(wire.EndConnected)
|
|
1072 |
if index:
|
|
1073 |
diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE
|
|
1074 |
for k in xrange(abs(diff)):
|
|
1075 |
if diff < 0:
|
|
1076 |
block.DeleteConnector(index - 1 - k)
|
|
1077 |
else:
|
|
1078 |
block.InsertConnector(index + k, False)
|
|
1079 |
else:
|
|
1080 |
block.Move(0, startpoint.y + offset - endpoint.y)
|
8
|
1081 |
self.RefreshPosition(block, False)
|
0
|
1082 |
endpoint = wire.EndConnected.GetPosition(False)
|
|
1083 |
if not onlyone[i]:
|
|
1084 |
points = [startpoint, wxPoint(middlepoint, startpoint.y),
|
|
1085 |
wxPoint(middlepoint, endpoint.y), endpoint]
|
|
1086 |
else:
|
|
1087 |
points = [startpoint, endpoint]
|
|
1088 |
wire.SetPoints(points)
|
|
1089 |
previous_blocks.append(block)
|
|
1090 |
ExtractNextBlocks(block, block_list)
|
|
1091 |
element.RefreshModel(False)
|
8
|
1092 |
if recursive:
|
|
1093 |
for connector in output_connectors:
|
|
1094 |
for wire, handle in connector.GetWires():
|
|
1095 |
self.RefreshPosition(wire.StartConnected.GetParentBlock())
|
0
|
1096 |
|
|
1097 |
def RefreshRungs(self, movey, fromidx):
|
|
1098 |
if movey != 0:
|
|
1099 |
for i in xrange(fromidx, len(self.Rungs)):
|
|
1100 |
self.Comments[i].Move(0, movey)
|
|
1101 |
self.Comments[i].RefreshModel()
|
|
1102 |
self.Rungs[i].Move(0, movey)
|
|
1103 |
for element in self.Rungs[i].GetElements():
|
|
1104 |
if element in self.Blocks:
|
|
1105 |
self.RefreshPosition(element)
|
|
1106 |
|
|
1107 |
#-------------------------------------------------------------------------------
|
|
1108 |
# Edit element content functions
|
|
1109 |
#-------------------------------------------------------------------------------
|
|
1110 |
|
|
1111 |
def EditContactContent(self, contact):
|
|
1112 |
dialog = LDElementDialog(self.Parent, "contact")
|
|
1113 |
varlist = []
|
|
1114 |
vars = self.Controler.GetCurrentElementEditingInterfaceVars()
|
|
1115 |
if vars:
|
|
1116 |
for var in vars:
|
2
|
1117 |
if var["Class"] != "Output" and var["Type"] == "BOOL":
|
0
|
1118 |
varlist.append(var["Name"])
|
|
1119 |
dialog.SetVariables(varlist)
|
|
1120 |
dialog.SetValues({"name":contact.GetName(),"type":contact.GetType()})
|
|
1121 |
if dialog.ShowModal() == wxID_OK:
|
|
1122 |
values = dialog.GetValues()
|
|
1123 |
contact.SetName(values["name"])
|
|
1124 |
contact.SetType(values["type"])
|
|
1125 |
contact.RefreshModel(False)
|
|
1126 |
self.Refresh()
|
|
1127 |
dialog.Destroy()
|
|
1128 |
|
|
1129 |
def EditCoilContent(self, coil):
|
|
1130 |
dialog = LDElementDialog(self.Parent, "coil")
|
|
1131 |
varlist = []
|
|
1132 |
vars = self.Controler.GetCurrentElementEditingInterfaceVars()
|
|
1133 |
if vars:
|
|
1134 |
for var in vars:
|
2
|
1135 |
if var["Class"] != "Input" and var["Type"] == "BOOL":
|
0
|
1136 |
varlist.append(var["Name"])
|
|
1137 |
returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
|
|
1138 |
if returntype == "BOOL":
|
|
1139 |
varlist.append(self.Controler.GetCurrentElementEditingName())
|
|
1140 |
dialog.SetVariables(varlist)
|
|
1141 |
dialog.SetValues({"name":coil.GetName(),"type":coil.GetType()})
|
|
1142 |
if dialog.ShowModal() == wxID_OK:
|
|
1143 |
values = dialog.GetValues()
|
|
1144 |
coil.SetName(values["name"])
|
|
1145 |
coil.SetType(values["type"])
|
|
1146 |
coil.RefreshModel(False)
|
|
1147 |
self.Refresh()
|
|
1148 |
dialog.Destroy()
|
|
1149 |
|
|
1150 |
#-------------------------------------------------------------------------------
|
|
1151 |
# Edit Ladder Element Properties Dialog
|
|
1152 |
#-------------------------------------------------------------------------------
|
|
1153 |
|
|
1154 |
[wxID_LDELEMENTDIALOG, wxID_LDELEMENTDIALOGMAINPANEL,
|
|
1155 |
wxID_LDELEMENTDIALOGNAME, wxID_LDELEMENTDIALOGRADIOBUTTON1,
|
|
1156 |
wxID_LDELEMENTDIALOGRADIOBUTTON2, wxID_LDELEMENTDIALOGRADIOBUTTON3,
|
|
1157 |
wxID_LDELEMENTDIALOGRADIOBUTTON4, wxID_LDELEMENTDIALOGPREVIEW,
|
|
1158 |
wxID_LDELEMENTDIALOGSTATICTEXT1, wxID_LDELEMENTDIALOGSTATICTEXT2,
|
|
1159 |
wxID_LDELEMENTDIALOGSTATICTEXT3,
|
|
1160 |
] = [wx.NewId() for _init_ctrls in range(11)]
|
|
1161 |
|
|
1162 |
class LDElementDialog(wx.Dialog):
|
|
1163 |
def _init_coll_flexGridSizer1_Items(self, parent):
|
|
1164 |
# generated method, don't edit
|
|
1165 |
|
|
1166 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
|
|
1167 |
|
|
1168 |
def _init_sizers(self):
|
|
1169 |
# generated method, don't edit
|
|
1170 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
|
|
1171 |
|
|
1172 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
|
|
1173 |
|
|
1174 |
self.SetSizer(self.flexGridSizer1)
|
|
1175 |
|
|
1176 |
def _init_ctrls(self, prnt, title, labels):
|
|
1177 |
# generated method, don't edit
|
|
1178 |
wx.Dialog.__init__(self, id=wxID_LDELEMENTDIALOG,
|
|
1179 |
name='VariablePropertiesDialog', parent=prnt, pos=wx.Point(376, 223),
|
|
1180 |
size=wx.Size(350, 260), style=wx.DEFAULT_DIALOG_STYLE,
|
|
1181 |
title=title)
|
|
1182 |
self.SetClientSize(wx.Size(350, 260))
|
|
1183 |
|
|
1184 |
self.MainPanel = wx.Panel(id=wxID_LDELEMENTDIALOGMAINPANEL,
|
|
1185 |
name='MainPanel', parent=self, pos=wx.Point(0, 0),
|
|
1186 |
size=wx.Size(340, 200), style=wx.TAB_TRAVERSAL)
|
|
1187 |
self.MainPanel.SetAutoLayout(True)
|
|
1188 |
|
|
1189 |
self.staticText1 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT1,
|
6
|
1190 |
label='Modifier:', name='staticText1', parent=self.MainPanel,
|
0
|
1191 |
pos=wx.Point(24, 24), size=wx.Size(70, 17), style=0)
|
|
1192 |
|
|
1193 |
self.staticText2 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT2,
|
|
1194 |
label='Name:', name='staticText2', parent=self.MainPanel,
|
|
1195 |
pos=wx.Point(24, 150), size=wx.Size(70, 17), style=0)
|
|
1196 |
|
|
1197 |
self.staticText3 = wx.StaticText(id=wxID_LDELEMENTDIALOGSTATICTEXT3,
|
|
1198 |
label='Preview:', name='staticText3', parent=self.MainPanel,
|
|
1199 |
pos=wx.Point(174, 24), size=wx.Size(100, 17), style=0)
|
|
1200 |
|
|
1201 |
self.radioButton1 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON1,
|
|
1202 |
label=labels[0], name='radioButton1', parent=self.MainPanel,
|
|
1203 |
pos=wx.Point(24, 48), size=wx.Size(114, 24), style=0)
|
|
1204 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON1, self.OnTypeChanged)
|
|
1205 |
self.radioButton1.SetValue(True)
|
|
1206 |
|
|
1207 |
self.radioButton2 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON2,
|
|
1208 |
label=labels[1], name='radioButton2', parent=self.MainPanel,
|
|
1209 |
pos=wx.Point(24, 72), size=wx.Size(128, 24), style=0)
|
|
1210 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON2, self.OnTypeChanged)
|
|
1211 |
|
|
1212 |
self.radioButton3 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON3,
|
|
1213 |
label=labels[2], name='radioButton3', parent=self.MainPanel,
|
|
1214 |
pos=wx.Point(24, 96), size=wx.Size(114, 24), style=0)
|
|
1215 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON3, self.OnTypeChanged)
|
|
1216 |
|
|
1217 |
self.radioButton4 = wx.RadioButton(id=wxID_LDELEMENTDIALOGRADIOBUTTON4,
|
|
1218 |
label=labels[3], name='radioButton4', parent=self.MainPanel,
|
|
1219 |
pos=wx.Point(24, 120), size=wx.Size(128, 24), style=0)
|
|
1220 |
EVT_RADIOBUTTON(self, wxID_LDELEMENTDIALOGRADIOBUTTON4, self.OnTypeChanged)
|
|
1221 |
|
|
1222 |
self.Name = wx.Choice(id=wxID_LDELEMENTDIALOGNAME,
|
|
1223 |
name='Name', parent=self.MainPanel, pos=wx.Point(24, 174),
|
|
1224 |
size=wx.Size(145, 24), style=0)
|
|
1225 |
EVT_CHOICE(self, wxID_LDELEMENTDIALOGNAME, self.OnNameChanged)
|
|
1226 |
|
|
1227 |
self.Preview = wx.Panel(id=wxID_LDELEMENTDIALOGPREVIEW,
|
|
1228 |
name='Preview', parent=self.MainPanel, pos=wx.Point(174, 48),
|
|
1229 |
size=wx.Size(150, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
|
|
1230 |
self.Preview.SetBackgroundColour(wxColour(255,255,255))
|
|
1231 |
|
|
1232 |
self._init_sizers()
|
|
1233 |
|
|
1234 |
def __init__(self, parent, type):
|
|
1235 |
self.Type = type
|
|
1236 |
if type == "contact":
|
2
|
1237 |
self._init_ctrls(parent, "Edit Contact Values", ['Normal','Negate','Rising Edge','Falling Edge'])
|
0
|
1238 |
self.Element = LD_Contact(self.Preview, CONTACT_NORMAL, "")
|
|
1239 |
elif type == "coil":
|
2
|
1240 |
self._init_ctrls(parent, "Edit Coil Values", ['Normal','Negate','Set','Reset'])
|
0
|
1241 |
self.Element = LD_Coil(self.Preview, COIL_NORMAL, "")
|
|
1242 |
self.Element.SetPosition((150 - LD_ELEMENT_SIZE[0]) / 2, (150 - LD_ELEMENT_SIZE[1]) / 2)
|
|
1243 |
|
9
|
1244 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
|
0
|
1245 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
|
|
1246 |
|
|
1247 |
EVT_PAINT(self, self.OnPaint)
|
|
1248 |
|
|
1249 |
def SetVariables(self, vars):
|
|
1250 |
self.Name.Clear()
|
|
1251 |
for name in vars:
|
|
1252 |
self.Name.Append(name)
|
|
1253 |
self.Name.Enable(self.Name.GetCount() > 0)
|
|
1254 |
|
|
1255 |
def SetValues(self, values):
|
|
1256 |
for name, value in values.items():
|
|
1257 |
if name == "name":
|
|
1258 |
self.Element.SetName(value)
|
|
1259 |
self.Name.SetStringSelection(value)
|
|
1260 |
elif name == "type":
|
|
1261 |
self.Element.SetType(value)
|
|
1262 |
if self.Type == "contact":
|
|
1263 |
if value == CONTACT_NORMAL:
|
|
1264 |
self.radioButton1.SetValue(True)
|
|
1265 |
elif value == CONTACT_REVERSE:
|
|
1266 |
self.radioButton2.SetValue(True)
|
|
1267 |
elif value == CONTACT_RISING:
|
|
1268 |
self.radioButton3.SetValue(True)
|
|
1269 |
elif value == CONTACT_FALLING:
|
|
1270 |
self.radioButton4.SetValue(True)
|
|
1271 |
elif self.Type == "coil":
|
|
1272 |
if value == COIL_NORMAL:
|
|
1273 |
self.radioButton1.SetValue(True)
|
|
1274 |
elif value == COIL_REVERSE:
|
|
1275 |
self.radioButton2.SetValue(True)
|
|
1276 |
elif value == COIL_SET:
|
|
1277 |
self.radioButton3.SetValue(True)
|
|
1278 |
elif value == COIL_RESET:
|
|
1279 |
self.radioButton4.SetValue(True)
|
|
1280 |
|
|
1281 |
def GetValues(self):
|
|
1282 |
values = {}
|
|
1283 |
values["name"] = self.Element.GetName()
|
|
1284 |
values["type"] = self.Element.GetType()
|
|
1285 |
return values
|
|
1286 |
|
|
1287 |
def OnTypeChanged(self, event):
|
|
1288 |
if self.Type == "contact":
|
|
1289 |
if self.radioButton1.GetValue():
|
|
1290 |
self.Element.SetType(CONTACT_NORMAL)
|
|
1291 |
elif self.radioButton2.GetValue():
|
|
1292 |
self.Element.SetType(CONTACT_REVERSE)
|
|
1293 |
elif self.radioButton3.GetValue():
|
|
1294 |
self.Element.SetType(CONTACT_RISING)
|
|
1295 |
elif self.radioButton4.GetValue():
|
|
1296 |
self.Element.SetType(CONTACT_FALLING)
|
|
1297 |
elif self.Type == "coil":
|
|
1298 |
if self.radioButton1.GetValue():
|
|
1299 |
self.Element.SetType(COIL_NORMAL)
|
|
1300 |
elif self.radioButton2.GetValue():
|
|
1301 |
self.Element.SetType(COIL_REVERSE)
|
|
1302 |
elif self.radioButton3.GetValue():
|
|
1303 |
self.Element.SetType(COIL_SET)
|
|
1304 |
elif self.radioButton4.GetValue():
|
|
1305 |
self.Element.SetType(COIL_RESET)
|
|
1306 |
self.RefreshPreview()
|
|
1307 |
event.Skip()
|
|
1308 |
|
|
1309 |
def OnNameChanged(self, event):
|
|
1310 |
self.Element.SetName(self.Name.GetStringSelection())
|
|
1311 |
self.RefreshPreview()
|
|
1312 |
event.Skip()
|
|
1313 |
|
|
1314 |
def RefreshPreview(self):
|
|
1315 |
dc = wxClientDC(self.Preview)
|
|
1316 |
dc.Clear()
|
|
1317 |
self.Element.Draw(dc)
|
|
1318 |
|
|
1319 |
def OnPaint(self, event):
|
|
1320 |
self.RefreshPreview()
|
|
1321 |
event.Skip()
|