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