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