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