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