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