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