author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 12 Sep 2017 18:32:13 +0300 | |
changeset 1801 | 58ff55053518 |
parent 1782 | 5b6ad7a7fd9d |
child 1847 | 6198190bc121 |
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 |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
46 |
def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors={}, 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 |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
177 |
def RefreshConnected(self, exclude=[]): |
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 |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
239 |
def SetType(self, type, extension, inputs=None, connectors={}, 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", "")) |
|
255 |
for i in xrange(self.Extension - len(blocktype["inputs"])): |
|
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 |
|
262 |
inputs = connectors.get("inputs", []) |
|
263 |
outputs = connectors.get("outputs", []) |
|
264 |
self.Description = None |
|
265 |
if self.ExecutionControl: |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
266 |
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
|
267 |
outputs.insert(0, ("ENO", "BOOL", "none")) |
814 | 268 |
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
|
269 |
|
814 | 270 |
# 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
|
271 |
input_connectors = [] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
272 |
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
|
273 |
connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone=True) |
814 | 274 |
if input_modifier == "negated": |
275 |
connector.SetNegated(True) |
|
276 |
elif input_modifier != "none": |
|
277 |
connector.SetEdge(input_modifier) |
|
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
278 |
for input in self.Inputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
279 |
if input.GetName() == input_name: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
280 |
wires = input.GetWires()[:] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
281 |
input.UnConnect() |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
282 |
for wire in wires: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
283 |
connector.Connect(wire) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
284 |
break |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
285 |
input_connectors.append(connector) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
286 |
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
|
287 |
input.UnConnect(delete=True) |
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
288 |
self.Inputs = input_connectors |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
289 |
|
814 | 290 |
# 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
|
291 |
output_connectors = [] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
292 |
for output_name, output_type, output_modifier in outputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
293 |
connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST) |
814 | 294 |
if output_modifier == "negated": |
295 |
connector.SetNegated(True) |
|
296 |
elif output_modifier != "none": |
|
297 |
connector.SetEdge(output_modifier) |
|
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
298 |
for output in self.Outputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
299 |
if output.GetName() == output_name: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
300 |
wires = output.GetWires()[:] |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
301 |
output.UnConnect() |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
302 |
for wire in wires: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
303 |
connector.Connect(wire) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
304 |
break |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
305 |
output_connectors.append(connector) |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
306 |
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
|
307 |
output.UnConnect(delete=True) |
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
308 |
self.Outputs = output_connectors |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
309 |
|
814 | 310 |
self.RefreshMinSize() |
311 |
self.RefreshConnectors() |
|
1054
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
312 |
for output in self.Outputs: |
ef514eaacd8c
Fixed connections of block when changing block type
Laurent Bessard
parents:
873
diff
changeset
|
313 |
output.RefreshWires() |
814 | 314 |
self.RefreshBoundingBox() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
315 |
|
814 | 316 |
# Returns the block type |
317 |
def GetType(self): |
|
318 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
319 |
|
814 | 320 |
# Changes the block name |
321 |
def SetName(self, name): |
|
322 |
self.Name = name |
|
323 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
324 |
|
814 | 325 |
# Returs the block name |
326 |
def GetName(self): |
|
327 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
328 |
|
814 | 329 |
# Changes the extension name |
330 |
def SetExtension(self, extension): |
|
331 |
self.Extension = extension |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
332 |
|
814 | 333 |
# Returs the extension name |
334 |
def GetExtension(self): |
|
335 |
return self.Extension |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
336 |
|
814 | 337 |
# Changes the execution order |
338 |
def SetExecutionOrder(self, executionOrder): |
|
339 |
self.ExecutionOrder = executionOrder |
|
340 |
self.RefreshExecutionOrderSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
341 |
|
814 | 342 |
# Returs the execution order |
343 |
def GetExecutionOrder(self): |
|
344 |
return self.ExecutionOrder |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
345 |
|
814 | 346 |
# Returs the execution order |
347 |
def GetExecutionControl(self): |
|
348 |
return self.ExecutionControl |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
349 |
|
814 | 350 |
# Refresh the block minimum size |
351 |
def RefreshMinSize(self): |
|
352 |
# Calculate the inputs maximum width |
|
353 |
max_input = 0 |
|
354 |
for input in self.Inputs: |
|
355 |
w, h = input.GetNameSize() |
|
356 |
max_input = max(max_input, w) |
|
357 |
# Calculate the outputs maximum width |
|
358 |
max_output = 0 |
|
359 |
for output in self.Outputs: |
|
360 |
w, h = output.GetNameSize() |
|
361 |
max_output = max(max_output, w) |
|
362 |
width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
|
363 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
|
364 |
self.MinSize = width, height |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
365 |
|
814 | 366 |
# Returns the block minimum size |
367 |
def GetMinSize(self): |
|
368 |
return self.MinSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
369 |
|
814 | 370 |
# Changes the negated property of the connector handled |
371 |
def SetConnectorNegated(self, negated): |
|
372 |
handle_type, handle = self.Handle |
|
373 |
if handle_type == HANDLE_CONNECTOR: |
|
374 |
handle.SetNegated(negated) |
|
375 |
self.RefreshModel(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
376 |
|
814 | 377 |
# Changes the edge property of the connector handled |
378 |
def SetConnectorEdge(self, edge): |
|
379 |
handle_type, handle = self.Handle |
|
380 |
if handle_type == HANDLE_CONNECTOR: |
|
381 |
handle.SetEdge(edge) |
|
382 |
self.RefreshModel(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
383 |
|
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
384 |
# # 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
|
385 |
# 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
|
386 |
# 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
|
387 |
# 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
|
388 |
# 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
|
389 |
# 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
|
390 |
# 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
|
391 |
# 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
|
392 |
# 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
|
393 |
# 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
|
394 |
# 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
|
395 |
|
814 | 396 |
# Method called when a LeftDClick event have been generated |
397 |
def OnLeftDClick(self, event, dc, scaling): |
|
398 |
# Edit the block properties |
|
399 |
self.Parent.EditBlockContent(self) |
|
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 RightUp event have been generated |
402 |
def OnRightUp(self, event, dc, scaling): |
|
403 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
404 |
# Popup the menu with special items for a block and a connector if one is handled |
|
405 |
connector = self.TestConnector(pos, exclude=False) |
|
406 |
if connector: |
|
407 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
408 |
self.Parent.PopupBlockMenu(connector) |
|
409 |
else: |
|
410 |
self.Parent.PopupBlockMenu() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
411 |
|
814 | 412 |
# Refreshes the block model |
413 |
def RefreshModel(self, move=True): |
|
414 |
self.Parent.RefreshBlockModel(self) |
|
415 |
# If block has moved, refresh the model of wires connected to outputs |
|
416 |
if move: |
|
417 |
for output in self.Outputs: |
|
418 |
output.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
419 |
|
814 | 420 |
def GetToolTipValue(self): |
421 |
return self.Description |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
422 |
|
814 | 423 |
# 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
|
424 |
def AddHighlight(self, infos, start, end, highlight_type): |
814 | 425 |
if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: |
426 |
highlights = self.Highlights.setdefault(infos[0], []) |
|
427 |
AddHighlight(highlights, (start, end, highlight_type)) |
|
428 |
elif infos[0] == "input" and infos[1] < len(self.Inputs): |
|
429 |
self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) |
|
430 |
elif infos[0] == "output" and infos[1] < len(self.Outputs): |
|
431 |
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
|
432 |
|
814 | 433 |
# Removes an highlight from the block |
434 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
435 |
if infos[0] in ["type", "name"]: |
|
436 |
highlights = self.Highlights.get(infos[0], []) |
|
437 |
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
|
438 |
self.Highlights.pop(infos[0]) |
|
439 |
elif infos[0] == "input" and infos[1] < len(self.Inputs): |
|
440 |
self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) |
|
441 |
elif infos[0] == "output" and infos[1] < len(self.Outputs): |
|
442 |
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
|
443 |
|
814 | 444 |
# Removes all the highlights of one particular type from the block |
445 |
def ClearHighlight(self, highlight_type=None): |
|
446 |
if highlight_type is None: |
|
447 |
self.Highlights = {} |
|
448 |
else: |
|
449 |
highlight_items = self.Highlights.items() |
|
450 |
for name, highlights in highlight_items: |
|
451 |
highlights = ClearHighlights(highlights, highlight_type) |
|
452 |
if len(highlights) == 0: |
|
453 |
self.Highlights.pop(name) |
|
454 |
for input in self.Inputs: |
|
455 |
input.ClearHighlights(highlight_type) |
|
456 |
for output in self.Outputs: |
|
457 |
output.ClearHighlights(highlight_type) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
458 |
|
814 | 459 |
# Draws block |
460 |
def Draw(self, dc): |
|
461 |
Graphic_Element.Draw(self, dc) |
|
462 |
dc.SetPen(self.Pen) |
|
463 |
dc.SetBrush(wx.WHITE_BRUSH) |
|
464 |
dc.SetTextForeground(self.Colour) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
465 |
|
814 | 466 |
if getattr(dc, "printing", False): |
467 |
name_size = dc.GetTextExtent(self.Name) |
|
468 |
type_size = dc.GetTextExtent(self.Type) |
|
469 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
470 |
else: |
|
471 |
name_size = self.NameSize |
|
472 |
type_size = self.TypeSize |
|
473 |
executionorder_size = self.ExecutionOrderSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
474 |
|
814 | 475 |
# Draw a rectangle with the block size |
476 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
477 |
# Draw block name and block type |
|
478 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
|
479 |
self.Pos.y - (name_size[1] + 2)) |
|
480 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2, |
|
481 |
self.Pos.y + 5) |
|
482 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
|
483 |
dc.DrawText(self.Type, type_pos[0], type_pos[1]) |
|
484 |
# Draw inputs and outputs connectors |
|
485 |
for input in self.Inputs: |
|
486 |
input.Draw(dc) |
|
487 |
for output in self.Outputs: |
|
488 |
output.Draw(dc) |
|
489 |
if self.ExecutionOrder != 0: |
|
490 |
# Draw block execution order |
|
491 |
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
|
492 |
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
|
493 |
|
814 | 494 |
if not getattr(dc, "printing", False): |
495 |
DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1]) |
|
496 |
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
|
497 |
|
814 | 498 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
499 |
# ------------------------------------------------------------------------------- |
814 | 500 |
# 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
|
501 |
# ------------------------------------------------------------------------------- |
814 | 502 |
|
503 |
||
504 |
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
|
505 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
506 |
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
|
507 |
""" |
814 | 508 |
|
509 |
# 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
|
510 |
def __init__(self, parent, type, name, value_type, id=None, executionOrder=0): |
814 | 511 |
Graphic_Element.__init__(self, parent) |
512 |
self.Type = None |
|
513 |
self.ValueType = None |
|
514 |
self.Id = id |
|
515 |
self.SetName(name) |
|
516 |
self.SetExecutionOrder(executionOrder) |
|
517 |
self.Input = None |
|
518 |
self.Output = None |
|
519 |
self.SetType(type, value_type) |
|
520 |
self.Highlights = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
521 |
|
814 | 522 |
# 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
|
523 |
def Clone(self, parent, id=None, pos=None): |
814 | 524 |
variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id) |
525 |
variable.SetSize(self.Size[0], self.Size[1]) |
|
526 |
if pos is not None: |
|
527 |
variable.SetPosition(pos.x, pos.y) |
|
528 |
else: |
|
529 |
variable.SetPosition(self.Pos.x, self.Pos.y) |
|
530 |
if self.Input: |
|
531 |
variable.Input = self.Input.Clone(variable) |
|
532 |
if self.Output: |
|
533 |
variable.Output = self.Output.Clone(variable) |
|
534 |
return variable |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
535 |
|
814 | 536 |
def GetConnectorTranslation(self, element): |
537 |
connectors = {} |
|
538 |
if self.Input is not None: |
|
539 |
connectors[self.Input] = element.Input |
|
540 |
if self.Output is not None: |
|
541 |
connectors[self.Output] = element.Output |
|
542 |
return connectors |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
543 |
|
814 | 544 |
def Flush(self): |
545 |
if self.Input is not None: |
|
546 |
self.Input.Flush() |
|
547 |
self.Input = None |
|
548 |
if self.Output is not None: |
|
549 |
self.Output.Flush() |
|
550 |
self.Output = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
551 |
|
814 | 552 |
# 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
|
553 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 554 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
555 |
if movex != 0 or movey != 0: |
|
556 |
if self.Input and self.Input.IsConnected(): |
|
557 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
558 |
if self.Output and self.Output.IsConnected(): |
|
559 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
560 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
561 |
|
814 | 562 |
# Unconnect connector |
563 |
def Clean(self): |
|
564 |
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
|
565 |
self.Input.UnConnect(delete=True) |
814 | 566 |
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
|
567 |
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
|
568 |
|
814 | 569 |
# Delete this variable by calling the appropriate method |
570 |
def Delete(self): |
|
571 |
self.Parent.DeleteVariable(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
572 |
|
814 | 573 |
# Refresh the size of text for name |
574 |
def RefreshNameSize(self): |
|
575 |
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
|
576 |
|
814 | 577 |
# Refresh the size of text for execution order |
578 |
def RefreshExecutionOrderSize(self): |
|
579 |
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
|
580 |
|
814 | 581 |
# Refresh the variable bounding box |
582 |
def RefreshBoundingBox(self): |
|
583 |
if self.Type in (OUTPUT, INOUT): |
|
584 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
585 |
else: |
|
586 |
bbx_x = self.Pos.x |
|
587 |
if self.Type == INOUT: |
|
588 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE |
|
589 |
else: |
|
590 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
591 |
bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2) |
|
592 |
bbx_width = max(bbx_width, self.NameSize[0]) |
|
593 |
bbx_height = self.Size[1] |
|
594 |
if self.ExecutionOrder != 0: |
|
595 |
bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) |
|
596 |
bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) |
|
597 |
bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) |
|
598 |
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
|
599 |
|
814 | 600 |
# Refresh the position of the variable connector |
601 |
def RefreshConnectors(self): |
|
602 |
scaling = self.Parent.GetScaling() |
|
603 |
if scaling is not None: |
|
604 |
position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y |
|
605 |
else: |
|
606 |
position = self.Size[1] / 2 |
|
607 |
if self.Input: |
|
608 |
self.Input.SetPosition(wx.Point(0, position)) |
|
609 |
if self.Output: |
|
610 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
611 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
612 |
|
814 | 613 |
# Refresh the position of wires connected to connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
614 |
def RefreshConnected(self, exclude=[]): |
814 | 615 |
if self.Input: |
616 |
self.Input.MoveConnected(exclude) |
|
617 |
if self.Output: |
|
618 |
self.Output.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
619 |
|
814 | 620 |
# 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
|
621 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 622 |
if self.Input and self.Input.TestPoint(pt, direction, exclude): |
623 |
return self.Input |
|
624 |
if self.Output and self.Output.TestPoint(pt, direction, exclude): |
|
625 |
return self.Output |
|
626 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
627 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
628 |
# 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
|
629 |
def GetConnector(self, position, name=None): |
814 | 630 |
# if a name is given |
631 |
if name is not None: |
|
632 |
# 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
|
633 |
# if self.Input and name == self.Input.GetName(): |
814 | 634 |
# return self.Input |
635 |
if self.Output and name == self.Output.GetName(): |
|
636 |
return self.Output |
|
637 |
connectors = [] |
|
638 |
# Test input connector if it exists |
|
639 |
if self.Input: |
|
640 |
connectors.append(self.Input) |
|
641 |
# Test output connector if it exists |
|
642 |
if self.Output: |
|
643 |
connectors.append(self.Output) |
|
644 |
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
|
645 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
646 |
# Returns all the block connectors |
814 | 647 |
def GetConnectors(self): |
648 |
connectors = {"inputs": [], "outputs": []} |
|
649 |
if self.Input: |
|
650 |
connectors["inputs"].append(self.Input) |
|
651 |
if self.Output: |
|
652 |
connectors["outputs"].append(self.Output) |
|
653 |
return connectors |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
654 |
|
814 | 655 |
# Changes the negated property of the variable connector if handled |
656 |
def SetConnectorNegated(self, negated): |
|
657 |
handle_type, handle = self.Handle |
|
658 |
if handle_type == HANDLE_CONNECTOR: |
|
659 |
handle.SetNegated(negated) |
|
660 |
self.RefreshModel(False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
661 |
|
814 | 662 |
# Changes the variable type |
663 |
def SetType(self, type, value_type): |
|
664 |
if type != self.Type: |
|
665 |
self.Type = type |
|
666 |
# Create an input or output connector according to variable type |
|
667 |
if self.Type != INPUT: |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
668 |
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
|
669 |
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
|
670 |
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
|
671 |
self.Input.UnConnect(delete=True) |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
672 |
self.Input = None |
814 | 673 |
if self.Type != OUTPUT: |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
674 |
if self.Output is None: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
675 |
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
|
676 |
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
|
677 |
self.Output.UnConnect(delete=True) |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
678 |
self.Output = None |
814 | 679 |
self.RefreshConnectors() |
873
8737f1554494
Fix bug Variable and Continuation BoundingBox not refreshed when using Type modification shortcuts
Laurent Bessard
parents:
857
diff
changeset
|
680 |
self.RefreshBoundingBox() |
814 | 681 |
elif value_type != self.ValueType: |
682 |
if self.Input: |
|
683 |
self.Input.SetType(value_type) |
|
684 |
if self.Output: |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
685 |
self.Output.SetType(value_type) |
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
686 |
|
814 | 687 |
# Returns the variable type |
688 |
def GetType(self): |
|
689 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
690 |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
691 |
# Returns the variable value type |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
692 |
def GetValueType(self): |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
693 |
return self.ValueType |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
694 |
|
814 | 695 |
# Changes the variable name |
696 |
def SetName(self, name): |
|
697 |
self.Name = name |
|
698 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
699 |
|
814 | 700 |
# Returns the variable name |
701 |
def GetName(self): |
|
702 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
703 |
|
814 | 704 |
# Changes the execution order |
705 |
def SetExecutionOrder(self, executionOrder): |
|
706 |
self.ExecutionOrder = executionOrder |
|
707 |
self.RefreshExecutionOrderSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
708 |
|
814 | 709 |
# Returs the execution order |
710 |
def GetExecutionOrder(self): |
|
711 |
return self.ExecutionOrder |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
712 |
|
814 | 713 |
# Returns the variable minimum size |
714 |
def GetMinSize(self): |
|
715 |
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
|
716 |
|
852
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
717 |
# 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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
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
|
722 |
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
|
723 |
else: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
724 |
return Graphic_Element.SetBestSize(self, scaling) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
725 |
|
814 | 726 |
# Method called when a LeftDClick event have been generated |
727 |
def OnLeftDClick(self, event, dc, scaling): |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
728 |
if event.ControlDown(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
729 |
# Change variable type |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
else: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
734 |
# Edit the variable properties |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
735 |
self.Parent.EditVariableContent(self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
736 |
|
814 | 737 |
# Method called when a RightUp event have been generated |
738 |
def OnRightUp(self, event, dc, scaling): |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
739 |
self.Parent.PopupVariableMenu() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
740 |
|
814 | 741 |
# Refreshes the variable model |
742 |
def RefreshModel(self, move=True): |
|
743 |
self.Parent.RefreshVariableModel(self) |
|
744 |
# If variable has moved and variable is not of type OUTPUT, refresh the model |
|
745 |
# of wires connected to output connector |
|
746 |
if move and self.Type != OUTPUT: |
|
747 |
if self.Output: |
|
748 |
self.Output.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
749 |
|
814 | 750 |
# Adds an highlight to the variable |
751 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
752 |
if infos[0] == "expression" and start[0] == 0 and end[0] == 0: |
|
753 |
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
|
754 |
|
814 | 755 |
# Removes an highlight from the variable |
756 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
757 |
if infos[0] == "expression": |
|
758 |
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
|
759 |
|
814 | 760 |
# Removes all the highlights of one particular type from the variable |
761 |
def ClearHighlight(self, highlight_type=None): |
|
762 |
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
|
763 |
|
814 | 764 |
# Draws variable |
765 |
def Draw(self, dc): |
|
766 |
Graphic_Element.Draw(self, dc) |
|
767 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
768 |
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
|
769 |
|
814 | 770 |
if getattr(dc, "printing", False): |
771 |
name_size = dc.GetTextExtent(self.Name) |
|
772 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
773 |
else: |
|
774 |
name_size = self.NameSize |
|
775 |
executionorder_size = self.ExecutionOrderSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
776 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
777 |
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
814 | 778 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
779 |
# Draw a rectangle with the variable size |
|
780 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
781 |
# Draw variable name |
|
782 |
dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
|
783 |
# Draw connectors |
|
784 |
if self.Input: |
|
785 |
self.Input.Draw(dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
786 |
if self.Output: |
814 | 787 |
self.Output.Draw(dc) |
788 |
if self.ExecutionOrder != 0: |
|
789 |
# Draw variable execution order |
|
790 |
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
|
791 |
self.Pos.y + self.Size[1] + 2) |
814 | 792 |
if not getattr(dc, "printing", False): |
793 |
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
|
794 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
795 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
796 |
# ------------------------------------------------------------------------------- |
814 | 797 |
# 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
|
798 |
# ------------------------------------------------------------------------------- |
814 | 799 |
|
800 |
||
801 |
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
|
802 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
803 |
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
|
804 |
""" |
814 | 805 |
|
806 |
# 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
|
807 |
def __init__(self, parent, type, name, id=None): |
814 | 808 |
Graphic_Element.__init__(self, parent) |
809 |
self.Type = type |
|
810 |
self.Id = id |
|
811 |
self.SetName(name) |
|
812 |
self.Pos = wx.Point(0, 0) |
|
813 |
self.Size = wx.Size(0, 0) |
|
814 |
self.Highlights = [] |
|
815 |
# Create an input or output connector according to connection type |
|
816 |
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
|
817 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True) |
814 | 818 |
else: |
819 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
|
820 |
self.RefreshConnectors() |
|
821 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
822 |
|
814 | 823 |
def Flush(self): |
824 |
if self.Connector: |
|
825 |
self.Connector.Flush() |
|
826 |
self.Connector = None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
827 |
|
814 | 828 |
# 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
|
829 |
def GetRedrawRect(self, movex=0, movey=0): |
814 | 830 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
831 |
if movex != 0 or movey != 0: |
|
832 |
if self.Connector and self.Connector.IsConnected(): |
|
833 |
rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
|
834 |
return rect |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
835 |
|
814 | 836 |
# 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
|
837 |
def Clone(self, parent, id=None, pos=None): |
814 | 838 |
connection = FBD_Connector(parent, self.Type, self.Name, id) |
839 |
connection.SetSize(self.Size[0], self.Size[1]) |
|
840 |
if pos is not None: |
|
841 |
connection.SetPosition(pos.x, pos.y) |
|
842 |
else: |
|
843 |
connection.SetPosition(self.Pos.x, self.Pos.y) |
|
844 |
connection.Connector = self.Connector.Clone(connection) |
|
845 |
return connection |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
846 |
|
814 | 847 |
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
|
848 |
return {self.Connector: element.Connector} |
814 | 849 |
|
850 |
# Unconnect connector |
|
851 |
def Clean(self): |
|
852 |
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
|
853 |
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
|
854 |
|
814 | 855 |
# Delete this connection by calling the appropriate method |
856 |
def Delete(self): |
|
857 |
self.Parent.DeleteConnection(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
858 |
|
814 | 859 |
# Refresh the size of text for name |
860 |
def RefreshNameSize(self): |
|
861 |
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
|
862 |
|
814 | 863 |
# Refresh the connection bounding box |
864 |
def RefreshBoundingBox(self): |
|
865 |
if self.Type == CONNECTOR: |
|
866 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
867 |
else: |
|
868 |
bbx_x = self.Pos.x |
|
869 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
870 |
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
|
871 |
|
814 | 872 |
# Refresh the position of the connection connector |
873 |
def RefreshConnectors(self): |
|
874 |
scaling = self.Parent.GetScaling() |
|
875 |
if scaling is not None: |
|
876 |
position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y |
|
877 |
else: |
|
878 |
position = self.Size[1] / 2 |
|
879 |
if self.Type == CONNECTOR: |
|
880 |
self.Connector.SetPosition(wx.Point(0, position)) |
|
881 |
else: |
|
882 |
self.Connector.SetPosition(wx.Point(self.Size[0], position)) |
|
883 |
self.RefreshConnected() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
884 |
|
814 | 885 |
# Refresh the position of wires connected to connector |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
886 |
def RefreshConnected(self, exclude=[]): |
814 | 887 |
if self.Connector: |
888 |
self.Connector.MoveConnected(exclude) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
889 |
|
814 | 890 |
# 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
|
891 |
def TestConnector(self, pt, direction=None, exclude=True): |
814 | 892 |
if self.Connector and self.Connector.TestPoint(pt, direction, exclude): |
893 |
return self.Connector |
|
894 |
return None |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
895 |
|
814 | 896 |
# 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
|
897 |
def GetConnector(self, position=None, name=None): |
814 | 898 |
return self.Connector |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
899 |
|
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
900 |
# Returns all the block connectors |
814 | 901 |
def GetConnectors(self): |
902 |
connectors = {"inputs": [], "outputs": []} |
|
903 |
if self.Type == CONNECTOR: |
|
904 |
connectors["inputs"].append(self.Connector) |
|
905 |
else: |
|
906 |
connectors["outputs"].append(self.Connector) |
|
907 |
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
|
908 |
|
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 |
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
|
910 |
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
|
911 |
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
|
912 |
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
|
913 |
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
|
914 |
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
|
915 |
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
|
916 |
|
814 | 917 |
# Changes the variable type |
918 |
def SetType(self, type): |
|
919 |
if type != self.Type: |
|
920 |
self.Type = type |
|
921 |
self.Clean() |
|
922 |
# Create an input or output connector according to connection type |
|
923 |
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
|
924 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True) |
814 | 925 |
else: |
926 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
|
927 |
self.RefreshConnectors() |
|
873
8737f1554494
Fix bug Variable and Continuation BoundingBox not refreshed when using Type modification shortcuts
Laurent Bessard
parents:
857
diff
changeset
|
928 |
self.RefreshBoundingBox() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
929 |
|
814 | 930 |
# Returns the connection type |
931 |
def GetType(self): |
|
932 |
return self.Type |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
933 |
|
814 | 934 |
def GetConnectionResultType(self, connector, connectortype): |
935 |
if self.Type == CONTINUATION: |
|
936 |
connector = self.Parent.GetConnectorByName(self.Name) |
|
937 |
if connector is not None: |
|
938 |
return connector.Connector.GetConnectedType() |
|
939 |
return connectortype |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
940 |
|
814 | 941 |
# Changes the connection name |
942 |
def SetName(self, name): |
|
943 |
self.Name = name |
|
944 |
self.RefreshNameSize() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
945 |
|
814 | 946 |
# Returns the connection name |
947 |
def GetName(self): |
|
948 |
return self.Name |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
949 |
|
852
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
950 |
# 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
|
951 |
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
|
952 |
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
|
953 |
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
|
954 |
else: |
1009f956d2ee
Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents:
814
diff
changeset
|
955 |
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
|
956 |
|
814 | 957 |
# Returns the connection minimum size |
958 |
def GetMinSize(self): |
|
959 |
text_width, text_height = self.NameSize |
|
960 |
if text_height % 2 == 1: |
|
961 |
text_height += 1 |
|
962 |
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
|
963 |
|
814 | 964 |
# Method called when a LeftDClick event have been generated |
965 |
def OnLeftDClick(self, event, dc, scaling): |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
966 |
if event.ControlDown(): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
967 |
# Change connection type |
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
968 |
if self.Type == CONNECTOR: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
969 |
self.Parent.ChangeConnectionType(self, CONTINUATION) |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
970 |
else: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
971 |
self.Parent.ChangeConnectionType(self, CONNECTOR) |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
972 |
else: |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
973 |
# Edit the connection properties |
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
974 |
self.Parent.EditConnectionContent(self) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
975 |
|
814 | 976 |
# Method called when a RightUp event have been generated |
977 |
def OnRightUp(self, event, dc, scaling): |
|
978 |
# Popup the default menu |
|
857
9695969796d0
Adding support for quickly changing variable and connection type
Laurent Bessard
parents:
852
diff
changeset
|
979 |
self.Parent.PopupConnectionMenu() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
980 |
|
814 | 981 |
# Refreshes the connection model |
982 |
def RefreshModel(self, move=True): |
|
983 |
self.Parent.RefreshConnectionModel(self) |
|
984 |
# If connection has moved and connection is of type CONTINUATION, refresh |
|
985 |
# the model of wires connected to connector |
|
986 |
if move and self.Type == CONTINUATION: |
|
987 |
if self.Connector: |
|
988 |
self.Connector.RefreshWires() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
989 |
|
814 | 990 |
# Adds an highlight to the connection |
991 |
def AddHighlight(self, infos, start, end, highlight_type): |
|
992 |
if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
|
993 |
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
|
994 |
|
814 | 995 |
# Removes an highlight from the connection |
996 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
|
997 |
if infos[0] == "name": |
|
998 |
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
|
999 |
|
814 | 1000 |
# Removes all the highlights of one particular type from the connection |
1001 |
def ClearHighlight(self, highlight_type=None): |
|
1002 |
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
|
1003 |
|
814 | 1004 |
# Draws connection |
1005 |
def Draw(self, dc): |
|
1006 |
Graphic_Element.Draw(self, dc) |
|
1007 |
dc.SetPen(MiterPen(wx.BLACK)) |
|
1008 |
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
|
1009 |
|
814 | 1010 |
if getattr(dc, "printing", False): |
1011 |
name_size = dc.GetTextExtent(self.Name) |
|
1012 |
else: |
|
1013 |
name_size = self.NameSize |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1014 |
|
814 | 1015 |
# Draw a rectangle with the connection size with arrows inside |
1016 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1017 |
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
|
1018 |
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
|
1019 |
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
|
1020 |
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
|
1021 |
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
|
1022 |
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
|
1023 |
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
|
1024 |
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
|
1025 |
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) |
814 | 1026 |
# Draw connection name |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1027 |
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
814 | 1028 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
1029 |
dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
|
1030 |
# Draw connector |
|
1031 |
if self.Connector: |
|
1032 |
self.Connector.Draw(dc) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1605
diff
changeset
|
1033 |
|
814 | 1034 |
if not getattr(dc, "printing", False): |
1035 |
DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) |