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