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