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