author | lbessard |
Tue, 02 Oct 2007 18:07:59 +0200 | |
changeset 102 | 85875dcb7754 |
parent 99 | 2b18a72dcaf0 |
child 103 | 26c10e28ee3a |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
5 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
0 | 20 |
# |
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import wx |
|
26 |
||
27 |
from GraphicCommons import * |
|
28 |
from plcopen.structures import * |
|
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
29 |
from plcopen.structures import IsOfType |
0 | 30 |
|
31 |
#------------------------------------------------------------------------------- |
|
32 |
# Function Block Diagram Block |
|
33 |
#------------------------------------------------------------------------------- |
|
34 |
||
35 |
""" |
|
36 |
Class that implements the graphic representation of a function block |
|
37 |
""" |
|
38 |
||
39 |
class FBD_Block(Graphic_Element): |
|
40 |
||
41 |
# Create a new block |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
42 |
def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}): |
0 | 43 |
Graphic_Element.__init__(self, parent) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
44 |
self.Type = None |
27 | 45 |
self.Extension = None |
0 | 46 |
self.Name = name |
47 |
self.Id = id |
|
2 | 48 |
self.Inputs = [] |
49 |
self.Outputs = [] |
|
42 | 50 |
self.RefreshNameSize() |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
51 |
self.Colour = wx.BLACK |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
52 |
self.Pen = wx.BLACK_PEN |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
53 |
self.SetType(type, extension, inputs, connectors) |
0 | 54 |
|
55 |
# Destructor |
|
56 |
def __del__(self): |
|
57 |
self.Inputs = [] |
|
58 |
self.Outputs = [] |
|
59 |
||
60 |
# Delete this block by calling the appropriate method |
|
61 |
def Delete(self): |
|
62 |
self.Parent.DeleteBlock(self) |
|
63 |
||
64 |
# Unconnect all inputs and outputs |
|
65 |
def Clean(self): |
|
66 |
for input in self.Inputs: |
|
2 | 67 |
input.UnConnect(delete = True) |
68 |
for output in self.Outputs: |
|
69 |
output.UnConnect(delete = True) |
|
0 | 70 |
|
42 | 71 |
# Refresh the size of text for name |
72 |
def RefreshNameSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
73 |
dc = wx.ClientDC(self.Parent) |
42 | 74 |
self.NameSize = dc.GetTextExtent(self.Name) |
75 |
||
0 | 76 |
# Refresh the block bounding box |
77 |
def RefreshBoundingBox(self): |
|
78 |
# Calculate the size of the name outside the block |
|
42 | 79 |
text_width, text_height = self.NameSize |
0 | 80 |
# Calculate the bounding box size |
81 |
bbx_x = self.Pos.x - max(min(1, len(self.Inputs)) * CONNECTOR_SIZE, (text_width - self.Size[0]) / 2) |
|
82 |
bbx_width = self.Size[0] + 1 + (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE |
|
83 |
if self.Name != "": |
|
84 |
bbx_y = self.Pos.y - (text_height + 2) |
|
85 |
bbx_height = self.Size[1] + (text_height + 2) |
|
86 |
else: |
|
87 |
bbx_y = self.Pos.y |
|
88 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
89 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 90 |
|
91 |
# Refresh the positions of the block connectors |
|
92 |
def RefreshConnectors(self): |
|
93 |
# Calculate the size for the connector lines |
|
94 |
lines = max(len(self.Inputs), len(self.Outputs)) |
|
95 |
linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE) |
|
96 |
# Update inputs positions |
|
97 |
position = BLOCK_LINE_SIZE + linesize / 2 |
|
98 |
for input in self.Inputs: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
99 |
input.SetPosition(wx.Point(0, position)) |
0 | 100 |
position += linesize |
101 |
# Update outputs positions |
|
102 |
position = BLOCK_LINE_SIZE + linesize / 2 |
|
103 |
for output in self.Outputs: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
104 |
output.SetPosition(wx.Point(self.Size[0], position)) |
0 | 105 |
position += linesize |
106 |
self.RefreshConnected() |
|
107 |
||
108 |
# Refresh the positions of wires connected to inputs and outputs |
|
109 |
def RefreshConnected(self, exclude = []): |
|
110 |
for input in self.Inputs: |
|
111 |
input.MoveConnected(exclude) |
|
112 |
for output in self.Outputs: |
|
113 |
output.MoveConnected(exclude) |
|
114 |
||
115 |
# Returns the block connector that starts with the point given if it exists |
|
27 | 116 |
def GetConnector(self, position, name = None): |
117 |
# if a name is given |
|
118 |
if name: |
|
119 |
# Test each input and output connector |
|
120 |
for input in self.Inputs: |
|
121 |
if name == input.GetName(): |
|
122 |
return input |
|
123 |
for output in self.Outputs: |
|
124 |
if name == output.GetName(): |
|
125 |
return output |
|
0 | 126 |
# Test each input connector |
127 |
for input in self.Inputs: |
|
128 |
input_pos = input.GetRelPosition() |
|
129 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
130 |
return input |
|
131 |
# Test each output connector |
|
132 |
for output in self.Outputs: |
|
133 |
output_pos = output.GetRelPosition() |
|
134 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
135 |
return output |
|
136 |
return None |
|
137 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
138 |
def GetInputTypes(self): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
139 |
return tuple([input.GetType() for input in self.Inputs]) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
140 |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
141 |
def SetOutputValues(self, values): |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
142 |
for output in self.Outputs: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
143 |
output.SetValue(values.get(ouput.getName(), None)) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
144 |
|
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
145 |
def GetConnectionResultType(self, connector, connectortype): |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
146 |
resulttype = connectortype |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
147 |
for input in self.Inputs: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
148 |
name = input.GetName() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
149 |
if input != connector and (name.startswith("IN") or name in ["MN", "MX"]): |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
150 |
inputtype = input.GetConnectedType() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
151 |
if resulttype is None or inputtype is not None and IsOfType(inputtype, resulttype): |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
152 |
resulttype = inputtype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
153 |
for output in self.Outputs: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
154 |
name = output.GetName() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
155 |
if output != connector and name == "OUT": |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
156 |
outputtype = output.GetConnectedType() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
157 |
if resulttype is None or outputtype is not None and IsOfType(outputtype, resulttype): |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
158 |
resulttype = outputtype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
159 |
return resulttype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
160 |
|
0 | 161 |
# Returns all the block connectors |
162 |
def GetConnectors(self): |
|
163 |
return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
|
164 |
||
165 |
# Test if point given is on one of the block connectors |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
166 |
def TestConnector(self, pt, exclude = True): |
0 | 167 |
# Test each input connector |
168 |
for input in self.Inputs: |
|
169 |
if input.TestPoint(pt, exclude): |
|
170 |
return input |
|
171 |
# Test each output connector |
|
172 |
for output in self.Outputs: |
|
173 |
if output.TestPoint(pt, exclude): |
|
174 |
return output |
|
175 |
return None |
|
176 |
||
2 | 177 |
# Changes the block type |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
178 |
def SetType(self, type, extension, inputs = None, connectors = {}): |
27 | 179 |
if type != self.Type or self.Extension != extension: |
42 | 180 |
if type != self.Type: |
181 |
self.Type = type |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
182 |
dc = wx.ClientDC(self.Parent) |
42 | 183 |
self.TypeSize = dc.GetTextExtent(self.Type) |
27 | 184 |
self.Extension = extension |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
185 |
# Find the block definition from type given and create the corresponding |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
186 |
# inputs and outputs |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
187 |
blocktype = GetBlockType(type, inputs) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
188 |
if blocktype: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
189 |
self.Colour = wx.BLACK |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
190 |
inputs = [input for input in blocktype["inputs"]] |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
191 |
outputs = [output for output in blocktype["outputs"]] |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
192 |
if blocktype["extensible"]: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
193 |
start = int(inputs[-1][0].replace("IN", "")) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
194 |
for i in xrange(self.Extension - len(blocktype["inputs"])): |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
195 |
start += 1 |
27 | 196 |
inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) |
16 | 197 |
else: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
198 |
self.Colour = wx.RED |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
199 |
if "inputs" in connectors: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
200 |
inputs = connectors["inputs"] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
201 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
202 |
inputs = [] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
203 |
if "outputs" in connectors: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
204 |
outputs = connectors["outputs"] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
205 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
206 |
outputs = [] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
207 |
self.Pen = wx.Pen(self.Colour) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
208 |
self.Clean() |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
209 |
# Extract the inputs properties and create the corresponding connector |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
210 |
self.Inputs = [] |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
211 |
for input_name, input_type, input_modifier in inputs: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
212 |
connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
213 |
if input_modifier == "negated": |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
214 |
connector.SetNegated(True) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
215 |
elif input_modifier != "none": |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
216 |
connector.SetEdge(input_modifier) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
217 |
self.Inputs.append(connector) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
218 |
# Extract the outputs properties and create the corresponding connector |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
219 |
self.Outputs = [] |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
220 |
for output_name, output_type, output_modifier in outputs: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
221 |
connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
222 |
if output_modifier == "negated": |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
223 |
connector.SetNegated(True) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
224 |
elif output_modifier != "none": |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
225 |
connector.SetEdge(output_modifier) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
226 |
self.Outputs.append(connector) |
42 | 227 |
self.RefreshMinSize() |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
228 |
self.RefreshConnectors() |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
229 |
self.RefreshBoundingBox() |
2 | 230 |
|
0 | 231 |
# Returns the block type |
232 |
def GetType(self): |
|
233 |
return self.Type |
|
234 |
||
235 |
# Changes the block name |
|
236 |
def SetName(self, name): |
|
237 |
self.Name = name |
|
42 | 238 |
self.RefreshNameSize() |
0 | 239 |
|
240 |
# Returs the block name |
|
241 |
def GetName(self): |
|
242 |
return self.Name |
|
243 |
||
2 | 244 |
# Changes the extension name |
245 |
def SetExtension(self, extension): |
|
246 |
self.Extension = extension |
|
247 |
||
248 |
# Returs the extension name |
|
249 |
def GetExtension(self): |
|
250 |
return self.Extension |
|
251 |
||
42 | 252 |
# Refresh the block minimum size |
253 |
def RefreshMinSize(self): |
|
0 | 254 |
# Calculate the inputs maximum width |
255 |
max_input = 0 |
|
256 |
for input in self.Inputs: |
|
42 | 257 |
w, h = input.GetNameSize() |
0 | 258 |
max_input = max(max_input, w) |
259 |
# Calculate the outputs maximum width |
|
260 |
max_output = 0 |
|
261 |
for output in self.Outputs: |
|
42 | 262 |
w, h = output.GetNameSize() |
0 | 263 |
max_output = max(max_output, w) |
42 | 264 |
width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
0 | 265 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
42 | 266 |
self.MinSize = width, height |
267 |
||
268 |
# Returns the block minimum size |
|
269 |
def GetMinSize(self): |
|
270 |
return self.MinSize |
|
0 | 271 |
|
272 |
# Changes the negated property of the connector handled |
|
273 |
def SetConnectorNegated(self, negated): |
|
274 |
handle_type, handle = self.Handle |
|
275 |
if handle_type == HANDLE_CONNECTOR: |
|
276 |
handle.SetNegated(negated) |
|
277 |
self.RefreshModel(False) |
|
278 |
||
279 |
# Changes the edge property of the connector handled |
|
280 |
def SetConnectorEdge(self, edge): |
|
281 |
handle_type, handle = self.Handle |
|
282 |
if handle_type == HANDLE_CONNECTOR: |
|
283 |
handle.SetEdge(edge) |
|
284 |
self.RefreshModel(False) |
|
285 |
||
2 | 286 |
# Method called when a LeftDClick event have been generated |
27 | 287 |
def OnLeftDClick(self, event, dc, scaling): |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
288 |
# Edit the block properties |
2 | 289 |
self.Parent.EditBlockContent(self) |
290 |
||
0 | 291 |
# Method called when a RightUp event have been generated |
27 | 292 |
def OnRightUp(self, event, dc, scaling): |
293 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 294 |
# Popup the menu with special items for a block and a connector if one is handled |
295 |
connector = self.TestConnector(pos, False) |
|
296 |
if connector: |
|
297 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
298 |
self.Parent.PopupBlockMenu(connector) |
|
299 |
else: |
|
300 |
self.Parent.PopupBlockMenu() |
|
301 |
||
302 |
# Refreshes the block model |
|
303 |
def RefreshModel(self, move=True): |
|
304 |
self.Parent.RefreshBlockModel(self) |
|
305 |
# If block has moved, refresh the model of wires connected to outputs |
|
306 |
if move: |
|
307 |
for output in self.Outputs: |
|
308 |
output.RefreshWires() |
|
309 |
||
310 |
# Draws block |
|
311 |
def Draw(self, dc): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
312 |
dc.SetPen(self.Pen) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
313 |
dc.SetBrush(wx.WHITE_BRUSH) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
314 |
dc.SetTextForeground(self.Colour) |
0 | 315 |
# Draw a rectangle with the block size |
316 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
317 |
# Draw block name and block type |
|
42 | 318 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
319 |
self.Pos.y - (self.NameSize[1] + 2)) |
|
320 |
dc.DrawText(self.Type, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2, |
|
0 | 321 |
self.Pos.y + 5) |
322 |
# Draw inputs and outputs connectors |
|
323 |
for input in self.Inputs: |
|
324 |
input.Draw(dc) |
|
325 |
for output in self.Outputs: |
|
326 |
output.Draw(dc) |
|
327 |
Graphic_Element.Draw(self, dc) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
328 |
dc.SetTextForeground(wx.BLACK) |
0 | 329 |
|
330 |
||
331 |
#------------------------------------------------------------------------------- |
|
332 |
# Function Block Diagram Variable |
|
333 |
#------------------------------------------------------------------------------- |
|
334 |
||
335 |
""" |
|
336 |
Class that implements the graphic representation of a variable |
|
337 |
""" |
|
338 |
||
339 |
class FBD_Variable(Graphic_Element): |
|
340 |
||
341 |
# Create a new variable |
|
342 |
def __init__(self, parent, type, name, value_type, id = None): |
|
343 |
Graphic_Element.__init__(self, parent) |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
344 |
self.Type = None |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
345 |
self.ValueType = None |
0 | 346 |
self.Name = name |
347 |
self.Id = id |
|
348 |
self.Input = None |
|
349 |
self.Output = None |
|
42 | 350 |
self.RefreshNameSize() |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
351 |
self.SetType(type, value_type) |
0 | 352 |
|
353 |
# Destructor |
|
354 |
def __del__(self): |
|
355 |
self.Input = None |
|
356 |
self.Output = None |
|
357 |
||
358 |
# Unconnect connector |
|
359 |
def Clean(self): |
|
360 |
if self.Input: |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
361 |
self.Input.UnConnect(delete = True) |
0 | 362 |
if self.Output: |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
363 |
self.Output.UnConnect(delete = True) |
0 | 364 |
|
365 |
# Delete this variable by calling the appropriate method |
|
366 |
def Delete(self): |
|
367 |
self.Parent.DeleteVariable(self) |
|
368 |
||
42 | 369 |
# Refresh the size of text for name |
370 |
def RefreshNameSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
371 |
dc = wx.ClientDC(self.Parent) |
42 | 372 |
self.NameSize = dc.GetTextExtent(self.Name) |
373 |
||
0 | 374 |
# Refresh the variable bounding box |
375 |
def RefreshBoundingBox(self): |
|
376 |
if self.Type in (OUTPUT, INOUT): |
|
377 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
378 |
else: |
|
379 |
bbx_x = self.Pos.x |
|
380 |
if self.Type == INOUT: |
|
381 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE |
|
382 |
else: |
|
383 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
384 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, self.Size[1] + 1) |
0 | 385 |
|
386 |
# Refresh the position of the variable connector |
|
387 |
def RefreshConnectors(self): |
|
388 |
if self.Input: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
389 |
self.Input.SetPosition(wx.Point(0, self.Size[1] / 2)) |
0 | 390 |
if self.Output: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
391 |
self.Output.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2)) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
392 |
self.RefreshConnected() |
0 | 393 |
|
394 |
# Refresh the position of wires connected to connector |
|
395 |
def RefreshConnected(self, exclude = []): |
|
396 |
if self.Input: |
|
397 |
self.Input.MoveConnected(exclude) |
|
398 |
if self.Output: |
|
399 |
self.Output.MoveConnected(exclude) |
|
400 |
||
401 |
# Test if point given is on the variable connector |
|
402 |
def TestConnector(self, pt, exclude=True): |
|
403 |
if self.Input and self.Input.TestPoint(pt, exclude): |
|
404 |
return self.Input |
|
405 |
if self.Output and self.Output.TestPoint(pt, exclude): |
|
406 |
return self.Output |
|
407 |
return None |
|
408 |
||
409 |
# Returns the block connector that starts with the point given if it exists |
|
27 | 410 |
def GetConnector(self, position, name = None): |
411 |
# if a name is given |
|
412 |
if name: |
|
413 |
# Test input and output connector if they exists |
|
414 |
if self.Input and name == self.Input.GetName(): |
|
415 |
return self.Input |
|
416 |
if self.Output and name == self.Output.GetName(): |
|
417 |
return self.Output |
|
0 | 418 |
# Test input connector if it exists |
419 |
if self.Input: |
|
420 |
input_pos = self.Input.GetRelPosition() |
|
421 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
422 |
return self.Input |
|
423 |
# Test output connector if it exists |
|
424 |
if self.Output: |
|
425 |
output_pos = self.Output.GetRelPosition() |
|
426 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
427 |
return self.Output |
|
428 |
return None |
|
429 |
||
430 |
# Returns all the block connectors |
|
431 |
def GetConnectors(self): |
|
432 |
return {"input" : self.Input, "output" : self.Output} |
|
433 |
||
434 |
# Changes the negated property of the variable connector if handled |
|
435 |
def SetConnectorNegated(self, negated): |
|
436 |
handle_type, handle = self.Handle |
|
437 |
if handle_type == HANDLE_CONNECTOR: |
|
438 |
handle.SetNegated(negated) |
|
439 |
self.RefreshModel(False) |
|
440 |
||
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
441 |
# Changes the variable type |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
442 |
def SetType(self, type, value_type): |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
443 |
if type != self.Type: |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
444 |
self.Type = type |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
445 |
self.Clean() |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
446 |
self.Input = None |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
447 |
self.Output = None |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
448 |
# Create an input or output connector according to variable type |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
449 |
if self.Type != INPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
450 |
self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
451 |
if self.Type != OUTPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
452 |
self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
453 |
self.RefreshConnectors() |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
454 |
elif value_type != self.ValueType: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
455 |
if self.Input: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
456 |
self.Input.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
457 |
if self.Output: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
458 |
self.Output.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
459 |
self.RefreshConnectors() |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
460 |
|
0 | 461 |
# Returns the variable type |
462 |
def GetType(self): |
|
463 |
return self.Type |
|
464 |
||
465 |
# Changes the variable name |
|
466 |
def SetName(self, name): |
|
467 |
self.Name = name |
|
42 | 468 |
self.RefreshNameSize() |
0 | 469 |
|
470 |
# Returns the variable name |
|
471 |
def GetName(self): |
|
472 |
return self.Name |
|
473 |
||
474 |
# Returns the variable minimum size |
|
475 |
def GetMinSize(self): |
|
42 | 476 |
return self.NameSize[0] + 10, self.NameSize[1] + 10 |
0 | 477 |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
478 |
# Method called when a LeftDClick event have been generated |
27 | 479 |
def OnLeftDClick(self, event, dc, scaling): |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
480 |
# Edit the variable properties |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
481 |
self.Parent.EditVariableContent(self) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
482 |
|
0 | 483 |
# Method called when a RightUp event have been generated |
27 | 484 |
def OnRightUp(self, event, dc, scaling): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
485 |
self.Parent.PopupDefaultMenu() |
0 | 486 |
|
487 |
# Refreshes the variable model |
|
488 |
def RefreshModel(self, move=True): |
|
489 |
self.Parent.RefreshVariableModel(self) |
|
490 |
# If variable has moved and variable is not of type OUTPUT, refresh the model |
|
491 |
# of wires connected to output connector |
|
492 |
if move and self.Type != OUTPUT: |
|
493 |
if self.Output: |
|
494 |
self.Output.RefreshWires() |
|
495 |
||
496 |
# Draws variable |
|
497 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
498 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
499 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 500 |
# Draw a rectangle with the variable size |
501 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
502 |
# Draw variable name |
|
42 | 503 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
504 |
self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2) |
|
0 | 505 |
# Draw connectors |
506 |
if self.Input: |
|
507 |
self.Input.Draw(dc) |
|
508 |
if self.Output: |
|
509 |
self.Output.Draw(dc) |
|
510 |
Graphic_Element.Draw(self, dc) |
|
511 |
||
512 |
||
513 |
#------------------------------------------------------------------------------- |
|
514 |
# Function Block Diagram Connector |
|
515 |
#------------------------------------------------------------------------------- |
|
516 |
||
517 |
""" |
|
518 |
Class that implements the graphic representation of a connection |
|
519 |
""" |
|
520 |
||
521 |
class FBD_Connector(Graphic_Element): |
|
522 |
||
523 |
# Create a new connection |
|
524 |
def __init__(self, parent, type, name, id = None): |
|
525 |
Graphic_Element.__init__(self, parent) |
|
526 |
self.Type = type |
|
527 |
self.Name = name |
|
528 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
529 |
self.Pos = wx.Point(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
530 |
self.Size = wx.Size(0, 0) |
0 | 531 |
# Create an input or output connector according to connection type |
532 |
if self.Type == CONNECTOR: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
533 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
534 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
535 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
0 | 536 |
self.RefreshConnectors() |
42 | 537 |
self.RefreshNameSize() |
0 | 538 |
|
539 |
# Destructor |
|
540 |
def __del__(self): |
|
541 |
self.Connector = None |
|
542 |
||
543 |
# Unconnect connector |
|
544 |
def Clean(self): |
|
545 |
if self.Connector: |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
546 |
self.Connector.UnConnect(delete = True) |
0 | 547 |
|
548 |
# Delete this connection by calling the appropriate method |
|
549 |
def Delete(self): |
|
550 |
self.Parent.DeleteConnection(self) |
|
551 |
||
42 | 552 |
# Refresh the size of text for name |
553 |
def RefreshNameSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
554 |
dc = wx.ClientDC(self.Parent) |
42 | 555 |
self.NameSize = dc.GetTextExtent(self.Name) |
556 |
||
0 | 557 |
# Refresh the connection bounding box |
558 |
def RefreshBoundingBox(self): |
|
559 |
if self.Type == CONNECTOR: |
|
560 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
561 |
else: |
|
562 |
bbx_x = self.Pos.x |
|
563 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
564 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
0 | 565 |
|
566 |
# Refresh the position of the connection connector |
|
567 |
def RefreshConnectors(self): |
|
568 |
if self.Type == CONNECTOR: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
569 |
self.Connector.SetPosition(wx.Point(0, self.Size[1] / 2)) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
570 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
571 |
self.Connector.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2)) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
572 |
self.RefreshConnected() |
0 | 573 |
|
574 |
# Refresh the position of wires connected to connector |
|
575 |
def RefreshConnected(self, exclude = []): |
|
576 |
if self.Connector: |
|
577 |
self.Connector.MoveConnected(exclude) |
|
578 |
||
579 |
# Test if point given is on the connection connector |
|
580 |
def TestConnector(self, pt, exclude=True): |
|
581 |
if self.Connector and self.Connector.TestPoint(pt, exclude): |
|
582 |
return self.Connector |
|
583 |
return None |
|
584 |
||
585 |
# Returns the connection connector |
|
27 | 586 |
def GetConnector(self, position = None, name = None): |
0 | 587 |
return self.Connector |
588 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
589 |
# Changes the variable type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
590 |
def SetType(self, type): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
591 |
if type != self.Type: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
592 |
self.Type = type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
593 |
self.Clean() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
594 |
# Create an input or output connector according to connection type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
595 |
if self.Type == CONNECTOR: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
596 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
597 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
598 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
599 |
self.RefreshConnectors() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
600 |
|
0 | 601 |
# Returns the connection type |
602 |
def GetType(self): |
|
603 |
return self.Type |
|
604 |
||
605 |
# Changes the connection name |
|
606 |
def SetName(self, name): |
|
607 |
self.Name = name |
|
42 | 608 |
self.RefreshNameSize() |
0 | 609 |
|
610 |
# Returns the connection name |
|
611 |
def GetName(self): |
|
612 |
return self.Name |
|
613 |
||
614 |
# Returns the connection minimum size |
|
615 |
def GetMinSize(self): |
|
42 | 616 |
text_width, text_height = self.NameSize |
0 | 617 |
if text_height % 2 == 1: |
618 |
text_height += 1 |
|
619 |
return text_width + text_height + 20, text_height + 10 |
|
620 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
621 |
# Method called when a LeftDClick event have been generated |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
622 |
def OnLeftDClick(self, event, dc, scaling): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
623 |
# Edit the connection properties |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
624 |
self.Parent.EditConnectionContent(self) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
625 |
|
0 | 626 |
# Method called when a RightUp event have been generated |
27 | 627 |
def OnRightUp(self, event, dc, scaling): |
0 | 628 |
# Popup the default menu |
629 |
self.Parent.PopupDefaultMenu() |
|
630 |
||
631 |
# Refreshes the connection model |
|
632 |
def RefreshModel(self, move=True): |
|
633 |
self.Parent.RefreshConnectionModel(self) |
|
634 |
# If connection has moved and connection is of type CONTINUATION, refresh |
|
635 |
# the model of wires connected to connector |
|
636 |
if move and self.Type == CONTINUATION: |
|
637 |
if self.Connector: |
|
638 |
self.Connector.RefreshWires() |
|
639 |
||
640 |
# Draws connection |
|
641 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
642 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
643 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 644 |
# Draw a rectangle with the connection size with arrows in |
645 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
42 | 646 |
arrowsize = min(self.Size[1] / 2, (self.Size[0] - self.NameSize[0] - 10) / 2) |
0 | 647 |
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
648 |
self.Pos.y + self.Size[1] / 2) |
|
649 |
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, |
|
650 |
self.Pos.x, self.Pos.y + self.Size[1]) |
|
651 |
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
|
652 |
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) |
|
653 |
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, |
|
654 |
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) |
|
655 |
# Draw variable name |
|
42 | 656 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
657 |
self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2) |
|
0 | 658 |
# Draw connector |
659 |
if self.Connector: |
|
660 |
self.Connector.Draw(dc) |
|
661 |
Graphic_Element.Draw(self, dc) |