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