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