author | etisserant |
Tue, 05 Jun 2007 14:32:01 +0200 | |
changeset 14 | cd0133ed377b |
parent 5 | f8652b073e84 |
child 27 | dae55dd9ee14 |
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 |
# |
|
7 |
#Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
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 |
|
19 |
#Lesser General Public License for more details. |
|
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 |
from wxPython.wx import * |
|
26 |
import wx |
|
27 |
from math import * |
|
28 |
||
29 |
||
30 |
#------------------------------------------------------------------------------- |
|
31 |
# Common constants |
|
32 |
#------------------------------------------------------------------------------- |
|
33 |
||
34 |
""" |
|
35 |
Definition of constants for dimensions of graphic elements |
|
36 |
""" |
|
37 |
||
38 |
# FBD and SFC constants |
|
39 |
MIN_MOVE = 5 # Minimum move before starting a element dragging |
|
40 |
CONNECTOR_SIZE = 8 # Size of connectors |
|
41 |
BLOCK_LINE_SIZE = 20 # Minimum size of each line in a block |
|
42 |
HANDLE_SIZE = 6 # Size of the squares for handles |
|
43 |
ANCHOR_DISTANCE = 5 # Distance where wire is automativally attached to a connector |
|
44 |
POINT_RADIUS = 2 # Radius of the point of wire ends |
|
45 |
MIN_SEGMENT_SIZE = 2 # Minimum size of the endling segments of a wire |
|
46 |
||
47 |
# LD constants |
|
48 |
LD_LINE_SIZE = 40 # Distance between two lines in a ladder rung |
|
49 |
LD_ELEMENT_SIZE = (21, 15) # Size (width, height) of a ladder element (contact or coil) |
|
50 |
LD_WIRE_SIZE = 30 # Size of a wire between two contact |
|
51 |
LD_WIRECOIL_SIZE = 70 # Size of a wire between a coil and a contact |
|
52 |
LD_OFFSET = (10, 10) # Distance (x, y) between each comment and rung of the ladder |
|
53 |
LD_COMMENT_DEFAULTSIZE = (600, 40) # Size (width, height) of a comment box |
|
54 |
||
55 |
# SFC constants |
|
56 |
SFC_STEP_DEFAULT_SIZE = (40, 30) # Default size of a SFC step |
|
57 |
SFC_TRANSITION_SIZE = (20, 2) # Size of a SFC transition |
|
58 |
SFC_DEFAULT_SEQUENCE_INTERVAL = 80 # Default size of the interval between two divergence branches |
|
59 |
SFC_SIMULTANEOUS_SEQUENCE_EXTRA = 20 # Size of extra lines for simultaneous divergence and convergence |
|
60 |
SFC_JUMP_SIZE = (12, 13) # Size of a SFC jump to step |
|
61 |
SFC_WIRE_MIN_SIZE = 25 # Size of a wire between two elements |
|
62 |
SFC_ACTION_MIN_SIZE = (100, 30) # Minimum size of an action block line |
|
63 |
||
64 |
# Type definition constants for graphic elements |
|
65 |
[INPUT, OUTPUT, INOUT] = range(3) |
|
66 |
[CONNECTOR, CONTINUATION] = range(2) |
|
67 |
[LEFTRAIL, RIGHTRAIL] = range(2) |
|
68 |
[CONTACT_NORMAL, CONTACT_REVERSE, CONTACT_RISING, CONTACT_FALLING] = range(4) |
|
69 |
[COIL_NORMAL, COIL_REVERSE, COIL_SET, COIL_RESET] = range(4) |
|
70 |
[SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] = range(4) |
|
71 |
||
72 |
# Constants for defining the type of dragging that has been selected |
|
73 |
[HANDLE_MOVE, HANDLE_RESIZE, HANDLE_POINT, HANDLE_SEGMENT, HANDLE_CONNECTOR] = range(5) |
|
74 |
||
75 |
# List of value for resize handle that are valid |
|
76 |
VALID_HANDLES = [(1,1), (1,2), (1,3), (2,3), (3,3), (3,2), (3,1), (2,1)] |
|
77 |
||
78 |
# Contants for defining the direction of a connector |
|
79 |
[EAST, NORTH, WEST, SOUTH] = [(1,0), (0,-1), (-1,0), (0,1)] |
|
80 |
||
81 |
# Contants for defining which mode is selected for each view |
|
82 |
[MODE_SELECTION, MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, MODE_WIRE, |
|
83 |
MODE_INITIAL_STEP] = range(7) |
|
84 |
||
85 |
""" |
|
86 |
Basic vector operations for calculate wire points |
|
87 |
""" |
|
88 |
||
89 |
# Calculate the scalar product of two vectors |
|
90 |
def product(v1, v2): |
|
91 |
return v1[0] * v2[0] + v1[1] * v2[1] |
|
92 |
||
93 |
# Create a vector from two points and define if vector must be normal |
|
94 |
def vector(p1, p2, normal = True): |
|
95 |
vector = (p2.x - p1.x, p2.y - p1.y) |
|
96 |
if normal: |
|
97 |
return normalize(vector) |
|
98 |
return vector |
|
99 |
||
100 |
# Calculate the norm of a given vector |
|
101 |
def norm(v): |
|
102 |
return sqrt(v[0] * v[0] + v[1] * v[1]) |
|
103 |
||
104 |
# Normalize a given vector |
|
105 |
def normalize(v): |
|
106 |
v_norm = norm(v) |
|
107 |
# Verifie if it is not a null vector |
|
108 |
if v_norm > 0: |
|
109 |
return (v[0] / v_norm, v[1] / v_norm) |
|
110 |
else: |
|
111 |
return v |
|
112 |
||
113 |
||
114 |
""" |
|
115 |
Function that calculates the nearest point of the grid defined by scaling for the given point |
|
116 |
""" |
|
117 |
||
118 |
def GetScaledEventPosition(event, scaling): |
|
119 |
pos = event.GetPosition() |
|
120 |
if scaling: |
|
121 |
pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0] |
|
122 |
pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1] |
|
123 |
return pos |
|
124 |
||
125 |
||
126 |
""" |
|
127 |
Function that choose a direction during the wire points generation |
|
128 |
""" |
|
129 |
||
130 |
def DirectionChoice(v_base, v_target, dir_target): |
|
131 |
dir_product = product(v_base, v_target) |
|
132 |
if dir_product < 0: |
|
133 |
return (-v_base[0], -v_base[1]) |
|
134 |
elif dir_product == 0 and product(v_base, dir_target) != 0: |
|
135 |
return dir_target |
|
136 |
return v_base |
|
137 |
||
138 |
||
139 |
#------------------------------------------------------------------------------- |
|
140 |
# Viewer Rubberband |
|
141 |
#------------------------------------------------------------------------------- |
|
142 |
||
143 |
""" |
|
144 |
Class that implements a rubberband |
|
145 |
""" |
|
146 |
||
147 |
class RubberBand: |
|
148 |
||
149 |
# Create a rubberband by indicated on which window it must be drawn |
|
150 |
def __init__(self, drawingSurface): |
|
151 |
self.drawingSurface = drawingSurface |
|
152 |
self.Reset() |
|
153 |
||
154 |
# Method that initializes the internal attributes of the rubberband |
|
155 |
def Reset(self): |
|
156 |
self.startPoint = None |
|
157 |
self.currentBox = None |
|
158 |
self.lastBox = None |
|
159 |
||
160 |
# Method that return if a box is currently edited |
|
161 |
def IsShown(self): |
|
162 |
return self.currentBox != None |
|
163 |
||
164 |
# Method that returns the currently edited box |
|
165 |
def GetCurrentExtent(self): |
|
166 |
return self.currentBox |
|
167 |
||
168 |
# Method called when a new box starts to be edited |
|
169 |
def OnLeftDown(self, event, scaling): |
|
170 |
pos = GetScaledEventPosition(event, scaling) |
|
171 |
# Save the point for calculate the box position and size |
|
172 |
self.startPoint = pos |
|
173 |
self.currentBox = wxRect(pos.x, pos.y, 0, 0) |
|
174 |
self.drawingSurface.SetCursor(wxStockCursor(wxCURSOR_CROSS)) |
|
175 |
self.Redraw() |
|
176 |
||
177 |
# Method called when dragging with a box edited |
|
178 |
def OnMotion(self, event, scaling): |
|
179 |
pos = GetScaledEventPosition(event, scaling) |
|
180 |
# Save the last position and size of the box for erasing it |
|
181 |
self.lastBox = wxRect(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
|
182 |
self.currentBox.height) |
|
183 |
# Calculate new position and size of the box |
|
184 |
if pos.x >= self.startPoint.x: |
|
185 |
self.currentBox.x = self.startPoint.x |
|
186 |
self.currentBox.width = pos.x - self.startPoint.x + 1 |
|
187 |
else: |
|
188 |
self.currentBox.x = pos.x |
|
189 |
self.currentBox.width = self.startPoint.x - pos.x + 1 |
|
190 |
if pos.y >= self.startPoint.y: |
|
191 |
self.currentBox.y = self.startPoint.y |
|
192 |
self.currentBox.height = pos.y - self.startPoint.y + 1 |
|
193 |
else: |
|
194 |
self.currentBox.y = pos.y |
|
195 |
self.currentBox.height = self.startPoint.y - pos.y + 1 |
|
196 |
self.Redraw() |
|
197 |
||
198 |
# Method called when dragging is stopped |
|
199 |
def OnLeftUp(self, event, scaling): |
|
200 |
self.drawingSurface.SetCursor(wxNullCursor) |
|
201 |
self.lastBox = self.currentBox |
|
202 |
self.currentBox = None |
|
203 |
self.Redraw() |
|
204 |
||
205 |
# Method that erase the last box and draw the new box |
|
206 |
def Redraw(self): |
|
207 |
dc = wxClientDC(self.drawingSurface) |
|
208 |
dc.SetPen(wxPen(wxWHITE, 1, wxDOT)) |
|
209 |
dc.SetBrush(wxTRANSPARENT_BRUSH) |
|
210 |
dc.SetLogicalFunction(wxXOR) |
|
211 |
if self.lastBox: |
|
212 |
# Erase last box |
|
213 |
dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
|
214 |
self.lastBox.height) |
|
215 |
if self.currentBox: |
|
216 |
# Draw current box |
|
217 |
dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
|
218 |
self.currentBox.height) |
|
219 |
||
220 |
||
221 |
#------------------------------------------------------------------------------- |
|
222 |
# Graphic element base class |
|
223 |
#------------------------------------------------------------------------------- |
|
224 |
||
225 |
""" |
|
226 |
Class that implements a generic graphic element |
|
227 |
""" |
|
228 |
||
229 |
class Graphic_Element: |
|
230 |
||
231 |
# Create a new graphic element |
|
232 |
def __init__(self, parent, id = None): |
|
233 |
self.Parent = parent |
|
234 |
self.Id = id |
|
235 |
self.oldPos = None |
|
236 |
self.Handle = False |
|
237 |
self.Dragging = False |
|
238 |
self.Selected = False |
|
239 |
self.Pos = wxPoint(0, 0) |
|
240 |
self.Size = wxSize(0, 0) |
|
241 |
self.BoundingBox = wxRect(0, 0, 0, 0) |
|
242 |
||
243 |
# Make a clone of this element |
|
244 |
def Clone(self): |
|
245 |
return Graphic_Element(self.Parent, self.Id) |
|
246 |
||
247 |
# Changes the block position |
|
248 |
def SetPosition(self, x, y): |
|
249 |
self.Pos.x = x |
|
250 |
self.Pos.y = y |
|
251 |
self.RefreshConnected() |
|
252 |
self.RefreshBoundingBox() |
|
253 |
||
254 |
# Returns the block position |
|
255 |
def GetPosition(self): |
|
256 |
return self.Pos.x, self.Pos.y |
|
257 |
||
258 |
# Changes the element size |
|
259 |
def SetSize(self, width, height): |
|
260 |
self.Size.SetWidth(width) |
|
261 |
self.Size.SetHeight(height) |
|
262 |
self.RefreshConnectors() |
|
263 |
self.RefreshBoundingBox() |
|
264 |
||
265 |
# Returns the element size |
|
266 |
def GetSize(self): |
|
267 |
return self.Size.GetWidth(), self.Size.GetHeight() |
|
268 |
||
269 |
# Refresh the element Bounding Box |
|
270 |
def RefreshBoundingBox(self): |
|
271 |
self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]) |
|
272 |
||
273 |
# Refresh the element connectors position |
|
274 |
def RefreshConnectors(self): |
|
275 |
pass |
|
276 |
||
277 |
# Refresh the position of wires connected to element inputs and outputs |
|
278 |
def RefreshConnected(self): |
|
279 |
pass |
|
280 |
||
281 |
# Change the parent |
|
282 |
def SetParent(self, parent): |
|
283 |
self.Parent = parent |
|
284 |
||
285 |
# Override this method for defining the method to call for deleting this element |
|
286 |
def Delete(self): |
|
287 |
pass |
|
288 |
||
289 |
# Returns the Id |
|
290 |
def GetId(self): |
|
291 |
return self.Id |
|
292 |
||
293 |
# Returns if the point given is in the bounding box |
|
294 |
def HitTest(self, pt): |
|
295 |
rect = self.BoundingBox |
|
296 |
return rect.InsideXY(pt.x, pt.y) |
|
297 |
||
298 |
# Override this method for refreshing the bounding box |
|
299 |
def RefreshBoundingBox(self): |
|
300 |
pass |
|
301 |
||
302 |
# Returns the bounding box |
|
303 |
def GetBoundingBox(self): |
|
304 |
return self.BoundingBox |
|
305 |
||
306 |
# Change the variable that indicates if this element is selected |
|
307 |
def SetSelected(self, selected): |
|
308 |
self.Selected = selected |
|
309 |
||
310 |
# Test if the point is on a handle of this element |
|
311 |
def TestHandle(self, pt): |
|
312 |
# Verify that this element is selected |
|
313 |
if self.Selected: |
|
314 |
# Find if point is on a handle horizontally |
|
315 |
if self.BoundingBox.x - HANDLE_SIZE - 2 <= pt.x < self.BoundingBox.x - 2: |
|
316 |
handle_x = 1 |
|
317 |
elif self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2 <= pt.x < self.BoundingBox.x + (self.BoundingBox.width + HANDLE_SIZE) / 2: |
|
318 |
handle_x = 2 |
|
319 |
elif self.BoundingBox.x + self.BoundingBox.width + 2 <= pt.x < self.BoundingBox.x + self.BoundingBox.width + HANDLE_SIZE + 2: |
|
320 |
handle_x = 3 |
|
321 |
else: |
|
322 |
handle_x = 0 |
|
323 |
# Find if point is on a handle vertically |
|
324 |
if self.BoundingBox.y - HANDLE_SIZE - 2 <= pt.y < self.BoundingBox.y - 2: |
|
325 |
handle_y = 1 |
|
326 |
elif self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2 <= pt.y < self.BoundingBox.y + (self.BoundingBox.height + HANDLE_SIZE) / 2: |
|
327 |
handle_y = 2 |
|
328 |
elif self.BoundingBox.y + self.BoundingBox.height - 2 <= pt.y < self.BoundingBox.y + self.BoundingBox.height + HANDLE_SIZE + 2: |
|
329 |
handle_y = 3 |
|
330 |
else: |
|
331 |
handle_y = 0 |
|
332 |
# Verify that the result is valid |
|
333 |
if (handle_x, handle_y) in VALID_HANDLES: |
|
334 |
return handle_x, handle_y |
|
335 |
return 0, 0 |
|
336 |
||
337 |
# Method called when a LeftDown event have been generated |
|
338 |
def OnLeftDown(self, event, scaling): |
|
339 |
pos = event.GetPosition() |
|
340 |
# Test if an handle have been clicked |
|
341 |
result = self.TestHandle(pos) |
|
342 |
# Find which type of handle have been clicked, |
|
343 |
# Save a resize event and change the cursor |
|
344 |
if result == (1, 1) or result == (3, 3): |
|
345 |
self.Handle = (HANDLE_RESIZE, result) |
|
346 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENWSE)) |
|
347 |
elif result == (1, 3) or result == (3, 1): |
|
348 |
self.Handle = (HANDLE_RESIZE, result) |
|
349 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENESW)) |
|
350 |
elif result == (1, 2) or result == (3, 2): |
|
351 |
self.Handle = (HANDLE_RESIZE, result) |
|
352 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZEWE)) |
|
353 |
elif result == (2, 1) or result == (2, 3): |
|
354 |
self.Handle = (HANDLE_RESIZE, result) |
|
355 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENS)) |
|
356 |
# If no handle have been clicked, save a move event, and change the cursor |
|
357 |
else: |
|
358 |
self.Handle = (HANDLE_MOVE, None) |
|
359 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND)) |
|
360 |
self.SetSelected(False) |
|
361 |
# Initializes the last position |
|
362 |
self.oldPos = GetScaledEventPosition(event, scaling) |
|
363 |
||
364 |
# Method called when a LeftUp event have been generated |
|
365 |
def OnLeftUp(self, event, scaling): |
|
366 |
# If a dragging have been initiated |
|
367 |
if self.Dragging and self.oldPos: |
|
368 |
# Calculate the movement of cursor and refreshes the element state |
|
369 |
pos = GetScaledEventPosition(event, scaling) |
|
370 |
movex = pos.x - self.oldPos.x |
|
371 |
movey = pos.y - self.oldPos.y |
|
372 |
self.ProcessDragging(movex, movey) |
|
373 |
self.RefreshModel() |
|
374 |
self.SetSelected(True) |
|
375 |
self.oldPos = None |
|
376 |
||
377 |
# Method called when a RightUp event have been generated |
|
378 |
def OnRightUp(self, event, scaling): |
|
379 |
self.SetSelected(True) |
|
380 |
self.oldPos = None |
|
381 |
||
382 |
# Method called when a LeftDClick event have been generated |
|
383 |
def OnLeftDClick(self, event, scaling): |
|
384 |
pass |
|
385 |
||
386 |
# Method called when a Motion event have been generated |
|
387 |
def OnMotion(self, event, scaling): |
|
388 |
# If the cursor is dragging and the element have been clicked |
|
389 |
if event.Dragging() and self.oldPos: |
|
390 |
# Calculate the movement of cursor |
|
391 |
pos = GetScaledEventPosition(event, scaling) |
|
392 |
movex = pos.x - self.oldPos.x |
|
393 |
movey = pos.y - self.oldPos.y |
|
394 |
# If movement is greater than MIN_MOVE then a dragging is initiated |
|
395 |
if not self.Dragging and (abs(movex) > MIN_MOVE or abs(movey) > MIN_MOVE): |
|
396 |
self.Dragging = True |
|
397 |
# If a dragging have been initiated, refreshes the element state |
|
398 |
if self.Dragging: |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
399 |
self.oldPos = pos |
0 | 400 |
self.ProcessDragging(movex, movey) |
401 |
# If cursor just pass over the element, changes the cursor if it is on a handle |
|
402 |
else: |
|
403 |
pos = event.GetPosition() |
|
404 |
handle = self.TestHandle(pos) |
|
405 |
if handle == (1, 1) or handle == (3, 3): |
|
406 |
wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENWSE)) |
|
407 |
elif handle == (1, 3) or handle == (3, 1): |
|
408 |
wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENESW)) |
|
409 |
elif handle == (1, 2) or handle == (3, 2): |
|
410 |
wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZEWE)) |
|
411 |
elif handle == (2, 1) or handle == (2, 3): |
|
412 |
wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENS)) |
|
413 |
else: |
|
414 |
wxCallAfter(self.Parent.SetCursor, wxNullCursor) |
|
415 |
||
416 |
# Moves the element |
|
417 |
def Move(self, dx, dy, exclude = []): |
|
418 |
self.Pos.x += dx |
|
419 |
self.Pos.y += dy |
|
420 |
self.RefreshConnected(exclude) |
|
421 |
self.RefreshBoundingBox() |
|
422 |
||
423 |
# Resizes the element from position and size given |
|
424 |
def Resize(self, x, y, width, height): |
|
425 |
self.Move(x, y) |
|
426 |
self.SetSize(width, height) |
|
427 |
||
428 |
# Refreshes the element state according to move defined and handle selected |
|
429 |
def ProcessDragging(self, movex, movey): |
|
430 |
handle_type, handle = self.Handle |
|
431 |
# If it is a resize handle, calculate the values from resizing |
|
432 |
if handle_type == HANDLE_RESIZE: |
|
433 |
x, y = 0, 0 |
|
434 |
width, height = self.GetSize() |
|
435 |
if handle[0] == 1: |
|
436 |
x = movex |
|
437 |
width -= movex |
|
438 |
elif handle[0] == 3: |
|
439 |
width += movex |
|
440 |
if handle[1] == 1: |
|
441 |
y = movey |
|
442 |
height -= movey |
|
443 |
elif handle[1] == 3: |
|
444 |
height += movey |
|
445 |
# Verify that new size is not lesser than minimum |
|
446 |
min_width, min_height = self.GetMinSize() |
|
447 |
if width >= min_width and height >= min_height: |
|
448 |
self.Resize(x, y, width, height) |
|
449 |
# If it is a move handle, Move this element |
|
450 |
elif handle_type == HANDLE_MOVE: |
|
451 |
self.Move(movex, movey) |
|
452 |
||
453 |
# Override this method for defining the method to call for refreshing the model of this element |
|
454 |
def RefreshModel(self, move=True): |
|
455 |
pass |
|
456 |
||
457 |
# Draws the handles of this element if it is selected |
|
458 |
def Draw(self, dc): |
|
459 |
if self.Selected: |
|
460 |
dc.SetPen(wxBLACK_PEN) |
|
461 |
dc.SetBrush(wxBLACK_BRUSH) |
|
462 |
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
|
463 |
dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
|
464 |
self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
|
465 |
dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
|
466 |
self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
|
467 |
dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
|
468 |
self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE) |
|
469 |
dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
|
470 |
self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
|
471 |
dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
|
472 |
self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
|
473 |
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
|
474 |
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE) |
|
475 |
dc.SetBrush(wxWHITE_BRUSH) |
|
476 |
||
477 |
||
478 |
#------------------------------------------------------------------------------- |
|
479 |
# Group of graphic elements |
|
480 |
#------------------------------------------------------------------------------- |
|
481 |
||
482 |
""" |
|
483 |
Class that implements a group of graphic elements |
|
484 |
""" |
|
485 |
||
486 |
class Graphic_Group(Graphic_Element): |
|
487 |
||
488 |
# Create a new group of graphic elements |
|
489 |
def __init__(self, parent): |
|
490 |
Graphic_Element.__init__(self, parent) |
|
491 |
self.Elements = [] |
|
492 |
self.RefreshBoundingBox() |
|
493 |
||
494 |
# Destructor |
|
495 |
def __del__(self): |
|
496 |
self.Elements = [] |
|
497 |
||
498 |
# Make a clone of this group |
|
499 |
def Clone(self): |
|
500 |
clone = Graphic_Group(self.Parent) |
|
501 |
elements = [] |
|
502 |
# Makes a clone of all the elements in this group |
|
503 |
for element in self.Elements: |
|
504 |
elements.append(element.Clone()) |
|
505 |
clone.SetElements(elements) |
|
506 |
return clone |
|
507 |
||
508 |
# Clean this group of elements |
|
509 |
def Clean(self): |
|
510 |
# Clean all the elements of the group |
|
511 |
for element in self.Elements: |
|
512 |
element.Clean() |
|
513 |
||
514 |
# Delete this group of elements |
|
515 |
def Delete(self): |
|
516 |
# Delete all the elements of the group |
|
517 |
for element in self.Elements: |
|
518 |
element.Delete() |
|
519 |
||
520 |
# Returns if the point given is in the bounding box of one of the elements of this group |
|
521 |
def HitTest(self, pt): |
|
522 |
result = False |
|
523 |
for element in self.Elements: |
|
524 |
result |= element.HitTest(pt) |
|
525 |
return result |
|
526 |
||
527 |
# Returns if the element given is in this group |
|
528 |
def IsElementIn(self, element): |
|
529 |
return element in self.Elements |
|
530 |
||
531 |
# Change the elements of the group |
|
532 |
def SetElements(self, elements): |
|
533 |
self.Elements = elements |
|
534 |
self.RefreshBoundingBox() |
|
535 |
||
536 |
# Returns the elements of the group |
|
537 |
def GetElements(self): |
|
538 |
return self.Elements |
|
539 |
||
540 |
# Remove or select the given element if it is or not in the group |
|
541 |
def SelectElement(self, element): |
|
542 |
if element in self.Elements: |
|
543 |
self.Elements.remove(element) |
|
544 |
else: |
|
545 |
self.Elements.append(element) |
|
546 |
self.RefreshBoundingBox() |
|
547 |
||
548 |
# Move this group of elements |
|
549 |
def Move(self, movex, movey): |
|
550 |
exclude = [] |
|
551 |
for element in self.Elements: |
|
552 |
if isinstance(element, Wire): |
|
553 |
exclude.append(element) |
|
554 |
# Move all the elements of the group |
|
555 |
for element in self.Elements: |
|
556 |
if isinstance(element, Wire): |
|
557 |
element.Move(movex, movey, True) |
|
558 |
else: |
|
559 |
element.Move(movex, movey, exclude) |
|
560 |
self.RefreshBoundingBox() |
|
561 |
||
562 |
# Refreshes the bounding box of this group of elements |
|
563 |
def RefreshBoundingBox(self): |
|
564 |
if len(self.Elements) > 0: |
|
565 |
bbox = self.Elements[0].GetBoundingBox() |
|
566 |
minx, miny = bbox.x, bbox.y |
|
567 |
maxx = bbox.x + bbox.width |
|
568 |
maxy = bbox.y + bbox.height |
|
569 |
for element in self.Elements[1:]: |
|
570 |
bbox = element.GetBoundingBox() |
|
571 |
minx = min(minx, bbox.x) |
|
572 |
miny = min(miny, bbox.y) |
|
573 |
maxx = max(maxx, bbox.x + bbox.width) |
|
574 |
maxy = max(maxy, bbox.y + bbox.height) |
|
575 |
self.BoundingBox = wxRect(minx, miny, maxx - minx, maxy - miny) |
|
576 |
else: |
|
577 |
self.BoundingBox = wxRect(0, 0, 0, 0) |
|
578 |
||
579 |
# Forbids to change the group position |
|
580 |
def SetPosition(x, y): |
|
581 |
pass |
|
582 |
||
583 |
# Returns the position of this group |
|
584 |
def GetPosition(self): |
|
585 |
return self.BoundingBox.x, self.BoundingBox.y |
|
586 |
||
587 |
# Forbids to change the group size |
|
588 |
def SetSize(width, height): |
|
589 |
pass |
|
590 |
||
591 |
# Returns the size of this group |
|
592 |
def GetSize(self): |
|
593 |
return self.BoundingBox.width, self.BoundingBox.height |
|
594 |
||
595 |
# Change the variable that indicates if the elemente is selected |
|
596 |
def SetSelected(self, selected): |
|
597 |
for element in self.Elements: |
|
598 |
element.SetSelected(selected) |
|
599 |
||
600 |
# Refreshes the model of all the elements of this group |
|
601 |
def RefreshModel(self): |
|
602 |
for element in self.Elements: |
|
603 |
element.RefreshModel() |
|
604 |
||
605 |
||
606 |
#------------------------------------------------------------------------------- |
|
607 |
# Connector for all types of blocks |
|
608 |
#------------------------------------------------------------------------------- |
|
609 |
||
610 |
""" |
|
611 |
Class that implements a connector for any type of block |
|
612 |
""" |
|
613 |
||
614 |
class Connector: |
|
615 |
||
616 |
# Create a new connector |
|
617 |
def __init__(self, parent, name, type, position, direction, negated = False, edge = "none"): |
|
618 |
self.ParentBlock = parent |
|
619 |
self.Name = name |
|
620 |
self.Type = type |
|
621 |
self.Pos = position |
|
622 |
self.Direction = direction |
|
623 |
self.Wires = [] |
|
624 |
self.Negated = negated |
|
625 |
self.Edge = edge |
|
626 |
self.Pen = wxBLACK_PEN |
|
627 |
||
628 |
# Change the connector pen |
|
629 |
def SetPen(self, pen): |
|
630 |
self.Pen = pen |
|
631 |
||
632 |
# Make a clone of the connector |
|
633 |
def Clone(self): |
|
634 |
return Connector(self.Parent, self.Name, self.Type, wxPoint(self.Pos[0], self.Pos[1]), |
|
635 |
self.Direction, self.Negated) |
|
636 |
||
637 |
# Returns the connector parent block |
|
638 |
def GetParentBlock(self): |
|
639 |
return self.ParentBlock |
|
640 |
||
641 |
# Returns the connector name |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
642 |
def GetType(self): |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
643 |
return self.Type |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
644 |
|
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
645 |
# Changes the connector name |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
646 |
def SetType(self, type): |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
647 |
self.Type = type |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
648 |
|
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
649 |
# Returns the connector name |
0 | 650 |
def GetName(self): |
651 |
return self.Name |
|
652 |
||
653 |
# Changes the connector name |
|
654 |
def SetName(self, name): |
|
655 |
self.Name = name |
|
656 |
||
657 |
# Returns the wires connected to the connector |
|
658 |
def GetWires(self): |
|
659 |
return self.Wires |
|
660 |
||
661 |
# Returns the parent block Id |
|
662 |
def GetBlockId(self): |
|
663 |
return self.ParentBlock.GetId() |
|
664 |
||
665 |
# Returns the connector relative position |
|
666 |
def GetRelPosition(self): |
|
667 |
return self.Pos |
|
668 |
||
669 |
# Returns the connector absolute position |
|
670 |
def GetPosition(self, size = True): |
|
671 |
parent_pos = self.ParentBlock.GetPosition() |
|
672 |
# If the position of the end of the connector is asked |
|
673 |
if size: |
|
674 |
x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE |
|
675 |
y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
|
676 |
else: |
|
677 |
x = parent_pos[0] + self.Pos.x |
|
678 |
y = parent_pos[1] + self.Pos.y |
|
679 |
return wxPoint(x, y) |
|
680 |
||
681 |
# Change the connector relative position |
|
682 |
def SetPosition(self, pos): |
|
683 |
self.Pos = pos |
|
684 |
||
685 |
# Returns the connector direction |
|
686 |
def GetDirection(self): |
|
687 |
return self.Direction |
|
688 |
||
689 |
# Change the connector direction |
|
690 |
def SetDirection(self, direction): |
|
691 |
self.Direction = direction |
|
692 |
||
693 |
# Connect a wire to this connector at the last place |
|
694 |
def Connect(self, wire, refresh = True): |
|
695 |
self.InsertConnect(len(self.Wires), wire, refresh) |
|
696 |
||
697 |
# Connect a wire to this connector at the place given |
|
698 |
def InsertConnect(self, idx, wire, refresh = True): |
|
699 |
if wire not in self.Wires: |
|
700 |
self.Wires.insert(idx, wire) |
|
701 |
if refresh: |
|
702 |
self.ParentBlock.RefreshModel(False) |
|
703 |
||
704 |
# Returns the index of the wire given in the list of connected |
|
705 |
def GetWireIndex(self, wire): |
|
706 |
for i, (tmp_wire, handle) in enumerate(self.Wires): |
|
707 |
if tmp_wire == wire: |
|
708 |
return i |
|
709 |
return None |
|
710 |
||
711 |
# Unconnect a wire or all wires connected to the connector |
|
2 | 712 |
def UnConnect(self, wire = None, unconnect = True, delete = False): |
0 | 713 |
i = 0 |
714 |
found = False |
|
715 |
while i < len(self.Wires) and not found: |
|
716 |
if not wire or self.Wires[i][0] == wire: |
|
717 |
# If Unconnect haven't been called from a wire, disconnect the connector in the wire |
|
718 |
if unconnect: |
|
719 |
if self.Wires[i][1] == 0: |
|
2 | 720 |
self.Wires[i][0].UnConnectStartPoint(delete) |
0 | 721 |
else: |
2 | 722 |
self.Wires[i][0].UnConnectEndPoint(delete) |
0 | 723 |
# Remove wire from connected |
724 |
if wire: |
|
725 |
self.Wires.pop(i) |
|
726 |
found = True |
|
727 |
i += 1 |
|
728 |
# If no wire defined, unconnect all wires |
|
729 |
if not wire: |
|
730 |
self.Wires = [] |
|
731 |
self.ParentBlock.RefreshModel(False) |
|
732 |
||
733 |
# Returns if connector has one or more wire connected |
|
734 |
def IsConnected(self): |
|
735 |
return len(self.Wires) > 0 |
|
736 |
||
737 |
# Move the wires connected |
|
738 |
def MoveConnected(self, exclude = []): |
|
739 |
if len(self.Wires) > 0: |
|
740 |
# Calculate the new position of the end point |
|
741 |
parent_pos = self.ParentBlock.GetPosition() |
|
742 |
x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE |
|
743 |
y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
|
744 |
# Move the corresponding point on all the wires connected |
|
745 |
for wire, index in self.Wires: |
|
746 |
if wire not in exclude: |
|
747 |
if index == 0: |
|
748 |
wire.MoveStartPoint(wxPoint(x, y)) |
|
749 |
else: |
|
750 |
wire.MoveEndPoint(wxPoint(x, y)) |
|
751 |
||
752 |
# Refreshes the model of all the wires connected |
|
753 |
def RefreshWires(self): |
|
754 |
for wire in self.Wires: |
|
755 |
wire[0].RefreshModel() |
|
756 |
||
757 |
# Refreshes the parent block model |
|
758 |
def RefreshParentBlock(self): |
|
759 |
self.ParentBlock.RefreshModel(False) |
|
760 |
||
761 |
# Returns the connector negated property |
|
762 |
def IsNegated(self): |
|
763 |
return self.Negated |
|
764 |
||
765 |
# Changes the connector negated property |
|
766 |
def SetNegated(self, negated): |
|
767 |
self.Negated = negated |
|
768 |
self.Edge = "none" |
|
769 |
||
770 |
# Returns the connector edge property |
|
771 |
def GetEdge(self): |
|
772 |
return self.Edge |
|
773 |
||
774 |
# Changes the connector edge property |
|
775 |
def SetEdge(self, edge): |
|
776 |
self.Edge = edge |
|
777 |
self.Negated = False |
|
778 |
||
779 |
# Tests if the point given is near from the end point of this connector |
|
780 |
def TestPoint(self, pt, exclude = True): |
|
781 |
parent_pos = self.ParentBlock.GetPosition() |
|
782 |
if not (len(self.Wires) > 0 and self.Direction == WEST and exclude): |
|
783 |
# Calculate a square around the end point of this connector |
|
784 |
x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
|
785 |
y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
|
786 |
width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE |
|
787 |
height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE |
|
788 |
rect = wxRect(x, y, width, height) |
|
789 |
return rect.InsideXY(pt.x, pt.y) |
|
790 |
return False |
|
791 |
||
792 |
# Draws the connector |
|
793 |
def Draw(self, dc): |
|
794 |
dc.SetPen(self.Pen) |
|
795 |
dc.SetBrush(wxWHITE_BRUSH) |
|
796 |
parent_pos = self.ParentBlock.GetPosition() |
|
797 |
if self.Negated: |
|
798 |
# If connector is negated, draw a circle |
|
799 |
xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2 |
|
800 |
ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2 |
|
801 |
dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE / 2) |
|
802 |
else: |
|
803 |
xstart = parent_pos[0] + self.Pos.x |
|
804 |
ystart = parent_pos[1] + self.Pos.y |
|
805 |
if self.Edge == "rising": |
|
806 |
# If connector has a rising edge, draw a right arrow |
|
807 |
dc.DrawLine(xstart, ystart, xstart - 4, ystart - 4) |
|
808 |
dc.DrawLine(xstart, ystart, xstart - 4, ystart + 4) |
|
809 |
elif self.Edge == "falling": |
|
810 |
# If connector has a falling edge, draw a left arrow |
|
811 |
dc.DrawLine(xstart, ystart, xstart + 4, ystart - 4) |
|
812 |
dc.DrawLine(xstart, ystart, xstart + 4, ystart + 4) |
|
813 |
xend = xstart + CONNECTOR_SIZE * self.Direction[0] |
|
814 |
yend = ystart + CONNECTOR_SIZE * self.Direction[1] |
|
815 |
dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) |
|
816 |
# Calculate the position of the text |
|
817 |
text_size = dc.GetTextExtent(self.Name) |
|
818 |
if self.Direction[0] != 0: |
|
819 |
ytext = parent_pos[1] + self.Pos.y - text_size[1] / 2 |
|
820 |
if self.Direction[0] < 0: |
|
821 |
xtext = parent_pos[0] + self.Pos.x + 5 |
|
822 |
else: |
|
823 |
xtext = parent_pos[0] + self.Pos.x - (text_size[0] + 5) |
|
824 |
if self.Direction[1] != 0: |
|
825 |
xtext = parent_pos[0] + self.Pos.x - text_size[0] / 2 |
|
826 |
if self.Direction[1] < 0: |
|
827 |
ytext = parent_pos[1] + self.Pos.y + 5 |
|
828 |
else: |
|
829 |
ytext = parent_pos[1] + self.Pos.y - (text_size[1] + 5) |
|
830 |
# Draw the text |
|
831 |
dc.DrawText(self.Name, xtext, ytext) |
|
832 |
||
833 |
||
834 |
#------------------------------------------------------------------------------- |
|
835 |
# Common Wire Element |
|
836 |
#------------------------------------------------------------------------------- |
|
837 |
||
838 |
""" |
|
839 |
Class that implements a wire for connecting two blocks |
|
840 |
""" |
|
841 |
||
842 |
class Wire(Graphic_Element): |
|
843 |
||
844 |
# Create a new wire |
|
845 |
def __init__(self, parent, start = None, end = None): |
|
846 |
Graphic_Element.__init__(self, parent) |
|
847 |
self.StartPoint = start |
|
848 |
self.EndPoint = end |
|
849 |
self.StartConnected = None |
|
850 |
self.EndConnected = None |
|
851 |
# If the start and end points are defined, calculate the wire |
|
852 |
if start and end: |
|
853 |
self.ResetPoints() |
|
854 |
self.GeneratePoints() |
|
855 |
else: |
|
856 |
self.Points = [] |
|
857 |
self.Segments = [] |
|
858 |
self.SelectedSegment = None |
|
859 |
self.OverStart = False |
|
860 |
self.OverEnd = False |
|
861 |
||
862 |
# Destructor of a wire |
|
863 |
def __del__(self): |
|
864 |
self.StartConnected = None |
|
865 |
self.EndConnected = None |
|
866 |
||
867 |
# Forbids to change the wire position |
|
868 |
def SetPosition(x, y): |
|
869 |
pass |
|
870 |
||
871 |
# Forbids to change the wire size |
|
872 |
def SetSize(width, height): |
|
873 |
pass |
|
874 |
||
875 |
# Unconnect the start and end points |
|
876 |
def Clean(self): |
|
877 |
if self.StartConnected: |
|
878 |
self.UnConnectStartPoint() |
|
879 |
if self.EndConnected: |
|
880 |
self.UnConnectEndPoint() |
|
881 |
||
882 |
# Delete this wire by calling the corresponding method |
|
883 |
def Delete(self): |
|
884 |
self.Parent.DeleteWire(self) |
|
885 |
||
886 |
# Select a segment and not the whole wire. It's useful for Ladder Diagram |
|
887 |
def SetSelectedSegment(self, segment): |
|
888 |
# The last segment is indicated |
|
889 |
if segment == -1: |
|
890 |
segment = len(self.Segments) - 1 |
|
891 |
# The selected segment is reinitialised |
|
892 |
if segment == None: |
|
893 |
if self.StartConnected: |
|
894 |
self.StartConnected.SetPen(wxBLACK_PEN) |
|
895 |
if self.EndConnected: |
|
896 |
self.EndConnected.SetPen(wxBLACK_PEN) |
|
897 |
# The segment selected is the first |
|
898 |
elif segment == 0: |
|
899 |
if self.StartConnected: |
|
900 |
self.StartConnected.SetPen(wxRED_PEN) |
|
901 |
if self.EndConnected: |
|
902 |
# There is only one segment |
|
903 |
if len(self.Segments) == 1: |
|
904 |
self.EndConnected.SetPen(wxRED_PEN) |
|
905 |
else: |
|
906 |
self.EndConnected.SetPen(wxBLACK_PEN) |
|
907 |
# The segment selected is the last |
|
908 |
elif segment == len(self.Segments) - 1: |
|
909 |
if self.StartConnected: |
|
910 |
self.StartConnected.SetPen(wxBLACK_PEN) |
|
911 |
if self.EndConnected: |
|
912 |
self.EndConnected.SetPen(wxRED_PEN) |
|
913 |
self.SelectedSegment = segment |
|
914 |
||
915 |
# Reinitialize the wire points |
|
916 |
def ResetPoints(self): |
|
917 |
if self.StartPoint and self.EndPoint: |
|
918 |
self.Points = [self.StartPoint[0], self.EndPoint[0]] |
|
919 |
self.Segments = [self.StartPoint[1]] |
|
920 |
else: |
|
921 |
self.Points = [] |
|
922 |
self.Segments = [] |
|
923 |
||
924 |
# Refresh the wire bounding box |
|
925 |
def RefreshBoundingBox(self): |
|
926 |
if len(self.Points) > 0: |
|
927 |
# If startpoint or endpoint is connected, save the point radius |
|
928 |
start_radius = end_radius = 0 |
|
929 |
if not self.StartConnected: |
|
930 |
start_radius = POINT_RADIUS |
|
931 |
if not self.EndConnected: |
|
932 |
end_radius = POINT_RADIUS |
|
933 |
# Initialize minimum and maximum from the first point |
|
934 |
minx, minbbxx = self.Points[0].x, self.Points[0].x - start_radius |
|
935 |
maxx, maxbbxx = self.Points[0].x, self.Points[0].x + start_radius |
|
936 |
miny, minbbxy = self.Points[0].y, self.Points[0].y - start_radius |
|
937 |
maxy, maxbbxy = self.Points[0].y, self.Points[0].y + start_radius |
|
938 |
# Actualize minimum and maximum with the other points |
|
939 |
for point in self.Points[1:-1]: |
|
940 |
minx, minbbxx = min(minx, point.x), min(minbbxx, point.x) |
|
941 |
maxx, maxbbxx = max(maxx, point.x), max(maxbbxx, point.x) |
|
942 |
miny, minbbxy = min(miny, point.y), min(minbbxy, point.y) |
|
943 |
maxy, maxbbxy = max(maxy, point.y), max(maxbbxy, point.y) |
|
944 |
if len(self.Points) > 1: |
|
945 |
minx, minbbxx = min(minx, self.Points[-1].x), min(minbbxx, self.Points[-1].x - end_radius) |
|
946 |
maxx, maxbbxx = max(maxx, self.Points[-1].x), max(maxbbxx, self.Points[-1].x + end_radius) |
|
947 |
miny, minbbxy = min(miny, self.Points[-1].y), min(minbbxy, self.Points[-1].y - end_radius) |
|
948 |
maxy, maxbbxy = max(maxy, self.Points[-1].y), max(maxbbxy, self.Points[-1].y + end_radius) |
|
949 |
self.Pos = wxPoint(minx, miny) |
|
950 |
self.Size = wxSize(maxx -minx + 1, maxy - miny + 1) |
|
951 |
self.BoundingBox = wxRect(minbbxx, minbbxy, maxbbxx - minbbxx + 1, maxbbxy - minbbxy + 1) |
|
952 |
||
953 |
# Refresh the realpoints that permits to keep the proportionality in wire during resizing |
|
954 |
def RefreshRealPoints(self): |
|
955 |
if len(self.Points) > 0: |
|
956 |
self.RealPoints = [] |
|
957 |
# Calculate float relative position of each point with the minimum point |
|
958 |
for point in self.Points: |
|
959 |
self.RealPoints.append([float(point.x - self.Pos.x), float(point.y - self.Pos.y)]) |
|
960 |
||
961 |
# Returns the wire minimum size |
|
962 |
def GetMinSize(self): |
|
963 |
width = 1 |
|
964 |
height = 1 |
|
965 |
dir_product = product(self.StartPoint[1], self.EndPoint[1]) |
|
966 |
# The directions are opposed |
|
967 |
if dir_product < 0: |
|
968 |
if self.StartPoint[0] != 0: |
|
969 |
width = MIN_SEGMENT_SIZE * 2 |
|
970 |
if self.StartPoint[1] != 0: |
|
971 |
height = MIN_SEGMENT_SIZE * 2 |
|
972 |
# The directions are the same |
|
973 |
elif dir_product > 0: |
|
974 |
if self.StartPoint[0] != 0: |
|
975 |
width = MIN_SEGMENT_SIZE |
|
976 |
if self.StartPoint[1] != 0: |
|
977 |
height = MIN_SEGMENT_SIZE |
|
978 |
# The directions are perpendiculars |
|
979 |
else: |
|
980 |
width = MIN_SEGMENT_SIZE |
|
981 |
height = MIN_SEGMENT_SIZE |
|
982 |
return width + 1, height + 1 |
|
983 |
||
984 |
# Returns if the point given is on one of the wire segments |
|
985 |
def HitTest(self, pt): |
|
986 |
test = False |
|
987 |
for i in xrange(len(self.Points) - 1): |
|
988 |
rect = wxRect(0, 0, 0, 0) |
|
989 |
x1, y1 = self.Points[i].x, self.Points[i].y |
|
990 |
x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
|
991 |
# Calculate a rectangle around the segment |
|
992 |
rect = wxRect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
|
993 |
abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
|
994 |
test |= rect.InsideXY(pt.x, pt.y) |
|
995 |
return test |
|
996 |
||
997 |
# Returns the wire start or end point if the point given is on one of them |
|
998 |
def TestPoint(self, pt): |
|
999 |
# Test the wire start point |
|
1000 |
rect = wxRect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE, |
|
1001 |
2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
|
1002 |
if rect.InsideXY(pt.x, pt.y): |
|
1003 |
return 0 |
|
1004 |
# Test the wire end point |
|
1005 |
if len(self.Points) > 1: |
|
1006 |
rect = wxRect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE, |
|
1007 |
2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
|
1008 |
if rect.InsideXY(pt.x, pt.y): |
|
1009 |
return -1 |
|
1010 |
return None |
|
1011 |
||
1012 |
# Returns the wire segment if the point given is on it |
|
1013 |
def TestSegment(self, pt, all=False): |
|
1014 |
for i in xrange(len(self.Segments)): |
|
1015 |
# If wire is not in a Ladder Diagram, first and last segments are excluded |
|
1016 |
if 0 < i < len(self.Segments) - 1 or all: |
|
1017 |
x1, y1 = self.Points[i].x, self.Points[i].y |
|
1018 |
x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
|
1019 |
# Calculate a rectangle around the segment |
|
1020 |
rect = wxRect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
|
1021 |
abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
|
1022 |
if rect.InsideXY(pt.x, pt.y): |
|
1023 |
return i, self.Segments[i] |
|
1024 |
return None |
|
1025 |
||
1026 |
# Define the wire points |
|
1027 |
def SetPoints(self, points): |
|
1028 |
if len(points) > 1: |
|
1029 |
self.Points = [wxPoint(x, y) for x, y in points] |
|
1030 |
# Calculate the start and end directions |
|
1031 |
self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
|
1032 |
self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
|
1033 |
# Calculate the start and end points |
|
1034 |
self.StartPoint[0] = wxPoint(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0], |
|
1035 |
self.Points[0].y + CONNECTOR_SIZE * self.StartPoint[1][1]) |
|
1036 |
self.EndPoint[0] = wxPoint(self.Points[-1].x + CONNECTOR_SIZE * self.EndPoint[1][0], |
|
1037 |
self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1]) |
|
1038 |
self.Points[0] = self.StartPoint[0] |
|
1039 |
self.Points[-1] = self.EndPoint[0] |
|
1040 |
# Calculate the segments directions |
|
1041 |
self.Segments = [] |
|
1042 |
for i in xrange(len(self.Points) - 1): |
|
1043 |
self.Segments.append(vector(self.Points[i], self.Points[i + 1])) |
|
1044 |
self.RefreshBoundingBox() |
|
1045 |
self.RefreshRealPoints() |
|
1046 |
||
1047 |
# Returns the position of the point indicated |
|
1048 |
def GetPoint(self, index): |
|
1049 |
if index < len(self.Points): |
|
1050 |
return self.Points[index].x, self.Points[index].y |
|
1051 |
return None |
|
1052 |
||
1053 |
# Returns a list of the position of all wire points |
|
1054 |
def GetPoints(self, invert = False): |
|
1055 |
points = self.VerifyPoints() |
|
1056 |
points[0] = wxPoint(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0], |
|
1057 |
points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1]) |
|
1058 |
points[-1] = wxPoint(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0], |
|
1059 |
points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1]) |
|
1060 |
# An inversion of the list is asked |
|
1061 |
if invert: |
|
1062 |
points.reverse() |
|
1063 |
return points |
|
1064 |
||
1065 |
# Returns the position of the two selected segment points |
|
1066 |
def GetSelectedSegmentPoints(self): |
|
1067 |
if self.SelectedSegment != None and len(self.Points) > 1: |
|
1068 |
return self.Points[self.SelectedSegment:self.SelectedSegment + 2] |
|
1069 |
return [] |
|
1070 |
||
1071 |
# Returns if the selected segment is the first and/or the last of the wire |
|
1072 |
def GetSelectedSegmentConnections(self): |
|
1073 |
if self.SelectedSegment != None and len(self.Points) > 1: |
|
1074 |
return self.SelectedSegment == 0, self.SelectedSegment == len(self.Segments) - 1 |
|
1075 |
return (True, True) |
|
1076 |
||
1077 |
# Returns the connectors on which the wire is connected |
|
1078 |
def GetConnected(self): |
|
1079 |
connected = [] |
|
1080 |
if self.StartConnected and self.StartPoint[1] == WEST: |
|
1081 |
connected.append(self.StartConnected) |
|
1082 |
if self.EndConnected and self.EndPoint[1] == WEST: |
|
1083 |
connected.append(self.EndConnected) |
|
1084 |
return connected |
|
1085 |
||
1086 |
# Returns the id of the block connected to the first or the last wire point |
|
1087 |
def GetConnectedId(self, index): |
|
1088 |
if index == 0 and self.StartConnected: |
|
1089 |
return self.StartConnected.GetBlockId() |
|
1090 |
elif index == -1 and self.EndConnected: |
|
1091 |
return self.EndConnected.GetBlockId() |
|
1092 |
return None |
|
1093 |
||
1094 |
# Update the wire points position by keeping at most possible the current positions |
|
1095 |
def GeneratePoints(self, realpoints = True): |
|
1096 |
i = 0 |
|
1097 |
# Calculate the start enad end points with the minimum segment size in the right direction |
|
1098 |
end = wxPoint(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE, |
|
1099 |
self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE) |
|
1100 |
start = wxPoint(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE, |
|
1101 |
self.StartPoint[0].y + self.StartPoint[1][1] * MIN_SEGMENT_SIZE) |
|
1102 |
# Evaluate the point till it's the last |
|
1103 |
while i < len(self.Points) - 1: |
|
1104 |
# The next point is the last |
|
1105 |
if i + 1 == len(self.Points) - 1: |
|
1106 |
# Calculate the direction from current point to end point |
|
1107 |
v_end = vector(self.Points[i], end) |
|
1108 |
# The current point is the first |
|
1109 |
if i == 0: |
|
1110 |
# If the end point is not in the start direction, a point is added |
|
1111 |
if v_end != self.Segments[0] or v_end == self.EndPoint[1]: |
|
1112 |
self.Points.insert(1, wxPoint(start.x, start.y)) |
|
1113 |
self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
|
1114 |
self.Segments[0][0]), v_end, self.EndPoint[1])) |
|
1115 |
# The current point is the second |
|
1116 |
elif i == 1: |
|
1117 |
# The previous direction and the target direction are mainly opposed, a point is added |
|
1118 |
if product(v_end, self.Segments[0]) < 0: |
|
1119 |
self.Points.insert(2, wxPoint(self.Points[1].x, self.Points[1].y)) |
|
1120 |
self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
|
1121 |
self.Segments[1][0]), v_end, self.EndPoint[1])) |
|
1122 |
# The previous direction and the end direction are the same or they are |
|
1123 |
# perpendiculars and the end direction points towards current segment |
|
1124 |
elif product(self.Segments[0], self.EndPoint[1]) >= 0 and product(self.Segments[1], self.EndPoint[1]) <= 0: |
|
1125 |
# Current point and end point are aligned |
|
1126 |
if self.Segments[0][0] != 0: |
|
1127 |
self.Points[1].x = end.x |
|
1128 |
if self.Segments[0][1] != 0: |
|
1129 |
self.Points[1].y = end.y |
|
1130 |
# If the previous direction and the end direction are the same, a point is added |
|
1131 |
if product(self.Segments[0], self.EndPoint[1]) > 0: |
|
1132 |
self.Points.insert(2, wxPoint(self.Points[1].x, self.Points[1].y)) |
|
1133 |
self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
|
1134 |
self.Segments[1][0]), v_end, self.EndPoint[1])) |
|
1135 |
else: |
|
1136 |
# Current point is positioned in the middle of start point |
|
1137 |
# and end point on the current direction and a point is added |
|
1138 |
if self.Segments[0][0] != 0: |
|
1139 |
self.Points[1].x = (end.x + start.x) / 2 |
|
1140 |
if self.Segments[0][1] != 0: |
|
1141 |
self.Points[1].y = (end.y + start.y) / 2 |
|
1142 |
self.Points.insert(2, wxPoint(self.Points[1].x, self.Points[1].y)) |
|
1143 |
self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
|
1144 |
self.Segments[1][0]), v_end, self.EndPoint[1])) |
|
1145 |
else: |
|
1146 |
# The previous direction and the end direction are perpendiculars |
|
1147 |
if product(self.Segments[i - 1], self.EndPoint[1]) == 0: |
|
1148 |
# The target direction and the end direction aren't mainly the same |
|
1149 |
if product(v_end, self.EndPoint[1]) <= 0: |
|
1150 |
# Current point and end point are aligned |
|
1151 |
if self.Segments[i - 1][0] != 0: |
|
1152 |
self.Points[i].x = end.x |
|
1153 |
if self.Segments[i - 1][1] != 0: |
|
1154 |
self.Points[i].y = end.y |
|
1155 |
# Previous direction is updated from the new point |
|
1156 |
if product(vector(self.Points[i - 1], self.Points[i]), self.Segments[i - 1]) < 0: |
|
1157 |
self.Segments[i - 1] = (-self.Segments[i - 1][0], -self.Segments[i - 1][1]) |
|
1158 |
else: |
|
1159 |
test = True |
|
1160 |
# If the current point is the third, test if the second |
|
1161 |
# point can be aligned with the end point |
|
1162 |
if i == 2: |
|
1163 |
test_point = wxPoint(self.Points[1].x, self.Points[1].y) |
|
1164 |
if self.Segments[1][0] != 0: |
|
1165 |
test_point.y = end.y |
|
1166 |
if self.Segments[1][1] != 0: |
|
1167 |
test_point.x = end.x |
|
1168 |
test = norm(vector(self.Points[0], test_point, False)) > MIN_SEGMENT_SIZE |
|
1169 |
# The previous point can be aligned |
|
1170 |
if test: |
|
1171 |
self.Points[i].x, self.Points[i].y = end.x, end.y |
|
1172 |
if self.Segments[i - 1][0] != 0: |
|
1173 |
self.Points[i - 1].y = end.y |
|
1174 |
if self.Segments[i - 1][1] != 0: |
|
1175 |
self.Points[i - 1].x = end.x |
|
1176 |
self.Segments[i] = (-self.EndPoint[1][0], -self.EndPoint[1][1]) |
|
1177 |
else: |
|
1178 |
# Current point is positioned in the middle of previous point |
|
1179 |
# and end point on the current direction and a point is added |
|
1180 |
if self.Segments[1][0] != 0: |
|
1181 |
self.Points[2].x = (self.Points[1].x + end.x) / 2 |
|
1182 |
if self.Segments[1][1] != 0: |
|
1183 |
self.Points[2].y = (self.Points[1].y + end.y) / 2 |
|
1184 |
self.Points.insert(3, wxPoint(self.Points[2].x, self.Points[2].y)) |
|
1185 |
self.Segments.insert(3, DirectionChoice((self.Segments[2][1], |
|
1186 |
self.Segments[2][0]), v_end, self.EndPoint[1])) |
|
1187 |
else: |
|
1188 |
# Current point is aligned with end point |
|
1189 |
if self.Segments[i - 1][0] != 0: |
|
1190 |
self.Points[i].x = end.x |
|
1191 |
if self.Segments[i - 1][1] != 0: |
|
1192 |
self.Points[i].y = end.y |
|
1193 |
# Previous direction is updated from the new point |
|
1194 |
if product(vector(self.Points[i - 1], self.Points[i]), self.Segments[i - 1]) < 0: |
|
1195 |
self.Segments[i - 1] = (-self.Segments[i - 1][0], -self.Segments[i - 1][1]) |
|
1196 |
# If previous direction and end direction are opposed |
|
1197 |
if product(self.Segments[i - 1], self.EndPoint[1]) < 0: |
|
1198 |
# Current point is positioned in the middle of previous point |
|
1199 |
# and end point on the current direction |
|
1200 |
if self.Segments[i - 1][0] != 0: |
|
1201 |
self.Points[i].x = (end.x + self.Points[i - 1].x) / 2 |
|
1202 |
if self.Segments[i - 1][1] != 0: |
|
1203 |
self.Points[i].y = (end.y + self.Points[i - 1].y) / 2 |
|
1204 |
# A point is added |
|
1205 |
self.Points.insert(i + 1, wxPoint(self.Points[i].x, self.Points[i].y)) |
|
1206 |
self.Segments.insert(i + 1, DirectionChoice((self.Segments[i][1], |
|
1207 |
self.Segments[i][0]), v_end, self.EndPoint[1])) |
|
1208 |
else: |
|
1209 |
# Current point is the first, and second is not mainly in the first direction |
|
1210 |
if i == 0 and product(vector(start, self.Points[1]), self.Segments[0]) < 0: |
|
1211 |
# If first and second directions aren't perpendiculars, a point is added |
|
1212 |
if product(self.Segments[0], self.Segments[1]) != 0: |
|
1213 |
self.Points.insert(1, wxPoint(start.x, start.y)) |
|
1214 |
self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
|
1215 |
self.Segments[0][0]), vector(start, self.Points[1]), self.Segments[1])) |
|
1216 |
else: |
|
1217 |
self.Points[1].x, self.Points[1].y = start.x, start.y |
|
1218 |
else: |
|
1219 |
# Next point is aligned with current point |
|
1220 |
if self.Segments[i][0] != 0: |
|
1221 |
self.Points[i + 1].y = self.Points[i].y |
|
1222 |
if self.Segments[i][1] != 0: |
|
1223 |
self.Points[i + 1].x = self.Points[i].x |
|
1224 |
# Current direction is updated from the new point |
|
1225 |
if product(vector(self.Points[i], self.Points[i + 1]), self.Segments[i]) < 0: |
|
1226 |
self.Segments[i] = (-self.Segments[i][0], -self.Segments[i][1]) |
|
1227 |
i += 1 |
|
1228 |
self.RefreshBoundingBox() |
|
1229 |
if realpoints: |
|
1230 |
self.RefreshRealPoints() |
|
1231 |
||
1232 |
# Verify that two consecutive points haven't the same position |
|
1233 |
def VerifyPoints(self): |
|
1234 |
points = [point for point in self.Points] |
|
1235 |
segments = [segment for segment in self.Segments] |
|
1236 |
i = 1 |
|
1237 |
while i < len(points) - 1: |
|
1238 |
if points[i] == points[i + 1] and segments[i - 1] == segments[i + 1]: |
|
1239 |
for j in xrange(2): |
|
1240 |
points.pop(i) |
|
1241 |
segments.pop(i) |
|
1242 |
else: |
|
1243 |
i += 1 |
|
1244 |
# If the wire isn't in a Ladder Diagram, save the new point list |
|
1245 |
if self.Parent.__class__.__name__ != "LD_Viewer": |
|
1246 |
self.Points = [point for point in points] |
|
1247 |
self.Segments = [segment for segment in segments] |
|
1248 |
self.RefreshBoundingBox() |
|
1249 |
self.RefreshRealPoints() |
|
1250 |
return points |
|
1251 |
||
1252 |
# Moves all the wire points except the first and the last if they are connected |
|
1253 |
def Move(self, dx, dy, endpoints = False): |
|
1254 |
for i, point in enumerate(self.Points): |
|
1255 |
if endpoints or not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
1256 |
point.x += dx |
|
1257 |
point.y += dy |
|
1258 |
self.StartPoint[0] = self.Points[0] |
|
1259 |
self.EndPoint[0] = self.Points[-1] |
|
1260 |
self.GeneratePoints() |
|
1261 |
||
1262 |
# Resize the wire from position and size given |
|
1263 |
def Resize(self, x, y, width, height): |
|
1264 |
if len(self.Points) > 1: |
|
1265 |
# Calculate the new position of each point for testing the new size |
|
1266 |
minx, miny = self.Pos.x, self.Pos.y |
|
1267 |
lastwidth, lastheight = self.Size.width, self.Size.height |
|
1268 |
for i, point in enumerate(self.RealPoints): |
|
1269 |
# If start or end point is connected, it's not calculate |
|
1270 |
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
1271 |
if i == 0: |
|
1272 |
dir = self.StartPoint[1] |
|
1273 |
elif i == len(self.Points) - 1: |
|
1274 |
dir = self.EndPoint[1] |
|
1275 |
else: |
|
1276 |
dir = (0, 0) |
|
1277 |
pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * (width - 1) / float(lastwidth - 1))), |
|
1278 |
width - dir[0] * MIN_SEGMENT_SIZE - 1)) |
|
1279 |
pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * (height - 1) / float(lastheight - 1))), |
|
1280 |
height - dir[1] * MIN_SEGMENT_SIZE - 1)) |
|
1281 |
self.Points[i] = wxPoint(minx + x + pointx, miny + y + pointy) |
|
1282 |
self.StartPoint[0] = self.Points[0] |
|
1283 |
self.EndPoint[0] = self.Points[-1] |
|
1284 |
self.GeneratePoints(False) |
|
1285 |
# Test if the wire position or size have changed |
|
1286 |
if x != 0 and minx == self.Pos.x: |
|
1287 |
x = 0 |
|
1288 |
width = lastwidth |
|
1289 |
if y != 0 and miny == self.Pos.y: |
|
1290 |
y = 0 |
|
1291 |
height = lastwidth |
|
1292 |
if width != lastwidth and lastwidth == self.Size.width: |
|
1293 |
width = lastwidth |
|
1294 |
if height != lastheight and lastheight == self.Size.height: |
|
1295 |
height = lastheight |
|
1296 |
# Calculate the real points from the new size, it's important for |
|
1297 |
# keeping a proportionality in the points position with the size |
|
1298 |
# duringa resize dragging |
|
1299 |
for i, point in enumerate(self.RealPoints): |
|
1300 |
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
1301 |
point[0] = point[0] * (width - 1) / float(lastwidth - 1) |
|
1302 |
point[1] = point[1] * (height - 1) / float(lastheight - 1) |
|
1303 |
# Calculate the correct position of the points from real points |
|
1304 |
for i, point in enumerate(self.RealPoints): |
|
1305 |
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
1306 |
if i == 0: |
|
1307 |
dir = self.StartPoint[1] |
|
1308 |
elif i == len(self.Points) - 1: |
|
1309 |
dir = self.EndPoint[1] |
|
1310 |
else: |
|
1311 |
dir = (0, 0) |
|
1312 |
realpointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0])), |
|
1313 |
width - dir[0] * MIN_SEGMENT_SIZE - 1)) |
|
1314 |
realpointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1])), |
|
1315 |
height - dir[1] * MIN_SEGMENT_SIZE - 1)) |
|
1316 |
self.Points[i] = wxPoint(minx + x + realpointx, miny + y + realpointy) |
|
1317 |
self.StartPoint[0] = self.Points[0] |
|
1318 |
self.EndPoint[0] = self.Points[-1] |
|
1319 |
self.GeneratePoints(False) |
|
1320 |
||
1321 |
# Moves the wire start point and update the wire points |
|
1322 |
def MoveStartPoint(self, point): |
|
1323 |
if len(self.Points) > 1: |
|
1324 |
self.StartPoint[0] = point |
|
1325 |
self.Points[0] = point |
|
1326 |
self.GeneratePoints() |
|
1327 |
||
1328 |
# Changes the wire start direction and update the wire points |
|
1329 |
def SetStartPointDirection(self, dir): |
|
1330 |
if len(self.Points) > 1: |
|
1331 |
self.StartPoint[1] = dir |
|
1332 |
self.Segments[0] = dir |
|
1333 |
self.GeneratePoints() |
|
1334 |
||
1335 |
# Rotates the wire start direction by an angle of 90 degrees anticlockwise |
|
1336 |
def RotateStartPoint(self): |
|
1337 |
self.SetStartPointDirection((self.StartPoint[1][1], -self.StartPoint[1][0])) |
|
1338 |
||
1339 |
# Connects wire start point to the connector given and moves wire start point |
|
1340 |
# to given point |
|
1341 |
def ConnectStartPoint(self, point, connector): |
|
1342 |
if point: |
|
1343 |
self.MoveStartPoint(point) |
|
1344 |
self.StartConnected = connector |
|
1345 |
||
1346 |
# Unconnects wire start point |
|
2 | 1347 |
def UnConnectStartPoint(self, delete = False): |
0 | 1348 |
self.StartConnected.UnConnect(self, False) |
2 | 1349 |
if delete: |
1350 |
self.Delete() |
|
1351 |
else: |
|
1352 |
self.StartConnected = None |
|
0 | 1353 |
|
1354 |
# Moves the wire end point and update the wire points |
|
1355 |
def MoveEndPoint(self, point): |
|
1356 |
if len(self.Points) > 1: |
|
1357 |
self.EndPoint[0] = point |
|
1358 |
self.Points[-1] = point |
|
1359 |
self.GeneratePoints() |
|
1360 |
||
1361 |
# Changes the wire end direction and update the wire points |
|
1362 |
def SetEndPointDirection(self, dir): |
|
1363 |
if len(self.Points) > 1: |
|
1364 |
self.EndPoint[1] = dir |
|
1365 |
self.GeneratePoints() |
|
1366 |
||
1367 |
# Rotates the wire end direction by an angle of 90 degrees anticlockwise |
|
1368 |
def RotateEndPoint(self): |
|
1369 |
self.SetEndPointDirection((self.EndPoint[1][1], -self.EndPoint[1][0])) |
|
1370 |
||
1371 |
# Connects wire end point to the connector given and moves wire end point |
|
1372 |
# to given point |
|
1373 |
def ConnectEndPoint(self, point, connector): |
|
1374 |
if point: |
|
1375 |
self.MoveEndPoint(point) |
|
1376 |
self.EndConnected = connector |
|
1377 |
||
1378 |
# Unconnects wire end point |
|
2 | 1379 |
def UnConnectEndPoint(self, delete = False): |
0 | 1380 |
self.EndConnected.UnConnect(self, False) |
2 | 1381 |
if delete: |
1382 |
self.Delete() |
|
1383 |
else: |
|
1384 |
self.EndConnected = None |
|
0 | 1385 |
|
1386 |
# Moves the wire segment given by its index |
|
1387 |
def MoveSegment(self, idx, movex, movey): |
|
1388 |
if 0 < idx < len(self.Segments) - 1: |
|
1389 |
if self.Segments[idx] in (NORTH, SOUTH): |
|
1390 |
self.Points[idx].x += movex |
|
1391 |
self.Points[idx + 1].x += movex |
|
1392 |
elif self.Segments[idx] in (EAST, WEST): |
|
1393 |
self.Points[idx].y += movey |
|
1394 |
self.Points[idx + 1].y += movey |
|
1395 |
self.GeneratePoints() |
|
1396 |
||
1397 |
# Adds two points in the middle of the handled segment |
|
1398 |
def AddSegment(self): |
|
1399 |
handle_type, handle = self.Handle |
|
1400 |
if handle_type == HANDLE_SEGMENT: |
|
1401 |
segment, dir = handle |
|
1402 |
pointx = self.Points[segment].x |
|
1403 |
pointy = self.Points[segment].y |
|
1404 |
if dir[0] != 0: |
|
1405 |
pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2 |
|
1406 |
if dir[1] != 0: |
|
1407 |
pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2 |
|
1408 |
self.Points.insert(segment + 1, wxPoint(pointx, pointy)) |
|
1409 |
self.Segments.insert(segment + 1, (dir[1], dir[0])) |
|
1410 |
self.Points.insert(segment + 2, wxPoint(pointx, pointy)) |
|
1411 |
self.Segments.insert(segment + 2, dir) |
|
1412 |
self.GeneratePoints() |
|
1413 |
||
1414 |
# Delete the handled segment by removing the two segment points |
|
1415 |
def DeleteSegment(self): |
|
1416 |
handle_type, handle = self.Handle |
|
1417 |
if handle_type == HANDLE_SEGMENT: |
|
1418 |
segment, dir = handle |
|
1419 |
for i in xrange(2): |
|
1420 |
self.Points.pop(segment) |
|
1421 |
self.Segments.pop(segment) |
|
1422 |
self.GeneratePoints() |
|
1423 |
self.RefreshModel() |
|
1424 |
||
1425 |
# Method called when a LeftDown event have been generated |
|
1426 |
def OnLeftDown(self, event, scaling): |
|
1427 |
pos = GetScaledEventPosition(event, scaling) |
|
1428 |
# Test if a point have been handled |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1429 |
#result = self.TestPoint(pos) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1430 |
#if result != None: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1431 |
# self.Handle = (HANDLE_POINT, result) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1432 |
# self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND)) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1433 |
#else: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1434 |
# Test if a segment have been handled |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1435 |
result = self.TestSegment(pos) |
0 | 1436 |
if result != None: |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1437 |
if result[1] in (NORTH, SOUTH): |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1438 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZEWE)) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1439 |
elif result[1] in (EAST, WEST): |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1440 |
self.Parent.SetCursor(wxStockCursor(wxCURSOR_SIZENS)) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1441 |
self.Handle = (HANDLE_SEGMENT, result) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1442 |
# Execute the default method for a graphic element |
0 | 1443 |
else: |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1444 |
Graphic_Element.OnLeftDown(self, event, scaling) |
0 | 1445 |
self.oldPos = pos |
1446 |
||
1447 |
# Method called when a RightUp event have been generated |
|
1448 |
def OnRightUp(self, event, scaling): |
|
1449 |
pos = GetScaledEventPosition(event, scaling) |
|
1450 |
# Test if a segment has been handled |
|
1451 |
result = self.TestSegment(pos) |
|
1452 |
if result != None: |
|
1453 |
self.Handle = (HANDLE_SEGMENT, result) |
|
1454 |
# Popup the menu with special items for a wire |
|
1455 |
self.Parent.PopupWireMenu() |
|
1456 |
else: |
|
1457 |
# Execute the default method for a graphic element |
|
1458 |
Graphic_Element.OnRightUp(self, event, scaling) |
|
1459 |
||
1460 |
# Method called when a LeftDClick event have been generated |
|
1461 |
def OnLeftDClick(self, event, scaling): |
|
1462 |
self.ResetPoints() |
|
1463 |
self.GeneratePoints() |
|
1464 |
||
1465 |
# Method called when a Motion event have been generated |
|
1466 |
def OnMotion(self, event, scaling): |
|
1467 |
pos = GetScaledEventPosition(event, scaling) |
|
1468 |
if not event.Dragging(): |
|
1469 |
# Test if a segment has been handled |
|
1470 |
result = self.TestSegment(pos) |
|
1471 |
if result: |
|
1472 |
if result[1] in (NORTH, SOUTH): |
|
1473 |
wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZEWE)) |
|
1474 |
elif result[1] in (EAST, WEST): |
|
1475 |
wxCallAfter(self.Parent.SetCursor, wxStockCursor(wxCURSOR_SIZENS)) |
|
1476 |
else: |
|
1477 |
# Test if a point has been handled |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1478 |
#result = self.TestPoint(pos) |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1479 |
#if result != None: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1480 |
# if result == 0 and self.StartConnected: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1481 |
# self.OverStart = True |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1482 |
# elif result != 0 and self.EndConnected: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1483 |
# self.OverEnd = True |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1484 |
#else: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1485 |
# self.OverStart = False |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1486 |
# self.OverEnd = False |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1487 |
# Execute the default method for a graphic element |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1488 |
Graphic_Element.OnMotion(self, event, scaling) |
0 | 1489 |
else: |
1490 |
# Execute the default method for a graphic element |
|
1491 |
Graphic_Element.OnMotion(self, event, scaling) |
|
1492 |
||
1493 |
# Refreshes the wire state according to move defined and handle selected |
|
1494 |
def ProcessDragging(self, movex, movey): |
|
1495 |
handle_type, handle = self.Handle |
|
1496 |
# A point has been handled |
|
1497 |
if handle_type == HANDLE_POINT: |
|
1498 |
# Try to connect point to a connector |
|
1499 |
new_pos = wxPoint(self.Points[handle].x + movex, self.Points[handle].y + movey) |
|
1500 |
connector = self.Parent.FindBlockConnector(new_pos) |
|
1501 |
if connector: |
|
1502 |
if handle == 0 and self.EndConnected != connector: |
|
1503 |
connector.Connect((self, handle)) |
|
1504 |
self.SetStartPointDirection(connector.GetDirection()) |
|
1505 |
self.ConnectStartPoint(connector.GetPosition(), connector) |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1506 |
self.oldPos = connector.GetPosition() |
0 | 1507 |
self.Dragging = False |
1508 |
elif handle != 0 and self.StartConnected != connector: |
|
1509 |
connector.Connect((self, handle)) |
|
1510 |
self.SetEndPointDirection(connector.GetDirection()) |
|
1511 |
self.ConnectEndPoint(connector.GetPosition(), connector) |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1512 |
self.oldPos = connector.GetPosition() |
0 | 1513 |
self.Dragging = False |
1514 |
elif handle == 0: |
|
1515 |
self.MoveStartPoint(new_pos) |
|
1516 |
else: |
|
1517 |
self.MoveEndPoint(new_pos) |
|
1518 |
# If there is no connector, move the point |
|
1519 |
elif handle == 0: |
|
1520 |
if self.StartConnected: |
|
1521 |
self.UnConnectStartPoint() |
|
1522 |
self.MoveStartPoint(new_pos) |
|
1523 |
else: |
|
1524 |
if self.EndConnected: |
|
1525 |
self.UnConnectEndPoint() |
|
1526 |
self.MoveEndPoint(new_pos) |
|
1527 |
self.RefreshModel() |
|
1528 |
# A segment has been handled, move a segment |
|
1529 |
elif handle_type == HANDLE_SEGMENT: |
|
1530 |
self.MoveSegment(handle[0], movex, movey) |
|
1531 |
# Execute the default method for a graphic element |
|
1532 |
else: |
|
1533 |
Graphic_Element.ProcessDragging(self, movex, movey) |
|
1534 |
||
1535 |
# Refreshes the wire model |
|
1536 |
def RefreshModel(self, move=True): |
|
1537 |
if self.StartConnected and self.StartPoint[1] in [WEST, NORTH]: |
|
1538 |
self.StartConnected.RefreshParentBlock() |
|
1539 |
if self.EndConnected and self.EndPoint[1] in [WEST, NORTH]: |
|
1540 |
self.EndConnected.RefreshParentBlock() |
|
1541 |
||
1542 |
# Draws the wire lines and points |
|
1543 |
def Draw(self, dc): |
|
1544 |
dc.SetPen(wxBLACK_PEN) |
|
1545 |
dc.SetBrush(wxBLACK_BRUSH) |
|
1546 |
# Draw the start and end points if they are not connected or the mouse is over them |
|
1547 |
if len(self.Points) > 0 and (not self.StartConnected or self.OverStart): |
|
1548 |
dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS) |
|
1549 |
if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd): |
|
1550 |
dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS) |
|
1551 |
# Draw the wire lines and the last point (it seems that DrawLines stop before the last point) |
|
1552 |
dc.DrawLines(self.Points) |
|
1553 |
dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
|
1554 |
# Draw the segment selected in red |
|
1555 |
if self.SelectedSegment != None: |
|
1556 |
dc.SetPen(wxRED_PEN) |
|
1557 |
dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y, |
|
1558 |
self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y) |
|
1559 |
if self.SelectedSegment == len(self.Segments) - 1: |
|
1560 |
dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
|
1561 |
Graphic_Element.Draw(self, dc) |
|
1562 |
||
1563 |
||
1564 |
#------------------------------------------------------------------------------- |
|
1565 |
# Graphic comment element |
|
1566 |
#------------------------------------------------------------------------------- |
|
1567 |
||
1568 |
""" |
|
1569 |
Class that implements a comment |
|
1570 |
""" |
|
1571 |
||
1572 |
class Comment(Graphic_Element): |
|
1573 |
||
1574 |
# Create a new comment |
|
1575 |
def __init__(self, parent, content, id = None): |
|
1576 |
Graphic_Element.__init__(self, parent) |
|
1577 |
self.Id = id |
|
1578 |
self.Content = content |
|
1579 |
self.Pos = wxPoint(0, 0) |
|
1580 |
self.Size = wxSize(0, 0) |
|
1581 |
||
1582 |
# Method for keeping compatibility with others |
|
1583 |
def Clean(self): |
|
1584 |
pass |
|
1585 |
||
1586 |
# Delete this comment by calling the corresponding method |
|
1587 |
def Delete(self): |
|
1588 |
self.Parent.DeleteComment(self) |
|
1589 |
||
1590 |
# Refresh the comment bounding box |
|
1591 |
def RefreshBoundingBox(self): |
|
1592 |
self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
1593 |
||
1594 |
# Changes the comment size |
|
1595 |
def SetSize(self, width, height): |
|
1596 |
self.Size.SetWidth(width) |
|
1597 |
self.Size.SetHeight(height) |
|
1598 |
self.RefreshBoundingBox() |
|
1599 |
||
1600 |
# Returns the comment size |
|
1601 |
def GetSize(self): |
|
1602 |
return self.Size.GetWidth(), self.Size.GetHeight() |
|
1603 |
||
1604 |
# Returns the comment minimum size |
|
1605 |
def GetMinSize(self): |
|
1606 |
dc = wxClientDC(self.Parent) |
|
1607 |
min_width = 0 |
|
1608 |
min_height = 0 |
|
1609 |
# The comment minimum size is the maximum size of words in the content |
|
1610 |
for line in self.Content.splitlines(): |
|
1611 |
for word in line.split(" "): |
|
1612 |
wordwidth, wordheight = dc.GetTextExtent(word) |
|
1613 |
min_width = max(min_width, wordwidth) |
|
1614 |
min_height = max(min_height, wordheight) |
|
1615 |
return min_width + 20, min_height + 20 |
|
1616 |
||
1617 |
# Changes the comment position |
|
1618 |
def SetPosition(self, x, y): |
|
1619 |
self.Pos.x = x |
|
1620 |
self.Pos.y = y |
|
1621 |
self.RefreshBoundingBox() |
|
1622 |
||
1623 |
# Changes the comment content |
|
1624 |
def SetContent(self, content): |
|
1625 |
self.Content = content |
|
1626 |
min_width, min_height = self.GetMinSize() |
|
1627 |
self.Size[0] = max(self.Size[0], min_width) |
|
1628 |
self.Size[1] = max(self.Size[1], min_height) |
|
1629 |
self.RefreshBoundingBox() |
|
1630 |
||
1631 |
# Returns the comment content |
|
1632 |
def GetContent(self): |
|
1633 |
return self.Content |
|
1634 |
||
1635 |
# Returns the comment position |
|
1636 |
def GetPosition(self): |
|
1637 |
return self.Pos.x, self.Pos.y |
|
1638 |
||
1639 |
# Moves the comment |
|
1640 |
def Move(self, dx, dy, connected = True): |
|
1641 |
self.Pos.x += dx |
|
1642 |
self.Pos.y += dy |
|
1643 |
self.RefreshBoundingBox() |
|
1644 |
||
1645 |
# Resizes the comment with the position and the size given |
|
1646 |
def Resize(self, x, y, width, height): |
|
1647 |
self.Move(x, y) |
|
1648 |
self.SetSize(width, height) |
|
1649 |
||
1650 |
# Method called when a RightUp event have been generated |
|
1651 |
def OnRightUp(self, event, scaling): |
|
1652 |
# Popup the default menu |
|
1653 |
self.Parent.PopupDefaultMenu() |
|
1654 |
||
1655 |
# Refreshes the comment model |
|
1656 |
def RefreshModel(self, move=True): |
|
1657 |
self.Parent.RefreshCommentModel(self) |
|
1658 |
||
1659 |
# Method called when a LeftDClick event have been generated |
|
1660 |
def OnLeftDClick(self, event, scaling): |
|
1661 |
# Edit the comment content |
|
1662 |
self.Parent.EditCommentContent(self) |
|
1663 |
||
1664 |
# Draws the comment and its content |
|
1665 |
def Draw(self, dc): |
|
1666 |
dc.SetPen(wxBLACK_PEN) |
|
1667 |
dc.SetBrush(wxWHITE_BRUSH) |
|
1668 |
# Draws the comment shape |
|
1669 |
polygon = [wxPoint(self.Pos.x, self.Pos.y), |
|
1670 |
wxPoint(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
|
1671 |
wxPoint(self.Pos.x + self.Size[0], self.Pos.y + 10), |
|
1672 |
wxPoint(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] + 1), |
|
1673 |
wxPoint(self.Pos.x, self.Pos.y + self.Size[1] + 1)] |
|
1674 |
dc.DrawPolygon(polygon) |
|
1675 |
lines = [wxPoint(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
|
1676 |
wxPoint(self.Pos.x + self.Size[0] - 10, self.Pos.y + 10), |
|
1677 |
wxPoint(self.Pos.x + self.Size[0], self.Pos.y + 10)] |
|
1678 |
dc.DrawLines(lines) |
|
1679 |
# Draws the comment content |
|
1680 |
y = self.Pos.y + 10 |
|
1681 |
for line in self.Content.splitlines(): |
|
1682 |
first = True |
|
1683 |
words = line.split(" ") |
|
1684 |
for i, word in enumerate(words): |
|
1685 |
if first: |
|
1686 |
test = word |
|
1687 |
else: |
|
1688 |
test = linetext + " " + word |
|
1689 |
wordwidth, wordheight = dc.GetTextExtent(test) |
|
1690 |
if y + wordheight > self.Pos.y + self.Size[1] - 10: |
|
1691 |
break |
|
1692 |
if wordwidth < self.Size[0] - 20 and i < len(words) - 1: |
|
1693 |
linetext = test |
|
1694 |
first = False |
|
1695 |
else: |
|
1696 |
if wordwidth < self.Size[0] - 20 and i == len(words) - 1: |
|
1697 |
dc.DrawText(test, self.Pos.x + 10, y) |
|
1698 |
else: |
|
1699 |
dc.DrawText(linetext, self.Pos.x + 10, y) |
|
1700 |
if i == len(words) - 1: |
|
1701 |
y += wordheight + 5 |
|
1702 |
if y + wordheight > self.Pos.y + self.Size[1] - 10: |
|
1703 |
break |
|
1704 |
dc.DrawText(word, self.Pos.x + 10, y) |
|
1705 |
else: |
|
1706 |
linetext = word |
|
1707 |
y += wordheight + 5 |
|
1708 |
if y + wordheight > self.Pos.y + self.Size[1] - 10: |
|
1709 |
break |
|
1710 |
Graphic_Element.Draw(self, dc) |