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