author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sat, 13 May 2023 14:28:29 +0200 | |
changeset 3802 | 8616ffd7c29d |
parent 3752 | 9f6f46dbe3ae |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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:
1176
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 |
|
814 | 26 |
import wx |
27 |
||
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1133
diff
changeset
|
28 |
from graphics.GraphicCommons import * |
814 | 29 |
from plcopen.structures import * |
30 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
31 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
32 |
# ------------------------------------------------------------------------------- |
814 | 33 |
# Function Block Diagram Block |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
34 |
# ------------------------------------------------------------------------------- |
814 | 35 |
|
36 |
||
37 |
def TestConnectorName(name, block_type): |
|
38 |
return name in ["OUT", "MN", "MX"] or name.startswith("IN") and (block_type, name) != ("EXPT", "IN2") |
|
39 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
40 |
|
814 | 41 |
class FBD_Block(Graphic_Element): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
42 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
43 |
Class that implements the graphic representation of a function block |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
44 |
""" |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
45 |
|
814 | 46 |
# Create a new block |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
47 |
def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors=None, executionControl=False, executionOrder=0): |
814 | 48 |
Graphic_Element.__init__(self, parent) |
49 |
self.Type = None |
|
50 |
self.Description = None |
|
51 |
self.Extension = None |
|
52 |
self.ExecutionControl = False |
|
53 |
self.Id = id |
|
54 |
self.SetName(name) |
|
55 |
self.SetExecutionOrder(executionOrder) |
|
56 |
self.Inputs = [] |
|
57 |
self.Outputs = [] |
|
58 |
self.Colour = wx.BLACK |
|
59 |
self.Pen = MiterPen(wx.BLACK) |
|
60 |
self.SetType(type, extension, inputs, connectors, executionControl) |
|
61 |
self.Highlights = {} |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
62 |
|
814 | 63 |
# Make a clone of this FBD_Block |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
64 |
def Clone(self, parent, id=None, name="", pos=None): |
814 | 65 |
if self.Name != "" and name == "": |
66 |
name = self.Name |
|
67 |
block = FBD_Block(parent, self.Type, name, id, self.Extension) |
|
68 |
block.SetSize(self.Size[0], self.Size[1]) |
|
69 |
if pos is not None: |
|
70 |
block.SetPosition(pos.x, pos.y) |
|
71 |
else: |
|
72 |
block.SetPosition(self.Pos.x, self.Pos.y) |
|
73 |
block.Inputs = [input.Clone(block) for input in self.Inputs] |
|
74 |
block.Outputs = [output.Clone(block) for output in self.Outputs] |
|
75 |
return block |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
76 |
|
814 | 77 |
def GetConnectorTranslation(self, element): |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3537
diff
changeset
|
78 |
return dict(list(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs))) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
79 |
|
814 | 80 |
def Flush(self): |
81 |
for input in self.Inputs: |
|
82 |
input.Flush() |
|
83 |
self.Inputs = [] |
|
84 |
for output in self.Outputs: |
|
85 |
output.Flush() |
|
86 |
self.Outputs = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
87 |
|
814 | 88 |
# Returns the RedrawRect |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
89 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 90 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
91 |
if movex != 0 or movey != 0: |
|
92 |
for input in self.Inputs: |
|
93 |
if input.IsConnected(): |
|
94 |
rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
|
95 |
for output in self.Outputs: |
|
96 |
if output.IsConnected(): |
|
97 |
rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
|
98 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
99 |
|
814 | 100 |
# Delete this block by calling the appropriate method |
101 |
def Delete(self): |
|
102 |
self.Parent.DeleteBlock(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
103 |
|
814 | 104 |
# Unconnect all inputs and outputs |
105 |
def Clean(self): |
|
106 |
for input in self.Inputs: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
107 |
input.UnConnect(delete=True) |
814 | 108 |
for output in self.Outputs: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
109 |
output.UnConnect(delete=True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
110 |
|
814 | 111 |
# Refresh the size of text for name |
112 |
def RefreshNameSize(self): |
|
113 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
114 |
|
814 | 115 |
# Refresh the size of text for execution order |
116 |
def RefreshExecutionOrderSize(self): |
|
117 |
self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
118 |
|
814 | 119 |
# Returns if the point given is in the bounding box |
120 |
def HitTest(self, pt, connectors=True): |
|
121 |
if self.Name != "": |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2437
diff
changeset
|
122 |
test_text = self.GetTextBoundingBox().Contains(pt.x, pt.y) |
814 | 123 |
else: |
124 |
test_text = False |
|
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2437
diff
changeset
|
125 |
test_block = self.GetBlockBoundingBox(connectors).Contains(pt.x, pt.y) |
814 | 126 |
return test_text or test_block |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
127 |
|
814 | 128 |
# Returns the bounding box of the name outside the block |
129 |
def GetTextBoundingBox(self): |
|
130 |
# Calculate the size of the name outside the block |
|
131 |
text_width, text_height = self.NameSize |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
132 |
return wx.Rect(self.Pos.x + (self.Size[0] - text_width) // 2, |
814 | 133 |
self.Pos.y - (text_height + 2), |
134 |
text_width, |
|
135 |
text_height) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
136 |
|
814 | 137 |
# Returns the bounding box of function block without name outside |
138 |
def GetBlockBoundingBox(self, connectors=True): |
|
139 |
bbx_x, bbx_y = self.Pos.x, self.Pos.y |
|
140 |
bbx_width, bbx_height = self.Size |
|
141 |
if connectors: |
|
142 |
bbx_x -= min(1, len(self.Inputs)) * CONNECTOR_SIZE |
|
143 |
bbx_width += (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE |
|
144 |
if self.ExecutionOrder != 0: |
|
145 |
bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) |
|
146 |
bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) |
|
147 |
bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) |
|
148 |
return 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:
1605
diff
changeset
|
149 |
|
814 | 150 |
# Refresh the block bounding box |
151 |
def RefreshBoundingBox(self): |
|
152 |
self.BoundingBox = self.GetBlockBoundingBox() |
|
153 |
if self.Name != "": |
|
154 |
self.BoundingBox.Union(self.GetTextBoundingBox()) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
155 |
|
814 | 156 |
# Refresh the positions of the block connectors |
157 |
def RefreshConnectors(self): |
|
158 |
scaling = self.Parent.GetScaling() |
|
159 |
# Calculate the size for the connector lines |
|
160 |
lines = max(len(self.Inputs), len(self.Outputs)) |
|
161 |
if lines > 0: |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
162 |
linesize = max((self.Size[1] - BLOCK_LINE_SIZE) // lines, BLOCK_LINE_SIZE) |
814 | 163 |
# Update inputs and outputs positions |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
164 |
position = BLOCK_LINE_SIZE + linesize // 2 |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3537
diff
changeset
|
165 |
for i in range(lines): |
814 | 166 |
if scaling is not None: |
167 |
ypos = round_scaling(self.Pos.y + position, scaling[1]) - self.Pos.y |
|
168 |
else: |
|
169 |
ypos = position |
|
170 |
if i < len(self.Inputs): |
|
171 |
self.Inputs[i].SetPosition(wx.Point(0, ypos)) |
|
172 |
if i < len(self.Outputs): |
|
173 |
self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos)) |
|
174 |
position += linesize |
|
175 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
176 |
|
814 | 177 |
# Refresh the positions of wires connected to inputs and outputs |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
178 |
def RefreshConnected(self, exclude=None): |
814 | 179 |
for input in self.Inputs: |
180 |
input.MoveConnected(exclude) |
|
181 |
for output in self.Outputs: |
|
182 |
output.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
183 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
184 |
# Returns the block 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:
1740
diff
changeset
|
185 |
def GetConnector(self, position, output_name=None, input_name=None): |
1130
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
186 |
if input_name is not None: |
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
187 |
# Test each input connector |
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
188 |
for input in self.Inputs: |
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
189 |
if input_name == input.GetName(): |
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
190 |
return input |
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
191 |
if output_name is not None: |
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
192 |
# Test each output connector |
814 | 193 |
for output in self.Outputs: |
1130
f96e0254f0ce
Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents:
1054
diff
changeset
|
194 |
if output_name == output.GetName(): |
814 | 195 |
return output |
1133
d81d99fd1932
Fixed bug in loading block in Viewer when block interface has changed
Laurent Bessard
parents:
1130
diff
changeset
|
196 |
if input_name is None and output_name is None: |
d81d99fd1932
Fixed bug in loading block in Viewer when block interface has changed
Laurent Bessard
parents:
1130
diff
changeset
|
197 |
return self.FindNearestConnector(position, self.Inputs + self.Outputs) |
d81d99fd1932
Fixed bug in loading block in Viewer when block interface has changed
Laurent Bessard
parents:
1130
diff
changeset
|
198 |
return None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
199 |
|
814 | 200 |
def GetInputTypes(self): |
201 |
return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
202 |
|
814 | 203 |
def SetOutputValues(self, values): |
204 |
for output in self.Outputs: |
|
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1852
diff
changeset
|
205 |
output.SetValue(values.get(output.getName(), None)) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
206 |
|
814 | 207 |
def GetConnectionResultType(self, connector, connectortype): |
208 |
if not TestConnectorName(connector.GetName(), self.Type): |
|
209 |
return connectortype |
|
210 |
resulttype = connectortype |
|
211 |
for input in self.Inputs: |
|
212 |
if input != connector and input.GetType(True) == "ANY" and TestConnectorName(input.GetName(), self.Type): |
|
213 |
inputtype = input.GetConnectedType() |
|
214 |
if resulttype is None or inputtype is not None and self.IsOfType(inputtype, resulttype): |
|
215 |
resulttype = inputtype |
|
216 |
for output in self.Outputs: |
|
217 |
if output != connector and output.GetType(True) == "ANY" and TestConnectorName(output.GetName(), self.Type): |
|
218 |
outputtype = output.GetConnectedType() |
|
219 |
if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype): |
|
220 |
resulttype = outputtype |
|
221 |
return resulttype |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
222 |
|
814 | 223 |
# Returns all the block connectors |
224 |
def GetConnectors(self): |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
225 |
return {"inputs": self.Inputs, "outputs": self.Outputs} |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
226 |
|
814 | 227 |
# Test if point given is on one of the block connectors |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
228 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 229 |
# Test each input connector |
230 |
for input in self.Inputs: |
|
231 |
if input.TestPoint(pt, direction, exclude): |
|
232 |
return input |
|
233 |
# Test each output connector |
|
234 |
for output in self.Outputs: |
|
235 |
if output.TestPoint(pt, direction, exclude): |
|
236 |
return output |
|
237 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
238 |
|
814 | 239 |
# Changes the block type |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
240 |
def SetType(self, type, extension, inputs=None, connectors=None, executionControl=False): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
241 |
if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: |
814 | 242 |
if type != self.Type: |
243 |
self.Type = type |
|
244 |
self.TypeSize = self.Parent.GetTextExtent(self.Type) |
|
245 |
self.Extension = extension |
|
246 |
self.ExecutionControl = executionControl |
|
247 |
# Find the block definition from type given and create the corresponding |
|
248 |
# inputs and outputs |
|
249 |
blocktype = self.Parent.GetBlockType(type, inputs) |
|
250 |
if blocktype: |
|
251 |
self.Colour = wx.BLACK |
|
252 |
inputs = [input for input in blocktype["inputs"]] |
|
253 |
outputs = [output for output in blocktype["outputs"]] |
|
254 |
if blocktype["extensible"]: |
|
255 |
start = int(inputs[-1][0].replace("IN", "")) |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3537
diff
changeset
|
256 |
for dummy in range(self.Extension - len(blocktype["inputs"])): |
814 | 257 |
start += 1 |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
258 |
inputs.append(("IN%d" % start, inputs[-1][1], inputs[-1][2])) |
814 | 259 |
comment = blocktype["comment"] |
260 |
self.Description = _(comment) + blocktype.get("usage", "") |
|
261 |
else: |
|
262 |
self.Colour = wx.RED |
|
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
263 |
connectors = {} if connectors is None else connectors |
814 | 264 |
inputs = connectors.get("inputs", []) |
265 |
outputs = connectors.get("outputs", []) |
|
266 |
self.Description = None |
|
267 |
if self.ExecutionControl: |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
268 |
inputs.insert(0, ("EN", "BOOL", "none")) |
1761
8c98bad90b8d
clean-up: fix PEP8 E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1753
diff
changeset
|
269 |
outputs.insert(0, ("ENO", "BOOL", "none")) |
814 | 270 |
self.Pen = MiterPen(self.Colour) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
271 |
|
814 | 272 |
# Extract the inputs properties and create or modify the corresponding connector |
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
273 |
input_connectors = [] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
274 |
for input_name, input_type, input_modifier in inputs: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
275 |
connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone=True) |
814 | 276 |
if input_modifier == "negated": |
277 |
connector.SetNegated(True) |
|
278 |
elif input_modifier != "none": |
|
279 |
connector.SetEdge(input_modifier) |
|
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
280 |
for input in self.Inputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
281 |
if input.GetName() == input_name: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
282 |
wires = input.GetWires()[:] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
283 |
input.UnConnect() |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
284 |
for wire in wires: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
285 |
connector.Connect(wire) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
286 |
break |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
287 |
input_connectors.append(connector) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
288 |
for input in self.Inputs: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
289 |
input.UnConnect(delete=True) |
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
290 |
self.Inputs = input_connectors |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
291 |
|
814 | 292 |
# Extract the outputs properties and create or modify the corresponding connector |
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
293 |
output_connectors = [] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
294 |
for output_name, output_type, output_modifier in outputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
295 |
connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST) |
814 | 296 |
if output_modifier == "negated": |
297 |
connector.SetNegated(True) |
|
298 |
elif output_modifier != "none": |
|
299 |
connector.SetEdge(output_modifier) |
|
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
300 |
for output in self.Outputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
301 |
if output.GetName() == output_name: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
302 |
wires = output.GetWires()[:] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
303 |
output.UnConnect() |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
304 |
for wire in wires: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
305 |
connector.Connect(wire) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
306 |
break |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
307 |
output_connectors.append(connector) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
308 |
for output in self.Outputs: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
309 |
output.UnConnect(delete=True) |
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
310 |
self.Outputs = output_connectors |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
311 |
|
814 | 312 |
self.RefreshMinSize() |
313 |
self.RefreshConnectors() |
|
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
314 |
for output in self.Outputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
315 |
output.RefreshWires() |
814 | 316 |
self.RefreshBoundingBox() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
317 |
|
814 | 318 |
# Returns the block type |
319 |
def GetType(self): |
|
320 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
321 |
|
814 | 322 |
# Changes the block name |
323 |
def SetName(self, name): |
|
324 |
self.Name = name |
|
325 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
326 |
|
814 | 327 |
# Returs the block name |
328 |
def GetName(self): |
|
329 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
330 |
|
814 | 331 |
# Changes the extension name |
332 |
def SetExtension(self, extension): |
|
333 |
self.Extension = extension |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
334 |
|
814 | 335 |
# Returs the extension name |
336 |
def GetExtension(self): |
|
337 |
return self.Extension |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
338 |
|
814 | 339 |
# Changes the execution order |
340 |
def SetExecutionOrder(self, executionOrder): |
|
341 |
self.ExecutionOrder = executionOrder |
|
342 |
self.RefreshExecutionOrderSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
343 |
|
814 | 344 |
# Returs the execution order |
345 |
def GetExecutionOrder(self): |
|
346 |
return self.ExecutionOrder |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
347 |
|
814 | 348 |
# Returs the execution order |
349 |
def GetExecutionControl(self): |
|
350 |
return self.ExecutionControl |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
351 |
|
814 | 352 |
# Refresh the block minimum size |
353 |
def RefreshMinSize(self): |
|
354 |
# Calculate the inputs maximum width |
|
355 |
max_input = 0 |
|
356 |
for input in self.Inputs: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
357 |
w, _h = input.GetNameSize() |
814 | 358 |
max_input = max(max_input, w) |
359 |
# Calculate the outputs maximum width |
|
360 |
max_output = 0 |
|
361 |
for output in self.Outputs: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
362 |
w, _h = output.GetNameSize() |
814 | 363 |
max_output = max(max_output, w) |
364 |
width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
|
365 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
|
366 |
self.MinSize = width, height |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
367 |
|
814 | 368 |
# Returns the block minimum size |
369 |
def GetMinSize(self): |
|
370 |
return self.MinSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
371 |
|
814 | 372 |
# Changes the negated property of the connector handled |
373 |
def SetConnectorNegated(self, negated): |
|
374 |
handle_type, handle = self.Handle |
|
375 |
if handle_type == HANDLE_CONNECTOR: |
|
376 |
handle.SetNegated(negated) |
|
377 |
self.RefreshModel(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
378 |
|
814 | 379 |
# Changes the edge property of the connector handled |
380 |
def SetConnectorEdge(self, edge): |
|
381 |
handle_type, handle = self.Handle |
|
382 |
if handle_type == HANDLE_CONNECTOR: |
|
383 |
handle.SetEdge(edge) |
|
384 |
self.RefreshModel(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
385 |
|
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
386 |
# # Method called when a Motion event have been generated |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
387 |
# def OnMotion(self, event, dc, scaling): |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
388 |
# if not event.Dragging(): |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
389 |
# pos = event.GetLogicalPosition(dc) |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
390 |
# for input in self.Inputs: |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
391 |
# rect = input.GetRedrawRect() |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2437
diff
changeset
|
392 |
# if rect.Contains(pos.x, pos.y): |
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
393 |
# print "Find input" |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
394 |
# tip = wx.TipWindow(self.Parent, "Test") |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
395 |
# tip.SetBoundingRect(rect) |
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
396 |
# return Graphic_Element.OnMotion(self, event, dc, scaling) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
397 |
|
814 | 398 |
# Method called when a LeftDClick event have been generated |
399 |
def OnLeftDClick(self, event, dc, scaling): |
|
400 |
# Edit the block properties |
|
401 |
self.Parent.EditBlockContent(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
402 |
|
814 | 403 |
# Method called when a RightUp event have been generated |
404 |
def OnRightUp(self, event, dc, scaling): |
|
405 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
406 |
# Popup the menu with special items for a block and a connector if one is handled |
|
407 |
connector = self.TestConnector(pos, exclude=False) |
|
408 |
if connector: |
|
409 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
410 |
self.Parent.PopupBlockMenu(connector) |
|
411 |
else: |
|
412 |
self.Parent.PopupBlockMenu() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
413 |
|
814 | 414 |
# Refreshes the block model |
415 |
def RefreshModel(self, move=True): |
|
416 |
self.Parent.RefreshBlockModel(self) |
|
417 |
# If block has moved, refresh the model of wires connected to outputs |
|
418 |
if move: |
|
419 |
for output in self.Outputs: |
|
420 |
output.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
421 |
|
814 | 422 |
def GetToolTipValue(self): |
423 |
return self.Description |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
424 |
|
814 | 425 |
# Adds an highlight to the block |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
426 |
def AddHighlight(self, infos, start, end, highlight_type): |
814 | 427 |
if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: |
428 |
highlights = self.Highlights.setdefault(infos[0], []) |
|
429 |
AddHighlight(highlights, (start, end, highlight_type)) |
|
430 |
elif infos[0] == "input" and infos[1] < len(self.Inputs): |
|
431 |
self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
|
432 |
elif infos[0] == "output" and infos[1] < len(self.Outputs): |
|
433 |
self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
434 |
|
814 | 435 |
# Removes an highlight from the block |
436 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
437 |
if infos[0] in ["type", "name"]: |
|
438 |
highlights = self.Highlights.get(infos[0], []) |
|
439 |
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
|
440 |
self.Highlights.pop(infos[0]) |
|
441 |
elif infos[0] == "input" and infos[1] < len(self.Inputs): |
|
442 |
self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
|
443 |
elif infos[0] == "output" and infos[1] < len(self.Outputs): |
|
444 |
self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
445 |
|
814 | 446 |
# Removes all the highlights of one particular type from the block |
447 |
def ClearHighlight(self, highlight_type=None): |
|
448 |
if highlight_type is None: |
|
449 |
self.Highlights = {} |
|
450 |
else: |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3537
diff
changeset
|
451 |
highlight_items = list(self.Highlights.items()) |
814 | 452 |
for name, highlights in highlight_items: |
453 |
highlights = ClearHighlights(highlights, highlight_type) |
|
454 |
if len(highlights) == 0: |
|
455 |
self.Highlights.pop(name) |
|
456 |
for input in self.Inputs: |
|
457 |
input.ClearHighlights(highlight_type) |
|
458 |
for output in self.Outputs: |
|
459 |
output.ClearHighlights(highlight_type) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
460 |
|
814 | 461 |
# Draws block |
462 |
def Draw(self, dc): |
|
463 |
Graphic_Element.Draw(self, dc) |
|
464 |
dc.SetPen(self.Pen) |
|
465 |
dc.SetBrush(wx.WHITE_BRUSH) |
|
466 |
dc.SetTextForeground(self.Colour) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
467 |
|
814 | 468 |
if getattr(dc, "printing", False): |
469 |
name_size = dc.GetTextExtent(self.Name) |
|
470 |
type_size = dc.GetTextExtent(self.Type) |
|
471 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
472 |
else: |
|
473 |
name_size = self.NameSize |
|
474 |
type_size = self.TypeSize |
|
475 |
executionorder_size = self.ExecutionOrderSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
476 |
|
814 | 477 |
# Draw a rectangle with the block size |
478 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
479 |
# Draw block name and block type |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
480 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, |
814 | 481 |
self.Pos.y - (name_size[1] + 2)) |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
482 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) // 2, |
814 | 483 |
self.Pos.y + 5) |
484 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
|
485 |
dc.DrawText(self.Type, type_pos[0], type_pos[1]) |
|
486 |
# Draw inputs and outputs connectors |
|
487 |
for input in self.Inputs: |
|
488 |
input.Draw(dc) |
|
489 |
for output in self.Outputs: |
|
490 |
output.Draw(dc) |
|
491 |
if self.ExecutionOrder != 0: |
|
492 |
# Draw block execution order |
|
493 |
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1761
diff
changeset
|
494 |
self.Pos.y + self.Size[1] + 2) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
495 |
|
814 | 496 |
if not getattr(dc, "printing", False): |
497 |
DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1]) |
|
498 |
DrawHighlightedText(dc, self.Type, self.Highlights.get("type", []), type_pos[0], type_pos[1]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
499 |
|
814 | 500 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
501 |
# ------------------------------------------------------------------------------- |
814 | 502 |
# Function Block Diagram Variable |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
503 |
# ------------------------------------------------------------------------------- |
814 | 504 |
|
505 |
||
506 |
class FBD_Variable(Graphic_Element): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
507 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
508 |
Class that implements the graphic representation of a variable |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
509 |
""" |
814 | 510 |
|
511 |
# Create a new variable |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
512 |
def __init__(self, parent, type, name, value_type, id=None, executionOrder=0): |
814 | 513 |
Graphic_Element.__init__(self, parent) |
514 |
self.Type = None |
|
515 |
self.ValueType = None |
|
516 |
self.Id = id |
|
517 |
self.SetName(name) |
|
518 |
self.SetExecutionOrder(executionOrder) |
|
519 |
self.Input = None |
|
520 |
self.Output = None |
|
521 |
self.SetType(type, value_type) |
|
522 |
self.Highlights = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
523 |
|
814 | 524 |
# Make a clone of this FBD_Variable |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
525 |
def Clone(self, parent, id=None, pos=None): |
814 | 526 |
variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id) |
527 |
variable.SetSize(self.Size[0], self.Size[1]) |
|
528 |
if pos is not None: |
|
529 |
variable.SetPosition(pos.x, pos.y) |
|
530 |
else: |
|
531 |
variable.SetPosition(self.Pos.x, self.Pos.y) |
|
532 |
if self.Input: |
|
533 |
variable.Input = self.Input.Clone(variable) |
|
534 |
if self.Output: |
|
535 |
variable.Output = self.Output.Clone(variable) |
|
536 |
return variable |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
537 |
|
814 | 538 |
def GetConnectorTranslation(self, element): |
539 |
connectors = {} |
|
540 |
if self.Input is not None: |
|
541 |
connectors[self.Input] = element.Input |
|
542 |
if self.Output is not None: |
|
543 |
connectors[self.Output] = element.Output |
|
544 |
return connectors |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
545 |
|
814 | 546 |
def Flush(self): |
547 |
if self.Input is not None: |
|
548 |
self.Input.Flush() |
|
549 |
self.Input = None |
|
550 |
if self.Output is not None: |
|
551 |
self.Output.Flush() |
|
552 |
self.Output = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
553 |
|
814 | 554 |
# Returns the RedrawRect |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
555 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 556 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
557 |
if movex != 0 or movey != 0: |
|
558 |
if self.Input and self.Input.IsConnected(): |
|
559 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
560 |
if self.Output and self.Output.IsConnected(): |
|
561 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
562 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
563 |
|
814 | 564 |
# Unconnect connector |
565 |
def Clean(self): |
|
566 |
if self.Input: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
567 |
self.Input.UnConnect(delete=True) |
814 | 568 |
if self.Output: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
569 |
self.Output.UnConnect(delete=True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
570 |
|
814 | 571 |
# Delete this variable by calling the appropriate method |
572 |
def Delete(self): |
|
573 |
self.Parent.DeleteVariable(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
574 |
|
814 | 575 |
# Refresh the size of text for name |
576 |
def RefreshNameSize(self): |
|
577 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
578 |
|
814 | 579 |
# Refresh the size of text for execution order |
580 |
def RefreshExecutionOrderSize(self): |
|
581 |
self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
582 |
|
814 | 583 |
# Refresh the variable bounding box |
584 |
def RefreshBoundingBox(self): |
|
585 |
if self.Type in (OUTPUT, INOUT): |
|
586 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
587 |
else: |
|
588 |
bbx_x = self.Pos.x |
|
589 |
if self.Type == INOUT: |
|
590 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE |
|
591 |
else: |
|
592 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
593 |
bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) // 2) |
814 | 594 |
bbx_width = max(bbx_width, self.NameSize[0]) |
595 |
bbx_height = self.Size[1] |
|
596 |
if self.ExecutionOrder != 0: |
|
597 |
bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) |
|
598 |
bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) |
|
599 |
bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) |
|
600 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
601 |
|
814 | 602 |
# Refresh the position of the variable connector |
603 |
def RefreshConnectors(self): |
|
604 |
scaling = self.Parent.GetScaling() |
|
605 |
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
|
606 |
position = round_scaling(self.Pos.y + self.Size[1] // 2, scaling[1]) - self.Pos.y |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
607 |
else: |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
608 |
position = self.Size[1] // 2 |
814 | 609 |
if self.Input: |
610 |
self.Input.SetPosition(wx.Point(0, position)) |
|
611 |
if self.Output: |
|
612 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
613 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
614 |
|
814 | 615 |
# Refresh the position of wires connected to connector |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
616 |
def RefreshConnected(self, exclude=None): |
814 | 617 |
if self.Input: |
618 |
self.Input.MoveConnected(exclude) |
|
619 |
if self.Output: |
|
620 |
self.Output.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
621 |
|
814 | 622 |
# Test if point given is on the variable connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
623 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 624 |
if self.Input and self.Input.TestPoint(pt, direction, exclude): |
625 |
return self.Input |
|
626 |
if self.Output and self.Output.TestPoint(pt, direction, exclude): |
|
627 |
return self.Output |
|
628 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
629 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
630 |
# Returns the block 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:
1740
diff
changeset
|
631 |
def GetConnector(self, position, name=None): |
814 | 632 |
# if a name is given |
633 |
if name is not None: |
|
634 |
# Test input and output connector if they exists |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
635 |
# if self.Input and name == self.Input.GetName(): |
814 | 636 |
# return self.Input |
637 |
if self.Output and name == self.Output.GetName(): |
|
638 |
return self.Output |
|
639 |
connectors = [] |
|
640 |
# Test input connector if it exists |
|
641 |
if self.Input: |
|
642 |
connectors.append(self.Input) |
|
643 |
# Test output connector if it exists |
|
644 |
if self.Output: |
|
645 |
connectors.append(self.Output) |
|
646 |
return self.FindNearestConnector(position, connectors) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
647 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
648 |
# Returns all the block connectors |
814 | 649 |
def GetConnectors(self): |
650 |
connectors = {"inputs": [], "outputs": []} |
|
651 |
if self.Input: |
|
652 |
connectors["inputs"].append(self.Input) |
|
653 |
if self.Output: |
|
654 |
connectors["outputs"].append(self.Output) |
|
655 |
return connectors |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
656 |
|
814 | 657 |
# Changes the negated property of the variable connector if handled |
658 |
def SetConnectorNegated(self, negated): |
|
659 |
handle_type, handle = self.Handle |
|
660 |
if handle_type == HANDLE_CONNECTOR: |
|
661 |
handle.SetNegated(negated) |
|
662 |
self.RefreshModel(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
663 |
|
814 | 664 |
# Changes the variable type |
665 |
def SetType(self, type, value_type): |
|
666 |
if type != self.Type: |
|
667 |
self.Type = type |
|
668 |
# Create an input or output connector according to variable type |
|
669 |
if self.Type != INPUT: |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
670 |
if self.Input is None: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
671 |
self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone=True) |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
672 |
elif self.Input: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
673 |
self.Input.UnConnect(delete=True) |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
674 |
self.Input = None |
814 | 675 |
if self.Type != OUTPUT: |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
676 |
if self.Output is None: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
677 |
self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST) |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
678 |
elif self.Output: |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
679 |
self.Output.UnConnect(delete=True) |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
680 |
self.Output = None |
814 | 681 |
self.RefreshConnectors() |
873
8737f1554494
Fix bug Variable and Continuation BoundingBox not refreshed when using Type modification shortcuts
Laurent Bessard
parents:
857
diff
changeset
|
682 |
self.RefreshBoundingBox() |
814 | 683 |
elif value_type != self.ValueType: |
684 |
if self.Input: |
|
685 |
self.Input.SetType(value_type) |
|
686 |
if self.Output: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
687 |
self.Output.SetType(value_type) |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
688 |
|
814 | 689 |
# Returns the variable type |
690 |
def GetType(self): |
|
691 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
692 |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
693 |
# Returns the variable value type |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
694 |
def GetValueType(self): |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
695 |
return self.ValueType |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
696 |
|
814 | 697 |
# Changes the variable name |
698 |
def SetName(self, name): |
|
699 |
self.Name = name |
|
700 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
701 |
|
814 | 702 |
# Returns the variable name |
703 |
def GetName(self): |
|
704 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
705 |
|
814 | 706 |
# Changes the execution order |
707 |
def SetExecutionOrder(self, executionOrder): |
|
708 |
self.ExecutionOrder = executionOrder |
|
709 |
self.RefreshExecutionOrderSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
710 |
|
814 | 711 |
# Returs the execution order |
712 |
def GetExecutionOrder(self): |
|
713 |
return self.ExecutionOrder |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
714 |
|
814 | 715 |
# Returns the variable minimum size |
716 |
def GetMinSize(self): |
|
717 |
return self.NameSize[0] + 10, self.NameSize[1] + 10 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
718 |
|
852
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
719 |
# Set size of the variable to the minimum size |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
720 |
def SetBestSize(self, scaling): |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
721 |
if self.Type == INPUT: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
722 |
return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
723 |
elif self.Type == OUTPUT: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
724 |
return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
725 |
else: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
726 |
return Graphic_Element.SetBestSize(self, scaling) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
727 |
|
814 | 728 |
# Method called when a LeftDClick event have been generated |
729 |
def OnLeftDClick(self, event, dc, scaling): |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
730 |
if event.ControlDown(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
731 |
# Change variable type |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
732 |
types = [INPUT, OUTPUT, INOUT] |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1761
diff
changeset
|
733 |
self.Parent.ChangeVariableType( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1761
diff
changeset
|
734 |
self, types[(types.index(self.Type) + 1) % len(types)]) |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
735 |
else: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
736 |
# Edit the variable properties |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
737 |
self.Parent.EditVariableContent(self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
738 |
|
814 | 739 |
# Method called when a RightUp event have been generated |
740 |
def OnRightUp(self, event, dc, scaling): |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
741 |
self.Parent.PopupVariableMenu() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
742 |
|
814 | 743 |
# Refreshes the variable model |
744 |
def RefreshModel(self, move=True): |
|
745 |
self.Parent.RefreshVariableModel(self) |
|
746 |
# If variable has moved and variable is not of type OUTPUT, refresh the model |
|
747 |
# of wires connected to output connector |
|
748 |
if move and self.Type != OUTPUT: |
|
749 |
if self.Output: |
|
750 |
self.Output.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
751 |
|
814 | 752 |
# Adds an highlight to the variable |
753 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
754 |
if infos[0] == "expression" and start[0] == 0 and end[0] == 0: |
|
755 |
AddHighlight(self.Highlights, (start, end, highlight_type)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
756 |
|
814 | 757 |
# Removes an highlight from the variable |
758 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
759 |
if infos[0] == "expression": |
|
760 |
RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
761 |
|
814 | 762 |
# Removes all the highlights of one particular type from the variable |
763 |
def ClearHighlight(self, highlight_type=None): |
|
764 |
ClearHighlights(self.Highlights, highlight_type) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
765 |
|
814 | 766 |
# Draws variable |
767 |
def Draw(self, dc): |
|
768 |
Graphic_Element.Draw(self, dc) |
|
769 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
770 |
dc.SetBrush(wx.WHITE_BRUSH) |
|
3537
cb7db021280c
wxPython4 sequels: fix exception in connection dialog, force black text in FBD.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
771 |
dc.SetTextForeground(wx.BLACK) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
772 |
|
814 | 773 |
if getattr(dc, "printing", False): |
774 |
name_size = dc.GetTextExtent(self.Name) |
|
775 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
776 |
else: |
|
777 |
name_size = self.NameSize |
|
778 |
executionorder_size = self.ExecutionOrderSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
779 |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
780 |
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
781 |
self.Pos.y + (self.Size[1] - name_size[1]) // 2) |
814 | 782 |
# Draw a rectangle with the variable size |
783 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
784 |
# Draw variable name |
|
785 |
dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
|
786 |
# Draw connectors |
|
787 |
if self.Input: |
|
788 |
self.Input.Draw(dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
789 |
if self.Output: |
814 | 790 |
self.Output.Draw(dc) |
791 |
if self.ExecutionOrder != 0: |
|
792 |
# Draw variable execution order |
|
793 |
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1761
diff
changeset
|
794 |
self.Pos.y + self.Size[1] + 2) |
814 | 795 |
if not getattr(dc, "printing", False): |
796 |
DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
797 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
798 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
799 |
# ------------------------------------------------------------------------------- |
814 | 800 |
# Function Block Diagram Connector |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
801 |
# ------------------------------------------------------------------------------- |
814 | 802 |
|
803 |
||
804 |
class FBD_Connector(Graphic_Element): |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
805 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
806 |
Class that implements the graphic representation of a connection |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
807 |
""" |
814 | 808 |
|
809 |
# Create a new connection |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
810 |
def __init__(self, parent, type, name, id=None): |
814 | 811 |
Graphic_Element.__init__(self, parent) |
812 |
self.Type = type |
|
813 |
self.Id = id |
|
814 |
self.SetName(name) |
|
815 |
self.Pos = wx.Point(0, 0) |
|
816 |
self.Size = wx.Size(0, 0) |
|
817 |
self.Highlights = [] |
|
818 |
# Create an input or output connector according to connection type |
|
819 |
if self.Type == CONNECTOR: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
820 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True) |
814 | 821 |
else: |
822 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
|
823 |
self.RefreshConnectors() |
|
824 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
825 |
|
814 | 826 |
def Flush(self): |
827 |
if self.Connector: |
|
828 |
self.Connector.Flush() |
|
829 |
self.Connector = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
830 |
|
814 | 831 |
# Returns the RedrawRect |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
832 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 833 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
834 |
if movex != 0 or movey != 0: |
|
835 |
if self.Connector and self.Connector.IsConnected(): |
|
836 |
rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
|
837 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
838 |
|
814 | 839 |
# Make a clone of this FBD_Connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
840 |
def Clone(self, parent, id=None, pos=None): |
814 | 841 |
connection = FBD_Connector(parent, self.Type, self.Name, id) |
842 |
connection.SetSize(self.Size[0], self.Size[1]) |
|
843 |
if pos is not None: |
|
844 |
connection.SetPosition(pos.x, pos.y) |
|
845 |
else: |
|
846 |
connection.SetPosition(self.Pos.x, self.Pos.y) |
|
847 |
connection.Connector = self.Connector.Clone(connection) |
|
848 |
return connection |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
849 |
|
814 | 850 |
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
|
851 |
return {self.Connector: element.Connector} |
814 | 852 |
|
853 |
# Unconnect connector |
|
854 |
def Clean(self): |
|
855 |
if self.Connector: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
856 |
self.Connector.UnConnect(delete=True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
857 |
|
814 | 858 |
# Delete this connection by calling the appropriate method |
859 |
def Delete(self): |
|
860 |
self.Parent.DeleteConnection(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
861 |
|
814 | 862 |
# Refresh the size of text for name |
863 |
def RefreshNameSize(self): |
|
864 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
865 |
|
814 | 866 |
# Refresh the connection bounding box |
867 |
def RefreshBoundingBox(self): |
|
868 |
if self.Type == CONNECTOR: |
|
869 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
870 |
else: |
|
871 |
bbx_x = self.Pos.x |
|
872 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
873 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
874 |
|
814 | 875 |
# Refresh the position of the connection connector |
876 |
def RefreshConnectors(self): |
|
877 |
scaling = self.Parent.GetScaling() |
|
878 |
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
|
879 |
position = round_scaling(self.Pos.y + self.Size[1] // 2, scaling[1]) - self.Pos.y |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
880 |
else: |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
881 |
position = self.Size[1] // 2 |
814 | 882 |
if self.Type == CONNECTOR: |
883 |
self.Connector.SetPosition(wx.Point(0, position)) |
|
884 |
else: |
|
885 |
self.Connector.SetPosition(wx.Point(self.Size[0], position)) |
|
886 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
887 |
|
814 | 888 |
# Refresh the position of wires connected to connector |
1852
70c1cc354a8f
fix pylint warning '(dangerous-default-value) Dangerous default value {} as argument'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
889 |
def RefreshConnected(self, exclude=None): |
814 | 890 |
if self.Connector: |
891 |
self.Connector.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
892 |
|
814 | 893 |
# Test if point given is on the connection connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
894 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 895 |
if self.Connector and self.Connector.TestPoint(pt, direction, exclude): |
896 |
return self.Connector |
|
897 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
898 |
|
814 | 899 |
# Returns the connection connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
900 |
def GetConnector(self, position=None, name=None): |
814 | 901 |
return self.Connector |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
902 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
903 |
# Returns all the block connectors |
814 | 904 |
def GetConnectors(self): |
905 |
connectors = {"inputs": [], "outputs": []} |
|
906 |
if self.Type == CONNECTOR: |
|
907 |
connectors["inputs"].append(self.Connector) |
|
908 |
else: |
|
909 |
connectors["outputs"].append(self.Connector) |
|
910 |
return connectors |
|
1605
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
911 |
|
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
912 |
def SpreadCurrent(self): |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
913 |
if self.Type == CONNECTOR: |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
914 |
continuations = self.Parent.GetContinuationByName(self.Name) |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
915 |
if continuations is not None: |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
916 |
value = self.Connector.ReceivingCurrent() |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
917 |
for cont in continuations: |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
918 |
cont.Connector.SpreadCurrent(value) |
0b6b60241230
fix issue that in Debug mode LD instance doesn't show correctly its state after
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
919 |
|
814 | 920 |
# Changes the variable type |
921 |
def SetType(self, type): |
|
922 |
if type != self.Type: |
|
923 |
self.Type = type |
|
924 |
self.Clean() |
|
925 |
# Create an input or output connector according to connection type |
|
926 |
if self.Type == CONNECTOR: |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
927 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True) |
814 | 928 |
else: |
929 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
|
930 |
self.RefreshConnectors() |
|
873
8737f1554494
Fix bug Variable and Continuation BoundingBox not refreshed when using Type modification shortcuts
Laurent Bessard
parents:
857
diff
changeset
|
931 |
self.RefreshBoundingBox() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
932 |
|
814 | 933 |
# Returns the connection type |
934 |
def GetType(self): |
|
935 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
936 |
|
814 | 937 |
def GetConnectionResultType(self, connector, connectortype): |
938 |
if self.Type == CONTINUATION: |
|
939 |
connector = self.Parent.GetConnectorByName(self.Name) |
|
940 |
if connector is not None: |
|
941 |
return connector.Connector.GetConnectedType() |
|
942 |
return connectortype |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
943 |
|
814 | 944 |
# Changes the connection name |
945 |
def SetName(self, name): |
|
946 |
self.Name = name |
|
947 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
948 |
|
814 | 949 |
# Returns the connection name |
950 |
def GetName(self): |
|
951 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
952 |
|
852
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
953 |
# Set size of the variable to the minimum size |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
954 |
def SetBestSize(self, scaling): |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
955 |
if self.Type == CONTINUATION: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
956 |
return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
957 |
else: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
958 |
return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
959 |
|
814 | 960 |
# Returns the connection minimum size |
961 |
def GetMinSize(self): |
|
962 |
text_width, text_height = self.NameSize |
|
963 |
if text_height % 2 == 1: |
|
964 |
text_height += 1 |
|
965 |
return text_width + text_height + 20, text_height + 10 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
966 |
|
814 | 967 |
# Method called when a LeftDClick event have been generated |
968 |
def OnLeftDClick(self, event, dc, scaling): |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
969 |
if event.ControlDown(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
970 |
# Change connection type |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
971 |
if self.Type == CONNECTOR: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
972 |
self.Parent.ChangeConnectionType(self, CONTINUATION) |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
973 |
else: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
974 |
self.Parent.ChangeConnectionType(self, CONNECTOR) |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
975 |
else: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
976 |
# Edit the connection properties |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
977 |
self.Parent.EditConnectionContent(self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
978 |
|
814 | 979 |
# Method called when a RightUp event have been generated |
980 |
def OnRightUp(self, event, dc, scaling): |
|
981 |
# Popup the default menu |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
982 |
self.Parent.PopupConnectionMenu() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
983 |
|
814 | 984 |
# Refreshes the connection model |
985 |
def RefreshModel(self, move=True): |
|
986 |
self.Parent.RefreshConnectionModel(self) |
|
987 |
# If connection has moved and connection is of type CONTINUATION, refresh |
|
988 |
# the model of wires connected to connector |
|
989 |
if move and self.Type == CONTINUATION: |
|
990 |
if self.Connector: |
|
991 |
self.Connector.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
992 |
|
814 | 993 |
# Adds an highlight to the connection |
994 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
995 |
if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
|
996 |
AddHighlight(self.Highlights, (start, end, highlight_type)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
997 |
|
814 | 998 |
# Removes an highlight from the connection |
999 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
1000 |
if infos[0] == "name": |
|
1001 |
RemoveHighlight(self.Highlights, (start, end, highlight_type)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1002 |
|
814 | 1003 |
# Removes all the highlights of one particular type from the connection |
1004 |
def ClearHighlight(self, highlight_type=None): |
|
1005 |
ClearHighlights(self.Highlights, highlight_type) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1006 |
|
814 | 1007 |
# Draws connection |
1008 |
def Draw(self, dc): |
|
1009 |
Graphic_Element.Draw(self, dc) |
|
1010 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
1011 |
dc.SetBrush(wx.WHITE_BRUSH) |
|
3537
cb7db021280c
wxPython4 sequels: fix exception in connection dialog, force black text in FBD.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
1012 |
dc.SetTextForeground(wx.BLACK) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1013 |
|
814 | 1014 |
if getattr(dc, "printing", False): |
1015 |
name_size = dc.GetTextExtent(self.Name) |
|
1016 |
else: |
|
1017 |
name_size = self.NameSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1018 |
|
814 | 1019 |
# Draw a rectangle with the connection size with arrows inside |
1020 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1021 |
arrowsize = min(self.Size[1] // 2, (self.Size[0] - name_size[0] - 10) // 2) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1022 |
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1023 |
self.Pos.y + self.Size[1] // 2) |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1024 |
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] // 2, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1761
diff
changeset
|
1025 |
self.Pos.x, self.Pos.y + self.Size[1]) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1026 |
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1027 |
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] // 2) |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1028 |
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] // 2, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1761
diff
changeset
|
1029 |
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) |
814 | 1030 |
# Draw connection name |
2437
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1031 |
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) // 2, |
105c20fdeb19
python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2432
diff
changeset
|
1032 |
self.Pos.y + (self.Size[1] - name_size[1]) // 2) |
814 | 1033 |
dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
1034 |
# Draw connector |
|
1035 |
if self.Connector: |
|
1036 |
self.Connector.Draw(dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1037 |
|
814 | 1038 |
if not getattr(dc, "printing", False): |
1039 |
DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |