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