author | lbessard |
Fri, 16 Jan 2009 13:22:07 +0100 | |
changeset 304 | 2df3d31d8059 |
parent 289 | 151e73a02caf |
child 379 | e4c26ee9c998 |
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 * |
|
29 |
||
30 |
#------------------------------------------------------------------------------- |
|
31 |
# Function Block Diagram Block |
|
32 |
#------------------------------------------------------------------------------- |
|
33 |
||
34 |
""" |
|
35 |
Class that implements the graphic representation of a function block |
|
36 |
""" |
|
37 |
||
38 |
class FBD_Block(Graphic_Element): |
|
39 |
||
40 |
# Create a new block |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
41 |
def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0): |
0 | 42 |
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
|
43 |
self.Type = None |
27 | 44 |
self.Extension = None |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
45 |
self.ExecutionControl = False |
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 |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
53 |
self.SetType(type, extension, inputs, connectors, executionControl) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
54 |
self.Errors = {} |
0 | 55 |
|
112 | 56 |
# Make a clone of this FBD_Block |
162 | 57 |
def Clone(self, parent, id = None, name = "", pos = None): |
144 | 58 |
if self.Name != "" and name == "": |
59 |
name = self.Name |
|
162 | 60 |
block = FBD_Block(parent, self.Type, name, id, self.Extension) |
112 | 61 |
block.SetSize(self.Size[0], self.Size[1]) |
62 |
if pos is not None: |
|
63 |
block.SetPosition(pos.x, pos.y) |
|
283 | 64 |
else: |
65 |
block.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 66 |
block.Inputs = [input.Clone(block) for input in self.Inputs] |
67 |
block.Outputs = [output.Clone(block) for output in self.Outputs] |
|
68 |
return block |
|
69 |
||
283 | 70 |
def GetConnectorTranslation(self, element): |
71 |
return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs)) |
|
72 |
||
249 | 73 |
def Flush(self): |
74 |
for input in self.Inputs: |
|
75 |
input.Flush() |
|
0 | 76 |
self.Inputs = [] |
249 | 77 |
for output in self.Outputs: |
78 |
output.Flush() |
|
0 | 79 |
self.Outputs = [] |
80 |
||
144 | 81 |
# Returns the RedrawRect |
82 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
83 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
84 |
if movex != 0 or movey != 0: |
|
85 |
for input in self.Inputs: |
|
86 |
if input.IsConnected(): |
|
87 |
rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
|
88 |
for output in self.Outputs: |
|
89 |
if output.IsConnected(): |
|
90 |
rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
|
91 |
return rect |
|
92 |
||
0 | 93 |
# Delete this block by calling the appropriate method |
94 |
def Delete(self): |
|
95 |
self.Parent.DeleteBlock(self) |
|
96 |
||
97 |
# Unconnect all inputs and outputs |
|
98 |
def Clean(self): |
|
99 |
for input in self.Inputs: |
|
2 | 100 |
input.UnConnect(delete = True) |
101 |
for output in self.Outputs: |
|
102 |
output.UnConnect(delete = True) |
|
0 | 103 |
|
42 | 104 |
# Refresh the size of text for name |
105 |
def RefreshNameSize(self): |
|
165 | 106 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 107 |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
108 |
# 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
|
109 |
def RefreshExecutionOrderSize(self): |
165 | 110 |
self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
111 |
|
0 | 112 |
# Refresh the block bounding box |
113 |
def RefreshBoundingBox(self): |
|
114 |
# Calculate the size of the name outside the block |
|
42 | 115 |
text_width, text_height = self.NameSize |
0 | 116 |
# Calculate the bounding box size |
117 |
bbx_x = self.Pos.x - max(min(1, len(self.Inputs)) * CONNECTOR_SIZE, (text_width - self.Size[0]) / 2) |
|
289 | 118 |
bbx_width = max(self.Size[0] + 1 + (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE, text_width) |
0 | 119 |
if self.Name != "": |
120 |
bbx_y = self.Pos.y - (text_height + 2) |
|
121 |
bbx_height = self.Size[1] + (text_height + 2) |
|
122 |
else: |
|
123 |
bbx_y = self.Pos.y |
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 130 |
|
131 |
# Refresh the positions of the block connectors |
|
132 |
def RefreshConnectors(self): |
|
145 | 133 |
scaling = self.Parent.GetScaling() |
0 | 134 |
# Calculate the size for the connector lines |
135 |
lines = max(len(self.Inputs), len(self.Outputs)) |
|
103 | 136 |
if lines > 0: |
137 |
linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE) |
|
145 | 138 |
# Update inputs and outputs positions |
103 | 139 |
position = BLOCK_LINE_SIZE + linesize / 2 |
145 | 140 |
for i in xrange(lines): |
141 |
if scaling is not None: |
|
142 |
ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
143 |
else: |
|
144 |
ypos = position |
|
145 |
if i < len(self.Inputs): |
|
146 |
self.Inputs[i].SetPosition(wx.Point(0, ypos)) |
|
147 |
if i < len(self.Outputs): |
|
148 |
self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos)) |
|
103 | 149 |
position += linesize |
0 | 150 |
self.RefreshConnected() |
151 |
||
152 |
# Refresh the positions of wires connected to inputs and outputs |
|
153 |
def RefreshConnected(self, exclude = []): |
|
154 |
for input in self.Inputs: |
|
155 |
input.MoveConnected(exclude) |
|
156 |
for output in self.Outputs: |
|
157 |
output.MoveConnected(exclude) |
|
158 |
||
159 |
# Returns the block connector that starts with the point given if it exists |
|
27 | 160 |
def GetConnector(self, position, name = None): |
161 |
# if a name is given |
|
162 |
if name: |
|
163 |
# Test each input and output connector |
|
164 |
for input in self.Inputs: |
|
165 |
if name == input.GetName(): |
|
166 |
return input |
|
167 |
for output in self.Outputs: |
|
168 |
if name == output.GetName(): |
|
169 |
return output |
|
0 | 170 |
# Test each input connector |
171 |
for input in self.Inputs: |
|
172 |
input_pos = input.GetRelPosition() |
|
173 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
174 |
return input |
|
175 |
# Test each output connector |
|
176 |
for output in self.Outputs: |
|
177 |
output_pos = output.GetRelPosition() |
|
178 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
179 |
return output |
|
180 |
return None |
|
181 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
182 |
def GetInputTypes(self): |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
183 |
return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"]) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
184 |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
185 |
def SetOutputValues(self, values): |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
186 |
for output in self.Outputs: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
187 |
output.SetValue(values.get(ouput.getName(), None)) |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
188 |
|
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
189 |
def GetConnectionResultType(self, connector, connectortype): |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
190 |
resulttype = connectortype |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
191 |
for input in self.Inputs: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
192 |
name = input.GetName() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
193 |
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
|
194 |
inputtype = input.GetConnectedType() |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
195 |
if resulttype is None or inputtype is not None and self.IsOfType(inputtype, resulttype): |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
196 |
resulttype = inputtype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
197 |
for output in self.Outputs: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
198 |
name = output.GetName() |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
199 |
if output != connector and name == "OUT" and not self.IsEndType(output.GetType()): |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
200 |
outputtype = output.GetConnectedType() |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
201 |
if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype): |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
202 |
resulttype = outputtype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
203 |
return resulttype |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
90
diff
changeset
|
204 |
|
145 | 205 |
# Returns all the block connectors |
0 | 206 |
def GetConnectors(self): |
207 |
return {"inputs" : self.Inputs, "outputs" : self.Outputs} |
|
208 |
||
209 |
# Test if point given is on one of the block connectors |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
210 |
def TestConnector(self, pt, direction = None, exclude = True): |
0 | 211 |
# Test each input connector |
212 |
for input in self.Inputs: |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
213 |
if input.TestPoint(pt, direction, exclude): |
0 | 214 |
return input |
215 |
# Test each output connector |
|
216 |
for output in self.Outputs: |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
217 |
if output.TestPoint(pt, direction, exclude): |
0 | 218 |
return output |
219 |
return None |
|
220 |
||
2 | 221 |
# Changes the block type |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
222 |
def SetType(self, type, extension, inputs = None, connectors = {}, executionControl = False): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
223 |
if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: |
42 | 224 |
if type != self.Type: |
225 |
self.Type = type |
|
165 | 226 |
self.TypeSize = self.Parent.GetTextExtent(self.Type) |
27 | 227 |
self.Extension = extension |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
228 |
self.ExecutionControl = executionControl |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
229 |
# 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
|
230 |
# inputs and outputs |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
231 |
blocktype = self.Parent.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
|
232 |
if blocktype: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
start += 1 |
27 | 240 |
inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) |
16 | 241 |
else: |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
242 |
self.Colour = wx.RED |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
243 |
if "inputs" in connectors: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
244 |
inputs = connectors["inputs"] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
245 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
246 |
inputs = [] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
247 |
if "outputs" in connectors: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
248 |
outputs = connectors["outputs"] |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
249 |
else: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
250 |
outputs = [] |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
251 |
if self.ExecutionControl: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
252 |
inputs.insert(0, ("EN","BOOL","none")) |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
253 |
outputs.insert(0, ("ENO","BOOL","none")) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
# 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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
# 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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
self.Outputs.append(connector) |
42 | 274 |
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
|
275 |
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
|
276 |
self.RefreshBoundingBox() |
2 | 277 |
|
0 | 278 |
# Returns the block type |
279 |
def GetType(self): |
|
280 |
return self.Type |
|
281 |
||
282 |
# Changes the block name |
|
283 |
def SetName(self, name): |
|
284 |
self.Name = name |
|
42 | 285 |
self.RefreshNameSize() |
0 | 286 |
|
287 |
# Returs the block name |
|
288 |
def GetName(self): |
|
289 |
return self.Name |
|
290 |
||
2 | 291 |
# Changes the extension name |
292 |
def SetExtension(self, extension): |
|
293 |
self.Extension = extension |
|
294 |
||
295 |
# Returs the extension name |
|
296 |
def GetExtension(self): |
|
297 |
return self.Extension |
|
298 |
||
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
299 |
# 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
|
300 |
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
|
301 |
self.ExecutionOrder = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
302 |
self.RefreshExecutionOrderSize() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
303 |
|
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
304 |
# 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
|
305 |
def GetExecutionOrder(self): |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
306 |
return self.ExecutionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
307 |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
308 |
# Returs the execution order |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
309 |
def GetExecutionControl(self): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
310 |
return self.ExecutionControl |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
311 |
|
42 | 312 |
# Refresh the block minimum size |
313 |
def RefreshMinSize(self): |
|
0 | 314 |
# Calculate the inputs maximum width |
315 |
max_input = 0 |
|
316 |
for input in self.Inputs: |
|
42 | 317 |
w, h = input.GetNameSize() |
0 | 318 |
max_input = max(max_input, w) |
319 |
# Calculate the outputs maximum width |
|
320 |
max_output = 0 |
|
321 |
for output in self.Outputs: |
|
42 | 322 |
w, h = output.GetNameSize() |
0 | 323 |
max_output = max(max_output, w) |
42 | 324 |
width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
0 | 325 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
42 | 326 |
self.MinSize = width, height |
327 |
||
328 |
# Returns the block minimum size |
|
329 |
def GetMinSize(self): |
|
330 |
return self.MinSize |
|
0 | 331 |
|
332 |
# Changes the negated property of the connector handled |
|
333 |
def SetConnectorNegated(self, negated): |
|
334 |
handle_type, handle = self.Handle |
|
335 |
if handle_type == HANDLE_CONNECTOR: |
|
336 |
handle.SetNegated(negated) |
|
337 |
self.RefreshModel(False) |
|
338 |
||
339 |
# Changes the edge property of the connector handled |
|
340 |
def SetConnectorEdge(self, edge): |
|
341 |
handle_type, handle = self.Handle |
|
342 |
if handle_type == HANDLE_CONNECTOR: |
|
343 |
handle.SetEdge(edge) |
|
344 |
self.RefreshModel(False) |
|
345 |
||
287 | 346 |
## # Method called when a Motion event have been generated |
347 |
## def OnMotion(self, event, dc, scaling): |
|
348 |
## if not event.Dragging(): |
|
349 |
## pos = event.GetLogicalPosition(dc) |
|
350 |
## for input in self.Inputs: |
|
351 |
## rect = input.GetRedrawRect() |
|
352 |
## if rect.InsideXY(pos.x, pos.y): |
|
353 |
## print "Find input" |
|
354 |
## tip = wx.TipWindow(self.Parent, "Test") |
|
355 |
## tip.SetBoundingRect(rect) |
|
356 |
## return Graphic_Element.OnMotion(self, event, dc, scaling) |
|
357 |
||
2 | 358 |
# Method called when a LeftDClick event have been generated |
27 | 359 |
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
|
360 |
# Edit the block properties |
2 | 361 |
self.Parent.EditBlockContent(self) |
362 |
||
0 | 363 |
# Method called when a RightUp event have been generated |
27 | 364 |
def OnRightUp(self, event, dc, scaling): |
365 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 366 |
# Popup the menu with special items for a block and a connector if one is handled |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
367 |
connector = self.TestConnector(pos, exclude=False) |
0 | 368 |
if connector: |
369 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
370 |
self.Parent.PopupBlockMenu(connector) |
|
371 |
else: |
|
372 |
self.Parent.PopupBlockMenu() |
|
373 |
||
374 |
# Refreshes the block model |
|
375 |
def RefreshModel(self, move=True): |
|
376 |
self.Parent.RefreshBlockModel(self) |
|
377 |
# If block has moved, refresh the model of wires connected to outputs |
|
378 |
if move: |
|
379 |
for output in self.Outputs: |
|
380 |
output.RefreshWires() |
|
381 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
382 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
383 |
if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
384 |
self.Errors[infos[0]] = (start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
385 |
elif infos[0] == "input" and infos[1] < len(self.Inputs): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
386 |
self.Inputs[infos[1]].AddError(infos[2:], start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
387 |
elif infos[0] == "output" and infos[1] < len(self.Outputs): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
388 |
self.Outputs[infos[1]].AddError(infos[2:], start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
389 |
|
0 | 390 |
# Draws block |
391 |
def Draw(self, dc): |
|
144 | 392 |
Graphic_Element.Draw(self, dc) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
393 |
dc.SetPen(self.Pen) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
394 |
dc.SetBrush(wx.WHITE_BRUSH) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
395 |
dc.SetTextForeground(self.Colour) |
213 | 396 |
|
397 |
if getattr(dc, "printing", False): |
|
398 |
name_size = dc.GetTextExtent(self.Name) |
|
399 |
type_size = dc.GetTextExtent(self.Type) |
|
400 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
401 |
else: |
|
402 |
name_size = self.NameSize |
|
403 |
type_size = self.TypeSize |
|
404 |
executionorder_size = self.ExecutionOrderSize |
|
405 |
||
0 | 406 |
# Draw a rectangle with the block size |
407 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
408 |
# Draw block name and block type |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
409 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
410 |
self.Pos.y - (name_size[1] + 2)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
411 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
412 |
self.Pos.y + 5) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
413 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
414 |
dc.DrawText(self.Type, type_pos[0], type_pos[1]) |
0 | 415 |
# Draw inputs and outputs connectors |
416 |
for input in self.Inputs: |
|
417 |
input.Draw(dc) |
|
418 |
for output in self.Outputs: |
|
419 |
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
|
420 |
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
|
421 |
# Draw block execution order |
213 | 422 |
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
423 |
self.Pos.y + self.Size[1] + 2) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
424 |
if "name" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
425 |
HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
426 |
if "type" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
427 |
HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1]) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
118
diff
changeset
|
428 |
dc.SetTextForeground(wx.BLACK) |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
118
diff
changeset
|
429 |
|
0 | 430 |
|
431 |
#------------------------------------------------------------------------------- |
|
432 |
# Function Block Diagram Variable |
|
433 |
#------------------------------------------------------------------------------- |
|
434 |
||
435 |
""" |
|
436 |
Class that implements the graphic representation of a variable |
|
437 |
""" |
|
438 |
||
439 |
class FBD_Variable(Graphic_Element): |
|
440 |
||
441 |
# 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
|
442 |
def __init__(self, parent, type, name, value_type, id = None, executionOrder = 0): |
0 | 443 |
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
|
444 |
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
|
445 |
self.ValueType = None |
0 | 446 |
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
|
447 |
self.SetName(name) |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
448 |
self.SetExecutionOrder(executionOrder) |
0 | 449 |
self.Input = None |
450 |
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
|
451 |
self.SetType(type, value_type) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
452 |
self.Errors = [] |
0 | 453 |
|
112 | 454 |
# Make a clone of this FBD_Variable |
162 | 455 |
def Clone(self, parent, id = None, pos = None): |
456 |
variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id) |
|
112 | 457 |
variable.SetSize(self.Size[0], self.Size[1]) |
458 |
if pos is not None: |
|
459 |
variable.SetPosition(pos.x, pos.y) |
|
283 | 460 |
else: |
461 |
variable.SetPosition(self.Pos.x, self.Pos.y) |
|
144 | 462 |
if self.Input: |
463 |
variable.Input = self.Input.Clone(variable) |
|
464 |
if self.Output: |
|
465 |
variable.Output = self.Output.Clone(variable) |
|
112 | 466 |
return variable |
467 |
||
283 | 468 |
def GetConnectorTranslation(self, element): |
469 |
connectors = {} |
|
470 |
if self.Input is not None: |
|
287 | 471 |
connectors[self.Input] = element.Input |
283 | 472 |
if self.Output is not None: |
473 |
connectors[self.Output] = element.Output |
|
474 |
return connectors |
|
475 |
||
249 | 476 |
def Flush(self): |
477 |
if self.Input is not None: |
|
478 |
self.Input.Flush() |
|
479 |
self.Input = None |
|
480 |
if self.Output is not None: |
|
481 |
self.Output.Flush() |
|
482 |
self.Output = None |
|
0 | 483 |
|
144 | 484 |
# Returns the RedrawRect |
485 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
486 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
487 |
if movex != 0 or movey != 0: |
|
488 |
if self.Input and self.Input.IsConnected(): |
|
489 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
490 |
if self.Output and self.Output.IsConnected(): |
|
491 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
492 |
return rect |
|
493 |
||
0 | 494 |
# Unconnect connector |
495 |
def Clean(self): |
|
496 |
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
|
497 |
self.Input.UnConnect(delete = True) |
0 | 498 |
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
|
499 |
self.Output.UnConnect(delete = True) |
0 | 500 |
|
501 |
# Delete this variable by calling the appropriate method |
|
502 |
def Delete(self): |
|
503 |
self.Parent.DeleteVariable(self) |
|
504 |
||
42 | 505 |
# Refresh the size of text for name |
506 |
def RefreshNameSize(self): |
|
165 | 507 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 508 |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
509 |
# 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
|
510 |
def RefreshExecutionOrderSize(self): |
165 | 511 |
self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
512 |
|
0 | 513 |
# Refresh the variable bounding box |
514 |
def RefreshBoundingBox(self): |
|
515 |
if self.Type in (OUTPUT, INOUT): |
|
516 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
517 |
else: |
|
518 |
bbx_x = self.Pos.x |
|
519 |
if self.Type == INOUT: |
|
520 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE |
|
521 |
else: |
|
522 |
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
|
523 |
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
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1) |
0 | 529 |
|
530 |
# Refresh the position of the variable connector |
|
531 |
def RefreshConnectors(self): |
|
145 | 532 |
scaling = self.Parent.GetScaling() |
533 |
if scaling is not None: |
|
534 |
position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
535 |
else: |
|
536 |
position = self.Size[1] / 2 |
|
0 | 537 |
if self.Input: |
145 | 538 |
self.Input.SetPosition(wx.Point(0, position)) |
0 | 539 |
if self.Output: |
145 | 540 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
541 |
self.RefreshConnected() |
0 | 542 |
|
543 |
# Refresh the position of wires connected to connector |
|
544 |
def RefreshConnected(self, exclude = []): |
|
545 |
if self.Input: |
|
546 |
self.Input.MoveConnected(exclude) |
|
547 |
if self.Output: |
|
548 |
self.Output.MoveConnected(exclude) |
|
549 |
||
550 |
# Test if point given is on the variable connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
551 |
def TestConnector(self, pt, direction = None, exclude=True): |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
552 |
if self.Input and self.Input.TestPoint(pt, direction, exclude): |
0 | 553 |
return self.Input |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
554 |
if self.Output and self.Output.TestPoint(pt, direction, exclude): |
0 | 555 |
return self.Output |
556 |
return None |
|
557 |
||
558 |
# Returns the block connector that starts with the point given if it exists |
|
27 | 559 |
def GetConnector(self, position, name = None): |
560 |
# if a name is given |
|
561 |
if name: |
|
562 |
# Test input and output connector if they exists |
|
563 |
if self.Input and name == self.Input.GetName(): |
|
564 |
return self.Input |
|
565 |
if self.Output and name == self.Output.GetName(): |
|
566 |
return self.Output |
|
0 | 567 |
# Test input connector if it exists |
568 |
if self.Input: |
|
569 |
input_pos = self.Input.GetRelPosition() |
|
570 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
571 |
return self.Input |
|
572 |
# Test output connector if it exists |
|
573 |
if self.Output: |
|
574 |
output_pos = self.Output.GetRelPosition() |
|
575 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
576 |
return self.Output |
|
577 |
return None |
|
578 |
||
579 |
# Returns all the block connectors |
|
580 |
def GetConnectors(self): |
|
581 |
return {"input" : self.Input, "output" : self.Output} |
|
582 |
||
583 |
# Changes the negated property of the variable connector if handled |
|
584 |
def SetConnectorNegated(self, negated): |
|
585 |
handle_type, handle = self.Handle |
|
586 |
if handle_type == HANDLE_CONNECTOR: |
|
587 |
handle.SetNegated(negated) |
|
588 |
self.RefreshModel(False) |
|
589 |
||
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
590 |
# 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
|
591 |
def SetType(self, type, value_type): |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
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
|
597 |
# 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
|
598 |
if self.Type != INPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
599 |
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
|
600 |
if self.Type != OUTPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
601 |
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
|
602 |
self.RefreshConnectors() |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
603 |
elif value_type != self.ValueType: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
604 |
if self.Input: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
605 |
self.Input.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
606 |
if self.Output: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
607 |
self.Output.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
608 |
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
|
609 |
|
0 | 610 |
# Returns the variable type |
611 |
def GetType(self): |
|
612 |
return self.Type |
|
613 |
||
614 |
# Changes the variable name |
|
615 |
def SetName(self, name): |
|
616 |
self.Name = name |
|
42 | 617 |
self.RefreshNameSize() |
0 | 618 |
|
619 |
# Returns the variable name |
|
620 |
def GetName(self): |
|
621 |
return self.Name |
|
622 |
||
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
623 |
# 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
|
624 |
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
|
625 |
self.ExecutionOrder = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
626 |
self.RefreshExecutionOrderSize() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
627 |
|
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
628 |
# 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
|
629 |
def GetExecutionOrder(self): |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
630 |
return self.ExecutionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
631 |
|
0 | 632 |
# Returns the variable minimum size |
633 |
def GetMinSize(self): |
|
42 | 634 |
return self.NameSize[0] + 10, self.NameSize[1] + 10 |
0 | 635 |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
636 |
# Method called when a LeftDClick event have been generated |
27 | 637 |
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
|
638 |
# 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
|
639 |
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
|
640 |
|
0 | 641 |
# Method called when a RightUp event have been generated |
27 | 642 |
def OnRightUp(self, event, dc, scaling): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
643 |
self.Parent.PopupDefaultMenu() |
0 | 644 |
|
645 |
# Refreshes the variable model |
|
646 |
def RefreshModel(self, move=True): |
|
647 |
self.Parent.RefreshVariableModel(self) |
|
648 |
# If variable has moved and variable is not of type OUTPUT, refresh the model |
|
649 |
# of wires connected to output connector |
|
650 |
if move and self.Type != OUTPUT: |
|
651 |
if self.Output: |
|
652 |
self.Output.RefreshWires() |
|
653 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
654 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
655 |
if infos[0] == "expression" and start[0] == 0 and end[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
656 |
self.Errors.append((start[1], end[1])) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
657 |
|
0 | 658 |
# Draws variable |
659 |
def Draw(self, dc): |
|
144 | 660 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
661 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
662 |
dc.SetBrush(wx.WHITE_BRUSH) |
213 | 663 |
|
664 |
if getattr(dc, "printing", False): |
|
665 |
name_size = dc.GetTextExtent(self.Name) |
|
666 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
667 |
else: |
|
668 |
name_size = self.NameSize |
|
669 |
executionorder_size = self.ExecutionOrderSize |
|
670 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
671 |
text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
672 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
0 | 673 |
# Draw a rectangle with the variable size |
674 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
675 |
# Draw variable name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
676 |
dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
0 | 677 |
# Draw connectors |
678 |
if self.Input: |
|
679 |
self.Input.Draw(dc) |
|
680 |
if self.Output: |
|
681 |
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
|
682 |
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
|
683 |
# Draw variable execution order |
213 | 684 |
dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], |
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
685 |
self.Pos.y + self.Size[1] + 2) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
686 |
for start, end in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
687 |
offset = dc.GetTextExtent(self.Name[:start]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
688 |
size = dc.GetTextExtent(self.Name[start:end + 1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
689 |
HighlightErrorZone(dc, text_pos[0] + offset[0], text_pos[1], size[0], size[1]) |
0 | 690 |
|
691 |
#------------------------------------------------------------------------------- |
|
692 |
# Function Block Diagram Connector |
|
693 |
#------------------------------------------------------------------------------- |
|
694 |
||
695 |
""" |
|
696 |
Class that implements the graphic representation of a connection |
|
697 |
""" |
|
698 |
||
699 |
class FBD_Connector(Graphic_Element): |
|
700 |
||
701 |
# Create a new connection |
|
702 |
def __init__(self, parent, type, name, id = None): |
|
703 |
Graphic_Element.__init__(self, parent) |
|
704 |
self.Type = type |
|
705 |
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
|
706 |
self.SetName(name) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
707 |
self.Pos = wx.Point(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
708 |
self.Size = wx.Size(0, 0) |
0 | 709 |
# Create an input or output connector according to connection type |
710 |
if self.Type == CONNECTOR: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
711 |
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
|
712 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
713 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
0 | 714 |
self.RefreshConnectors() |
42 | 715 |
self.RefreshNameSize() |
0 | 716 |
|
249 | 717 |
def Flush(self): |
718 |
if self.Connector: |
|
719 |
self.Connector.Flush() |
|
720 |
self.Connector = None |
|
0 | 721 |
|
144 | 722 |
# Returns the RedrawRect |
723 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
724 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
725 |
if movex != 0 or movey != 0: |
|
726 |
if self.Connector and self.Connector.IsConnected(): |
|
727 |
rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
|
728 |
return rect |
|
729 |
||
112 | 730 |
# Make a clone of this FBD_Connector |
162 | 731 |
def Clone(self, parent, id = None, pos = None): |
732 |
connection = FBD_Connector(parent, self.Type, self.Name, id) |
|
112 | 733 |
connection.SetSize(self.Size[0], self.Size[1]) |
734 |
if pos is not None: |
|
735 |
connection.SetPosition(pos.x, pos.y) |
|
283 | 736 |
else: |
737 |
connection.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 738 |
connection.Connector = self.Connector.Clone(connection) |
739 |
return connection |
|
740 |
||
283 | 741 |
def GetConnectorTranslation(self, element): |
742 |
return {self.Connector : element.Connector} |
|
743 |
||
0 | 744 |
# Unconnect connector |
745 |
def Clean(self): |
|
746 |
if self.Connector: |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
747 |
self.Connector.UnConnect(delete = True) |
0 | 748 |
|
749 |
# Delete this connection by calling the appropriate method |
|
750 |
def Delete(self): |
|
751 |
self.Parent.DeleteConnection(self) |
|
752 |
||
42 | 753 |
# Refresh the size of text for name |
754 |
def RefreshNameSize(self): |
|
165 | 755 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 756 |
|
0 | 757 |
# Refresh the connection bounding box |
758 |
def RefreshBoundingBox(self): |
|
759 |
if self.Type == CONNECTOR: |
|
760 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
761 |
else: |
|
762 |
bbx_x = self.Pos.x |
|
763 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
764 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
0 | 765 |
|
766 |
# Refresh the position of the connection connector |
|
767 |
def RefreshConnectors(self): |
|
145 | 768 |
scaling = self.Parent.GetScaling() |
769 |
if scaling is not None: |
|
770 |
position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
771 |
else: |
|
772 |
position = self.Size[1] / 2 |
|
0 | 773 |
if self.Type == CONNECTOR: |
145 | 774 |
self.Connector.SetPosition(wx.Point(0, position)) |
775 |
else: |
|
776 |
self.Connector.SetPosition(wx.Point(self.Size[0], position)) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
777 |
self.RefreshConnected() |
0 | 778 |
|
779 |
# Refresh the position of wires connected to connector |
|
780 |
def RefreshConnected(self, exclude = []): |
|
781 |
if self.Connector: |
|
782 |
self.Connector.MoveConnected(exclude) |
|
783 |
||
784 |
# Test if point given is on the connection connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
785 |
def TestConnector(self, pt, direction = None, exclude=True): |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
786 |
if self.Connector and self.Connector.TestPoint(pt, direction, exclude): |
0 | 787 |
return self.Connector |
788 |
return None |
|
789 |
||
790 |
# Returns the connection connector |
|
27 | 791 |
def GetConnector(self, position = None, name = None): |
0 | 792 |
return self.Connector |
793 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
794 |
# Changes the variable type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
795 |
def SetType(self, type): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
796 |
if type != self.Type: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
797 |
self.Type = type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
798 |
self.Clean() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
799 |
# Create an input or output connector according to connection type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
800 |
if self.Type == CONNECTOR: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
801 |
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
|
802 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
803 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
804 |
self.RefreshConnectors() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
805 |
|
0 | 806 |
# Returns the connection type |
807 |
def GetType(self): |
|
808 |
return self.Type |
|
809 |
||
145 | 810 |
def GetConnectionResultType(self, connector, connectortype): |
811 |
return connectortype |
|
812 |
||
0 | 813 |
# Changes the connection name |
814 |
def SetName(self, name): |
|
815 |
self.Name = name |
|
42 | 816 |
self.RefreshNameSize() |
0 | 817 |
|
818 |
# Returns the connection name |
|
819 |
def GetName(self): |
|
820 |
return self.Name |
|
821 |
||
822 |
# Returns the connection minimum size |
|
823 |
def GetMinSize(self): |
|
42 | 824 |
text_width, text_height = self.NameSize |
0 | 825 |
if text_height % 2 == 1: |
826 |
text_height += 1 |
|
827 |
return text_width + text_height + 20, text_height + 10 |
|
828 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
829 |
# Method called when a LeftDClick event have been generated |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
830 |
def OnLeftDClick(self, event, dc, scaling): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
831 |
# Edit the connection properties |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
832 |
self.Parent.EditConnectionContent(self) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
833 |
|
0 | 834 |
# Method called when a RightUp event have been generated |
27 | 835 |
def OnRightUp(self, event, dc, scaling): |
0 | 836 |
# Popup the default menu |
837 |
self.Parent.PopupDefaultMenu() |
|
838 |
||
839 |
# Refreshes the connection model |
|
840 |
def RefreshModel(self, move=True): |
|
841 |
self.Parent.RefreshConnectionModel(self) |
|
842 |
# If connection has moved and connection is of type CONTINUATION, refresh |
|
843 |
# the model of wires connected to connector |
|
844 |
if move and self.Type == CONTINUATION: |
|
845 |
if self.Connector: |
|
846 |
self.Connector.RefreshWires() |
|
847 |
||
848 |
# Draws connection |
|
849 |
def Draw(self, dc): |
|
144 | 850 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
851 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
852 |
dc.SetBrush(wx.WHITE_BRUSH) |
213 | 853 |
|
854 |
if getattr(dc, "printing", False): |
|
855 |
name_size = dc.GetTextExtent(self.Name) |
|
856 |
else: |
|
857 |
name_size = self.NameSize |
|
858 |
||
0 | 859 |
# Draw a rectangle with the connection size with arrows in |
860 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
213 | 861 |
arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2) |
0 | 862 |
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
863 |
self.Pos.y + self.Size[1] / 2) |
|
864 |
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, |
|
865 |
self.Pos.x, self.Pos.y + self.Size[1]) |
|
866 |
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
|
867 |
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) |
|
868 |
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, |
|
869 |
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
|
870 |
# Draw connection name |
213 | 871 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
872 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
|
0 | 873 |
# Draw connector |
874 |
if self.Connector: |
|
875 |
self.Connector.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
118
diff
changeset
|
876 |