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