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