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