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