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