author | laurent |
Wed, 30 Mar 2011 17:59:54 +0200 | |
changeset 511 | 38fdcbc8ebd7 |
parent 388 | 7ea1f5094df3 |
child 526 | 79900abdfa3c |
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 |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
289
diff
changeset
|
243 |
inputs = connectors.get("inputs", []) |
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
289
diff
changeset
|
244 |
outputs = connectors.get("outputs", []) |
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
245 |
if self.ExecutionControl: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
246 |
inputs.insert(0, ("EN","BOOL","none")) |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
247 |
outputs.insert(0, ("ENO","BOOL","none")) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
# 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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
# 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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
self.Outputs.append(connector) |
42 | 268 |
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
|
269 |
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
|
270 |
self.RefreshBoundingBox() |
2 | 271 |
|
0 | 272 |
# Returns the block type |
273 |
def GetType(self): |
|
274 |
return self.Type |
|
275 |
||
276 |
# Changes the block name |
|
277 |
def SetName(self, name): |
|
278 |
self.Name = name |
|
42 | 279 |
self.RefreshNameSize() |
0 | 280 |
|
281 |
# Returs the block name |
|
282 |
def GetName(self): |
|
283 |
return self.Name |
|
284 |
||
2 | 285 |
# Changes the extension name |
286 |
def SetExtension(self, extension): |
|
287 |
self.Extension = extension |
|
288 |
||
289 |
# Returs the extension name |
|
290 |
def GetExtension(self): |
|
291 |
return self.Extension |
|
292 |
||
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
293 |
# 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
|
294 |
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
|
295 |
self.ExecutionOrder = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
296 |
self.RefreshExecutionOrderSize() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
297 |
|
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
298 |
# 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
|
299 |
def GetExecutionOrder(self): |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
300 |
return self.ExecutionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
301 |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
302 |
# Returs the execution order |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
303 |
def GetExecutionControl(self): |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
304 |
return self.ExecutionControl |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
249
diff
changeset
|
305 |
|
42 | 306 |
# Refresh the block minimum size |
307 |
def RefreshMinSize(self): |
|
0 | 308 |
# Calculate the inputs maximum width |
309 |
max_input = 0 |
|
310 |
for input in self.Inputs: |
|
42 | 311 |
w, h = input.GetNameSize() |
0 | 312 |
max_input = max(max_input, w) |
313 |
# Calculate the outputs maximum width |
|
314 |
max_output = 0 |
|
315 |
for output in self.Outputs: |
|
42 | 316 |
w, h = output.GetNameSize() |
0 | 317 |
max_output = max(max_output, w) |
42 | 318 |
width = max(self.TypeSize[0] + 10, max_input + max_output + 15) |
0 | 319 |
height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE |
42 | 320 |
self.MinSize = width, height |
321 |
||
322 |
# Returns the block minimum size |
|
323 |
def GetMinSize(self): |
|
324 |
return self.MinSize |
|
0 | 325 |
|
326 |
# Changes the negated property of the connector handled |
|
327 |
def SetConnectorNegated(self, negated): |
|
328 |
handle_type, handle = self.Handle |
|
329 |
if handle_type == HANDLE_CONNECTOR: |
|
330 |
handle.SetNegated(negated) |
|
331 |
self.RefreshModel(False) |
|
332 |
||
333 |
# Changes the edge property of the connector handled |
|
334 |
def SetConnectorEdge(self, edge): |
|
335 |
handle_type, handle = self.Handle |
|
336 |
if handle_type == HANDLE_CONNECTOR: |
|
337 |
handle.SetEdge(edge) |
|
338 |
self.RefreshModel(False) |
|
339 |
||
287 | 340 |
## # Method called when a Motion event have been generated |
341 |
## def OnMotion(self, event, dc, scaling): |
|
342 |
## if not event.Dragging(): |
|
343 |
## pos = event.GetLogicalPosition(dc) |
|
344 |
## for input in self.Inputs: |
|
345 |
## rect = input.GetRedrawRect() |
|
346 |
## if rect.InsideXY(pos.x, pos.y): |
|
347 |
## print "Find input" |
|
348 |
## tip = wx.TipWindow(self.Parent, "Test") |
|
349 |
## tip.SetBoundingRect(rect) |
|
350 |
## return Graphic_Element.OnMotion(self, event, dc, scaling) |
|
351 |
||
2 | 352 |
# Method called when a LeftDClick event have been generated |
27 | 353 |
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
|
354 |
# Edit the block properties |
2 | 355 |
self.Parent.EditBlockContent(self) |
356 |
||
0 | 357 |
# Method called when a RightUp event have been generated |
27 | 358 |
def OnRightUp(self, event, dc, scaling): |
359 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 360 |
# 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
|
361 |
connector = self.TestConnector(pos, exclude=False) |
0 | 362 |
if connector: |
363 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
364 |
self.Parent.PopupBlockMenu(connector) |
|
365 |
else: |
|
366 |
self.Parent.PopupBlockMenu() |
|
367 |
||
368 |
# Refreshes the block model |
|
369 |
def RefreshModel(self, move=True): |
|
370 |
self.Parent.RefreshBlockModel(self) |
|
371 |
# If block has moved, refresh the model of wires connected to outputs |
|
372 |
if move: |
|
373 |
for output in self.Outputs: |
|
374 |
output.RefreshWires() |
|
375 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
376 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
377 |
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
|
378 |
self.Errors[infos[0]] = (start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
379 |
elif infos[0] == "input" and infos[1] < len(self.Inputs): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
380 |
self.Inputs[infos[1]].AddError(infos[2:], start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
381 |
elif infos[0] == "output" and infos[1] < len(self.Outputs): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
382 |
self.Outputs[infos[1]].AddError(infos[2:], start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
383 |
|
0 | 384 |
# Draws block |
385 |
def Draw(self, dc): |
|
144 | 386 |
Graphic_Element.Draw(self, dc) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
387 |
dc.SetPen(self.Pen) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
388 |
dc.SetBrush(wx.WHITE_BRUSH) |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
64
diff
changeset
|
389 |
dc.SetTextForeground(self.Colour) |
213 | 390 |
|
391 |
if getattr(dc, "printing", False): |
|
392 |
name_size = dc.GetTextExtent(self.Name) |
|
393 |
type_size = dc.GetTextExtent(self.Type) |
|
394 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
395 |
else: |
|
396 |
name_size = self.NameSize |
|
397 |
type_size = self.TypeSize |
|
398 |
executionorder_size = self.ExecutionOrderSize |
|
399 |
||
0 | 400 |
# Draw a rectangle with the block size |
401 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
402 |
# Draw block name and block type |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
403 |
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
|
404 |
self.Pos.y - (name_size[1] + 2)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
405 |
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
|
406 |
self.Pos.y + 5) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
407 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
408 |
dc.DrawText(self.Type, type_pos[0], type_pos[1]) |
0 | 409 |
# Draw inputs and outputs connectors |
410 |
for input in self.Inputs: |
|
411 |
input.Draw(dc) |
|
412 |
for output in self.Outputs: |
|
413 |
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
|
414 |
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
|
415 |
# Draw block execution order |
213 | 416 |
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
|
417 |
self.Pos.y + self.Size[1] + 2) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
289
diff
changeset
|
418 |
if self.Errors.has_key("name"): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
419 |
HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
289
diff
changeset
|
420 |
if self.Errors.has_key("type"): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
421 |
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
|
422 |
dc.SetTextForeground(wx.BLACK) |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
118
diff
changeset
|
423 |
|
0 | 424 |
|
425 |
#------------------------------------------------------------------------------- |
|
426 |
# Function Block Diagram Variable |
|
427 |
#------------------------------------------------------------------------------- |
|
428 |
||
429 |
""" |
|
430 |
Class that implements the graphic representation of a variable |
|
431 |
""" |
|
432 |
||
433 |
class FBD_Variable(Graphic_Element): |
|
434 |
||
435 |
# 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
|
436 |
def __init__(self, parent, type, name, value_type, id = None, executionOrder = 0): |
0 | 437 |
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
|
438 |
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
|
439 |
self.ValueType = None |
0 | 440 |
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
|
441 |
self.SetName(name) |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
442 |
self.SetExecutionOrder(executionOrder) |
0 | 443 |
self.Input = None |
444 |
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
|
445 |
self.SetType(type, value_type) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
446 |
self.Errors = [] |
0 | 447 |
|
112 | 448 |
# Make a clone of this FBD_Variable |
162 | 449 |
def Clone(self, parent, id = None, pos = None): |
450 |
variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id) |
|
112 | 451 |
variable.SetSize(self.Size[0], self.Size[1]) |
452 |
if pos is not None: |
|
453 |
variable.SetPosition(pos.x, pos.y) |
|
283 | 454 |
else: |
455 |
variable.SetPosition(self.Pos.x, self.Pos.y) |
|
144 | 456 |
if self.Input: |
457 |
variable.Input = self.Input.Clone(variable) |
|
458 |
if self.Output: |
|
459 |
variable.Output = self.Output.Clone(variable) |
|
112 | 460 |
return variable |
461 |
||
283 | 462 |
def GetConnectorTranslation(self, element): |
463 |
connectors = {} |
|
464 |
if self.Input is not None: |
|
287 | 465 |
connectors[self.Input] = element.Input |
283 | 466 |
if self.Output is not None: |
467 |
connectors[self.Output] = element.Output |
|
468 |
return connectors |
|
469 |
||
249 | 470 |
def Flush(self): |
471 |
if self.Input is not None: |
|
472 |
self.Input.Flush() |
|
473 |
self.Input = None |
|
474 |
if self.Output is not None: |
|
475 |
self.Output.Flush() |
|
476 |
self.Output = None |
|
0 | 477 |
|
144 | 478 |
# Returns the RedrawRect |
479 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
480 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
481 |
if movex != 0 or movey != 0: |
|
482 |
if self.Input and self.Input.IsConnected(): |
|
483 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
484 |
if self.Output and self.Output.IsConnected(): |
|
485 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
486 |
return rect |
|
487 |
||
0 | 488 |
# Unconnect connector |
489 |
def Clean(self): |
|
490 |
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
|
491 |
self.Input.UnConnect(delete = True) |
0 | 492 |
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
|
493 |
self.Output.UnConnect(delete = True) |
0 | 494 |
|
495 |
# Delete this variable by calling the appropriate method |
|
496 |
def Delete(self): |
|
497 |
self.Parent.DeleteVariable(self) |
|
498 |
||
42 | 499 |
# Refresh the size of text for name |
500 |
def RefreshNameSize(self): |
|
165 | 501 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 502 |
|
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
503 |
# 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
|
504 |
def RefreshExecutionOrderSize(self): |
165 | 505 |
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
|
506 |
|
0 | 507 |
# Refresh the variable bounding box |
508 |
def RefreshBoundingBox(self): |
|
509 |
if self.Type in (OUTPUT, INOUT): |
|
510 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
511 |
else: |
|
512 |
bbx_x = self.Pos.x |
|
513 |
if self.Type == INOUT: |
|
514 |
bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE |
|
515 |
else: |
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1) |
0 | 523 |
|
524 |
# Refresh the position of the variable connector |
|
525 |
def RefreshConnectors(self): |
|
145 | 526 |
scaling = self.Parent.GetScaling() |
527 |
if scaling is not None: |
|
528 |
position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
529 |
else: |
|
530 |
position = self.Size[1] / 2 |
|
0 | 531 |
if self.Input: |
145 | 532 |
self.Input.SetPosition(wx.Point(0, position)) |
0 | 533 |
if self.Output: |
145 | 534 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
535 |
self.RefreshConnected() |
0 | 536 |
|
537 |
# Refresh the position of wires connected to connector |
|
538 |
def RefreshConnected(self, exclude = []): |
|
539 |
if self.Input: |
|
540 |
self.Input.MoveConnected(exclude) |
|
541 |
if self.Output: |
|
542 |
self.Output.MoveConnected(exclude) |
|
543 |
||
544 |
# 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
|
545 |
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
|
546 |
if self.Input and self.Input.TestPoint(pt, direction, exclude): |
0 | 547 |
return self.Input |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
548 |
if self.Output and self.Output.TestPoint(pt, direction, exclude): |
0 | 549 |
return self.Output |
550 |
return None |
|
551 |
||
552 |
# Returns the block connector that starts with the point given if it exists |
|
27 | 553 |
def GetConnector(self, position, name = None): |
554 |
# if a name is given |
|
555 |
if name: |
|
556 |
# Test input and output connector if they exists |
|
557 |
if self.Input and name == self.Input.GetName(): |
|
558 |
return self.Input |
|
559 |
if self.Output and name == self.Output.GetName(): |
|
560 |
return self.Output |
|
0 | 561 |
# Test input connector if it exists |
562 |
if self.Input: |
|
563 |
input_pos = self.Input.GetRelPosition() |
|
564 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
565 |
return self.Input |
|
566 |
# Test output connector if it exists |
|
567 |
if self.Output: |
|
568 |
output_pos = self.Output.GetRelPosition() |
|
569 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
570 |
return self.Output |
|
571 |
return None |
|
572 |
||
573 |
# Returns all the block connectors |
|
574 |
def GetConnectors(self): |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
575 |
connectors = {"inputs": [], "outputs": []} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
576 |
if self.Input: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
577 |
connectors["inputs"].append(self.Input) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
578 |
if self.Output: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
579 |
connectors["outputs"].append(self.Output) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
580 |
return connectors |
0 | 581 |
|
582 |
# Changes the negated property of the variable connector if handled |
|
583 |
def SetConnectorNegated(self, negated): |
|
584 |
handle_type, handle = self.Handle |
|
585 |
if handle_type == HANDLE_CONNECTOR: |
|
586 |
handle.SetNegated(negated) |
|
587 |
self.RefreshModel(False) |
|
588 |
||
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
589 |
# 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
|
590 |
def SetType(self, type, value_type): |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
591 |
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
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
# 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
|
597 |
if self.Type != INPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
598 |
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
|
599 |
if self.Type != OUTPUT: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
600 |
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
|
601 |
self.RefreshConnectors() |
32
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
602 |
elif value_type != self.ValueType: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
603 |
if self.Input: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
604 |
self.Input.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
605 |
if self.Output: |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
606 |
self.Output.SetType(value_type) |
cf9efccff009
FBD_Variable don't remove wire when just expression changed
lbessard
parents:
28
diff
changeset
|
607 |
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
|
608 |
|
0 | 609 |
# Returns the variable type |
610 |
def GetType(self): |
|
611 |
return self.Type |
|
612 |
||
613 |
# Changes the variable name |
|
614 |
def SetName(self, name): |
|
615 |
self.Name = name |
|
42 | 616 |
self.RefreshNameSize() |
0 | 617 |
|
618 |
# Returns the variable name |
|
619 |
def GetName(self): |
|
620 |
return self.Name |
|
621 |
||
118
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
622 |
# 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
|
623 |
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
|
624 |
self.ExecutionOrder = executionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
625 |
self.RefreshExecutionOrderSize() |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
626 |
|
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
627 |
# 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
|
628 |
def GetExecutionOrder(self): |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
629 |
return self.ExecutionOrder |
0c53d6a36013
Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents:
112
diff
changeset
|
630 |
|
0 | 631 |
# Returns the variable minimum size |
632 |
def GetMinSize(self): |
|
42 | 633 |
return self.NameSize[0] + 10, self.NameSize[1] + 10 |
0 | 634 |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
635 |
# Method called when a LeftDClick event have been generated |
27 | 636 |
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
|
637 |
# 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
|
638 |
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
|
639 |
|
0 | 640 |
# Method called when a RightUp event have been generated |
27 | 641 |
def OnRightUp(self, event, dc, scaling): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
642 |
self.Parent.PopupDefaultMenu() |
0 | 643 |
|
644 |
# Refreshes the variable model |
|
645 |
def RefreshModel(self, move=True): |
|
646 |
self.Parent.RefreshVariableModel(self) |
|
647 |
# If variable has moved and variable is not of type OUTPUT, refresh the model |
|
648 |
# of wires connected to output connector |
|
649 |
if move and self.Type != OUTPUT: |
|
650 |
if self.Output: |
|
651 |
self.Output.RefreshWires() |
|
652 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
653 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
654 |
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
|
655 |
self.Errors.append((start[1], end[1])) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
656 |
|
0 | 657 |
# Draws variable |
658 |
def Draw(self, dc): |
|
144 | 659 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
660 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
661 |
dc.SetBrush(wx.WHITE_BRUSH) |
213 | 662 |
|
663 |
if getattr(dc, "printing", False): |
|
664 |
name_size = dc.GetTextExtent(self.Name) |
|
665 |
executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) |
|
666 |
else: |
|
667 |
name_size = self.NameSize |
|
668 |
executionorder_size = self.ExecutionOrderSize |
|
669 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
670 |
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
|
671 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
0 | 672 |
# Draw a rectangle with the variable size |
673 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
674 |
# Draw variable name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
675 |
dc.DrawText(self.Name, text_pos[0], text_pos[1]) |
0 | 676 |
# Draw connectors |
677 |
if self.Input: |
|
678 |
self.Input.Draw(dc) |
|
679 |
if self.Output: |
|
680 |
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
|
681 |
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
|
682 |
# Draw variable execution order |
213 | 683 |
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
|
684 |
self.Pos.y + self.Size[1] + 2) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
685 |
for start, end in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
686 |
offset = dc.GetTextExtent(self.Name[:start]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
687 |
size = dc.GetTextExtent(self.Name[start:end + 1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
688 |
HighlightErrorZone(dc, text_pos[0] + offset[0], text_pos[1], size[0], size[1]) |
0 | 689 |
|
690 |
#------------------------------------------------------------------------------- |
|
691 |
# Function Block Diagram Connector |
|
692 |
#------------------------------------------------------------------------------- |
|
693 |
||
694 |
""" |
|
695 |
Class that implements the graphic representation of a connection |
|
696 |
""" |
|
697 |
||
698 |
class FBD_Connector(Graphic_Element): |
|
699 |
||
700 |
# Create a new connection |
|
701 |
def __init__(self, parent, type, name, id = None): |
|
702 |
Graphic_Element.__init__(self, parent) |
|
703 |
self.Type = type |
|
704 |
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
|
705 |
self.SetName(name) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
706 |
self.Pos = wx.Point(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
707 |
self.Size = wx.Size(0, 0) |
0 | 708 |
# Create an input or output connector according to connection type |
709 |
if self.Type == CONNECTOR: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
710 |
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
|
711 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
712 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
0 | 713 |
self.RefreshConnectors() |
42 | 714 |
self.RefreshNameSize() |
0 | 715 |
|
249 | 716 |
def Flush(self): |
717 |
if self.Connector: |
|
718 |
self.Connector.Flush() |
|
719 |
self.Connector = None |
|
0 | 720 |
|
144 | 721 |
# Returns the RedrawRect |
722 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
723 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
724 |
if movex != 0 or movey != 0: |
|
725 |
if self.Connector and self.Connector.IsConnected(): |
|
726 |
rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) |
|
727 |
return rect |
|
728 |
||
112 | 729 |
# Make a clone of this FBD_Connector |
162 | 730 |
def Clone(self, parent, id = None, pos = None): |
731 |
connection = FBD_Connector(parent, self.Type, self.Name, id) |
|
112 | 732 |
connection.SetSize(self.Size[0], self.Size[1]) |
733 |
if pos is not None: |
|
734 |
connection.SetPosition(pos.x, pos.y) |
|
283 | 735 |
else: |
736 |
connection.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 737 |
connection.Connector = self.Connector.Clone(connection) |
738 |
return connection |
|
739 |
||
283 | 740 |
def GetConnectorTranslation(self, element): |
741 |
return {self.Connector : element.Connector} |
|
742 |
||
0 | 743 |
# Unconnect connector |
744 |
def Clean(self): |
|
745 |
if self.Connector: |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
746 |
self.Connector.UnConnect(delete = True) |
0 | 747 |
|
748 |
# Delete this connection by calling the appropriate method |
|
749 |
def Delete(self): |
|
750 |
self.Parent.DeleteConnection(self) |
|
751 |
||
42 | 752 |
# Refresh the size of text for name |
753 |
def RefreshNameSize(self): |
|
165 | 754 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 755 |
|
0 | 756 |
# Refresh the connection bounding box |
757 |
def RefreshBoundingBox(self): |
|
758 |
if self.Type == CONNECTOR: |
|
759 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
|
760 |
else: |
|
761 |
bbx_x = self.Pos.x |
|
762 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
763 |
self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) |
0 | 764 |
|
765 |
# Refresh the position of the connection connector |
|
766 |
def RefreshConnectors(self): |
|
145 | 767 |
scaling = self.Parent.GetScaling() |
768 |
if scaling is not None: |
|
769 |
position = round(float(self.Pos.y + self.Size[1] / 2) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
770 |
else: |
|
771 |
position = self.Size[1] / 2 |
|
0 | 772 |
if self.Type == CONNECTOR: |
145 | 773 |
self.Connector.SetPosition(wx.Point(0, position)) |
774 |
else: |
|
775 |
self.Connector.SetPosition(wx.Point(self.Size[0], position)) |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
776 |
self.RefreshConnected() |
0 | 777 |
|
778 |
# Refresh the position of wires connected to connector |
|
779 |
def RefreshConnected(self, exclude = []): |
|
780 |
if self.Connector: |
|
781 |
self.Connector.MoveConnected(exclude) |
|
782 |
||
783 |
# 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
|
784 |
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
|
785 |
if self.Connector and self.Connector.TestPoint(pt, direction, exclude): |
0 | 786 |
return self.Connector |
787 |
return None |
|
788 |
||
789 |
# Returns the connection connector |
|
27 | 790 |
def GetConnector(self, position = None, name = None): |
0 | 791 |
return self.Connector |
792 |
||
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
793 |
# Returns all the block connectors |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
794 |
def GetConnectors(self): |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
795 |
connectors = {"inputs": [], "outputs": []} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
796 |
if self.Type == CONNECTOR: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
797 |
connectors["inputs"].append(self.Connector) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
798 |
else: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
799 |
connectors["outputs"].append(self.Connector) |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
800 |
return connectors |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
379
diff
changeset
|
801 |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
802 |
# Changes the variable type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
803 |
def SetType(self, type): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
804 |
if type != self.Type: |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
805 |
self.Type = type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
806 |
self.Clean() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
807 |
# Create an input or output connector according to connection type |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
808 |
if self.Type == CONNECTOR: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
809 |
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
|
810 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
811 |
self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
812 |
self.RefreshConnectors() |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
813 |
|
0 | 814 |
# Returns the connection type |
815 |
def GetType(self): |
|
816 |
return self.Type |
|
817 |
||
145 | 818 |
def GetConnectionResultType(self, connector, connectortype): |
388
7ea1f5094df3
Adding support for testing type between element connected with connector/continuation
laurent
parents:
383
diff
changeset
|
819 |
if self.Type == CONTINUATION: |
7ea1f5094df3
Adding support for testing type between element connected with connector/continuation
laurent
parents:
383
diff
changeset
|
820 |
connector = self.Parent.GetConnectorByName(self.Name) |
7ea1f5094df3
Adding support for testing type between element connected with connector/continuation
laurent
parents:
383
diff
changeset
|
821 |
if connector is not None: |
7ea1f5094df3
Adding support for testing type between element connected with connector/continuation
laurent
parents:
383
diff
changeset
|
822 |
return connector.Connector.GetConnectedType() |
145 | 823 |
return connectortype |
824 |
||
0 | 825 |
# Changes the connection name |
826 |
def SetName(self, name): |
|
827 |
self.Name = name |
|
42 | 828 |
self.RefreshNameSize() |
0 | 829 |
|
830 |
# Returns the connection name |
|
831 |
def GetName(self): |
|
832 |
return self.Name |
|
833 |
||
834 |
# Returns the connection minimum size |
|
835 |
def GetMinSize(self): |
|
42 | 836 |
text_width, text_height = self.NameSize |
0 | 837 |
if text_height % 2 == 1: |
838 |
text_height += 1 |
|
839 |
return text_width + text_height + 20, text_height + 10 |
|
840 |
||
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
841 |
# Method called when a LeftDClick event have been generated |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
842 |
def OnLeftDClick(self, event, dc, scaling): |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
843 |
# Edit the connection properties |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
844 |
self.Parent.EditConnectionContent(self) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
845 |
|
0 | 846 |
# Method called when a RightUp event have been generated |
27 | 847 |
def OnRightUp(self, event, dc, scaling): |
0 | 848 |
# Popup the default menu |
849 |
self.Parent.PopupDefaultMenu() |
|
850 |
||
851 |
# Refreshes the connection model |
|
852 |
def RefreshModel(self, move=True): |
|
853 |
self.Parent.RefreshConnectionModel(self) |
|
854 |
# If connection has moved and connection is of type CONTINUATION, refresh |
|
855 |
# the model of wires connected to connector |
|
856 |
if move and self.Type == CONTINUATION: |
|
857 |
if self.Connector: |
|
858 |
self.Connector.RefreshWires() |
|
859 |
||
860 |
# Draws connection |
|
861 |
def Draw(self, dc): |
|
144 | 862 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
863 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
864 |
dc.SetBrush(wx.WHITE_BRUSH) |
213 | 865 |
|
866 |
if getattr(dc, "printing", False): |
|
867 |
name_size = dc.GetTextExtent(self.Name) |
|
868 |
else: |
|
869 |
name_size = self.NameSize |
|
870 |
||
379
e4c26ee9c998
Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents:
289
diff
changeset
|
871 |
# Draw a rectangle with the connection size with arrows inside |
0 | 872 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
213 | 873 |
arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2) |
0 | 874 |
dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, |
875 |
self.Pos.y + self.Size[1] / 2) |
|
876 |
dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, |
|
877 |
self.Pos.x, self.Pos.y + self.Size[1]) |
|
878 |
dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, |
|
879 |
self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) |
|
880 |
dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, |
|
881 |
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
|
882 |
# Draw connection name |
213 | 883 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
884 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
|
0 | 885 |
# Draw connector |
886 |
if self.Connector: |
|
887 |
self.Connector.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
118
diff
changeset
|
888 |