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