author | b.taylor@willowglen.ca |
Thu, 17 Sep 2009 14:17:52 -0600 | |
changeset 427 | 22d16c457d87 |
parent 399 | 3b9e0b092298 |
child 407 | 0a324a874981 |
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 |
|
367 | 26 |
from time import time as gettime |
0 | 27 |
from math import * |
249 | 28 |
from types import * |
0 | 29 |
|
30 |
#------------------------------------------------------------------------------- |
|
31 |
# Common constants |
|
32 |
#------------------------------------------------------------------------------- |
|
33 |
||
34 |
""" |
|
35 |
Definition of constants for dimensions of graphic elements |
|
36 |
""" |
|
37 |
||
38 |
# FBD and SFC constants |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
39 |
MIN_MOVE = 5 # Minimum move before starting a element dragging |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
40 |
CONNECTOR_SIZE = 8 # Size of connectors |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
41 |
BLOCK_LINE_SIZE = 20 # Minimum size of each line in a block |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
42 |
HANDLE_SIZE = 6 # Size of the squares for handles |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
43 |
ANCHOR_DISTANCE = 5 # Distance where wire is automativally attached to a connector |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
44 |
POINT_RADIUS = 2 # Radius of the point of wire ends |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
45 |
MIN_SEGMENT_SIZE = 2 # Minimum size of the endling segments of a wire |
0 | 46 |
|
47 |
# LD constants |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
48 |
LD_LINE_SIZE = 40 # Distance between two lines in a ladder rung |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
49 |
LD_ELEMENT_SIZE = (21, 15) # Size (width, height) of a ladder element (contact or coil) |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
50 |
LD_WIRE_SIZE = 30 # Size of a wire between two contact |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
51 |
LD_WIRECOIL_SIZE = 70 # Size of a wire between a coil and a contact |
144 | 52 |
LD_POWERRAIL_WIDTH = 3 # Width of a Powerrail |
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
53 |
LD_OFFSET = (10, 10) # Distance (x, y) between each comment and rung of the ladder |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
54 |
LD_COMMENT_DEFAULTSIZE = (600, 40) # Size (width, height) of a comment box |
0 | 55 |
|
56 |
# SFC constants |
|
28
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
57 |
SFC_STEP_DEFAULT_SIZE = (40, 30) # Default size of a SFC step |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
58 |
SFC_TRANSITION_SIZE = (20, 2) # Size of a SFC transition |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
59 |
SFC_DEFAULT_SEQUENCE_INTERVAL = 40 # Default size of the interval between two divergence branches |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
60 |
SFC_SIMULTANEOUS_SEQUENCE_EXTRA = 20 # Size of extra lines for simultaneous divergence and convergence |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
61 |
SFC_JUMP_SIZE = (12, 13) # Size of a SFC jump to step |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
62 |
SFC_WIRE_MIN_SIZE = 25 # Size of a wire between two elements |
fc23e1f415d8
Adding support for concurrent overriden standard function
lbessard
parents:
27
diff
changeset
|
63 |
SFC_ACTION_MIN_SIZE = (100, 30) # Minimum size of an action block line |
0 | 64 |
|
65 |
# Type definition constants for graphic elements |
|
66 |
[INPUT, OUTPUT, INOUT] = range(3) |
|
67 |
[CONNECTOR, CONTINUATION] = range(2) |
|
68 |
[LEFTRAIL, RIGHTRAIL] = range(2) |
|
69 |
[CONTACT_NORMAL, CONTACT_REVERSE, CONTACT_RISING, CONTACT_FALLING] = range(4) |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
265
diff
changeset
|
70 |
[COIL_NORMAL, COIL_REVERSE, COIL_SET, COIL_RESET, COIL_RISING, COIL_FALLING] = range(6) |
0 | 71 |
[SELECTION_DIVERGENCE, SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE] = range(4) |
72 |
||
73 |
# Constants for defining the type of dragging that has been selected |
|
74 |
[HANDLE_MOVE, HANDLE_RESIZE, HANDLE_POINT, HANDLE_SEGMENT, HANDLE_CONNECTOR] = range(5) |
|
75 |
||
76 |
# List of value for resize handle that are valid |
|
77 |
VALID_HANDLES = [(1,1), (1,2), (1,3), (2,3), (3,3), (3,2), (3,1), (2,1)] |
|
78 |
||
79 |
# Contants for defining the direction of a connector |
|
80 |
[EAST, NORTH, WEST, SOUTH] = [(1,0), (0,-1), (-1,0), (0,1)] |
|
81 |
||
82 |
# Contants for defining which mode is selected for each view |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
83 |
[MODE_SELECTION, MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
84 |
MODE_COIL, MODE_CONTACT, MODE_POWERRAIL, MODE_INITIALSTEP, MODE_STEP, |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
85 |
MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION] = range(14) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
86 |
|
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
87 |
# Contants for defining alignment types for graphic group |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
88 |
[ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM] = range(6) |
27 | 89 |
|
90 |
# Contants for defining which drawing mode is selected for app |
|
91 |
[FREEDRAWING_MODE, DRIVENDRAWING_MODE] = [1, 2] |
|
92 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
93 |
# Color for Highlighting |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
94 |
HIGHLIGHTCOLOR = wx.CYAN |
58 | 95 |
|
96 |
HANDLE_CURSORS = { |
|
97 |
(1, 1) : 2, |
|
98 |
(3, 3) : 2, |
|
99 |
(1, 3) : 3, |
|
100 |
(3, 1) : 3, |
|
101 |
(1, 2) : 4, |
|
102 |
(3, 2) : 4, |
|
103 |
(2, 1) : 5, |
|
104 |
(2, 3) : 5 |
|
105 |
} |
|
0 | 106 |
|
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
107 |
def round_scaling(x, n, constraint=0): |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
108 |
fraction = float(x) / float(n) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
109 |
if constraint == - 1: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
110 |
xround = int(fraction) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
111 |
else: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
112 |
xround = round(fraction) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
113 |
if constraint == 1 and int(fraction) == xround: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
114 |
xround += 1 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
115 |
return xround * n |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
116 |
|
0 | 117 |
""" |
118 |
Basic vector operations for calculate wire points |
|
119 |
""" |
|
120 |
||
121 |
# Create a vector from two points and define if vector must be normal |
|
122 |
def vector(p1, p2, normal = True): |
|
123 |
vector = (p2.x - p1.x, p2.y - p1.y) |
|
124 |
if normal: |
|
125 |
return normalize(vector) |
|
126 |
return vector |
|
127 |
||
128 |
# Calculate the norm of a given vector |
|
129 |
def norm(v): |
|
130 |
return sqrt(v[0] * v[0] + v[1] * v[1]) |
|
131 |
||
132 |
# Normalize a given vector |
|
133 |
def normalize(v): |
|
134 |
v_norm = norm(v) |
|
135 |
# Verifie if it is not a null vector |
|
136 |
if v_norm > 0: |
|
137 |
return (v[0] / v_norm, v[1] / v_norm) |
|
138 |
else: |
|
139 |
return v |
|
140 |
||
296 | 141 |
# Calculate the scalar product of two vectors |
142 |
def is_null_vector(v): |
|
143 |
return v == (0, 0) |
|
144 |
||
145 |
# Calculate the scalar product of two vectors |
|
146 |
def add_vectors(v1, v2): |
|
147 |
return (v1[0] + v2[0], v1[1] + v2[1]) |
|
148 |
||
149 |
# Calculate the scalar product of two vectors |
|
150 |
def product(v1, v2): |
|
151 |
return v1[0] * v2[0] + v1[1] * v2[1] |
|
152 |
||
0 | 153 |
|
154 |
""" |
|
155 |
Function that calculates the nearest point of the grid defined by scaling for the given point |
|
156 |
""" |
|
157 |
||
27 | 158 |
def GetScaledEventPosition(event, dc, scaling): |
159 |
pos = event.GetLogicalPosition(dc) |
|
0 | 160 |
if scaling: |
161 |
pos.x = round(float(pos.x) / float(scaling[0])) * scaling[0] |
|
162 |
pos.y = round(float(pos.y) / float(scaling[1])) * scaling[1] |
|
163 |
return pos |
|
164 |
||
165 |
||
166 |
""" |
|
167 |
Function that choose a direction during the wire points generation |
|
168 |
""" |
|
169 |
||
170 |
def DirectionChoice(v_base, v_target, dir_target): |
|
171 |
dir_product = product(v_base, v_target) |
|
172 |
if dir_product < 0: |
|
173 |
return (-v_base[0], -v_base[1]) |
|
174 |
elif dir_product == 0 and product(v_base, dir_target) != 0: |
|
175 |
return dir_target |
|
176 |
return v_base |
|
177 |
||
178 |
||
179 |
#------------------------------------------------------------------------------- |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
180 |
# Debug Data Consumer Class |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
181 |
#------------------------------------------------------------------------------- |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
182 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
183 |
class DebugDataConsumer: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
184 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
185 |
def __init__(self): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
186 |
self.LastValue = None |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
187 |
self.Value = None |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
188 |
self.Inhibited = False |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
189 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
190 |
def Inhibit(self, inhibit): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
191 |
self.Inhibited = inhibit |
372 | 192 |
if not inhibit and self.LastValue is not None: |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
193 |
self.SetValue(self.LastValue) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
194 |
self.LastValue = None |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
195 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
196 |
def NewValue(self, tick, value): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
197 |
if self.Inhibited: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
198 |
self.LastValue = value |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
199 |
else: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
200 |
self.SetValue(value) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
201 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
202 |
def SetValue(self, value): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
203 |
self.Value = value |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
204 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
205 |
#------------------------------------------------------------------------------- |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
206 |
# Debug Viewer Class |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
207 |
#------------------------------------------------------------------------------- |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
208 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
209 |
REFRESH_PERIOD = 0.1 |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
210 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
211 |
class DebugViewer: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
212 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
213 |
def __init__(self, producer, debug, register_tick=True): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
214 |
self.DataProducer = producer |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
215 |
self.Debug = debug |
372 | 216 |
self.Inhibited = False |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
217 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
218 |
self.DataConsumers = {} |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
219 |
|
367 | 220 |
self.LastRefreshTime = gettime() |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
221 |
|
372 | 222 |
self.RefreshTimer = wx.Timer(self, -1) |
223 |
self.Bind(wx.EVT_TIMER, self.OnRefreshTimer, self.RefreshTimer) |
|
224 |
||
364 | 225 |
if register_tick and debug: |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
226 |
self.DataProducer.SubscribeDebugIECVariable("__tick__", self) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
227 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
228 |
def __del__(self): |
364 | 229 |
if self.Debug: |
230 |
self.DataProducer.UnsubscribeDebugIECVariable("__tick__", self) |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
231 |
self.DeleteDataConsumers() |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
232 |
self.RefreshTimer.Stop() |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
233 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
234 |
def Inhibit(self, inhibit): |
372 | 235 |
self.Inhibited = inhibit |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
236 |
for consumer, iec_path in self.DataConsumers.iteritems(): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
237 |
consumer.Inhibit(inhibit) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
238 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
239 |
def AddDataConsumer(self, iec_path, consumer): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
240 |
result = self.DataProducer.SubscribeDebugIECVariable(iec_path, consumer) is not None |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
241 |
if result is not None and consumer != self: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
242 |
self.DataConsumers[consumer] = iec_path |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
243 |
return result |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
244 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
245 |
def RemoveDataConsumer(self, consumer): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
246 |
iec_path = self.DataConsumers.pop(consumer, None) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
247 |
if iec_path is not None: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
248 |
self.DataProducer.UnsubscribeDebugIECVariable(iec_path, consumer) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
249 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
250 |
def DeleteDataConsumers(self): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
251 |
for consumer, iec_path in self.DataConsumers.iteritems(): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
252 |
self.DataProducer.UnsubscribeDebugIECVariable(iec_path, consumer) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
253 |
self.DataConsumers = {} |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
254 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
255 |
def OnRefreshTimer(self, event): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
256 |
self.RefreshNewData() |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
257 |
event.Skip() |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
258 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
259 |
def NewDataAvailable(self): |
372 | 260 |
self.RefreshTimer.Stop() |
261 |
if not self.Inhibited: |
|
262 |
current_time = gettime() |
|
263 |
if current_time - self.LastRefreshTime > REFRESH_PERIOD: |
|
264 |
self.LastRefreshTime = current_time |
|
265 |
self.Inhibit(True) |
|
266 |
wx.CallAfter(self.RefreshViewOnNewData) |
|
267 |
||
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
268 |
def RefreshViewOnNewData(self): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
269 |
if self: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
270 |
self.RefreshNewData() |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
271 |
self.RefreshTimer.Start(int(REFRESH_PERIOD * 1000), oneShot=True) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
272 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
273 |
def RefreshNewData(self): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
274 |
self.Inhibit(False) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
275 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
276 |
#------------------------------------------------------------------------------- |
0 | 277 |
# Viewer Rubberband |
278 |
#------------------------------------------------------------------------------- |
|
279 |
||
280 |
""" |
|
281 |
Class that implements a rubberband |
|
282 |
""" |
|
283 |
||
284 |
class RubberBand: |
|
285 |
||
286 |
# Create a rubberband by indicated on which window it must be drawn |
|
287 |
def __init__(self, drawingSurface): |
|
288 |
self.drawingSurface = drawingSurface |
|
289 |
self.Reset() |
|
290 |
||
291 |
# Method that initializes the internal attributes of the rubberband |
|
292 |
def Reset(self): |
|
293 |
self.startPoint = None |
|
294 |
self.currentBox = None |
|
295 |
self.lastBox = None |
|
296 |
||
297 |
# Method that return if a box is currently edited |
|
298 |
def IsShown(self): |
|
299 |
return self.currentBox != None |
|
300 |
||
301 |
# Method that returns the currently edited box |
|
302 |
def GetCurrentExtent(self): |
|
303 |
return self.currentBox |
|
304 |
||
305 |
# Method called when a new box starts to be edited |
|
27 | 306 |
def OnLeftDown(self, event, dc, scaling): |
307 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 308 |
# Save the point for calculate the box position and size |
309 |
self.startPoint = pos |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
310 |
self.currentBox = wx.Rect(pos.x, pos.y, 0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
311 |
self.drawingSurface.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) |
0 | 312 |
self.Redraw() |
313 |
||
314 |
# Method called when dragging with a box edited |
|
27 | 315 |
def OnMotion(self, event, dc, scaling): |
316 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 317 |
# Save the last position and size of the box for erasing it |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
318 |
self.lastBox = wx.Rect(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
0 | 319 |
self.currentBox.height) |
320 |
# Calculate new position and size of the box |
|
321 |
if pos.x >= self.startPoint.x: |
|
322 |
self.currentBox.x = self.startPoint.x |
|
323 |
self.currentBox.width = pos.x - self.startPoint.x + 1 |
|
324 |
else: |
|
325 |
self.currentBox.x = pos.x |
|
326 |
self.currentBox.width = self.startPoint.x - pos.x + 1 |
|
327 |
if pos.y >= self.startPoint.y: |
|
328 |
self.currentBox.y = self.startPoint.y |
|
329 |
self.currentBox.height = pos.y - self.startPoint.y + 1 |
|
330 |
else: |
|
331 |
self.currentBox.y = pos.y |
|
332 |
self.currentBox.height = self.startPoint.y - pos.y + 1 |
|
333 |
self.Redraw() |
|
334 |
||
335 |
# Method called when dragging is stopped |
|
27 | 336 |
def OnLeftUp(self, event, dc, scaling): |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
337 |
self.drawingSurface.SetCursor(wx.NullCursor) |
0 | 338 |
self.lastBox = self.currentBox |
339 |
self.currentBox = None |
|
340 |
self.Redraw() |
|
341 |
||
342 |
# Method that erase the last box and draw the new box |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
343 |
def Redraw(self, dc = None): |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
344 |
if not dc: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
345 |
dc = self.drawingSurface.GetLogicalDC() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
346 |
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT)) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
347 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
348 |
dc.SetLogicalFunction(wx.XOR) |
0 | 349 |
if self.lastBox: |
350 |
# Erase last box |
|
351 |
dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
|
352 |
self.lastBox.height) |
|
353 |
if self.currentBox: |
|
354 |
# Draw current box |
|
355 |
dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
|
356 |
self.currentBox.height) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
357 |
|
27 | 358 |
# Erase last box |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
359 |
def Erase(self, dc = None): |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
360 |
if not dc: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
361 |
dc = self.drawingSurface.GetLogicalDC() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
362 |
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT)) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
363 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
364 |
dc.SetLogicalFunction(wx.XOR) |
27 | 365 |
if self.lastBox: |
366 |
dc.DrawRectangle(self.lastBox.x, self.lastBox.y, self.lastBox.width, |
|
367 |
self.lastBox.height) |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
368 |
|
27 | 369 |
# Draw current box |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
370 |
def Draw(self, dc = None): |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
371 |
if not dc: |
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
372 |
dc = self.drawingSurface.GetLogicalDC() |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
373 |
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT)) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
374 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
375 |
dc.SetLogicalFunction(wx.XOR) |
27 | 376 |
if self.currentBox: |
377 |
# Draw current box |
|
378 |
dc.DrawRectangle(self.currentBox.x, self.currentBox.y, self.currentBox.width, |
|
379 |
self.currentBox.height) |
|
380 |
||
0 | 381 |
#------------------------------------------------------------------------------- |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
382 |
# Viewer ToolTip |
338 | 383 |
#------------------------------------------------------------------------------- |
384 |
||
385 |
""" |
|
386 |
Class that implements a custom tool tip |
|
387 |
""" |
|
388 |
||
389 |
class ToolTip(wx.PopupWindow): |
|
390 |
||
391 |
# Create a rubberband by indicated on which window it must be drawn |
|
392 |
def __init__(self, parent, tip): |
|
393 |
wx.PopupWindow.__init__(self, parent) |
|
358 | 394 |
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) |
338 | 395 |
self.SetTip(tip) |
396 |
||
397 |
self.Bind(wx.EVT_PAINT, self.OnPaint) |
|
398 |
||
399 |
def SetTip(self, tip): |
|
400 |
self.Tip = tip |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
401 |
wx.CallAfter(self.RefreshTip) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
402 |
|
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
403 |
def RefreshTip(self): |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
404 |
if self: |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
405 |
dc = wx.ClientDC(self) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
406 |
w, h = dc.GetTextExtent(self.Tip) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
407 |
self.SetSize(wx.Size(w + 4, h + 4)) |
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
408 |
self.Refresh() |
338 | 409 |
|
410 |
def OnPaint(self, event): |
|
411 |
dc = wx.AutoBufferedPaintDC(self) |
|
412 |
dc.Clear() |
|
413 |
dc.SetPen(wx.BLACK_PEN) |
|
414 |
dc.SetBrush(wx.Brush(wx.Colour(255, 238, 170))) |
|
415 |
dc.BeginDrawing() |
|
416 |
w, h = dc.GetTextExtent(self.Tip) |
|
417 |
dc.DrawRectangle(0, 0, w + 4, h + 4) |
|
418 |
dc.DrawText(self.Tip, 2, 2) |
|
419 |
dc.EndDrawing() |
|
420 |
event.Skip() |
|
421 |
||
422 |
#------------------------------------------------------------------------------- |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
423 |
# Helper for highlighting error in drawn text |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
424 |
#------------------------------------------------------------------------------- |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
425 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
426 |
def HighlightErrorZone(dc, x, y, width, height): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
427 |
dc.SetPen(wx.TRANSPARENT_PEN) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
428 |
dc.SetLogicalFunction(wx.AND) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
429 |
dc.SetBrush(wx.Brush(wx.Colour(0,255,0))) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
430 |
dc.DrawRectangle(x, y, width, height) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
431 |
dc.SetLogicalFunction(wx.XOR) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
432 |
dc.SetBrush(wx.Brush(wx.Colour(255,0,0))) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
433 |
dc.DrawRectangle(x, y, width, height) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
434 |
dc.SetLogicalFunction(wx.COPY) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
435 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
436 |
#------------------------------------------------------------------------------- |
0 | 437 |
# Graphic element base class |
438 |
#------------------------------------------------------------------------------- |
|
439 |
||
440 |
""" |
|
441 |
Class that implements a generic graphic element |
|
442 |
""" |
|
443 |
||
444 |
class Graphic_Element: |
|
445 |
||
446 |
# Create a new graphic element |
|
447 |
def __init__(self, parent, id = None): |
|
448 |
self.Parent = parent |
|
449 |
self.Id = id |
|
450 |
self.oldPos = None |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
451 |
self.StartPos = None |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
452 |
self.CurrentDrag = None |
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
453 |
self.Handle = (None,None) |
0 | 454 |
self.Dragging = False |
455 |
self.Selected = False |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
456 |
self.Highlighted = False |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
457 |
self.Pos = wx.Point(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
458 |
self.Size = wx.Size(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
459 |
self.BoundingBox = wx.Rect(0, 0, 0, 0) |
249 | 460 |
self.Visible = False |
0 | 461 |
|
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
462 |
def GetDefinition(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
463 |
return [self.Id], [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
464 |
|
249 | 465 |
def TestVisible(self, screen): |
265 | 466 |
self.Visible = self.GetRedrawRect().Intersects(screen) |
249 | 467 |
|
468 |
def IsVisible(self): |
|
469 |
return self.Visible |
|
470 |
||
471 |
def SpreadCurrent(self): |
|
472 |
pass |
|
473 |
||
283 | 474 |
def GetConnectorTranslation(self, element): |
475 |
return {} |
|
476 |
||
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
477 |
def IsOfType(self, type, reference): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
478 |
return self.Parent.IsOfType(type, reference) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
479 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
480 |
def IsEndType(self, type): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
481 |
return self.Parent.IsEndType(type) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
482 |
|
144 | 483 |
def GetDragging(self): |
484 |
return self.Dragging |
|
485 |
||
0 | 486 |
# Make a clone of this element |
162 | 487 |
def Clone(self, parent): |
488 |
return Graphic_Element(parent, self.Id) |
|
0 | 489 |
|
490 |
# Changes the block position |
|
491 |
def SetPosition(self, x, y): |
|
492 |
self.Pos.x = x |
|
493 |
self.Pos.y = y |
|
494 |
self.RefreshConnected() |
|
495 |
self.RefreshBoundingBox() |
|
496 |
||
497 |
# Returns the block position |
|
498 |
def GetPosition(self): |
|
499 |
return self.Pos.x, self.Pos.y |
|
500 |
||
501 |
# Changes the element size |
|
502 |
def SetSize(self, width, height): |
|
503 |
self.Size.SetWidth(width) |
|
504 |
self.Size.SetHeight(height) |
|
505 |
self.RefreshConnectors() |
|
506 |
self.RefreshBoundingBox() |
|
507 |
||
508 |
# Returns the element size |
|
509 |
def GetSize(self): |
|
510 |
return self.Size.GetWidth(), self.Size.GetHeight() |
|
511 |
||
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
512 |
# Returns the minimum element size |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
513 |
def GetMinSize(self): |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
514 |
return 0, 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
515 |
|
0 | 516 |
# Refresh the element Bounding Box |
517 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
518 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]) |
0 | 519 |
|
520 |
# Refresh the element connectors position |
|
521 |
def RefreshConnectors(self): |
|
522 |
pass |
|
523 |
||
524 |
# Refresh the position of wires connected to element inputs and outputs |
|
525 |
def RefreshConnected(self): |
|
526 |
pass |
|
527 |
||
528 |
# Change the parent |
|
529 |
def SetParent(self, parent): |
|
530 |
self.Parent = parent |
|
531 |
||
532 |
# Override this method for defining the method to call for deleting this element |
|
533 |
def Delete(self): |
|
534 |
pass |
|
535 |
||
536 |
# Returns the Id |
|
537 |
def GetId(self): |
|
538 |
return self.Id |
|
539 |
||
540 |
# Returns if the point given is in the bounding box |
|
541 |
def HitTest(self, pt): |
|
542 |
rect = self.BoundingBox |
|
543 |
return rect.InsideXY(pt.x, pt.y) |
|
544 |
||
42 | 545 |
# Returns if the point given is in the bounding box |
546 |
def IsInSelection(self, rect): |
|
547 |
return rect.InsideXY(self.BoundingBox.x, self.BoundingBox.y) and rect.InsideXY(self.BoundingBox.x + self.BoundingBox.width, self.BoundingBox.y + self.BoundingBox.height) |
|
548 |
||
0 | 549 |
# Override this method for refreshing the bounding box |
550 |
def RefreshBoundingBox(self): |
|
551 |
pass |
|
552 |
||
553 |
# Returns the bounding box |
|
554 |
def GetBoundingBox(self): |
|
555 |
return self.BoundingBox |
|
556 |
||
144 | 557 |
# Returns the RedrawRect |
558 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
559 |
rect = wx.Rect() |
|
560 |
rect.x = self.BoundingBox.x - HANDLE_SIZE - 2 - abs(movex) |
|
561 |
rect.y = self.BoundingBox.y - HANDLE_SIZE - 2 - abs(movey) |
|
562 |
rect.width = self.BoundingBox.width + 2 * (HANDLE_SIZE + abs(movex)) + 4 |
|
563 |
rect.height = self.BoundingBox.height + 2 * (HANDLE_SIZE + abs(movey)) + 4 |
|
564 |
return rect |
|
565 |
||
566 |
def Refresh(self, rect = None): |
|
339 | 567 |
if self.Visible: |
568 |
if rect is not None: |
|
569 |
self.Parent.RefreshRect(self.Parent.GetScrolledRect(rect), False) |
|
570 |
else: |
|
571 |
self.Parent.RefreshRect(self.Parent.GetScrolledRect(self.GetRedrawRect()), False) |
|
144 | 572 |
|
0 | 573 |
# Change the variable that indicates if this element is selected |
574 |
def SetSelected(self, selected): |
|
575 |
self.Selected = selected |
|
144 | 576 |
self.Refresh() |
0 | 577 |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
578 |
# Change the variable that indicates if this element is highlighted |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
579 |
def SetHighlighted(self, highlighted): |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
580 |
self.Highlighted = highlighted |
144 | 581 |
self.Refresh() |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
582 |
|
0 | 583 |
# Test if the point is on a handle of this element |
584 |
def TestHandle(self, pt): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
585 |
extern_rect = wx.Rect(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, |
58 | 586 |
self.BoundingBox.width + 2 * HANDLE_SIZE + 4, self.BoundingBox.height + 2 * HANDLE_SIZE + 4) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
587 |
intern_rect = wx.Rect(self.BoundingBox.x - 2, self.BoundingBox.y - 2, |
58 | 588 |
self.BoundingBox.width + 4, self.BoundingBox.height + 4) |
0 | 589 |
# Verify that this element is selected |
58 | 590 |
if self.Selected and extern_rect.InsideXY(pt.x, pt.y) and not intern_rect.InsideXY(pt.x, pt.y): |
0 | 591 |
# Find if point is on a handle horizontally |
592 |
if self.BoundingBox.x - HANDLE_SIZE - 2 <= pt.x < self.BoundingBox.x - 2: |
|
593 |
handle_x = 1 |
|
594 |
elif self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2 <= pt.x < self.BoundingBox.x + (self.BoundingBox.width + HANDLE_SIZE) / 2: |
|
595 |
handle_x = 2 |
|
596 |
elif self.BoundingBox.x + self.BoundingBox.width + 2 <= pt.x < self.BoundingBox.x + self.BoundingBox.width + HANDLE_SIZE + 2: |
|
597 |
handle_x = 3 |
|
598 |
else: |
|
599 |
handle_x = 0 |
|
600 |
# Find if point is on a handle vertically |
|
601 |
if self.BoundingBox.y - HANDLE_SIZE - 2 <= pt.y < self.BoundingBox.y - 2: |
|
602 |
handle_y = 1 |
|
603 |
elif self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2 <= pt.y < self.BoundingBox.y + (self.BoundingBox.height + HANDLE_SIZE) / 2: |
|
604 |
handle_y = 2 |
|
605 |
elif self.BoundingBox.y + self.BoundingBox.height - 2 <= pt.y < self.BoundingBox.y + self.BoundingBox.height + HANDLE_SIZE + 2: |
|
606 |
handle_y = 3 |
|
607 |
else: |
|
608 |
handle_y = 0 |
|
609 |
# Verify that the result is valid |
|
610 |
if (handle_x, handle_y) in VALID_HANDLES: |
|
611 |
return handle_x, handle_y |
|
612 |
return 0, 0 |
|
613 |
||
614 |
# Method called when a LeftDown event have been generated |
|
27 | 615 |
def OnLeftDown(self, event, dc, scaling): |
616 |
pos = event.GetLogicalPosition(dc) |
|
0 | 617 |
# Test if an handle have been clicked |
58 | 618 |
handle = self.TestHandle(pos) |
0 | 619 |
# Find which type of handle have been clicked, |
620 |
# Save a resize event and change the cursor |
|
58 | 621 |
cursor = HANDLE_CURSORS.get(handle, 1) |
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
622 |
wx.CallAfter(self.Parent.SetCurrentCursor, cursor) |
58 | 623 |
if cursor > 1: |
624 |
self.Handle = (HANDLE_RESIZE, handle) |
|
0 | 625 |
else: |
626 |
self.Handle = (HANDLE_MOVE, None) |
|
627 |
self.SetSelected(False) |
|
628 |
# Initializes the last position |
|
27 | 629 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
630 |
self.StartPos = wx.Point(self.Pos.x, self.Pos.y) |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
631 |
self.CurrentDrag = wx.Point(0, 0) |
0 | 632 |
|
633 |
# Method called when a LeftUp event have been generated |
|
27 | 634 |
def OnLeftUp(self, event, dc, scaling): |
0 | 635 |
# If a dragging have been initiated |
636 |
if self.Dragging and self.oldPos: |
|
637 |
self.RefreshModel() |
|
56
7187e1c00975
Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents:
42
diff
changeset
|
638 |
self.Parent.RefreshBuffer() |
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
639 |
wx.CallAfter(self.Parent.SetCurrentCursor, 0) |
0 | 640 |
self.SetSelected(True) |
641 |
self.oldPos = None |
|
642 |
||
145 | 643 |
# Method called when a RightDown event have been generated |
644 |
def OnRightDown(self, event, dc, scaling): |
|
645 |
pass |
|
646 |
||
0 | 647 |
# Method called when a RightUp event have been generated |
27 | 648 |
def OnRightUp(self, event, dc, scaling): |
145 | 649 |
if self.Dragging and self.oldPos: |
650 |
self.RefreshModel() |
|
651 |
self.Parent.RefreshBuffer() |
|
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
652 |
wx.CallAfter(self.Parent.SetCurrentCursor, 0) |
0 | 653 |
self.SetSelected(True) |
654 |
self.oldPos = None |
|
655 |
||
656 |
# Method called when a LeftDClick event have been generated |
|
27 | 657 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 658 |
pass |
659 |
||
660 |
# Method called when a Motion event have been generated |
|
27 | 661 |
def OnMotion(self, event, dc, scaling): |
0 | 662 |
# If the cursor is dragging and the element have been clicked |
663 |
if event.Dragging() and self.oldPos: |
|
664 |
# Calculate the movement of cursor |
|
145 | 665 |
pos = event.GetLogicalPosition(dc) |
0 | 666 |
movex = pos.x - self.oldPos.x |
667 |
movey = pos.y - self.oldPos.y |
|
668 |
# If movement is greater than MIN_MOVE then a dragging is initiated |
|
669 |
if not self.Dragging and (abs(movex) > MIN_MOVE or abs(movey) > MIN_MOVE): |
|
670 |
self.Dragging = True |
|
671 |
# If a dragging have been initiated, refreshes the element state |
|
672 |
if self.Dragging: |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
673 |
dragx, dragy = self.ProcessDragging(movex, movey, event, scaling) |
329
1cf72cb51dc9
Adding support for contraining move to only one direction when control down
lbessard
parents:
328
diff
changeset
|
674 |
if event.ControlDown() and self.Handle[0] == HANDLE_MOVE: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
675 |
self.oldPos.x = self.StartPos.x + self.CurrentDrag.x |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
676 |
self.oldPos.y = self.StartPos.y + self.CurrentDrag.y |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
677 |
else: |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
678 |
self.oldPos.x += dragx |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
679 |
self.oldPos.y += dragy |
144 | 680 |
return dragx, dragy |
681 |
return movex, movey |
|
0 | 682 |
# If cursor just pass over the element, changes the cursor if it is on a handle |
683 |
else: |
|
27 | 684 |
pos = event.GetLogicalPosition(dc) |
0 | 685 |
handle = self.TestHandle(pos) |
58 | 686 |
# Find which type of handle have been clicked, |
687 |
# Save a resize event and change the cursor |
|
688 |
cursor = HANDLE_CURSORS.get(handle, 0) |
|
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
689 |
wx.CallAfter(self.Parent.SetCurrentCursor, cursor) |
144 | 690 |
return 0, 0 |
58 | 691 |
|
0 | 692 |
# Moves the element |
693 |
def Move(self, dx, dy, exclude = []): |
|
694 |
self.Pos.x += dx |
|
695 |
self.Pos.y += dy |
|
696 |
self.RefreshConnected(exclude) |
|
697 |
self.RefreshBoundingBox() |
|
698 |
||
699 |
# Resizes the element from position and size given |
|
700 |
def Resize(self, x, y, width, height): |
|
701 |
self.Move(x, y) |
|
702 |
self.SetSize(width, height) |
|
703 |
||
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
704 |
# Moves and Resizes the element for fitting scaling |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
705 |
def AdjustToScaling(self, scaling): |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
706 |
if scaling is not None: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
707 |
movex = round_scaling(self.Pos.x, scaling[0]) - self.Pos.x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
708 |
movey = round_scaling(self.Pos.y, scaling[1]) - self.Pos.y |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
709 |
min_width, min_height = self.GetMinSize() |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
710 |
width = max(round_scaling(min_width, scaling[0], 1), |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
711 |
round_scaling(self.Size.width, scaling[0])) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
712 |
height = max(round_scaling(min_height, scaling[1], 1), |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
713 |
round_scaling(self.Size.height, scaling[1])) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
714 |
self.Resize(movex, movey, width, height) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
715 |
return movex, movey |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
716 |
return 0, 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
717 |
|
0 | 718 |
# Refreshes the element state according to move defined and handle selected |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
719 |
def ProcessDragging(self, movex, movey, event, scaling, width_fac = 1, height_fac = 1): |
0 | 720 |
handle_type, handle = self.Handle |
721 |
# If it is a resize handle, calculate the values from resizing |
|
722 |
if handle_type == HANDLE_RESIZE: |
|
175 | 723 |
if scaling is not None: |
724 |
scaling = (scaling[0] * width_fac, scaling[1] * height_fac) |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
725 |
x = y = start_x = start_y = 0 |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
726 |
width, height = start_width, start_height = self.GetSize() |
0 | 727 |
if handle[0] == 1: |
145 | 728 |
movex = max(-self.BoundingBox.x, movex) |
729 |
if scaling is not None: |
|
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
730 |
movex = -(round_scaling(width - movex, scaling[0]) - width) |
145 | 731 |
x = movex |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
732 |
if event.ShiftDown(): |
165 | 733 |
width -= 2 * movex |
734 |
else: |
|
735 |
width -= movex |
|
0 | 736 |
elif handle[0] == 3: |
145 | 737 |
if scaling is not None: |
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
738 |
movex = round_scaling(width + movex, scaling[0]) - width |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
739 |
if event.ShiftDown(): |
334
cf0809bc5675
Adding support for preventing expending graphical element to have a negative position
lbessard
parents:
333
diff
changeset
|
740 |
movex = min(self.BoundingBox.x, movex) |
165 | 741 |
x = -movex |
742 |
width += 2 * movex |
|
743 |
else: |
|
744 |
width += movex |
|
0 | 745 |
if handle[1] == 1: |
145 | 746 |
movey = max(-self.BoundingBox.y, movey) |
747 |
if scaling is not None: |
|
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
748 |
movey = -(round_scaling(height - movey, scaling[1]) - height) |
145 | 749 |
y = movey |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
750 |
if event.ShiftDown(): |
165 | 751 |
height -= 2 * movey |
752 |
else: |
|
753 |
height -= movey |
|
0 | 754 |
elif handle[1] == 3: |
145 | 755 |
if scaling is not None: |
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
756 |
movey = round_scaling(height + movey, scaling[1]) - height |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
757 |
if event.ShiftDown(): |
334
cf0809bc5675
Adding support for preventing expending graphical element to have a negative position
lbessard
parents:
333
diff
changeset
|
758 |
movey = min(self.BoundingBox.y, movey) |
165 | 759 |
y = -movey |
760 |
height += 2 * movey |
|
761 |
else: |
|
762 |
height += movey |
|
0 | 763 |
# Verify that new size is not lesser than minimum |
764 |
min_width, min_height = self.GetMinSize() |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
765 |
if handle[0] != 2 and (width >= min_width or width > self.Size[0]): |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
766 |
start_x = x |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
767 |
start_width = width |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
768 |
else: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
769 |
movex = 0 |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
770 |
if handle[1] != 2 and (height >= min_height or height > self.Size[1]): |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
771 |
start_y = y |
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
772 |
start_height = height |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
773 |
else: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
774 |
movey = 0 |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
775 |
if movex != 0 or movey != 0: |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
108
diff
changeset
|
776 |
self.Resize(start_x, start_y, start_width, start_height) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
777 |
return movex, movey |
0 | 778 |
# If it is a move handle, Move this element |
779 |
elif handle_type == HANDLE_MOVE: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
780 |
movex = max(-self.BoundingBox.x, movex) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
781 |
movey = max(-self.BoundingBox.y, movey) |
145 | 782 |
if scaling is not None: |
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
783 |
movex = round_scaling(self.Pos.x + movex, scaling[0]) - self.Pos.x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
784 |
movey = round_scaling(self.Pos.y + movey, scaling[1]) - self.Pos.y |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
785 |
if event.ControlDown(): |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
786 |
self.CurrentDrag.x = self.CurrentDrag.x + movex |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
787 |
self.CurrentDrag.y = self.CurrentDrag.y + movey |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
788 |
if abs(self.CurrentDrag.x) > abs(self.CurrentDrag.y): |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
789 |
movex = self.StartPos.x + self.CurrentDrag.x - self.Pos.x |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
790 |
movey = self.StartPos.y - self.Pos.y |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
791 |
else: |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
792 |
movex = self.StartPos.x - self.Pos.x |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
793 |
movey = self.StartPos.y + self.CurrentDrag.y - self.Pos.y |
0 | 794 |
self.Move(movex, movey) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
795 |
return movex, movey |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
796 |
return 0, 0 |
0 | 797 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
798 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
799 |
pass |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
800 |
|
0 | 801 |
# Override this method for defining the method to call for refreshing the model of this element |
802 |
def RefreshModel(self, move=True): |
|
803 |
pass |
|
804 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
805 |
# Draws the highlightment of this element if it is highlighted (can be overwritten) |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
806 |
def DrawHighlightment(self, dc): |
144 | 807 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
808 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
809 |
dc.SetLogicalFunction(wx.AND) |
|
810 |
dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, self.Size.width + 5, self.Size.height + 5) |
|
811 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
812 |
|
0 | 813 |
# Draws the handles of this element if it is selected |
814 |
def Draw(self, dc): |
|
399
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
815 |
if not getattr(dc, "printing", False): |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
816 |
if self.Highlighted: |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
817 |
self.DrawHighlightment(dc) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
818 |
if self.Selected: |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
819 |
dc.SetPen(wx.BLACK_PEN) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
820 |
dc.SetBrush(wx.BLACK_BRUSH) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
821 |
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
822 |
dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
823 |
self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
824 |
dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
825 |
self.BoundingBox.y - HANDLE_SIZE - 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
826 |
dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
827 |
self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
828 |
dc.DrawRectangle(self.BoundingBox.x + self.BoundingBox.width + 2, |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
829 |
self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
830 |
dc.DrawRectangle(self.BoundingBox.x + (self.BoundingBox.width - HANDLE_SIZE) / 2, |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
831 |
self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
832 |
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + self.BoundingBox.height + 2, HANDLE_SIZE, HANDLE_SIZE) |
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
833 |
dc.DrawRectangle(self.BoundingBox.x - HANDLE_SIZE - 2, self.BoundingBox.y + (self.BoundingBox.height - HANDLE_SIZE) / 2, HANDLE_SIZE, HANDLE_SIZE) |
0 | 834 |
|
835 |
||
836 |
#------------------------------------------------------------------------------- |
|
837 |
# Group of graphic elements |
|
838 |
#------------------------------------------------------------------------------- |
|
839 |
||
840 |
""" |
|
841 |
Class that implements a group of graphic elements |
|
842 |
""" |
|
843 |
||
844 |
class Graphic_Group(Graphic_Element): |
|
845 |
||
846 |
# Create a new group of graphic elements |
|
847 |
def __init__(self, parent): |
|
848 |
Graphic_Element.__init__(self, parent) |
|
849 |
self.Elements = [] |
|
42 | 850 |
self.RefreshWireExclusion() |
0 | 851 |
self.RefreshBoundingBox() |
852 |
||
853 |
# Destructor |
|
854 |
def __del__(self): |
|
855 |
self.Elements = [] |
|
856 |
||
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
857 |
def GetDefinition(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
858 |
blocks = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
859 |
wires = [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
860 |
for element in self.Elements: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
861 |
block, wire = element.GetDefinition() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
862 |
blocks.extend(block) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
863 |
wires.extend(wire) |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
864 |
return blocks, wires |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
865 |
|
283 | 866 |
# Make a clone of this element |
867 |
def Clone(self, parent, pos = None): |
|
868 |
group = Graphic_Group(parent) |
|
869 |
connectors = {} |
|
339 | 870 |
exclude_names = {} |
283 | 871 |
wires = [] |
872 |
if pos is not None: |
|
873 |
dx, dy = pos.x - self.BoundingBox.x, pos.y - self.BoundingBox.y |
|
874 |
for element in self.Elements: |
|
875 |
if isinstance(element, Wire): |
|
876 |
wires.append(element) |
|
877 |
else: |
|
878 |
if pos is not None: |
|
879 |
x, y = element.GetPosition() |
|
880 |
new_pos = wx.Point(x + dx, y + dy) |
|
881 |
newid = parent.GetNewId() |
|
882 |
if parent.IsNamedElement(element): |
|
339 | 883 |
name = parent.GenerateNewName(element, exclude_names) |
884 |
exclude_names[name.upper()] = True |
|
283 | 885 |
new_element = element.Clone(parent, newid, name, pos = new_pos) |
886 |
else: |
|
887 |
new_element = element.Clone(parent, newid, pos = new_pos) |
|
339 | 888 |
new_element.AdjustToScaling(parent.Scaling) |
283 | 889 |
else: |
890 |
new_element = element.Clone(parent) |
|
891 |
connectors.update(element.GetConnectorTranslation(new_element)) |
|
892 |
group.SelectElement(new_element) |
|
893 |
for element in wires: |
|
894 |
if pos is not None: |
|
895 |
new_wire = element.Clone(parent, connectors, dx, dy) |
|
896 |
else: |
|
897 |
new_wire = element.Clone(parent, connectors) |
|
898 |
if new_wire is not None: |
|
287 | 899 |
if pos is not None: |
900 |
parent.AddWire(new_wire) |
|
283 | 901 |
group.SelectElement(new_wire) |
902 |
if pos is not None: |
|
903 |
for element in group.Elements: |
|
904 |
if not isinstance(element, Wire): |
|
905 |
parent.AddBlockInModel(element) |
|
906 |
return group |
|
907 |
||
908 |
def CanAddBlocks(self, parent): |
|
909 |
valid = True |
|
910 |
for element in self.Elements: |
|
911 |
if not isinstance(element, Wire): |
|
912 |
valid &= parent.CanAddElement(element) |
|
913 |
return valid |
|
914 |
||
249 | 915 |
def IsVisible(self): |
916 |
for element in self.Elements: |
|
917 |
if element.IsVisible(): |
|
918 |
return True |
|
919 |
return False |
|
920 |
||
42 | 921 |
# Refresh the list of wire excluded |
922 |
def RefreshWireExclusion(self): |
|
923 |
self.WireExcluded = [] |
|
924 |
for element in self.Elements: |
|
925 |
if isinstance(element, Wire): |
|
926 |
startblock = element.StartConnected.GetParentBlock() |
|
927 |
endblock = element.EndConnected.GetParentBlock() |
|
928 |
if startblock in self.Elements and endblock in self.Elements: |
|
929 |
self.WireExcluded.append(element) |
|
930 |
||
144 | 931 |
# Returns the RedrawRect |
932 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
933 |
rect = None |
|
934 |
for element in self.Elements: |
|
935 |
if rect is None: |
|
936 |
rect = element.GetRedrawRect(movex, movey) |
|
937 |
else: |
|
938 |
rect = rect.Union(element.GetRedrawRect(movex, movey)) |
|
939 |
return rect |
|
940 |
||
0 | 941 |
# Clean this group of elements |
942 |
def Clean(self): |
|
943 |
# Clean all the elements of the group |
|
944 |
for element in self.Elements: |
|
945 |
element.Clean() |
|
946 |
||
947 |
# Delete this group of elements |
|
948 |
def Delete(self): |
|
949 |
# Delete all the elements of the group |
|
950 |
for element in self.Elements: |
|
951 |
element.Delete() |
|
42 | 952 |
self.WireExcluded = [] |
0 | 953 |
|
954 |
# Returns if the point given is in the bounding box of one of the elements of this group |
|
955 |
def HitTest(self, pt): |
|
956 |
result = False |
|
957 |
for element in self.Elements: |
|
958 |
result |= element.HitTest(pt) |
|
959 |
return result |
|
960 |
||
961 |
# Returns if the element given is in this group |
|
962 |
def IsElementIn(self, element): |
|
963 |
return element in self.Elements |
|
964 |
||
965 |
# Change the elements of the group |
|
966 |
def SetElements(self, elements): |
|
967 |
self.Elements = elements |
|
42 | 968 |
self.RefreshWireExclusion() |
0 | 969 |
self.RefreshBoundingBox() |
970 |
||
971 |
# Returns the elements of the group |
|
972 |
def GetElements(self): |
|
973 |
return self.Elements |
|
974 |
||
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
975 |
# Align the group elements |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
976 |
def AlignElements(self, horizontally, vertically): |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
977 |
minx = self.BoundingBox.x + self.BoundingBox.width |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
978 |
miny = self.BoundingBox.y + self.BoundingBox.height |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
979 |
maxx = self.BoundingBox.x |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
980 |
maxy = self.BoundingBox.y |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
981 |
for element in self.Elements: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
982 |
if not isinstance(element, Wire): |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
983 |
posx, posy = element.GetPosition() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
984 |
width, height = element.GetSize() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
985 |
minx = min(minx, posx) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
986 |
miny = min(miny, posy) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
987 |
maxx = max(maxx, posx + width) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
988 |
maxy = max(maxy, posy + height) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
989 |
for element in self.Elements: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
990 |
if not isinstance(element, Wire): |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
991 |
posx, posy = element.GetPosition() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
992 |
width, height = element.GetSize() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
993 |
movex = movey = 0 |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
994 |
if horizontally == ALIGN_LEFT: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
995 |
movex = minx - posx |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
996 |
elif horizontally == ALIGN_CENTER: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
997 |
movex = (maxx + minx - width) / 2 - posx |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
998 |
elif horizontally == ALIGN_RIGHT: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
999 |
movex = maxx - width - posx |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1000 |
if vertically == ALIGN_TOP: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1001 |
movey = miny - posy |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1002 |
elif vertically == ALIGN_MIDDLE: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1003 |
movey = (maxy + miny - height) / 2 - posy |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1004 |
elif vertically == ALIGN_BOTTOM: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1005 |
movey = maxy - height - posy |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1006 |
if movex != 0 or movey != 0: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1007 |
element.Move(movex, movey) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1008 |
element.RefreshModel() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1009 |
self.RefreshWireExclusion() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1010 |
self.RefreshBoundingBox() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1011 |
|
0 | 1012 |
# Remove or select the given element if it is or not in the group |
1013 |
def SelectElement(self, element): |
|
1014 |
if element in self.Elements: |
|
1015 |
self.Elements.remove(element) |
|
1016 |
else: |
|
1017 |
self.Elements.append(element) |
|
42 | 1018 |
self.RefreshWireExclusion() |
0 | 1019 |
self.RefreshBoundingBox() |
1020 |
||
1021 |
# Move this group of elements |
|
1022 |
def Move(self, movex, movey): |
|
1023 |
# Move all the elements of the group |
|
1024 |
for element in self.Elements: |
|
42 | 1025 |
if not isinstance(element, Wire): |
1026 |
element.Move(movex, movey, self.WireExcluded) |
|
1027 |
elif element in self.WireExcluded: |
|
0 | 1028 |
element.Move(movex, movey, True) |
1029 |
self.RefreshBoundingBox() |
|
1030 |
||
1031 |
# Refreshes the bounding box of this group of elements |
|
1032 |
def RefreshBoundingBox(self): |
|
1033 |
if len(self.Elements) > 0: |
|
1034 |
bbox = self.Elements[0].GetBoundingBox() |
|
1035 |
minx, miny = bbox.x, bbox.y |
|
1036 |
maxx = bbox.x + bbox.width |
|
1037 |
maxy = bbox.y + bbox.height |
|
1038 |
for element in self.Elements[1:]: |
|
1039 |
bbox = element.GetBoundingBox() |
|
1040 |
minx = min(minx, bbox.x) |
|
1041 |
miny = min(miny, bbox.y) |
|
1042 |
maxx = max(maxx, bbox.x + bbox.width) |
|
1043 |
maxy = max(maxy, bbox.y + bbox.height) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1044 |
self.BoundingBox = wx.Rect(minx, miny, maxx - minx, maxy - miny) |
0 | 1045 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1046 |
self.BoundingBox = wx.Rect(0, 0, 0, 0) |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
1047 |
self.Pos = wx.Point(self.BoundingBox.x, self.BoundingBox.y) |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
1048 |
self.Size = wx.Size(self.BoundingBox.width, self.BoundingBox.height) |
0 | 1049 |
|
1050 |
# Forbids to change the group position |
|
1051 |
def SetPosition(x, y): |
|
1052 |
pass |
|
1053 |
||
1054 |
# Returns the position of this group |
|
1055 |
def GetPosition(self): |
|
1056 |
return self.BoundingBox.x, self.BoundingBox.y |
|
1057 |
||
1058 |
# Forbids to change the group size |
|
1059 |
def SetSize(width, height): |
|
1060 |
pass |
|
1061 |
||
1062 |
# Returns the size of this group |
|
1063 |
def GetSize(self): |
|
1064 |
return self.BoundingBox.width, self.BoundingBox.height |
|
1065 |
||
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1066 |
# Moves and Resizes the group elements for fitting scaling |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1067 |
def AdjustToScaling(self, scaling): |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1068 |
movex_max = movey_max = 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1069 |
for element in self.Elements: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1070 |
movex, movey = element.AdjustToScaling(scaling) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1071 |
movex_max = max(movex_max, abs(movex)) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1072 |
movey_max = max(movey_max, abs(movey)) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1073 |
return movex_max, movey_max |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1074 |
|
339 | 1075 |
# Refreshes the group elements to move defined and handle selected |
1076 |
def ProcessDragging(self, movex, movey, event, scaling): |
|
1077 |
handle_type, handle = self.Handle |
|
1078 |
# If it is a move handle, Move this group elements |
|
1079 |
if handle_type == HANDLE_MOVE: |
|
1080 |
movex = max(-self.BoundingBox.x, movex) |
|
1081 |
movey = max(-self.BoundingBox.y, movey) |
|
1082 |
if scaling is not None: |
|
1083 |
movex = round_scaling(movex, scaling[0]) |
|
1084 |
movey = round_scaling(movey, scaling[1]) |
|
1085 |
if event.ControlDown(): |
|
1086 |
self.CurrentDrag.x = self.CurrentDrag.x + movex |
|
1087 |
self.CurrentDrag.y = self.CurrentDrag.y + movey |
|
1088 |
if abs(self.CurrentDrag.x) > abs(self.CurrentDrag.y): |
|
1089 |
movex = self.StartPos.x + self.CurrentDrag.x - self.Pos.x |
|
1090 |
movey = self.StartPos.y - self.Pos.y |
|
1091 |
else: |
|
1092 |
movex = self.StartPos.x - self.Pos.x |
|
1093 |
movey = self.StartPos.y + self.CurrentDrag.y - self.Pos.y |
|
1094 |
self.Move(movex, movey) |
|
1095 |
return movex, movey |
|
1096 |
return 0, 0 |
|
1097 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1098 |
# Change the variable that indicates if this element is highlighted |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1099 |
def SetHighlighted(self, highlighted): |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1100 |
for element in self.Elements: |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1101 |
element.SetHighlighted(highlighted) |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1102 |
|
339 | 1103 |
# Method called when a LeftDown event have been generated |
1104 |
def OnLeftDown(self, event, dc, scaling): |
|
1105 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
1106 |
for element in self.Elements: |
|
1107 |
element.Handle = self.Handle |
|
1108 |
||
0 | 1109 |
# Change the variable that indicates if the elemente is selected |
1110 |
def SetSelected(self, selected): |
|
1111 |
for element in self.Elements: |
|
1112 |
element.SetSelected(selected) |
|
1113 |
||
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1114 |
# Method called when a RightUp event has been generated |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1115 |
def OnRightUp(self, event, dc, scaling): |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1116 |
# Popup the menu with special items for a group |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1117 |
self.Parent.PopupGroupMenu() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
1118 |
|
0 | 1119 |
# Refreshes the model of all the elements of this group |
1120 |
def RefreshModel(self): |
|
1121 |
for element in self.Elements: |
|
1122 |
element.RefreshModel() |
|
1123 |
||
1124 |
||
1125 |
#------------------------------------------------------------------------------- |
|
1126 |
# Connector for all types of blocks |
|
1127 |
#------------------------------------------------------------------------------- |
|
1128 |
||
1129 |
""" |
|
1130 |
Class that implements a connector for any type of block |
|
1131 |
""" |
|
1132 |
||
1133 |
class Connector: |
|
1134 |
||
1135 |
# Create a new connector |
|
27 | 1136 |
def __init__(self, parent, name, type, position, direction, negated = False, edge = "none", onlyone = False): |
0 | 1137 |
self.ParentBlock = parent |
1138 |
self.Name = name |
|
1139 |
self.Type = type |
|
1140 |
self.Pos = position |
|
1141 |
self.Direction = direction |
|
1142 |
self.Wires = [] |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1143 |
if self.ParentBlock.IsOfType("BOOL", type): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1144 |
self.Negated = negated |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1145 |
self.Edge = edge |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1146 |
else: |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1147 |
self.Negated = False |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1148 |
self.Edge = "none" |
27 | 1149 |
self.OneConnected = onlyone |
249 | 1150 |
self.Valid = True |
1151 |
self.Value = None |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1152 |
self.Pen = wx.BLACK_PEN |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1153 |
self.Errors = {} |
42 | 1154 |
self.RefreshNameSize() |
0 | 1155 |
|
249 | 1156 |
def Flush(self): |
1157 |
self.ParentBlock = None |
|
1158 |
for wire, handle in self.Wires: |
|
1159 |
wire.Flush() |
|
1160 |
self.Wires = [] |
|
1161 |
||
144 | 1162 |
# Returns the RedrawRect |
1163 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
1164 |
parent_pos = self.ParentBlock.GetPosition() |
|
1165 |
x = min(parent_pos[0] + self.Pos.x, parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE) |
|
1166 |
y = min(parent_pos[1] + self.Pos.y, parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE) |
|
1167 |
if self.Direction[0] == 0: |
|
1168 |
width = 5 |
|
1169 |
else: |
|
1170 |
width = CONNECTOR_SIZE |
|
1171 |
if self.Direction[1] == 0: |
|
1172 |
height = 5 |
|
1173 |
else: |
|
1174 |
height = CONNECTOR_SIZE |
|
1175 |
return wx.Rect(x - abs(movex), y - abs(movey), width + 2 * abs(movex), height + 2 * abs(movey)) |
|
1176 |
||
0 | 1177 |
# Change the connector pen |
1178 |
def SetPen(self, pen): |
|
1179 |
self.Pen = pen |
|
1180 |
||
1181 |
# Make a clone of the connector |
|
112 | 1182 |
def Clone(self, parent = None): |
1183 |
if parent is None: |
|
1184 |
parent = self.ParentBlock |
|
1185 |
return Connector(parent, self.Name, self.Type, wx.Point(self.Pos[0], self.Pos[1]), |
|
0 | 1186 |
self.Direction, self.Negated) |
1187 |
||
1188 |
# Returns the connector parent block |
|
1189 |
def GetParentBlock(self): |
|
1190 |
return self.ParentBlock |
|
1191 |
||
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1192 |
# Returns the connector type |
112 | 1193 |
def GetType(self, raw = False): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1194 |
if self.ParentBlock.IsEndType(self.Type) or raw: |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1195 |
return self.Type |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1196 |
elif (self.Negated or self.Edge != "none") and self.ParentBlock.IsOfType("BOOL", self.Type): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1197 |
return "BOOL" |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1198 |
else: |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1199 |
return self.ParentBlock.GetConnectionResultType(self, self.Type) |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1200 |
|
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1201 |
# Returns the connector type |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1202 |
def GetConnectedType(self): |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1203 |
if self.ParentBlock.IsEndType(self.Type): |
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1204 |
return self.Type |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1205 |
elif len(self.Wires) == 1: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1206 |
return self.Wires[0][0].GetOtherConnectedType(self.Wires[0][1]) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1207 |
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
|
1208 |
|
144 | 1209 |
# Returns the connector type |
1210 |
def GetConnectedRedrawRect(self, movex, movey): |
|
1211 |
rect = None |
|
1212 |
for wire, handle in self.Wires: |
|
1213 |
if rect is None: |
|
1214 |
rect = wire.GetRedrawRect() |
|
1215 |
else: |
|
1216 |
rect = rect.Union(wire.GetRedrawRect()) |
|
1217 |
return rect |
|
1218 |
||
98 | 1219 |
# Returns if connector type is compatible with type given |
1220 |
def IsCompatible(self, type): |
|
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1221 |
reference = self.GetType() |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1222 |
return self.ParentBlock.IsOfType(type, reference) or self.ParentBlock.IsOfType(reference, type) |
98 | 1223 |
|
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1224 |
# 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
|
1225 |
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
|
1226 |
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
|
1227 |
|
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
1228 |
# Returns the connector name |
0 | 1229 |
def GetName(self): |
1230 |
return self.Name |
|
1231 |
||
1232 |
# Changes the connector name |
|
1233 |
def SetName(self, name): |
|
1234 |
self.Name = name |
|
42 | 1235 |
self.RefreshNameSize() |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1236 |
|
249 | 1237 |
def RefreshValue(self): |
1238 |
self.Value = self.ReceivingCurrent() |
|
1239 |
||
339 | 1240 |
def RefreshValid(self): |
1241 |
self.Valid = True |
|
1242 |
for wire, handle in self.Wires: |
|
1243 |
self.Valid &= wire.GetValid() |
|
1244 |
||
249 | 1245 |
def ReceivingCurrent(self): |
1246 |
current = False |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1247 |
for wire, handle in self.Wires: |
249 | 1248 |
value = wire.GetValue() |
253 | 1249 |
if current != "undefined" and isinstance(value, BooleanType): |
249 | 1250 |
current |= wire.GetValue() |
253 | 1251 |
elif value == "undefined": |
1252 |
current = "undefined" |
|
249 | 1253 |
return current |
1254 |
||
1255 |
def SpreadCurrent(self, spreading): |
|
1256 |
for wire, handle in self.Wires: |
|
1257 |
wire.SetValue(spreading) |
|
42 | 1258 |
|
1259 |
# Changes the connector name size |
|
1260 |
def RefreshNameSize(self): |
|
1261 |
if self.Name != "": |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1262 |
dc = wx.ClientDC(self.ParentBlock.Parent) |
42 | 1263 |
self.NameSize = dc.GetTextExtent(self.Name) |
1264 |
else: |
|
1265 |
self.NameSize = 0, 0 |
|
1266 |
||
1267 |
# Returns the connector name size |
|
1268 |
def GetNameSize(self): |
|
1269 |
return self.NameSize |
|
0 | 1270 |
|
1271 |
# Returns the wires connected to the connector |
|
1272 |
def GetWires(self): |
|
1273 |
return self.Wires |
|
1274 |
||
1275 |
# Returns the parent block Id |
|
1276 |
def GetBlockId(self): |
|
1277 |
return self.ParentBlock.GetId() |
|
1278 |
||
1279 |
# Returns the connector relative position |
|
1280 |
def GetRelPosition(self): |
|
1281 |
return self.Pos |
|
1282 |
||
1283 |
# Returns the connector absolute position |
|
1284 |
def GetPosition(self, size = True): |
|
1285 |
parent_pos = self.ParentBlock.GetPosition() |
|
1286 |
# If the position of the end of the connector is asked |
|
1287 |
if size: |
|
1288 |
x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE |
|
1289 |
y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
|
1290 |
else: |
|
1291 |
x = parent_pos[0] + self.Pos.x |
|
1292 |
y = parent_pos[1] + self.Pos.y |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1293 |
return wx.Point(x, y) |
0 | 1294 |
|
1295 |
# Change the connector relative position |
|
1296 |
def SetPosition(self, pos): |
|
1297 |
self.Pos = pos |
|
1298 |
||
1299 |
# Returns the connector direction |
|
1300 |
def GetDirection(self): |
|
1301 |
return self.Direction |
|
1302 |
||
1303 |
# Change the connector direction |
|
1304 |
def SetDirection(self, direction): |
|
1305 |
self.Direction = direction |
|
1306 |
||
1307 |
# Connect a wire to this connector at the last place |
|
1308 |
def Connect(self, wire, refresh = True): |
|
1309 |
self.InsertConnect(len(self.Wires), wire, refresh) |
|
1310 |
||
1311 |
# Connect a wire to this connector at the place given |
|
1312 |
def InsertConnect(self, idx, wire, refresh = True): |
|
1313 |
if wire not in self.Wires: |
|
1314 |
self.Wires.insert(idx, wire) |
|
1315 |
if refresh: |
|
1316 |
self.ParentBlock.RefreshModel(False) |
|
1317 |
||
1318 |
# Returns the index of the wire given in the list of connected |
|
1319 |
def GetWireIndex(self, wire): |
|
1320 |
for i, (tmp_wire, handle) in enumerate(self.Wires): |
|
1321 |
if tmp_wire == wire: |
|
1322 |
return i |
|
1323 |
return None |
|
1324 |
||
1325 |
# Unconnect a wire or all wires connected to the connector |
|
2 | 1326 |
def UnConnect(self, wire = None, unconnect = True, delete = False): |
0 | 1327 |
i = 0 |
1328 |
found = False |
|
1329 |
while i < len(self.Wires) and not found: |
|
1330 |
if not wire or self.Wires[i][0] == wire: |
|
1331 |
# If Unconnect haven't been called from a wire, disconnect the connector in the wire |
|
1332 |
if unconnect: |
|
1333 |
if self.Wires[i][1] == 0: |
|
2 | 1334 |
self.Wires[i][0].UnConnectStartPoint(delete) |
0 | 1335 |
else: |
2 | 1336 |
self.Wires[i][0].UnConnectEndPoint(delete) |
0 | 1337 |
# Remove wire from connected |
1338 |
if wire: |
|
1339 |
self.Wires.pop(i) |
|
1340 |
found = True |
|
1341 |
i += 1 |
|
1342 |
# If no wire defined, unconnect all wires |
|
1343 |
if not wire: |
|
1344 |
self.Wires = [] |
|
339 | 1345 |
self.RefreshValid() |
0 | 1346 |
self.ParentBlock.RefreshModel(False) |
1347 |
||
1348 |
# Returns if connector has one or more wire connected |
|
1349 |
def IsConnected(self): |
|
1350 |
return len(self.Wires) > 0 |
|
1351 |
||
1352 |
# Move the wires connected |
|
1353 |
def MoveConnected(self, exclude = []): |
|
1354 |
if len(self.Wires) > 0: |
|
1355 |
# Calculate the new position of the end point |
|
1356 |
parent_pos = self.ParentBlock.GetPosition() |
|
1357 |
x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE |
|
1358 |
y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE |
|
1359 |
# Move the corresponding point on all the wires connected |
|
1360 |
for wire, index in self.Wires: |
|
1361 |
if wire not in exclude: |
|
1362 |
if index == 0: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1363 |
wire.MoveStartPoint(wx.Point(x, y)) |
0 | 1364 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1365 |
wire.MoveEndPoint(wx.Point(x, y)) |
0 | 1366 |
|
1367 |
# Refreshes the model of all the wires connected |
|
1368 |
def RefreshWires(self): |
|
1369 |
for wire in self.Wires: |
|
1370 |
wire[0].RefreshModel() |
|
1371 |
||
1372 |
# Refreshes the parent block model |
|
1373 |
def RefreshParentBlock(self): |
|
1374 |
self.ParentBlock.RefreshModel(False) |
|
1375 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1376 |
# Highlight the parent block |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1377 |
def HighlightParentBlock(self, highlight): |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1378 |
self.ParentBlock.SetHighlighted(highlight) |
144 | 1379 |
self.ParentBlock.Refresh() |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1380 |
|
27 | 1381 |
# Returns all the blocks connected to this connector |
1382 |
def GetConnectedBlocks(self): |
|
1383 |
blocks = [] |
|
1384 |
for wire, handle in self.Wires: |
|
1385 |
# Get other connector connected to each wire |
|
1386 |
if handle == 0: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1387 |
connector = wire.GetEndConnected() |
27 | 1388 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1389 |
connector = wire.GetStartConnected() |
27 | 1390 |
# Get parent block for this connector |
1391 |
if connector: |
|
1392 |
block = connector.GetParentBlock() |
|
1393 |
if block not in blocks: |
|
1394 |
blocks.append(block) |
|
1395 |
return blocks |
|
1396 |
||
0 | 1397 |
# Returns the connector negated property |
1398 |
def IsNegated(self): |
|
1399 |
return self.Negated |
|
1400 |
||
1401 |
# Changes the connector negated property |
|
1402 |
def SetNegated(self, negated): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1403 |
if self.ParentBlock.IsOfType("BOOL", self.Type): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1404 |
self.Negated = negated |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1405 |
self.Edge = "none" |
0 | 1406 |
|
1407 |
# Returns the connector edge property |
|
1408 |
def GetEdge(self): |
|
1409 |
return self.Edge |
|
1410 |
||
1411 |
# Changes the connector edge property |
|
1412 |
def SetEdge(self, edge): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1413 |
if self.ParentBlock.IsOfType("BOOL", self.Type): |
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1414 |
self.Edge = edge |
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1415 |
self.Negated = False |
0 | 1416 |
|
1417 |
# Tests if the point given is near from the end point of this connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1418 |
def TestPoint(self, pt, direction = None, exclude = True): |
0 | 1419 |
parent_pos = self.ParentBlock.GetPosition() |
249 | 1420 |
if (not (len(self.Wires) > 0 and self.OneConnected and exclude) or self.Type == "BOOL")\ |
1421 |
and direction is None or self.Direction == direction: |
|
1422 |
# Calculate a square around the end point of this connector |
|
1423 |
x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
|
1424 |
y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE |
|
1425 |
width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE |
|
1426 |
height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE |
|
1427 |
rect = wx.Rect(x, y, width, height) |
|
1428 |
return rect.InsideXY(pt.x, pt.y) |
|
0 | 1429 |
return False |
1430 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1431 |
# 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
|
1432 |
def DrawHighlightment(self, dc): |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1433 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1434 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
144 | 1435 |
dc.SetLogicalFunction(wx.AND) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1436 |
parent_pos = self.ParentBlock.GetPosition() |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1437 |
posx = parent_pos[0] + self.Pos.x |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1438 |
posy = parent_pos[1] + self.Pos.y |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1439 |
width = CONNECTOR_SIZE |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1440 |
height = CONNECTOR_SIZE |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1441 |
if self.Direction[0] < 0: |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1442 |
posx += CONNECTOR_SIZE * self.Direction[0] |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1443 |
elif self.Direction[0] == 0: |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1444 |
posx -= 2 |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1445 |
width = 5 |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1446 |
if self.Direction[1] < 0: |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1447 |
posy += CONNECTOR_SIZE * self.Direction[1] |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1448 |
elif self.Direction[1] == 0: |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1449 |
posy -= 2 |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1450 |
height = 5 |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1451 |
dc.DrawRectangle(posx, posy, width, height) |
144 | 1452 |
dc.SetLogicalFunction(wx.COPY) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
1453 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1454 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1455 |
if len(infos) == 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1456 |
for wire, handle in self.Wires: |
339 | 1457 |
wire.SetValid(False) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1458 |
else: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1459 |
self.Errors[infos[0]] = (start, end) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1460 |
|
0 | 1461 |
# Draws the connector |
1462 |
def Draw(self, dc): |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1463 |
if len(self.Errors) > 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1464 |
dc.SetPen(wx.RED_PEN) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1465 |
dc.SetBrush(wx.Brush(wx.Colour(255, 255, 0))) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1466 |
else: |
249 | 1467 |
if not self.Valid: |
1468 |
dc.SetPen(wx.RED_PEN) |
|
1469 |
elif isinstance(self.Value, BooleanType) and self.Value: |
|
1470 |
dc.SetPen(wx.GREEN_PEN) |
|
253 | 1471 |
elif self.Value == "undefined": |
1472 |
dc.SetPen(wx.Pen(wx.NamedColour("orange"))) |
|
249 | 1473 |
else: |
1474 |
dc.SetPen(self.Pen) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1475 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 1476 |
parent_pos = self.ParentBlock.GetPosition() |
213 | 1477 |
|
1478 |
if getattr(dc, "printing", False): |
|
1479 |
name_size = dc.GetTextExtent(self.Name) |
|
1480 |
else: |
|
1481 |
name_size = self.NameSize |
|
1482 |
||
0 | 1483 |
if self.Negated: |
1484 |
# If connector is negated, draw a circle |
|
1485 |
xcenter = parent_pos[0] + self.Pos.x + (CONNECTOR_SIZE * self.Direction[0]) / 2 |
|
1486 |
ycenter = parent_pos[1] + self.Pos.y + (CONNECTOR_SIZE * self.Direction[1]) / 2 |
|
1487 |
dc.DrawCircle(xcenter, ycenter, CONNECTOR_SIZE / 2) |
|
1488 |
else: |
|
1489 |
xstart = parent_pos[0] + self.Pos.x |
|
1490 |
ystart = parent_pos[1] + self.Pos.y |
|
1491 |
if self.Edge == "rising": |
|
1492 |
# If connector has a rising edge, draw a right arrow |
|
1493 |
dc.DrawLine(xstart, ystart, xstart - 4, ystart - 4) |
|
1494 |
dc.DrawLine(xstart, ystart, xstart - 4, ystart + 4) |
|
1495 |
elif self.Edge == "falling": |
|
1496 |
# If connector has a falling edge, draw a left arrow |
|
1497 |
dc.DrawLine(xstart, ystart, xstart + 4, ystart - 4) |
|
1498 |
dc.DrawLine(xstart, ystart, xstart + 4, ystart + 4) |
|
1499 |
xend = xstart + CONNECTOR_SIZE * self.Direction[0] |
|
1500 |
yend = ystart + CONNECTOR_SIZE * self.Direction[1] |
|
1501 |
dc.DrawLine(xstart + self.Direction[0], ystart + self.Direction[1], xend, yend) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1502 |
if len(self.Errors) > 0: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1503 |
dc.SetPen(self.Pen) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
222
diff
changeset
|
1504 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 1505 |
if self.Direction[0] != 0: |
213 | 1506 |
ytext = parent_pos[1] + self.Pos.y - name_size[1] / 2 |
0 | 1507 |
if self.Direction[0] < 0: |
1508 |
xtext = parent_pos[0] + self.Pos.x + 5 |
|
1509 |
else: |
|
213 | 1510 |
xtext = parent_pos[0] + self.Pos.x - (name_size[0] + 5) |
0 | 1511 |
if self.Direction[1] != 0: |
213 | 1512 |
xtext = parent_pos[0] + self.Pos.x - name_size[0] / 2 |
0 | 1513 |
if self.Direction[1] < 0: |
1514 |
ytext = parent_pos[1] + self.Pos.y + 5 |
|
1515 |
else: |
|
213 | 1516 |
ytext = parent_pos[1] + self.Pos.y - (name_size[1] + 5) |
0 | 1517 |
# Draw the text |
1518 |
dc.DrawText(self.Name, xtext, ytext) |
|
1519 |
||
1520 |
||
1521 |
#------------------------------------------------------------------------------- |
|
1522 |
# Common Wire Element |
|
1523 |
#------------------------------------------------------------------------------- |
|
1524 |
||
1525 |
""" |
|
1526 |
Class that implements a wire for connecting two blocks |
|
1527 |
""" |
|
1528 |
||
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
1529 |
class Wire(Graphic_Element, DebugDataConsumer): |
0 | 1530 |
|
1531 |
# Create a new wire |
|
1532 |
def __init__(self, parent, start = None, end = None): |
|
1533 |
Graphic_Element.__init__(self, parent) |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
1534 |
DebugDataConsumer.__init__(self) |
0 | 1535 |
self.StartPoint = start |
1536 |
self.EndPoint = end |
|
1537 |
self.StartConnected = None |
|
1538 |
self.EndConnected = None |
|
1539 |
# If the start and end points are defined, calculate the wire |
|
1540 |
if start and end: |
|
1541 |
self.ResetPoints() |
|
1542 |
self.GeneratePoints() |
|
1543 |
else: |
|
1544 |
self.Points = [] |
|
1545 |
self.Segments = [] |
|
1546 |
self.SelectedSegment = None |
|
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1547 |
self.Valid = True |
249 | 1548 |
self.ValueSize = None |
253 | 1549 |
self.ComputedValue = None |
0 | 1550 |
self.OverStart = False |
1551 |
self.OverEnd = False |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1552 |
self.ComputingType = False |
338 | 1553 |
self.ToolTip = None |
384
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1554 |
self.Font = parent.GetMiniFont() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1555 |
|
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1556 |
def GetDefinition(self): |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1557 |
if self.StartConnected is not None and self.EndConnected is not None: |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1558 |
startblock = self.StartConnected.GetParentBlock() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1559 |
endblock = self.EndConnected.GetParentBlock() |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1560 |
return [], [(startblock.GetId(), endblock.GetId())] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1561 |
return [], [] |
ed27a676d5c9
Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents:
381
diff
changeset
|
1562 |
|
249 | 1563 |
def Flush(self): |
0 | 1564 |
self.StartConnected = None |
1565 |
self.EndConnected = None |
|
1566 |
||
338 | 1567 |
def CreateToolTip(self, pos): |
1568 |
if self.Value is not None and self.Value != "undefined" and not isinstance(self.Value, BooleanType): |
|
1569 |
if isinstance(self.Value, StringType): |
|
339 | 1570 |
computed_value = "\"%s\""%self.Value |
338 | 1571 |
else: |
339 | 1572 |
computed_value = str(self.Value) |
1573 |
self.ToolTip = ToolTip(self.Parent, computed_value) |
|
338 | 1574 |
self.ToolTip.SetPosition(pos) |
1575 |
self.ToolTip.Show() |
|
1576 |
||
339 | 1577 |
def MoveToolTip(self, pos): |
1578 |
if self.ToolTip is not None: |
|
1579 |
self.ToolTip.SetPosition(pos) |
|
1580 |
||
338 | 1581 |
def ClearToolTip(self): |
1582 |
if self.ToolTip is not None: |
|
1583 |
self.ToolTip.Destroy() |
|
1584 |
self.ToolTip = None |
|
1585 |
||
144 | 1586 |
# Returns the RedrawRect |
1587 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
1588 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
1589 |
if self.StartConnected: |
|
1590 |
rect = rect.Union(self.StartConnected.GetRedrawRect(movex, movey)) |
|
1591 |
if self.EndConnected: |
|
1592 |
rect = rect.Union(self.EndConnected.GetRedrawRect(movex, movey)) |
|
249 | 1593 |
if self.ValueSize is not None: |
1594 |
width, height = self.ValueSize |
|
1595 |
if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: |
|
1596 |
x = self.Points[0].x + width * self.StartPoint[1][0] / 2 |
|
1597 |
y = self.Points[0].y + (height * self.StartPoint[1][1] - 1) / 2 |
|
1598 |
rect = rect.Union(wx.Rect(x, y, width, height)) |
|
1599 |
x = self.Points[-1].x + width * self.EndPoint[1][0] / 2 |
|
1600 |
y = self.Points[-1].y + (height * self.EndPoint[1][1] - 1) / 2 |
|
1601 |
rect = rect.Union(wx.Rect(x, y, width, height)) |
|
1602 |
else: |
|
1603 |
middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1 |
|
1604 |
x = self.Points[middle].x - width / 2 |
|
1605 |
y = self.Points[middle].y - height / 2 |
|
1606 |
rect = rect.Union(wx.Rect(x, y, width, height)) |
|
144 | 1607 |
return rect |
1608 |
||
283 | 1609 |
def Clone(self, parent, connectors = {}, dx = 0, dy = 0): |
1610 |
start_connector = connectors.get(self.StartConnected, None) |
|
1611 |
end_connector = connectors.get(self.EndConnected, None) |
|
1612 |
if start_connector is not None and end_connector is not None: |
|
1613 |
wire = Wire(parent) |
|
1614 |
wire.SetPoints([(point.x + dx, point.y + dy) for point in self.Points]) |
|
1615 |
start_connector.Connect((wire, 0), False) |
|
1616 |
end_connector.Connect((wire, -1), False) |
|
1617 |
wire.ConnectStartPoint(start_connector.GetPosition(), start_connector) |
|
1618 |
wire.ConnectEndPoint(end_connector.GetPosition(), end_connector) |
|
1619 |
return wire |
|
1620 |
return None |
|
1621 |
||
0 | 1622 |
# Forbids to change the wire position |
1623 |
def SetPosition(x, y): |
|
1624 |
pass |
|
1625 |
||
1626 |
# Forbids to change the wire size |
|
1627 |
def SetSize(width, height): |
|
1628 |
pass |
|
1629 |
||
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1630 |
# Moves and Resizes the element for fitting scaling |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1631 |
def AdjustToScaling(self, scaling): |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1632 |
if scaling is not None: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1633 |
movex_max = movey_max = 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1634 |
for idx, point in enumerate(self.Points): |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1635 |
if 0 < idx < len(self.Points) - 1: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1636 |
movex = round_scaling(point.x, scaling[0]) - point.x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1637 |
movey = round_scaling(point.y, scaling[1]) - point.y |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1638 |
if idx == 1: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1639 |
if self.Segments[0][0] == 0: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1640 |
movex = 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1641 |
elif (point.x + movex - self.Points[0].x) * self.Segments[0][0] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1642 |
movex = round_scaling(self.Points[0].x + MIN_SEGMENT_SIZE * self.Segments[0][0], scaling[0], self.Segments[0][0]) - point.x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1643 |
if self.Segments[0][1] == 0: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1644 |
movey = 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1645 |
elif (point.y + movey - self.Points[0].y) * self.Segments[0][1] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1646 |
movey = round_scaling(self.Points[0].y + MIN_SEGMENT_SIZE * self.Segments[0][1], scaling[0], self.Segments[0][1]) - point.y |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1647 |
elif idx == len(self.Points) - 2: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1648 |
if self.Segments[-1][0] == 0: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1649 |
movex = 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1650 |
elif (self.Points[-1].x - (point.x + movex)) * self.Segments[-1][0] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1651 |
movex = round_scaling(self.Points[-1].x + MIN_SEGMENT_SIZE * self.Segments[0][0], scaling[0], self.Segments[0][0]) - point.x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1652 |
if self.Segments[-1][1] == 0: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1653 |
movey = 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1654 |
elif (self.Points[-1].y - (point.y + movey)) * self.Segments[-1][1] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1655 |
movey = round_scaling(self.Points[-1].y - MIN_SEGMENT_SIZE * self.Segments[-1][1], scaling[1], -self.Segments[-1][1]) - point.y |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1656 |
movex_max = max(movex_max, movex) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1657 |
movey_max = max(movey_max, movey) |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1658 |
point.x += movex |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1659 |
point.y += movey |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1660 |
return movex_max, movey_max |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1661 |
return 0, 0 |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
1662 |
|
27 | 1663 |
# Returns connector to which start point is connected |
1664 |
def GetStartConnected(self): |
|
1665 |
return self.StartConnected |
|
1666 |
||
98 | 1667 |
# Returns connector to which start point is connected |
1668 |
def GetStartConnectedType(self): |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1669 |
if self.StartConnected and not self.ComputingType: |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1670 |
self.ComputingType = True |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1671 |
computed_type = self.StartConnected.GetType() |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1672 |
self.ComputingType = False |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1673 |
return computed_type |
98 | 1674 |
return None |
1675 |
||
27 | 1676 |
# Returns connector to which end point is connected |
1677 |
def GetEndConnected(self): |
|
1678 |
return self.EndConnected |
|
1679 |
||
98 | 1680 |
# Returns connector to which end point is connected |
1681 |
def GetEndConnectedType(self): |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1682 |
if self.EndConnected and not self.ComputingType: |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1683 |
self.ComputingType = True |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1684 |
computed_type = self.EndConnected.GetType() |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1685 |
self.ComputingType = False |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1686 |
return computed_type |
98 | 1687 |
return None |
1688 |
||
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1689 |
def GetConnectionDirection(self): |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1690 |
if self.StartConnected is None and self.EndConnected is None: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1691 |
return None |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1692 |
elif self.StartConnected is not None and self.EndConnected is None: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1693 |
return (-self.StartPoint[1][0], -self.StartPoint[1][1]) |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1694 |
elif self.StartConnected is None and self.EndConnected is not None: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1695 |
return self.EndPoint |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1696 |
elif self.Handle is not None: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1697 |
handle_type, handle = self.Handle |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1698 |
# A point has been handled |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1699 |
if handle_type == HANDLE_POINT: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1700 |
if handle == 0: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1701 |
return self.EndPoint |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1702 |
else: |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1703 |
return (-self.StartPoint[1][0], -self.StartPoint[1][1]) |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1704 |
return None |
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
1705 |
|
145 | 1706 |
def GetOtherConnected(self, connector): |
1707 |
if self.StartConnected == connector: |
|
1708 |
return self.EndConnected |
|
1709 |
else: |
|
1710 |
return self.StartConnected |
|
1711 |
||
99
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1712 |
def GetOtherConnectedType(self, handle): |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1713 |
if handle == 0: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1714 |
return self.GetEndConnectedType() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1715 |
else: |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1716 |
return self.GetStartConnectedType() |
2b18a72dcaf0
Added support for standard functions type compatibility check
lbessard
parents:
98
diff
changeset
|
1717 |
|
98 | 1718 |
def IsConnectedCompatible(self): |
1719 |
if self.StartConnected: |
|
1720 |
return self.StartConnected.IsCompatible(self.GetEndConnectedType()) |
|
1721 |
elif self.EndConnected: |
|
1722 |
return True |
|
1723 |
return False |
|
1724 |
||
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1725 |
def SetValue(self, value): |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
1726 |
if self.Value != value: |
249 | 1727 |
self.Value = value |
253 | 1728 |
if value is not None and not isinstance(value, BooleanType): |
1729 |
if isinstance(value, StringType): |
|
1730 |
self.ComputedValue = "\"%s\""%value |
|
1731 |
else: |
|
1732 |
self.ComputedValue = str(value) |
|
338 | 1733 |
if self.ToolTip is not None: |
1734 |
self.ToolTip.SetTip(self.ComputedValue) |
|
253 | 1735 |
if len(self.ComputedValue) > 4: |
338 | 1736 |
self.ComputedValue = self.ComputedValue[:4] + "..." |
253 | 1737 |
if isinstance(self.ComputedValue, StringType): |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
1738 |
self.ValueSize = self.Parent.GetMiniTextExtent(self.ComputedValue) |
249 | 1739 |
else: |
1740 |
self.ValueSize = None |
|
1741 |
if self.StartConnected: |
|
1742 |
self.StartConnected.RefreshValue() |
|
1743 |
if self.EndConnected: |
|
1744 |
self.EndConnected.RefreshValue() |
|
368 | 1745 |
if self.Visible: |
1746 |
self.Parent.UpdateRefreshRect(self.GetRedrawRect()) |
|
339 | 1747 |
if isinstance(value, BooleanType) and self.StartConnected is not None: |
249 | 1748 |
block = self.StartConnected.GetParentBlock() |
1749 |
block.SpreadCurrent() |
|
1750 |
||
1751 |
def GetValue(self): |
|
1752 |
return self.Value |
|
102
85875dcb7754
Adding edit user's POU by double click on block instance
lbessard
parents:
99
diff
changeset
|
1753 |
|
0 | 1754 |
# Unconnect the start and end points |
1755 |
def Clean(self): |
|
1756 |
if self.StartConnected: |
|
1757 |
self.UnConnectStartPoint() |
|
1758 |
if self.EndConnected: |
|
1759 |
self.UnConnectEndPoint() |
|
1760 |
||
1761 |
# Delete this wire by calling the corresponding method |
|
1762 |
def Delete(self): |
|
1763 |
self.Parent.DeleteWire(self) |
|
1764 |
||
1765 |
# Select a segment and not the whole wire. It's useful for Ladder Diagram |
|
1766 |
def SetSelectedSegment(self, segment): |
|
1767 |
# The last segment is indicated |
|
1768 |
if segment == -1: |
|
1769 |
segment = len(self.Segments) - 1 |
|
1770 |
# The selected segment is reinitialised |
|
1771 |
if segment == None: |
|
1772 |
if self.StartConnected: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1773 |
self.StartConnected.SetPen(wx.BLACK_PEN) |
0 | 1774 |
if self.EndConnected: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1775 |
self.EndConnected.SetPen(wx.BLACK_PEN) |
0 | 1776 |
# The segment selected is the first |
1777 |
elif segment == 0: |
|
1778 |
if self.StartConnected: |
|
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1779 |
self.StartConnected.SetPen(wx.BLUE_PEN) |
0 | 1780 |
if self.EndConnected: |
1781 |
# There is only one segment |
|
1782 |
if len(self.Segments) == 1: |
|
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1783 |
self.EndConnected.SetPen(wx.BLUE_PEN) |
0 | 1784 |
else: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1785 |
self.EndConnected.SetPen(wx.BLACK_PEN) |
0 | 1786 |
# The segment selected is the last |
1787 |
elif segment == len(self.Segments) - 1: |
|
1788 |
if self.StartConnected: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1789 |
self.StartConnected.SetPen(wx.BLACK_PEN) |
0 | 1790 |
if self.EndConnected: |
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1791 |
self.EndConnected.SetPen(wx.BLUE_PEN) |
0 | 1792 |
self.SelectedSegment = segment |
144 | 1793 |
self.Refresh() |
0 | 1794 |
|
339 | 1795 |
def SetValid(self, valid): |
1796 |
self.Valid = valid |
|
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1797 |
if self.StartConnected: |
339 | 1798 |
self.StartConnected.RefreshValid() |
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1799 |
if self.EndConnected: |
339 | 1800 |
self.EndConnected.RefreshValid() |
1801 |
||
1802 |
def GetValid(self): |
|
1803 |
return self.Valid |
|
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
1804 |
|
0 | 1805 |
# Reinitialize the wire points |
1806 |
def ResetPoints(self): |
|
1807 |
if self.StartPoint and self.EndPoint: |
|
1808 |
self.Points = [self.StartPoint[0], self.EndPoint[0]] |
|
1809 |
self.Segments = [self.StartPoint[1]] |
|
1810 |
else: |
|
1811 |
self.Points = [] |
|
1812 |
self.Segments = [] |
|
1813 |
||
1814 |
# Refresh the wire bounding box |
|
1815 |
def RefreshBoundingBox(self): |
|
1816 |
if len(self.Points) > 0: |
|
1817 |
# If startpoint or endpoint is connected, save the point radius |
|
1818 |
start_radius = end_radius = 0 |
|
1819 |
if not self.StartConnected: |
|
1820 |
start_radius = POINT_RADIUS |
|
1821 |
if not self.EndConnected: |
|
1822 |
end_radius = POINT_RADIUS |
|
1823 |
# Initialize minimum and maximum from the first point |
|
1824 |
minx, minbbxx = self.Points[0].x, self.Points[0].x - start_radius |
|
1825 |
maxx, maxbbxx = self.Points[0].x, self.Points[0].x + start_radius |
|
1826 |
miny, minbbxy = self.Points[0].y, self.Points[0].y - start_radius |
|
1827 |
maxy, maxbbxy = self.Points[0].y, self.Points[0].y + start_radius |
|
1828 |
# Actualize minimum and maximum with the other points |
|
1829 |
for point in self.Points[1:-1]: |
|
1830 |
minx, minbbxx = min(minx, point.x), min(minbbxx, point.x) |
|
1831 |
maxx, maxbbxx = max(maxx, point.x), max(maxbbxx, point.x) |
|
1832 |
miny, minbbxy = min(miny, point.y), min(minbbxy, point.y) |
|
1833 |
maxy, maxbbxy = max(maxy, point.y), max(maxbbxy, point.y) |
|
1834 |
if len(self.Points) > 1: |
|
1835 |
minx, minbbxx = min(minx, self.Points[-1].x), min(minbbxx, self.Points[-1].x - end_radius) |
|
1836 |
maxx, maxbbxx = max(maxx, self.Points[-1].x), max(maxbbxx, self.Points[-1].x + end_radius) |
|
1837 |
miny, minbbxy = min(miny, self.Points[-1].y), min(minbbxy, self.Points[-1].y - end_radius) |
|
1838 |
maxy, maxbbxy = max(maxy, self.Points[-1].y), max(maxbbxy, self.Points[-1].y + end_radius) |
|
108 | 1839 |
self.Pos.x, self.Pos.y = minx, miny |
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
1840 |
self.Size = wx.Size(maxx - minx, maxy - miny) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1841 |
self.BoundingBox = wx.Rect(minbbxx, minbbxy, maxbbxx - minbbxx + 1, maxbbxy - minbbxy + 1) |
0 | 1842 |
|
1843 |
# Refresh the realpoints that permits to keep the proportionality in wire during resizing |
|
1844 |
def RefreshRealPoints(self): |
|
1845 |
if len(self.Points) > 0: |
|
1846 |
self.RealPoints = [] |
|
1847 |
# Calculate float relative position of each point with the minimum point |
|
1848 |
for point in self.Points: |
|
1849 |
self.RealPoints.append([float(point.x - self.Pos.x), float(point.y - self.Pos.y)]) |
|
1850 |
||
1851 |
# Returns the wire minimum size |
|
1852 |
def GetMinSize(self): |
|
1853 |
width = 1 |
|
1854 |
height = 1 |
|
1855 |
dir_product = product(self.StartPoint[1], self.EndPoint[1]) |
|
1856 |
# The directions are opposed |
|
1857 |
if dir_product < 0: |
|
1858 |
if self.StartPoint[0] != 0: |
|
1859 |
width = MIN_SEGMENT_SIZE * 2 |
|
1860 |
if self.StartPoint[1] != 0: |
|
1861 |
height = MIN_SEGMENT_SIZE * 2 |
|
1862 |
# The directions are the same |
|
1863 |
elif dir_product > 0: |
|
1864 |
if self.StartPoint[0] != 0: |
|
1865 |
width = MIN_SEGMENT_SIZE |
|
1866 |
if self.StartPoint[1] != 0: |
|
1867 |
height = MIN_SEGMENT_SIZE |
|
1868 |
# The directions are perpendiculars |
|
1869 |
else: |
|
1870 |
width = MIN_SEGMENT_SIZE |
|
1871 |
height = MIN_SEGMENT_SIZE |
|
1872 |
return width + 1, height + 1 |
|
1873 |
||
1874 |
# Returns if the point given is on one of the wire segments |
|
1875 |
def HitTest(self, pt): |
|
1876 |
test = False |
|
1877 |
for i in xrange(len(self.Points) - 1): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1878 |
rect = wx.Rect(0, 0, 0, 0) |
0 | 1879 |
x1, y1 = self.Points[i].x, self.Points[i].y |
1880 |
x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
|
1881 |
# Calculate a rectangle around the segment |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1882 |
rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
0 | 1883 |
abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
1884 |
test |= rect.InsideXY(pt.x, pt.y) |
|
1885 |
return test |
|
1886 |
||
1887 |
# Returns the wire start or end point if the point given is on one of them |
|
1888 |
def TestPoint(self, pt): |
|
1889 |
# Test the wire start point |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1890 |
rect = wx.Rect(self.Points[0].x - ANCHOR_DISTANCE, self.Points[0].y - ANCHOR_DISTANCE, |
0 | 1891 |
2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
1892 |
if rect.InsideXY(pt.x, pt.y): |
|
1893 |
return 0 |
|
1894 |
# Test the wire end point |
|
1895 |
if len(self.Points) > 1: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1896 |
rect = wx.Rect(self.Points[-1].x - ANCHOR_DISTANCE, self.Points[-1].y - ANCHOR_DISTANCE, |
0 | 1897 |
2 * ANCHOR_DISTANCE, 2 * ANCHOR_DISTANCE) |
1898 |
if rect.InsideXY(pt.x, pt.y): |
|
1899 |
return -1 |
|
1900 |
return None |
|
1901 |
||
1902 |
# Returns the wire segment if the point given is on it |
|
1903 |
def TestSegment(self, pt, all=False): |
|
1904 |
for i in xrange(len(self.Segments)): |
|
1905 |
# If wire is not in a Ladder Diagram, first and last segments are excluded |
|
237 | 1906 |
if all or 0 < i < len(self.Segments) - 1: |
0 | 1907 |
x1, y1 = self.Points[i].x, self.Points[i].y |
1908 |
x2, y2 = self.Points[i + 1].x, self.Points[i + 1].y |
|
1909 |
# Calculate a rectangle around the segment |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1910 |
rect = wx.Rect(min(x1, x2) - ANCHOR_DISTANCE, min(y1, y2) - ANCHOR_DISTANCE, |
0 | 1911 |
abs(x1 - x2) + 2 * ANCHOR_DISTANCE, abs(y1 - y2) + 2 * ANCHOR_DISTANCE) |
1912 |
if rect.InsideXY(pt.x, pt.y): |
|
1913 |
return i, self.Segments[i] |
|
1914 |
return None |
|
1915 |
||
1916 |
# Define the wire points |
|
1917 |
def SetPoints(self, points): |
|
1918 |
if len(points) > 1: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1919 |
self.Points = [wx.Point(x, y) for x, y in points] |
0 | 1920 |
# Calculate the start and end directions |
1921 |
self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
|
1922 |
self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
|
1923 |
# Calculate the start and end points |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1924 |
self.StartPoint[0] = wx.Point(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0], |
0 | 1925 |
self.Points[0].y + CONNECTOR_SIZE * self.StartPoint[1][1]) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1926 |
self.EndPoint[0] = wx.Point(self.Points[-1].x + CONNECTOR_SIZE * self.EndPoint[1][0], |
0 | 1927 |
self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1]) |
1928 |
self.Points[0] = self.StartPoint[0] |
|
1929 |
self.Points[-1] = self.EndPoint[0] |
|
1930 |
# Calculate the segments directions |
|
1931 |
self.Segments = [] |
|
296 | 1932 |
i = 0 |
1933 |
while i < len(self.Points) - 1: |
|
398
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1934 |
if 0 < i < len(self.Points) - 2 and \ |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1935 |
self.Points[i] == self.Points[i + 1] and \ |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1936 |
self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]): |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1937 |
for j in xrange(2): |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1938 |
self.Points.pop(i) |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1939 |
else: |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1940 |
segment = vector(self.Points[i], self.Points[i + 1]) |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1941 |
if is_null_vector(segment) and i > 0: |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1942 |
segment = (self.Segments[-1][1], self.Segments[-1][0]) |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1943 |
if i < len(self.Points) - 2: |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1944 |
next = vector(self.Points[i + 1], self.Points[i + 2]) |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1945 |
if next == segment or is_null_vector(add_vectors(segment, next)): |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1946 |
self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y)) |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1947 |
self.Segments.append(segment) |
c215899298c7
Bug with wire not well designed generating unlimited loop fixed
laurent
parents:
395
diff
changeset
|
1948 |
i += 1 |
0 | 1949 |
self.RefreshBoundingBox() |
1950 |
self.RefreshRealPoints() |
|
1951 |
||
1952 |
# Returns the position of the point indicated |
|
1953 |
def GetPoint(self, index): |
|
1954 |
if index < len(self.Points): |
|
1955 |
return self.Points[index].x, self.Points[index].y |
|
1956 |
return None |
|
1957 |
||
1958 |
# Returns a list of the position of all wire points |
|
1959 |
def GetPoints(self, invert = False): |
|
1960 |
points = self.VerifyPoints() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1961 |
points[0] = wx.Point(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0], |
0 | 1962 |
points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1]) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
1963 |
points[-1] = wx.Point(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0], |
0 | 1964 |
points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1]) |
1965 |
# An inversion of the list is asked |
|
1966 |
if invert: |
|
1967 |
points.reverse() |
|
1968 |
return points |
|
1969 |
||
1970 |
# Returns the position of the two selected segment points |
|
1971 |
def GetSelectedSegmentPoints(self): |
|
1972 |
if self.SelectedSegment != None and len(self.Points) > 1: |
|
1973 |
return self.Points[self.SelectedSegment:self.SelectedSegment + 2] |
|
1974 |
return [] |
|
1975 |
||
1976 |
# Returns if the selected segment is the first and/or the last of the wire |
|
1977 |
def GetSelectedSegmentConnections(self): |
|
1978 |
if self.SelectedSegment != None and len(self.Points) > 1: |
|
1979 |
return self.SelectedSegment == 0, self.SelectedSegment == len(self.Segments) - 1 |
|
1980 |
return (True, True) |
|
1981 |
||
1982 |
# Returns the connectors on which the wire is connected |
|
1983 |
def GetConnected(self): |
|
1984 |
connected = [] |
|
1985 |
if self.StartConnected and self.StartPoint[1] == WEST: |
|
1986 |
connected.append(self.StartConnected) |
|
1987 |
if self.EndConnected and self.EndPoint[1] == WEST: |
|
1988 |
connected.append(self.EndConnected) |
|
1989 |
return connected |
|
1990 |
||
1991 |
# Returns the id of the block connected to the first or the last wire point |
|
27 | 1992 |
def GetConnectedInfos(self, index): |
0 | 1993 |
if index == 0 and self.StartConnected: |
27 | 1994 |
return self.StartConnected.GetBlockId(), self.StartConnected.GetName() |
0 | 1995 |
elif index == -1 and self.EndConnected: |
42 | 1996 |
return self.EndConnected.GetBlockId(), self.EndConnected.GetName() |
0 | 1997 |
return None |
1998 |
||
1999 |
# Update the wire points position by keeping at most possible the current positions |
|
2000 |
def GeneratePoints(self, realpoints = True): |
|
2001 |
i = 0 |
|
2002 |
# Calculate the start enad end points with the minimum segment size in the right direction |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2003 |
end = wx.Point(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE, |
0 | 2004 |
self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2005 |
start = wx.Point(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE, |
0 | 2006 |
self.StartPoint[0].y + self.StartPoint[1][1] * MIN_SEGMENT_SIZE) |
2007 |
# Evaluate the point till it's the last |
|
2008 |
while i < len(self.Points) - 1: |
|
2009 |
# The next point is the last |
|
2010 |
if i + 1 == len(self.Points) - 1: |
|
2011 |
# Calculate the direction from current point to end point |
|
2012 |
v_end = vector(self.Points[i], end) |
|
2013 |
# The current point is the first |
|
2014 |
if i == 0: |
|
2015 |
# If the end point is not in the start direction, a point is added |
|
2016 |
if v_end != self.Segments[0] or v_end == self.EndPoint[1]: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2017 |
self.Points.insert(1, wx.Point(start.x, start.y)) |
0 | 2018 |
self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
2019 |
self.Segments[0][0]), v_end, self.EndPoint[1])) |
|
2020 |
# The current point is the second |
|
2021 |
elif i == 1: |
|
2022 |
# The previous direction and the target direction are mainly opposed, a point is added |
|
2023 |
if product(v_end, self.Segments[0]) < 0: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2024 |
self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
0 | 2025 |
self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
2026 |
self.Segments[1][0]), v_end, self.EndPoint[1])) |
|
2027 |
# The previous direction and the end direction are the same or they are |
|
2028 |
# perpendiculars and the end direction points towards current segment |
|
2029 |
elif product(self.Segments[0], self.EndPoint[1]) >= 0 and product(self.Segments[1], self.EndPoint[1]) <= 0: |
|
2030 |
# Current point and end point are aligned |
|
2031 |
if self.Segments[0][0] != 0: |
|
2032 |
self.Points[1].x = end.x |
|
2033 |
if self.Segments[0][1] != 0: |
|
2034 |
self.Points[1].y = end.y |
|
2035 |
# If the previous direction and the end direction are the same, a point is added |
|
2036 |
if product(self.Segments[0], self.EndPoint[1]) > 0: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2037 |
self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
0 | 2038 |
self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
2039 |
self.Segments[1][0]), v_end, self.EndPoint[1])) |
|
2040 |
else: |
|
2041 |
# Current point is positioned in the middle of start point |
|
2042 |
# and end point on the current direction and a point is added |
|
2043 |
if self.Segments[0][0] != 0: |
|
2044 |
self.Points[1].x = (end.x + start.x) / 2 |
|
2045 |
if self.Segments[0][1] != 0: |
|
2046 |
self.Points[1].y = (end.y + start.y) / 2 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2047 |
self.Points.insert(2, wx.Point(self.Points[1].x, self.Points[1].y)) |
0 | 2048 |
self.Segments.insert(2, DirectionChoice((self.Segments[1][1], |
2049 |
self.Segments[1][0]), v_end, self.EndPoint[1])) |
|
2050 |
else: |
|
2051 |
# The previous direction and the end direction are perpendiculars |
|
2052 |
if product(self.Segments[i - 1], self.EndPoint[1]) == 0: |
|
2053 |
# The target direction and the end direction aren't mainly the same |
|
2054 |
if product(v_end, self.EndPoint[1]) <= 0: |
|
2055 |
# Current point and end point are aligned |
|
2056 |
if self.Segments[i - 1][0] != 0: |
|
2057 |
self.Points[i].x = end.x |
|
2058 |
if self.Segments[i - 1][1] != 0: |
|
2059 |
self.Points[i].y = end.y |
|
2060 |
# Previous direction is updated from the new point |
|
2061 |
if product(vector(self.Points[i - 1], self.Points[i]), self.Segments[i - 1]) < 0: |
|
2062 |
self.Segments[i - 1] = (-self.Segments[i - 1][0], -self.Segments[i - 1][1]) |
|
2063 |
else: |
|
2064 |
test = True |
|
2065 |
# If the current point is the third, test if the second |
|
2066 |
# point can be aligned with the end point |
|
2067 |
if i == 2: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2068 |
test_point = wx.Point(self.Points[1].x, self.Points[1].y) |
0 | 2069 |
if self.Segments[1][0] != 0: |
2070 |
test_point.y = end.y |
|
2071 |
if self.Segments[1][1] != 0: |
|
2072 |
test_point.x = end.x |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2073 |
vector_test = vector(self.Points[0], test_point, False) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2074 |
test = norm(vector_test) > MIN_SEGMENT_SIZE and product(self.Segments[0], vector_test) > 0 |
0 | 2075 |
# The previous point can be aligned |
2076 |
if test: |
|
2077 |
self.Points[i].x, self.Points[i].y = end.x, end.y |
|
2078 |
if self.Segments[i - 1][0] != 0: |
|
2079 |
self.Points[i - 1].y = end.y |
|
2080 |
if self.Segments[i - 1][1] != 0: |
|
2081 |
self.Points[i - 1].x = end.x |
|
2082 |
self.Segments[i] = (-self.EndPoint[1][0], -self.EndPoint[1][1]) |
|
2083 |
else: |
|
2084 |
# Current point is positioned in the middle of previous point |
|
2085 |
# and end point on the current direction and a point is added |
|
2086 |
if self.Segments[1][0] != 0: |
|
2087 |
self.Points[2].x = (self.Points[1].x + end.x) / 2 |
|
2088 |
if self.Segments[1][1] != 0: |
|
2089 |
self.Points[2].y = (self.Points[1].y + end.y) / 2 |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2090 |
self.Points.insert(3, wx.Point(self.Points[2].x, self.Points[2].y)) |
0 | 2091 |
self.Segments.insert(3, DirectionChoice((self.Segments[2][1], |
2092 |
self.Segments[2][0]), v_end, self.EndPoint[1])) |
|
2093 |
else: |
|
2094 |
# Current point is aligned with end point |
|
2095 |
if self.Segments[i - 1][0] != 0: |
|
2096 |
self.Points[i].x = end.x |
|
2097 |
if self.Segments[i - 1][1] != 0: |
|
2098 |
self.Points[i].y = end.y |
|
2099 |
# Previous direction is updated from the new point |
|
2100 |
if product(vector(self.Points[i - 1], self.Points[i]), self.Segments[i - 1]) < 0: |
|
2101 |
self.Segments[i - 1] = (-self.Segments[i - 1][0], -self.Segments[i - 1][1]) |
|
2102 |
# If previous direction and end direction are opposed |
|
2103 |
if product(self.Segments[i - 1], self.EndPoint[1]) < 0: |
|
2104 |
# Current point is positioned in the middle of previous point |
|
2105 |
# and end point on the current direction |
|
2106 |
if self.Segments[i - 1][0] != 0: |
|
2107 |
self.Points[i].x = (end.x + self.Points[i - 1].x) / 2 |
|
2108 |
if self.Segments[i - 1][1] != 0: |
|
2109 |
self.Points[i].y = (end.y + self.Points[i - 1].y) / 2 |
|
2110 |
# A point is added |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2111 |
self.Points.insert(i + 1, wx.Point(self.Points[i].x, self.Points[i].y)) |
0 | 2112 |
self.Segments.insert(i + 1, DirectionChoice((self.Segments[i][1], |
2113 |
self.Segments[i][0]), v_end, self.EndPoint[1])) |
|
2114 |
else: |
|
2115 |
# Current point is the first, and second is not mainly in the first direction |
|
2116 |
if i == 0 and product(vector(start, self.Points[1]), self.Segments[0]) < 0: |
|
2117 |
# If first and second directions aren't perpendiculars, a point is added |
|
2118 |
if product(self.Segments[0], self.Segments[1]) != 0: |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2119 |
self.Points.insert(1, wx.Point(start.x, start.y)) |
0 | 2120 |
self.Segments.insert(1, DirectionChoice((self.Segments[0][1], |
2121 |
self.Segments[0][0]), vector(start, self.Points[1]), self.Segments[1])) |
|
2122 |
else: |
|
2123 |
self.Points[1].x, self.Points[1].y = start.x, start.y |
|
2124 |
else: |
|
2125 |
# Next point is aligned with current point |
|
2126 |
if self.Segments[i][0] != 0: |
|
2127 |
self.Points[i + 1].y = self.Points[i].y |
|
2128 |
if self.Segments[i][1] != 0: |
|
2129 |
self.Points[i + 1].x = self.Points[i].x |
|
2130 |
# Current direction is updated from the new point |
|
2131 |
if product(vector(self.Points[i], self.Points[i + 1]), self.Segments[i]) < 0: |
|
2132 |
self.Segments[i] = (-self.Segments[i][0], -self.Segments[i][1]) |
|
2133 |
i += 1 |
|
2134 |
self.RefreshBoundingBox() |
|
2135 |
if realpoints: |
|
2136 |
self.RefreshRealPoints() |
|
2137 |
||
2138 |
# Verify that two consecutive points haven't the same position |
|
2139 |
def VerifyPoints(self): |
|
2140 |
points = [point for point in self.Points] |
|
2141 |
segments = [segment for segment in self.Segments] |
|
2142 |
i = 1 |
|
2143 |
while i < len(points) - 1: |
|
2144 |
if points[i] == points[i + 1] and segments[i - 1] == segments[i + 1]: |
|
2145 |
for j in xrange(2): |
|
2146 |
points.pop(i) |
|
2147 |
segments.pop(i) |
|
2148 |
else: |
|
2149 |
i += 1 |
|
2150 |
# If the wire isn't in a Ladder Diagram, save the new point list |
|
2151 |
if self.Parent.__class__.__name__ != "LD_Viewer": |
|
2152 |
self.Points = [point for point in points] |
|
2153 |
self.Segments = [segment for segment in segments] |
|
2154 |
self.RefreshBoundingBox() |
|
2155 |
self.RefreshRealPoints() |
|
2156 |
return points |
|
2157 |
||
2158 |
# Moves all the wire points except the first and the last if they are connected |
|
2159 |
def Move(self, dx, dy, endpoints = False): |
|
2160 |
for i, point in enumerate(self.Points): |
|
2161 |
if endpoints or not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
2162 |
point.x += dx |
|
2163 |
point.y += dy |
|
2164 |
self.StartPoint[0] = self.Points[0] |
|
2165 |
self.EndPoint[0] = self.Points[-1] |
|
2166 |
self.GeneratePoints() |
|
2167 |
||
2168 |
# Resize the wire from position and size given |
|
2169 |
def Resize(self, x, y, width, height): |
|
2170 |
if len(self.Points) > 1: |
|
2171 |
# Calculate the new position of each point for testing the new size |
|
2172 |
minx, miny = self.Pos.x, self.Pos.y |
|
2173 |
lastwidth, lastheight = self.Size.width, self.Size.height |
|
2174 |
for i, point in enumerate(self.RealPoints): |
|
2175 |
# If start or end point is connected, it's not calculate |
|
2176 |
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
2177 |
if i == 0: |
|
2178 |
dir = self.StartPoint[1] |
|
2179 |
elif i == len(self.Points) - 1: |
|
2180 |
dir = self.EndPoint[1] |
|
2181 |
else: |
|
2182 |
dir = (0, 0) |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2183 |
pointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0] * width / float(max(lastwidth, 1)))), |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2184 |
width - dir[0] * MIN_SEGMENT_SIZE)) |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2185 |
pointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1] * height / float(max(lastheight, 1)))), |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2186 |
height - dir[1] * MIN_SEGMENT_SIZE)) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2187 |
self.Points[i] = wx.Point(minx + x + pointx, miny + y + pointy) |
0 | 2188 |
self.StartPoint[0] = self.Points[0] |
2189 |
self.EndPoint[0] = self.Points[-1] |
|
2190 |
self.GeneratePoints(False) |
|
2191 |
# Test if the wire position or size have changed |
|
2192 |
if x != 0 and minx == self.Pos.x: |
|
2193 |
x = 0 |
|
2194 |
width = lastwidth |
|
2195 |
if y != 0 and miny == self.Pos.y: |
|
2196 |
y = 0 |
|
2197 |
height = lastwidth |
|
2198 |
if width != lastwidth and lastwidth == self.Size.width: |
|
2199 |
width = lastwidth |
|
2200 |
if height != lastheight and lastheight == self.Size.height: |
|
2201 |
height = lastheight |
|
2202 |
# Calculate the real points from the new size, it's important for |
|
2203 |
# keeping a proportionality in the points position with the size |
|
249 | 2204 |
# during a resize dragging |
0 | 2205 |
for i, point in enumerate(self.RealPoints): |
2206 |
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2207 |
point[0] = point[0] * width / float(max(lastwidth, 1)) |
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2208 |
point[1] = point[1] * height / float(max(lastheight, 1)) |
0 | 2209 |
# Calculate the correct position of the points from real points |
2210 |
for i, point in enumerate(self.RealPoints): |
|
2211 |
if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected): |
|
2212 |
if i == 0: |
|
2213 |
dir = self.StartPoint[1] |
|
2214 |
elif i == len(self.Points) - 1: |
|
2215 |
dir = self.EndPoint[1] |
|
2216 |
else: |
|
2217 |
dir = (0, 0) |
|
2218 |
realpointx = max(-dir[0] * MIN_SEGMENT_SIZE, min(int(round(point[0])), |
|
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2219 |
width - dir[0] * MIN_SEGMENT_SIZE)) |
0 | 2220 |
realpointy = max(-dir[1] * MIN_SEGMENT_SIZE, min(int(round(point[1])), |
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
180
diff
changeset
|
2221 |
height - dir[1] * MIN_SEGMENT_SIZE)) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2222 |
self.Points[i] = wx.Point(minx + x + realpointx, miny + y + realpointy) |
0 | 2223 |
self.StartPoint[0] = self.Points[0] |
2224 |
self.EndPoint[0] = self.Points[-1] |
|
2225 |
self.GeneratePoints(False) |
|
2226 |
||
2227 |
# Moves the wire start point and update the wire points |
|
2228 |
def MoveStartPoint(self, point): |
|
2229 |
if len(self.Points) > 1: |
|
2230 |
self.StartPoint[0] = point |
|
2231 |
self.Points[0] = point |
|
2232 |
self.GeneratePoints() |
|
2233 |
||
2234 |
# Changes the wire start direction and update the wire points |
|
2235 |
def SetStartPointDirection(self, dir): |
|
2236 |
if len(self.Points) > 1: |
|
2237 |
self.StartPoint[1] = dir |
|
2238 |
self.Segments[0] = dir |
|
2239 |
self.GeneratePoints() |
|
2240 |
||
2241 |
# Rotates the wire start direction by an angle of 90 degrees anticlockwise |
|
2242 |
def RotateStartPoint(self): |
|
2243 |
self.SetStartPointDirection((self.StartPoint[1][1], -self.StartPoint[1][0])) |
|
2244 |
||
2245 |
# Connects wire start point to the connector given and moves wire start point |
|
2246 |
# to given point |
|
2247 |
def ConnectStartPoint(self, point, connector): |
|
2248 |
if point: |
|
2249 |
self.MoveStartPoint(point) |
|
2250 |
self.StartConnected = connector |
|
145 | 2251 |
self.RefreshBoundingBox() |
0 | 2252 |
|
2253 |
# Unconnects wire start point |
|
2 | 2254 |
def UnConnectStartPoint(self, delete = False): |
2255 |
if delete: |
|
60 | 2256 |
self.StartConnected = None |
2 | 2257 |
self.Delete() |
60 | 2258 |
elif self.StartConnected: |
2259 |
self.StartConnected.UnConnect(self, unconnect = False) |
|
2 | 2260 |
self.StartConnected = None |
145 | 2261 |
self.RefreshBoundingBox() |
0 | 2262 |
|
2263 |
# Moves the wire end point and update the wire points |
|
2264 |
def MoveEndPoint(self, point): |
|
2265 |
if len(self.Points) > 1: |
|
2266 |
self.EndPoint[0] = point |
|
2267 |
self.Points[-1] = point |
|
2268 |
self.GeneratePoints() |
|
2269 |
||
2270 |
# Changes the wire end direction and update the wire points |
|
2271 |
def SetEndPointDirection(self, dir): |
|
2272 |
if len(self.Points) > 1: |
|
2273 |
self.EndPoint[1] = dir |
|
2274 |
self.GeneratePoints() |
|
2275 |
||
2276 |
# Rotates the wire end direction by an angle of 90 degrees anticlockwise |
|
2277 |
def RotateEndPoint(self): |
|
2278 |
self.SetEndPointDirection((self.EndPoint[1][1], -self.EndPoint[1][0])) |
|
2279 |
||
2280 |
# Connects wire end point to the connector given and moves wire end point |
|
2281 |
# to given point |
|
2282 |
def ConnectEndPoint(self, point, connector): |
|
2283 |
if point: |
|
2284 |
self.MoveEndPoint(point) |
|
2285 |
self.EndConnected = connector |
|
145 | 2286 |
self.RefreshBoundingBox() |
0 | 2287 |
|
2288 |
# Unconnects wire end point |
|
2 | 2289 |
def UnConnectEndPoint(self, delete = False): |
2290 |
if delete: |
|
60 | 2291 |
self.EndConnected = None |
2 | 2292 |
self.Delete() |
60 | 2293 |
elif self.EndConnected: |
2294 |
self.EndConnected.UnConnect(self, unconnect = False) |
|
2 | 2295 |
self.EndConnected = None |
145 | 2296 |
self.RefreshBoundingBox() |
0 | 2297 |
|
2298 |
# Moves the wire segment given by its index |
|
145 | 2299 |
def MoveSegment(self, idx, movex, movey, scaling): |
0 | 2300 |
if 0 < idx < len(self.Segments) - 1: |
2301 |
if self.Segments[idx] in (NORTH, SOUTH): |
|
112 | 2302 |
start_x = self.Points[idx].x |
145 | 2303 |
if scaling is not None: |
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2304 |
movex = round_scaling(self.Points[idx].x + movex, scaling[0]) - self.Points[idx].x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2305 |
if idx == 1 and (self.Points[1].x + movex - self.Points[0].x) * self.Segments[0][0] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2306 |
movex = round_scaling(self.Points[0].x + MIN_SEGMENT_SIZE * self.Segments[0][0], scaling[0], self.Segments[0][0]) - self.Points[idx].x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2307 |
elif idx == len(self.Segments) - 2 and (self.Points[-1].x - (self.Points[-2].x + movex)) * self.Segments[-1][0] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2308 |
movex = round_scaling(self.Points[-1].x - MIN_SEGMENT_SIZE * self.Segments[-1][0], scaling[0], -self.Segments[-1][0]) - self.Points[idx].x |
0 | 2309 |
self.Points[idx].x += movex |
2310 |
self.Points[idx + 1].x += movex |
|
112 | 2311 |
self.GeneratePoints() |
2312 |
if start_x != self.Points[idx].x: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2313 |
return self.Points[idx].x - start_x, 0 |
0 | 2314 |
elif self.Segments[idx] in (EAST, WEST): |
112 | 2315 |
start_y = self.Points[idx].y |
145 | 2316 |
if scaling is not None: |
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2317 |
movey = round_scaling(self.Points[idx].y + movey, scaling[1]) - self.Points[idx].y |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2318 |
if idx == 1 and (self.Points[1].y + movey - self.Points[0].y) * self.Segments[0][1] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2319 |
movex = round_scaling(self.Points[0].y + MIN_SEGMENT_SIZE * self.Segments[0][1], scaling[0], self.Segments[0][1]) - self.Points[idx].y |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2320 |
elif idx == len(self.Segments) - 2 and (self.Points[-1].y - (self.Points[-2].y + movey)) * self.Segments[-1][1] < MIN_SEGMENT_SIZE: |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2321 |
movey = round_scaling(self.Points[idx].y - MIN_SEGMENT_SIZE * self.Segments[-1][1], scaling[1], -self.Segments[-1][1]) - self.Points[idx].y |
0 | 2322 |
self.Points[idx].y += movey |
2323 |
self.Points[idx + 1].y += movey |
|
112 | 2324 |
self.GeneratePoints() |
2325 |
if start_y != self.Points[idx].y: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2326 |
return 0, self.Points[idx].y - start_y |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2327 |
return 0, 0 |
0 | 2328 |
|
2329 |
# Adds two points in the middle of the handled segment |
|
2330 |
def AddSegment(self): |
|
2331 |
handle_type, handle = self.Handle |
|
2332 |
if handle_type == HANDLE_SEGMENT: |
|
2333 |
segment, dir = handle |
|
321
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2334 |
if len(self.Segments) > 1: |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2335 |
pointx = self.Points[segment].x |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2336 |
pointy = self.Points[segment].y |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2337 |
if dir[0] != 0: |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2338 |
pointx = (self.Points[segment].x + self.Points[segment + 1].x) / 2 |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2339 |
if dir[1] != 0: |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2340 |
pointy = (self.Points[segment].y + self.Points[segment + 1].y) / 2 |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2341 |
self.Points.insert(segment + 1, wx.Point(pointx, pointy)) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2342 |
self.Segments.insert(segment + 1, (dir[1], dir[0])) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2343 |
self.Points.insert(segment + 2, wx.Point(pointx, pointy)) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2344 |
self.Segments.insert(segment + 2, dir) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2345 |
else: |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2346 |
p1x = p2x = self.Points[segment].x |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2347 |
p1y = p2y = self.Points[segment].y |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2348 |
if dir[0] != 0: |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2349 |
p1x = (2 * self.Points[segment].x + self.Points[segment + 1].x) / 3 |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2350 |
p2x = (self.Points[segment].x + 2 * self.Points[segment + 1].x) / 3 |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2351 |
if dir[1] != 0: |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2352 |
p1y = (2 * self.Points[segment].y + self.Points[segment + 1].y) / 3 |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2353 |
p2y = (self.Points[segment].y + 2 * self.Points[segment + 1].y) / 3 |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2354 |
self.Points.insert(segment + 1, wx.Point(p1x, p1y)) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2355 |
self.Segments.insert(segment + 1, (dir[1], dir[0])) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2356 |
self.Points.insert(segment + 2, wx.Point(p1x, p1y)) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2357 |
self.Segments.insert(segment + 2, dir) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2358 |
self.Points.insert(segment + 3, wx.Point(p2x, p2y)) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2359 |
self.Segments.insert(segment + 3, (dir[1], dir[0])) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2360 |
self.Points.insert(segment + 4, wx.Point(p2x, p2y)) |
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2361 |
self.Segments.insert(segment + 4, dir) |
0 | 2362 |
self.GeneratePoints() |
2363 |
||
2364 |
# Delete the handled segment by removing the two segment points |
|
2365 |
def DeleteSegment(self): |
|
2366 |
handle_type, handle = self.Handle |
|
2367 |
if handle_type == HANDLE_SEGMENT: |
|
2368 |
segment, dir = handle |
|
2369 |
for i in xrange(2): |
|
2370 |
self.Points.pop(segment) |
|
2371 |
self.Segments.pop(segment) |
|
2372 |
self.GeneratePoints() |
|
2373 |
self.RefreshModel() |
|
2374 |
||
2375 |
# Method called when a LeftDown event have been generated |
|
27 | 2376 |
def OnLeftDown(self, event, dc, scaling): |
2377 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 2378 |
# 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
|
2379 |
#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
|
2380 |
#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
|
2381 |
# self.Handle = (HANDLE_POINT, result) |
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
2382 |
# wx.CallAfter(self.Parent.SetCurrentCursor, 1) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
2383 |
#else: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
2384 |
# 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
|
2385 |
result = self.TestSegment(pos) |
0 | 2386 |
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
|
2387 |
if result[1] in (NORTH, SOUTH): |
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
2388 |
wx.CallAfter(self.Parent.SetCurrentCursor, 4) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
2389 |
elif result[1] in (EAST, WEST): |
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
2390 |
wx.CallAfter(self.Parent.SetCurrentCursor, 5) |
3
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
2391 |
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
|
2392 |
# Execute the default method for a graphic element |
0 | 2393 |
else: |
27 | 2394 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
0 | 2395 |
self.oldPos = pos |
2396 |
||
80 | 2397 |
# Method called when a RightUp event has been generated |
27 | 2398 |
def OnRightUp(self, event, dc, scaling): |
2399 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 2400 |
# Test if a segment has been handled |
237 | 2401 |
result = self.TestSegment(pos, True) |
0 | 2402 |
if result != None: |
2403 |
self.Handle = (HANDLE_SEGMENT, result) |
|
2404 |
# Popup the menu with special items for a wire |
|
321
5b37e16f7b2a
Adding support for adding segments on only one segment wire
lbessard
parents:
316
diff
changeset
|
2405 |
self.Parent.PopupWireMenu(0 < result[0] < len(self.Segments) - 1) |
0 | 2406 |
else: |
2407 |
# Execute the default method for a graphic element |
|
27 | 2408 |
Graphic_Element.OnRightUp(self, event, dc, scaling) |
0 | 2409 |
|
80 | 2410 |
# Method called when a LeftDClick event has been generated |
27 | 2411 |
def OnLeftDClick(self, event, dc, scaling): |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2412 |
rect = self.GetRedrawRect() |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2413 |
if event.ControlDown(): |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2414 |
direction = (self.StartPoint[1], self.EndPoint[1]) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2415 |
if direction in [(EAST, WEST), (WEST, EAST)]: |
395
d432eae889ed
Bug when aligning blocks on wire connectors without scaling defined fixed
laurent
parents:
386
diff
changeset
|
2416 |
avgy = (self.StartPoint[0].y + self.EndPoint[0].y) / 2 |
d432eae889ed
Bug when aligning blocks on wire connectors without scaling defined fixed
laurent
parents:
386
diff
changeset
|
2417 |
if scaling is not None: |
d432eae889ed
Bug when aligning blocks on wire connectors without scaling defined fixed
laurent
parents:
386
diff
changeset
|
2418 |
avgy = round(float(avgy) / scaling[1]) * scaling[1] |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2419 |
if self.StartConnected is not None: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2420 |
movey = avgy - self.StartPoint[0].y |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2421 |
startblock = self.StartConnected.GetParentBlock() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2422 |
startblock.Move(0, movey) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2423 |
startblock.RefreshModel() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2424 |
rect.Union(startblock.GetRedrawRect(0, movey)) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2425 |
else: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2426 |
self.MoveStartPoint(wx.Point(self.StartPoint[0].x, avgy)) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2427 |
if self.EndConnected is not None: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2428 |
movey = avgy - self.EndPoint[0].y |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2429 |
endblock = self.EndConnected.GetParentBlock() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2430 |
endblock.Move(0, movey) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2431 |
endblock.RefreshModel() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2432 |
rect.Union(endblock.GetRedrawRect(0, movey)) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2433 |
else: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2434 |
self.MoveEndPoint(wx.Point(self.EndPoint[0].x, avgy)) |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2435 |
self.Parent.RefreshBuffer() |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2436 |
elif direction in [(NORTH, SOUTH), (SOUTH, NORTH)]: |
395
d432eae889ed
Bug when aligning blocks on wire connectors without scaling defined fixed
laurent
parents:
386
diff
changeset
|
2437 |
avgx = (self.StartPoint[0].x + self.EndPoint[0].x) / 2 |
d432eae889ed
Bug when aligning blocks on wire connectors without scaling defined fixed
laurent
parents:
386
diff
changeset
|
2438 |
if scaling is not None: |
d432eae889ed
Bug when aligning blocks on wire connectors without scaling defined fixed
laurent
parents:
386
diff
changeset
|
2439 |
avgx = round(float(avgx) / scaling[0]) * scaling[0] |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2440 |
if self.StartConnected is not None: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2441 |
movex = avgx - self.StartPoint[0].x |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2442 |
startblock = self.StartConnected.GetParentBlock() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2443 |
startblock.Move(movex, 0) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2444 |
startblock.RefreshModel() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2445 |
rect.Union(startblock.GetRedrawRect(movex, 0)) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2446 |
else: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2447 |
self.MoveStartPoint(wx.Point(avgx, self.StartPoint[0].y)) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2448 |
if self.EndConnected is not None: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2449 |
movex = avgx - self.EndPoint[0].x |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2450 |
endblock = self.EndConnected.GetParentBlock() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2451 |
endblock.Move(movex, 0) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2452 |
endblock.RefreshModel() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2453 |
rect.Union(endblock.GetRedrawRect(movex, 0)) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2454 |
else: |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2455 |
self.MoveEndPoint(wx.Point(avgx, self.EndPoint[0].y)) |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2456 |
self.Parent.RefreshBuffer() |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2457 |
else: |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2458 |
self.ResetPoints() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2459 |
self.GeneratePoints() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2460 |
self.RefreshModel() |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2461 |
self.Parent.RefreshBuffer() |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2462 |
rect.Union(self.GetRedrawRect()) |
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2463 |
self.Parent.RefreshRect(self.Parent.GetScrolledRect(rect), False) |
0 | 2464 |
|
80 | 2465 |
# Method called when a Motion event has been generated |
27 | 2466 |
def OnMotion(self, event, dc, scaling): |
2467 |
pos = GetScaledEventPosition(event, dc, scaling) |
|
0 | 2468 |
if not event.Dragging(): |
2469 |
# Test if a segment has been handled |
|
2470 |
result = self.TestSegment(pos) |
|
2471 |
if result: |
|
2472 |
if result[1] in (NORTH, SOUTH): |
|
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
2473 |
wx.CallAfter(self.Parent.SetCurrentCursor, 4) |
0 | 2474 |
elif result[1] in (EAST, WEST): |
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
372
diff
changeset
|
2475 |
wx.CallAfter(self.Parent.SetCurrentCursor, 5) |
144 | 2476 |
return 0, 0 |
0 | 2477 |
else: |
2478 |
# 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
|
2479 |
#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
|
2480 |
#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
|
2481 |
# 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
|
2482 |
# 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
|
2483 |
# 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
|
2484 |
# 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
|
2485 |
#else: |
86ccc89d7b0b
FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents:
2
diff
changeset
|
2486 |
# 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
|
2487 |
# 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
|
2488 |
# Execute the default method for a graphic element |
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
2489 |
return Graphic_Element.OnMotion(self, event, dc, scaling) |
0 | 2490 |
else: |
2491 |
# Execute the default method for a graphic element |
|
90
2245e8776086
Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents:
80
diff
changeset
|
2492 |
return Graphic_Element.OnMotion(self, event, dc, scaling) |
0 | 2493 |
|
2494 |
# Refreshes the wire state according to move defined and handle selected |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2495 |
def ProcessDragging(self, movex, movey, event, scaling): |
0 | 2496 |
handle_type, handle = self.Handle |
2497 |
# A point has been handled |
|
2498 |
if handle_type == HANDLE_POINT: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2499 |
movex = max(-self.Points[handle].x + POINT_RADIUS, movex) |
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2500 |
movey = max(-self.Points[handle].y + POINT_RADIUS, movey) |
145 | 2501 |
if scaling is not None: |
331
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2502 |
movex = round_scaling(self.Points[handle].x + movex, scaling[0]) - self.Points[handle].x |
9106d66bd204
Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents:
329
diff
changeset
|
2503 |
movey = round_scaling(self.Points[handle].y + movey, scaling[1]) - self.Points[handle].y |
0 | 2504 |
# Try to connect point to a connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2505 |
new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey) |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
2506 |
connector = self.Parent.FindBlockConnector(new_pos, self.GetConnectionDirection()) |
0 | 2507 |
if connector: |
339 | 2508 |
if handle == 0 and self.EndConnected != connector: |
2509 |
if connector.IsCompatible(self.GetEndConnectedType()): |
|
2510 |
connector.HighlightParentBlock(True) |
|
2511 |
connector.Connect((self, handle)) |
|
2512 |
self.SetStartPointDirection(connector.GetDirection()) |
|
2513 |
self.ConnectStartPoint(connector.GetPosition(), connector) |
|
2514 |
pos = connector.GetPosition() |
|
2515 |
movex = pos.x - self.oldPos.x |
|
2516 |
movey = pos.y - self.oldPos.y |
|
2517 |
self.Dragging = False |
|
2518 |
else: |
|
2519 |
self.SetValid(False) |
|
2520 |
self.MoveStartPoint(new_pos) |
|
2521 |
elif handle != 0 and self.StartConnected != connector: |
|
2522 |
if connector.IsCompatible(self.GetStartConnectedType()): |
|
2523 |
connector.HighlightParentBlock(True) |
|
2524 |
connector.Connect((self, handle)) |
|
2525 |
self.SetEndPointDirection(connector.GetDirection()) |
|
2526 |
self.ConnectEndPoint(connector.GetPosition(), connector) |
|
2527 |
pos = connector.GetPosition() |
|
2528 |
movex = pos.x - self.oldPos.x |
|
2529 |
movey = pos.y - self.oldPos.y |
|
2530 |
self.Dragging = False |
|
2531 |
else: |
|
2532 |
self.SetValid(False) |
|
2533 |
self.MoveEndPoint(new_pos) |
|
0 | 2534 |
elif handle == 0: |
2535 |
self.MoveStartPoint(new_pos) |
|
2536 |
else: |
|
2537 |
self.MoveEndPoint(new_pos) |
|
2538 |
# If there is no connector, move the point |
|
2539 |
elif handle == 0: |
|
339 | 2540 |
self.SetValid(True) |
0 | 2541 |
if self.StartConnected: |
339 | 2542 |
self.StartConnected.HighlightParentBlock(False) |
0 | 2543 |
self.UnConnectStartPoint() |
2544 |
self.MoveStartPoint(new_pos) |
|
2545 |
else: |
|
339 | 2546 |
self.SetValid(True) |
0 | 2547 |
if self.EndConnected: |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2548 |
self.EndConnected.HighlightParentBlock(False) |
0 | 2549 |
self.UnConnectEndPoint() |
2550 |
self.MoveEndPoint(new_pos) |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
112
diff
changeset
|
2551 |
return movex, movey |
0 | 2552 |
# A segment has been handled, move a segment |
2553 |
elif handle_type == HANDLE_SEGMENT: |
|
145 | 2554 |
return self.MoveSegment(handle[0], movex, movey, scaling) |
0 | 2555 |
# Execute the default method for a graphic element |
2556 |
else: |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
321
diff
changeset
|
2557 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
0 | 2558 |
|
2559 |
# Refreshes the wire model |
|
2560 |
def RefreshModel(self, move=True): |
|
2561 |
if self.StartConnected and self.StartPoint[1] in [WEST, NORTH]: |
|
2562 |
self.StartConnected.RefreshParentBlock() |
|
2563 |
if self.EndConnected and self.EndPoint[1] in [WEST, NORTH]: |
|
2564 |
self.EndConnected.RefreshParentBlock() |
|
2565 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2566 |
# 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
|
2567 |
def DrawHighlightment(self, dc): |
144 | 2568 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
2569 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
2570 |
dc.SetLogicalFunction(wx.AND) |
|
2571 |
# Draw the start and end points if they are not connected or the mouse is over them |
|
2572 |
if len(self.Points) > 0 and (not self.StartConnected or self.OverStart): |
|
2573 |
dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS + 2) |
|
2574 |
if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd): |
|
2575 |
dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS + 2) |
|
2576 |
for i in xrange(len(self.Points) - 1): |
|
2577 |
posx = min(self.Points[i].x, self.Points[i + 1].x) - 2 |
|
2578 |
posy = min(self.Points[i].y, self.Points[i + 1].y) - 2 |
|
2579 |
width = abs(self.Points[i + 1].x - self.Points[i].x) + 5 |
|
2580 |
height = abs(self.Points[i + 1].y - self.Points[i].y) + 5 |
|
2581 |
dc.DrawRectangle(posx, posy, width, height) |
|
145 | 2582 |
dc.SetLogicalFunction(wx.COPY) |
144 | 2583 |
if self.StartConnected is not None: |
2584 |
self.StartConnected.DrawHighlightment(dc) |
|
145 | 2585 |
self.StartConnected.Draw(dc) |
144 | 2586 |
if self.EndConnected is not None: |
2587 |
self.EndConnected.DrawHighlightment(dc) |
|
145 | 2588 |
self.EndConnected.Draw(dc) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2589 |
|
0 | 2590 |
# Draws the wire lines and points |
2591 |
def Draw(self, dc): |
|
144 | 2592 |
Graphic_Element.Draw(self, dc) |
249 | 2593 |
if not self.Valid: |
2594 |
dc.SetPen(wx.RED_PEN) |
|
339 | 2595 |
dc.SetBrush(wx.RED_BRUSH) |
249 | 2596 |
elif isinstance(self.Value, BooleanType) and self.Value: |
2597 |
dc.SetPen(wx.GREEN_PEN) |
|
339 | 2598 |
dc.SetBrush(wx.GREEN_BRUSH) |
253 | 2599 |
elif self.Value == "undefined": |
2600 |
dc.SetPen(wx.Pen(wx.NamedColour("orange"))) |
|
339 | 2601 |
dc.SetBrush(wx.Brush(wx.NamedColour("orange"))) |
249 | 2602 |
else: |
222
8ce5c2635976
Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents:
213
diff
changeset
|
2603 |
dc.SetPen(wx.BLACK_PEN) |
339 | 2604 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 2605 |
# Draw the start and end points if they are not connected or the mouse is over them |
2606 |
if len(self.Points) > 0 and (not self.StartConnected or self.OverStart): |
|
2607 |
dc.DrawCircle(self.Points[0].x, self.Points[0].y, POINT_RADIUS) |
|
2608 |
if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd): |
|
2609 |
dc.DrawCircle(self.Points[-1].x, self.Points[-1].y, POINT_RADIUS) |
|
2610 |
# Draw the wire lines and the last point (it seems that DrawLines stop before the last point) |
|
2611 |
dc.DrawLines(self.Points) |
|
2612 |
dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
|
2613 |
# Draw the segment selected in red |
|
399
3b9e0b092298
Bug drawing element selection state on printed documents fixed
laurent
parents:
398
diff
changeset
|
2614 |
if not getattr(dc, "printing", False) and self.SelectedSegment is not None: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2615 |
dc.SetPen(wx.RED_PEN) |
0 | 2616 |
dc.DrawLine(self.Points[self.SelectedSegment].x, self.Points[self.SelectedSegment].y, |
2617 |
self.Points[self.SelectedSegment + 1].x, self.Points[self.SelectedSegment + 1].y) |
|
2618 |
if self.SelectedSegment == len(self.Segments) - 1: |
|
2619 |
dc.DrawPoint(self.Points[-1].x, self.Points[-1].y) |
|
253 | 2620 |
if self.Value is not None and not isinstance(self.Value, BooleanType) and self.Value != "undefined": |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
358
diff
changeset
|
2621 |
dc.SetFont(self.Parent.GetMiniFont()) |
249 | 2622 |
dc.SetTextForeground(wx.NamedColour("purple")) |
2623 |
width, height = self.ValueSize |
|
2624 |
if self.BoundingBox[2] > width * 4 or self.BoundingBox[3] > height * 4: |
|
253 | 2625 |
x = self.Points[0].x + width * (self.StartPoint[1][0] - 1) / 2 |
249 | 2626 |
y = self.Points[0].y + height * (self.StartPoint[1][1] - 1) / 2 |
253 | 2627 |
dc.DrawText(self.ComputedValue, x, y) |
2628 |
x = self.Points[-1].x + width * (self.EndPoint[1][0] - 1) / 2 |
|
249 | 2629 |
y = self.Points[-1].y + height * (self.EndPoint[1][1] - 1) / 2 |
253 | 2630 |
dc.DrawText(self.ComputedValue, x, y) |
249 | 2631 |
else: |
2632 |
middle = len(self.Segments) / 2 + len(self.Segments) % 2 - 1 |
|
2633 |
x = (self.Points[middle].x + self.Points[middle + 1].x - width) / 2 |
|
2634 |
y = (self.Points[middle].y + self.Points[middle + 1].y - height) / 2 |
|
253 | 2635 |
dc.DrawText(self.ComputedValue, x, y) |
249 | 2636 |
dc.SetFont(self.Parent.GetFont()) |
2637 |
dc.SetTextForeground(wx.BLACK) |
|
144 | 2638 |
|
0 | 2639 |
|
2640 |
#------------------------------------------------------------------------------- |
|
2641 |
# Graphic comment element |
|
2642 |
#------------------------------------------------------------------------------- |
|
2643 |
||
2644 |
""" |
|
2645 |
Class that implements a comment |
|
2646 |
""" |
|
2647 |
||
2648 |
class Comment(Graphic_Element): |
|
2649 |
||
2650 |
# Create a new comment |
|
2651 |
def __init__(self, parent, content, id = None): |
|
2652 |
Graphic_Element.__init__(self, parent) |
|
2653 |
self.Id = id |
|
2654 |
self.Content = content |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2655 |
self.Pos = wx.Point(0, 0) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2656 |
self.Size = wx.Size(0, 0) |
0 | 2657 |
|
112 | 2658 |
# Make a clone of this comment |
162 | 2659 |
def Clone(self, parent, id = None, pos = None): |
2660 |
comment = Comment(parent, self.Content, id) |
|
145 | 2661 |
if pos is not None: |
2662 |
comment.SetPosition(pos.x, pos.y) |
|
112 | 2663 |
comment.SetSize(self.Size[0], self.Size[1]) |
2664 |
return comment |
|
2665 |
||
0 | 2666 |
# Method for keeping compatibility with others |
2667 |
def Clean(self): |
|
2668 |
pass |
|
2669 |
||
2670 |
# Delete this comment by calling the corresponding method |
|
2671 |
def Delete(self): |
|
2672 |
self.Parent.DeleteComment(self) |
|
2673 |
||
2674 |
# Refresh the comment bounding box |
|
2675 |
def RefreshBoundingBox(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2676 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 2677 |
|
2678 |
# Changes the comment size |
|
2679 |
def SetSize(self, width, height): |
|
2680 |
self.Size.SetWidth(width) |
|
2681 |
self.Size.SetHeight(height) |
|
2682 |
self.RefreshBoundingBox() |
|
2683 |
||
2684 |
# Returns the comment size |
|
2685 |
def GetSize(self): |
|
2686 |
return self.Size.GetWidth(), self.Size.GetHeight() |
|
2687 |
||
2688 |
# Returns the comment minimum size |
|
2689 |
def GetMinSize(self): |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2690 |
dc = wx.ClientDC(self.Parent) |
0 | 2691 |
min_width = 0 |
2692 |
min_height = 0 |
|
2693 |
# The comment minimum size is the maximum size of words in the content |
|
2694 |
for line in self.Content.splitlines(): |
|
2695 |
for word in line.split(" "): |
|
2696 |
wordwidth, wordheight = dc.GetTextExtent(word) |
|
2697 |
min_width = max(min_width, wordwidth) |
|
2698 |
min_height = max(min_height, wordheight) |
|
2699 |
return min_width + 20, min_height + 20 |
|
2700 |
||
2701 |
# Changes the comment position |
|
2702 |
def SetPosition(self, x, y): |
|
2703 |
self.Pos.x = x |
|
2704 |
self.Pos.y = y |
|
2705 |
self.RefreshBoundingBox() |
|
2706 |
||
2707 |
# Changes the comment content |
|
2708 |
def SetContent(self, content): |
|
2709 |
self.Content = content |
|
2710 |
min_width, min_height = self.GetMinSize() |
|
2711 |
self.Size[0] = max(self.Size[0], min_width) |
|
2712 |
self.Size[1] = max(self.Size[1], min_height) |
|
2713 |
self.RefreshBoundingBox() |
|
2714 |
||
2715 |
# Returns the comment content |
|
2716 |
def GetContent(self): |
|
2717 |
return self.Content |
|
2718 |
||
2719 |
# Returns the comment position |
|
2720 |
def GetPosition(self): |
|
2721 |
return self.Pos.x, self.Pos.y |
|
2722 |
||
2723 |
# Moves the comment |
|
2724 |
def Move(self, dx, dy, connected = True): |
|
2725 |
self.Pos.x += dx |
|
2726 |
self.Pos.y += dy |
|
2727 |
self.RefreshBoundingBox() |
|
2728 |
||
2729 |
# Resizes the comment with the position and the size given |
|
2730 |
def Resize(self, x, y, width, height): |
|
2731 |
self.Move(x, y) |
|
2732 |
self.SetSize(width, height) |
|
2733 |
||
2734 |
# Method called when a RightUp event have been generated |
|
27 | 2735 |
def OnRightUp(self, event, dc, scaling): |
0 | 2736 |
# Popup the default menu |
2737 |
self.Parent.PopupDefaultMenu() |
|
2738 |
||
2739 |
# Refreshes the comment model |
|
2740 |
def RefreshModel(self, move=True): |
|
2741 |
self.Parent.RefreshCommentModel(self) |
|
2742 |
||
2743 |
# Method called when a LeftDClick event have been generated |
|
27 | 2744 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 2745 |
# Edit the comment content |
2746 |
self.Parent.EditCommentContent(self) |
|
2747 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2748 |
# 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
|
2749 |
def DrawHighlightment(self, dc): |
144 | 2750 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
2751 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
2752 |
dc.SetLogicalFunction(wx.AND) |
|
2753 |
polygon = [wx.Point(self.Pos.x - 2, self.Pos.y - 2), |
|
2754 |
wx.Point(self.Pos.x + self.Size[0] - 8, self.Pos.y - 2), |
|
2755 |
wx.Point(self.Pos.x + self.Size[0] + 2, self.Pos.y + 8), |
|
2756 |
wx.Point(self.Pos.x + self.Size[0] + 2, self.Pos.y + self.Size[1] + 2), |
|
2757 |
wx.Point(self.Pos.x - 2, self.Pos.y + self.Size[1] + 2)] |
|
2758 |
dc.DrawPolygon(polygon) |
|
2759 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2760 |
|
0 | 2761 |
# Draws the comment and its content |
2762 |
def Draw(self, dc): |
|
144 | 2763 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2764 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2765 |
dc.SetBrush(wx.WHITE_BRUSH) |
0 | 2766 |
# Draws the comment shape |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2767 |
polygon = [wx.Point(self.Pos.x, self.Pos.y), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2768 |
wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2769 |
wx.Point(self.Pos.x + self.Size[0], self.Pos.y + 10), |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2770 |
wx.Point(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1]), |
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
2771 |
wx.Point(self.Pos.x, self.Pos.y + self.Size[1])] |
0 | 2772 |
dc.DrawPolygon(polygon) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2773 |
lines = [wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2774 |
wx.Point(self.Pos.x + self.Size[0] - 10, self.Pos.y + 10), |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
60
diff
changeset
|
2775 |
wx.Point(self.Pos.x + self.Size[0], self.Pos.y + 10)] |
0 | 2776 |
dc.DrawLines(lines) |
2777 |
# Draws the comment content |
|
2778 |
y = self.Pos.y + 10 |
|
2779 |
for line in self.Content.splitlines(): |
|
2780 |
first = True |
|
353 | 2781 |
linetext = "" |
0 | 2782 |
words = line.split(" ") |
2783 |
for i, word in enumerate(words): |
|
2784 |
if first: |
|
2785 |
test = word |
|
2786 |
else: |
|
2787 |
test = linetext + " " + word |
|
2788 |
wordwidth, wordheight = dc.GetTextExtent(test) |
|
2789 |
if y + wordheight > self.Pos.y + self.Size[1] - 10: |
|
2790 |
break |
|
386 | 2791 |
if wordwidth < self.Size[0] - 20: |
2792 |
if i < len(words) - 1: |
|
2793 |
linetext = test |
|
2794 |
first = False |
|
2795 |
else: |
|
2796 |
dc.DrawText(test, self.Pos.x + 10, y) |
|
2797 |
y += wordheight + 5 |
|
0 | 2798 |
else: |
386 | 2799 |
dc.DrawText(linetext, self.Pos.x + 10, y) |
2800 |
if i == len(words) - 1: |
|
2801 |
y += wordheight + 5 |
|
2802 |
if y + wordheight > self.Pos.y + self.Size[1] - 10: |
|
2803 |
break |
|
2804 |
dc.DrawText(word, self.Pos.x + 10, y) |
|
0 | 2805 |
else: |
386 | 2806 |
linetext = word |
0 | 2807 |
y += wordheight + 5 |
2808 |
if y + wordheight > self.Pos.y + self.Size[1] - 10: |
|
2809 |
break |
|
249 | 2810 |