author | lbessard |
Thu, 09 Apr 2009 15:34:35 +0200 | |
changeset 341 | 88030497e29e |
parent 327 | 7fd5233ce5ce |
child 361 | 62570186dad4 |
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 |
def GetWireSize(block): |
|
31 |
if isinstance(block, SFC_Step): |
|
32 |
return SFC_WIRE_MIN_SIZE + block.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
|
33 |
else: |
|
34 |
return SFC_WIRE_MIN_SIZE |
|
35 |
||
36 |
#------------------------------------------------------------------------------- |
|
37 |
# Sequencial Function Chart Step |
|
38 |
#------------------------------------------------------------------------------- |
|
39 |
||
40 |
""" |
|
41 |
Class that implements the graphic representation of a step |
|
42 |
""" |
|
43 |
||
44 |
class SFC_Step(Graphic_Element): |
|
45 |
||
46 |
# Create a new step |
|
47 |
def __init__(self, parent, name, initial = False, id = None): |
|
48 |
Graphic_Element.__init__(self, parent) |
|
213 | 49 |
self.SetName(name) |
0 | 50 |
self.Initial = initial |
51 |
self.Id = id |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
52 |
self.Error = None |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
53 |
self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
0 | 54 |
# Create an input and output connector |
55 |
if not self.Initial: |
|
108 | 56 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
0 | 57 |
else: |
58 |
self.Input = None |
|
59 |
self.Output = None |
|
60 |
self.Action = None |
|
253 | 61 |
self.Value = None |
62 |
self.PreviousValue = None |
|
63 |
self.PreviousSpreading = False |
|
0 | 64 |
|
249 | 65 |
def Flush(self): |
66 |
if self.Input is not None: |
|
67 |
self.Input.Flush() |
|
68 |
self.Input = None |
|
69 |
if self.Output is not None: |
|
70 |
self.Output.Flush() |
|
71 |
self.Output = None |
|
72 |
if self.Output is not None: |
|
73 |
self.Action.Flush() |
|
74 |
self.Action = None |
|
0 | 75 |
|
253 | 76 |
def SetValue(self, value): |
77 |
self.PreviousValue = self.Value |
|
78 |
self.Value = value |
|
79 |
if self.Value != self.PreviousValue: |
|
80 |
self.Refresh() |
|
81 |
self.SpreadCurrent() |
|
82 |
||
83 |
def SpreadCurrent(self): |
|
84 |
if self.Parent.Debug: |
|
85 |
spreading = self.Value |
|
86 |
if spreading and not self.PreviousSpreading: |
|
263 | 87 |
if self.Output is not None: |
88 |
self.Output.SpreadCurrent(True) |
|
253 | 89 |
if self.Action is not None: |
90 |
self.Action.SpreadCurrent(True) |
|
91 |
elif not spreading and self.PreviousSpreading: |
|
263 | 92 |
if self.Output is not None: |
93 |
self.Output.SpreadCurrent(False) |
|
253 | 94 |
if self.Action is not None: |
95 |
self.Action.SpreadCurrent(False) |
|
96 |
self.PreviousSpreading = spreading |
|
97 |
||
112 | 98 |
# Make a clone of this SFC_Step |
162 | 99 |
def Clone(self, parent, id = None, name = "Step", pos = None): |
100 |
step = SFC_Step(parent, name, self.Initial, id) |
|
112 | 101 |
step.SetSize(self.Size[0], self.Size[1]) |
102 |
if pos is not None: |
|
103 |
step.SetPosition(pos.x, pos.y) |
|
283 | 104 |
else: |
105 |
step.SetPosition(self.Pos.x, self.Pos.y) |
|
144 | 106 |
if self.Input: |
107 |
step.Input = self.Input.Clone(step) |
|
108 |
if self.Output: |
|
109 |
step.Output = self.Output.Clone(step) |
|
110 |
if self.Action: |
|
111 |
step.Action = self.Action.Clone(step) |
|
112 | 112 |
return step |
113 |
||
283 | 114 |
def GetConnectorTranslation(self, element): |
115 |
connectors = {} |
|
116 |
if self.Input is not None: |
|
287 | 117 |
connectors[self.Input] = element.Input |
283 | 118 |
if self.Output is not None: |
119 |
connectors[self.Output] = element.Output |
|
120 |
if self.Action is not None: |
|
121 |
connectors[self.Action] = element.Action |
|
122 |
return connectors |
|
123 |
||
144 | 124 |
# Returns the RedrawRect |
125 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
126 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
127 |
if self.Input: |
|
128 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
129 |
if self.Output: |
|
130 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
131 |
if self.Action: |
|
132 |
rect = rect.Union(self.Action.GetRedrawRect(movex, movey)) |
|
133 |
if movex != 0 or movey != 0: |
|
134 |
if self.Input and self.Input.IsConnected(): |
|
135 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
136 |
if self.Output and self.Output.IsConnected(): |
|
137 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
138 |
if self.Action and self.Action.IsConnected(): |
|
139 |
rect = rect.Union(self.Action.GetConnectedRedrawRect(movex, movey)) |
|
140 |
return rect |
|
141 |
||
0 | 142 |
# Delete this step by calling the appropriate method |
143 |
def Delete(self): |
|
144 |
self.Parent.DeleteStep(self) |
|
145 |
||
146 |
# Unconnect input and output |
|
147 |
def Clean(self): |
|
148 |
if self.Input: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
149 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 150 |
if self.Output: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
151 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 152 |
if self.Action: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
153 |
self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 154 |
|
213 | 155 |
# Refresh the size of text for name |
156 |
def RefreshNameSize(self): |
|
157 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
|
158 |
||
0 | 159 |
# Add output connector to step |
71 | 160 |
def AddInput(self): |
161 |
if not self.Input: |
|
108 | 162 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
71 | 163 |
self.RefreshBoundingBox() |
164 |
||
165 |
# Remove output connector from step |
|
166 |
def RemoveInput(self): |
|
167 |
if self.Input: |
|
154 | 168 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
71 | 169 |
self.Input = None |
170 |
self.RefreshBoundingBox() |
|
171 |
||
172 |
# Add output connector to step |
|
0 | 173 |
def AddOutput(self): |
174 |
if not self.Output: |
|
145 | 175 |
self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) |
0 | 176 |
self.RefreshBoundingBox() |
177 |
||
178 |
# Remove output connector from step |
|
179 |
def RemoveOutput(self): |
|
180 |
if self.Output: |
|
154 | 181 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 182 |
self.Output = None |
183 |
self.RefreshBoundingBox() |
|
184 |
||
185 |
# Add action connector to step |
|
186 |
def AddAction(self): |
|
187 |
if not self.Action: |
|
145 | 188 |
self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST, onlyone = True) |
0 | 189 |
self.RefreshBoundingBox() |
190 |
||
191 |
# Remove action connector from step |
|
192 |
def RemoveAction(self): |
|
193 |
if self.Action: |
|
154 | 194 |
self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 195 |
self.Action = None |
196 |
self.RefreshBoundingBox() |
|
197 |
||
198 |
# Refresh the step bounding box |
|
199 |
def RefreshBoundingBox(self): |
|
200 |
# Calculate the bounding box size |
|
201 |
if self.Action: |
|
202 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
203 |
else: |
|
204 |
bbx_width = self.Size[0] |
|
205 |
if self.Initial: |
|
206 |
bbx_y = self.Pos.y |
|
207 |
bbx_height = self.Size[1] |
|
208 |
if self.Output: |
|
209 |
bbx_height += CONNECTOR_SIZE |
|
210 |
else: |
|
211 |
bbx_y = self.Pos.y - CONNECTOR_SIZE |
|
212 |
bbx_height = self.Size[1] + CONNECTOR_SIZE |
|
213 |
if self.Output: |
|
214 |
bbx_height += CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
215 |
#self.BoundingBox = wx.Rect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
216 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 217 |
|
218 |
# Refresh the positions of the step connectors |
|
219 |
def RefreshConnectors(self): |
|
145 | 220 |
scaling = self.Parent.GetScaling() |
221 |
horizontal_pos = self.Size[0] / 2 |
|
222 |
vertical_pos = self.Size[1] / 2 |
|
223 |
if scaling is not None: |
|
224 |
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
225 |
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
0 | 226 |
# Update input position if it exists |
227 |
if self.Input: |
|
145 | 228 |
self.Input.SetPosition(wx.Point(horizontal_pos, 0)) |
0 | 229 |
# Update output position |
230 |
if self.Output: |
|
145 | 231 |
self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) |
0 | 232 |
# Update action position if it exists |
233 |
if self.Action: |
|
145 | 234 |
self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos)) |
0 | 235 |
self.RefreshConnected() |
236 |
||
237 |
# Refresh the position of wires connected to step |
|
238 |
def RefreshConnected(self, exclude = []): |
|
239 |
if self.Input: |
|
240 |
self.Input.MoveConnected(exclude) |
|
241 |
if self.Output: |
|
242 |
self.Output.MoveConnected(exclude) |
|
243 |
if self.Action: |
|
244 |
self.Action.MoveConnected(exclude) |
|
245 |
||
246 |
# Returns the step connector that starts with the point given if it exists |
|
27 | 247 |
def GetConnector(self, position, name = None): |
248 |
# if a name is given |
|
249 |
if name: |
|
250 |
# Test input, output and action connector if they exists |
|
251 |
if self.Input and name == self.Input.GetName(): |
|
252 |
return self.Input |
|
253 |
if self.Output and name == self.Output.GetName(): |
|
254 |
return self.Output |
|
255 |
if self.Action and name == self.Action.GetName(): |
|
256 |
return self.Action |
|
0 | 257 |
# Test input connector if it exists |
258 |
if self.Input: |
|
259 |
input_pos = self.Input.GetRelPosition() |
|
260 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
261 |
return self.Input |
|
262 |
# Test output connector if it exists |
|
263 |
if self.Output: |
|
264 |
output_pos = self.Output.GetRelPosition() |
|
265 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
266 |
return self.Output |
|
267 |
# Test action connector if it exists |
|
268 |
if self.Action: |
|
269 |
action_pos = self.Action.GetRelPosition() |
|
270 |
if position.x == self.Pos.x + action_pos.x and position.y == self.Pos.y + action_pos.y: |
|
271 |
return self.Action |
|
272 |
return None |
|
273 |
||
274 |
# Returns input and output step connectors |
|
275 |
def GetConnectors(self): |
|
276 |
return {"input":self.Input,"output":self.Output,"action":self.Action} |
|
277 |
||
278 |
# Test if point given is on step input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
279 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 280 |
# Test input connector if it exists |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
281 |
if self.Input and self.Input.TestPoint(pt, direction, exclude): |
0 | 282 |
return self.Input |
283 |
# Test output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
284 |
if self.Output and self.Output.TestPoint(pt, direction, exclude): |
0 | 285 |
return self.Output |
108 | 286 |
# Test action connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
287 |
if self.Action and self.Action.TestPoint(pt, direction, exclude): |
108 | 288 |
return self.Action |
0 | 289 |
return None |
290 |
||
291 |
# Changes the step name |
|
292 |
def SetName(self, name): |
|
293 |
self.Name = name |
|
213 | 294 |
self.RefreshNameSize() |
0 | 295 |
|
296 |
# Returns the step name |
|
297 |
def GetName(self): |
|
298 |
return self.Name |
|
299 |
||
300 |
# Returns the step initial property |
|
301 |
def GetInitial(self): |
|
302 |
return self.Initial |
|
303 |
||
304 |
# Returns the connector connected to input |
|
305 |
def GetPreviousConnector(self): |
|
306 |
if self.Input: |
|
307 |
wires = self.Input.GetWires() |
|
308 |
if len(wires) == 1: |
|
145 | 309 |
return wires[0][0].GetOtherConnected(self.Input) |
0 | 310 |
return None |
311 |
||
312 |
# Returns the connector connected to output |
|
313 |
def GetNextConnector(self): |
|
314 |
if self.Output: |
|
315 |
wires = self.Output.GetWires() |
|
316 |
if len(wires) == 1: |
|
145 | 317 |
return wires[0][0].GetOtherConnected(self.Output) |
0 | 318 |
return None |
319 |
||
320 |
# Returns the connector connected to action |
|
321 |
def GetActionConnector(self): |
|
322 |
if self.Action: |
|
323 |
wires = self.Action.GetWires() |
|
324 |
if len(wires) == 1: |
|
145 | 325 |
return wires[0][0].GetOtherConnected(self.Action) |
0 | 326 |
return None |
327 |
||
328 |
# Returns the number of action line |
|
329 |
def GetActionExtraLineNumber(self): |
|
330 |
if self.Action: |
|
331 |
wires = self.Action.GetWires() |
|
332 |
if len(wires) != 1: |
|
333 |
return 0 |
|
145 | 334 |
action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock() |
0 | 335 |
return max(0, action_block.GetLineNumber() - 1) |
336 |
return 0 |
|
337 |
||
338 |
# Returns the step minimum size |
|
339 |
def GetMinSize(self): |
|
165 | 340 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 341 |
if self.Initial: |
342 |
return text_width + 14, text_height + 14 |
|
343 |
else: |
|
344 |
return text_width + 10, text_height + 10 |
|
345 |
||
346 |
# Updates the step size |
|
347 |
def UpdateSize(self, width, height): |
|
348 |
diffx = self.Size.GetWidth() / 2 - width / 2 |
|
349 |
diffy = height - self.Size.GetHeight() |
|
350 |
self.Move(diffx, 0) |
|
351 |
Graphic_Element.SetSize(self, width, height) |
|
108 | 352 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
353 |
self.RefreshConnected() |
|
354 |
else: |
|
355 |
self.RefreshOutputPosition((0, diffy)) |
|
0 | 356 |
|
357 |
# Align input element with this step |
|
358 |
def RefreshInputPosition(self): |
|
359 |
if self.Input: |
|
360 |
current_pos = self.Input.GetPosition(False) |
|
361 |
input = self.GetPreviousConnector() |
|
362 |
if input: |
|
363 |
input_pos = input.GetPosition(False) |
|
364 |
diffx = current_pos.x - input_pos.x |
|
365 |
input_block = input.GetParentBlock() |
|
366 |
if isinstance(input_block, SFC_Divergence): |
|
367 |
input_block.MoveConnector(input, diffx) |
|
368 |
else: |
|
369 |
if isinstance(input_block, SFC_Step): |
|
370 |
input_block.MoveActionBlock((diffx, 0)) |
|
371 |
input_block.Move(diffx, 0) |
|
372 |
input_block.RefreshInputPosition() |
|
373 |
||
374 |
# Align output element with this step |
|
375 |
def RefreshOutputPosition(self, move = None): |
|
376 |
if self.Output: |
|
377 |
wires = self.Output.GetWires() |
|
378 |
if len(wires) != 1: |
|
379 |
return |
|
380 |
current_pos = self.Output.GetPosition(False) |
|
145 | 381 |
output = wires[0][0].GetOtherConnected(self.Output) |
0 | 382 |
output_pos = output.GetPosition(False) |
383 |
diffx = current_pos.x - output_pos.x |
|
384 |
output_block = output.GetParentBlock() |
|
385 |
wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
|
386 |
diffy = wire_size - output_pos.y + current_pos.y |
|
387 |
if diffy != 0: |
|
388 |
if isinstance(output_block, SFC_Step): |
|
389 |
output_block.MoveActionBlock((diffx, diffy)) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
390 |
wires[0][0].SetPoints([wx.Point(current_pos.x, current_pos.y + wire_size), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
391 |
wx.Point(current_pos.x, current_pos.y)]) |
0 | 392 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
393 |
output_block.Move(diffx, diffy, self.Parent.Wires) |
|
394 |
output_block.RefreshOutputPosition((diffx, diffy)) |
|
395 |
else: |
|
396 |
output_block.RefreshPosition() |
|
397 |
elif move: |
|
398 |
if isinstance(output_block, SFC_Step): |
|
399 |
output_block.MoveActionBlock(move) |
|
400 |
wires[0][0].Move(move[0], move[1], True) |
|
401 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
402 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
403 |
output_block.RefreshOutputPosition(move) |
|
404 |
else: |
|
405 |
output_block.RefreshPosition() |
|
406 |
elif isinstance(output_block, SFC_Divergence): |
|
407 |
output_block.MoveConnector(output, diffx) |
|
408 |
else: |
|
409 |
if isinstance(output_block, SFC_Step): |
|
410 |
output_block.MoveActionBlock((diffx, 0)) |
|
411 |
output_block.Move(diffx, 0) |
|
412 |
output_block.RefreshOutputPosition() |
|
413 |
||
414 |
# Refresh action element with this step |
|
415 |
def MoveActionBlock(self, move): |
|
416 |
if self.Action: |
|
417 |
wires = self.Action.GetWires() |
|
418 |
if len(wires) != 1: |
|
419 |
return |
|
145 | 420 |
action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock() |
0 | 421 |
action_block.Move(move[0], move[1], self.Parent.Wires) |
422 |
wires[0][0].Move(move[0], move[1], True) |
|
423 |
||
424 |
# Resize the divergence from position and size given |
|
425 |
def Resize(self, x, y, width, height): |
|
27 | 426 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
427 |
self.UpdateSize(width, height) |
|
428 |
else: |
|
429 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 430 |
|
431 |
# Method called when a LeftDClick event have been generated |
|
42 | 432 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 433 |
# Edit the step properties |
434 |
self.Parent.EditStepContent(self) |
|
435 |
||
436 |
# Method called when a RightUp event have been generated |
|
27 | 437 |
def OnRightUp(self, event, dc, scaling): |
0 | 438 |
# Popup the menu with special items for a step |
439 |
self.Parent.PopupDefaultMenu() |
|
440 |
||
441 |
# Refreshes the step state according to move defined and handle selected |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
442 |
def ProcessDragging(self, movex, movey, event, scaling): |
0 | 443 |
handle_type, handle = self.Handle |
444 |
if handle_type == HANDLE_MOVE: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
445 |
movex = max(-self.BoundingBox.x, movex) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
446 |
movey = max(-self.BoundingBox.y, movey) |
145 | 447 |
if scaling is not None: |
448 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
449 |
movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
0 | 450 |
action_block = None |
27 | 451 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
452 |
self.Move(movex, movey) |
|
453 |
self.RefreshConnected() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
454 |
return movex, movey |
27 | 455 |
elif self.Initial: |
0 | 456 |
self.MoveActionBlock((movex, movey)) |
457 |
self.Move(movex, movey, self.Parent.Wires) |
|
458 |
self.RefreshOutputPosition((movex, movey)) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
459 |
return movex, movey |
0 | 460 |
else: |
461 |
self.MoveActionBlock((movex, 0)) |
|
462 |
self.Move(movex, 0) |
|
463 |
self.RefreshInputPosition() |
|
464 |
self.RefreshOutputPosition() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
465 |
return movex, 0 |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
466 |
else: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
467 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
0 | 468 |
|
469 |
# Refresh input element model |
|
470 |
def RefreshInputModel(self): |
|
471 |
if self.Input: |
|
472 |
input = self.GetPreviousConnector() |
|
473 |
if input: |
|
474 |
input_block = input.GetParentBlock() |
|
475 |
input_block.RefreshModel(False) |
|
476 |
if not isinstance(input_block, SFC_Divergence): |
|
477 |
input_block.RefreshInputModel() |
|
478 |
||
479 |
# Refresh output element model |
|
480 |
def RefreshOutputModel(self, move=False): |
|
481 |
if self.Output: |
|
482 |
output = self.GetNextConnector() |
|
483 |
if output: |
|
484 |
output_block = output.GetParentBlock() |
|
485 |
output_block.RefreshModel(False) |
|
486 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
487 |
output_block.RefreshOutputModel(move) |
|
488 |
||
489 |
# Refreshes the step model |
|
490 |
def RefreshModel(self, move=True): |
|
491 |
self.Parent.RefreshStepModel(self) |
|
492 |
if self.Action: |
|
493 |
action = self.GetActionConnector() |
|
494 |
if action: |
|
495 |
action_block = action.GetParentBlock() |
|
496 |
action_block.RefreshModel(False) |
|
497 |
# If step has moved, refresh the model of wires connected to output |
|
498 |
if move: |
|
27 | 499 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
500 |
self.RefreshInputModel() |
|
501 |
self.RefreshOutputModel(self.Initial) |
|
502 |
elif self.Output: |
|
503 |
self.Output.RefreshWires() |
|
0 | 504 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
505 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
506 |
if infos[0] == "name" and start[0] == 0 and end[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
507 |
self.Error = (start[1], end[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
508 |
|
0 | 509 |
# Draws step |
510 |
def Draw(self, dc): |
|
144 | 511 |
Graphic_Element.Draw(self, dc) |
253 | 512 |
if self.Value: |
513 |
dc.SetPen(wx.GREEN_PEN) |
|
514 |
else: |
|
515 |
dc.SetPen(wx.BLACK_PEN) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
516 |
dc.SetBrush(wx.WHITE_BRUSH) |
213 | 517 |
|
518 |
if getattr(dc, "printing", False): |
|
519 |
name_size = dc.GetTextExtent(self.Name) |
|
520 |
else: |
|
521 |
name_size = self.NameSize |
|
522 |
||
0 | 523 |
# Draw two rectangles for representing the step |
524 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
525 |
if self.Initial: |
|
526 |
dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
|
527 |
# Draw step name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
528 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
213 | 529 |
self.Pos.y + (self.Size[1] - name_size[1]) / 2) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
530 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
0 | 531 |
# Draw input and output connectors |
532 |
if self.Input: |
|
533 |
self.Input.Draw(dc) |
|
534 |
if self.Output: |
|
535 |
self.Output.Draw(dc) |
|
536 |
if self.Action: |
|
537 |
self.Action.Draw(dc) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
538 |
if self.Error is not None: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
539 |
HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
540 |
|
0 | 541 |
|
542 |
#------------------------------------------------------------------------------- |
|
543 |
# Sequencial Function Chart Transition |
|
544 |
#------------------------------------------------------------------------------- |
|
545 |
||
546 |
""" |
|
547 |
Class that implements the graphic representation of a transition |
|
548 |
""" |
|
549 |
||
550 |
class SFC_Transition(Graphic_Element): |
|
551 |
||
552 |
# Create a new transition |
|
80 | 553 |
def __init__(self, parent, type = "reference", condition = None, priority = 0, id = None): |
0 | 554 |
Graphic_Element.__init__(self, parent) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
555 |
self.Type = None |
0 | 556 |
self.Id = id |
80 | 557 |
self.Priority = 0 |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
558 |
self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) |
0 | 559 |
# Create an input and output connector |
145 | 560 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
561 |
self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
562 |
self.SetType(type, condition) |
80 | 563 |
self.SetPriority(priority) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
564 |
self.Errors = {} |
253 | 565 |
self.Value = None |
566 |
self.PreviousValue = None |
|
567 |
self.PreviousSpreading = False |
|
0 | 568 |
|
249 | 569 |
def Flush(self): |
570 |
if self.Input is not None: |
|
571 |
self.Input.Flush() |
|
572 |
self.Input = None |
|
573 |
if self.Output is not None: |
|
574 |
self.Output.Flush() |
|
575 |
self.Output = None |
|
576 |
if self.Type == "connection" and self.Condition is not None: |
|
577 |
self.Condition.Flush() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
578 |
self.Condition = None |
0 | 579 |
|
253 | 580 |
def SetValue(self, value): |
581 |
self.PreviousValue = self.Value |
|
582 |
self.Value = value |
|
583 |
if self.Value != self.PreviousValue: |
|
584 |
self.Refresh() |
|
585 |
self.SpreadCurrent() |
|
586 |
||
587 |
def SpreadCurrent(self): |
|
588 |
if self.Parent.Debug: |
|
589 |
if self.Value is None: |
|
590 |
self.Value = False |
|
591 |
spreading = self.Input.ReceivingCurrent() & self.Value |
|
592 |
if spreading and not self.PreviousSpreading: |
|
593 |
self.Output.SpreadCurrent(True) |
|
594 |
elif not spreading and self.PreviousSpreading: |
|
595 |
self.Output.SpreadCurrent(False) |
|
596 |
self.PreviousSpreading = spreading |
|
597 |
||
112 | 598 |
# Make a clone of this SFC_Transition |
162 | 599 |
def Clone(self, parent, id = None, pos = None): |
600 |
transition = SFC_Transition(parent, self.Type, self.Condition, self.Priority, id) |
|
112 | 601 |
transition.SetSize(self.Size[0], self.Size[1]) |
602 |
if pos is not None: |
|
603 |
transition.SetPosition(pos.x, pos.y) |
|
283 | 604 |
else: |
605 |
transition.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 606 |
transition.Input = self.Input.Clone(transition) |
607 |
transition.Output = self.Output.Clone(transition) |
|
172 | 608 |
if self.Type == "connection": |
609 |
transition.Condition = self.Condition.Clone(transition) |
|
112 | 610 |
return transition |
611 |
||
283 | 612 |
def GetConnectorTranslation(self, element): |
613 |
connectors = {self.Input : element.Input, self.Output : element.Output} |
|
614 |
if self.Type == "connection" and self.Condition is not None: |
|
615 |
connectors[self.Condition] = element.Condition |
|
616 |
return connectors |
|
617 |
||
144 | 618 |
# Returns the RedrawRect |
619 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
620 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
621 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
622 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
623 |
if movex != 0 or movey != 0: |
|
624 |
if self.Input.IsConnected(): |
|
625 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
626 |
if self.Output.IsConnected(): |
|
627 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
175 | 628 |
if self.Type == "connection" and self.Condition.IsConnected(): |
172 | 629 |
rect = rect.Union(self.Condition.GetConnectedRedrawRect(movex, movey)) |
144 | 630 |
return rect |
631 |
||
0 | 632 |
# Forbids to change the transition size |
633 |
def SetSize(self, width, height): |
|
27 | 634 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
635 |
Graphic_Element.SetSize(self, width, height) |
|
0 | 636 |
|
637 |
# Forbids to resize the transition |
|
638 |
def Resize(self, x, y, width, height): |
|
27 | 639 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
640 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 641 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
642 |
# Refresh the size of text for name |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
643 |
def RefreshConditionSize(self): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
644 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
645 |
if self.Condition != "": |
165 | 646 |
self.ConditionSize = self.Parent.GetTextExtent(self.Condition) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
647 |
else: |
165 | 648 |
self.ConditionSize = self.Parent.GetTextExtent("Transition") |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
649 |
|
80 | 650 |
# Refresh the size of text for name |
651 |
def RefreshPrioritySize(self): |
|
652 |
if self.Priority != "": |
|
165 | 653 |
self.PrioritySize = self.Parent.GetTextExtent(str(self.Priority)) |
80 | 654 |
else: |
655 |
self.PrioritySize = None |
|
656 |
||
0 | 657 |
# Delete this transition by calling the appropriate method |
658 |
def Delete(self): |
|
659 |
self.Parent.DeleteTransition(self) |
|
660 |
||
661 |
# Unconnect input and output |
|
662 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
663 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
664 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
665 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
666 |
self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 667 |
|
668 |
# Refresh the transition bounding box |
|
669 |
def RefreshBoundingBox(self): |
|
80 | 670 |
bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] |
671 |
if self.Priority != 0: |
|
672 |
bbx_y = self.Pos.y - self.PrioritySize[1] - 2 |
|
673 |
bbx_width = max(self.Size[0], self.PrioritySize[0]) |
|
674 |
bbx_height = self.Size[1] + self.PrioritySize[1] + 2 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
675 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
676 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
80 | 677 |
bbx_width = bbx_width + CONNECTOR_SIZE |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
678 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
679 |
text_width, text_height = self.ConditionSize |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
680 |
# Calculate the bounding box size |
80 | 681 |
bbx_width = max(bbx_width, self.Size[0] + 5 + text_width) |
682 |
bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2)) |
|
683 |
bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
684 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 685 |
|
686 |
# Returns the connector connected to input |
|
687 |
def GetPreviousConnector(self): |
|
688 |
wires = self.Input.GetWires() |
|
689 |
if len(wires) == 1: |
|
145 | 690 |
return wires[0][0].GetOtherConnected(self.Input) |
0 | 691 |
return None |
692 |
||
693 |
# Returns the connector connected to output |
|
694 |
def GetNextConnector(self): |
|
695 |
wires = self.Output.GetWires() |
|
696 |
if len(wires) == 1: |
|
145 | 697 |
return wires[0][0].GetOtherConnected(self.Output) |
0 | 698 |
return None |
699 |
||
700 |
# Refresh the positions of the transition connectors |
|
701 |
def RefreshConnectors(self): |
|
145 | 702 |
scaling = self.Parent.GetScaling() |
703 |
horizontal_pos = self.Size[0] / 2 |
|
704 |
vertical_pos = self.Size[1] / 2 |
|
705 |
if scaling is not None: |
|
706 |
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
707 |
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
0 | 708 |
# Update input position |
145 | 709 |
self.Input.SetPosition(wx.Point(horizontal_pos, 0)) |
0 | 710 |
# Update output position |
145 | 711 |
self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
712 |
if self.Type == "connection": |
145 | 713 |
self.Condition.SetPosition(wx.Point(0, vertical_pos)) |
0 | 714 |
self.RefreshConnected() |
715 |
||
716 |
# Refresh the position of the wires connected to transition |
|
717 |
def RefreshConnected(self, exclude = []): |
|
718 |
self.Input.MoveConnected(exclude) |
|
719 |
self.Output.MoveConnected(exclude) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
720 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
721 |
self.Condition.MoveConnected(exclude) |
0 | 722 |
|
723 |
# Returns the transition connector that starts with the point given if it exists |
|
27 | 724 |
def GetConnector(self, position, name = None): |
725 |
# if a name is given |
|
726 |
if name: |
|
727 |
# Test input and output connector |
|
728 |
if name == self.Input.GetName(): |
|
729 |
return self.Input |
|
730 |
if name == self.Output.GetName(): |
|
731 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
732 |
if self.Type == "connection" and name == self.Condition.GetName(): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
733 |
return self.Condition |
0 | 734 |
# Test input connector |
735 |
input_pos = self.Input.GetRelPosition() |
|
736 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
737 |
return self.Input |
|
738 |
# Test output connector |
|
739 |
output_pos = self.Output.GetRelPosition() |
|
740 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
741 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
742 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
743 |
# Test condition connector |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
744 |
condition_pos = self.Condition.GetRelPosition() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
745 |
if position.x == self.Pos.x + condition_pos.x and position.y == self.Pos.y + condition_pos.y: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
746 |
return self.Condition |
0 | 747 |
return None |
748 |
||
749 |
# Returns input and output transition connectors |
|
750 |
def GetConnectors(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
751 |
connectors = {"input":self.Input,"output":self.Output} |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
752 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
753 |
connectors["connection"] = self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
754 |
return connectors |
0 | 755 |
|
756 |
# Test if point given is on transition input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
757 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 758 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
759 |
if self.Input.TestPoint(pt, direction, exclude): |
0 | 760 |
return self.Input |
761 |
# Test output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
762 |
if self.Output.TestPoint(pt, direction, exclude): |
0 | 763 |
return self.Output |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
764 |
# Test condition connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
765 |
if self.Type == "connection" and self.Condition.TestPoint(pt, direction, exclude): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
766 |
return self.Condition |
0 | 767 |
return None |
768 |
||
769 |
# Changes the transition type |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
770 |
def SetType(self, type, condition = None): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
771 |
if self.Type != type: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
772 |
if self.Type == "connection": |
154 | 773 |
self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
774 |
self.Type = type |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
775 |
if type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
776 |
self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
777 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
778 |
if condition == None: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
779 |
condition = "" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
780 |
self.Condition = condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
781 |
self.RefreshConditionSize() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
782 |
elif self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
783 |
if condition == None: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
784 |
condition = "" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
785 |
self.Condition = condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
786 |
self.RefreshConditionSize() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
787 |
self.RefreshBoundingBox() |
0 | 788 |
|
789 |
# Returns the transition type |
|
790 |
def GetType(self): |
|
791 |
return self.Type |
|
792 |
||
80 | 793 |
# Changes the transition priority |
794 |
def SetPriority(self, priority): |
|
795 |
self.Priority = priority |
|
796 |
self.RefreshPrioritySize() |
|
797 |
self.RefreshBoundingBox() |
|
798 |
||
799 |
# Returns the transition type |
|
800 |
def GetPriority(self): |
|
801 |
return self.Priority |
|
802 |
||
0 | 803 |
# Returns the transition condition |
804 |
def GetCondition(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
805 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
806 |
return self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
807 |
return None |
0 | 808 |
|
809 |
# Returns the transition minimum size |
|
810 |
def GetMinSize(self): |
|
811 |
return SFC_TRANSITION_SIZE |
|
812 |
||
813 |
# Align input element with this step |
|
814 |
def RefreshInputPosition(self): |
|
815 |
wires = self.Input.GetWires() |
|
816 |
current_pos = self.Input.GetPosition(False) |
|
817 |
input = self.GetPreviousConnector() |
|
818 |
if input: |
|
819 |
input_pos = input.GetPosition(False) |
|
820 |
diffx = current_pos.x - input_pos.x |
|
821 |
input_block = input.GetParentBlock() |
|
822 |
if isinstance(input_block, SFC_Divergence): |
|
823 |
input_block.MoveConnector(input, diffx) |
|
824 |
else: |
|
825 |
if isinstance(input_block, SFC_Step): |
|
826 |
input_block.MoveActionBlock((diffx, 0)) |
|
827 |
input_block.Move(diffx, 0) |
|
828 |
input_block.RefreshInputPosition() |
|
829 |
||
830 |
# Align output element with this step |
|
831 |
def RefreshOutputPosition(self, move = None): |
|
832 |
wires = self.Output.GetWires() |
|
833 |
if len(wires) != 1: |
|
834 |
return |
|
835 |
current_pos = self.Output.GetPosition(False) |
|
145 | 836 |
output = wires[0][0].GetOtherConnected(self.Output) |
0 | 837 |
output_pos = output.GetPosition(False) |
838 |
diffx = current_pos.x - output_pos.x |
|
839 |
output_block = output.GetParentBlock() |
|
840 |
if move: |
|
841 |
if isinstance(output_block, SFC_Step): |
|
842 |
output_block.MoveActionBlock(move) |
|
843 |
wires[0][0].Move(move[0], move[1], True) |
|
844 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
845 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
846 |
output_block.RefreshOutputPosition(move) |
|
847 |
else: |
|
848 |
output_block.RefreshPosition() |
|
849 |
elif isinstance(output_block, SFC_Divergence): |
|
850 |
output_block.MoveConnector(output, diffx) |
|
851 |
else: |
|
852 |
if isinstance(output_block, SFC_Step): |
|
853 |
output_block.MoveActionBlock((diffx, 0)) |
|
854 |
output_block.Move(diffx, 0) |
|
855 |
output_block.RefreshOutputPosition() |
|
27 | 856 |
|
0 | 857 |
# Method called when a LeftDClick event have been generated |
27 | 858 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 859 |
# Edit the transition properties |
860 |
self.Parent.EditTransitionContent(self) |
|
861 |
||
862 |
# Method called when a RightUp event have been generated |
|
27 | 863 |
def OnRightUp(self, event, dc, scaling): |
0 | 864 |
# Popup the menu with special items for a step |
865 |
self.Parent.PopupDefaultMenu() |
|
866 |
||
867 |
# Refreshes the transition state according to move defined and handle selected |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
868 |
def ProcessDragging(self, movex, movey, event, scaling): |
27 | 869 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
870 |
movex = max(-self.BoundingBox.x, movex) |
145 | 871 |
if scaling is not None: |
872 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
27 | 873 |
self.Move(movex, 0) |
874 |
self.RefreshInputPosition() |
|
875 |
self.RefreshOutputPosition() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
876 |
return movex, 0 |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
877 |
else: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
878 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, width_fac = 2, height_fac = 2) |
0 | 879 |
|
880 |
# Refresh input element model |
|
881 |
def RefreshInputModel(self): |
|
27 | 882 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
883 |
input = self.GetPreviousConnector() |
|
884 |
if input: |
|
885 |
input_block = input.GetParentBlock() |
|
886 |
input_block.RefreshModel(False) |
|
887 |
if not isinstance(input_block, SFC_Divergence): |
|
888 |
input_block.RefreshInputModel() |
|
0 | 889 |
|
890 |
# Refresh output element model |
|
891 |
def RefreshOutputModel(self, move=False): |
|
892 |
output = self.GetNextConnector() |
|
893 |
if output: |
|
894 |
output_block = output.GetParentBlock() |
|
895 |
output_block.RefreshModel(False) |
|
896 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
897 |
output_block.RefreshOutputModel(move) |
|
898 |
||
899 |
# Refreshes the transition model |
|
900 |
def RefreshModel(self, move=True): |
|
901 |
self.Parent.RefreshTransitionModel(self) |
|
902 |
# If transition has moved, refresh the model of wires connected to output |
|
903 |
if move: |
|
27 | 904 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
905 |
self.RefreshInputModel() |
|
906 |
self.RefreshOutputModel() |
|
907 |
else: |
|
908 |
self.Output.RefreshWires() |
|
0 | 909 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
910 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
911 |
if infos[0] == "priority" and start[0] == 0 and start[1] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
912 |
self.Errors[infos[0]] = (start[1], end[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
913 |
elif infos[0] == "inline": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
914 |
if infos[0] not in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
915 |
self.Errors[infos[0]] = [] |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
916 |
self.Errors[infos[0]].append((start[1], end[1])) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
917 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
918 |
pass |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
919 |
|
0 | 920 |
# Draws transition |
921 |
def Draw(self, dc): |
|
144 | 922 |
Graphic_Element.Draw(self, dc) |
253 | 923 |
if self.Value: |
924 |
dc.SetPen(wx.GREEN_PEN) |
|
925 |
dc.SetBrush(wx.GREEN_BRUSH) |
|
926 |
else: |
|
927 |
dc.SetPen(wx.BLACK_PEN) |
|
928 |
dc.SetBrush(wx.BLACK_BRUSH) |
|
213 | 929 |
|
930 |
if getattr(dc, "printing", False): |
|
931 |
if self.Type != "connection": |
|
932 |
condition_size = dc.GetTextExtent(self.Condition) |
|
933 |
if self.Priority != 0: |
|
934 |
priority_size = dc.GetTextExtent(str(self.Priority)) |
|
935 |
else: |
|
936 |
if self.Type != "connection": |
|
937 |
condition_size = self.ConditionSize |
|
938 |
if self.Priority != 0: |
|
939 |
priority_size = self.PrioritySize |
|
940 |
||
0 | 941 |
# Draw plain rectangle for representing the transition |
175 | 942 |
dc.DrawRectangle(self.Pos.x, |
943 |
self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1])/2, |
|
944 |
self.Size[0] + 1, |
|
945 |
SFC_TRANSITION_SIZE[1] + 1) |
|
946 |
vertical_line_x = self.Input.GetPosition()[0] |
|
199 | 947 |
dc.DrawLine(vertical_line_x, self.Pos.y, vertical_line_x, self.Pos.y + self.Size[1] + 1) |
0 | 948 |
# Draw transition condition |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
949 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
950 |
if self.Condition != "": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
951 |
condition = self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
952 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
953 |
condition = "Transition" |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
954 |
condition_pos = (self.Pos.x + self.Size[0] + 5, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
955 |
self.Pos.y + (self.Size[1] - condition_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
956 |
dc.DrawText(condition, condition_pos[0], condition_pos[1]) |
80 | 957 |
# Draw priority number |
958 |
if self.Priority != 0: |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
959 |
priority_pos = (self.Pos.x, self.Pos.y - priority_size[1] - 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
960 |
dc.DrawText(str(self.Priority), priority_pos[0], priority_pos[1]) |
0 | 961 |
# Draw input and output connectors |
962 |
self.Input.Draw(dc) |
|
963 |
self.Output.Draw(dc) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
964 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
965 |
self.Condition.Draw(dc) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
966 |
if "priority" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
967 |
HighlightErrorZone(dc, priority_pos[0], priority_pos[1], priority_size[0], priority_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
968 |
if "inline" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
969 |
for start, end in self.Errors["inline"]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
970 |
offset = dc.GetTextExtent(self.Condition[:start]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
971 |
size = dc.GetTextExtent(self.Condition[start:end + 1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
972 |
HighlightErrorZone(dc, condition_pos[0] + offset[0], condition_pos[1], size[0], size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
973 |
|
0 | 974 |
|
975 |
#------------------------------------------------------------------------------- |
|
976 |
# Sequencial Function Chart Divergence and Convergence |
|
977 |
#------------------------------------------------------------------------------- |
|
978 |
||
979 |
""" |
|
980 |
Class that implements the graphic representation of a divergence or convergence, |
|
981 |
selection or simultaneous |
|
982 |
""" |
|
983 |
||
984 |
class SFC_Divergence(Graphic_Element): |
|
985 |
||
986 |
# Create a new divergence |
|
987 |
def __init__(self, parent, type, number = 2, id = None): |
|
988 |
Graphic_Element.__init__(self, parent) |
|
989 |
self.Type = type |
|
990 |
self.Id = id |
|
991 |
self.RealConnectors = None |
|
992 |
number = max(2, number) |
|
175 | 993 |
self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1]) |
0 | 994 |
# Create an input and output connector |
995 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
145 | 996 |
self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)] |
0 | 997 |
self.Outputs = [] |
998 |
for i in xrange(number): |
|
145 | 999 |
self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True)) |
0 | 1000 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
1001 |
self.Inputs = [] |
|
1002 |
for i in xrange(number): |
|
145 | 1003 |
self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True)) |
1004 |
self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)] |
|
253 | 1005 |
self.Value = None |
1006 |
self.PreviousValue = None |
|
0 | 1007 |
|
249 | 1008 |
def Flush(self): |
1009 |
for input in self.Inputs: |
|
1010 |
input.Flush() |
|
0 | 1011 |
self.Inputs = [] |
249 | 1012 |
for output in self.Outputs: |
1013 |
output.Flush() |
|
0 | 1014 |
self.Outputs = [] |
1015 |
||
253 | 1016 |
def SpreadCurrent(self): |
1017 |
if self.Parent.Debug: |
|
1018 |
self.PreviousValue = self.Value |
|
1019 |
if self.Type == SELECTION_CONVERGENCE: |
|
1020 |
self.Value = False |
|
1021 |
for input in self.Inputs: |
|
1022 |
self.Value |= input.ReceivingCurrent() |
|
1023 |
elif self.Type == SIMULTANEOUS_CONVERGENCE: |
|
1024 |
self.Value = True |
|
1025 |
for input in self.Inputs: |
|
1026 |
self.Value &= input.ReceivingCurrent() |
|
1027 |
elif self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
1028 |
self.Value = self.Inputs[0].ReceivingCurrent() |
|
1029 |
else: |
|
1030 |
self.Value = False |
|
1031 |
if self.Value and not self.PreviousValue: |
|
1032 |
self.Refresh() |
|
1033 |
for output in self.Outputs: |
|
1034 |
output.SpreadCurrent(True) |
|
1035 |
elif not self.Value and self.PreviousValue: |
|
1036 |
self.Refresh() |
|
1037 |
for output in self.Outputs: |
|
1038 |
output.SpreadCurrent(False) |
|
1039 |
||
112 | 1040 |
# Make a clone of this SFC_Divergence |
162 | 1041 |
def Clone(self, parent, id = None, pos = None): |
1042 |
divergence = SFC_Divergence(parent, self.Type, max(len(self.Inputs), len(self.Outputs)), id) |
|
112 | 1043 |
divergence.SetSize(self.Size[0], self.Size[1]) |
1044 |
if pos is not None: |
|
1045 |
divergence.SetPosition(pos.x, pos.y) |
|
283 | 1046 |
else: |
1047 |
divergence.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 1048 |
divergence.Inputs = [input.Clone(divergence) for input in self.Inputs] |
1049 |
divergence.Outputs = [output.Clone(divergence) for output in self.Outputs] |
|
1050 |
return divergence |
|
1051 |
||
283 | 1052 |
def GetConnectorTranslation(self, element): |
1053 |
return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs)) |
|
1054 |
||
144 | 1055 |
# Returns the RedrawRect |
1056 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
1057 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1058 |
if movex != 0 or movey != 0: |
|
1059 |
for input in self.Inputs: |
|
1060 |
if input.IsConnected(): |
|
1061 |
rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
|
1062 |
for output in self.Outputs: |
|
1063 |
if output.IsConnected(): |
|
1064 |
rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
|
1065 |
return rect |
|
1066 |
||
0 | 1067 |
# Forbids to resize the divergence |
1068 |
def Resize(self, x, y, width, height): |
|
27 | 1069 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
175 | 1070 |
Graphic_Element.Resize(self, x, 0, width, self.GetMinSize()[1]) |
0 | 1071 |
|
1072 |
# Delete this divergence by calling the appropriate method |
|
1073 |
def Delete(self): |
|
1074 |
self.Parent.DeleteDivergence(self) |
|
1075 |
||
1076 |
# Returns the divergence type |
|
1077 |
def GetType(self): |
|
1078 |
return self.Type |
|
1079 |
||
1080 |
# Unconnect input and output |
|
1081 |
def Clean(self): |
|
1082 |
for input in self.Inputs: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1083 |
input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1084 |
for output in self.Outputs: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1085 |
output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1086 |
|
1087 |
# Add a branch to the divergence |
|
1088 |
def AddBranch(self): |
|
1089 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
1090 |
maxx = 0 |
|
1091 |
for output in self.Outputs: |
|
1092 |
pos = output.GetRelPosition() |
|
1093 |
maxx = max(maxx, pos.x) |
|
145 | 1094 |
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True) |
0 | 1095 |
self.Outputs.append(connector) |
1096 |
self.MoveConnector(connector, 0) |
|
1097 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1098 |
maxx = 0 |
|
1099 |
for input in self.Inputs: |
|
1100 |
pos = input.GetRelPosition() |
|
1101 |
maxx = max(maxx, pos.x) |
|
145 | 1102 |
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True) |
0 | 1103 |
self.Inputs.append(connector) |
1104 |
self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) |
|
1105 |
||
1106 |
# Remove a branch from the divergence |
|
1107 |
def RemoveBranch(self, connector): |
|
1108 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1109 |
if connector in self.Outputs and len(self.Outputs) > 2: |
0 | 1110 |
self.Outputs.remove(connector) |
1111 |
self.MoveConnector(self.Outputs[0], 0) |
|
1112 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1113 |
if connector in self.Inputs and len(self.Inputs) > 2: |
0 | 1114 |
self.Inputs.remove(connector) |
1115 |
self.MoveConnector(self.Inputs[0], 0) |
|
1116 |
||
80 | 1117 |
# Remove the handled branch from the divergence |
1118 |
def RemoveHandledBranch(self): |
|
1119 |
handle_type, handle = self.Handle |
|
1120 |
if handle_type == HANDLE_CONNECTOR: |
|
1121 |
handle.UnConnect(delete=True) |
|
1122 |
self.RemoveBranch(handle) |
|
1123 |
||
0 | 1124 |
# Return the number of branches for the divergence |
1125 |
def GetBranchNumber(self): |
|
1126 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
1127 |
return len(self.Outputs) |
|
1128 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1129 |
return len(self.Inputs) |
|
1130 |
||
1131 |
# Returns if the point given is in the bounding box |
|
1132 |
def HitTest(self, pt): |
|
1133 |
rect = self.BoundingBox |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1134 |
return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, exclude=False) != None |
0 | 1135 |
|
1136 |
# Refresh the divergence bounding box |
|
1137 |
def RefreshBoundingBox(self): |
|
1138 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
145 | 1139 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, |
1140 |
self.Size[0] + 1, self.Size[1] + 1) |
|
0 | 1141 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
145 | 1142 |
self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, |
1143 |
self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1) |
|
0 | 1144 |
|
1145 |
# Refresh the position of wires connected to divergence |
|
1146 |
def RefreshConnected(self, exclude = []): |
|
1147 |
for input in self.Inputs: |
|
1148 |
input.MoveConnected(exclude) |
|
1149 |
for output in self.Outputs: |
|
1150 |
output.MoveConnected(exclude) |
|
1151 |
||
1152 |
# Moves the divergence connector given |
|
1153 |
def MoveConnector(self, connector, movex): |
|
1154 |
position = connector.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1155 |
connector.SetPosition(wx.Point(position.x + movex, position.y)) |
0 | 1156 |
minx = self.Size[0] |
1157 |
maxx = 0 |
|
1158 |
for input in self.Inputs: |
|
1159 |
input_pos = input.GetRelPosition() |
|
1160 |
minx = min(minx, input_pos.x) |
|
1161 |
maxx = max(maxx, input_pos.x) |
|
1162 |
for output in self.Outputs: |
|
1163 |
output_pos = output.GetRelPosition() |
|
1164 |
minx = min(minx, output_pos.x) |
|
1165 |
maxx = max(maxx, output_pos.x) |
|
1166 |
if minx != 0: |
|
1167 |
for input in self.Inputs: |
|
1168 |
input_pos = input.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1169 |
input.SetPosition(wx.Point(input_pos.x - minx, input_pos.y)) |
0 | 1170 |
for output in self.Outputs: |
1171 |
output_pos = output.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1172 |
output.SetPosition(wx.Point(output_pos.x - minx, output_pos.y)) |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1173 |
self.Inputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x)) |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1174 |
self.Outputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x)) |
0 | 1175 |
self.Pos.x += minx |
1176 |
self.Size[0] = maxx - minx |
|
1177 |
connector.MoveConnected() |
|
1178 |
self.RefreshBoundingBox() |
|
1179 |
||
1180 |
# Returns the divergence connector that starts with the point given if it exists |
|
27 | 1181 |
def GetConnector(self, position, name = None): |
1182 |
# if a name is given |
|
1183 |
if name: |
|
1184 |
# Test each input and output connector |
|
1185 |
for input in self.Inputs: |
|
1186 |
if name == input.GetName(): |
|
1187 |
return input |
|
1188 |
for output in self.Outputs: |
|
1189 |
if name == output.GetName(): |
|
1190 |
return output |
|
0 | 1191 |
# Test input connector |
1192 |
for input in self.Inputs: |
|
1193 |
input_pos = input.GetPosition(False) |
|
1194 |
if position.x == input_pos.x and position.y == input_pos.y: |
|
1195 |
return input |
|
1196 |
# Test output connector |
|
1197 |
for output in self.Outputs: |
|
1198 |
output_pos = output.GetPosition(False) |
|
1199 |
if position.x == output_pos.x and position.y == output_pos.y: |
|
1200 |
return output |
|
1201 |
return None |
|
1202 |
||
1203 |
# Returns input and output divergence connectors |
|
1204 |
def GetConnectors(self): |
|
1205 |
return {"inputs":self.Inputs,"outputs":self.Outputs} |
|
1206 |
||
1207 |
# Test if point given is on divergence input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1208 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 1209 |
# Test input connector |
1210 |
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
|
1211 |
if input.TestPoint(pt, direction, exclude): |
0 | 1212 |
return input |
1213 |
# Test output connector |
|
1214 |
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
|
1215 |
if output.TestPoint(pt, direction, exclude): |
0 | 1216 |
return output |
1217 |
return None |
|
1218 |
||
1219 |
# Changes the divergence size |
|
1220 |
def SetSize(self, width, height): |
|
199 | 1221 |
height = self.GetMinSize()[1] |
0 | 1222 |
for i, input in enumerate(self.Inputs): |
1223 |
position = input.GetRelPosition() |
|
1224 |
if self.RealConnectors: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1225 |
input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) |
0 | 1226 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1227 |
input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) |
0 | 1228 |
input.MoveConnected() |
1229 |
for i, output in enumerate(self.Outputs): |
|
1230 |
position = output.GetRelPosition() |
|
1231 |
if self.RealConnectors: |
|
146 | 1232 |
output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height)) |
0 | 1233 |
else: |
146 | 1234 |
output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height)) |
0 | 1235 |
output.MoveConnected() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1236 |
self.Size = wx.Size(width, height) |
0 | 1237 |
self.RefreshBoundingBox() |
1238 |
||
1239 |
# Returns the divergence minimum size |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1240 |
def GetMinSize(self, default=False): |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1241 |
width = 0 |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1242 |
if default: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1243 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1244 |
width = (len(self.Outputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1245 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1246 |
width = (len(self.Inputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL |
27 | 1247 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1248 |
return width, 1 |
27 | 1249 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1250 |
return width, 3 |
27 | 1251 |
return 0, 0 |
0 | 1252 |
|
1253 |
# Refresh the position of the block connected to connector |
|
1254 |
def RefreshConnectedPosition(self, connector): |
|
1255 |
wires = connector.GetWires() |
|
1256 |
if len(wires) != 1: |
|
1257 |
return |
|
1258 |
current_pos = connector.GetPosition(False) |
|
145 | 1259 |
next = wires[0][0].GetOtherConnected(connector) |
0 | 1260 |
next_pos = next.GetPosition(False) |
1261 |
diffx = current_pos.x - next_pos.x |
|
1262 |
next_block = next.GetParentBlock() |
|
1263 |
if isinstance(next_block, SFC_Divergence): |
|
1264 |
next_block.MoveConnector(next, diffx) |
|
1265 |
else: |
|
1266 |
next_block.Move(diffx, 0) |
|
1267 |
if connector in self.Inputs: |
|
1268 |
next_block.RefreshInputPosition() |
|
1269 |
else: |
|
1270 |
next_block.RefreshOutputPosition() |
|
27 | 1271 |
|
0 | 1272 |
# Refresh the position of this divergence |
1273 |
def RefreshPosition(self): |
|
1274 |
y = 0 |
|
1275 |
for input in self.Inputs: |
|
1276 |
wires = input.GetWires() |
|
1277 |
if len(wires) != 1: |
|
1278 |
return |
|
145 | 1279 |
previous = wires[0][0].GetOtherConnected(input) |
0 | 1280 |
previous_pos = previous.GetPosition(False) |
1281 |
y = max(y, previous_pos.y + GetWireSize(previous.GetParentBlock())) |
|
1282 |
diffy = y - self.Pos.y |
|
1283 |
if diffy != 0: |
|
1284 |
self.Move(0, diffy, self.Parent.Wires) |
|
1285 |
self.RefreshOutputPosition((0, diffy)) |
|
1286 |
for input in self.Inputs: |
|
1287 |
input.MoveConnected() |
|
1288 |
||
1289 |
# Align output element with this divergence |
|
1290 |
def RefreshOutputPosition(self, move = None): |
|
1291 |
if move: |
|
1292 |
for output_connector in self.Outputs: |
|
1293 |
wires = output_connector.GetWires() |
|
1294 |
if len(wires) != 1: |
|
1295 |
return |
|
1296 |
current_pos = output_connector.GetPosition(False) |
|
145 | 1297 |
output = wires[0][0].GetOtherConnected(self.Output) |
0 | 1298 |
output_pos = output.GetPosition(False) |
1299 |
diffx = current_pos.x - output_pos.x |
|
1300 |
output_block = output.GetParentBlock() |
|
1301 |
if isinstance(output_block, SFC_Step): |
|
1302 |
output_block.MoveActionBlock(move) |
|
1303 |
wires[0][0].Move(move[0], move[1], True) |
|
1304 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
1305 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
1306 |
output_block.RefreshOutputPosition(move) |
|
1307 |
||
1308 |
# Method called when a LeftDown event have been generated |
|
27 | 1309 |
def OnLeftDown(self, event, dc, scaling): |
145 | 1310 |
self.RealConnectors = {"Inputs":[],"Outputs":[]} |
1311 |
for input in self.Inputs: |
|
1312 |
position = input.GetRelPosition() |
|
1313 |
self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) |
|
1314 |
for output in self.Outputs: |
|
1315 |
position = output.GetRelPosition() |
|
1316 |
self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) |
|
1317 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
1318 |
||
1319 |
# Method called when a LeftUp event have been generated |
|
1320 |
def OnLeftUp(self, event, dc, scaling): |
|
1321 |
Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
1322 |
self.RealConnectors = None |
|
1323 |
||
1324 |
# Method called when a RightDown event have been generated |
|
1325 |
def OnRightDown(self, event, dc, scaling): |
|
27 | 1326 |
pos = GetScaledEventPosition(event, dc, scaling) |
0 | 1327 |
# Test if a connector have been handled |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1328 |
connector = self.TestConnector(pos, exclude=False) |
0 | 1329 |
if connector: |
1330 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1331 |
self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
0 | 1332 |
self.Selected = False |
1333 |
# Initializes the last position |
|
27 | 1334 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
0 | 1335 |
else: |
145 | 1336 |
Graphic_Element.OnRightDown(self, event, dc, scaling) |
1337 |
||
1338 |
# Method called when a RightUp event have been generated |
|
1339 |
def OnRightUp(self, event, dc, scaling): |
|
0 | 1340 |
handle_type, handle = self.Handle |
204
5eb48c97f6e5
Bug with RightUp on SFC_Divergence connectors without movement fixed
lbessard
parents:
199
diff
changeset
|
1341 |
if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos: |
0 | 1342 |
wires = handle.GetWires() |
320 | 1343 |
if len(wires) == 1: |
1344 |
block = wires[0][0].GetOtherConnected(handle).GetParentBlock() |
|
1345 |
block.RefreshModel(False) |
|
1346 |
if not isinstance(block, SFC_Divergence): |
|
1347 |
if handle in self.Inputs: |
|
1348 |
block.RefreshInputModel() |
|
1349 |
else: |
|
1350 |
block.RefreshOutputModel() |
|
145 | 1351 |
Graphic_Element.OnRightUp(self, event, dc, scaling) |
1352 |
else: |
|
1353 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
1354 |
# 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
|
1355 |
connector = self.TestConnector(pos, exclude=False) |
145 | 1356 |
if connector: |
1357 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
1358 |
self.Parent.PopupDivergenceMenu(True) |
|
1359 |
else: |
|
1360 |
# Popup the divergence menu without delete branch |
|
1361 |
self.Parent.PopupDivergenceMenu(False) |
|
0 | 1362 |
|
1363 |
# Refreshes the divergence state according to move defined and handle selected |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1364 |
def ProcessDragging(self, movex, movey, event, scaling): |
0 | 1365 |
handle_type, handle = self.Handle |
1366 |
# A connector has been handled |
|
1367 |
if handle_type == HANDLE_CONNECTOR: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1368 |
movex = max(-self.BoundingBox.x, movex) |
145 | 1369 |
if scaling is not None: |
1370 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
0 | 1371 |
self.MoveConnector(handle, movex) |
27 | 1372 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1373 |
self.RefreshConnectedPosition(handle) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1374 |
return movex, 0 |
27 | 1375 |
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1376 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1377 |
return 0, 0 |
0 | 1378 |
|
1379 |
# Refresh output element model |
|
1380 |
def RefreshOutputModel(self, move=False): |
|
27 | 1381 |
if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
0 | 1382 |
for output in self.Outputs: |
1383 |
wires = output.GetWires() |
|
1384 |
if len(wires) != 1: |
|
1385 |
return |
|
145 | 1386 |
output_block = wires[0][0].GetOtherConnected(output).GetParentBlock() |
0 | 1387 |
output_block.RefreshModel(False) |
1388 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
1389 |
output_block.RefreshOutputModel(move) |
|
1390 |
||
1391 |
# Refreshes the divergence model |
|
1392 |
def RefreshModel(self, move=True): |
|
1393 |
self.Parent.RefreshDivergenceModel(self) |
|
1394 |
# If divergence has moved, refresh the model of wires connected to outputs |
|
1395 |
if move: |
|
27 | 1396 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1397 |
self.RefreshOutputModel() |
|
1398 |
else: |
|
1399 |
for output in self.Outputs: |
|
1400 |
output.RefreshWires() |
|
0 | 1401 |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1402 |
# Draws the highlightment of this element if it is highlighted |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1403 |
def DrawHighlightment(self, dc): |
144 | 1404 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1405 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
1406 |
dc.SetLogicalFunction(wx.AND) |
|
1407 |
# Draw two rectangles for representing the contact |
|
1408 |
posx = self.Pos.x - 2 |
|
1409 |
width = self.Size[0] + 5 |
|
1410 |
if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1411 |
posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA |
|
1412 |
width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2 |
|
1413 |
dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5) |
|
1414 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1415 |
|
0 | 1416 |
# Draws divergence |
1417 |
def Draw(self, dc): |
|
144 | 1418 |
Graphic_Element.Draw(self, dc) |
253 | 1419 |
if self.Value: |
1420 |
dc.SetPen(wx.GREEN_PEN) |
|
1421 |
dc.SetBrush(wx.GREEN_BRUSH) |
|
1422 |
else: |
|
1423 |
dc.SetPen(wx.BLACK_PEN) |
|
1424 |
dc.SetBrush(wx.BLACK_BRUSH) |
|
0 | 1425 |
# Draw plain rectangle for representing the divergence |
1426 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
1427 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1428 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1429 |
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, |
|
1430 |
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y) |
|
27 | 1431 |
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + self.Size[1], |
1432 |
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + self.Size[1]) |
|
0 | 1433 |
# Draw inputs and outputs connectors |
1434 |
for input in self.Inputs: |
|
1435 |
input.Draw(dc) |
|
1436 |
for output in self.Outputs: |
|
1437 |
output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1438 |
|
0 | 1439 |
|
1440 |
#------------------------------------------------------------------------------- |
|
1441 |
# Sequencial Function Chart Jump to Step |
|
1442 |
#------------------------------------------------------------------------------- |
|
1443 |
||
1444 |
""" |
|
1445 |
Class that implements the graphic representation of a jump to step |
|
1446 |
""" |
|
1447 |
||
1448 |
class SFC_Jump(Graphic_Element): |
|
1449 |
||
1450 |
# Create a new jump |
|
1451 |
def __init__(self, parent, target, id = None): |
|
1452 |
Graphic_Element.__init__(self, parent) |
|
213 | 1453 |
self.SetTarget(target) |
0 | 1454 |
self.Id = id |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1455 |
self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1456 |
self.Errors = {} |
0 | 1457 |
# Create an input and output connector |
145 | 1458 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
253 | 1459 |
self.Value = None |
1460 |
self.PreviousValue = None |
|
0 | 1461 |
|
249 | 1462 |
def Flush(self): |
1463 |
if self.Input is not None: |
|
1464 |
self.Input.Flush() |
|
1465 |
self.Input = None |
|
0 | 1466 |
|
253 | 1467 |
def SpreadCurrent(self): |
1468 |
if self.Parent.Debug: |
|
1469 |
self.PreviousValue = self.Value |
|
1470 |
self.Value = self.Input.ReceivingCurrent() |
|
1471 |
if self.Value != self.PreviousValue: |
|
1472 |
self.Refresh() |
|
1473 |
||
112 | 1474 |
# Make a clone of this SFC_Jump |
162 | 1475 |
def Clone(self, parent, id = None, pos = None): |
1476 |
jump = SFC_Jump(parent, self.Target, id) |
|
112 | 1477 |
jump.SetSize(self.Size[0], self.Size[1]) |
1478 |
if pos is not None: |
|
1479 |
jump.SetPosition(pos.x, pos.y) |
|
283 | 1480 |
else: |
1481 |
jump.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 1482 |
jump.Input = self.Input.Clone(jump) |
1483 |
return jump |
|
1484 |
||
283 | 1485 |
def GetConnectorTranslation(self, element): |
1486 |
return {self.Input : element.Input} |
|
1487 |
||
144 | 1488 |
# Returns the RedrawRect |
1489 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
1490 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1491 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
1492 |
if movex != 0 or movey != 0: |
|
1493 |
if self.Input.IsConnected(): |
|
1494 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
1495 |
return rect |
|
1496 |
||
0 | 1497 |
# Forbids to change the jump size |
1498 |
def SetSize(self, width, height): |
|
27 | 1499 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1500 |
Graphic_Element.SetSize(self, width, height) |
|
0 | 1501 |
|
1502 |
# Forbids to resize jump |
|
1503 |
def Resize(self, x, y, width, height): |
|
27 | 1504 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1505 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 1506 |
|
1507 |
# Delete this jump by calling the appropriate method |
|
1508 |
def Delete(self): |
|
1509 |
self.Parent.DeleteJump(self) |
|
1510 |
||
1511 |
# Unconnect input |
|
1512 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1513 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1514 |
|
213 | 1515 |
# Refresh the size of text for target |
1516 |
def RefreshTargetSize(self): |
|
1517 |
self.TargetSize = self.Parent.GetTextExtent(self.Target) |
|
1518 |
||
0 | 1519 |
# Refresh the jump bounding box |
1520 |
def RefreshBoundingBox(self): |
|
165 | 1521 |
text_width, text_height = self.Parent.GetTextExtent(self.Target) |
0 | 1522 |
# Calculate the bounding box size |
1523 |
bbx_width = self.Size[0] + 2 + text_width |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1524 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, |
0 | 1525 |
bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1) |
1526 |
||
1527 |
# Returns the connector connected to input |
|
1528 |
def GetPreviousConnector(self): |
|
27 | 1529 |
wires = self.Input.GetWires() |
1530 |
if len(wires) == 1: |
|
145 | 1531 |
return wires[0][0].GetOtherConnected(self.Input) |
0 | 1532 |
return None |
1533 |
||
27 | 1534 |
# Refresh the element connectors position |
1535 |
def RefreshConnectors(self): |
|
145 | 1536 |
scaling = self.Parent.GetScaling() |
1537 |
horizontal_pos = self.Size[0] / 2 |
|
1538 |
if scaling is not None: |
|
1539 |
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
1540 |
self.Input.SetPosition(wx.Point(horizontal_pos, 0)) |
|
27 | 1541 |
self.RefreshConnected() |
1542 |
||
0 | 1543 |
# Refresh the position of wires connected to jump |
1544 |
def RefreshConnected(self, exclude = []): |
|
1545 |
if self.Input: |
|
1546 |
self.Input.MoveConnected(exclude) |
|
1547 |
||
1548 |
# Returns input jump connector |
|
27 | 1549 |
def GetConnector(self, position = None, name = None): |
0 | 1550 |
return self.Input |
1551 |
||
1552 |
# Test if point given is on jump input connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1553 |
def TestConnector(self, pt, direction = None, exclude = True): |
0 | 1554 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1555 |
if self.Input and self.Input.TestPoint(pt, direction, exclude): |
0 | 1556 |
return self.Input |
1557 |
return None |
|
1558 |
||
1559 |
# Changes the jump target |
|
1560 |
def SetTarget(self, target): |
|
1561 |
self.Target = target |
|
213 | 1562 |
self.RefreshTargetSize() |
0 | 1563 |
self.RefreshBoundingBox() |
1564 |
||
1565 |
# Returns the jump target |
|
1566 |
def GetTarget(self): |
|
1567 |
return self.Target |
|
1568 |
||
1569 |
# Returns the jump minimum size |
|
1570 |
def GetMinSize(self): |
|
1571 |
return SFC_JUMP_SIZE |
|
1572 |
||
1573 |
# Align input element with this jump |
|
1574 |
def RefreshInputPosition(self): |
|
1575 |
if self.Input: |
|
1576 |
current_pos = self.Input.GetPosition(False) |
|
1577 |
input = self.GetPreviousConnector() |
|
1578 |
if input: |
|
1579 |
input_pos = input.GetPosition(False) |
|
1580 |
diffx = current_pos.x - input_pos.x |
|
1581 |
input_block = input.GetParentBlock() |
|
1582 |
if isinstance(input_block, SFC_Divergence): |
|
1583 |
input_block.MoveConnector(input, diffx) |
|
1584 |
else: |
|
1585 |
if isinstance(input_block, SFC_Step): |
|
1586 |
input_block.MoveActionBlock((diffx, 0)) |
|
1587 |
input_block.Move(diffx, 0) |
|
1588 |
input_block.RefreshInputPosition() |
|
1589 |
||
1590 |
# Can't align output element, because there is no output |
|
1591 |
def RefreshOutputPosition(self, move = None): |
|
1592 |
pass |
|
1593 |
||
1594 |
# Method called when a LeftDClick event have been generated |
|
27 | 1595 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 1596 |
# Edit the jump properties |
1597 |
self.Parent.EditJumpContent(self) |
|
1598 |
||
1599 |
# Method called when a RightUp event have been generated |
|
27 | 1600 |
def OnRightUp(self, event, dc, scaling): |
0 | 1601 |
# Popup the default menu |
1602 |
self.Parent.PopupDefaultMenu() |
|
1603 |
||
1604 |
# Refreshes the jump state according to move defined and handle selected |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1605 |
def ProcessDragging(self, movex, movey, event, scaling): |
27 | 1606 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1607 |
movex = max(-self.BoundingBox.x, movex) |
145 | 1608 |
if scaling is not None: |
1609 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
27 | 1610 |
self.Move(movex, 0) |
1611 |
self.RefreshInputPosition() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1612 |
return movex, 0 |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1613 |
else: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1614 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, width_fac = 2) |
0 | 1615 |
|
1616 |
# Refresh input element model |
|
1617 |
def RefreshInputModel(self): |
|
27 | 1618 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1619 |
input = self.GetPreviousConnector() |
|
1620 |
if input: |
|
1621 |
input_block = input.GetParentBlock() |
|
1622 |
input_block.RefreshModel(False) |
|
1623 |
if not isinstance(input_block, SFC_Divergence): |
|
1624 |
input_block.RefreshInputModel() |
|
0 | 1625 |
|
1626 |
# Refresh output element model |
|
1627 |
def RefreshOutputModel(self, move=False): |
|
1628 |
pass |
|
1629 |
||
1630 |
# Refreshes the jump model |
|
1631 |
def RefreshModel(self, move=True): |
|
1632 |
self.Parent.RefreshJumpModel(self) |
|
1633 |
if move: |
|
27 | 1634 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1635 |
self.RefreshInputModel() |
|
0 | 1636 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1637 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1638 |
if infos[0] == "target" and start[0] == 0 and end[0] == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1639 |
self.Errors[infos[0]] = (start[1], end[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1640 |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1641 |
# Draws the highlightment of this element if it is highlighted |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1642 |
def DrawHighlightment(self, dc): |
144 | 1643 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1644 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
1645 |
dc.SetLogicalFunction(wx.AND) |
|
1646 |
points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2), |
|
1647 |
wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2), |
|
1648 |
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)] |
|
1649 |
dc.DrawPolygon(points) |
|
1650 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1651 |
|
0 | 1652 |
# Draws divergence |
1653 |
def Draw(self, dc): |
|
144 | 1654 |
Graphic_Element.Draw(self, dc) |
253 | 1655 |
if self.Value: |
1656 |
dc.SetPen(wx.GREEN_PEN) |
|
1657 |
dc.SetBrush(wx.GREEN_BRUSH) |
|
1658 |
else: |
|
1659 |
dc.SetPen(wx.BLACK_PEN) |
|
1660 |
dc.SetBrush(wx.BLACK_BRUSH) |
|
213 | 1661 |
|
1662 |
if getattr(dc, "printing", False): |
|
1663 |
target_size = dc.GetTextExtent(self.Target) |
|
1664 |
else: |
|
1665 |
target_size = self.TargetSize |
|
1666 |
||
0 | 1667 |
# Draw plain rectangle for representing the divergence |
1668 |
dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1669 |
points = [wx.Point(self.Pos.x, self.Pos.y), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1670 |
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1671 |
wx.Point(self.Pos.x + self.Size[0], self.Pos.y), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1672 |
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
0 | 1673 |
dc.DrawPolygon(points) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1674 |
target_pos = (self.Pos.x + self.Size[0] + 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1675 |
self.Pos.y + (self.Size[1] - target_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1676 |
dc.DrawText(self.Target, target_pos[0], target_pos[1]) |
0 | 1677 |
# Draw input connector |
1678 |
if self.Input: |
|
1679 |
self.Input.Draw(dc) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1680 |
if "target" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1681 |
HighlightErrorZone(dc, target_pos[0], target_pos[1], target_size[0], target_size[1]) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1682 |
|
0 | 1683 |
|
1684 |
#------------------------------------------------------------------------------- |
|
1685 |
# Sequencial Function Chart Action Block |
|
1686 |
#------------------------------------------------------------------------------- |
|
1687 |
||
1688 |
""" |
|
1689 |
Class that implements the graphic representation of an action block |
|
1690 |
""" |
|
1691 |
||
1692 |
class SFC_ActionBlock(Graphic_Element): |
|
1693 |
||
1694 |
# Create a new action block |
|
1695 |
def __init__(self, parent, actions = [], id = None): |
|
1696 |
Graphic_Element.__init__(self, parent) |
|
1697 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1698 |
self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
108 | 1699 |
self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1700 |
self.Errors = {} |
0 | 1701 |
# Create an input and output connector |
145 | 1702 |
self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True) |
0 | 1703 |
self.SetActions(actions) |
253 | 1704 |
self.Value = None |
1705 |
self.PreviousValue = None |
|
0 | 1706 |
|
249 | 1707 |
def Flush(self): |
1708 |
if self.Input is not None: |
|
1709 |
self.Input.Flush() |
|
1710 |
self.Input = None |
|
0 | 1711 |
|
253 | 1712 |
def SpreadCurrent(self): |
1713 |
if self.Parent.Debug: |
|
1714 |
self.PreviousValue = self.Value |
|
1715 |
self.Value = self.Input.ReceivingCurrent() |
|
1716 |
if self.Value != self.PreviousValue: |
|
1717 |
self.Refresh() |
|
1718 |
||
112 | 1719 |
# Make a clone of this SFC_ActionBlock |
162 | 1720 |
def Clone(self, parent, id = None, pos = None): |
112 | 1721 |
actions = [action.copy() for action in self.Actions] |
162 | 1722 |
action_block = SFC_ActionBlock(parent, actions, id) |
112 | 1723 |
action_block.SetSize(self.Size[0], self.Size[1]) |
1724 |
if pos is not None: |
|
1725 |
action_block.SetPosition(pos.x, pos.y) |
|
283 | 1726 |
else: |
1727 |
action_block.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 1728 |
action_block.Input = self.Input.Clone(action_block) |
144 | 1729 |
return action_block |
1730 |
||
283 | 1731 |
def GetConnectorTranslation(self, element): |
1732 |
return {self.Input : element.Input} |
|
1733 |
||
1734 |
# Returns the RedrawRect |
|
144 | 1735 |
def GetRedrawRect(self, movex = 0, movey = 0): |
1736 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1737 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
1738 |
if movex != 0 or movey != 0: |
|
1739 |
if self.Input.IsConnected(): |
|
1740 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
1741 |
return rect |
|
112 | 1742 |
|
0 | 1743 |
# Returns the number of action lines |
1744 |
def GetLineNumber(self): |
|
1745 |
return len(self.Actions) |
|
1746 |
||
27 | 1747 |
def GetLineSize(self): |
108 | 1748 |
if len(self.Actions) > 0: |
27 | 1749 |
return self.Size[1] / len(self.Actions) |
1750 |
else: |
|
1751 |
return SFC_ACTION_MIN_SIZE[1] |
|
1752 |
||
0 | 1753 |
# Forbids to resize the action block |
1754 |
def Resize(self, x, y, width, height): |
|
27 | 1755 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1756 |
if x == 0: |
|
1757 |
self.SetSize(width, self.Size[1]) |
|
1758 |
else: |
|
1759 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 1760 |
|
1761 |
# Delete this action block by calling the appropriate method |
|
1762 |
def Delete(self): |
|
1763 |
self.Parent.DeleteActionBlock(self) |
|
1764 |
||
1765 |
# Unconnect input and output |
|
1766 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1767 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1768 |
|
1769 |
# Refresh the action block bounding box |
|
1770 |
def RefreshBoundingBox(self): |
|
144 | 1771 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 1772 |
|
1773 |
# Refresh the position of wires connected to action block |
|
1774 |
def RefreshConnected(self, exclude = []): |
|
1775 |
self.Input.MoveConnected(exclude) |
|
1776 |
||
1777 |
# Returns input action block connector |
|
27 | 1778 |
def GetConnector(self, position = None, name = None): |
0 | 1779 |
return self.Input |
1780 |
||
1781 |
# Test if point given is on action block input connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1782 |
def TestConnector(self, pt, direction = None, exclude = True): |
0 | 1783 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
231
diff
changeset
|
1784 |
if self.Input.TestPoint(pt, direction, exclude): |
0 | 1785 |
return self.Input |
1786 |
return None |
|
1787 |
||
145 | 1788 |
# Refresh the element connectors position |
1789 |
def RefreshConnectors(self): |
|
1790 |
scaling = self.Parent.GetScaling() |
|
1791 |
vertical_pos = SFC_ACTION_MIN_SIZE[1] / 2 |
|
1792 |
if scaling is not None: |
|
1793 |
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
1794 |
self.Input.SetPosition(wx.Point(0, vertical_pos)) |
|
1795 |
self.RefreshConnected() |
|
1796 |
||
0 | 1797 |
# Changes the action block actions |
1798 |
def SetActions(self, actions): |
|
1799 |
self.Actions = actions |
|
1800 |
self.ColSize = [0, 0, 0] |
|
108 | 1801 |
min_height = 0 |
0 | 1802 |
for action in self.Actions: |
165 | 1803 |
width, height = self.Parent.GetTextExtent(action["qualifier"]) |
0 | 1804 |
self.ColSize[0] = max(self.ColSize[0], width + 10) |
108 | 1805 |
row_height = height |
0 | 1806 |
if "duration" in action: |
165 | 1807 |
width, height = self.Parent.GetTextExtent(action["duration"]) |
108 | 1808 |
row_height = max(row_height, height) |
0 | 1809 |
self.ColSize[0] = max(self.ColSize[0], width + 10) |
165 | 1810 |
width, height = self.Parent.GetTextExtent(action["value"]) |
108 | 1811 |
row_height = max(row_height, height) |
0 | 1812 |
self.ColSize[1] = max(self.ColSize[1], width + 10) |
1813 |
if "indicator" in action and action["indicator"] != "": |
|
165 | 1814 |
width, height = self.Parent.GetTextExtent(action["indicator"]) |
108 | 1815 |
row_height = max(row_height, height) |
0 | 1816 |
self.ColSize[2] = max(self.ColSize[2], width + 10) |
108 | 1817 |
min_height += row_height + 5 |
27 | 1818 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
108 | 1819 |
self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1])) |
1820 |
self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
|
1821 |
SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height) |
|
1822 |
self.RefreshBoundingBox() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1823 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1824 |
self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
27 | 1825 |
SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) |
108 | 1826 |
self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
1827 |
SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] |
|
1828 |
self.RefreshBoundingBox() |
|
1829 |
if self.Input: |
|
1830 |
wires = self.Input.GetWires() |
|
1831 |
if len(wires) == 1: |
|
145 | 1832 |
input_block = wires[0][0].GetOtherConnected(self.Input).GetParentBlock() |
108 | 1833 |
input_block.RefreshOutputPosition() |
1834 |
input_block.RefreshOutputModel(True) |
|
0 | 1835 |
|
1836 |
# Returns the action block actions |
|
1837 |
def GetActions(self): |
|
1838 |
return self.Actions |
|
1839 |
||
1840 |
# Returns the action block minimum size |
|
1841 |
def GetMinSize(self): |
|
108 | 1842 |
return self.MinSize |
0 | 1843 |
|
1844 |
# Method called when a LeftDClick event have been generated |
|
27 | 1845 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 1846 |
# Edit the action block properties |
1847 |
self.Parent.EditActionBlockContent(self) |
|
1848 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1849 |
# Method called when a RightUp event have been generated |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1850 |
def OnRightUp(self, event, dc, scaling): |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1851 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1852 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1853 |
|
0 | 1854 |
# Refreshes the action block state according to move defined and handle selected |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1855 |
def ProcessDragging(self, movex, movey, event, scaling): |
27 | 1856 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1857 |
handle_type, handle = self.Handle |
|
1858 |
if handle_type == HANDLE_MOVE: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1859 |
movex = max(-self.BoundingBox.x, movex) |
145 | 1860 |
if scaling is not None: |
1861 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
27 | 1862 |
wires = self.Input.GetWires() |
1863 |
if len(wires) == 1: |
|
145 | 1864 |
input_pos = wires[0][0].GetOtherConnected(self.Input).GetPosition(False) |
27 | 1865 |
if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE: |
1866 |
self.Move(movex, 0) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1867 |
return movex, 0 |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1868 |
return 0, 0 |
27 | 1869 |
else: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1870 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1871 |
else: |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
320
diff
changeset
|
1872 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
27 | 1873 |
|
0 | 1874 |
|
1875 |
# Refreshes the action block model |
|
1876 |
def RefreshModel(self, move=True): |
|
1877 |
self.Parent.RefreshActionBlockModel(self) |
|
1878 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1879 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1880 |
if infos[0] == "action" and infos[1] < len(self.Actions): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1881 |
if infos[1] not in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1882 |
self.Errors[infos[1]] = {} |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1883 |
if infos[2] == "inline": |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1884 |
if infos[2] not in self.Errors[infos[1]]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1885 |
self.Errors[infos[1]][infos[2]] = [] |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1886 |
self.Errors[infos[1]][infos[2]].append((start[1], end[1])) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1887 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1888 |
self.Errors[infos[1]][infos[2]] = (start[1], end[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1889 |
|
0 | 1890 |
# Draws divergence |
1891 |
def Draw(self, dc): |
|
144 | 1892 |
Graphic_Element.Draw(self, dc) |
253 | 1893 |
if self.Value: |
1894 |
dc.SetPen(wx.GREEN_PEN) |
|
1895 |
else: |
|
1896 |
dc.SetPen(wx.BLACK_PEN) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1897 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 1898 |
colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1899 |
# Draw plain rectangle for representing the action block |
|
1900 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1901 |
dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, |
|
1902 |
self.Pos.x + colsize[0], self.Pos.y + self.Size[1]) |
|
1903 |
dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y, |
|
1904 |
self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1]) |
|
27 | 1905 |
line_size = self.GetLineSize() |
0 | 1906 |
for i, action in enumerate(self.Actions): |
1907 |
if i != 0: |
|
27 | 1908 |
dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, |
1909 |
self.Pos.x + self.Size[0], self.Pos.y + i * line_size) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1910 |
qualifier_size = dc.GetTextExtent(action["qualifier"]) |
0 | 1911 |
if "duration" in action: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1912 |
qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1913 |
self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1914 |
duration_size = dc.GetTextExtent(action["duration"]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1915 |
duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1916 |
self.Pos.y + i * line_size + line_size / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1917 |
dc.DrawText(action["duration"], duration_pos[0], duration_pos[1]) |
0 | 1918 |
else: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1919 |
qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1920 |
self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1921 |
dc.DrawText(action["qualifier"], qualifier_pos[0], qualifier_pos[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1922 |
content_size = dc.GetTextExtent(action["value"]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1923 |
content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1924 |
self.Pos.y + i * line_size + (line_size - content_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1925 |
dc.DrawText(action["value"], content_pos[0], content_pos[1]) |
0 | 1926 |
if "indicator" in action: |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1927 |
indicator_size = dc.GetTextExtent(action["indicator"]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1928 |
indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1929 |
self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1930 |
dc.DrawText(action["indicator"], indicator_pos[0], indicator_pos[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1931 |
if i in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1932 |
if "duration" in self.Errors[i] and "duration" in action: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1933 |
HighlightErrorZone(dc, duration_pos[0], duration_pos[1], duration_size[0], duration_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1934 |
if "qualifier" in self.Errors[i]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1935 |
HighlightErrorZone(dc, qualifier_pos[0], qualifier_pos[1], qualifier_size[0], qualifier_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1936 |
if "reference" in self.Errors[i]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1937 |
HighlightErrorZone(dc, content_pos[0], content_pos[1], content_size[0], content_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1938 |
elif "inline" in self.Errors[i]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1939 |
for start, end in self.Errors[i]["inline"]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1940 |
offset = dc.GetTextExtent(action["value"][:start]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1941 |
size = dc.GetTextExtent(action["value"][start:end + 1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1942 |
HighlightErrorZone(dc, content_pos[0] + offset[0], content_pos[1], size[0], size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1943 |
if "indicator" in self.Errors[i]: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1944 |
HighlightErrorZone(dc, indicator_pos[0], indicator_pos[1], indicator_size[0], indicator_size[1]) |
0 | 1945 |
# Draw input connector |
1946 |
self.Input.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1947 |