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