author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 30 Aug 2024 11:50:23 +0200 | |
changeset 4008 | f30573e98600 |
parent 3975 | 2ef76b61bf1e |
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
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:
1356
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1872
diff
changeset
|
25 |
|
3759
f713566d5d01
convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents:
3752
diff
changeset
|
26 |
from functools import cmp_to_key |
f713566d5d01
convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents:
3752
diff
changeset
|
27 |
from operator import eq |
814 | 28 |
import wx |
29 |
||
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
814
diff
changeset
|
30 |
from graphics.GraphicCommons import * |
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
814
diff
changeset
|
31 |
from graphics.DebugDataConsumer import DebugDataConsumer |
814 | 32 |
from plcopen.structures import * |
33 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
34 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
35 |
# ------------------------------------------------------------------------------- |
814 | 36 |
# Ladder Diagram PowerRail |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
37 |
# ------------------------------------------------------------------------------- |
814 | 38 |
|
39 |
||
40 |
class LD_PowerRail(Graphic_Element): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
41 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
42 |
Class that implements the graphic representation of a power rail |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
43 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
44 |
|
814 | 45 |
# Create a new power rail |
46 |
def __init__(self, parent, type, id=None, connectors=1): |
|
47 |
Graphic_Element.__init__(self, parent) |
|
48 |
self.Type = None |
|
49 |
self.Connectors = [] |
|
50 |
self.RealConnectors = None |
|
51 |
self.Id = id |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
52 |
self.Extensions = [LD_LINE_SIZE // 2, LD_LINE_SIZE // 2] |
814 | 53 |
self.SetType(type, connectors) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
54 |
|
814 | 55 |
def Flush(self): |
56 |
for connector in self.Connectors: |
|
57 |
connector.Flush() |
|
58 |
self.Connectors = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
59 |
|
814 | 60 |
# Make a clone of this LD_PowerRail |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
61 |
def Clone(self, parent, id=None, pos=None): |
814 | 62 |
powerrail = LD_PowerRail(parent, self.Type, id) |
63 |
powerrail.SetSize(self.Size[0], self.Size[1]) |
|
64 |
if pos is not None: |
|
65 |
powerrail.SetPosition(pos.x, pos.y) |
|
66 |
else: |
|
67 |
powerrail.SetPosition(self.Pos.x, self.Pos.y) |
|
68 |
powerrail.Connectors = [] |
|
69 |
for connector in self.Connectors: |
|
70 |
powerrail.Connectors.append(connector.Clone(powerrail)) |
|
71 |
return powerrail |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
72 |
|
814 | 73 |
def GetConnectorTranslation(self, element): |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
74 |
return dict(list(zip([connector for connector in self.Connectors], |
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
75 |
[connector for connector in element.Connectors]))) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
76 |
|
814 | 77 |
# Returns the RedrawRect |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
78 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 79 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
80 |
for connector in self.Connectors: |
|
81 |
rect = rect.Union(connector.GetRedrawRect(movex, movey)) |
|
82 |
if movex != 0 or movey != 0: |
|
83 |
for connector in self.Connectors: |
|
84 |
if connector.IsConnected(): |
|
85 |
rect = rect.Union(connector.GetConnectedRedrawRect(movex, movey)) |
|
86 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
87 |
|
814 | 88 |
# Forbids to change the power rail size |
89 |
def SetSize(self, width, height): |
|
90 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
91 |
Graphic_Element.SetSize(self, width, height) |
|
92 |
else: |
|
93 |
Graphic_Element.SetSize(self, LD_POWERRAIL_WIDTH, height) |
|
94 |
self.RefreshConnectors() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
95 |
|
814 | 96 |
# Forbids to select a power rail |
97 |
def HitTest(self, pt, connectors=True): |
|
98 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
1743
c3c3d1318130
clean-up: fix PEP8 E711 comparison to None should be 'if cond is not None:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
99 |
return Graphic_Element.HitTest(self, pt, connectors) or self.TestConnector(pt, exclude=False) is not None |
814 | 100 |
return False |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
101 |
|
814 | 102 |
# Forbids to select a power rail |
103 |
def IsInSelection(self, rect): |
|
104 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
105 |
return Graphic_Element.IsInSelection(self, rect) |
|
106 |
return False |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
107 |
|
814 | 108 |
# Deletes this power rail by calling the appropriate method |
109 |
def Delete(self): |
|
110 |
self.Parent.DeletePowerRail(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
111 |
|
814 | 112 |
# Unconnect all connectors |
113 |
def Clean(self): |
|
114 |
for connector in self.Connectors: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
115 |
connector.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
116 |
|
814 | 117 |
# Refresh the power rail bounding box |
118 |
def RefreshBoundingBox(self): |
|
119 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
120 |
|
814 | 121 |
# Refresh the power rail size |
122 |
def RefreshSize(self): |
|
123 |
self.Size = wx.Size(LD_POWERRAIL_WIDTH, max(LD_LINE_SIZE * len(self.Connectors), self.Size[1])) |
|
124 |
self.RefreshBoundingBox() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
125 |
|
814 | 126 |
# Returns the block minimum size |
1258
441f31474b50
Fixed move of LD_PowerRail and SFC_Divergence connectors using Right button
Laurent Bessard
parents:
1176
diff
changeset
|
127 |
def GetMinSize(self, default=False): |
441f31474b50
Fixed move of LD_PowerRail and SFC_Divergence connectors using Right button
Laurent Bessard
parents:
1176
diff
changeset
|
128 |
height = (LD_LINE_SIZE * (len(self.Connectors) - 1) |
441f31474b50
Fixed move of LD_PowerRail and SFC_Divergence connectors using Right button
Laurent Bessard
parents:
1176
diff
changeset
|
129 |
if default else 0) |
441f31474b50
Fixed move of LD_PowerRail and SFC_Divergence connectors using Right button
Laurent Bessard
parents:
1176
diff
changeset
|
130 |
return LD_POWERRAIL_WIDTH, height + self.Extensions[0] + self.Extensions[1] |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
131 |
|
814 | 132 |
# Add a connector or a blank to this power rail at the last place |
133 |
def AddConnector(self): |
|
134 |
self.InsertConnector(len(self.Connectors)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
135 |
|
814 | 136 |
# Add a connector or a blank to this power rail at the place given |
137 |
def InsertConnector(self, idx): |
|
138 |
if self.Type == LEFTRAIL: |
|
139 |
connector = Connector(self, "", "BOOL", wx.Point(self.Size[0], 0), EAST) |
|
140 |
elif self.Type == RIGHTRAIL: |
|
141 |
connector = Connector(self, "", "BOOL", wx.Point(0, 0), WEST) |
|
142 |
self.Connectors.insert(idx, connector) |
|
143 |
self.RefreshSize() |
|
144 |
self.RefreshConnectors() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
145 |
|
814 | 146 |
# Moves the divergence connector given |
147 |
def MoveConnector(self, connector, movey): |
|
148 |
position = connector.GetRelPosition() |
|
149 |
connector.SetPosition(wx.Point(position.x, position.y + movey)) |
|
150 |
miny = self.Size[1] |
|
151 |
maxy = 0 |
|
152 |
for connect in self.Connectors: |
|
153 |
connect_pos = connect.GetRelPosition() |
|
154 |
miny = min(miny, connect_pos.y - self.Extensions[0]) |
|
155 |
maxy = max(maxy, connect_pos.y - self.Extensions[0]) |
|
156 |
min_pos = self.Pos.y + miny |
|
157 |
self.Pos.y = min(min_pos, self.Pos.y) |
|
158 |
if min_pos == self.Pos.y: |
|
159 |
for connect in self.Connectors: |
|
160 |
connect_pos = connect.GetRelPosition() |
|
161 |
connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny)) |
|
3759
f713566d5d01
convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents:
3752
diff
changeset
|
162 |
self.Connectors.sort(key=cmp_to_key(lambda x, y: eq(x.Pos.y, y.Pos.y))) |
814 | 163 |
maxy = 0 |
164 |
for connect in self.Connectors: |
|
165 |
connect_pos = connect.GetRelPosition() |
|
166 |
maxy = max(maxy, connect_pos.y) |
|
167 |
self.Size[1] = max(maxy + self.Extensions[1], self.Size[1]) |
|
168 |
connector.MoveConnected() |
|
169 |
self.RefreshBoundingBox() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
170 |
|
814 | 171 |
# Returns the index in connectors list for the connector given |
172 |
def GetConnectorIndex(self, connector): |
|
173 |
if connector in self.Connectors: |
|
174 |
return self.Connectors.index(connector) |
|
175 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
176 |
|
814 | 177 |
# Delete the connector or blank from connectors list at the index given |
178 |
def DeleteConnector(self, idx): |
|
179 |
self.Connectors.pop(idx) |
|
180 |
self.RefreshConnectors() |
|
181 |
self.RefreshSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
182 |
|
814 | 183 |
# Refresh the positions of the power rail connectors |
184 |
def RefreshConnectors(self): |
|
185 |
scaling = self.Parent.GetScaling() |
|
186 |
height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
187 |
interval = height / max(len(self.Connectors) - 1, 1) |
814 | 188 |
for i, connector in enumerate(self.Connectors): |
189 |
if self.RealConnectors: |
|
190 |
position = self.Extensions[0] + int(round(self.RealConnectors[i] * height)) |
|
191 |
else: |
|
192 |
position = self.Extensions[0] + int(round(i * interval)) |
|
193 |
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
|
194 |
position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y |
814 | 195 |
if self.Type == LEFTRAIL: |
196 |
connector.SetPosition(wx.Point(self.Size[0], position)) |
|
197 |
elif self.Type == RIGHTRAIL: |
|
198 |
connector.SetPosition(wx.Point(0, position)) |
|
199 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
200 |
|
814 | 201 |
# Refresh the position of wires connected to power rail |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
202 |
def RefreshConnected(self, exclude=None): |
814 | 203 |
for connector in self.Connectors: |
204 |
connector.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
205 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
206 |
# Returns the power rail connector that starts with the point given if it exists |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
207 |
def GetConnector(self, position, name=None): |
814 | 208 |
# if a name is given |
209 |
if name is not None: |
|
210 |
# Test each connector if it exists |
|
211 |
for connector in self.Connectors: |
|
212 |
if name == connector.GetName(): |
|
213 |
return connector |
|
214 |
return self.FindNearestConnector(position, [connector for connector in self.Connectors if connector is not None]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
215 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
216 |
# Returns all the power rail connectors |
814 | 217 |
def GetConnectors(self): |
218 |
connectors = [connector for connector in self.Connectors if connector] |
|
219 |
if self.Type == LEFTRAIL: |
|
220 |
return {"inputs": [], "outputs": connectors} |
|
221 |
else: |
|
222 |
return {"inputs": connectors, "outputs": []} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
223 |
|
814 | 224 |
# Test if point given is on one of the power rail connectors |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
225 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 226 |
for connector in self.Connectors: |
227 |
if connector.TestPoint(pt, direction, exclude): |
|
228 |
return connector |
|
229 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
230 |
|
814 | 231 |
# Returns the power rail type |
232 |
def SetType(self, type, connectors): |
|
233 |
if type != self.Type or len(self.Connectors) != connectors: |
|
234 |
# Create a connector or a blank according to 'connectors' and add it in |
|
235 |
# the connectors list |
|
236 |
self.Type = type |
|
237 |
self.Clean() |
|
238 |
self.Connectors = [] |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
239 |
for dummy in range(connectors): |
814 | 240 |
self.AddConnector() |
241 |
self.RefreshSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
242 |
|
814 | 243 |
# Returns the power rail type |
244 |
def GetType(self): |
|
245 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
246 |
|
814 | 247 |
# Method called when a LeftDown event have been generated |
248 |
def OnLeftDown(self, event, dc, scaling): |
|
249 |
self.RealConnectors = [] |
|
250 |
height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
251 |
if height > 0: |
|
252 |
for connector in self.Connectors: |
|
253 |
position = connector.GetRelPosition() |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
254 |
self.RealConnectors.append(max(0., min((position.y - self.Extensions[0]) / height, 1.))) |
814 | 255 |
elif len(self.Connectors) > 1: |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
256 |
self.RealConnectors = [x * 1 / (len(self.Connectors) - 1) for x in range(len(self.Connectors))] |
814 | 257 |
else: |
258 |
self.RealConnectors = [0.5] |
|
259 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
260 |
|
814 | 261 |
# Method called when a LeftUp event have been generated |
262 |
def OnLeftUp(self, event, dc, scaling): |
|
263 |
Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
264 |
self.RealConnectors = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
265 |
|
814 | 266 |
# Method called when a LeftDown event have been generated |
267 |
def OnRightDown(self, event, dc, scaling): |
|
268 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
269 |
# Test if a connector have been handled |
|
270 |
connector = self.TestConnector(pos, exclude=False) |
|
271 |
if connector: |
|
272 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
273 |
wx.CallAfter(self.Parent.SetCurrentCursor, 1) |
|
274 |
self.Selected = False |
|
275 |
# Initializes the last position |
|
276 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
|
277 |
else: |
|
278 |
Graphic_Element.OnRightDown(self, event, dc, scaling) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
279 |
|
814 | 280 |
# Method called when a LeftDClick event have been generated |
281 |
def OnLeftDClick(self, event, dc, scaling): |
|
282 |
# Edit the powerrail properties |
|
283 |
self.Parent.EditPowerRailContent(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
284 |
|
814 | 285 |
# Method called when a RightUp event have been generated |
286 |
def OnRightUp(self, event, dc, scaling): |
|
287 |
handle_type, handle = self.Handle |
|
1258
441f31474b50
Fixed move of LD_PowerRail and SFC_Divergence connectors using Right button
Laurent Bessard
parents:
1176
diff
changeset
|
288 |
if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos: |
814 | 289 |
wires = handle.GetWires() |
290 |
if len(wires) == 1: |
|
291 |
if handle == wires[0][0].StartConnected: |
|
292 |
block = wires[0][0].EndConnected.GetParentBlock() |
|
293 |
else: |
|
294 |
block = wires[0][0].StartConnected.GetParentBlock() |
|
295 |
block.RefreshModel(False) |
|
296 |
Graphic_Element.OnRightUp(self, event, dc, scaling) |
|
297 |
else: |
|
298 |
self.Parent.PopupDefaultMenu() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
299 |
|
814 | 300 |
def Resize(self, x, y, width, height): |
301 |
self.Move(x, y) |
|
302 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
303 |
self.SetSize(width, height) |
|
304 |
else: |
|
305 |
self.SetSize(LD_POWERRAIL_WIDTH, height) |
|
306 |
||
307 |
# Refreshes the powerrail state according to move defined and handle selected |
|
308 |
def ProcessDragging(self, movex, movey, event, scaling): |
|
309 |
handle_type, handle = self.Handle |
|
310 |
# A connector has been handled |
|
311 |
if handle_type == HANDLE_CONNECTOR: |
|
312 |
movey = max(-self.BoundingBox.y, movey) |
|
313 |
if scaling is not None: |
|
314 |
position = handle.GetRelPosition() |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
315 |
movey = round((self.Pos.y + position.y + movey) / scaling[1]) * scaling[1] - self.Pos.y - position.y |
814 | 316 |
self.MoveConnector(handle, movey) |
317 |
return 0, movey |
|
318 |
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
319 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
|
320 |
return 0, 0 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
321 |
|
814 | 322 |
# Refreshes the power rail model |
323 |
def RefreshModel(self, move=True): |
|
324 |
self.Parent.RefreshPowerRailModel(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
325 |
# If power rail has moved and power rail is of type LEFT, refresh the model |
814 | 326 |
# of wires connected to connectors |
327 |
if move and self.Type == LEFTRAIL: |
|
328 |
for connector in self.Connectors: |
|
329 |
connector.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
330 |
|
814 | 331 |
# Draws power rail |
332 |
def Draw(self, dc): |
|
333 |
Graphic_Element.Draw(self, dc) |
|
334 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
335 |
dc.SetBrush(wx.BLACK_BRUSH) |
|
336 |
# Draw a rectangle with the power rail size |
|
337 |
if self.Type == LEFTRAIL: |
|
338 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - LD_POWERRAIL_WIDTH, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1) |
|
339 |
else: |
|
340 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1) |
|
341 |
# Draw connectors |
|
342 |
for connector in self.Connectors: |
|
343 |
connector.Draw(dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
344 |
|
814 | 345 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
346 |
# ------------------------------------------------------------------------------- |
814 | 347 |
# Ladder Diagram Contact |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
348 |
# ------------------------------------------------------------------------------- |
814 | 349 |
|
350 |
||
351 |
class LD_Contact(Graphic_Element, DebugDataConsumer): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
352 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
353 |
Class that implements the graphic representation of a contact |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
354 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
355 |
|
814 | 356 |
# Create a new contact |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
357 |
def __init__(self, parent, type, name, id=None): |
814 | 358 |
Graphic_Element.__init__(self, parent) |
359 |
DebugDataConsumer.__init__(self) |
|
360 |
self.Type = type |
|
361 |
self.Name = name |
|
362 |
self.Id = id |
|
363 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
|
364 |
self.Highlights = {} |
|
365 |
# Create an input and output connector |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
366 |
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] // 2 + 1), WEST) |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
367 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] // 2 + 1), EAST) |
814 | 368 |
self.PreviousValue = False |
369 |
self.PreviousSpreading = False |
|
370 |
self.RefreshNameSize() |
|
371 |
self.RefreshTypeSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
372 |
|
814 | 373 |
def Flush(self): |
374 |
if self.Input is not None: |
|
375 |
self.Input.Flush() |
|
376 |
self.Input = None |
|
377 |
if self.Output is not None: |
|
378 |
self.Output.Flush() |
|
379 |
self.Output = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
380 |
|
814 | 381 |
def SetForced(self, forced): |
382 |
if self.Forced != forced: |
|
383 |
self.Forced = forced |
|
384 |
if self.Visible: |
|
385 |
self.Parent.ElementNeedRefresh(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
386 |
|
814 | 387 |
def SetValue(self, value): |
388 |
if self.Type == CONTACT_RISING: |
|
389 |
refresh = self.Value and not self.PreviousValue |
|
390 |
elif self.Type == CONTACT_FALLING: |
|
391 |
refresh = not self.Value and self.PreviousValue |
|
392 |
else: |
|
393 |
refresh = False |
|
394 |
self.PreviousValue = self.Value |
|
395 |
self.Value = value |
|
396 |
if self.Value != self.PreviousValue or refresh: |
|
397 |
if self.Visible: |
|
398 |
self.Parent.ElementNeedRefresh(self) |
|
399 |
self.SpreadCurrent() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
400 |
|
814 | 401 |
def SpreadCurrent(self): |
402 |
if self.Parent.Debug: |
|
403 |
if self.Value is None: |
|
404 |
self.Value = False |
|
405 |
spreading = self.Input.ReceivingCurrent() |
|
3333
dd49e4055a10
Fixed two exceptions happening when interacting with viewer(s) in debug mode, when debug data is still not initialized.
Edouard Tisserant
parents:
2457
diff
changeset
|
406 |
if spreading == "undefined": |
dd49e4055a10
Fixed two exceptions happening when interacting with viewer(s) in debug mode, when debug data is still not initialized.
Edouard Tisserant
parents:
2457
diff
changeset
|
407 |
spreading = False |
814 | 408 |
if self.Type == CONTACT_NORMAL: |
409 |
spreading &= self.Value |
|
410 |
elif self.Type == CONTACT_REVERSE: |
|
411 |
spreading &= not self.Value |
|
412 |
elif self.Type == CONTACT_RISING: |
|
413 |
spreading &= self.Value and not self.PreviousValue |
|
414 |
elif self.Type == CONTACT_FALLING: |
|
415 |
spreading &= not self.Value and self.PreviousValue |
|
416 |
else: |
|
417 |
spreading = False |
|
418 |
if spreading and not self.PreviousSpreading: |
|
419 |
self.Output.SpreadCurrent(True) |
|
420 |
elif not spreading and self.PreviousSpreading: |
|
421 |
self.Output.SpreadCurrent(False) |
|
422 |
self.PreviousSpreading = spreading |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
423 |
|
814 | 424 |
# Make a clone of this LD_Contact |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
425 |
def Clone(self, parent, id=None, pos=None): |
814 | 426 |
contact = LD_Contact(parent, self.Type, self.Name, id) |
427 |
contact.SetSize(self.Size[0], self.Size[1]) |
|
428 |
if pos is not None: |
|
429 |
contact.SetPosition(pos.x, pos.y) |
|
430 |
else: |
|
431 |
contact.SetPosition(self.Pos.x, self.Pos.y) |
|
432 |
contact.Input = self.Input.Clone(contact) |
|
433 |
contact.Output = self.Output.Clone(contact) |
|
434 |
return contact |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
435 |
|
814 | 436 |
def GetConnectorTranslation(self, element): |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
437 |
return {self.Input: element.Input, self.Output: element.Output} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
438 |
|
814 | 439 |
# Returns the RedrawRect |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
440 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 441 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
442 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
443 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
444 |
if movex != 0 or movey != 0: |
|
445 |
if self.Input.IsConnected(): |
|
446 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
447 |
if self.Output.IsConnected(): |
|
448 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
449 |
return rect |
|
450 |
||
451 |
def ProcessDragging(self, movex, movey, event, scaling): |
|
452 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
|
453 |
movex = movey = 0 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
454 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac=2) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
455 |
|
814 | 456 |
# Forbids to change the contact size |
457 |
def SetSize(self, width, height): |
|
458 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
459 |
Graphic_Element.SetSize(self, width, height) |
|
460 |
self.RefreshConnectors() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
461 |
|
814 | 462 |
# Delete this contact by calling the appropriate method |
463 |
def Delete(self): |
|
464 |
self.Parent.DeleteContact(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
465 |
|
814 | 466 |
# Unconnect input and output |
467 |
def Clean(self): |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
468 |
self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
469 |
self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
470 |
|
814 | 471 |
# Refresh the size of text for name |
472 |
def RefreshNameSize(self): |
|
473 |
if self.Name != "": |
|
474 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
|
475 |
else: |
|
476 |
self.NameSize = 0, 0 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
477 |
|
814 | 478 |
# Refresh the size of text for type |
479 |
def RefreshTypeSize(self): |
|
480 |
typetext = "" |
|
481 |
if self.Type == CONTACT_REVERSE: |
|
482 |
typetext = "/" |
|
483 |
elif self.Type == CONTACT_RISING: |
|
484 |
typetext = "P" |
|
485 |
elif self.Type == CONTACT_FALLING: |
|
486 |
typetext = "N" |
|
487 |
if typetext != "": |
|
488 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
|
489 |
else: |
|
490 |
self.TypeSize = 0, 0 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
491 |
|
814 | 492 |
# Refresh the contact bounding box |
493 |
def RefreshBoundingBox(self): |
|
494 |
# Calculate the size of the name outside the contact |
|
495 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
|
496 |
# Calculate the bounding box size |
|
497 |
if self.Name != "": |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
498 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) // 2) |
814 | 499 |
bbx_width = max(self.Size[0], text_width) |
500 |
bbx_y = self.Pos.y - (text_height + 2) |
|
501 |
bbx_height = self.Size[1] + (text_height + 2) |
|
502 |
else: |
|
503 |
bbx_x = self.Pos.x |
|
504 |
bbx_width = self.Size[0] |
|
505 |
bbx_y = self.Pos.y |
|
506 |
bbx_height = self.Size[1] |
|
507 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
508 |
|
814 | 509 |
# Returns the block minimum size |
510 |
def GetMinSize(self): |
|
511 |
return LD_ELEMENT_SIZE |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
512 |
|
814 | 513 |
# Refresh the position of wire connected to contact |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
514 |
def RefreshConnected(self, exclude=None): |
814 | 515 |
self.Input.MoveConnected(exclude) |
516 |
self.Output.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
517 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
518 |
# Returns the contact connector that starts with the point given if it exists |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
519 |
def GetConnector(self, position, name=None): |
814 | 520 |
# if a name is given |
521 |
if name is not None: |
|
522 |
# Test input and output connector |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
523 |
# if name == self.Input.GetName(): |
814 | 524 |
# return self.Input |
525 |
if name == self.Output.GetName(): |
|
526 |
return self.Output |
|
527 |
return self.FindNearestConnector(position, [self.Input, self.Output]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
528 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
529 |
# Returns input and output contact connectors |
814 | 530 |
def GetConnectors(self): |
531 |
return {"inputs": [self.Input], "outputs": [self.Output]} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
532 |
|
814 | 533 |
# Test if point given is on contact input or output connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
534 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 535 |
# Test input connector |
536 |
if self.Input.TestPoint(pt, direction, exclude): |
|
537 |
return self.Input |
|
538 |
# Test output connector |
|
539 |
if self.Output.TestPoint(pt, direction, exclude): |
|
540 |
return self.Output |
|
541 |
return None |
|
542 |
||
543 |
# Refresh the positions of the block connectors |
|
544 |
def RefreshConnectors(self): |
|
545 |
scaling = self.Parent.GetScaling() |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
546 |
position = self.Size[1] // 2 + 1 |
814 | 547 |
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
|
548 |
position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y |
814 | 549 |
self.Input.SetPosition(wx.Point(0, position)) |
550 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
551 |
self.RefreshConnected() |
|
552 |
||
553 |
# Changes the contact name |
|
554 |
def SetName(self, name): |
|
555 |
self.Name = name |
|
556 |
self.RefreshNameSize() |
|
557 |
||
558 |
# Returns the contact name |
|
559 |
def GetName(self): |
|
560 |
return self.Name |
|
561 |
||
562 |
# Changes the contact type |
|
563 |
def SetType(self, type): |
|
564 |
self.Type = type |
|
565 |
self.RefreshTypeSize() |
|
566 |
||
567 |
# Returns the contact type |
|
568 |
def GetType(self): |
|
569 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
570 |
|
814 | 571 |
# Method called when a LeftDClick event have been generated |
572 |
def OnLeftDClick(self, event, dc, scaling): |
|
573 |
# Edit the contact properties |
|
574 |
self.Parent.EditContactContent(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
575 |
|
814 | 576 |
# Method called when a RightUp event have been generated |
577 |
def OnRightUp(self, event, dc, scaling): |
|
578 |
# Popup the default menu |
|
579 |
self.Parent.PopupDefaultMenu() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
580 |
|
814 | 581 |
# Refreshes the contact model |
582 |
def RefreshModel(self, move=True): |
|
583 |
self.Parent.RefreshContactModel(self) |
|
584 |
# If contact has moved, refresh the model of wires connected to output |
|
585 |
if move: |
|
586 |
self.Output.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
587 |
|
814 | 588 |
# Draws the highlightment of this element if it is highlighted |
589 |
def DrawHighlightment(self, dc): |
|
590 |
scalex, scaley = dc.GetUserScale() |
|
591 |
dc.SetUserScale(1, 1) |
|
592 |
dc.SetPen(MiterPen(HIGHLIGHTCOLOR)) |
|
593 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
594 |
dc.SetLogicalFunction(wx.AND) |
|
595 |
# Draw two rectangles for representing the contact |
|
3975
2ef76b61bf1e
IDE: hopefully last fix about float type being passed to WxPy4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3966
diff
changeset
|
596 |
left_left = round((self.Pos.x - 1) * scalex) - 2 |
2ef76b61bf1e
IDE: hopefully last fix about float type being passed to WxPy4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3966
diff
changeset
|
597 |
right_left = round((self.Pos.x + self.Size[0] - 2) * scalex) - 2 |
2ef76b61bf1e
IDE: hopefully last fix about float type being passed to WxPy4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3966
diff
changeset
|
598 |
top = round((self.Pos.y - 1) * scaley) - 2 |
2ef76b61bf1e
IDE: hopefully last fix about float type being passed to WxPy4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3966
diff
changeset
|
599 |
width = round(4 * scalex + 5) |
2ef76b61bf1e
IDE: hopefully last fix about float type being passed to WxPy4.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3966
diff
changeset
|
600 |
height = round((self.Size[1] + 3) * scaley) + 5 |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
601 |
|
814 | 602 |
dc.DrawRectangle(left_left, top, width, height) |
603 |
dc.DrawRectangle(right_left, top, width, height) |
|
604 |
dc.SetLogicalFunction(wx.COPY) |
|
605 |
dc.SetUserScale(scalex, scaley) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
606 |
|
814 | 607 |
# Adds an highlight to the connection |
608 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
609 |
highlights = self.Highlights.setdefault(infos[0], []) |
|
610 |
if infos[0] == "reference": |
|
611 |
if start[0] == 0 and end[0] == 0: |
|
612 |
AddHighlight(highlights, (start, end, highlight_type)) |
|
613 |
else: |
|
614 |
AddHighlight(highlights, ((0, 0), (0, 1), highlight_type)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
615 |
|
814 | 616 |
# Removes an highlight from the connection |
617 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
618 |
highlights = self.Highlights.get(infos[0], []) |
|
619 |
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
|
620 |
self.Highlights.pop(infos[0]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
621 |
|
814 | 622 |
# Removes all the highlights of one particular type from the connection |
623 |
def ClearHighlight(self, highlight_type=None): |
|
624 |
if highlight_type is None: |
|
625 |
self.Highlights = {} |
|
626 |
else: |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
627 |
highlight_items = list(self.Highlights.items()) |
814 | 628 |
for name, highlights in highlight_items: |
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1852
diff
changeset
|
629 |
highlights = ClearHighlights(highlights, highlight_type) |
814 | 630 |
if len(highlights) == 0: |
631 |
self.Highlights.pop(name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
632 |
|
814 | 633 |
# Draws contact |
634 |
def Draw(self, dc): |
|
635 |
Graphic_Element.Draw(self, dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
636 |
if self.Value is not None: |
814 | 637 |
if self.Type == CONTACT_NORMAL and self.Value or \ |
638 |
self.Type == CONTACT_REVERSE and not self.Value or \ |
|
639 |
self.Type == CONTACT_RISING and self.Value and not self.PreviousValue or \ |
|
640 |
self.Type == CONTACT_RISING and not self.Value and self.PreviousValue: |
|
641 |
if self.Forced: |
|
642 |
dc.SetPen(MiterPen(wx.CYAN)) |
|
643 |
else: |
|
644 |
dc.SetPen(MiterPen(wx.GREEN)) |
|
645 |
elif self.Forced: |
|
646 |
dc.SetPen(MiterPen(wx.BLUE)) |
|
647 |
else: |
|
648 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
649 |
else: |
|
650 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
651 |
dc.SetBrush(wx.BLACK_BRUSH) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
652 |
|
814 | 653 |
# Compiling contact type modifier symbol |
654 |
typetext = "" |
|
655 |
if self.Type == CONTACT_REVERSE: |
|
656 |
typetext = "/" |
|
657 |
elif self.Type == CONTACT_RISING: |
|
658 |
typetext = "P" |
|
659 |
elif self.Type == CONTACT_FALLING: |
|
660 |
typetext = "N" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
661 |
|
814 | 662 |
if getattr(dc, "printing", False): |
663 |
name_size = dc.GetTextExtent(self.Name) |
|
664 |
if typetext != "": |
|
665 |
type_size = dc.GetTextExtent(typetext) |
|
666 |
else: |
|
667 |
name_size = self.NameSize |
|
668 |
if typetext != "": |
|
669 |
type_size = self.TypeSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
670 |
|
814 | 671 |
# Draw two rectangles for representing the contact |
672 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
|
673 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
|
674 |
# Draw contact name |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
675 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, |
814 | 676 |
self.Pos.y - (name_size[1] + 2)) |
677 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
|
678 |
# Draw the modifier symbol in the middle of contact |
|
679 |
if typetext != "": |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
680 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) // 2 + 1, |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
681 |
self.Pos.y + (self.Size[1] - type_size[1]) // 2) |
814 | 682 |
dc.DrawText(typetext, type_pos[0], type_pos[1]) |
683 |
# Draw input and output connectors |
|
684 |
self.Input.Draw(dc) |
|
685 |
self.Output.Draw(dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
686 |
|
814 | 687 |
if not getattr(dc, "printing", False): |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
688 |
for name, highlights in self.Highlights.items(): |
814 | 689 |
if name == "reference": |
690 |
DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
|
691 |
elif typetext != "": |
|
692 |
DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |
|
693 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
694 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
695 |
# ------------------------------------------------------------------------------- |
814 | 696 |
# Ladder Diagram Coil |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
697 |
# ------------------------------------------------------------------------------- |
814 | 698 |
|
699 |
||
700 |
class LD_Coil(Graphic_Element): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
701 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
702 |
Class that implements the graphic representation of a coil |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
703 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
704 |
|
814 | 705 |
# Create a new coil |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
706 |
def __init__(self, parent, type, name, id=None): |
814 | 707 |
Graphic_Element.__init__(self, parent) |
708 |
self.Type = type |
|
709 |
self.Name = name |
|
710 |
self.Id = id |
|
711 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
|
712 |
self.Highlights = {} |
|
713 |
# Create an input and output connector |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
714 |
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] // 2 + 1), WEST) |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
715 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] // 2 + 1), EAST) |
814 | 716 |
self.Value = None |
717 |
self.PreviousValue = False |
|
718 |
self.RefreshNameSize() |
|
719 |
self.RefreshTypeSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
720 |
|
814 | 721 |
def Flush(self): |
722 |
if self.Input is not None: |
|
723 |
self.Input.Flush() |
|
724 |
self.Input = None |
|
725 |
if self.Output is not None: |
|
726 |
self.Output.Flush() |
|
727 |
self.Output = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
728 |
|
814 | 729 |
def SpreadCurrent(self): |
730 |
if self.Parent.Debug: |
|
731 |
self.PreviousValue = self.Value |
|
732 |
self.Value = self.Input.ReceivingCurrent() |
|
733 |
if self.Value and not self.PreviousValue: |
|
734 |
self.Output.SpreadCurrent(True) |
|
735 |
elif not self.Value and self.PreviousValue: |
|
736 |
self.Output.SpreadCurrent(False) |
|
737 |
if self.Value != self.PreviousValue and self.Visible: |
|
738 |
self.Parent.ElementNeedRefresh(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
739 |
|
814 | 740 |
# Make a clone of this LD_Coil |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
741 |
def Clone(self, parent, id=None, pos=None): |
814 | 742 |
coil = LD_Coil(parent, self.Type, self.Name, id) |
743 |
coil.SetSize(self.Size[0], self.Size[1]) |
|
744 |
if pos is not None: |
|
745 |
coil.SetPosition(pos.x, pos.y) |
|
746 |
else: |
|
747 |
coil.SetPosition(self.Pos.x, self.Pos.y) |
|
748 |
coil.Input = self.Input.Clone(coil) |
|
749 |
coil.Output = self.Output.Clone(coil) |
|
750 |
return coil |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
751 |
|
814 | 752 |
def GetConnectorTranslation(self, element): |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
753 |
return {self.Input: element.Input, self.Output: element.Output} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
754 |
|
814 | 755 |
# Returns the RedrawRect |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
756 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 757 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
758 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
759 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
760 |
if movex != 0 or movey != 0: |
|
761 |
if self.Input.IsConnected(): |
|
762 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
763 |
if self.Output.IsConnected(): |
|
764 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
765 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
766 |
|
814 | 767 |
def ProcessDragging(self, movex, movey, event, scaling): |
768 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
|
769 |
movex = movey = 0 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
770 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac=2) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
771 |
|
814 | 772 |
# Forbids to change the Coil size |
773 |
def SetSize(self, width, height): |
|
774 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
775 |
Graphic_Element.SetSize(self, width, height) |
|
776 |
self.RefreshConnectors() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
777 |
|
814 | 778 |
# Delete this coil by calling the appropriate method |
779 |
def Delete(self): |
|
780 |
self.Parent.DeleteCoil(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
781 |
|
814 | 782 |
# Unconnect input and output |
783 |
def Clean(self): |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
784 |
self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
785 |
self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
786 |
|
814 | 787 |
# Refresh the size of text for name |
788 |
def RefreshNameSize(self): |
|
789 |
if self.Name != "": |
|
790 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
|
791 |
else: |
|
792 |
self.NameSize = 0, 0 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
793 |
|
814 | 794 |
# Refresh the size of text for type |
795 |
def RefreshTypeSize(self): |
|
796 |
typetext = "" |
|
797 |
if self.Type == COIL_REVERSE: |
|
798 |
typetext = "/" |
|
799 |
elif self.Type == COIL_SET: |
|
800 |
typetext = "S" |
|
801 |
elif self.Type == COIL_RESET: |
|
802 |
typetext = "R" |
|
803 |
elif self.Type == COIL_RISING: |
|
804 |
typetext = "P" |
|
805 |
elif self.Type == COIL_FALLING: |
|
806 |
typetext = "N" |
|
807 |
if typetext != "": |
|
808 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
|
809 |
else: |
|
810 |
self.TypeSize = 0, 0 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
811 |
|
814 | 812 |
# Refresh the coil bounding box |
813 |
def RefreshBoundingBox(self): |
|
814 |
# Calculate the size of the name outside the coil |
|
815 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
|
816 |
# Calculate the bounding box size |
|
817 |
if self.Name != "": |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
818 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) // 2) |
814 | 819 |
bbx_width = max(self.Size[0], text_width) |
820 |
bbx_y = self.Pos.y - (text_height + 2) |
|
821 |
bbx_height = self.Size[1] + (text_height + 2) |
|
822 |
else: |
|
823 |
bbx_x = self.Pos.x |
|
824 |
bbx_width = self.Size[0] |
|
825 |
bbx_y = self.Pos.y |
|
826 |
bbx_height = self.Size[1] |
|
827 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
828 |
|
814 | 829 |
# Returns the block minimum size |
830 |
def GetMinSize(self): |
|
831 |
return LD_ELEMENT_SIZE |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
832 |
|
814 | 833 |
# Refresh the position of wire connected to coil |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
834 |
def RefreshConnected(self, exclude=None): |
814 | 835 |
self.Input.MoveConnected(exclude) |
836 |
self.Output.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
837 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
838 |
# Returns the coil connector that starts with the point given if it exists |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
839 |
def GetConnector(self, position, name=None): |
814 | 840 |
# if a name is given |
841 |
if name is not None: |
|
842 |
# Test input and output connector |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
843 |
# if self.Input and name == self.Input.GetName(): |
814 | 844 |
# return self.Input |
845 |
if self.Output and name == self.Output.GetName(): |
|
846 |
return self.Output |
|
847 |
return self.FindNearestConnector(position, [self.Input, self.Output]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
848 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
849 |
# Returns input and output coil connectors |
814 | 850 |
def GetConnectors(self): |
851 |
return {"inputs": [self.Input], "outputs": [self.Output]} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
852 |
|
814 | 853 |
# Test if point given is on coil input or output connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1743
diff
changeset
|
854 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 855 |
# Test input connector |
856 |
if self.Input.TestPoint(pt, direction, exclude): |
|
857 |
return self.Input |
|
858 |
# Test output connector |
|
859 |
if self.Output.TestPoint(pt, direction, exclude): |
|
860 |
return self.Output |
|
861 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
862 |
|
814 | 863 |
# Refresh the positions of the block connectors |
864 |
def RefreshConnectors(self): |
|
865 |
scaling = self.Parent.GetScaling() |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
866 |
position = self.Size[1] // 2 + 1 |
814 | 867 |
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
|
868 |
position = round((self.Pos.y + position) / scaling[1]) * scaling[1] - self.Pos.y |
814 | 869 |
self.Input.SetPosition(wx.Point(0, position)) |
870 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
871 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
872 |
|
814 | 873 |
# Changes the coil name |
874 |
def SetName(self, name): |
|
875 |
self.Name = name |
|
876 |
self.RefreshNameSize() |
|
877 |
||
878 |
# Returns the coil name |
|
879 |
def GetName(self): |
|
880 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
881 |
|
814 | 882 |
# Changes the coil type |
883 |
def SetType(self, type): |
|
884 |
self.Type = type |
|
885 |
self.RefreshTypeSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
886 |
|
814 | 887 |
# Returns the coil type |
888 |
def GetType(self): |
|
889 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
890 |
|
814 | 891 |
# Method called when a LeftDClick event have been generated |
892 |
def OnLeftDClick(self, event, dc, scaling): |
|
893 |
# Edit the coil properties |
|
894 |
self.Parent.EditCoilContent(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
895 |
|
814 | 896 |
# Method called when a RightUp event have been generated |
897 |
def OnRightUp(self, event, dc, scaling): |
|
898 |
# Popup the default menu |
|
899 |
self.Parent.PopupDefaultMenu() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
900 |
|
814 | 901 |
# Refreshes the coil model |
902 |
def RefreshModel(self, move=True): |
|
903 |
self.Parent.RefreshCoilModel(self) |
|
904 |
# If coil has moved, refresh the model of wires connected to output |
|
905 |
if move: |
|
906 |
self.Output.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
907 |
|
814 | 908 |
# Draws the highlightment of this element if it is highlighted |
909 |
def DrawHighlightment(self, dc): |
|
910 |
scalex, scaley = dc.GetUserScale() |
|
911 |
dc.SetUserScale(1, 1) |
|
912 |
dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (3 * scalex + 5), wx.SOLID)) |
|
913 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
914 |
dc.SetLogicalFunction(wx.AND) |
|
915 |
# Draw a two circle arcs for representing the coil |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
916 |
dc.DrawEllipticArc(round(self.Pos.x * scalex), |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
917 |
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley), |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
918 |
round(self.Size[0] * scalex), |
814 | 919 |
round((int(self.Size[1] * sqrt(2)) - 1) * scaley), |
920 |
135, 225) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
921 |
dc.DrawEllipticArc(round(self.Pos.x * scalex), |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
922 |
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley), |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
923 |
round(self.Size[0] * scalex), |
814 | 924 |
round((int(self.Size[1] * sqrt(2)) - 1) * scaley), |
925 |
-45, 45) |
|
926 |
dc.SetLogicalFunction(wx.COPY) |
|
927 |
dc.SetUserScale(scalex, scaley) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
928 |
|
814 | 929 |
# Adds an highlight to the connection |
930 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
931 |
highlights = self.Highlights.setdefault(infos[0], []) |
|
932 |
if infos[0] == "reference": |
|
933 |
if start[0] == 0 and end[0] == 0: |
|
934 |
AddHighlight(highlights, (start, end, highlight_type)) |
|
935 |
else: |
|
936 |
AddHighlight(highlights, ((0, 0), (0, 1), highlight_type)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
937 |
|
814 | 938 |
# Removes an highlight from the connection |
939 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
940 |
highlights = self.Highlights.get(infos[0], []) |
|
941 |
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
|
942 |
self.Highlights.pop(infos[0]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
943 |
|
814 | 944 |
# Removes all the highlights of one particular type from the connection |
945 |
def ClearHighlight(self, highlight_type=None): |
|
946 |
if highlight_type is None: |
|
947 |
self.Highlights = {} |
|
948 |
else: |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
949 |
highlight_items = list(self.Highlights.items()) |
814 | 950 |
for name, highlights in highlight_items: |
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1852
diff
changeset
|
951 |
highlights = ClearHighlights(highlights, highlight_type) |
814 | 952 |
if len(highlights) == 0: |
953 |
self.Highlights.pop(name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
954 |
|
814 | 955 |
# Draws coil |
956 |
def Draw(self, dc): |
|
957 |
Graphic_Element.Draw(self, dc) |
|
958 |
if self.Value is not None and self.Value: |
|
959 |
dc.SetPen(MiterPen(wx.GREEN, 2, wx.SOLID)) |
|
960 |
else: |
|
961 |
dc.SetPen(MiterPen(wx.BLACK, 2, wx.SOLID)) |
|
962 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
963 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
964 |
# Compiling coil type modifier symbol |
814 | 965 |
typetext = "" |
966 |
if self.Type == COIL_REVERSE: |
|
967 |
typetext = "/" |
|
968 |
elif self.Type == COIL_SET: |
|
969 |
typetext = "S" |
|
970 |
elif self.Type == COIL_RESET: |
|
971 |
typetext = "R" |
|
972 |
elif self.Type == COIL_RISING: |
|
973 |
typetext = "P" |
|
974 |
elif self.Type == COIL_FALLING: |
|
975 |
typetext = "N" |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
976 |
|
3966
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
977 |
printing = getattr(dc, "printing", False) |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
978 |
# Draw a two ellipse arcs for representing the coil |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
979 |
pos = (self.Pos.x, |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
980 |
self.Pos.y - round(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
981 |
self.Size[0], round(self.Size[1] * sqrt(2)) - 1) |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
982 |
|
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
983 |
if printing: |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
984 |
# workaround for printing bug with DrawEllipticArc |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
985 |
# add an offset to the y position proportional to the height of the ellipse |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
986 |
# sqrt(2) ratio obtained heuristically |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
987 |
pos = (pos[0], pos[1] + round(sqrt(2)*pos[3]), pos[2], pos[3]) |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
988 |
|
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
989 |
dc.DrawEllipticArc(*pos, 135, 225) |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
990 |
dc.DrawEllipticArc(*pos, -45, 45) |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
991 |
|
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
992 |
name_size = self.NameSize |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
993 |
if typetext != "": |
8cc6f56c3710
IDE: Fix printing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3759
diff
changeset
|
994 |
type_size = self.TypeSize |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
995 |
|
814 | 996 |
# Draw coil name |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
997 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, |
814 | 998 |
self.Pos.y - (name_size[1] + 2)) |
999 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
|
1000 |
# Draw the modifier symbol in the middle of coil |
|
1001 |
if typetext != "": |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1002 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) // 2 + 1, |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1003 |
self.Pos.y + (self.Size[1] - type_size[1]) // 2) |
814 | 1004 |
dc.DrawText(typetext, type_pos[0], type_pos[1]) |
1005 |
# Draw input and output connectors |
|
1006 |
self.Input.Draw(dc) |
|
1007 |
self.Output.Draw(dc) |
|
1008 |
||
1009 |
if not getattr(dc, "printing", False): |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3333
diff
changeset
|
1010 |
for name, highlights in self.Highlights.items(): |
814 | 1011 |
if name == "reference": |
1012 |
DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
|
1013 |
elif typetext != "": |
|
1014 |
DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |