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