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