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 |
#
|
|
7 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD
|
|
8 |
#
|
|
9 |
#See COPYING file for copyrights details.
|
|
10 |
#
|
|
11 |
#This library is free software; you can redistribute it and/or
|
|
12 |
#modify it under the terms of the GNU Lesser General Public
|
|
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
|
|
19 |
#Lesser General Public License for more details.
|
|
20 |
#
|
|
21 |
#You should have received a copy of the GNU Lesser General Public
|
|
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 |
from wxPython.wx import *
|
|
26 |
import wx
|
|
27 |
|
|
28 |
from GraphicCommons import *
|
|
29 |
from plcopen.structures import *
|
|
30 |
|
|
31 |
|
|
32 |
#-------------------------------------------------------------------------------
|
|
33 |
# Function Block Diagram Block
|
|
34 |
#-------------------------------------------------------------------------------
|
|
35 |
|
|
36 |
"""
|
|
37 |
Class that implements the graphic representation of a function block
|
|
38 |
"""
|
|
39 |
|
|
40 |
class FBD_Block(Graphic_Element):
|
|
41 |
|
|
42 |
# Create a new block
|
|
43 |
def __init__(self, parent, type, name, id = None, extension = 0, inputs = [], outputs = []):
|
|
44 |
Graphic_Element.__init__(self, parent)
|
|
45 |
self.Name = name
|
|
46 |
self.Id = id
|
2
|
47 |
self.Extension = extension
|
|
48 |
self.Inputs = []
|
|
49 |
self.Outputs = []
|
|
50 |
self.SetType(type)
|
0
|
51 |
|
|
52 |
# Destructor
|
|
53 |
def __del__(self):
|
|
54 |
self.Inputs = []
|
|
55 |
self.Outputs = []
|
|
56 |
|
|
57 |
# Delete this block by calling the appropriate method
|
|
58 |
def Delete(self):
|
|
59 |
self.Parent.DeleteBlock(self)
|
|
60 |
|
|
61 |
# Unconnect all inputs and outputs
|
|
62 |
def Clean(self):
|
|
63 |
for input in self.Inputs:
|
2
|
64 |
input.UnConnect(delete = True)
|
|
65 |
for output in self.Outputs:
|
|
66 |
output.UnConnect(delete = True)
|
0
|
67 |
|
|
68 |
# Refresh the block bounding box
|
|
69 |
def RefreshBoundingBox(self):
|
|
70 |
dc = wxClientDC(self.Parent)
|
|
71 |
# Calculate the size of the name outside the block
|
|
72 |
text_width, text_height = dc.GetTextExtent(self.Name)
|
|
73 |
# Calculate the bounding box size
|
|
74 |
bbx_x = self.Pos.x - max(min(1, len(self.Inputs)) * CONNECTOR_SIZE, (text_width - self.Size[0]) / 2)
|
|
75 |
bbx_width = self.Size[0] + 1 + (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE
|
|
76 |
if self.Name != "":
|
|
77 |
bbx_y = self.Pos.y - (text_height + 2)
|
|
78 |
bbx_height = self.Size[1] + (text_height + 2)
|
|
79 |
else:
|
|
80 |
bbx_y = self.Pos.y
|
|
81 |
bbx_height = self.Size[1]
|
|
82 |
self.BoundingBox = wxRect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
|
|
83 |
|
|
84 |
# Refresh the positions of the block connectors
|
|
85 |
def RefreshConnectors(self):
|
|
86 |
# Calculate the size for the connector lines
|
|
87 |
lines = max(len(self.Inputs), len(self.Outputs))
|
|
88 |
linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE)
|
|
89 |
# Update inputs positions
|
|
90 |
position = BLOCK_LINE_SIZE + linesize / 2
|
|
91 |
for input in self.Inputs:
|
|
92 |
input.SetPosition(wxPoint(0, position))
|
|
93 |
position += linesize
|
|
94 |
# Update outputs positions
|
|
95 |
position = BLOCK_LINE_SIZE + linesize / 2
|
|
96 |
for output in self.Outputs:
|
|
97 |
output.SetPosition(wxPoint(self.Size[0], position))
|
|
98 |
position += linesize
|
|
99 |
self.RefreshConnected()
|
|
100 |
|
|
101 |
# Refresh the positions of wires connected to inputs and outputs
|
|
102 |
def RefreshConnected(self, exclude = []):
|
|
103 |
for input in self.Inputs:
|
|
104 |
input.MoveConnected(exclude)
|
|
105 |
for output in self.Outputs:
|
|
106 |
output.MoveConnected(exclude)
|
|
107 |
|
|
108 |
# Returns the block connector that starts with the point given if it exists
|
|
109 |
def GetConnector(self, position):
|
|
110 |
# Test each input connector
|
|
111 |
for input in self.Inputs:
|
|
112 |
input_pos = input.GetRelPosition()
|
|
113 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
|
|
114 |
return input
|
|
115 |
# Test each output connector
|
|
116 |
for output in self.Outputs:
|
|
117 |
output_pos = output.GetRelPosition()
|
|
118 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y:
|
|
119 |
return output
|
|
120 |
return None
|
|
121 |
|
|
122 |
# Returns all the block connectors
|
|
123 |
def GetConnectors(self):
|
|
124 |
return {"inputs" : self.Inputs, "outputs" : self.Outputs}
|
|
125 |
|
|
126 |
# Test if point given is on one of the block connectors
|
|
127 |
def TestConnector(self, pt, exclude=True):
|
|
128 |
# Test each input connector
|
|
129 |
for input in self.Inputs:
|
|
130 |
if input.TestPoint(pt, exclude):
|
|
131 |
return input
|
|
132 |
# Test each output connector
|
|
133 |
for output in self.Outputs:
|
|
134 |
if output.TestPoint(pt, exclude):
|
|
135 |
return output
|
|
136 |
return None
|
|
137 |
|
2
|
138 |
# Changes the block type
|
|
139 |
def SetType(self, type):
|
|
140 |
self.Type = type
|
|
141 |
# Find the block definition from type given and create the corresponding
|
|
142 |
# inputs and outputs
|
|
143 |
blocktype = GetBlockType(type)
|
|
144 |
if blocktype:
|
|
145 |
inputs = [input for input in blocktype["inputs"]]
|
|
146 |
outputs = [output for output in blocktype["outputs"]]
|
|
147 |
if blocktype["extensible"]:
|
|
148 |
start = int(inputs[-1][0].replace("IN", ""))
|
|
149 |
for i in xrange(self.Extension - len(blocktype["inputs"])):
|
|
150 |
start += 1
|
|
151 |
inputs.append(("IN%d"%start, inputs[-1][1], input[-1][2]))
|
|
152 |
self.SetConnectors(inputs, outputs)
|
|
153 |
|
0
|
154 |
# Returns the block type
|
|
155 |
def GetType(self):
|
|
156 |
return self.Type
|
|
157 |
|
|
158 |
# Changes the block name
|
|
159 |
def SetName(self, name):
|
|
160 |
self.Name = name
|
|
161 |
|
|
162 |
# Returs the block name
|
|
163 |
def GetName(self):
|
|
164 |
return self.Name
|
|
165 |
|
2
|
166 |
# Changes the extension name
|
|
167 |
def SetExtension(self, extension):
|
|
168 |
self.Extension = extension
|
|
169 |
|
|
170 |
# Returs the extension name
|
|
171 |
def GetExtension(self):
|
|
172 |
return self.Extension
|
|
173 |
|
0
|
174 |
# Returns the block minimum size
|
|
175 |
def GetMinSize(self):
|
|
176 |
dc = wxClientDC(self.Parent)
|
|
177 |
text_width, text_height = dc.GetTextExtent(self.Type)
|
|
178 |
# Calculate the inputs maximum width
|
|
179 |
max_input = 0
|
|
180 |
for input in self.Inputs:
|
|
181 |
w, h = dc.GetTextExtent(input.GetName())
|
|
182 |
max_input = max(max_input, w)
|
|
183 |
# Calculate the outputs maximum width
|
|
184 |
max_output = 0
|
|
185 |
for output in self.Outputs:
|
|
186 |
w, h = dc.GetTextExtent(output.GetName())
|
|
187 |
max_output = max(max_output, w)
|
|
188 |
width = max(text_width + 10, max_input + max_output + 15)
|
|
189 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE
|
|
190 |
return width, height
|
|
191 |
|
|
192 |
# Changes the block connectors
|
|
193 |
def SetConnectors(self, inputs, outputs):
|
2
|
194 |
self.Clean()
|
0
|
195 |
# Extract the inputs properties and create the corresponding connector
|
|
196 |
self.Inputs = []
|
|
197 |
for input_name, input_type, input_modifier in inputs:
|
|
198 |
connector = Connector(self, input_name, input_type, wxPoint(0, 0), WEST)
|
|
199 |
if input_modifier == "negated":
|
|
200 |
connector.SetNegated(True)
|
|
201 |
elif input_modifier != "none":
|
|
202 |
connector.SetEdge(input_modifier)
|
|
203 |
self.Inputs.append(connector)
|
|
204 |
# Extract the outputs properties and create the corresponding connector
|
|
205 |
self.Outputs = []
|
|
206 |
for output_name, output_type, output_modifier in outputs:
|
|
207 |
connector = Connector(self, output_name, output_type, wxPoint(0, 0), EAST)
|
|
208 |
if output_modifier == "negated":
|
|
209 |
connector.SetNegated(True)
|
|
210 |
elif output_modifier != "none":
|
|
211 |
connector.SetEdge(output_modifier)
|
|
212 |
self.Outputs.append(connector)
|
2
|
213 |
self.RefreshConnectors()
|
0
|
214 |
self.RefreshBoundingBox()
|
|
215 |
|
|
216 |
# Changes the negated property of the connector handled
|
|
217 |
def SetConnectorNegated(self, negated):
|
|
218 |
handle_type, handle = self.Handle
|
|
219 |
if handle_type == HANDLE_CONNECTOR:
|
|
220 |
handle.SetNegated(negated)
|
|
221 |
self.RefreshModel(False)
|
|
222 |
|
|
223 |
# Changes the edge property of the connector handled
|
|
224 |
def SetConnectorEdge(self, edge):
|
|
225 |
handle_type, handle = self.Handle
|
|
226 |
if handle_type == HANDLE_CONNECTOR:
|
|
227 |
handle.SetEdge(edge)
|
|
228 |
self.RefreshModel(False)
|
|
229 |
|
2
|
230 |
# Method called when a LeftDClick event have been generated
|
|
231 |
def OnLeftDClick(self, event, scaling):
|
|
232 |
# Edit the step properties
|
|
233 |
self.Parent.EditBlockContent(self)
|
|
234 |
|
0
|
235 |
# Method called when a RightUp event have been generated
|
|
236 |
def OnRightUp(self, event, scaling):
|
|
237 |
pos = GetScaledEventPosition(event, scaling)
|
|
238 |
# Popup the menu with special items for a block and a connector if one is handled
|
|
239 |
connector = self.TestConnector(pos, False)
|
|
240 |
if connector:
|
|
241 |
self.Handle = (HANDLE_CONNECTOR, connector)
|
|
242 |
self.Parent.PopupBlockMenu(connector)
|
|
243 |
else:
|
|
244 |
self.Parent.PopupBlockMenu()
|
|
245 |
|
|
246 |
# Refreshes the block model
|
|
247 |
def RefreshModel(self, move=True):
|
|
248 |
self.Parent.RefreshBlockModel(self)
|
|
249 |
# If block has moved, refresh the model of wires connected to outputs
|
|
250 |
if move:
|
|
251 |
for output in self.Outputs:
|
|
252 |
output.RefreshWires()
|
|
253 |
|
|
254 |
# Draws block
|
|
255 |
def Draw(self, dc):
|
|
256 |
dc.SetPen(wxBLACK_PEN)
|
|
257 |
dc.SetBrush(wxWHITE_BRUSH)
|
|
258 |
# Draw a rectangle with the block size
|
|
259 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
|
|
260 |
# Draw block name and block type
|
|
261 |
namewidth, nameheight = dc.GetTextExtent(self.Name)
|
|
262 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2,
|
|
263 |
self.Pos.y - (nameheight + 2))
|
|
264 |
typewidth, typeheight = dc.GetTextExtent(self.Type)
|
|
265 |
dc.DrawText(self.Type, self.Pos.x + (self.Size[0] - typewidth) / 2,
|
|
266 |
self.Pos.y + 5)
|
|
267 |
# Draw inputs and outputs connectors
|
|
268 |
for input in self.Inputs:
|
|
269 |
input.Draw(dc)
|
|
270 |
for output in self.Outputs:
|
|
271 |
output.Draw(dc)
|
|
272 |
Graphic_Element.Draw(self, dc)
|
|
273 |
|
|
274 |
|
|
275 |
#-------------------------------------------------------------------------------
|
|
276 |
# Function Block Diagram Variable
|
|
277 |
#-------------------------------------------------------------------------------
|
|
278 |
|
|
279 |
"""
|
|
280 |
Class that implements the graphic representation of a variable
|
|
281 |
"""
|
|
282 |
|
|
283 |
class FBD_Variable(Graphic_Element):
|
|
284 |
|
|
285 |
# Create a new variable
|
|
286 |
def __init__(self, parent, type, name, value_type, id = None):
|
|
287 |
Graphic_Element.__init__(self, parent)
|
|
288 |
self.Type = type
|
|
289 |
self.Name = name
|
|
290 |
self.Id = id
|
|
291 |
self.Input = None
|
|
292 |
self.Output = None
|
|
293 |
# Create an input or output connector according to variable type
|
|
294 |
if self.Type != INPUT:
|
|
295 |
self.Input = Connector(self, "", value_type, wxPoint(0, 0), WEST)
|
|
296 |
if self.Type != OUTPUT:
|
|
297 |
self.Output = Connector(self, "", value_type, wxPoint(0, 0), EAST)
|
|
298 |
self.RefreshConnectors()
|
|
299 |
|
|
300 |
# Destructor
|
|
301 |
def __del__(self):
|
|
302 |
self.Input = None
|
|
303 |
self.Output = None
|
|
304 |
|
|
305 |
# Unconnect connector
|
|
306 |
def Clean(self):
|
|
307 |
if self.Input:
|
|
308 |
self.Input.UnConnect()
|
|
309 |
if self.Output:
|
|
310 |
self.Output.UnConnect()
|
|
311 |
|
|
312 |
# Delete this variable by calling the appropriate method
|
|
313 |
def Delete(self):
|
|
314 |
self.Parent.DeleteVariable(self)
|
|
315 |
|
|
316 |
# Refresh the variable bounding box
|
|
317 |
def RefreshBoundingBox(self):
|
|
318 |
dc = wxClientDC(self.Parent)
|
|
319 |
if self.Type in (OUTPUT, INOUT):
|
|
320 |
bbx_x = self.Pos.x - CONNECTOR_SIZE
|
|
321 |
else:
|
|
322 |
bbx_x = self.Pos.x
|
|
323 |
if self.Type == INOUT:
|
|
324 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE
|
|
325 |
else:
|
|
326 |
bbx_width = self.Size[0] + CONNECTOR_SIZE
|
|
327 |
self.BoundingBox = wxRect(bbx_x, self.Pos.y, bbx_width + 1, self.Size[1] + 1)
|
|
328 |
|
|
329 |
# Refresh the position of the variable connector
|
|
330 |
def RefreshConnectors(self):
|
|
331 |
if self.Input:
|
|
332 |
self.Input.SetPosition(wxPoint(0, self.Size[1] / 2))
|
|
333 |
if self.Output:
|
|
334 |
self.Output.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2))
|
|
335 |
self.RefreshConnected(self)
|
|
336 |
|
|
337 |
# Refresh the position of wires connected to connector
|
|
338 |
def RefreshConnected(self, exclude = []):
|
|
339 |
if self.Input:
|
|
340 |
self.Input.MoveConnected(exclude)
|
|
341 |
if self.Output:
|
|
342 |
self.Output.MoveConnected(exclude)
|
|
343 |
|
|
344 |
# Test if point given is on the variable connector
|
|
345 |
def TestConnector(self, pt, exclude=True):
|
|
346 |
if self.Input and self.Input.TestPoint(pt, exclude):
|
|
347 |
return self.Input
|
|
348 |
if self.Output and self.Output.TestPoint(pt, exclude):
|
|
349 |
return self.Output
|
|
350 |
return None
|
|
351 |
|
|
352 |
# Returns the block connector that starts with the point given if it exists
|
|
353 |
def GetConnector(self, position):
|
|
354 |
# Test input connector if it exists
|
|
355 |
if self.Input:
|
|
356 |
input_pos = self.Input.GetRelPosition()
|
|
357 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
|
|
358 |
return self.Input
|
|
359 |
# Test output connector if it exists
|
|
360 |
if self.Output:
|
|
361 |
output_pos = self.Output.GetRelPosition()
|
|
362 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y:
|
|
363 |
return self.Output
|
|
364 |
return None
|
|
365 |
|
|
366 |
# Returns all the block connectors
|
|
367 |
def GetConnectors(self):
|
|
368 |
return {"input" : self.Input, "output" : self.Output}
|
|
369 |
|
|
370 |
# Changes the negated property of the variable connector if handled
|
|
371 |
def SetConnectorNegated(self, negated):
|
|
372 |
handle_type, handle = self.Handle
|
|
373 |
if handle_type == HANDLE_CONNECTOR:
|
|
374 |
handle.SetNegated(negated)
|
|
375 |
self.RefreshModel(False)
|
|
376 |
|
|
377 |
# Returns the variable type
|
|
378 |
def GetType(self):
|
|
379 |
return self.Type
|
|
380 |
|
|
381 |
# Changes the variable name
|
|
382 |
def SetName(self, name):
|
|
383 |
self.Name = name
|
|
384 |
|
|
385 |
# Returns the variable name
|
|
386 |
def GetName(self):
|
|
387 |
return self.Name
|
|
388 |
|
|
389 |
# Returns the variable minimum size
|
|
390 |
def GetMinSize(self):
|
|
391 |
dc = wxClientDC(self.Parent)
|
|
392 |
text_width, text_height = dc.GetTextExtent(self.Name)
|
|
393 |
return text_width + 10, text_height + 10
|
|
394 |
|
|
395 |
# Method called when a RightUp event have been generated
|
|
396 |
def OnRightUp(self, event, scaling):
|
|
397 |
pos = GetScaledEventPosition(event, scaling)
|
|
398 |
# Popup the menu with special items for a variable and a connector if it's handled
|
|
399 |
connector = self.TestConnectors(pos, False)
|
|
400 |
if connector:
|
|
401 |
self.Handle = (HANDLE_CONNECTOR, connector)
|
|
402 |
self.Parent.PopupVariableMenu(connector)
|
|
403 |
else:
|
|
404 |
self.Parent.PopupVariableMenu()
|
|
405 |
|
|
406 |
# Refreshes the variable model
|
|
407 |
def RefreshModel(self, move=True):
|
|
408 |
self.Parent.RefreshVariableModel(self)
|
|
409 |
# If variable has moved and variable is not of type OUTPUT, refresh the model
|
|
410 |
# of wires connected to output connector
|
|
411 |
if move and self.Type != OUTPUT:
|
|
412 |
if self.Output:
|
|
413 |
self.Output.RefreshWires()
|
|
414 |
|
|
415 |
# Draws variable
|
|
416 |
def Draw(self, dc):
|
|
417 |
dc.SetPen(wxBLACK_PEN)
|
|
418 |
dc.SetBrush(wxWHITE_BRUSH)
|
|
419 |
# Draw a rectangle with the variable size
|
|
420 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
|
|
421 |
# Draw variable name
|
|
422 |
namewidth, nameheight = dc.GetTextExtent(self.Name)
|
|
423 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2,
|
|
424 |
self.Pos.y + (self.Size[1] - nameheight) / 2)
|
|
425 |
# Draw connectors
|
|
426 |
if self.Input:
|
|
427 |
self.Input.Draw(dc)
|
|
428 |
if self.Output:
|
|
429 |
self.Output.Draw(dc)
|
|
430 |
Graphic_Element.Draw(self, dc)
|
|
431 |
|
|
432 |
|
|
433 |
#-------------------------------------------------------------------------------
|
|
434 |
# Function Block Diagram Connector
|
|
435 |
#-------------------------------------------------------------------------------
|
|
436 |
|
|
437 |
"""
|
|
438 |
Class that implements the graphic representation of a connection
|
|
439 |
"""
|
|
440 |
|
|
441 |
class FBD_Connector(Graphic_Element):
|
|
442 |
|
|
443 |
# Create a new connection
|
|
444 |
def __init__(self, parent, type, name, id = None):
|
|
445 |
Graphic_Element.__init__(self, parent)
|
|
446 |
self.Type = type
|
|
447 |
self.Name = name
|
|
448 |
self.Id = id
|
|
449 |
self.Pos = wxPoint(0, 0)
|
|
450 |
self.Size = wxSize(0, 0)
|
|
451 |
# Create an input or output connector according to connection type
|
|
452 |
if self.Type == CONNECTOR:
|
|
453 |
self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), WEST)
|
|
454 |
else:
|
|
455 |
self.Connector = Connector(self, "", "ANY", wxPoint(0, 0), EAST)
|
|
456 |
self.RefreshConnectors()
|
|
457 |
|
|
458 |
# Destructor
|
|
459 |
def __del__(self):
|
|
460 |
self.Connector = None
|
|
461 |
|
|
462 |
# Unconnect connector
|
|
463 |
def Clean(self):
|
|
464 |
if self.Connector:
|
|
465 |
self.Connector.UnConnect()
|
|
466 |
|
|
467 |
# Delete this connection by calling the appropriate method
|
|
468 |
def Delete(self):
|
|
469 |
self.Parent.DeleteConnection(self)
|
|
470 |
|
|
471 |
# Refresh the connection bounding box
|
|
472 |
def RefreshBoundingBox(self):
|
|
473 |
dc = wxClientDC(self.Parent)
|
|
474 |
if self.Type == CONNECTOR:
|
|
475 |
bbx_x = self.Pos.x - CONNECTOR_SIZE
|
|
476 |
else:
|
|
477 |
bbx_x = self.Pos.x
|
|
478 |
bbx_width = self.Size[0] + CONNECTOR_SIZE
|
|
479 |
self.BoundingBox = wxRect(bbx_x, self.Pos.y, bbx_width, self.Size[1])
|
|
480 |
|
|
481 |
# Refresh the position of the connection connector
|
|
482 |
def RefreshConnectors(self):
|
|
483 |
if self.Type == CONNECTOR:
|
|
484 |
self.Connector.SetPosition(wxPoint(0, self.Size[1] / 2))
|
|
485 |
else:
|
|
486 |
self.Connector.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2))
|
|
487 |
self.RefreshConnected(self)
|
|
488 |
|
|
489 |
# Refresh the position of wires connected to connector
|
|
490 |
def RefreshConnected(self, exclude = []):
|
|
491 |
if self.Connector:
|
|
492 |
self.Connector.MoveConnected(exclude)
|
|
493 |
|
|
494 |
# Test if point given is on the connection connector
|
|
495 |
def TestConnector(self, pt, exclude=True):
|
|
496 |
if self.Connector and self.Connector.TestPoint(pt, exclude):
|
|
497 |
return self.Connector
|
|
498 |
return None
|
|
499 |
|
|
500 |
# Returns the connection connector
|
|
501 |
def GetConnector(self, position = None):
|
|
502 |
return self.Connector
|
|
503 |
|
|
504 |
# Returns the connection type
|
|
505 |
def GetType(self):
|
|
506 |
return self.Type
|
|
507 |
|
|
508 |
# Changes the connection name
|
|
509 |
def SetName(self, name):
|
|
510 |
self.Name = name
|
|
511 |
|
|
512 |
# Returns the connection name
|
|
513 |
def GetName(self):
|
|
514 |
return self.Name
|
|
515 |
|
|
516 |
# Returns the connection minimum size
|
|
517 |
def GetMinSize(self):
|
|
518 |
dc = wxClientDC(self.Parent)
|
|
519 |
text_width, text_height = dc.GetTextExtent(self.Name)
|
|
520 |
if text_height % 2 == 1:
|
|
521 |
text_height += 1
|
|
522 |
return text_width + text_height + 20, text_height + 10
|
|
523 |
|
|
524 |
# Method called when a RightUp event have been generated
|
|
525 |
def OnRightUp(self, event, scaling):
|
|
526 |
# Popup the default menu
|
|
527 |
self.Parent.PopupDefaultMenu()
|
|
528 |
|
|
529 |
# Refreshes the connection model
|
|
530 |
def RefreshModel(self, move=True):
|
|
531 |
self.Parent.RefreshConnectionModel(self)
|
|
532 |
# If connection has moved and connection is of type CONTINUATION, refresh
|
|
533 |
# the model of wires connected to connector
|
|
534 |
if move and self.Type == CONTINUATION:
|
|
535 |
if self.Connector:
|
|
536 |
self.Connector.RefreshWires()
|
|
537 |
|
|
538 |
# Draws connection
|
|
539 |
def Draw(self, dc):
|
|
540 |
dc.SetPen(wxBLACK_PEN)
|
|
541 |
dc.SetBrush(wxWHITE_BRUSH)
|
|
542 |
# Draw a rectangle with the connection size with arrows in
|
|
543 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
|
|
544 |
namewidth, nameheight = dc.GetTextExtent(self.Name)
|
|
545 |
arrowsize = min(self.Size[1] / 2, (self.Size[0] - namewidth - 10) / 2)
|
|
546 |
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize,
|
|
547 |
self.Pos.y + self.Size[1] / 2)
|
|
548 |
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2,
|
|
549 |
self.Pos.x, self.Pos.y + self.Size[1])
|
|
550 |
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y,
|
|
551 |
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
|
|
552 |
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2,
|
|
553 |
self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
|
|
554 |
# Draw variable name
|
|
555 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2,
|
|
556 |
self.Pos.y + (self.Size[1] - nameheight) / 2)
|
|
557 |
# Draw connector
|
|
558 |
if self.Connector:
|
|
559 |
self.Connector.Draw(dc)
|
|
560 |
Graphic_Element.Draw(self, dc)
|