author | lbessard |
Thu, 06 Dec 2007 18:05:29 +0100 | |
changeset 125 | 394d9f168258 |
parent 112 | 317148fc1225 |
child 127 | 436268f31dae |
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) |
|
49 |
self.Name = name |
|
50 |
self.Initial = initial |
|
51 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
52 |
self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) |
0 | 53 |
# Create an input and output connector |
54 |
if not self.Initial: |
|
108 | 55 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
0 | 56 |
else: |
57 |
self.Input = None |
|
58 |
self.Output = None |
|
59 |
self.Action = None |
|
60 |
||
61 |
# Destructor |
|
62 |
def __del__(self): |
|
63 |
self.Input = None |
|
64 |
self.Output = None |
|
65 |
self.Action = None |
|
66 |
||
112 | 67 |
# Make a clone of this SFC_Step |
68 |
def Clone(self, id = None, pos = None): |
|
69 |
step = SFC_Step(self.Parent, self.Type, self.Name, id) |
|
70 |
step.SetSize(self.Size[0], self.Size[1]) |
|
71 |
if pos is not None: |
|
72 |
step.SetPosition(pos.x, pos.y) |
|
73 |
step.Input = self.Input.Clone(step) |
|
74 |
step.Output = self.Output.Clone(step) |
|
75 |
step.Action = self.Action.Clone(step) |
|
76 |
return step |
|
77 |
||
0 | 78 |
# Delete this step by calling the appropriate method |
79 |
def Delete(self): |
|
80 |
self.Parent.DeleteStep(self) |
|
81 |
||
82 |
# Unconnect input and output |
|
83 |
def Clean(self): |
|
84 |
if self.Input: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
85 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 86 |
if self.Output: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
87 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 88 |
if self.Action: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
89 |
self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 90 |
|
91 |
# Add output connector to step |
|
71 | 92 |
def AddInput(self): |
93 |
if not self.Input: |
|
108 | 94 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
71 | 95 |
self.RefreshBoundingBox() |
96 |
||
97 |
# Remove output connector from step |
|
98 |
def RemoveInput(self): |
|
99 |
if self.Input: |
|
100 |
self.Input.UnConnect() |
|
101 |
self.Input = None |
|
102 |
self.RefreshBoundingBox() |
|
103 |
||
104 |
# Add output connector to step |
|
0 | 105 |
def AddOutput(self): |
106 |
if not self.Output: |
|
108 | 107 |
self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) |
0 | 108 |
self.RefreshBoundingBox() |
109 |
||
110 |
# Remove output connector from step |
|
111 |
def RemoveOutput(self): |
|
112 |
if self.Output: |
|
113 |
self.Output.UnConnect() |
|
114 |
self.Output = None |
|
115 |
self.RefreshBoundingBox() |
|
116 |
||
117 |
# Add action connector to step |
|
118 |
def AddAction(self): |
|
119 |
if not self.Action: |
|
108 | 120 |
self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST) |
0 | 121 |
self.RefreshBoundingBox() |
122 |
||
123 |
# Remove action connector from step |
|
124 |
def RemoveAction(self): |
|
125 |
if self.Action: |
|
126 |
self.Action.UnConnect() |
|
127 |
self.Action = None |
|
128 |
self.RefreshBoundingBox() |
|
129 |
||
130 |
# Refresh the step bounding box |
|
131 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
132 |
dc = wx.ClientDC(self.Parent) |
0 | 133 |
# Calculate the bounding box size |
134 |
if self.Action: |
|
135 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
136 |
else: |
|
137 |
bbx_width = self.Size[0] |
|
138 |
if self.Initial: |
|
139 |
bbx_y = self.Pos.y |
|
140 |
bbx_height = self.Size[1] |
|
141 |
if self.Output: |
|
142 |
bbx_height += CONNECTOR_SIZE |
|
143 |
else: |
|
144 |
bbx_y = self.Pos.y - CONNECTOR_SIZE |
|
145 |
bbx_height = self.Size[1] + CONNECTOR_SIZE |
|
146 |
if self.Output: |
|
147 |
bbx_height += CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
148 |
#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
|
149 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 150 |
|
151 |
# Refresh the positions of the step connectors |
|
152 |
def RefreshConnectors(self): |
|
153 |
# Update input position if it exists |
|
154 |
if self.Input: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
155 |
self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0)) |
0 | 156 |
# Update output position |
157 |
if self.Output: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
158 |
self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1])) |
0 | 159 |
# Update action position if it exists |
160 |
if self.Action: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
161 |
self.Action.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2)) |
0 | 162 |
self.RefreshConnected() |
163 |
||
164 |
# Refresh the position of wires connected to step |
|
165 |
def RefreshConnected(self, exclude = []): |
|
166 |
if self.Input: |
|
167 |
self.Input.MoveConnected(exclude) |
|
168 |
if self.Output: |
|
169 |
self.Output.MoveConnected(exclude) |
|
170 |
if self.Action: |
|
171 |
self.Action.MoveConnected(exclude) |
|
172 |
||
173 |
# Returns the step connector that starts with the point given if it exists |
|
27 | 174 |
def GetConnector(self, position, name = None): |
175 |
# if a name is given |
|
176 |
if name: |
|
177 |
# Test input, output and action connector if they exists |
|
178 |
if self.Input and name == self.Input.GetName(): |
|
179 |
return self.Input |
|
180 |
if self.Output and name == self.Output.GetName(): |
|
181 |
return self.Output |
|
182 |
if self.Action and name == self.Action.GetName(): |
|
183 |
return self.Action |
|
0 | 184 |
# Test input connector if it exists |
185 |
if self.Input: |
|
186 |
input_pos = self.Input.GetRelPosition() |
|
187 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
188 |
return self.Input |
|
189 |
# Test output connector if it exists |
|
190 |
if self.Output: |
|
191 |
output_pos = self.Output.GetRelPosition() |
|
192 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
193 |
return self.Output |
|
194 |
# Test action connector if it exists |
|
195 |
if self.Action: |
|
196 |
action_pos = self.Action.GetRelPosition() |
|
197 |
if position.x == self.Pos.x + action_pos.x and position.y == self.Pos.y + action_pos.y: |
|
198 |
return self.Action |
|
199 |
return None |
|
200 |
||
201 |
# Returns input and output step connectors |
|
202 |
def GetConnectors(self): |
|
203 |
return {"input":self.Input,"output":self.Output,"action":self.Action} |
|
204 |
||
205 |
# Test if point given is on step input or output connector |
|
206 |
def TestConnector(self, pt, exclude=True): |
|
207 |
# Test input connector if it exists |
|
208 |
if self.Input and self.Input.TestPoint(pt, exclude): |
|
209 |
return self.Input |
|
210 |
# Test output connector |
|
211 |
if self.Output and self.Output.TestPoint(pt, exclude): |
|
212 |
return self.Output |
|
108 | 213 |
# Test action connector |
214 |
if self.Action and self.Action.TestPoint(pt, exclude): |
|
215 |
return self.Action |
|
0 | 216 |
return None |
217 |
||
218 |
# Changes the step name |
|
219 |
def SetName(self, name): |
|
220 |
self.Name = name |
|
221 |
||
222 |
# Returns the step name |
|
223 |
def GetName(self): |
|
224 |
return self.Name |
|
225 |
||
226 |
# Returns the step initial property |
|
227 |
def GetInitial(self): |
|
228 |
return self.Initial |
|
229 |
||
230 |
# Returns the connector connected to input |
|
231 |
def GetPreviousConnector(self): |
|
232 |
if self.Input: |
|
233 |
wires = self.Input.GetWires() |
|
234 |
if len(wires) == 1: |
|
235 |
return wires[0][0].EndConnected |
|
236 |
return None |
|
237 |
||
238 |
# Returns the connector connected to output |
|
239 |
def GetNextConnector(self): |
|
240 |
if self.Output: |
|
241 |
wires = self.Output.GetWires() |
|
242 |
if len(wires) == 1: |
|
243 |
return wires[0][0].StartConnected |
|
244 |
return None |
|
245 |
||
246 |
# Returns the connector connected to action |
|
247 |
def GetActionConnector(self): |
|
248 |
if self.Action: |
|
249 |
wires = self.Action.GetWires() |
|
250 |
if len(wires) == 1: |
|
251 |
return wires[0][0].StartConnected |
|
252 |
return None |
|
253 |
||
254 |
# Returns the number of action line |
|
255 |
def GetActionExtraLineNumber(self): |
|
256 |
if self.Action: |
|
257 |
wires = self.Action.GetWires() |
|
258 |
if len(wires) != 1: |
|
259 |
return 0 |
|
260 |
action_block = wires[0][0].StartConnected.GetParentBlock() |
|
261 |
return max(0, action_block.GetLineNumber() - 1) |
|
262 |
return 0 |
|
263 |
||
264 |
# Returns the step minimum size |
|
265 |
def GetMinSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
266 |
dc = wx.ClientDC(self.Parent) |
0 | 267 |
text_width, text_height = dc.GetTextExtent(self.Name) |
268 |
if self.Initial: |
|
269 |
return text_width + 14, text_height + 14 |
|
270 |
else: |
|
271 |
return text_width + 10, text_height + 10 |
|
272 |
||
273 |
# Updates the step size |
|
274 |
def UpdateSize(self, width, height): |
|
275 |
diffx = self.Size.GetWidth() / 2 - width / 2 |
|
276 |
diffy = height - self.Size.GetHeight() |
|
277 |
self.Move(diffx, 0) |
|
278 |
Graphic_Element.SetSize(self, width, height) |
|
108 | 279 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
280 |
self.RefreshConnected() |
|
281 |
else: |
|
282 |
self.RefreshOutputPosition((0, diffy)) |
|
0 | 283 |
|
284 |
# Align input element with this step |
|
285 |
def RefreshInputPosition(self): |
|
286 |
if self.Input: |
|
287 |
current_pos = self.Input.GetPosition(False) |
|
288 |
input = self.GetPreviousConnector() |
|
289 |
if input: |
|
290 |
input_pos = input.GetPosition(False) |
|
291 |
diffx = current_pos.x - input_pos.x |
|
292 |
input_block = input.GetParentBlock() |
|
293 |
if isinstance(input_block, SFC_Divergence): |
|
294 |
input_block.MoveConnector(input, diffx) |
|
295 |
else: |
|
296 |
if isinstance(input_block, SFC_Step): |
|
297 |
input_block.MoveActionBlock((diffx, 0)) |
|
298 |
input_block.Move(diffx, 0) |
|
299 |
input_block.RefreshInputPosition() |
|
300 |
||
301 |
# Align output element with this step |
|
302 |
def RefreshOutputPosition(self, move = None): |
|
303 |
if self.Output: |
|
304 |
wires = self.Output.GetWires() |
|
305 |
if len(wires) != 1: |
|
306 |
return |
|
307 |
current_pos = self.Output.GetPosition(False) |
|
308 |
output = wires[0][0].StartConnected |
|
309 |
output_pos = output.GetPosition(False) |
|
310 |
diffx = current_pos.x - output_pos.x |
|
311 |
output_block = output.GetParentBlock() |
|
312 |
wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
|
313 |
diffy = wire_size - output_pos.y + current_pos.y |
|
314 |
if diffy != 0: |
|
315 |
if isinstance(output_block, SFC_Step): |
|
316 |
output_block.MoveActionBlock((diffx, diffy)) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
317 |
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
|
318 |
wx.Point(current_pos.x, current_pos.y)]) |
0 | 319 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
320 |
output_block.Move(diffx, diffy, self.Parent.Wires) |
|
321 |
output_block.RefreshOutputPosition((diffx, diffy)) |
|
322 |
else: |
|
323 |
output_block.RefreshPosition() |
|
324 |
elif move: |
|
325 |
if isinstance(output_block, SFC_Step): |
|
326 |
output_block.MoveActionBlock(move) |
|
327 |
wires[0][0].Move(move[0], move[1], True) |
|
328 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
329 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
330 |
output_block.RefreshOutputPosition(move) |
|
331 |
else: |
|
332 |
output_block.RefreshPosition() |
|
333 |
elif isinstance(output_block, SFC_Divergence): |
|
334 |
output_block.MoveConnector(output, diffx) |
|
335 |
else: |
|
336 |
if isinstance(output_block, SFC_Step): |
|
337 |
output_block.MoveActionBlock((diffx, 0)) |
|
338 |
output_block.Move(diffx, 0) |
|
339 |
output_block.RefreshOutputPosition() |
|
340 |
||
341 |
# Refresh action element with this step |
|
342 |
def MoveActionBlock(self, move): |
|
343 |
if self.Action: |
|
344 |
wires = self.Action.GetWires() |
|
345 |
if len(wires) != 1: |
|
346 |
return |
|
347 |
action_block = wires[0][0].StartConnected.GetParentBlock() |
|
348 |
action_block.Move(move[0], move[1], self.Parent.Wires) |
|
349 |
wires[0][0].Move(move[0], move[1], True) |
|
350 |
||
351 |
# Resize the divergence from position and size given |
|
352 |
def Resize(self, x, y, width, height): |
|
27 | 353 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
354 |
self.UpdateSize(width, height) |
|
355 |
else: |
|
356 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 357 |
|
358 |
# Method called when a LeftDClick event have been generated |
|
42 | 359 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 360 |
# Edit the step properties |
361 |
self.Parent.EditStepContent(self) |
|
362 |
||
363 |
# Method called when a RightUp event have been generated |
|
27 | 364 |
def OnRightUp(self, event, dc, scaling): |
0 | 365 |
# Popup the menu with special items for a step |
366 |
self.Parent.PopupDefaultMenu() |
|
367 |
||
368 |
# Refreshes the step state according to move defined and handle selected |
|
369 |
def ProcessDragging(self, movex, movey): |
|
370 |
handle_type, handle = self.Handle |
|
371 |
if handle_type == HANDLE_MOVE: |
|
372 |
action_block = None |
|
27 | 373 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
374 |
self.Move(movex, movey) |
|
375 |
self.RefreshConnected() |
|
376 |
elif self.Initial: |
|
0 | 377 |
self.MoveActionBlock((movex, movey)) |
378 |
self.Move(movex, movey, self.Parent.Wires) |
|
379 |
self.RefreshOutputPosition((movex, movey)) |
|
380 |
else: |
|
381 |
self.MoveActionBlock((movex, 0)) |
|
382 |
self.Move(movex, 0) |
|
383 |
self.RefreshInputPosition() |
|
384 |
self.RefreshOutputPosition() |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
385 |
return True, False |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
386 |
else: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
387 |
return Graphic_Element.ProcessDragging(self, movex, movey) |
0 | 388 |
|
389 |
# Refresh input element model |
|
390 |
def RefreshInputModel(self): |
|
391 |
if self.Input: |
|
392 |
input = self.GetPreviousConnector() |
|
393 |
if input: |
|
394 |
input_block = input.GetParentBlock() |
|
395 |
input_block.RefreshModel(False) |
|
396 |
if not isinstance(input_block, SFC_Divergence): |
|
397 |
input_block.RefreshInputModel() |
|
398 |
||
399 |
# Refresh output element model |
|
400 |
def RefreshOutputModel(self, move=False): |
|
401 |
if self.Output: |
|
402 |
output = self.GetNextConnector() |
|
403 |
if output: |
|
404 |
output_block = output.GetParentBlock() |
|
405 |
output_block.RefreshModel(False) |
|
406 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
407 |
output_block.RefreshOutputModel(move) |
|
408 |
||
409 |
# Refreshes the step model |
|
410 |
def RefreshModel(self, move=True): |
|
411 |
self.Parent.RefreshStepModel(self) |
|
412 |
if self.Action: |
|
413 |
action = self.GetActionConnector() |
|
414 |
if action: |
|
415 |
action_block = action.GetParentBlock() |
|
416 |
action_block.RefreshModel(False) |
|
417 |
# If step has moved, refresh the model of wires connected to output |
|
418 |
if move: |
|
27 | 419 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
420 |
self.RefreshInputModel() |
|
421 |
self.RefreshOutputModel(self.Initial) |
|
422 |
elif self.Output: |
|
423 |
self.Output.RefreshWires() |
|
0 | 424 |
|
425 |
# Draws step |
|
426 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
427 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
428 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 429 |
# Draw two rectangles for representing the step |
430 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
431 |
if self.Initial: |
|
432 |
dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
|
433 |
# Draw step name |
|
434 |
namewidth, nameheight = dc.GetTextExtent(self.Name) |
|
435 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2, |
|
436 |
self.Pos.y + (self.Size[1] - nameheight) / 2) |
|
437 |
# Draw input and output connectors |
|
438 |
if self.Input: |
|
439 |
self.Input.Draw(dc) |
|
440 |
if self.Output: |
|
441 |
self.Output.Draw(dc) |
|
442 |
if self.Action: |
|
443 |
self.Action.Draw(dc) |
|
444 |
Graphic_Element.Draw(self, dc) |
|
445 |
||
446 |
#------------------------------------------------------------------------------- |
|
447 |
# Sequencial Function Chart Transition |
|
448 |
#------------------------------------------------------------------------------- |
|
449 |
||
450 |
""" |
|
451 |
Class that implements the graphic representation of a transition |
|
452 |
""" |
|
453 |
||
454 |
class SFC_Transition(Graphic_Element): |
|
455 |
||
456 |
# Create a new transition |
|
80 | 457 |
def __init__(self, parent, type = "reference", condition = None, priority = 0, id = None): |
0 | 458 |
Graphic_Element.__init__(self, parent) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
459 |
self.Type = None |
0 | 460 |
self.Id = id |
80 | 461 |
self.Priority = 0 |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
462 |
self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) |
0 | 463 |
# Create an input and output connector |
108 | 464 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
465 |
self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
466 |
self.SetType(type, condition) |
80 | 467 |
self.SetPriority(priority) |
0 | 468 |
|
469 |
# Destructor |
|
470 |
def __del__(self): |
|
471 |
self.Input = None |
|
472 |
self.Output = None |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
473 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
474 |
self.Condition = None |
0 | 475 |
|
112 | 476 |
# Make a clone of this SFC_Transition |
477 |
def Clone(self, id = None, pos = None): |
|
478 |
transition = SFC_Transition(self.Parent, self.Type, self.Condition, self.Priority, id) |
|
479 |
transition.SetSize(self.Size[0], self.Size[1]) |
|
480 |
if pos is not None: |
|
481 |
transition.SetPosition(pos.x, pos.y) |
|
482 |
transition.Input = self.Input.Clone(transition) |
|
483 |
transition.Output = self.Output.Clone(transition) |
|
484 |
return transition |
|
485 |
||
0 | 486 |
# Forbids to change the transition size |
487 |
def SetSize(self, width, height): |
|
27 | 488 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
489 |
Graphic_Element.SetSize(self, width, height) |
|
0 | 490 |
|
491 |
# Forbids to resize the transition |
|
492 |
def Resize(self, x, y, width, height): |
|
27 | 493 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
494 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 495 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
496 |
# Refresh the size of text for name |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
497 |
def RefreshConditionSize(self): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
498 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
499 |
dc = wx.ClientDC(self.Parent) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
500 |
if self.Condition != "": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
501 |
self.ConditionSize = dc.GetTextExtent(self.Condition) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
502 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
503 |
self.ConditionSize = dc.GetTextExtent("Transition") |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
504 |
|
80 | 505 |
# Refresh the size of text for name |
506 |
def RefreshPrioritySize(self): |
|
507 |
if self.Priority != "": |
|
508 |
dc = wx.ClientDC(self.Parent) |
|
509 |
self.PrioritySize = dc.GetTextExtent(str(self.Priority)) |
|
510 |
else: |
|
511 |
self.PrioritySize = None |
|
512 |
||
0 | 513 |
# Delete this transition by calling the appropriate method |
514 |
def Delete(self): |
|
515 |
self.Parent.DeleteTransition(self) |
|
516 |
||
517 |
# Unconnect input and output |
|
518 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
519 |
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
|
520 |
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
|
521 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
522 |
self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 523 |
|
524 |
# Refresh the transition bounding box |
|
525 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
526 |
dc = wx.ClientDC(self.Parent) |
80 | 527 |
bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] |
528 |
if self.Priority != 0: |
|
529 |
bbx_y = self.Pos.y - self.PrioritySize[1] - 2 |
|
530 |
bbx_width = max(self.Size[0], self.PrioritySize[0]) |
|
531 |
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
|
532 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
533 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
80 | 534 |
bbx_width = bbx_width + CONNECTOR_SIZE |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
535 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
536 |
text_width, text_height = self.ConditionSize |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
537 |
# Calculate the bounding box size |
80 | 538 |
bbx_width = max(bbx_width, self.Size[0] + 5 + text_width) |
539 |
bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2)) |
|
540 |
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
|
541 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 542 |
|
543 |
# Returns the connector connected to input |
|
544 |
def GetPreviousConnector(self): |
|
545 |
wires = self.Input.GetWires() |
|
546 |
if len(wires) == 1: |
|
547 |
return wires[0][0].EndConnected |
|
548 |
return None |
|
549 |
||
550 |
# Returns the connector connected to output |
|
551 |
def GetNextConnector(self): |
|
552 |
wires = self.Output.GetWires() |
|
553 |
if len(wires) == 1: |
|
554 |
return wires[0][0].StartConnected |
|
555 |
return None |
|
556 |
||
557 |
# Refresh the positions of the transition connectors |
|
558 |
def RefreshConnectors(self): |
|
559 |
# Update input position |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
560 |
self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0)) |
0 | 561 |
# Update output position |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
562 |
self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1])) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
563 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
564 |
self.Condition.SetPosition(wx.Point(0, self.Size[1] / 2)) |
0 | 565 |
self.RefreshConnected() |
566 |
||
567 |
# Refresh the position of the wires connected to transition |
|
568 |
def RefreshConnected(self, exclude = []): |
|
569 |
self.Input.MoveConnected(exclude) |
|
570 |
self.Output.MoveConnected(exclude) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
571 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
572 |
self.Condition.MoveConnected(exclude) |
0 | 573 |
|
574 |
# Returns the transition connector that starts with the point given if it exists |
|
27 | 575 |
def GetConnector(self, position, name = None): |
576 |
# if a name is given |
|
577 |
if name: |
|
578 |
# Test input and output connector |
|
579 |
if name == self.Input.GetName(): |
|
580 |
return self.Input |
|
581 |
if name == self.Output.GetName(): |
|
582 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
583 |
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
|
584 |
return self.Condition |
0 | 585 |
# Test input connector |
586 |
input_pos = self.Input.GetRelPosition() |
|
587 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
588 |
return self.Input |
|
589 |
# Test output connector |
|
590 |
output_pos = self.Output.GetRelPosition() |
|
591 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
592 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
593 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
594 |
# Test condition connector |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
595 |
condition_pos = self.Condition.GetRelPosition() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
596 |
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
|
597 |
return self.Condition |
0 | 598 |
return None |
599 |
||
600 |
# Returns input and output transition connectors |
|
601 |
def GetConnectors(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
602 |
connectors = {"input":self.Input,"output":self.Output} |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
603 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
604 |
connectors["connection"] = self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
605 |
return connectors |
0 | 606 |
|
607 |
# Test if point given is on transition input or output connector |
|
608 |
def TestConnector(self, pt, exclude=True): |
|
609 |
# Test input connector |
|
610 |
if self.Input.TestPoint(pt, exclude): |
|
611 |
return self.Input |
|
612 |
# Test output connector |
|
613 |
if self.Output.TestPoint(pt, exclude): |
|
614 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
615 |
# Test condition connector |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
616 |
if self.Type == "connection" and self.Condition.TestPoint(pt, exclude): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
617 |
return self.Condition |
0 | 618 |
return None |
619 |
||
620 |
# Changes the transition type |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
621 |
def SetType(self, type, condition = None): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
622 |
if self.Type != type: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
623 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
624 |
self.Condition.UnConnect() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
625 |
self.Type = type |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
626 |
if type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
627 |
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
|
628 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
629 |
if condition == None: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
630 |
condition = "" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
631 |
self.Condition = condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
632 |
self.RefreshConditionSize() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
633 |
elif self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
634 |
if condition == None: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
635 |
condition = "" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
636 |
self.Condition = condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
637 |
self.RefreshConditionSize() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
638 |
self.RefreshBoundingBox() |
0 | 639 |
|
640 |
# Returns the transition type |
|
641 |
def GetType(self): |
|
642 |
return self.Type |
|
643 |
||
80 | 644 |
# Changes the transition priority |
645 |
def SetPriority(self, priority): |
|
646 |
self.Priority = priority |
|
647 |
self.RefreshPrioritySize() |
|
648 |
self.RefreshBoundingBox() |
|
649 |
||
650 |
# Returns the transition type |
|
651 |
def GetPriority(self): |
|
652 |
return self.Priority |
|
653 |
||
0 | 654 |
# Returns the transition condition |
655 |
def GetCondition(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
656 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
657 |
return self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
658 |
return None |
0 | 659 |
|
660 |
# Returns the transition minimum size |
|
661 |
def GetMinSize(self): |
|
662 |
return SFC_TRANSITION_SIZE |
|
663 |
||
664 |
# Align input element with this step |
|
665 |
def RefreshInputPosition(self): |
|
666 |
wires = self.Input.GetWires() |
|
667 |
current_pos = self.Input.GetPosition(False) |
|
668 |
input = self.GetPreviousConnector() |
|
669 |
if input: |
|
670 |
input_pos = input.GetPosition(False) |
|
671 |
diffx = current_pos.x - input_pos.x |
|
672 |
input_block = input.GetParentBlock() |
|
673 |
if isinstance(input_block, SFC_Divergence): |
|
674 |
input_block.MoveConnector(input, diffx) |
|
675 |
else: |
|
676 |
if isinstance(input_block, SFC_Step): |
|
677 |
input_block.MoveActionBlock((diffx, 0)) |
|
678 |
input_block.Move(diffx, 0) |
|
679 |
input_block.RefreshInputPosition() |
|
680 |
||
681 |
# Align output element with this step |
|
682 |
def RefreshOutputPosition(self, move = None): |
|
683 |
wires = self.Output.GetWires() |
|
684 |
if len(wires) != 1: |
|
685 |
return |
|
686 |
current_pos = self.Output.GetPosition(False) |
|
687 |
output = wires[0][0].StartConnected |
|
688 |
output_pos = output.GetPosition(False) |
|
689 |
diffx = current_pos.x - output_pos.x |
|
690 |
output_block = output.GetParentBlock() |
|
691 |
if move: |
|
692 |
if isinstance(output_block, SFC_Step): |
|
693 |
output_block.MoveActionBlock(move) |
|
694 |
wires[0][0].Move(move[0], move[1], True) |
|
695 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
696 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
697 |
output_block.RefreshOutputPosition(move) |
|
698 |
else: |
|
699 |
output_block.RefreshPosition() |
|
700 |
elif isinstance(output_block, SFC_Divergence): |
|
701 |
output_block.MoveConnector(output, diffx) |
|
702 |
else: |
|
703 |
if isinstance(output_block, SFC_Step): |
|
704 |
output_block.MoveActionBlock((diffx, 0)) |
|
705 |
output_block.Move(diffx, 0) |
|
706 |
output_block.RefreshOutputPosition() |
|
27 | 707 |
|
0 | 708 |
# Method called when a LeftDClick event have been generated |
27 | 709 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 710 |
# Edit the transition properties |
711 |
self.Parent.EditTransitionContent(self) |
|
712 |
||
713 |
# Method called when a RightUp event have been generated |
|
27 | 714 |
def OnRightUp(self, event, dc, scaling): |
0 | 715 |
# Popup the menu with special items for a step |
716 |
self.Parent.PopupDefaultMenu() |
|
717 |
||
718 |
# Refreshes the transition state according to move defined and handle selected |
|
719 |
def ProcessDragging(self, movex, movey): |
|
27 | 720 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
721 |
self.Move(movex, 0) |
|
722 |
self.RefreshInputPosition() |
|
723 |
self.RefreshOutputPosition() |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
724 |
return True, False |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
725 |
else: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
726 |
return Graphic_Element.ProcessDragging(self, movex, movey) |
0 | 727 |
|
728 |
# Refresh input element model |
|
729 |
def RefreshInputModel(self): |
|
27 | 730 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
731 |
input = self.GetPreviousConnector() |
|
732 |
if input: |
|
733 |
input_block = input.GetParentBlock() |
|
734 |
input_block.RefreshModel(False) |
|
735 |
if not isinstance(input_block, SFC_Divergence): |
|
736 |
input_block.RefreshInputModel() |
|
0 | 737 |
|
738 |
# Refresh output element model |
|
739 |
def RefreshOutputModel(self, move=False): |
|
740 |
output = self.GetNextConnector() |
|
741 |
if output: |
|
742 |
output_block = output.GetParentBlock() |
|
743 |
output_block.RefreshModel(False) |
|
744 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
745 |
output_block.RefreshOutputModel(move) |
|
746 |
||
747 |
# Refreshes the transition model |
|
748 |
def RefreshModel(self, move=True): |
|
749 |
self.Parent.RefreshTransitionModel(self) |
|
750 |
# If transition has moved, refresh the model of wires connected to output |
|
751 |
if move: |
|
27 | 752 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
753 |
self.RefreshInputModel() |
|
754 |
self.RefreshOutputModel() |
|
755 |
else: |
|
756 |
self.Output.RefreshWires() |
|
0 | 757 |
|
758 |
# Draws transition |
|
759 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
760 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
761 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 762 |
# Draw plain rectangle for representing the transition |
763 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
764 |
# Draw transition condition |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
765 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
766 |
text_width, text_height = self.ConditionSize |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
767 |
if self.Condition != "": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
768 |
condition = self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
769 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
770 |
condition = "Transition" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
771 |
dc.DrawText(condition, self.Pos.x + self.Size[0] + 5, |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
772 |
self.Pos.y + (self.Size[1] - text_height) / 2) |
80 | 773 |
# Draw priority number |
774 |
if self.Priority != 0: |
|
775 |
priority_width, priority_height = self.PrioritySize |
|
776 |
dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - self.PrioritySize[1] - 2) |
|
0 | 777 |
# Draw input and output connectors |
778 |
self.Input.Draw(dc) |
|
779 |
self.Output.Draw(dc) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
780 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
781 |
self.Condition.Draw(dc) |
0 | 782 |
Graphic_Element.Draw(self, dc) |
783 |
||
784 |
#------------------------------------------------------------------------------- |
|
785 |
# Sequencial Function Chart Divergence and Convergence |
|
786 |
#------------------------------------------------------------------------------- |
|
787 |
||
788 |
""" |
|
789 |
Class that implements the graphic representation of a divergence or convergence, |
|
790 |
selection or simultaneous |
|
791 |
""" |
|
792 |
||
793 |
class SFC_Divergence(Graphic_Element): |
|
794 |
||
795 |
# Create a new divergence |
|
796 |
def __init__(self, parent, type, number = 2, id = None): |
|
797 |
Graphic_Element.__init__(self, parent) |
|
798 |
self.Type = type |
|
799 |
self.Id = id |
|
800 |
self.RealConnectors = None |
|
801 |
number = max(2, number) |
|
802 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
803 |
self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1) |
0 | 804 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
805 |
self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3) |
0 | 806 |
# Create an input and output connector |
807 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
108 | 808 |
self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)] |
0 | 809 |
self.Outputs = [] |
810 |
for i in xrange(number): |
|
108 | 811 |
self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)) |
0 | 812 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
813 |
self.Inputs = [] |
|
814 |
for i in xrange(number): |
|
108 | 815 |
self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)) |
816 |
self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)] |
|
0 | 817 |
|
818 |
# Destructor |
|
819 |
def __del__(self): |
|
820 |
self.Inputs = [] |
|
821 |
self.Outputs = [] |
|
822 |
||
112 | 823 |
# Make a clone of this SFC_Divergence |
824 |
def Clone(self, id = None, pos = None): |
|
825 |
divergence = SFC_Divergence(self.Parent, self.Type, max(len(self.Inputs), len(self.Outputs)), id) |
|
826 |
divergence.SetSize(self.Size[0], self.Size[1]) |
|
827 |
if pos is not None: |
|
828 |
divergence.SetPosition(pos.x, pos.y) |
|
829 |
divergence.Inputs = [input.Clone(divergence) for input in self.Inputs] |
|
830 |
divergence.Outputs = [output.Clone(divergence) for output in self.Outputs] |
|
831 |
return divergence |
|
832 |
||
0 | 833 |
# Forbids to resize the divergence |
834 |
def Resize(self, x, y, width, height): |
|
27 | 835 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
836 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 837 |
|
838 |
# Delete this divergence by calling the appropriate method |
|
839 |
def Delete(self): |
|
840 |
self.Parent.DeleteDivergence(self) |
|
841 |
||
842 |
# Returns the divergence type |
|
843 |
def GetType(self): |
|
844 |
return self.Type |
|
845 |
||
846 |
# Unconnect input and output |
|
847 |
def Clean(self): |
|
848 |
for input in self.Inputs: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
849 |
input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 850 |
for output in self.Outputs: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
851 |
output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 852 |
|
853 |
# Add a branch to the divergence |
|
854 |
def AddBranch(self): |
|
855 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
856 |
maxx = 0 |
|
857 |
for output in self.Outputs: |
|
858 |
pos = output.GetRelPosition() |
|
859 |
maxx = max(maxx, pos.x) |
|
108 | 860 |
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH) |
0 | 861 |
self.Outputs.append(connector) |
862 |
self.MoveConnector(connector, 0) |
|
863 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
864 |
maxx = 0 |
|
865 |
for input in self.Inputs: |
|
866 |
pos = input.GetRelPosition() |
|
867 |
maxx = max(maxx, pos.x) |
|
108 | 868 |
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH) |
0 | 869 |
self.Inputs.append(connector) |
870 |
self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) |
|
871 |
||
872 |
# Remove a branch from the divergence |
|
873 |
def RemoveBranch(self, connector): |
|
874 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
875 |
if connector in self.Outputs and len(self.Outputs) > 2: |
0 | 876 |
self.Outputs.remove(connector) |
877 |
self.MoveConnector(self.Outputs[0], 0) |
|
878 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
879 |
if connector in self.Inputs and len(self.Inputs) > 2: |
0 | 880 |
self.Inputs.remove(connector) |
881 |
self.MoveConnector(self.Inputs[0], 0) |
|
882 |
||
80 | 883 |
# Remove the handled branch from the divergence |
884 |
def RemoveHandledBranch(self): |
|
885 |
handle_type, handle = self.Handle |
|
886 |
if handle_type == HANDLE_CONNECTOR: |
|
887 |
handle.UnConnect(delete=True) |
|
888 |
self.RemoveBranch(handle) |
|
889 |
||
0 | 890 |
# Return the number of branches for the divergence |
891 |
def GetBranchNumber(self): |
|
892 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
893 |
return len(self.Outputs) |
|
894 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
895 |
return len(self.Inputs) |
|
896 |
||
897 |
# Returns if the point given is in the bounding box |
|
898 |
def HitTest(self, pt): |
|
899 |
rect = self.BoundingBox |
|
900 |
return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None |
|
901 |
||
902 |
# Refresh the divergence bounding box |
|
903 |
def RefreshBoundingBox(self): |
|
904 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
905 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - 2, |
2 | 906 |
self.Size[0] + 1, self.Size[1] + 5) |
0 | 907 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
908 |
self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2, |
2 | 909 |
self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5) |
0 | 910 |
|
911 |
# Refresh the position of wires connected to divergence |
|
912 |
def RefreshConnected(self, exclude = []): |
|
913 |
for input in self.Inputs: |
|
914 |
input.MoveConnected(exclude) |
|
915 |
for output in self.Outputs: |
|
916 |
output.MoveConnected(exclude) |
|
917 |
||
918 |
# Moves the divergence connector given |
|
919 |
def MoveConnector(self, connector, movex): |
|
920 |
position = connector.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
921 |
connector.SetPosition(wx.Point(position.x + movex, position.y)) |
0 | 922 |
minx = self.Size[0] |
923 |
maxx = 0 |
|
924 |
for input in self.Inputs: |
|
925 |
input_pos = input.GetRelPosition() |
|
926 |
minx = min(minx, input_pos.x) |
|
927 |
maxx = max(maxx, input_pos.x) |
|
928 |
for output in self.Outputs: |
|
929 |
output_pos = output.GetRelPosition() |
|
930 |
minx = min(minx, output_pos.x) |
|
931 |
maxx = max(maxx, output_pos.x) |
|
932 |
if minx != 0: |
|
933 |
for input in self.Inputs: |
|
934 |
input_pos = input.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
935 |
input.SetPosition(wx.Point(input_pos.x - minx, input_pos.y)) |
0 | 936 |
for output in self.Outputs: |
937 |
output_pos = output.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
938 |
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
|
939 |
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
|
940 |
self.Outputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x)) |
0 | 941 |
self.Pos.x += minx |
942 |
self.Size[0] = maxx - minx |
|
943 |
connector.MoveConnected() |
|
944 |
self.RefreshBoundingBox() |
|
945 |
||
946 |
# Returns the divergence connector that starts with the point given if it exists |
|
27 | 947 |
def GetConnector(self, position, name = None): |
948 |
# if a name is given |
|
949 |
if name: |
|
950 |
# Test each input and output connector |
|
951 |
for input in self.Inputs: |
|
952 |
if name == input.GetName(): |
|
953 |
return input |
|
954 |
for output in self.Outputs: |
|
955 |
if name == output.GetName(): |
|
956 |
return output |
|
0 | 957 |
# Test input connector |
958 |
for input in self.Inputs: |
|
959 |
input_pos = input.GetPosition(False) |
|
960 |
if position.x == input_pos.x and position.y == input_pos.y: |
|
961 |
return input |
|
962 |
# Test output connector |
|
963 |
for output in self.Outputs: |
|
964 |
output_pos = output.GetPosition(False) |
|
965 |
if position.x == output_pos.x and position.y == output_pos.y: |
|
966 |
return output |
|
967 |
return None |
|
968 |
||
969 |
# Returns input and output divergence connectors |
|
970 |
def GetConnectors(self): |
|
971 |
return {"inputs":self.Inputs,"outputs":self.Outputs} |
|
972 |
||
973 |
# Test if point given is on divergence input or output connector |
|
974 |
def TestConnector(self, pt, exclude=True): |
|
975 |
# Test input connector |
|
976 |
for input in self.Inputs: |
|
977 |
if input.TestPoint(pt, exclude): |
|
978 |
return input |
|
979 |
# Test output connector |
|
980 |
for output in self.Outputs: |
|
981 |
if output.TestPoint(pt, exclude): |
|
982 |
return output |
|
983 |
return None |
|
984 |
||
985 |
# Changes the divergence size |
|
986 |
def SetSize(self, width, height): |
|
987 |
for i, input in enumerate(self.Inputs): |
|
988 |
position = input.GetRelPosition() |
|
989 |
if self.RealConnectors: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
990 |
input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) |
0 | 991 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
992 |
input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) |
0 | 993 |
input.MoveConnected() |
994 |
for i, output in enumerate(self.Outputs): |
|
995 |
position = output.GetRelPosition() |
|
996 |
if self.RealConnectors: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
997 |
output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), self.Size[1])) |
0 | 998 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
999 |
output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), self.Size[1])) |
0 | 1000 |
output.MoveConnected() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1001 |
self.Size = wx.Size(width, height) |
0 | 1002 |
self.RefreshBoundingBox() |
1003 |
||
1004 |
# Returns the divergence minimum size |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1005 |
def GetMinSize(self, default=False): |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1006 |
width = 0 |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1007 |
if default: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1008 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1009 |
width = (len(self.Outputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1010 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1011 |
width = (len(self.Inputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL |
27 | 1012 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1013 |
return width, 1 |
27 | 1014 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1015 |
return width, 3 |
27 | 1016 |
return 0, 0 |
0 | 1017 |
|
1018 |
# Refresh the position of the block connected to connector |
|
1019 |
def RefreshConnectedPosition(self, connector): |
|
1020 |
wires = connector.GetWires() |
|
1021 |
if len(wires) != 1: |
|
1022 |
return |
|
1023 |
current_pos = connector.GetPosition(False) |
|
1024 |
if connector in self.Inputs: |
|
1025 |
next = wires[0][0].EndConnected |
|
1026 |
else: |
|
1027 |
next = wires[0][0].StartConnected |
|
1028 |
next_pos = next.GetPosition(False) |
|
1029 |
diffx = current_pos.x - next_pos.x |
|
1030 |
next_block = next.GetParentBlock() |
|
1031 |
if isinstance(next_block, SFC_Divergence): |
|
1032 |
next_block.MoveConnector(next, diffx) |
|
1033 |
else: |
|
1034 |
next_block.Move(diffx, 0) |
|
1035 |
if connector in self.Inputs: |
|
1036 |
next_block.RefreshInputPosition() |
|
1037 |
else: |
|
1038 |
next_block.RefreshOutputPosition() |
|
27 | 1039 |
|
0 | 1040 |
# Refresh the position of this divergence |
1041 |
def RefreshPosition(self): |
|
1042 |
y = 0 |
|
1043 |
for input in self.Inputs: |
|
1044 |
wires = input.GetWires() |
|
1045 |
if len(wires) != 1: |
|
1046 |
return |
|
1047 |
previous = wires[0][0].EndConnected |
|
1048 |
previous_pos = previous.GetPosition(False) |
|
1049 |
y = max(y, previous_pos.y + GetWireSize(previous.GetParentBlock())) |
|
1050 |
diffy = y - self.Pos.y |
|
1051 |
if diffy != 0: |
|
1052 |
self.Move(0, diffy, self.Parent.Wires) |
|
1053 |
self.RefreshOutputPosition((0, diffy)) |
|
1054 |
for input in self.Inputs: |
|
1055 |
input.MoveConnected() |
|
1056 |
||
1057 |
# Align output element with this divergence |
|
1058 |
def RefreshOutputPosition(self, move = None): |
|
1059 |
if move: |
|
1060 |
for output_connector in self.Outputs: |
|
1061 |
wires = output_connector.GetWires() |
|
1062 |
if len(wires) != 1: |
|
1063 |
return |
|
1064 |
current_pos = output_connector.GetPosition(False) |
|
1065 |
output = wires[0][0].StartConnected |
|
1066 |
output_pos = output.GetPosition(False) |
|
1067 |
diffx = current_pos.x - output_pos.x |
|
1068 |
output_block = output.GetParentBlock() |
|
1069 |
if isinstance(output_block, SFC_Step): |
|
1070 |
output_block.MoveActionBlock(move) |
|
1071 |
wires[0][0].Move(move[0], move[1], True) |
|
1072 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
1073 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
1074 |
output_block.RefreshOutputPosition(move) |
|
1075 |
||
1076 |
# Method called when a LeftDown event have been generated |
|
27 | 1077 |
def OnLeftDown(self, event, dc, scaling): |
1078 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 1079 |
# Test if a connector have been handled |
1080 |
connector = self.TestConnector(pos, False) |
|
1081 |
if connector: |
|
1082 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1083 |
self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
0 | 1084 |
self.Selected = False |
1085 |
# Initializes the last position |
|
27 | 1086 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
0 | 1087 |
else: |
1088 |
self.RealConnectors = {"Inputs":[],"Outputs":[]} |
|
1089 |
for input in self.Inputs: |
|
1090 |
position = input.GetRelPosition() |
|
1091 |
self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) |
|
1092 |
for output in self.Outputs: |
|
1093 |
position = output.GetRelPosition() |
|
1094 |
self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) |
|
27 | 1095 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
0 | 1096 |
|
1097 |
# Method called when a LeftUp event have been generated |
|
27 | 1098 |
def OnLeftUp(self, event, dc, scaling): |
0 | 1099 |
self.RealConnectors = None |
1100 |
handle_type, handle = self.Handle |
|
1101 |
if handle_type == HANDLE_CONNECTOR: |
|
1102 |
wires = handle.GetWires() |
|
1103 |
if len(wires) != 1: |
|
1104 |
return |
|
1105 |
if handle in self.Inputs: |
|
1106 |
block = wires[0][0].EndConnected.GetParentBlock() |
|
1107 |
else: |
|
1108 |
block = wires[0][0].StartConnected.GetParentBlock() |
|
1109 |
block.RefreshModel(False) |
|
1110 |
if not isinstance(block, SFC_Divergence): |
|
1111 |
if handle in self.Inputs: |
|
1112 |
block.RefreshInputModel() |
|
1113 |
else: |
|
1114 |
block.RefreshOutputModel() |
|
27 | 1115 |
Graphic_Element.OnLeftUp(self, event, dc, scaling) |
0 | 1116 |
|
1117 |
# Method called when a RightUp event have been generated |
|
27 | 1118 |
def OnRightUp(self, event, dc, scaling): |
1119 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 1120 |
# Popup the menu with special items for a block and a connector if one is handled |
1121 |
connector = self.TestConnector(pos, False) |
|
1122 |
if connector: |
|
1123 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
1124 |
self.Parent.PopupDivergenceMenu(True) |
|
1125 |
else: |
|
1126 |
# Popup the divergence menu without delete branch |
|
1127 |
self.Parent.PopupDivergenceMenu(False) |
|
1128 |
||
1129 |
# Refreshes the divergence state according to move defined and handle selected |
|
1130 |
def ProcessDragging(self, movex, movey): |
|
1131 |
handle_type, handle = self.Handle |
|
1132 |
# A connector has been handled |
|
1133 |
if handle_type == HANDLE_CONNECTOR: |
|
1134 |
self.MoveConnector(handle, movex) |
|
27 | 1135 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1136 |
self.RefreshConnectedPosition(handle) |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1137 |
return True, False |
27 | 1138 |
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1139 |
return Graphic_Element.ProcessDragging(self, movex, movey) |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1140 |
return False, False |
0 | 1141 |
|
1142 |
# Refresh output element model |
|
1143 |
def RefreshOutputModel(self, move=False): |
|
27 | 1144 |
if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
0 | 1145 |
for output in self.Outputs: |
1146 |
wires = output.GetWires() |
|
1147 |
if len(wires) != 1: |
|
1148 |
return |
|
1149 |
output_block = wires[0][0].StartConnected.GetParentBlock() |
|
1150 |
output_block.RefreshModel(False) |
|
1151 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
1152 |
output_block.RefreshOutputModel(move) |
|
1153 |
||
1154 |
# Refreshes the divergence model |
|
1155 |
def RefreshModel(self, move=True): |
|
1156 |
self.Parent.RefreshDivergenceModel(self) |
|
1157 |
# If divergence has moved, refresh the model of wires connected to outputs |
|
1158 |
if move: |
|
27 | 1159 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1160 |
self.RefreshOutputModel() |
|
1161 |
else: |
|
1162 |
for output in self.Outputs: |
|
1163 |
output.RefreshWires() |
|
0 | 1164 |
|
1165 |
# Draws divergence |
|
1166 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1167 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1168 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 1169 |
# Draw plain rectangle for representing the divergence |
1170 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
1171 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1172 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1173 |
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, |
|
1174 |
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y) |
|
27 | 1175 |
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + self.Size[1], |
1176 |
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + self.Size[1]) |
|
0 | 1177 |
# Draw inputs and outputs connectors |
1178 |
for input in self.Inputs: |
|
1179 |
input.Draw(dc) |
|
1180 |
for output in self.Outputs: |
|
1181 |
output.Draw(dc) |
|
1182 |
Graphic_Element.Draw(self, dc) |
|
1183 |
||
1184 |
#------------------------------------------------------------------------------- |
|
1185 |
# Sequencial Function Chart Jump to Step |
|
1186 |
#------------------------------------------------------------------------------- |
|
1187 |
||
1188 |
""" |
|
1189 |
Class that implements the graphic representation of a jump to step |
|
1190 |
""" |
|
1191 |
||
1192 |
class SFC_Jump(Graphic_Element): |
|
1193 |
||
1194 |
# Create a new jump |
|
1195 |
def __init__(self, parent, target, id = None): |
|
1196 |
Graphic_Element.__init__(self, parent) |
|
1197 |
self.Target = target |
|
1198 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1199 |
self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
0 | 1200 |
# Create an input and output connector |
108 | 1201 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) |
0 | 1202 |
|
1203 |
# Destructor |
|
1204 |
def __del__(self): |
|
27 | 1205 |
self.Input = None |
0 | 1206 |
|
112 | 1207 |
# Make a clone of this SFC_Jump |
1208 |
def Clone(self, id = None, pos = None): |
|
1209 |
jump = SFC_Jump(self.Parent, self.Target, id) |
|
1210 |
jump.SetSize(self.Size[0], self.Size[1]) |
|
1211 |
if pos is not None: |
|
1212 |
jump.SetPosition(pos.x, pos.y) |
|
1213 |
jump.Input = self.Input.Clone(jump) |
|
1214 |
return jump |
|
1215 |
||
0 | 1216 |
# Forbids to change the jump size |
1217 |
def SetSize(self, width, height): |
|
27 | 1218 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1219 |
Graphic_Element.SetSize(self, width, height) |
|
0 | 1220 |
|
1221 |
# Forbids to resize jump |
|
1222 |
def Resize(self, x, y, width, height): |
|
27 | 1223 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1224 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 1225 |
|
1226 |
# Delete this jump by calling the appropriate method |
|
1227 |
def Delete(self): |
|
1228 |
self.Parent.DeleteJump(self) |
|
1229 |
||
1230 |
# Unconnect input |
|
1231 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1232 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1233 |
|
1234 |
# Refresh the jump bounding box |
|
1235 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1236 |
dc = wx.ClientDC(self.Parent) |
0 | 1237 |
text_width, text_height = dc.GetTextExtent(self.Target) |
1238 |
# Calculate the bounding box size |
|
1239 |
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
|
1240 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, |
0 | 1241 |
bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1) |
1242 |
||
1243 |
# Returns the connector connected to input |
|
1244 |
def GetPreviousConnector(self): |
|
27 | 1245 |
wires = self.Input.GetWires() |
1246 |
if len(wires) == 1: |
|
1247 |
return wires[0][0].EndConnected |
|
0 | 1248 |
return None |
1249 |
||
27 | 1250 |
# Refresh the element connectors position |
1251 |
def RefreshConnectors(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1252 |
self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0)) |
27 | 1253 |
self.RefreshConnected() |
1254 |
||
0 | 1255 |
# Refresh the position of wires connected to jump |
1256 |
def RefreshConnected(self, exclude = []): |
|
1257 |
if self.Input: |
|
1258 |
self.Input.MoveConnected(exclude) |
|
1259 |
||
1260 |
# Returns input jump connector |
|
27 | 1261 |
def GetConnector(self, position = None, name = None): |
0 | 1262 |
return self.Input |
1263 |
||
1264 |
# Test if point given is on jump input connector |
|
1265 |
def TestConnector(self, pt, exclude = True): |
|
1266 |
# Test input connector |
|
1267 |
if self.Input and self.Input.TestPoint(pt, exclude): |
|
1268 |
return self.Input |
|
1269 |
return None |
|
1270 |
||
1271 |
# Changes the jump target |
|
1272 |
def SetTarget(self, target): |
|
1273 |
self.Target = target |
|
1274 |
self.RefreshBoundingBox() |
|
1275 |
||
1276 |
# Returns the jump target |
|
1277 |
def GetTarget(self): |
|
1278 |
return self.Target |
|
1279 |
||
1280 |
# Returns the jump minimum size |
|
1281 |
def GetMinSize(self): |
|
1282 |
return SFC_JUMP_SIZE |
|
1283 |
||
1284 |
# Align input element with this jump |
|
1285 |
def RefreshInputPosition(self): |
|
1286 |
if self.Input: |
|
1287 |
current_pos = self.Input.GetPosition(False) |
|
1288 |
input = self.GetPreviousConnector() |
|
1289 |
if input: |
|
1290 |
input_pos = input.GetPosition(False) |
|
1291 |
diffx = current_pos.x - input_pos.x |
|
1292 |
input_block = input.GetParentBlock() |
|
1293 |
if isinstance(input_block, SFC_Divergence): |
|
1294 |
input_block.MoveConnector(input, diffx) |
|
1295 |
else: |
|
1296 |
if isinstance(input_block, SFC_Step): |
|
1297 |
input_block.MoveActionBlock((diffx, 0)) |
|
1298 |
input_block.Move(diffx, 0) |
|
1299 |
input_block.RefreshInputPosition() |
|
1300 |
||
1301 |
# Can't align output element, because there is no output |
|
1302 |
def RefreshOutputPosition(self, move = None): |
|
1303 |
pass |
|
1304 |
||
1305 |
# Method called when a LeftDClick event have been generated |
|
27 | 1306 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 1307 |
# Edit the jump properties |
1308 |
self.Parent.EditJumpContent(self) |
|
1309 |
||
1310 |
# Method called when a RightUp event have been generated |
|
27 | 1311 |
def OnRightUp(self, event, dc, scaling): |
0 | 1312 |
# Popup the default menu |
1313 |
self.Parent.PopupDefaultMenu() |
|
1314 |
||
1315 |
# Refreshes the jump state according to move defined and handle selected |
|
1316 |
def ProcessDragging(self, movex, movey): |
|
27 | 1317 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1318 |
self.Move(movex, 0) |
|
1319 |
self.RefreshInputPosition() |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1320 |
return True, False |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1321 |
else: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1322 |
return Graphic_Element.ProcessDragging(self, movex, movey) |
0 | 1323 |
|
1324 |
# Refresh input element model |
|
1325 |
def RefreshInputModel(self): |
|
27 | 1326 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1327 |
input = self.GetPreviousConnector() |
|
1328 |
if input: |
|
1329 |
input_block = input.GetParentBlock() |
|
1330 |
input_block.RefreshModel(False) |
|
1331 |
if not isinstance(input_block, SFC_Divergence): |
|
1332 |
input_block.RefreshInputModel() |
|
0 | 1333 |
|
1334 |
# Refresh output element model |
|
1335 |
def RefreshOutputModel(self, move=False): |
|
1336 |
pass |
|
1337 |
||
1338 |
# Refreshes the jump model |
|
1339 |
def RefreshModel(self, move=True): |
|
1340 |
self.Parent.RefreshJumpModel(self) |
|
1341 |
if move: |
|
27 | 1342 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1343 |
self.RefreshInputModel() |
|
0 | 1344 |
|
1345 |
# Draws divergence |
|
1346 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1347 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1348 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 1349 |
# Draw plain rectangle for representing the divergence |
1350 |
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
|
1351 |
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
|
1352 |
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
|
1353 |
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
|
1354 |
wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] |
0 | 1355 |
dc.DrawPolygon(points) |
1356 |
text_width, text_height = dc.GetTextExtent(self.Target) |
|
1357 |
dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2, |
|
1358 |
self.Pos.y + (self.Size[1] - text_height) / 2) |
|
1359 |
# Draw input connector |
|
1360 |
if self.Input: |
|
1361 |
self.Input.Draw(dc) |
|
1362 |
Graphic_Element.Draw(self, dc) |
|
1363 |
||
1364 |
||
1365 |
#------------------------------------------------------------------------------- |
|
1366 |
# Sequencial Function Chart Action Block |
|
1367 |
#------------------------------------------------------------------------------- |
|
1368 |
||
1369 |
""" |
|
1370 |
Class that implements the graphic representation of an action block |
|
1371 |
""" |
|
1372 |
||
1373 |
class SFC_ActionBlock(Graphic_Element): |
|
1374 |
||
1375 |
# Create a new action block |
|
1376 |
def __init__(self, parent, actions = [], id = None): |
|
1377 |
Graphic_Element.__init__(self, parent) |
|
1378 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1379 |
self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
108 | 1380 |
self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) |
0 | 1381 |
# Create an input and output connector |
108 | 1382 |
self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST) |
0 | 1383 |
self.SetActions(actions) |
1384 |
||
1385 |
# Destructor |
|
1386 |
def __del__(self): |
|
1387 |
self.Input = None |
|
1388 |
||
112 | 1389 |
# Make a clone of this SFC_ActionBlock |
1390 |
def Clone(self, id = None, pos = None): |
|
1391 |
actions = [action.copy() for action in self.Actions] |
|
1392 |
action_block = SFC_ActionBlock(self.Parent, actions, id) |
|
1393 |
action_block.SetSize(self.Size[0], self.Size[1]) |
|
1394 |
if pos is not None: |
|
1395 |
action_block.SetPosition(pos.x, pos.y) |
|
1396 |
action_block.Input = self.Input.Clone(action_block) |
|
1397 |
return jump |
|
1398 |
||
0 | 1399 |
# Returns the number of action lines |
1400 |
def GetLineNumber(self): |
|
1401 |
return len(self.Actions) |
|
1402 |
||
27 | 1403 |
def GetLineSize(self): |
108 | 1404 |
if len(self.Actions) > 0: |
27 | 1405 |
return self.Size[1] / len(self.Actions) |
1406 |
else: |
|
1407 |
return SFC_ACTION_MIN_SIZE[1] |
|
1408 |
||
0 | 1409 |
# Forbids to resize the action block |
1410 |
def Resize(self, x, y, width, height): |
|
27 | 1411 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1412 |
if x == 0: |
|
1413 |
self.SetSize(width, self.Size[1]) |
|
1414 |
else: |
|
1415 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 1416 |
|
1417 |
# Delete this action block by calling the appropriate method |
|
1418 |
def Delete(self): |
|
1419 |
self.Parent.DeleteActionBlock(self) |
|
1420 |
||
1421 |
# Unconnect input and output |
|
1422 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1423 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1424 |
|
1425 |
# Refresh the action block bounding box |
|
1426 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1427 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]) |
0 | 1428 |
|
1429 |
# Refresh the position of wires connected to action block |
|
1430 |
def RefreshConnected(self, exclude = []): |
|
1431 |
self.Input.MoveConnected(exclude) |
|
1432 |
||
1433 |
# Returns input action block connector |
|
27 | 1434 |
def GetConnector(self, position = None, name = None): |
0 | 1435 |
return self.Input |
1436 |
||
1437 |
# Test if point given is on action block input connector |
|
1438 |
def TestConnector(self, pt, exclude = True): |
|
1439 |
# Test input connector |
|
1440 |
if self.Input.TestPoint(pt, exclude): |
|
1441 |
return self.Input |
|
1442 |
return None |
|
1443 |
||
1444 |
# Changes the action block actions |
|
1445 |
def SetActions(self, actions): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1446 |
dc = wx.ClientDC(self.Parent) |
0 | 1447 |
self.Actions = actions |
1448 |
self.ColSize = [0, 0, 0] |
|
108 | 1449 |
min_height = 0 |
0 | 1450 |
for action in self.Actions: |
1451 |
width, height = dc.GetTextExtent(action["qualifier"]) |
|
1452 |
self.ColSize[0] = max(self.ColSize[0], width + 10) |
|
108 | 1453 |
row_height = height |
0 | 1454 |
if "duration" in action: |
2 | 1455 |
width, height = dc.GetTextExtent(action["duration"]) |
108 | 1456 |
row_height = max(row_height, height) |
0 | 1457 |
self.ColSize[0] = max(self.ColSize[0], width + 10) |
1458 |
width, height = dc.GetTextExtent(action["value"]) |
|
108 | 1459 |
row_height = max(row_height, height) |
0 | 1460 |
self.ColSize[1] = max(self.ColSize[1], width + 10) |
1461 |
if "indicator" in action and action["indicator"] != "": |
|
1462 |
width, height = dc.GetTextExtent(action["indicator"]) |
|
108 | 1463 |
row_height = max(row_height, height) |
0 | 1464 |
self.ColSize[2] = max(self.ColSize[2], width + 10) |
108 | 1465 |
min_height += row_height + 5 |
27 | 1466 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
108 | 1467 |
self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1])) |
1468 |
self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
|
1469 |
SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height) |
|
1470 |
self.RefreshBoundingBox() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1471 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1472 |
self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
27 | 1473 |
SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) |
108 | 1474 |
self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
1475 |
SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] |
|
1476 |
self.RefreshBoundingBox() |
|
1477 |
if self.Input: |
|
1478 |
wires = self.Input.GetWires() |
|
1479 |
if len(wires) == 1: |
|
1480 |
input_block = wires[0][0].EndConnected.GetParentBlock() |
|
1481 |
input_block.RefreshOutputPosition() |
|
1482 |
input_block.RefreshOutputModel(True) |
|
0 | 1483 |
|
1484 |
# Returns the action block actions |
|
1485 |
def GetActions(self): |
|
1486 |
return self.Actions |
|
1487 |
||
1488 |
# Returns the action block minimum size |
|
1489 |
def GetMinSize(self): |
|
108 | 1490 |
return self.MinSize |
0 | 1491 |
|
1492 |
# Method called when a LeftDClick event have been generated |
|
27 | 1493 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 1494 |
# Edit the action block properties |
1495 |
self.Parent.EditActionBlockContent(self) |
|
1496 |
||
1497 |
# Refreshes the action block state according to move defined and handle selected |
|
1498 |
def ProcessDragging(self, movex, movey): |
|
27 | 1499 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1500 |
handle_type, handle = self.Handle |
|
1501 |
if handle_type == HANDLE_MOVE: |
|
1502 |
wires = self.Input.GetWires() |
|
1503 |
if len(wires) == 1: |
|
1504 |
input_pos = wires[0][0].EndConnected.GetPosition(False) |
|
1505 |
if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE: |
|
1506 |
self.Move(movex, 0) |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1507 |
return True, False |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1508 |
return False, False |
27 | 1509 |
else: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1510 |
return Graphic_Element.ProcessDragging(self, movex, movey) |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1511 |
else: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1512 |
return Graphic_Element.ProcessDragging(self, movex, movey) |
27 | 1513 |
|
0 | 1514 |
|
1515 |
# Refreshes the action block model |
|
1516 |
def RefreshModel(self, move=True): |
|
1517 |
self.Parent.RefreshActionBlockModel(self) |
|
1518 |
||
1519 |
# Draws divergence |
|
1520 |
def Draw(self, dc): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1521 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1522 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 1523 |
colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1524 |
# Draw plain rectangle for representing the action block |
|
1525 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1526 |
dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, |
|
1527 |
self.Pos.x + colsize[0], self.Pos.y + self.Size[1]) |
|
1528 |
dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y, |
|
1529 |
self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1]) |
|
27 | 1530 |
line_size = self.GetLineSize() |
0 | 1531 |
for i, action in enumerate(self.Actions): |
1532 |
if i != 0: |
|
27 | 1533 |
dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, |
1534 |
self.Pos.x + self.Size[0], self.Pos.y + i * line_size) |
|
0 | 1535 |
text_width, text_height = dc.GetTextExtent(action["qualifier"]) |
1536 |
if "duration" in action: |
|
1537 |
dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2, |
|
27 | 1538 |
self.Pos.y + i * line_size + line_size / 2 - text_height) |
1 | 1539 |
text_width, text_height = dc.GetTextExtent(action["duration"]) |
1540 |
dc.DrawText(action["duration"], self.Pos.x + (colsize[0] - text_width) / 2, |
|
27 | 1541 |
self.Pos.y + i * line_size + line_size / 2) |
0 | 1542 |
else: |
1543 |
dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2, |
|
27 | 1544 |
self.Pos.y + i * line_size + (line_size - text_height) / 2) |
0 | 1545 |
text_width, text_height = dc.GetTextExtent(action["value"]) |
1546 |
dc.DrawText(action["value"], self.Pos.x + colsize[0] + (colsize[1] - text_width) / 2, |
|
27 | 1547 |
self.Pos.y + i * line_size + (line_size - text_height) / 2) |
0 | 1548 |
if "indicator" in action: |
1549 |
text_width, text_height = dc.GetTextExtent(action["indicator"]) |
|
1550 |
dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2, |
|
27 | 1551 |
self.Pos.y + i * line_size + (line_size - text_height) / 2) |
0 | 1552 |
# Draw input connector |
1553 |
self.Input.Draw(dc) |
|
1554 |
Graphic_Element.Draw(self, dc) |
|
27 | 1555 |