author | etisserant |
Tue, 02 Oct 2007 18:00:13 +0200 | |
changeset 101 | 3f06a178b960 |
parent 99 | 2b18a72dcaf0 |
child 102 | 85875dcb7754 |
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 |
|
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
141 |
def GetConnectionResultType(self, connector): |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
142 |
resulttype = None |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
143 |
for input in self.Inputs: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
144 |
name = input.GetName() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
145 |
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
|
146 |
inputtype = input.GetConnectedType() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
147 |
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
|
148 |
resulttype = inputtype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
149 |
for output in self.Outputs: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
150 |
name = output.GetName() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
151 |
if output != connector and name == "OUT": |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
152 |
outputtype = output.GetConnectedType() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
153 |
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
|
154 |
resulttype = outputtype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
155 |
return resulttype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
156 |
|
0 | 157 |
# Returns all the block connectors |
158 |
def GetConnectors(self): |
|
159 |
return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
|
160 |
||
161 |
# 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
|
162 |
def TestConnector(self, pt, exclude = True): |
0 | 163 |
# Test each input connector |
164 |
for input in self.Inputs: |
|
165 |
if input.TestPoint(pt, exclude): |
|
166 |
return input |
|
167 |
# Test each output connector |
|
168 |
for output in self.Outputs: |
|
169 |
if output.TestPoint(pt, exclude): |
|
170 |
return output |
|
171 |
return None |
|
172 |
||
2 | 173 |
# Changes the block type |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
174 |
def SetType(self, type, extension, inputs = None, connectors = {}): |
27 | 175 |
if type != self.Type or self.Extension != extension: |
42 | 176 |
if type != self.Type: |
177 |
self.Type = type |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
178 |
dc = wx.ClientDC(self.Parent) |
42 | 179 |
self.TypeSize = dc.GetTextExtent(self.Type) |
27 | 180 |
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
|
181 |
# 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
|
182 |
# inputs and outputs |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
183 |
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
|
184 |
if blocktype: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
start += 1 |
27 | 192 |
inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) |
16 | 193 |
else: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
194 |
self.Colour = wx.RED |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
195 |
if "inputs" in connectors: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
196 |
inputs = connectors["inputs"] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
197 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
198 |
inputs = [] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
199 |
if "outputs" in connectors: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
200 |
outputs = connectors["outputs"] |
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 |
outputs = [] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
# 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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
# 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
|
215 |
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
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
self.Outputs.append(connector) |
42 | 223 |
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
|
224 |
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
|
225 |
self.RefreshBoundingBox() |
2 | 226 |
|
0 | 227 |
# Returns the block type |
228 |
def GetType(self): |
|
229 |
return self.Type |
|
230 |
||
231 |
# Changes the block name |
|
232 |
def SetName(self, name): |
|
233 |
self.Name = name |
|
42 | 234 |
self.RefreshNameSize() |
0 | 235 |
|
236 |
# Returs the block name |
|
237 |
def GetName(self): |
|
238 |
return self.Name |
|
239 |
||
2 | 240 |
# Changes the extension name |
241 |
def SetExtension(self, extension): |
|
242 |
self.Extension = extension |
|
243 |
||
244 |
# Returs the extension name |
|
245 |
def GetExtension(self): |
|
246 |
return self.Extension |
|
247 |
||
42 | 248 |
# Refresh the block minimum size |
249 |
def RefreshMinSize(self): |
|
0 | 250 |
# Calculate the inputs maximum width |
251 |
max_input = 0 |
|
252 |
for input in self.Inputs: |
|
42 | 253 |
w, h = input.GetNameSize() |
0 | 254 |
max_input = max(max_input, w) |
255 |
# Calculate the outputs maximum width |
|
256 |
max_output = 0 |
|
257 |
for output in self.Outputs: |
|
42 | 258 |
w, h = output.GetNameSize() |
0 | 259 |
max_output = max(max_output, w) |
42 | 260 |
width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
0 | 261 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
42 | 262 |
self.MinSize = width, height |
263 |
||
264 |
# Returns the block minimum size |
|
265 |
def GetMinSize(self): |
|
266 |
return self.MinSize |
|
0 | 267 |
|
268 |
# Changes the negated property of the connector handled |
|
269 |
def SetConnectorNegated(self, negated): |
|
270 |
handle_type, handle = self.Handle |
|
271 |
if handle_type == HANDLE_CONNECTOR: |
|
272 |
handle.SetNegated(negated) |
|
273 |
self.RefreshModel(False) |
|
274 |
||
275 |
# Changes the edge property of the connector handled |
|
276 |
def SetConnectorEdge(self, edge): |
|
277 |
handle_type, handle = self.Handle |
|
278 |
if handle_type == HANDLE_CONNECTOR: |
|
279 |
handle.SetEdge(edge) |
|
280 |
self.RefreshModel(False) |
|
281 |
||
2 | 282 |
# Method called when a LeftDClick event have been generated |
27 | 283 |
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
|
284 |
# Edit the block properties |
2 | 285 |
self.Parent.EditBlockContent(self) |
286 |
||
0 | 287 |
# Method called when a RightUp event have been generated |
27 | 288 |
def OnRightUp(self, event, dc, scaling): |
289 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 290 |
# Popup the menu with special items for a block and a connector if one is handled |
291 |
connector = self.TestConnector(pos, False) |
|
292 |
if connector: |
|
293 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
294 |
self.Parent.PopupBlockMenu(connector) |
|
295 |
else: |
|
296 |
self.Parent.PopupBlockMenu() |
|
297 |
||
298 |
# Refreshes the block model |
|
299 |
def RefreshModel(self, move=True): |
|
300 |
self.Parent.RefreshBlockModel(self) |
|
301 |
# If block has moved, refresh the model of wires connected to outputs |
|
302 |
if move: |
|
303 |
for output in self.Outputs: |
|
304 |
output.RefreshWires() |
|
305 |
||
306 |
# Draws block |
|
307 |
def Draw(self, dc): |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
308 |
dc.SetPen(self.Pen) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
309 |
dc.SetBrush(wx.WHITE_BRUSH) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
310 |
dc.SetTextForeground(self.Colour) |
0 | 311 |
# Draw a rectangle with the block size |
312 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
313 |
# Draw block name and block type |
|
42 | 314 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
315 |
self.Pos.y - (self.NameSize[1] + 2)) |
|
316 |
dc.DrawText(self.Type, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2, |
|
0 | 317 |
self.Pos.y + 5) |
318 |
# Draw inputs and outputs connectors |
|
319 |
for input in self.Inputs: |
|
320 |
input.Draw(dc) |
|
321 |
for output in self.Outputs: |
|
322 |
output.Draw(dc) |
|
323 |
Graphic_Element.Draw(self, dc) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
324 |
dc.SetTextForeground(wx.BLACK) |
0 | 325 |
|
326 |
||
327 |
#------------------------------------------------------------------------------- |
|
328 |
# Function Block Diagram Variable |
|
329 |
#------------------------------------------------------------------------------- |
|
330 |
||
331 |
""" |
|
332 |
Class that implements the graphic representation of a variable |
|
333 |
""" |
|
334 |
||
335 |
class FBD_Variable(Graphic_Element): |
|
336 |
||
337 |
# Create a new variable |
|
338 |
def __init__(self, parent, type, name, value_type, id = None): |
|
339 |
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
|
340 |
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
|
341 |
self.ValueType = None |
0 | 342 |
self.Name = name |
343 |
self.Id = id |
|
344 |
self.Input = None |
|
345 |
self.Output = None |
|
42 | 346 |
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
|
347 |
self.SetType(type, value_type) |
0 | 348 |
|
349 |
# Destructor |
|
350 |
def __del__(self): |
|
351 |
self.Input = None |
|
352 |
self.Output = None |
|
353 |
||
354 |
# Unconnect connector |
|
355 |
def Clean(self): |
|
356 |
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
|
357 |
self.Input.UnConnect(delete = True) |
0 | 358 |
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
|
359 |
self.Output.UnConnect(delete = True) |
0 | 360 |
|
361 |
# Delete this variable by calling the appropriate method |
|
362 |
def Delete(self): |
|
363 |
self.Parent.DeleteVariable(self) |
|
364 |
||
42 | 365 |
# Refresh the size of text for name |
366 |
def RefreshNameSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
367 |
dc = wx.ClientDC(self.Parent) |
42 | 368 |
self.NameSize = dc.GetTextExtent(self.Name) |
369 |
||
0 | 370 |
# Refresh the variable bounding box |
371 |
def RefreshBoundingBox(self): |
|
372 |
if self.Type in (OUTPUT, INOUT): |
|
373 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
374 |
else: |
|
375 |
bbx_x = self.Pos.x |
|
376 |
if self.Type == INOUT: |
|
377 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE |
|
378 |
else: |
|
379 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
380 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, self.Size[1] + 1) |
0 | 381 |
|
382 |
# Refresh the position of the variable connector |
|
383 |
def RefreshConnectors(self): |
|
384 |
if self.Input: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
385 |
self.Input.SetPosition(wx.Point(0, self.Size[1] / 2)) |
0 | 386 |
if self.Output: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
387 |
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
|
388 |
self.RefreshConnected() |
0 | 389 |
|
390 |
# Refresh the position of wires connected to connector |
|
391 |
def RefreshConnected(self, exclude = []): |
|
392 |
if self.Input: |
|
393 |
self.Input.MoveConnected(exclude) |
|
394 |
if self.Output: |
|
395 |
self.Output.MoveConnected(exclude) |
|
396 |
||
397 |
# Test if point given is on the variable connector |
|
398 |
def TestConnector(self, pt, exclude=True): |
|
399 |
if self.Input and self.Input.TestPoint(pt, exclude): |
|
400 |
return self.Input |
|
401 |
if self.Output and self.Output.TestPoint(pt, exclude): |
|
402 |
return self.Output |
|
403 |
return None |
|
404 |
||
405 |
# Returns the block connector that starts with the point given if it exists |
|
27 | 406 |
def GetConnector(self, position, name = None): |
407 |
# if a name is given |
|
408 |
if name: |
|
409 |
# Test input and output connector if they exists |
|
410 |
if self.Input and name == self.Input.GetName(): |
|
411 |
return self.Input |
|
412 |
if self.Output and name == self.Output.GetName(): |
|
413 |
return self.Output |
|
0 | 414 |
# Test input connector if it exists |
415 |
if self.Input: |
|
416 |
input_pos = self.Input.GetRelPosition() |
|
417 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
418 |
return self.Input |
|
419 |
# Test output connector if it exists |
|
420 |
if self.Output: |
|
421 |
output_pos = self.Output.GetRelPosition() |
|
422 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
423 |
return self.Output |
|
424 |
return None |
|
425 |
||
426 |
# Returns all the block connectors |
|
427 |
def GetConnectors(self): |
|
428 |
return {"input" : self.Input, "output" : self.Output} |
|
429 |
||
430 |
# Changes the negated property of the variable connector if handled |
|
431 |
def SetConnectorNegated(self, negated): |
|
432 |
handle_type, handle = self.Handle |
|
433 |
if handle_type == HANDLE_CONNECTOR: |
|
434 |
handle.SetNegated(negated) |
|
435 |
self.RefreshModel(False) |
|
436 |
||
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
437 |
# 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
|
438 |
def SetType(self, type, value_type): |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
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
|
443 |
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
|
444 |
# 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
|
445 |
if self.Type != INPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
446 |
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
|
447 |
if self.Type != OUTPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
448 |
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
|
449 |
self.RefreshConnectors() |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
450 |
elif value_type != self.ValueType: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
451 |
if self.Input: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
452 |
self.Input.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
453 |
if self.Output: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
454 |
self.Output.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
455 |
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
|
456 |
|
0 | 457 |
# Returns the variable type |
458 |
def GetType(self): |
|
459 |
return self.Type |
|
460 |
||
461 |
# Changes the variable name |
|
462 |
def SetName(self, name): |
|
463 |
self.Name = name |
|
42 | 464 |
self.RefreshNameSize() |
0 | 465 |
|
466 |
# Returns the variable name |
|
467 |
def GetName(self): |
|
468 |
return self.Name |
|
469 |
||
470 |
# Returns the variable minimum size |
|
471 |
def GetMinSize(self): |
|
42 | 472 |
return self.NameSize[0] + 10, self.NameSize[1] + 10 |
0 | 473 |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
474 |
# Method called when a LeftDClick event have been generated |
27 | 475 |
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
|
476 |
# 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
|
477 |
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
|
478 |
|
0 | 479 |
# Method called when a RightUp event have been generated |
27 | 480 |
def OnRightUp(self, event, dc, scaling): |
481 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 482 |
# Popup the menu with special items for a variable and a connector if it's handled |
27 | 483 |
connector = self.TestConnector(pos, False) |
0 | 484 |
if connector: |
485 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
486 |
self.Parent.PopupVariableMenu(connector) |
|
487 |
else: |
|
488 |
self.Parent.PopupVariableMenu() |
|
489 |
||
490 |
# Refreshes the variable model |
|
491 |
def RefreshModel(self, move=True): |
|
492 |
self.Parent.RefreshVariableModel(self) |
|
493 |
# If variable has moved and variable is not of type OUTPUT, refresh the model |
|
494 |
# of wires connected to output connector |
|
495 |
if move and self.Type != OUTPUT: |
|
496 |
if self.Output: |
|
497 |
self.Output.RefreshWires() |
|
498 |
||
499 |
# Draws variable |
|
500 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
501 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
502 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 503 |
# Draw a rectangle with the variable size |
504 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
505 |
# Draw variable name |
|
42 | 506 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
507 |
self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2) |
|
0 | 508 |
# Draw connectors |
509 |
if self.Input: |
|
510 |
self.Input.Draw(dc) |
|
511 |
if self.Output: |
|
512 |
self.Output.Draw(dc) |
|
513 |
Graphic_Element.Draw(self, dc) |
|
514 |
||
515 |
||
516 |
#------------------------------------------------------------------------------- |
|
517 |
# Function Block Diagram Connector |
|
518 |
#------------------------------------------------------------------------------- |
|
519 |
||
520 |
""" |
|
521 |
Class that implements the graphic representation of a connection |
|
522 |
""" |
|
523 |
||
524 |
class FBD_Connector(Graphic_Element): |
|
525 |
||
526 |
# Create a new connection |
|
527 |
def __init__(self, parent, type, name, id = None): |
|
528 |
Graphic_Element.__init__(self, parent) |
|
529 |
self.Type = type |
|
530 |
self.Name = name |
|
531 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
532 |
self.Pos = wx.Point(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
533 |
self.Size = wx.Size(0, 0) |
0 | 534 |
# Create an input or output connector according to connection type |
535 |
if self.Type == CONNECTOR: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
536 |
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
|
537 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
538 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
0 | 539 |
self.RefreshConnectors() |
42 | 540 |
self.RefreshNameSize() |
0 | 541 |
|
542 |
# Destructor |
|
543 |
def __del__(self): |
|
544 |
self.Connector = None |
|
545 |
||
546 |
# Unconnect connector |
|
547 |
def Clean(self): |
|
548 |
if self.Connector: |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
549 |
self.Connector.UnConnect(delete = True) |
0 | 550 |
|
551 |
# Delete this connection by calling the appropriate method |
|
552 |
def Delete(self): |
|
553 |
self.Parent.DeleteConnection(self) |
|
554 |
||
42 | 555 |
# Refresh the size of text for name |
556 |
def RefreshNameSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
557 |
dc = wx.ClientDC(self.Parent) |
42 | 558 |
self.NameSize = dc.GetTextExtent(self.Name) |
559 |
||
0 | 560 |
# Refresh the connection bounding box |
561 |
def RefreshBoundingBox(self): |
|
562 |
if self.Type == CONNECTOR: |
|
563 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
564 |
else: |
|
565 |
bbx_x = self.Pos.x |
|
566 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
567 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
0 | 568 |
|
569 |
# Refresh the position of the connection connector |
|
570 |
def RefreshConnectors(self): |
|
571 |
if self.Type == CONNECTOR: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
572 |
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
|
573 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
574 |
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
|
575 |
self.RefreshConnected() |
0 | 576 |
|
577 |
# Refresh the position of wires connected to connector |
|
578 |
def RefreshConnected(self, exclude = []): |
|
579 |
if self.Connector: |
|
580 |
self.Connector.MoveConnected(exclude) |
|
581 |
||
582 |
# Test if point given is on the connection connector |
|
583 |
def TestConnector(self, pt, exclude=True): |
|
584 |
if self.Connector and self.Connector.TestPoint(pt, exclude): |
|
585 |
return self.Connector |
|
586 |
return None |
|
587 |
||
588 |
# Returns the connection connector |
|
27 | 589 |
def GetConnector(self, position = None, name = None): |
0 | 590 |
return self.Connector |
591 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
592 |
# Changes the variable type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
593 |
def SetType(self, type): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
594 |
if type != self.Type: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
595 |
self.Type = type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
596 |
self.Clean() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
597 |
# Create an input or output connector according to connection type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
598 |
if self.Type == CONNECTOR: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
599 |
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
|
600 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
601 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
602 |
self.RefreshConnectors() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
603 |
|
0 | 604 |
# Returns the connection type |
605 |
def GetType(self): |
|
606 |
return self.Type |
|
607 |
||
608 |
# Changes the connection name |
|
609 |
def SetName(self, name): |
|
610 |
self.Name = name |
|
42 | 611 |
self.RefreshNameSize() |
0 | 612 |
|
613 |
# Returns the connection name |
|
614 |
def GetName(self): |
|
615 |
return self.Name |
|
616 |
||
617 |
# Returns the connection minimum size |
|
618 |
def GetMinSize(self): |
|
42 | 619 |
text_width, text_height = self.NameSize |
0 | 620 |
if text_height % 2 == 1: |
621 |
text_height += 1 |
|
622 |
return text_width + text_height + 20, text_height + 10 |
|
623 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
624 |
# Method called when a LeftDClick event have been generated |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
625 |
def OnLeftDClick(self, event, dc, scaling): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
626 |
# Edit the connection properties |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
627 |
self.Parent.EditConnectionContent(self) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
628 |
|
0 | 629 |
# Method called when a RightUp event have been generated |
27 | 630 |
def OnRightUp(self, event, dc, scaling): |
0 | 631 |
# Popup the default menu |
632 |
self.Parent.PopupDefaultMenu() |
|
633 |
||
634 |
# Refreshes the connection model |
|
635 |
def RefreshModel(self, move=True): |
|
636 |
self.Parent.RefreshConnectionModel(self) |
|
637 |
# If connection has moved and connection is of type CONTINUATION, refresh |
|
638 |
# the model of wires connected to connector |
|
639 |
if move and self.Type == CONTINUATION: |
|
640 |
if self.Connector: |
|
641 |
self.Connector.RefreshWires() |
|
642 |
||
643 |
# Draws connection |
|
644 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
645 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
646 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 647 |
# Draw a rectangle with the connection size with arrows in |
648 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
42 | 649 |
arrowsize = min(self.Size[1] / 2, (self.Size[0] - self.NameSize[0] - 10) / 2) |
0 | 650 |
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
651 |
self.Pos.y + self.Size[1] / 2) |
|
652 |
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, |
|
653 |
self.Pos.x, self.Pos.y + self.Size[1]) |
|
654 |
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
|
655 |
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) |
|
656 |
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, |
|
657 |
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) |
|
658 |
# Draw variable name |
|
42 | 659 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
660 |
self.Pos.y + (self.Size[1] - self.NameSize[1]) / 2) |
|
0 | 661 |
# Draw connector |
662 |
if self.Connector: |
|
663 |
self.Connector.Draw(dc) |
|
664 |
Graphic_Element.Draw(self, dc) |