author | lbessard |
Mon, 14 Jan 2008 17:35:32 +0100 | |
changeset 147 | 5ef987c1b927 |
parent 146 | cc70dd430601 |
child 154 | 203c4acdaf27 |
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 |
144 | 68 |
def Clone(self, id = None, name = "Step", pos = None): |
69 |
step = SFC_Step(self.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: |
|
121 |
self.Input.UnConnect() |
|
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: |
|
134 |
self.Output.UnConnect() |
|
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: |
|
147 |
self.Action.UnConnect() |
|
148 |
self.Action = None |
|
149 |
self.RefreshBoundingBox() |
|
150 |
||
151 |
# Refresh the step bounding box |
|
152 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
153 |
dc = wx.ClientDC(self.Parent) |
0 | 154 |
# Calculate the bounding box size |
155 |
if self.Action: |
|
156 |
bbx_width = self.Size[0] + CONNECTOR_SIZE |
|
157 |
else: |
|
158 |
bbx_width = self.Size[0] |
|
159 |
if self.Initial: |
|
160 |
bbx_y = self.Pos.y |
|
161 |
bbx_height = self.Size[1] |
|
162 |
if self.Output: |
|
163 |
bbx_height += CONNECTOR_SIZE |
|
164 |
else: |
|
165 |
bbx_y = self.Pos.y - CONNECTOR_SIZE |
|
166 |
bbx_height = self.Size[1] + CONNECTOR_SIZE |
|
167 |
if self.Output: |
|
168 |
bbx_height += CONNECTOR_SIZE |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
169 |
#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
|
170 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 171 |
|
172 |
# Refresh the positions of the step connectors |
|
173 |
def RefreshConnectors(self): |
|
145 | 174 |
scaling = self.Parent.GetScaling() |
175 |
horizontal_pos = self.Size[0] / 2 |
|
176 |
vertical_pos = self.Size[1] / 2 |
|
177 |
if scaling is not None: |
|
178 |
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
179 |
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
0 | 180 |
# Update input position if it exists |
181 |
if self.Input: |
|
145 | 182 |
self.Input.SetPosition(wx.Point(horizontal_pos, 0)) |
0 | 183 |
# Update output position |
184 |
if self.Output: |
|
145 | 185 |
self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) |
0 | 186 |
# Update action position if it exists |
187 |
if self.Action: |
|
145 | 188 |
self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos)) |
0 | 189 |
self.RefreshConnected() |
190 |
||
191 |
# Refresh the position of wires connected to step |
|
192 |
def RefreshConnected(self, exclude = []): |
|
193 |
if self.Input: |
|
194 |
self.Input.MoveConnected(exclude) |
|
195 |
if self.Output: |
|
196 |
self.Output.MoveConnected(exclude) |
|
197 |
if self.Action: |
|
198 |
self.Action.MoveConnected(exclude) |
|
199 |
||
200 |
# Returns the step connector that starts with the point given if it exists |
|
27 | 201 |
def GetConnector(self, position, name = None): |
202 |
# if a name is given |
|
203 |
if name: |
|
204 |
# Test input, output and action connector if they exists |
|
205 |
if self.Input and name == self.Input.GetName(): |
|
206 |
return self.Input |
|
207 |
if self.Output and name == self.Output.GetName(): |
|
208 |
return self.Output |
|
209 |
if self.Action and name == self.Action.GetName(): |
|
210 |
return self.Action |
|
0 | 211 |
# Test input connector if it exists |
212 |
if self.Input: |
|
213 |
input_pos = self.Input.GetRelPosition() |
|
214 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
215 |
return self.Input |
|
216 |
# Test output connector if it exists |
|
217 |
if self.Output: |
|
218 |
output_pos = self.Output.GetRelPosition() |
|
219 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
220 |
return self.Output |
|
221 |
# Test action connector if it exists |
|
222 |
if self.Action: |
|
223 |
action_pos = self.Action.GetRelPosition() |
|
224 |
if position.x == self.Pos.x + action_pos.x and position.y == self.Pos.y + action_pos.y: |
|
225 |
return self.Action |
|
226 |
return None |
|
227 |
||
228 |
# Returns input and output step connectors |
|
229 |
def GetConnectors(self): |
|
230 |
return {"input":self.Input,"output":self.Output,"action":self.Action} |
|
231 |
||
232 |
# Test if point given is on step input or output connector |
|
233 |
def TestConnector(self, pt, exclude=True): |
|
234 |
# Test input connector if it exists |
|
235 |
if self.Input and self.Input.TestPoint(pt, exclude): |
|
236 |
return self.Input |
|
237 |
# Test output connector |
|
238 |
if self.Output and self.Output.TestPoint(pt, exclude): |
|
239 |
return self.Output |
|
108 | 240 |
# Test action connector |
241 |
if self.Action and self.Action.TestPoint(pt, exclude): |
|
242 |
return self.Action |
|
0 | 243 |
return None |
244 |
||
245 |
# Changes the step name |
|
246 |
def SetName(self, name): |
|
247 |
self.Name = name |
|
248 |
||
249 |
# Returns the step name |
|
250 |
def GetName(self): |
|
251 |
return self.Name |
|
252 |
||
253 |
# Returns the step initial property |
|
254 |
def GetInitial(self): |
|
255 |
return self.Initial |
|
256 |
||
257 |
# Returns the connector connected to input |
|
258 |
def GetPreviousConnector(self): |
|
259 |
if self.Input: |
|
260 |
wires = self.Input.GetWires() |
|
261 |
if len(wires) == 1: |
|
145 | 262 |
return wires[0][0].GetOtherConnected(self.Input) |
0 | 263 |
return None |
264 |
||
265 |
# Returns the connector connected to output |
|
266 |
def GetNextConnector(self): |
|
267 |
if self.Output: |
|
268 |
wires = self.Output.GetWires() |
|
269 |
if len(wires) == 1: |
|
145 | 270 |
return wires[0][0].GetOtherConnected(self.Output) |
0 | 271 |
return None |
272 |
||
273 |
# Returns the connector connected to action |
|
274 |
def GetActionConnector(self): |
|
275 |
if self.Action: |
|
276 |
wires = self.Action.GetWires() |
|
277 |
if len(wires) == 1: |
|
145 | 278 |
return wires[0][0].GetOtherConnected(self.Action) |
0 | 279 |
return None |
280 |
||
281 |
# Returns the number of action line |
|
282 |
def GetActionExtraLineNumber(self): |
|
283 |
if self.Action: |
|
284 |
wires = self.Action.GetWires() |
|
285 |
if len(wires) != 1: |
|
286 |
return 0 |
|
145 | 287 |
action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock() |
0 | 288 |
return max(0, action_block.GetLineNumber() - 1) |
289 |
return 0 |
|
290 |
||
291 |
# Returns the step minimum size |
|
292 |
def GetMinSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
293 |
dc = wx.ClientDC(self.Parent) |
0 | 294 |
text_width, text_height = dc.GetTextExtent(self.Name) |
295 |
if self.Initial: |
|
296 |
return text_width + 14, text_height + 14 |
|
297 |
else: |
|
298 |
return text_width + 10, text_height + 10 |
|
299 |
||
300 |
# Updates the step size |
|
301 |
def UpdateSize(self, width, height): |
|
302 |
diffx = self.Size.GetWidth() / 2 - width / 2 |
|
303 |
diffy = height - self.Size.GetHeight() |
|
304 |
self.Move(diffx, 0) |
|
305 |
Graphic_Element.SetSize(self, width, height) |
|
108 | 306 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
307 |
self.RefreshConnected() |
|
308 |
else: |
|
309 |
self.RefreshOutputPosition((0, diffy)) |
|
0 | 310 |
|
311 |
# Align input element with this step |
|
312 |
def RefreshInputPosition(self): |
|
313 |
if self.Input: |
|
314 |
current_pos = self.Input.GetPosition(False) |
|
315 |
input = self.GetPreviousConnector() |
|
316 |
if input: |
|
317 |
input_pos = input.GetPosition(False) |
|
318 |
diffx = current_pos.x - input_pos.x |
|
319 |
input_block = input.GetParentBlock() |
|
320 |
if isinstance(input_block, SFC_Divergence): |
|
321 |
input_block.MoveConnector(input, diffx) |
|
322 |
else: |
|
323 |
if isinstance(input_block, SFC_Step): |
|
324 |
input_block.MoveActionBlock((diffx, 0)) |
|
325 |
input_block.Move(diffx, 0) |
|
326 |
input_block.RefreshInputPosition() |
|
327 |
||
328 |
# Align output element with this step |
|
329 |
def RefreshOutputPosition(self, move = None): |
|
330 |
if self.Output: |
|
331 |
wires = self.Output.GetWires() |
|
332 |
if len(wires) != 1: |
|
333 |
return |
|
334 |
current_pos = self.Output.GetPosition(False) |
|
145 | 335 |
output = wires[0][0].GetOtherConnected(self.Output) |
0 | 336 |
output_pos = output.GetPosition(False) |
337 |
diffx = current_pos.x - output_pos.x |
|
338 |
output_block = output.GetParentBlock() |
|
339 |
wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
|
340 |
diffy = wire_size - output_pos.y + current_pos.y |
|
341 |
if diffy != 0: |
|
342 |
if isinstance(output_block, SFC_Step): |
|
343 |
output_block.MoveActionBlock((diffx, diffy)) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
344 |
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
|
345 |
wx.Point(current_pos.x, current_pos.y)]) |
0 | 346 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
347 |
output_block.Move(diffx, diffy, self.Parent.Wires) |
|
348 |
output_block.RefreshOutputPosition((diffx, diffy)) |
|
349 |
else: |
|
350 |
output_block.RefreshPosition() |
|
351 |
elif move: |
|
352 |
if isinstance(output_block, SFC_Step): |
|
353 |
output_block.MoveActionBlock(move) |
|
354 |
wires[0][0].Move(move[0], move[1], True) |
|
355 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
356 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
357 |
output_block.RefreshOutputPosition(move) |
|
358 |
else: |
|
359 |
output_block.RefreshPosition() |
|
360 |
elif isinstance(output_block, SFC_Divergence): |
|
361 |
output_block.MoveConnector(output, diffx) |
|
362 |
else: |
|
363 |
if isinstance(output_block, SFC_Step): |
|
364 |
output_block.MoveActionBlock((diffx, 0)) |
|
365 |
output_block.Move(diffx, 0) |
|
366 |
output_block.RefreshOutputPosition() |
|
367 |
||
368 |
# Refresh action element with this step |
|
369 |
def MoveActionBlock(self, move): |
|
370 |
if self.Action: |
|
371 |
wires = self.Action.GetWires() |
|
372 |
if len(wires) != 1: |
|
373 |
return |
|
145 | 374 |
action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock() |
0 | 375 |
action_block.Move(move[0], move[1], self.Parent.Wires) |
376 |
wires[0][0].Move(move[0], move[1], True) |
|
377 |
||
378 |
# Resize the divergence from position and size given |
|
379 |
def Resize(self, x, y, width, height): |
|
27 | 380 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
381 |
self.UpdateSize(width, height) |
|
382 |
else: |
|
383 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 384 |
|
385 |
# Method called when a LeftDClick event have been generated |
|
42 | 386 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 387 |
# Edit the step properties |
388 |
self.Parent.EditStepContent(self) |
|
389 |
||
390 |
# Method called when a RightUp event have been generated |
|
27 | 391 |
def OnRightUp(self, event, dc, scaling): |
0 | 392 |
# Popup the menu with special items for a step |
393 |
self.Parent.PopupDefaultMenu() |
|
394 |
||
395 |
# Refreshes the step state according to move defined and handle selected |
|
145 | 396 |
def ProcessDragging(self, movex, movey, scaling): |
0 | 397 |
handle_type, handle = self.Handle |
398 |
if handle_type == HANDLE_MOVE: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
399 |
movex = max(-self.BoundingBox.x, movex) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
400 |
movey = max(-self.BoundingBox.y, movey) |
145 | 401 |
if scaling is not None: |
402 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
403 |
movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
0 | 404 |
action_block = None |
27 | 405 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
406 |
self.Move(movex, movey) |
|
407 |
self.RefreshConnected() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
408 |
return movex, movey |
27 | 409 |
elif self.Initial: |
0 | 410 |
self.MoveActionBlock((movex, movey)) |
411 |
self.Move(movex, movey, self.Parent.Wires) |
|
412 |
self.RefreshOutputPosition((movex, movey)) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
413 |
return movex, movey |
0 | 414 |
else: |
415 |
self.MoveActionBlock((movex, 0)) |
|
416 |
self.Move(movex, 0) |
|
417 |
self.RefreshInputPosition() |
|
418 |
self.RefreshOutputPosition() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
419 |
return movex, 0 |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
420 |
else: |
145 | 421 |
return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
0 | 422 |
|
423 |
# Refresh input element model |
|
424 |
def RefreshInputModel(self): |
|
425 |
if self.Input: |
|
426 |
input = self.GetPreviousConnector() |
|
427 |
if input: |
|
428 |
input_block = input.GetParentBlock() |
|
429 |
input_block.RefreshModel(False) |
|
430 |
if not isinstance(input_block, SFC_Divergence): |
|
431 |
input_block.RefreshInputModel() |
|
432 |
||
433 |
# Refresh output element model |
|
434 |
def RefreshOutputModel(self, move=False): |
|
435 |
if self.Output: |
|
436 |
output = self.GetNextConnector() |
|
437 |
if output: |
|
438 |
output_block = output.GetParentBlock() |
|
439 |
output_block.RefreshModel(False) |
|
440 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
441 |
output_block.RefreshOutputModel(move) |
|
442 |
||
443 |
# Refreshes the step model |
|
444 |
def RefreshModel(self, move=True): |
|
445 |
self.Parent.RefreshStepModel(self) |
|
446 |
if self.Action: |
|
447 |
action = self.GetActionConnector() |
|
448 |
if action: |
|
449 |
action_block = action.GetParentBlock() |
|
450 |
action_block.RefreshModel(False) |
|
451 |
# If step has moved, refresh the model of wires connected to output |
|
452 |
if move: |
|
27 | 453 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
454 |
self.RefreshInputModel() |
|
455 |
self.RefreshOutputModel(self.Initial) |
|
456 |
elif self.Output: |
|
457 |
self.Output.RefreshWires() |
|
0 | 458 |
|
459 |
# Draws step |
|
460 |
def Draw(self, dc): |
|
144 | 461 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
462 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
463 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 464 |
# Draw two rectangles for representing the step |
465 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
466 |
if self.Initial: |
|
467 |
dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) |
|
468 |
# Draw step name |
|
469 |
namewidth, nameheight = dc.GetTextExtent(self.Name) |
|
470 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2, |
|
471 |
self.Pos.y + (self.Size[1] - nameheight) / 2) |
|
472 |
# Draw input and output connectors |
|
473 |
if self.Input: |
|
474 |
self.Input.Draw(dc) |
|
475 |
if self.Output: |
|
476 |
self.Output.Draw(dc) |
|
477 |
if self.Action: |
|
478 |
self.Action.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
479 |
|
0 | 480 |
|
481 |
#------------------------------------------------------------------------------- |
|
482 |
# Sequencial Function Chart Transition |
|
483 |
#------------------------------------------------------------------------------- |
|
484 |
||
485 |
""" |
|
486 |
Class that implements the graphic representation of a transition |
|
487 |
""" |
|
488 |
||
489 |
class SFC_Transition(Graphic_Element): |
|
490 |
||
491 |
# Create a new transition |
|
80 | 492 |
def __init__(self, parent, type = "reference", condition = None, priority = 0, id = None): |
0 | 493 |
Graphic_Element.__init__(self, parent) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
494 |
self.Type = None |
0 | 495 |
self.Id = id |
80 | 496 |
self.Priority = 0 |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
497 |
self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) |
0 | 498 |
# Create an input and output connector |
145 | 499 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
500 |
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
|
501 |
self.SetType(type, condition) |
80 | 502 |
self.SetPriority(priority) |
0 | 503 |
|
504 |
# Destructor |
|
505 |
def __del__(self): |
|
506 |
self.Input = None |
|
507 |
self.Output = None |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
508 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
509 |
self.Condition = None |
0 | 510 |
|
112 | 511 |
# Make a clone of this SFC_Transition |
512 |
def Clone(self, id = None, pos = None): |
|
513 |
transition = SFC_Transition(self.Parent, self.Type, self.Condition, self.Priority, id) |
|
514 |
transition.SetSize(self.Size[0], self.Size[1]) |
|
515 |
if pos is not None: |
|
516 |
transition.SetPosition(pos.x, pos.y) |
|
517 |
transition.Input = self.Input.Clone(transition) |
|
518 |
transition.Output = self.Output.Clone(transition) |
|
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)) |
|
531 |
return rect |
|
532 |
||
0 | 533 |
# Forbids to change the transition size |
534 |
def SetSize(self, width, height): |
|
27 | 535 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
536 |
Graphic_Element.SetSize(self, width, height) |
|
0 | 537 |
|
538 |
# Forbids to resize the transition |
|
539 |
def Resize(self, x, y, width, height): |
|
27 | 540 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
541 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 542 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
543 |
# Refresh the size of text for name |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
544 |
def RefreshConditionSize(self): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
545 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
546 |
dc = wx.ClientDC(self.Parent) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
547 |
if self.Condition != "": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
548 |
self.ConditionSize = dc.GetTextExtent(self.Condition) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
549 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
550 |
self.ConditionSize = dc.GetTextExtent("Transition") |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
551 |
|
80 | 552 |
# Refresh the size of text for name |
553 |
def RefreshPrioritySize(self): |
|
554 |
if self.Priority != "": |
|
555 |
dc = wx.ClientDC(self.Parent) |
|
556 |
self.PrioritySize = dc.GetTextExtent(str(self.Priority)) |
|
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): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
573 |
dc = wx.ClientDC(self.Parent) |
80 | 574 |
bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] |
575 |
if self.Priority != 0: |
|
576 |
bbx_y = self.Pos.y - self.PrioritySize[1] - 2 |
|
577 |
bbx_width = max(self.Size[0], self.PrioritySize[0]) |
|
578 |
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
|
579 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
580 |
bbx_x = self.Pos.x - CONNECTOR_SIZE |
80 | 581 |
bbx_width = bbx_width + CONNECTOR_SIZE |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
582 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
583 |
text_width, text_height = self.ConditionSize |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
584 |
# Calculate the bounding box size |
80 | 585 |
bbx_width = max(bbx_width, self.Size[0] + 5 + text_width) |
586 |
bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2)) |
|
587 |
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
|
588 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 589 |
|
590 |
# Returns the connector connected to input |
|
591 |
def GetPreviousConnector(self): |
|
592 |
wires = self.Input.GetWires() |
|
593 |
if len(wires) == 1: |
|
145 | 594 |
return wires[0][0].GetOtherConnected(self.Input) |
0 | 595 |
return None |
596 |
||
597 |
# Returns the connector connected to output |
|
598 |
def GetNextConnector(self): |
|
599 |
wires = self.Output.GetWires() |
|
600 |
if len(wires) == 1: |
|
145 | 601 |
return wires[0][0].GetOtherConnected(self.Output) |
0 | 602 |
return None |
603 |
||
604 |
# Refresh the positions of the transition connectors |
|
605 |
def RefreshConnectors(self): |
|
145 | 606 |
scaling = self.Parent.GetScaling() |
607 |
horizontal_pos = self.Size[0] / 2 |
|
608 |
vertical_pos = self.Size[1] / 2 |
|
609 |
if scaling is not None: |
|
610 |
horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
611 |
vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
0 | 612 |
# Update input position |
145 | 613 |
self.Input.SetPosition(wx.Point(horizontal_pos, 0)) |
0 | 614 |
# Update output position |
145 | 615 |
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
|
616 |
if self.Type == "connection": |
145 | 617 |
self.Condition.SetPosition(wx.Point(0, vertical_pos)) |
0 | 618 |
self.RefreshConnected() |
619 |
||
620 |
# Refresh the position of the wires connected to transition |
|
621 |
def RefreshConnected(self, exclude = []): |
|
622 |
self.Input.MoveConnected(exclude) |
|
623 |
self.Output.MoveConnected(exclude) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
624 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
625 |
self.Condition.MoveConnected(exclude) |
0 | 626 |
|
627 |
# Returns the transition connector that starts with the point given if it exists |
|
27 | 628 |
def GetConnector(self, position, name = None): |
629 |
# if a name is given |
|
630 |
if name: |
|
631 |
# Test input and output connector |
|
632 |
if name == self.Input.GetName(): |
|
633 |
return self.Input |
|
634 |
if name == self.Output.GetName(): |
|
635 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
636 |
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
|
637 |
return self.Condition |
0 | 638 |
# Test input connector |
639 |
input_pos = self.Input.GetRelPosition() |
|
640 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
641 |
return self.Input |
|
642 |
# Test output connector |
|
643 |
output_pos = self.Output.GetRelPosition() |
|
644 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
645 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
646 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
647 |
# Test condition connector |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
648 |
condition_pos = self.Condition.GetRelPosition() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
649 |
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
|
650 |
return self.Condition |
0 | 651 |
return None |
652 |
||
653 |
# Returns input and output transition connectors |
|
654 |
def GetConnectors(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
655 |
connectors = {"input":self.Input,"output":self.Output} |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
656 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
657 |
connectors["connection"] = self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
658 |
return connectors |
0 | 659 |
|
660 |
# Test if point given is on transition input or output connector |
|
661 |
def TestConnector(self, pt, exclude=True): |
|
662 |
# Test input connector |
|
663 |
if self.Input.TestPoint(pt, exclude): |
|
664 |
return self.Input |
|
665 |
# Test output connector |
|
666 |
if self.Output.TestPoint(pt, exclude): |
|
667 |
return self.Output |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
668 |
# Test condition connector |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
669 |
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
|
670 |
return self.Condition |
0 | 671 |
return None |
672 |
||
673 |
# Changes the transition type |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
674 |
def SetType(self, type, condition = None): |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
675 |
if self.Type != type: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
676 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
677 |
self.Condition.UnConnect() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
678 |
self.Type = type |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
679 |
if type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
680 |
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
|
681 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
682 |
if condition == None: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
683 |
condition = "" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
684 |
self.Condition = condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
685 |
self.RefreshConditionSize() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
686 |
elif self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
687 |
if condition == None: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
688 |
condition = "" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
689 |
self.Condition = condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
690 |
self.RefreshConditionSize() |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
691 |
self.RefreshBoundingBox() |
0 | 692 |
|
693 |
# Returns the transition type |
|
694 |
def GetType(self): |
|
695 |
return self.Type |
|
696 |
||
80 | 697 |
# Changes the transition priority |
698 |
def SetPriority(self, priority): |
|
699 |
self.Priority = priority |
|
700 |
self.RefreshPrioritySize() |
|
701 |
self.RefreshBoundingBox() |
|
702 |
||
703 |
# Returns the transition type |
|
704 |
def GetPriority(self): |
|
705 |
return self.Priority |
|
706 |
||
0 | 707 |
# Returns the transition condition |
708 |
def GetCondition(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
709 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
710 |
return self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
711 |
return None |
0 | 712 |
|
713 |
# Returns the transition minimum size |
|
714 |
def GetMinSize(self): |
|
715 |
return SFC_TRANSITION_SIZE |
|
716 |
||
717 |
# Align input element with this step |
|
718 |
def RefreshInputPosition(self): |
|
719 |
wires = self.Input.GetWires() |
|
720 |
current_pos = self.Input.GetPosition(False) |
|
721 |
input = self.GetPreviousConnector() |
|
722 |
if input: |
|
723 |
input_pos = input.GetPosition(False) |
|
724 |
diffx = current_pos.x - input_pos.x |
|
725 |
input_block = input.GetParentBlock() |
|
726 |
if isinstance(input_block, SFC_Divergence): |
|
727 |
input_block.MoveConnector(input, diffx) |
|
728 |
else: |
|
729 |
if isinstance(input_block, SFC_Step): |
|
730 |
input_block.MoveActionBlock((diffx, 0)) |
|
731 |
input_block.Move(diffx, 0) |
|
732 |
input_block.RefreshInputPosition() |
|
733 |
||
734 |
# Align output element with this step |
|
735 |
def RefreshOutputPosition(self, move = None): |
|
736 |
wires = self.Output.GetWires() |
|
737 |
if len(wires) != 1: |
|
738 |
return |
|
739 |
current_pos = self.Output.GetPosition(False) |
|
145 | 740 |
output = wires[0][0].GetOtherConnected(self.Output) |
0 | 741 |
output_pos = output.GetPosition(False) |
742 |
diffx = current_pos.x - output_pos.x |
|
743 |
output_block = output.GetParentBlock() |
|
744 |
if move: |
|
745 |
if isinstance(output_block, SFC_Step): |
|
746 |
output_block.MoveActionBlock(move) |
|
747 |
wires[0][0].Move(move[0], move[1], True) |
|
748 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
749 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
750 |
output_block.RefreshOutputPosition(move) |
|
751 |
else: |
|
752 |
output_block.RefreshPosition() |
|
753 |
elif isinstance(output_block, SFC_Divergence): |
|
754 |
output_block.MoveConnector(output, diffx) |
|
755 |
else: |
|
756 |
if isinstance(output_block, SFC_Step): |
|
757 |
output_block.MoveActionBlock((diffx, 0)) |
|
758 |
output_block.Move(diffx, 0) |
|
759 |
output_block.RefreshOutputPosition() |
|
27 | 760 |
|
0 | 761 |
# Method called when a LeftDClick event have been generated |
27 | 762 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 763 |
# Edit the transition properties |
764 |
self.Parent.EditTransitionContent(self) |
|
765 |
||
766 |
# Method called when a RightUp event have been generated |
|
27 | 767 |
def OnRightUp(self, event, dc, scaling): |
0 | 768 |
# Popup the menu with special items for a step |
769 |
self.Parent.PopupDefaultMenu() |
|
770 |
||
771 |
# Refreshes the transition state according to move defined and handle selected |
|
145 | 772 |
def ProcessDragging(self, movex, movey, scaling): |
27 | 773 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
774 |
movex = max(-self.BoundingBox.x, movex) |
145 | 775 |
if scaling is not None: |
776 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
27 | 777 |
self.Move(movex, 0) |
778 |
self.RefreshInputPosition() |
|
779 |
self.RefreshOutputPosition() |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
780 |
return movex, 0 |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
781 |
else: |
145 | 782 |
return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
0 | 783 |
|
784 |
# Refresh input element model |
|
785 |
def RefreshInputModel(self): |
|
27 | 786 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
787 |
input = self.GetPreviousConnector() |
|
788 |
if input: |
|
789 |
input_block = input.GetParentBlock() |
|
790 |
input_block.RefreshModel(False) |
|
791 |
if not isinstance(input_block, SFC_Divergence): |
|
792 |
input_block.RefreshInputModel() |
|
0 | 793 |
|
794 |
# Refresh output element model |
|
795 |
def RefreshOutputModel(self, move=False): |
|
796 |
output = self.GetNextConnector() |
|
797 |
if output: |
|
798 |
output_block = output.GetParentBlock() |
|
799 |
output_block.RefreshModel(False) |
|
800 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
801 |
output_block.RefreshOutputModel(move) |
|
802 |
||
803 |
# Refreshes the transition model |
|
804 |
def RefreshModel(self, move=True): |
|
805 |
self.Parent.RefreshTransitionModel(self) |
|
806 |
# If transition has moved, refresh the model of wires connected to output |
|
807 |
if move: |
|
27 | 808 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
809 |
self.RefreshInputModel() |
|
810 |
self.RefreshOutputModel() |
|
811 |
else: |
|
812 |
self.Output.RefreshWires() |
|
0 | 813 |
|
814 |
# Draws transition |
|
815 |
def Draw(self, dc): |
|
144 | 816 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
817 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
818 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 819 |
# Draw plain rectangle for representing the transition |
820 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
821 |
# Draw transition condition |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
822 |
if self.Type != "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
823 |
text_width, text_height = self.ConditionSize |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
824 |
if self.Condition != "": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
825 |
condition = self.Condition |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
826 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
827 |
condition = "Transition" |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
828 |
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
|
829 |
self.Pos.y + (self.Size[1] - text_height) / 2) |
80 | 830 |
# Draw priority number |
831 |
if self.Priority != 0: |
|
832 |
priority_width, priority_height = self.PrioritySize |
|
833 |
dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - self.PrioritySize[1] - 2) |
|
0 | 834 |
# Draw input and output connectors |
835 |
self.Input.Draw(dc) |
|
836 |
self.Output.Draw(dc) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
837 |
if self.Type == "connection": |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
838 |
self.Condition.Draw(dc) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
839 |
|
0 | 840 |
|
841 |
#------------------------------------------------------------------------------- |
|
842 |
# Sequencial Function Chart Divergence and Convergence |
|
843 |
#------------------------------------------------------------------------------- |
|
844 |
||
845 |
""" |
|
846 |
Class that implements the graphic representation of a divergence or convergence, |
|
847 |
selection or simultaneous |
|
848 |
""" |
|
849 |
||
850 |
class SFC_Divergence(Graphic_Element): |
|
851 |
||
852 |
# Create a new divergence |
|
853 |
def __init__(self, parent, type, number = 2, id = None): |
|
854 |
Graphic_Element.__init__(self, parent) |
|
855 |
self.Type = type |
|
856 |
self.Id = id |
|
857 |
self.RealConnectors = None |
|
858 |
number = max(2, number) |
|
859 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
860 |
self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1) |
0 | 861 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
862 |
self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3) |
0 | 863 |
# Create an input and output connector |
864 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
145 | 865 |
self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)] |
0 | 866 |
self.Outputs = [] |
867 |
for i in xrange(number): |
|
145 | 868 |
self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True)) |
0 | 869 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
870 |
self.Inputs = [] |
|
871 |
for i in xrange(number): |
|
145 | 872 |
self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True)) |
873 |
self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)] |
|
0 | 874 |
|
875 |
# Destructor |
|
876 |
def __del__(self): |
|
877 |
self.Inputs = [] |
|
878 |
self.Outputs = [] |
|
879 |
||
112 | 880 |
# Make a clone of this SFC_Divergence |
881 |
def Clone(self, id = None, pos = None): |
|
882 |
divergence = SFC_Divergence(self.Parent, self.Type, max(len(self.Inputs), len(self.Outputs)), id) |
|
883 |
divergence.SetSize(self.Size[0], self.Size[1]) |
|
884 |
if pos is not None: |
|
885 |
divergence.SetPosition(pos.x, pos.y) |
|
886 |
divergence.Inputs = [input.Clone(divergence) for input in self.Inputs] |
|
887 |
divergence.Outputs = [output.Clone(divergence) for output in self.Outputs] |
|
888 |
return divergence |
|
889 |
||
144 | 890 |
# Returns the RedrawRect |
891 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
892 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
893 |
if movex != 0 or movey != 0: |
|
894 |
for input in self.Inputs: |
|
895 |
if input.IsConnected(): |
|
896 |
rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) |
|
897 |
for output in self.Outputs: |
|
898 |
if output.IsConnected(): |
|
899 |
rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) |
|
900 |
return rect |
|
901 |
||
0 | 902 |
# Forbids to resize the divergence |
903 |
def Resize(self, x, y, width, height): |
|
27 | 904 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
905 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 906 |
|
907 |
# Delete this divergence by calling the appropriate method |
|
908 |
def Delete(self): |
|
909 |
self.Parent.DeleteDivergence(self) |
|
910 |
||
911 |
# Returns the divergence type |
|
912 |
def GetType(self): |
|
913 |
return self.Type |
|
914 |
||
915 |
# Unconnect input and output |
|
916 |
def Clean(self): |
|
917 |
for input in self.Inputs: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
918 |
input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 919 |
for output in self.Outputs: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
920 |
output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 921 |
|
922 |
# Add a branch to the divergence |
|
923 |
def AddBranch(self): |
|
924 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
925 |
maxx = 0 |
|
926 |
for output in self.Outputs: |
|
927 |
pos = output.GetRelPosition() |
|
928 |
maxx = max(maxx, pos.x) |
|
145 | 929 |
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True) |
0 | 930 |
self.Outputs.append(connector) |
931 |
self.MoveConnector(connector, 0) |
|
932 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
933 |
maxx = 0 |
|
934 |
for input in self.Inputs: |
|
935 |
pos = input.GetRelPosition() |
|
936 |
maxx = max(maxx, pos.x) |
|
145 | 937 |
connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True) |
0 | 938 |
self.Inputs.append(connector) |
939 |
self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) |
|
940 |
||
941 |
# Remove a branch from the divergence |
|
942 |
def RemoveBranch(self, connector): |
|
943 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
944 |
if connector in self.Outputs and len(self.Outputs) > 2: |
0 | 945 |
self.Outputs.remove(connector) |
946 |
self.MoveConnector(self.Outputs[0], 0) |
|
947 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
948 |
if connector in self.Inputs and len(self.Inputs) > 2: |
0 | 949 |
self.Inputs.remove(connector) |
950 |
self.MoveConnector(self.Inputs[0], 0) |
|
951 |
||
80 | 952 |
# Remove the handled branch from the divergence |
953 |
def RemoveHandledBranch(self): |
|
954 |
handle_type, handle = self.Handle |
|
955 |
if handle_type == HANDLE_CONNECTOR: |
|
956 |
handle.UnConnect(delete=True) |
|
957 |
self.RemoveBranch(handle) |
|
958 |
||
0 | 959 |
# Return the number of branches for the divergence |
960 |
def GetBranchNumber(self): |
|
961 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
|
962 |
return len(self.Outputs) |
|
963 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
964 |
return len(self.Inputs) |
|
965 |
||
966 |
# Returns if the point given is in the bounding box |
|
967 |
def HitTest(self, pt): |
|
968 |
rect = self.BoundingBox |
|
969 |
return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None |
|
970 |
||
971 |
# Refresh the divergence bounding box |
|
972 |
def RefreshBoundingBox(self): |
|
973 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
145 | 974 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, |
975 |
self.Size[0] + 1, self.Size[1] + 1) |
|
0 | 976 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
145 | 977 |
self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, |
978 |
self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1) |
|
0 | 979 |
|
980 |
# Refresh the position of wires connected to divergence |
|
981 |
def RefreshConnected(self, exclude = []): |
|
982 |
for input in self.Inputs: |
|
983 |
input.MoveConnected(exclude) |
|
984 |
for output in self.Outputs: |
|
985 |
output.MoveConnected(exclude) |
|
986 |
||
987 |
# Moves the divergence connector given |
|
988 |
def MoveConnector(self, connector, movex): |
|
989 |
position = connector.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
990 |
connector.SetPosition(wx.Point(position.x + movex, position.y)) |
0 | 991 |
minx = self.Size[0] |
992 |
maxx = 0 |
|
993 |
for input in self.Inputs: |
|
994 |
input_pos = input.GetRelPosition() |
|
995 |
minx = min(minx, input_pos.x) |
|
996 |
maxx = max(maxx, input_pos.x) |
|
997 |
for output in self.Outputs: |
|
998 |
output_pos = output.GetRelPosition() |
|
999 |
minx = min(minx, output_pos.x) |
|
1000 |
maxx = max(maxx, output_pos.x) |
|
1001 |
if minx != 0: |
|
1002 |
for input in self.Inputs: |
|
1003 |
input_pos = input.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1004 |
input.SetPosition(wx.Point(input_pos.x - minx, input_pos.y)) |
0 | 1005 |
for output in self.Outputs: |
1006 |
output_pos = output.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1007 |
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
|
1008 |
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
|
1009 |
self.Outputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x)) |
0 | 1010 |
self.Pos.x += minx |
1011 |
self.Size[0] = maxx - minx |
|
1012 |
connector.MoveConnected() |
|
1013 |
self.RefreshBoundingBox() |
|
1014 |
||
1015 |
# Returns the divergence connector that starts with the point given if it exists |
|
27 | 1016 |
def GetConnector(self, position, name = None): |
1017 |
# if a name is given |
|
1018 |
if name: |
|
1019 |
# Test each input and output connector |
|
1020 |
for input in self.Inputs: |
|
1021 |
if name == input.GetName(): |
|
1022 |
return input |
|
1023 |
for output in self.Outputs: |
|
1024 |
if name == output.GetName(): |
|
1025 |
return output |
|
0 | 1026 |
# Test input connector |
1027 |
for input in self.Inputs: |
|
1028 |
input_pos = input.GetPosition(False) |
|
1029 |
if position.x == input_pos.x and position.y == input_pos.y: |
|
1030 |
return input |
|
1031 |
# Test output connector |
|
1032 |
for output in self.Outputs: |
|
1033 |
output_pos = output.GetPosition(False) |
|
1034 |
if position.x == output_pos.x and position.y == output_pos.y: |
|
1035 |
return output |
|
1036 |
return None |
|
1037 |
||
1038 |
# Returns input and output divergence connectors |
|
1039 |
def GetConnectors(self): |
|
1040 |
return {"inputs":self.Inputs,"outputs":self.Outputs} |
|
1041 |
||
1042 |
# Test if point given is on divergence input or output connector |
|
1043 |
def TestConnector(self, pt, exclude=True): |
|
1044 |
# Test input connector |
|
1045 |
for input in self.Inputs: |
|
1046 |
if input.TestPoint(pt, exclude): |
|
1047 |
return input |
|
1048 |
# Test output connector |
|
1049 |
for output in self.Outputs: |
|
1050 |
if output.TestPoint(pt, exclude): |
|
1051 |
return output |
|
1052 |
return None |
|
1053 |
||
1054 |
# Changes the divergence size |
|
1055 |
def SetSize(self, width, height): |
|
1056 |
for i, input in enumerate(self.Inputs): |
|
1057 |
position = input.GetRelPosition() |
|
1058 |
if self.RealConnectors: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1059 |
input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) |
0 | 1060 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1061 |
input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) |
0 | 1062 |
input.MoveConnected() |
1063 |
for i, output in enumerate(self.Outputs): |
|
1064 |
position = output.GetRelPosition() |
|
1065 |
if self.RealConnectors: |
|
146 | 1066 |
output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height)) |
0 | 1067 |
else: |
146 | 1068 |
output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height)) |
0 | 1069 |
output.MoveConnected() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1070 |
self.Size = wx.Size(width, height) |
0 | 1071 |
self.RefreshBoundingBox() |
1072 |
||
1073 |
# Returns the divergence minimum size |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1074 |
def GetMinSize(self, default=False): |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1075 |
width = 0 |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1076 |
if default: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1077 |
if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1078 |
width = (len(self.Outputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1079 |
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1080 |
width = (len(self.Inputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL |
27 | 1081 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1082 |
return width, 1 |
27 | 1083 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
1084 |
return width, 3 |
27 | 1085 |
return 0, 0 |
0 | 1086 |
|
1087 |
# Refresh the position of the block connected to connector |
|
1088 |
def RefreshConnectedPosition(self, connector): |
|
1089 |
wires = connector.GetWires() |
|
1090 |
if len(wires) != 1: |
|
1091 |
return |
|
1092 |
current_pos = connector.GetPosition(False) |
|
145 | 1093 |
next = wires[0][0].GetOtherConnected(connector) |
0 | 1094 |
next_pos = next.GetPosition(False) |
1095 |
diffx = current_pos.x - next_pos.x |
|
1096 |
next_block = next.GetParentBlock() |
|
1097 |
if isinstance(next_block, SFC_Divergence): |
|
1098 |
next_block.MoveConnector(next, diffx) |
|
1099 |
else: |
|
1100 |
next_block.Move(diffx, 0) |
|
1101 |
if connector in self.Inputs: |
|
1102 |
next_block.RefreshInputPosition() |
|
1103 |
else: |
|
1104 |
next_block.RefreshOutputPosition() |
|
27 | 1105 |
|
0 | 1106 |
# Refresh the position of this divergence |
1107 |
def RefreshPosition(self): |
|
1108 |
y = 0 |
|
1109 |
for input in self.Inputs: |
|
1110 |
wires = input.GetWires() |
|
1111 |
if len(wires) != 1: |
|
1112 |
return |
|
145 | 1113 |
previous = wires[0][0].GetOtherConnected(input) |
0 | 1114 |
previous_pos = previous.GetPosition(False) |
1115 |
y = max(y, previous_pos.y + GetWireSize(previous.GetParentBlock())) |
|
1116 |
diffy = y - self.Pos.y |
|
1117 |
if diffy != 0: |
|
1118 |
self.Move(0, diffy, self.Parent.Wires) |
|
1119 |
self.RefreshOutputPosition((0, diffy)) |
|
1120 |
for input in self.Inputs: |
|
1121 |
input.MoveConnected() |
|
1122 |
||
1123 |
# Align output element with this divergence |
|
1124 |
def RefreshOutputPosition(self, move = None): |
|
1125 |
if move: |
|
1126 |
for output_connector in self.Outputs: |
|
1127 |
wires = output_connector.GetWires() |
|
1128 |
if len(wires) != 1: |
|
1129 |
return |
|
1130 |
current_pos = output_connector.GetPosition(False) |
|
145 | 1131 |
output = wires[0][0].GetOtherConnected(self.Output) |
0 | 1132 |
output_pos = output.GetPosition(False) |
1133 |
diffx = current_pos.x - output_pos.x |
|
1134 |
output_block = output.GetParentBlock() |
|
1135 |
if isinstance(output_block, SFC_Step): |
|
1136 |
output_block.MoveActionBlock(move) |
|
1137 |
wires[0][0].Move(move[0], move[1], True) |
|
1138 |
if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: |
|
1139 |
output_block.Move(move[0], move[1], self.Parent.Wires) |
|
1140 |
output_block.RefreshOutputPosition(move) |
|
1141 |
||
1142 |
# Method called when a LeftDown event have been generated |
|
27 | 1143 |
def OnLeftDown(self, event, dc, scaling): |
145 | 1144 |
self.RealConnectors = {"Inputs":[],"Outputs":[]} |
1145 |
for input in self.Inputs: |
|
1146 |
position = input.GetRelPosition() |
|
1147 |
self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) |
|
1148 |
for output in self.Outputs: |
|
1149 |
position = output.GetRelPosition() |
|
1150 |
self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) |
|
1151 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
1152 |
||
1153 |
# Method called when a LeftUp event have been generated |
|
1154 |
def OnLeftUp(self, event, dc, scaling): |
|
1155 |
Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
1156 |
self.RealConnectors = None |
|
1157 |
||
1158 |
# Method called when a RightDown event have been generated |
|
1159 |
def OnRightDown(self, event, dc, scaling): |
|
27 | 1160 |
pos = GetScaledEventPosition(event, dc, scaling) |
0 | 1161 |
# Test if a connector have been handled |
1162 |
connector = self.TestConnector(pos, False) |
|
1163 |
if connector: |
|
1164 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1165 |
self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
0 | 1166 |
self.Selected = False |
1167 |
# Initializes the last position |
|
27 | 1168 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
0 | 1169 |
else: |
145 | 1170 |
Graphic_Element.OnRightDown(self, event, dc, scaling) |
1171 |
||
1172 |
# Method called when a RightUp event have been generated |
|
1173 |
def OnRightUp(self, event, dc, scaling): |
|
0 | 1174 |
handle_type, handle = self.Handle |
1175 |
if handle_type == HANDLE_CONNECTOR: |
|
1176 |
wires = handle.GetWires() |
|
1177 |
if len(wires) != 1: |
|
1178 |
return |
|
145 | 1179 |
block = wires[0][0].GetOtherConnected(handle).GetParentBlock() |
0 | 1180 |
block.RefreshModel(False) |
1181 |
if not isinstance(block, SFC_Divergence): |
|
1182 |
if handle in self.Inputs: |
|
1183 |
block.RefreshInputModel() |
|
1184 |
else: |
|
1185 |
block.RefreshOutputModel() |
|
145 | 1186 |
Graphic_Element.OnRightUp(self, event, dc, scaling) |
1187 |
else: |
|
1188 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
1189 |
# Popup the menu with special items for a block and a connector if one is handled |
|
1190 |
connector = self.TestConnector(pos, False) |
|
1191 |
if connector: |
|
1192 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
1193 |
self.Parent.PopupDivergenceMenu(True) |
|
1194 |
else: |
|
1195 |
# Popup the divergence menu without delete branch |
|
1196 |
self.Parent.PopupDivergenceMenu(False) |
|
0 | 1197 |
|
1198 |
# Refreshes the divergence state according to move defined and handle selected |
|
145 | 1199 |
def ProcessDragging(self, movex, movey, scaling): |
0 | 1200 |
handle_type, handle = self.Handle |
1201 |
# A connector has been handled |
|
1202 |
if handle_type == HANDLE_CONNECTOR: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1203 |
movex = max(-self.BoundingBox.x, movex) |
145 | 1204 |
if scaling is not None: |
1205 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
0 | 1206 |
self.MoveConnector(handle, movex) |
27 | 1207 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1208 |
self.RefreshConnectedPosition(handle) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1209 |
return movex, 0 |
27 | 1210 |
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
145 | 1211 |
return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1212 |
return 0, 0 |
0 | 1213 |
|
1214 |
# Refresh output element model |
|
1215 |
def RefreshOutputModel(self, move=False): |
|
27 | 1216 |
if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
0 | 1217 |
for output in self.Outputs: |
1218 |
wires = output.GetWires() |
|
1219 |
if len(wires) != 1: |
|
1220 |
return |
|
145 | 1221 |
output_block = wires[0][0].GetOtherConnected(output).GetParentBlock() |
0 | 1222 |
output_block.RefreshModel(False) |
1223 |
if not isinstance(output_block, SFC_Divergence) or move: |
|
1224 |
output_block.RefreshOutputModel(move) |
|
1225 |
||
1226 |
# Refreshes the divergence model |
|
1227 |
def RefreshModel(self, move=True): |
|
1228 |
self.Parent.RefreshDivergenceModel(self) |
|
1229 |
# If divergence has moved, refresh the model of wires connected to outputs |
|
1230 |
if move: |
|
27 | 1231 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1232 |
self.RefreshOutputModel() |
|
1233 |
else: |
|
1234 |
for output in self.Outputs: |
|
1235 |
output.RefreshWires() |
|
0 | 1236 |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1237 |
# 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
|
1238 |
def DrawHighlightment(self, dc): |
144 | 1239 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
1240 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
1241 |
dc.SetLogicalFunction(wx.AND) |
|
1242 |
# Draw two rectangles for representing the contact |
|
1243 |
posx = self.Pos.x - 2 |
|
1244 |
width = self.Size[0] + 5 |
|
1245 |
if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1246 |
posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA |
|
1247 |
width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2 |
|
1248 |
dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5) |
|
1249 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1250 |
|
0 | 1251 |
# Draws divergence |
1252 |
def Draw(self, dc): |
|
144 | 1253 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1254 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1255 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 1256 |
# Draw plain rectangle for representing the divergence |
1257 |
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
1258 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1259 |
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: |
|
1260 |
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, |
|
1261 |
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y) |
|
27 | 1262 |
dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + self.Size[1], |
1263 |
self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + self.Size[1]) |
|
0 | 1264 |
# Draw inputs and outputs connectors |
1265 |
for input in self.Inputs: |
|
1266 |
input.Draw(dc) |
|
1267 |
for output in self.Outputs: |
|
1268 |
output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1269 |
|
0 | 1270 |
|
1271 |
#------------------------------------------------------------------------------- |
|
1272 |
# Sequencial Function Chart Jump to Step |
|
1273 |
#------------------------------------------------------------------------------- |
|
1274 |
||
1275 |
""" |
|
1276 |
Class that implements the graphic representation of a jump to step |
|
1277 |
""" |
|
1278 |
||
1279 |
class SFC_Jump(Graphic_Element): |
|
1280 |
||
1281 |
# Create a new jump |
|
1282 |
def __init__(self, parent, target, id = None): |
|
1283 |
Graphic_Element.__init__(self, parent) |
|
1284 |
self.Target = target |
|
1285 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1286 |
self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) |
0 | 1287 |
# Create an input and output connector |
145 | 1288 |
self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) |
0 | 1289 |
|
1290 |
# Destructor |
|
1291 |
def __del__(self): |
|
27 | 1292 |
self.Input = None |
0 | 1293 |
|
112 | 1294 |
# Make a clone of this SFC_Jump |
1295 |
def Clone(self, id = None, pos = None): |
|
1296 |
jump = SFC_Jump(self.Parent, self.Target, id) |
|
1297 |
jump.SetSize(self.Size[0], self.Size[1]) |
|
1298 |
if pos is not None: |
|
1299 |
jump.SetPosition(pos.x, pos.y) |
|
1300 |
jump.Input = self.Input.Clone(jump) |
|
1301 |
return jump |
|
1302 |
||
144 | 1303 |
# Returns the RedrawRect |
1304 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
1305 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1306 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
1307 |
if movex != 0 or movey != 0: |
|
1308 |
if self.Input.IsConnected(): |
|
1309 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
1310 |
return rect |
|
1311 |
||
0 | 1312 |
# Forbids to change the jump size |
1313 |
def SetSize(self, width, height): |
|
27 | 1314 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1315 |
Graphic_Element.SetSize(self, width, height) |
|
0 | 1316 |
|
1317 |
# Forbids to resize jump |
|
1318 |
def Resize(self, x, y, width, height): |
|
27 | 1319 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
1320 |
Graphic_Element.Resize(self, x, y, width, height) |
|
0 | 1321 |
|
1322 |
# Delete this jump by calling the appropriate method |
|
1323 |
def Delete(self): |
|
1324 |
self.Parent.DeleteJump(self) |
|
1325 |
||
1326 |
# Unconnect input |
|
1327 |
def Clean(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1328 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 1329 |
|
1330 |
# Refresh the jump bounding box |
|
1331 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1332 |
dc = wx.ClientDC(self.Parent) |
0 | 1333 |
text_width, text_height = dc.GetTextExtent(self.Target) |
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 |
|
145 | 1416 |
def ProcessDragging(self, movex, movey, 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: |
145 | 1425 |
return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
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 |
1504 |
def Clone(self, id = None, pos = None): |
|
1505 |
actions = [action.copy() for action in self.Actions] |
|
1506 |
action_block = SFC_ActionBlock(self.Parent, actions, id) |
|
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): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1578 |
dc = wx.ClientDC(self.Parent) |
0 | 1579 |
self.Actions = actions |
1580 |
self.ColSize = [0, 0, 0] |
|
108 | 1581 |
min_height = 0 |
0 | 1582 |
for action in self.Actions: |
1583 |
width, height = dc.GetTextExtent(action["qualifier"]) |
|
1584 |
self.ColSize[0] = max(self.ColSize[0], width + 10) |
|
108 | 1585 |
row_height = height |
0 | 1586 |
if "duration" in action: |
2 | 1587 |
width, height = dc.GetTextExtent(action["duration"]) |
108 | 1588 |
row_height = max(row_height, height) |
0 | 1589 |
self.ColSize[0] = max(self.ColSize[0], width + 10) |
1590 |
width, height = dc.GetTextExtent(action["value"]) |
|
108 | 1591 |
row_height = max(row_height, height) |
0 | 1592 |
self.ColSize[1] = max(self.ColSize[1], width + 10) |
1593 |
if "indicator" in action and action["indicator"] != "": |
|
1594 |
width, height = dc.GetTextExtent(action["indicator"]) |
|
108 | 1595 |
row_height = max(row_height, height) |
0 | 1596 |
self.ColSize[2] = max(self.ColSize[2], width + 10) |
108 | 1597 |
min_height += row_height + 5 |
27 | 1598 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
108 | 1599 |
self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1])) |
1600 |
self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
|
1601 |
SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height) |
|
1602 |
self.RefreshBoundingBox() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1603 |
else: |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1604 |
self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
27 | 1605 |
SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) |
108 | 1606 |
self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], |
1607 |
SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] |
|
1608 |
self.RefreshBoundingBox() |
|
1609 |
if self.Input: |
|
1610 |
wires = self.Input.GetWires() |
|
1611 |
if len(wires) == 1: |
|
145 | 1612 |
input_block = wires[0][0].GetOtherConnected(self.Input).GetParentBlock() |
108 | 1613 |
input_block.RefreshOutputPosition() |
1614 |
input_block.RefreshOutputModel(True) |
|
0 | 1615 |
|
1616 |
# Returns the action block actions |
|
1617 |
def GetActions(self): |
|
1618 |
return self.Actions |
|
1619 |
||
1620 |
# Returns the action block minimum size |
|
1621 |
def GetMinSize(self): |
|
108 | 1622 |
return self.MinSize |
0 | 1623 |
|
1624 |
# Method called when a LeftDClick event have been generated |
|
27 | 1625 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 1626 |
# Edit the action block properties |
1627 |
self.Parent.EditActionBlockContent(self) |
|
1628 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1629 |
# 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
|
1630 |
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
|
1631 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1632 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
1633 |
|
0 | 1634 |
# Refreshes the action block state according to move defined and handle selected |
145 | 1635 |
def ProcessDragging(self, movex, movey, scaling): |
27 | 1636 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
1637 |
handle_type, handle = self.Handle |
|
1638 |
if handle_type == HANDLE_MOVE: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1639 |
movex = max(-self.BoundingBox.x, movex) |
145 | 1640 |
if scaling is not None: |
1641 |
movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
|
27 | 1642 |
wires = self.Input.GetWires() |
1643 |
if len(wires) == 1: |
|
145 | 1644 |
input_pos = wires[0][0].GetOtherConnected(self.Input).GetPosition(False) |
27 | 1645 |
if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE: |
1646 |
self.Move(movex, 0) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1647 |
return movex, 0 |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
1648 |
return 0, 0 |
27 | 1649 |
else: |
145 | 1650 |
return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
1651 |
else: |
|
1652 |
return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
|
27 | 1653 |
|
0 | 1654 |
|
1655 |
# Refreshes the action block model |
|
1656 |
def RefreshModel(self, move=True): |
|
1657 |
self.Parent.RefreshActionBlockModel(self) |
|
1658 |
||
1659 |
# Draws divergence |
|
1660 |
def Draw(self, dc): |
|
144 | 1661 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1662 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
58
diff
changeset
|
1663 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 1664 |
colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] |
1665 |
# Draw plain rectangle for representing the action block |
|
1666 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1667 |
dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, |
|
1668 |
self.Pos.x + colsize[0], self.Pos.y + self.Size[1]) |
|
1669 |
dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y, |
|
1670 |
self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1]) |
|
27 | 1671 |
line_size = self.GetLineSize() |
0 | 1672 |
for i, action in enumerate(self.Actions): |
1673 |
if i != 0: |
|
27 | 1674 |
dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, |
1675 |
self.Pos.x + self.Size[0], self.Pos.y + i * line_size) |
|
0 | 1676 |
text_width, text_height = dc.GetTextExtent(action["qualifier"]) |
1677 |
if "duration" in action: |
|
1678 |
dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2, |
|
27 | 1679 |
self.Pos.y + i * line_size + line_size / 2 - text_height) |
1 | 1680 |
text_width, text_height = dc.GetTextExtent(action["duration"]) |
1681 |
dc.DrawText(action["duration"], self.Pos.x + (colsize[0] - text_width) / 2, |
|
27 | 1682 |
self.Pos.y + i * line_size + line_size / 2) |
0 | 1683 |
else: |
1684 |
dc.DrawText(action["qualifier"], self.Pos.x + (colsize[0] - text_width) / 2, |
|
27 | 1685 |
self.Pos.y + i * line_size + (line_size - text_height) / 2) |
0 | 1686 |
text_width, text_height = dc.GetTextExtent(action["value"]) |
1687 |
dc.DrawText(action["value"], self.Pos.x + colsize[0] + (colsize[1] - text_width) / 2, |
|
27 | 1688 |
self.Pos.y + i * line_size + (line_size - text_height) / 2) |
0 | 1689 |
if "indicator" in action: |
1690 |
text_width, text_height = dc.GetTextExtent(action["indicator"]) |
|
1691 |
dc.DrawText(action["indicator"], self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - text_width) / 2, |
|
27 | 1692 |
self.Pos.y + i * line_size + (line_size - text_height) / 2) |
0 | 1693 |
# Draw input connector |
1694 |
self.Input.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1695 |