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