author | laurent |
Wed, 16 Nov 2011 23:31:57 +0100 | |
changeset 587 | 98445f90f45d |
parent 566 | 6014ef82a98a |
child 633 | 3536f4469cde |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 |
#based on the plcopen standard. |
|
6 |
# |
|
58 | 7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
0 | 8 |
# |
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
5 | 12 |
#modify it under the terms of the GNU General Public |
0 | 13 |
#License as published by the Free Software Foundation; either |
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
58 | 19 |
#General Public License for more details. |
0 | 20 |
# |
5 | 21 |
#You should have received a copy of the GNU General Public |
0 | 22 |
#License along with this library; if not, write to the Free Software |
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import wx |
|
26 |
||
27 |
from GraphicCommons import * |
|
28 |
from plcopen.structures import * |
|
29 |
||
30 |
#------------------------------------------------------------------------------- |
|
31 |
# Ladder Diagram PowerRail |
|
32 |
#------------------------------------------------------------------------------- |
|
33 |
||
34 |
""" |
|
35 |
Class that implements the graphic representation of a power rail |
|
36 |
""" |
|
37 |
||
38 |
class LD_PowerRail(Graphic_Element): |
|
39 |
||
40 |
# Create a new power rail |
|
550 | 41 |
def __init__(self, parent, type, id=None, connectors=1): |
0 | 42 |
Graphic_Element.__init__(self, parent) |
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
43 |
self.Type = None |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
44 |
self.Connectors = [] |
71 | 45 |
self.RealConnectors = None |
0 | 46 |
self.Id = id |
27 | 47 |
self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2] |
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
48 |
self.SetType(type, connectors) |
0 | 49 |
|
249 | 50 |
def Flush(self): |
51 |
for connector in self.Connectors: |
|
550 | 52 |
connector.Flush() |
0 | 53 |
self.Connectors = [] |
54 |
||
112 | 55 |
# Make a clone of this LD_PowerRail |
162 | 56 |
def Clone(self, parent, id = None, pos = None): |
57 |
powerrail = LD_PowerRail(parent, self.Type, id) |
|
112 | 58 |
powerrail.SetSize(self.Size[0], self.Size[1]) |
59 |
if pos is not None: |
|
60 |
powerrail.SetPosition(pos.x, pos.y) |
|
283 | 61 |
else: |
62 |
powerrail.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 63 |
powerrail.Connectors = [] |
64 |
for connector in self.Connectors: |
|
550 | 65 |
powerrail.Connectors.append(connector.Clone(powerrail)) |
112 | 66 |
return powerrail |
67 |
||
283 | 68 |
def GetConnectorTranslation(self, element): |
550 | 69 |
return dict(zip([connector for connector in self.Connectors], |
70 |
[connector for connector in element.Connectors])) |
|
283 | 71 |
|
144 | 72 |
# Returns the RedrawRect |
73 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
74 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
75 |
for connector in self.Connectors: |
|
550 | 76 |
rect = rect.Union(connector.GetRedrawRect(movex, movey)) |
144 | 77 |
if movex != 0 or movey != 0: |
78 |
for connector in self.Connectors: |
|
550 | 79 |
if connector.IsConnected(): |
144 | 80 |
rect = rect.Union(connector.GetConnectedRedrawRect(movex, movey)) |
81 |
return rect |
|
82 |
||
0 | 83 |
# Forbids to change the power rail size |
84 |
def SetSize(self, width, height): |
|
42 | 85 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 86 |
Graphic_Element.SetSize(self, width, height) |
550 | 87 |
else: |
88 |
Graphic_Element.SetSize(self, LD_POWERRAIL_WIDTH, height) |
|
89 |
self.RefreshConnectors() |
|
0 | 90 |
|
91 |
# Forbids to select a power rail |
|
92 |
def HitTest(self, pt): |
|
42 | 93 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
94 |
return Graphic_Element.HitTest(self, pt) or self.TestConnector(pt, exclude=False) != None |
0 | 95 |
return False |
96 |
||
42 | 97 |
# Forbids to select a power rail |
98 |
def IsInSelection(self, rect): |
|
99 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
100 |
return Graphic_Element.IsInSelection(self, rect) |
42 | 101 |
return False |
102 |
||
0 | 103 |
# Deletes this power rail by calling the appropriate method |
104 |
def Delete(self): |
|
105 |
self.Parent.DeletePowerRail(self) |
|
106 |
||
107 |
# Unconnect all connectors |
|
108 |
def Clean(self): |
|
109 |
for connector in self.Connectors: |
|
550 | 110 |
connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 111 |
|
112 |
# Refresh the power rail bounding box |
|
113 |
def RefreshBoundingBox(self): |
|
144 | 114 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 115 |
|
116 |
# Refresh the power rail size |
|
117 |
def RefreshSize(self): |
|
550 | 118 |
self.Size = wx.Size(LD_POWERRAIL_WIDTH, max(LD_LINE_SIZE * len(self.Connectors), self.Size[1])) |
0 | 119 |
self.RefreshBoundingBox() |
120 |
||
27 | 121 |
# Returns the block minimum size |
122 |
def GetMinSize(self): |
|
550 | 123 |
return LD_POWERRAIL_WIDTH, self.Extensions[0] + self.Extensions[1] |
27 | 124 |
|
0 | 125 |
# Add a connector or a blank to this power rail at the last place |
550 | 126 |
def AddConnector(self): |
127 |
self.InsertConnector(len(self.Connectors)) |
|
0 | 128 |
|
129 |
# Add a connector or a blank to this power rail at the place given |
|
550 | 130 |
def InsertConnector(self, idx): |
131 |
if self.Type == LEFTRAIL: |
|
132 |
connector = Connector(self, "", "BOOL", wx.Point(self.Size[0], 0), EAST) |
|
133 |
elif self.Type == RIGHTRAIL: |
|
134 |
connector = Connector(self, "", "BOOL", wx.Point(0, 0), WEST) |
|
135 |
self.Connectors.insert(idx, connector) |
|
0 | 136 |
self.RefreshSize() |
137 |
self.RefreshConnectors() |
|
138 |
||
27 | 139 |
# Moves the divergence connector given |
140 |
def MoveConnector(self, connector, movey): |
|
141 |
position = connector.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
142 |
connector.SetPosition(wx.Point(position.x, position.y + movey)) |
27 | 143 |
miny = self.Size[1] |
144 |
maxy = 0 |
|
145 |
for connect in self.Connectors: |
|
146 |
connect_pos = connect.GetRelPosition() |
|
80 | 147 |
miny = min(miny, connect_pos.y - self.Extensions[0]) |
148 |
maxy = max(maxy, connect_pos.y - self.Extensions[0]) |
|
149 |
min_pos = self.Pos.y + miny |
|
27 | 150 |
self.Pos.y = min(min_pos, self.Pos.y) |
151 |
if min_pos == self.Pos.y: |
|
152 |
for connect in self.Connectors: |
|
153 |
connect_pos = connect.GetRelPosition() |
|
80 | 154 |
connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny)) |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
96
diff
changeset
|
155 |
self.Connectors.sort(lambda x, y: x.Pos.y.__cmp__(y.Pos.y)) |
80 | 156 |
maxy = 0 |
157 |
for connect in self.Connectors: |
|
158 |
connect_pos = connect.GetRelPosition() |
|
159 |
maxy = max(maxy, connect_pos.y) |
|
160 |
self.Size[1] = max(maxy + self.Extensions[1], self.Size[1]) |
|
27 | 161 |
connector.MoveConnected() |
162 |
self.RefreshBoundingBox() |
|
163 |
||
0 | 164 |
# Returns the index in connectors list for the connector given |
165 |
def GetConnectorIndex(self, connector): |
|
166 |
if connector in self.Connectors: |
|
167 |
return self.Connectors.index(connector) |
|
168 |
return None |
|
169 |
||
170 |
# Delete the connector or blank from connectors list at the index given |
|
171 |
def DeleteConnector(self, idx): |
|
172 |
self.Connectors.pop(idx) |
|
173 |
self.RefreshConnectors() |
|
174 |
self.RefreshSize() |
|
175 |
||
176 |
# Refresh the positions of the power rail connectors |
|
177 |
def RefreshConnectors(self): |
|
145 | 178 |
scaling = self.Parent.GetScaling() |
550 | 179 |
height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
180 |
interval = float(height) / float(max(len(self.Connectors) - 1, 1)) |
|
181 |
for i, connector in enumerate(self.Connectors): |
|
182 |
if self.RealConnectors: |
|
183 |
position = self.Extensions[0] + int(round(self.RealConnectors[i] * height)) |
|
184 |
else: |
|
185 |
position = self.Extensions[0] + int(round(i * interval)) |
|
186 |
if scaling is not None: |
|
187 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
188 |
if self.Type == LEFTRAIL: |
|
189 |
connector.SetPosition(wx.Point(self.Size[0], position)) |
|
190 |
elif self.Type == RIGHTRAIL: |
|
191 |
connector.SetPosition(wx.Point(0, position)) |
|
0 | 192 |
self.RefreshConnected() |
193 |
||
7 | 194 |
# Refresh the position of wires connected to power rail |
0 | 195 |
def RefreshConnected(self, exclude = []): |
196 |
for connector in self.Connectors: |
|
550 | 197 |
connector.MoveConnected(exclude) |
0 | 198 |
|
199 |
# Returns the power rail connector that starts with the point given if it exists |
|
27 | 200 |
def GetConnector(self, position, name = None): |
201 |
# if a name is given |
|
202 |
if name: |
|
203 |
# Test each connector if it exists |
|
204 |
for connector in self.Connectors: |
|
550 | 205 |
if name == connector.GetName(): |
27 | 206 |
return connector |
537
a31bf722aa82
Fix wire disappearing when wire tip and connector are not exactly at the same position fixed.
laurent
parents:
508
diff
changeset
|
207 |
return self.FindNearestConnector(position, [connector for connector in self.Connectors if connector is not None]) |
0 | 208 |
|
209 |
# Returns all the power rail connectors |
|
210 |
def GetConnectors(self): |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
211 |
connectors = [connector for connector in self.Connectors if connector] |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
212 |
if self.Type == LEFTRAIL: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
213 |
return {"inputs": [], "outputs": connectors} |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
214 |
else: |
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
215 |
return {"inputs": connectors, "outputs": []} |
0 | 216 |
|
217 |
# Test if point given is on one of the power rail connectors |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
218 |
def TestConnector(self, pt, direction = None, exclude = True): |
0 | 219 |
for connector in self.Connectors: |
550 | 220 |
if connector.TestPoint(pt, direction, exclude): |
0 | 221 |
return connector |
222 |
return None |
|
223 |
||
224 |
# Returns the power rail type |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
225 |
def SetType(self, type, connectors): |
550 | 226 |
if type != self.Type or len(self.Connectors) != connectors: |
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
227 |
# Create a connector or a blank according to 'connectors' and add it in |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
228 |
# the connectors list |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
229 |
self.Type = type |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
230 |
self.Clean() |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
231 |
self.Connectors = [] |
550 | 232 |
for connector in xrange(connectors): |
233 |
self.AddConnector() |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
234 |
self.RefreshSize() |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
235 |
|
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
236 |
# Returns the power rail type |
0 | 237 |
def GetType(self): |
238 |
return self.Type |
|
239 |
||
27 | 240 |
# Method called when a LeftDown event have been generated |
241 |
def OnLeftDown(self, event, dc, scaling): |
|
145 | 242 |
self.RealConnectors = [] |
243 |
height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
254 | 244 |
if height > 0: |
245 |
for connector in self.Connectors: |
|
246 |
position = connector.GetRelPosition() |
|
247 |
self.RealConnectors.append(max(0., min(float(position.y - self.Extensions[0]) / float(height), 1.))) |
|
248 |
elif len(self.Connectors) > 1: |
|
249 |
self.RealConnectors = map(lambda x : x * 1 / (len(self.Connectors) - 1), xrange(len(self.Connectors))) |
|
250 |
else: |
|
251 |
self.RealConnectors = [0.5] |
|
145 | 252 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
253 |
||
254 |
# Method called when a LeftUp event have been generated |
|
255 |
def OnLeftUp(self, event, dc, scaling): |
|
256 |
Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
257 |
self.RealConnectors = None |
|
258 |
||
259 |
# Method called when a LeftDown event have been generated |
|
260 |
def OnRightDown(self, event, dc, scaling): |
|
27 | 261 |
pos = GetScaledEventPosition(event, dc, scaling) |
262 |
# Test if a connector have been handled |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
263 |
connector = self.TestConnector(pos, exclude=False) |
27 | 264 |
if connector: |
265 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
381
98890d848701
Redefine cursor switching procedure in graphic viewers
laurent
parents:
379
diff
changeset
|
266 |
wx.CallAfter(self.Parent.SetCurrentCursor, 1) |
27 | 267 |
self.Selected = False |
268 |
# Initializes the last position |
|
269 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
|
270 |
else: |
|
145 | 271 |
Graphic_Element.OnRightDown(self, event, dc, scaling) |
272 |
||
273 |
# Method called when a LeftDClick event have been generated |
|
274 |
def OnLeftDClick(self, event, dc, scaling): |
|
275 |
# Edit the powerrail properties |
|
276 |
self.Parent.EditPowerRailContent(self) |
|
277 |
||
278 |
# Method called when a RightUp event have been generated |
|
279 |
def OnRightUp(self, event, dc, scaling): |
|
27 | 280 |
handle_type, handle = self.Handle |
281 |
if handle_type == HANDLE_CONNECTOR: |
|
282 |
wires = handle.GetWires() |
|
80 | 283 |
if len(wires) == 1: |
284 |
if handle == wires[0][0].StartConnected: |
|
285 |
block = wires[0][0].EndConnected.GetParentBlock() |
|
286 |
else: |
|
287 |
block = wires[0][0].StartConnected.GetParentBlock() |
|
288 |
block.RefreshModel(False) |
|
145 | 289 |
Graphic_Element.OnRightUp(self, event, dc, scaling) |
290 |
else: |
|
291 |
self.Parent.PopupDefaultMenu() |
|
27 | 292 |
|
175 | 293 |
def Resize(self, x, y, width, height): |
294 |
self.Move(x, y) |
|
254 | 295 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
296 |
self.SetSize(width, height) |
|
297 |
else: |
|
298 |
self.SetSize(LD_POWERRAIL_WIDTH, height) |
|
175 | 299 |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
96
diff
changeset
|
300 |
# Refreshes the powerrail state according to move defined and handle selected |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
283
diff
changeset
|
301 |
def ProcessDragging(self, movex, movey, event, scaling): |
27 | 302 |
handle_type, handle = self.Handle |
303 |
# A connector has been handled |
|
304 |
if handle_type == HANDLE_CONNECTOR: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
305 |
movey = max(-self.BoundingBox.y, movey) |
145 | 306 |
if scaling is not None: |
307 |
position = handle.GetRelPosition() |
|
308 |
movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y |
|
27 | 309 |
self.MoveConnector(handle, movey) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
310 |
return 0, movey |
554 | 311 |
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
283
diff
changeset
|
312 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling) |
554 | 313 |
return 0, 0 |
27 | 314 |
|
0 | 315 |
# Refreshes the power rail model |
316 |
def RefreshModel(self, move=True): |
|
317 |
self.Parent.RefreshPowerRailModel(self) |
|
318 |
# If power rail has moved and power rail is of type LEFT, refresh the model |
|
319 |
# of wires connected to connectors |
|
320 |
if move and self.Type == LEFTRAIL: |
|
321 |
for connector in self.Connectors: |
|
550 | 322 |
connector.RefreshWires() |
0 | 323 |
|
324 |
# Draws power rail |
|
325 |
def Draw(self, dc): |
|
144 | 326 |
Graphic_Element.Draw(self, dc) |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
327 |
dc.SetPen(MiterPen(wx.BLACK)) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
328 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 329 |
# Draw a rectangle with the power rail size |
175 | 330 |
if self.Type == LEFTRAIL: |
331 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - LD_POWERRAIL_WIDTH, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1) |
|
332 |
else: |
|
333 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1) |
|
0 | 334 |
# Draw connectors |
335 |
for connector in self.Connectors: |
|
550 | 336 |
connector.Draw(dc) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
337 |
|
0 | 338 |
|
339 |
#------------------------------------------------------------------------------- |
|
340 |
# Ladder Diagram Contact |
|
341 |
#------------------------------------------------------------------------------- |
|
342 |
||
343 |
""" |
|
344 |
Class that implements the graphic representation of a contact |
|
345 |
""" |
|
346 |
||
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
360
diff
changeset
|
347 |
class LD_Contact(Graphic_Element, DebugDataConsumer): |
0 | 348 |
|
349 |
# Create a new contact |
|
350 |
def __init__(self, parent, type, name, id = None): |
|
351 |
Graphic_Element.__init__(self, parent) |
|
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
360
diff
changeset
|
352 |
DebugDataConsumer.__init__(self) |
0 | 353 |
self.Type = type |
354 |
self.Name = name |
|
355 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
356 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
357 |
self.Highlights = {} |
0 | 358 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
359 |
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
360 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
249 | 361 |
self.PreviousValue = False |
362 |
self.PreviousSpreading = False |
|
42 | 363 |
self.RefreshNameSize() |
364 |
self.RefreshTypeSize() |
|
0 | 365 |
|
249 | 366 |
def Flush(self): |
367 |
if self.Input is not None: |
|
368 |
self.Input.Flush() |
|
369 |
self.Input = None |
|
370 |
if self.Output is not None: |
|
371 |
self.Output.Flush() |
|
372 |
self.Output = None |
|
373 |
||
478
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
374 |
def SetForced(self, forced): |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
375 |
if self.Forced != forced: |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
376 |
self.Forced = forced |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
377 |
if self.Visible: |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
378 |
self.Parent.UpdateRefreshRect(self.GetRedrawRect()) |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
379 |
|
249 | 380 |
def SetValue(self, value): |
508
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
381 |
if self.Type == CONTACT_RISING: |
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
382 |
refresh = self.Value and not self.PreviousValue |
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
383 |
elif self.Type == CONTACT_FALLING: |
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
384 |
refresh = not self.Value and self.PreviousValue |
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
385 |
else: |
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
386 |
refresh = False |
249 | 387 |
self.PreviousValue = self.Value |
388 |
self.Value = value |
|
508
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
389 |
if self.Value != self.PreviousValue or refresh: |
368 | 390 |
if self.Visible: |
391 |
self.Parent.UpdateRefreshRect(self.GetRedrawRect()) |
|
249 | 392 |
self.SpreadCurrent() |
393 |
||
394 |
def SpreadCurrent(self): |
|
253 | 395 |
if self.Parent.Debug: |
396 |
if self.Value is None: |
|
397 |
self.Value = False |
|
398 |
spreading = self.Input.ReceivingCurrent() |
|
249 | 399 |
if self.Type == CONTACT_NORMAL: |
400 |
spreading &= self.Value |
|
401 |
elif self.Type == CONTACT_REVERSE: |
|
402 |
spreading &= not self.Value |
|
403 |
elif self.Type == CONTACT_RISING: |
|
404 |
spreading &= self.Value and not self.PreviousValue |
|
405 |
elif self.Type == CONTACT_FALLING: |
|
508
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
406 |
spreading &= not self.Value and self.PreviousValue |
249 | 407 |
else: |
408 |
spreading = False |
|
253 | 409 |
if spreading and not self.PreviousSpreading: |
410 |
self.Output.SpreadCurrent(True) |
|
411 |
elif not spreading and self.PreviousSpreading: |
|
412 |
self.Output.SpreadCurrent(False) |
|
413 |
self.PreviousSpreading = spreading |
|
0 | 414 |
|
112 | 415 |
# Make a clone of this LD_Contact |
162 | 416 |
def Clone(self, parent, id = None, pos = None): |
417 |
contact = LD_Contact(parent, self.Type, self.Name, id) |
|
112 | 418 |
contact.SetSize(self.Size[0], self.Size[1]) |
419 |
if pos is not None: |
|
420 |
contact.SetPosition(pos.x, pos.y) |
|
283 | 421 |
else: |
422 |
contact.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 423 |
contact.Input = self.Input.Clone(contact) |
424 |
contact.Output = self.Output.Clone(contact) |
|
425 |
return contact |
|
426 |
||
283 | 427 |
def GetConnectorTranslation(self, element): |
428 |
return {self.Input : element.Input, self.Output : element.Output} |
|
429 |
||
144 | 430 |
# Returns the RedrawRect |
431 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
432 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
433 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
434 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
435 |
if movex != 0 or movey != 0: |
|
436 |
if self.Input.IsConnected(): |
|
437 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
438 |
if self.Output.IsConnected(): |
|
439 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
440 |
return rect |
|
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
441 |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
283
diff
changeset
|
442 |
def ProcessDragging(self, movex, movey, event, scaling): |
554 | 443 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
444 |
movex = movey = 0 |
|
360 | 445 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac = 2) |
144 | 446 |
|
0 | 447 |
# Forbids to change the contact size |
448 |
def SetSize(self, width, height): |
|
42 | 449 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 450 |
Graphic_Element.SetSize(self, width, height) |
451 |
self.RefreshConnectors() |
|
0 | 452 |
|
453 |
# Delete this contact by calling the appropriate method |
|
454 |
def Delete(self): |
|
455 |
self.Parent.DeleteContact(self) |
|
456 |
||
457 |
# Unconnect input and output |
|
458 |
def Clean(self): |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
459 |
self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
460 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 461 |
|
42 | 462 |
# Refresh the size of text for name |
463 |
def RefreshNameSize(self): |
|
464 |
if self.Name != "": |
|
165 | 465 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 466 |
else: |
467 |
self.NameSize = 0, 0 |
|
468 |
||
469 |
# Refresh the size of text for type |
|
470 |
def RefreshTypeSize(self): |
|
471 |
typetext = "" |
|
472 |
if self.Type == CONTACT_REVERSE: |
|
473 |
typetext = "/" |
|
474 |
elif self.Type == CONTACT_RISING: |
|
475 |
typetext = "P" |
|
476 |
elif self.Type == CONTACT_FALLING: |
|
477 |
typetext = "N" |
|
478 |
if typetext != "": |
|
165 | 479 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 480 |
else: |
481 |
self.TypeSize = 0, 0 |
|
482 |
||
0 | 483 |
# Refresh the contact bounding box |
484 |
def RefreshBoundingBox(self): |
|
485 |
# Calculate the size of the name outside the contact |
|
165 | 486 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 487 |
# Calculate the bounding box size |
488 |
if self.Name != "": |
|
489 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
490 |
bbx_width = max(self.Size[0], text_width) |
|
491 |
bbx_y = self.Pos.y - (text_height + 2) |
|
492 |
bbx_height = self.Size[1] + (text_height + 2) |
|
493 |
else: |
|
494 |
bbx_x = self.Pos.x |
|
495 |
bbx_width = self.Size[0] |
|
496 |
bbx_y = self.Pos.y |
|
497 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
498 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 499 |
|
27 | 500 |
# Returns the block minimum size |
501 |
def GetMinSize(self): |
|
502 |
return LD_ELEMENT_SIZE |
|
503 |
||
0 | 504 |
# Refresh the position of wire connected to contact |
505 |
def RefreshConnected(self, exclude = []): |
|
506 |
self.Input.MoveConnected(exclude) |
|
507 |
self.Output.MoveConnected(exclude) |
|
508 |
||
509 |
# Returns the contact connector that starts with the point given if it exists |
|
27 | 510 |
def GetConnector(self, position, name = None): |
511 |
# if a name is given |
|
512 |
if name: |
|
513 |
# Test input and output connector |
|
514 |
if name == self.Input.GetName(): |
|
515 |
return self.Input |
|
516 |
if name == self.Output.GetName(): |
|
517 |
return self.Output |
|
537
a31bf722aa82
Fix wire disappearing when wire tip and connector are not exactly at the same position fixed.
laurent
parents:
508
diff
changeset
|
518 |
return self.FindNearestConnector(position, [self.Input, self.Output]) |
0 | 519 |
|
520 |
# Returns input and output contact connectors |
|
521 |
def GetConnectors(self): |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
522 |
return {"inputs": [self.Input], "outputs": [self.Output]} |
0 | 523 |
|
524 |
# Test if point given is on contact input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
525 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 526 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
527 |
if self.Input.TestPoint(pt, direction, exclude): |
0 | 528 |
return self.Input |
529 |
# Test output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
530 |
if self.Output.TestPoint(pt, direction, exclude): |
0 | 531 |
return self.Output |
532 |
return None |
|
533 |
||
27 | 534 |
# Refresh the positions of the block connectors |
535 |
def RefreshConnectors(self): |
|
145 | 536 |
scaling = self.Parent.GetScaling() |
537 |
position = self.Size[1] / 2 + 1 |
|
538 |
if scaling is not None: |
|
539 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
540 |
self.Input.SetPosition(wx.Point(0, position)) |
|
541 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 542 |
self.RefreshConnected() |
543 |
||
0 | 544 |
# Changes the contact name |
545 |
def SetName(self, name): |
|
546 |
self.Name = name |
|
42 | 547 |
self.RefreshNameSize() |
0 | 548 |
|
549 |
# Returns the contact name |
|
550 |
def GetName(self): |
|
551 |
return self.Name |
|
552 |
||
553 |
# Changes the contact type |
|
554 |
def SetType(self, type): |
|
555 |
self.Type = type |
|
50 | 556 |
self.RefreshTypeSize() |
0 | 557 |
|
558 |
# Returns the contact type |
|
559 |
def GetType(self): |
|
560 |
return self.Type |
|
561 |
||
562 |
# Method called when a LeftDClick event have been generated |
|
27 | 563 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 564 |
# Edit the contact properties |
565 |
self.Parent.EditContactContent(self) |
|
566 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
567 |
# Method called when a RightUp event have been generated |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
568 |
def OnRightUp(self, event, dc, scaling): |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
569 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
570 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
571 |
|
0 | 572 |
# Refreshes the contact model |
573 |
def RefreshModel(self, move=True): |
|
574 |
self.Parent.RefreshContactModel(self) |
|
575 |
# If contact has moved, refresh the model of wires connected to output |
|
576 |
if move: |
|
577 |
self.Output.RefreshWires() |
|
578 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
579 |
# 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
|
580 |
def DrawHighlightment(self, dc): |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
581 |
scalex, scaley = dc.GetUserScale() |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
582 |
dc.SetUserScale(1, 1) |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
583 |
dc.SetPen(MiterPen(HIGHLIGHTCOLOR)) |
144 | 584 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
585 |
dc.SetLogicalFunction(wx.AND) |
|
586 |
# Draw two rectangles for representing the contact |
|
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
587 |
left_left = (self.Pos.x - 1) * scalex - 2 |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
588 |
right_left = (self.Pos.x + self.Size[0] - 2) * scalex - 2 |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
589 |
top = (self.Pos.y - 1) * scaley - 2 |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
590 |
width = 4 * scalex + 5 |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
591 |
height = (self.Size[1] + 3) * scaley + 5 |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
592 |
|
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
593 |
dc.DrawRectangle(left_left, top, width, height) |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
594 |
dc.DrawRectangle(right_left, top, width, height) |
144 | 595 |
dc.SetLogicalFunction(wx.COPY) |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
596 |
dc.SetUserScale(scalex, scaley) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
597 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
598 |
# Adds an highlight to the connection |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
599 |
def AddHighlight(self, infos, start, end, highlight_type): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
600 |
highlights = self.Highlights.setdefault(infos[0], []) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
601 |
if infos[0] == "reference": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
602 |
if start[0] == 0 and end[0] == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
603 |
AddHighlight(highlights, (start, end, highlight_type)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
604 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
605 |
AddHighlight(highlights, ((0, 0), (0, 1), highlight_type)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
606 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
607 |
# Removes an highlight from the connection |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
608 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
609 |
highlights = self.Highlights.get(infos[0], []) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
610 |
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
611 |
self.Highlights.pop(infos[0]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
612 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
613 |
# Removes all the highlights of one particular type from the connection |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
614 |
def ClearHighlight(self, highlight_type=None): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
615 |
if highlight_type is None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
616 |
self.Highlights = {} |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
617 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
618 |
highlight_items = self.Highlights.items() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
619 |
for name, highlights in highlight_items: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
620 |
highlights = ClearHighlights(highlight, highlight_type) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
621 |
if len(highlights) == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
622 |
self.Highlights.pop(name) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
623 |
|
0 | 624 |
# Draws contact |
625 |
def Draw(self, dc): |
|
144 | 626 |
Graphic_Element.Draw(self, dc) |
249 | 627 |
if self.Value is not None: |
478
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
628 |
if self.Type == CONTACT_NORMAL and self.Value or \ |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
629 |
self.Type == CONTACT_REVERSE and not self.Value or \ |
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
630 |
self.Type == CONTACT_RISING and self.Value and not self.PreviousValue or \ |
508
01f49e491be5
Bug on Contact Rising and Falling edge not displayed correctly while debugging fixed
laurent
parents:
495
diff
changeset
|
631 |
self.Type == CONTACT_RISING and not self.Value and self.PreviousValue: |
478
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
632 |
if self.Forced: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
633 |
dc.SetPen(MiterPen(wx.CYAN)) |
478
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
634 |
else: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
635 |
dc.SetPen(MiterPen(wx.GREEN)) |
478
dc403c47af54
Adding colour to graphic element that showing forced values
laurent
parents:
383
diff
changeset
|
636 |
elif self.Forced: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
637 |
dc.SetPen(MiterPen(wx.BLUE)) |
249 | 638 |
else: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
639 |
dc.SetPen(MiterPen(wx.BLACK)) |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
640 |
else: |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
641 |
dc.SetPen(MiterPen(wx.BLACK)) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
642 |
dc.SetBrush(wx.BLACK_BRUSH) |
213 | 643 |
|
644 |
# Compiling contact type modifier symbol |
|
0 | 645 |
typetext = "" |
646 |
if self.Type == CONTACT_REVERSE: |
|
647 |
typetext = "/" |
|
648 |
elif self.Type == CONTACT_RISING: |
|
649 |
typetext = "P" |
|
650 |
elif self.Type == CONTACT_FALLING: |
|
651 |
typetext = "N" |
|
213 | 652 |
|
653 |
if getattr(dc, "printing", False): |
|
654 |
name_size = dc.GetTextExtent(self.Name) |
|
655 |
if typetext != "": |
|
656 |
type_size = dc.GetTextExtent(typetext) |
|
657 |
else: |
|
658 |
name_size = self.NameSize |
|
659 |
if typetext != "": |
|
660 |
type_size = self.TypeSize |
|
661 |
||
662 |
# Draw two rectangles for representing the contact |
|
663 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
|
664 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
|
665 |
# Draw contact name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
666 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
667 |
self.Pos.y - (name_size[1] + 2)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
668 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
213 | 669 |
# Draw the modifier symbol in the middle of contact |
0 | 670 |
if typetext != "": |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
671 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
672 |
self.Pos.y + (self.Size[1] - type_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
673 |
dc.DrawText(typetext, type_pos[0], type_pos[1]) |
0 | 674 |
# Draw input and output connectors |
675 |
self.Input.Draw(dc) |
|
676 |
self.Output.Draw(dc) |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
677 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
678 |
if not getattr(dc, "printing", False): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
679 |
for name, highlights in self.Highlights.iteritems(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
680 |
if name == "reference": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
681 |
DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
682 |
elif typetext != "": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
683 |
DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |
0 | 684 |
|
685 |
#------------------------------------------------------------------------------- |
|
686 |
# Ladder Diagram Coil |
|
687 |
#------------------------------------------------------------------------------- |
|
688 |
||
689 |
""" |
|
690 |
Class that implements the graphic representation of a coil |
|
691 |
""" |
|
692 |
||
693 |
class LD_Coil(Graphic_Element): |
|
694 |
||
695 |
# Create a new coil |
|
696 |
def __init__(self, parent, type, name, id = None): |
|
697 |
Graphic_Element.__init__(self, parent) |
|
698 |
self.Type = type |
|
699 |
self.Name = name |
|
700 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
701 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
702 |
self.Highlights = {} |
0 | 703 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
704 |
self.Input = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2 + 1), WEST) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
705 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
249 | 706 |
self.Value = None |
707 |
self.PreviousValue = False |
|
42 | 708 |
self.RefreshNameSize() |
709 |
self.RefreshTypeSize() |
|
0 | 710 |
|
249 | 711 |
def Flush(self): |
712 |
if self.Input is not None: |
|
713 |
self.Input.Flush() |
|
714 |
self.Input = None |
|
715 |
if self.Output is not None: |
|
716 |
self.Output.Flush() |
|
717 |
self.Output = None |
|
718 |
||
719 |
def SpreadCurrent(self): |
|
253 | 720 |
if self.Parent.Debug: |
721 |
self.PreviousValue = self.Value |
|
722 |
self.Value = self.Input.ReceivingCurrent() |
|
723 |
if self.Value and not self.PreviousValue: |
|
724 |
self.Output.SpreadCurrent(True) |
|
725 |
elif not self.Value and self.PreviousValue: |
|
726 |
self.Output.SpreadCurrent(False) |
|
368 | 727 |
if self.Value != self.PreviousValue and self.Visible: |
361
62570186dad4
Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents:
360
diff
changeset
|
728 |
self.Parent.UpdateRefreshRect(self.GetRedrawRect()) |
0 | 729 |
|
112 | 730 |
# Make a clone of this LD_Coil |
162 | 731 |
def Clone(self, parent, id = None, pos = None): |
732 |
coil = LD_Coil(parent, self.Type, self.Name, id) |
|
112 | 733 |
coil.SetSize(self.Size[0], self.Size[1]) |
734 |
if pos is not None: |
|
735 |
coil.SetPosition(pos.x, pos.y) |
|
283 | 736 |
else: |
737 |
coil.SetPosition(self.Pos.x, self.Pos.y) |
|
112 | 738 |
coil.Input = self.Input.Clone(coil) |
739 |
coil.Output = self.Output.Clone(coil) |
|
740 |
return coil |
|
741 |
||
283 | 742 |
def GetConnectorTranslation(self, element): |
743 |
return {self.Input : element.Input, self.Output : element.Output} |
|
744 |
||
144 | 745 |
# Returns the RedrawRect |
746 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
747 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
748 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
749 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
750 |
if movex != 0 or movey != 0: |
|
751 |
if self.Input.IsConnected(): |
|
752 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
753 |
if self.Output.IsConnected(): |
|
754 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
755 |
return rect |
|
756 |
||
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
283
diff
changeset
|
757 |
def ProcessDragging(self, movex, movey, event, scaling): |
554 | 758 |
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: |
759 |
movex = movey = 0 |
|
327
7fd5233ce5ce
Adding support for contraining move to only one direction when control down
lbessard
parents:
283
diff
changeset
|
760 |
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac = 2) |
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
761 |
|
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
762 |
# Forbids to change the Coil size |
0 | 763 |
def SetSize(self, width, height): |
42 | 764 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 765 |
Graphic_Element.SetSize(self, width, height) |
766 |
self.RefreshConnectors() |
|
0 | 767 |
|
768 |
# Delete this coil by calling the appropriate method |
|
769 |
def Delete(self): |
|
770 |
self.Parent.DeleteCoil(self) |
|
771 |
||
772 |
# Unconnect input and output |
|
773 |
def Clean(self): |
|
774 |
self.Input.UnConnect() |
|
775 |
self.Output.UnConnect() |
|
776 |
||
42 | 777 |
# Refresh the size of text for name |
778 |
def RefreshNameSize(self): |
|
779 |
if self.Name != "": |
|
165 | 780 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 781 |
else: |
782 |
self.NameSize = 0, 0 |
|
783 |
||
784 |
# Refresh the size of text for type |
|
785 |
def RefreshTypeSize(self): |
|
786 |
typetext = "" |
|
787 |
if self.Type == COIL_REVERSE: |
|
788 |
typetext = "/" |
|
789 |
elif self.Type == COIL_SET: |
|
790 |
typetext = "S" |
|
791 |
elif self.Type == COIL_RESET: |
|
792 |
typetext = "R" |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
793 |
elif self.Type == COIL_RISING: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
794 |
typetext = "P" |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
795 |
elif self.Type == COIL_FALLING: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
796 |
typetext = "N" |
42 | 797 |
if typetext != "": |
165 | 798 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 799 |
else: |
800 |
self.TypeSize = 0, 0 |
|
801 |
||
0 | 802 |
# Refresh the coil bounding box |
803 |
def RefreshBoundingBox(self): |
|
804 |
# Calculate the size of the name outside the coil |
|
165 | 805 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 806 |
# Calculate the bounding box size |
807 |
if self.Name != "": |
|
808 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
809 |
bbx_width = max(self.Size[0], text_width) |
|
810 |
bbx_y = self.Pos.y - (text_height + 2) |
|
811 |
bbx_height = self.Size[1] + (text_height + 2) |
|
812 |
else: |
|
813 |
bbx_x = self.Pos.x |
|
814 |
bbx_width = self.Size[0] |
|
815 |
bbx_y = self.Pos.y |
|
816 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
817 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
27 | 818 |
|
819 |
# Returns the block minimum size |
|
820 |
def GetMinSize(self): |
|
821 |
return LD_ELEMENT_SIZE |
|
0 | 822 |
|
823 |
# Refresh the position of wire connected to coil |
|
824 |
def RefreshConnected(self, exclude = []): |
|
825 |
self.Input.MoveConnected(exclude) |
|
826 |
self.Output.MoveConnected(exclude) |
|
827 |
||
828 |
# Returns the coil connector that starts with the point given if it exists |
|
27 | 829 |
def GetConnector(self, position, name = None): |
830 |
# if a name is given |
|
831 |
if name: |
|
832 |
# Test input and output connector |
|
833 |
if self.Input and name == self.Input.GetName(): |
|
834 |
return self.Input |
|
835 |
if self.Output and name == self.Output.GetName(): |
|
836 |
return self.Output |
|
537
a31bf722aa82
Fix wire disappearing when wire tip and connector are not exactly at the same position fixed.
laurent
parents:
508
diff
changeset
|
837 |
return self.FindNearestConnector(position, [self.Input, self.Output]) |
0 | 838 |
|
839 |
# Returns input and output coil connectors |
|
840 |
def GetConnectors(self): |
|
383
25ffba02b6a8
Improving viewer loading instances procedure to faster
laurent
parents:
381
diff
changeset
|
841 |
return {"inputs": [self.Input], "outputs": [self.Output]} |
0 | 842 |
|
843 |
# Test if point given is on coil input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
844 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 845 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
846 |
if self.Input.TestPoint(pt, direction, exclude): |
0 | 847 |
return self.Input |
848 |
# Test output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
849 |
if self.Output.TestPoint(pt, direction, exclude): |
0 | 850 |
return self.Output |
851 |
return None |
|
852 |
||
27 | 853 |
# Refresh the positions of the block connectors |
854 |
def RefreshConnectors(self): |
|
145 | 855 |
scaling = self.Parent.GetScaling() |
856 |
position = self.Size[1] / 2 + 1 |
|
857 |
if scaling is not None: |
|
858 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
859 |
self.Input.SetPosition(wx.Point(0, position)) |
|
860 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 861 |
self.RefreshConnected() |
862 |
||
0 | 863 |
# Changes the coil name |
864 |
def SetName(self, name): |
|
865 |
self.Name = name |
|
42 | 866 |
self.RefreshNameSize() |
0 | 867 |
|
868 |
# Returns the coil name |
|
869 |
def GetName(self): |
|
870 |
return self.Name |
|
871 |
||
872 |
# Changes the coil type |
|
873 |
def SetType(self, type): |
|
874 |
self.Type = type |
|
42 | 875 |
self.RefreshTypeSize() |
0 | 876 |
|
877 |
# Returns the coil type |
|
878 |
def GetType(self): |
|
879 |
return self.Type |
|
880 |
||
881 |
# Method called when a LeftDClick event have been generated |
|
27 | 882 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 883 |
# Edit the coil properties |
884 |
self.Parent.EditCoilContent(self) |
|
885 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
886 |
# Method called when a RightUp event have been generated |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
887 |
def OnRightUp(self, event, dc, scaling): |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
888 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
889 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
890 |
|
0 | 891 |
# Refreshes the coil model |
892 |
def RefreshModel(self, move=True): |
|
893 |
self.Parent.RefreshCoilModel(self) |
|
894 |
# If coil has moved, refresh the model of wires connected to output |
|
895 |
if move: |
|
896 |
self.Output.RefreshWires() |
|
897 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
898 |
# 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
|
899 |
def DrawHighlightment(self, dc): |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
900 |
scalex, scaley = dc.GetUserScale() |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
901 |
dc.SetUserScale(1, 1) |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
902 |
dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (3 * scalex + 5), wx.SOLID)) |
144 | 903 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
904 |
dc.SetLogicalFunction(wx.AND) |
|
905 |
# Draw a two circle arcs for representing the coil |
|
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
906 |
dc.DrawEllipticArc(round(self.Pos.x * scalex), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
907 |
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
908 |
round(self.Size[0] * scalex), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
909 |
round((int(self.Size[1] * sqrt(2)) - 1) * scaley), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
910 |
135, 225) |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
911 |
dc.DrawEllipticArc(round(self.Pos.x * scalex), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
912 |
round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
913 |
round(self.Size[0] * scalex), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
914 |
round((int(self.Size[1] * sqrt(2)) - 1) * scaley), |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
915 |
-45, 45) |
144 | 916 |
dc.SetLogicalFunction(wx.COPY) |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
917 |
dc.SetUserScale(scalex, scaley) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
918 |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
919 |
# Adds an highlight to the connection |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
920 |
def AddHighlight(self, infos, start, end, highlight_type): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
921 |
highlights = self.Highlights.setdefault(infos[0], []) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
922 |
if infos[0] == "reference": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
923 |
if start[0] == 0 and end[0] == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
924 |
AddHighlight(highlights, (start, end, highlight_type)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
925 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
926 |
AddHighlight(highlights, ((0, 0), (0, 1), highlight_type)) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
927 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
928 |
# Removes an highlight from the connection |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
929 |
def RemoveHighlight(self, infos, start, end, highlight_type): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
930 |
highlights = self.Highlights.get(infos[0], []) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
931 |
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
932 |
self.Highlights.pop(infos[0]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
933 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
934 |
# Removes all the highlights of one particular type from the connection |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
935 |
def ClearHighlight(self, highlight_type=None): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
936 |
if highlight_type is None: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
937 |
self.Highlights = {} |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
938 |
else: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
939 |
highlight_items = self.Highlights.items() |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
940 |
for name, highlights in highlight_items: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
941 |
highlights = ClearHighlights(highlight, highlight_type) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
942 |
if len(highlights) == 0: |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
943 |
self.Highlights.pop(name) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
944 |
|
0 | 945 |
# Draws coil |
946 |
def Draw(self, dc): |
|
144 | 947 |
Graphic_Element.Draw(self, dc) |
249 | 948 |
if self.Value is not None and self.Value: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
949 |
dc.SetPen(MiterPen(wx.GREEN, 2, wx.SOLID)) |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
950 |
else: |
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
951 |
dc.SetPen(MiterPen(wx.BLACK, 2, wx.SOLID)) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
952 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
213 | 953 |
|
954 |
# Compiling coil type modifier symbol |
|
0 | 955 |
typetext = "" |
956 |
if self.Type == COIL_REVERSE: |
|
957 |
typetext = "/" |
|
958 |
elif self.Type == COIL_SET: |
|
959 |
typetext = "S" |
|
960 |
elif self.Type == COIL_RESET: |
|
961 |
typetext = "R" |
|
269
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
962 |
elif self.Type == COIL_RISING: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
963 |
typetext = "P" |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
964 |
elif self.Type == COIL_FALLING: |
34eff05909b0
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
254
diff
changeset
|
965 |
typetext = "N" |
213 | 966 |
|
967 |
if getattr(dc, "printing", False) and not isinstance(dc, wx.PostScriptDC): |
|
968 |
# Draw an clipped ellipse for representing the coil |
|
969 |
clipping_box = dc.GetClippingBox() |
|
970 |
dc.SetClippingRegion(self.Pos.x - 1, self.Pos.y, self.Size[0] + 2, self.Size[1] + 1) |
|
971 |
dc.DrawEllipse(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1) |
|
972 |
dc.DestroyClippingRegion() |
|
973 |
if clipping_box != (0, 0, 0, 0): |
|
974 |
dc.SetClippingRegion(*clipping_box) |
|
975 |
name_size = dc.GetTextExtent(self.Name) |
|
976 |
if typetext != "": |
|
977 |
type_size = dc.GetTextExtent(typetext) |
|
978 |
else: |
|
979 |
# Draw a two ellipse arcs for representing the coil |
|
980 |
dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, 135, 225) |
|
981 |
dc.DrawEllipticArc(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1, -45, 45) |
|
982 |
# Draw a point to avoid hole in left arc |
|
983 |
if not getattr(dc, "printing", False): |
|
249 | 984 |
if self.Value is not None and self.Value: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
985 |
dc.SetPen(MiterPen(wx.GREEN)) |
249 | 986 |
else: |
563
3f92a5e18804
- Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents:
554
diff
changeset
|
987 |
dc.SetPen(MiterPen(wx.BLACK)) |
213 | 988 |
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
989 |
name_size = self.NameSize |
|
990 |
if typetext != "": |
|
991 |
type_size = self.TypeSize |
|
992 |
||
993 |
# Draw coil name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
994 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
995 |
self.Pos.y - (name_size[1] + 2)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
996 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
213 | 997 |
# Draw the modifier symbol in the middle of coil |
0 | 998 |
if typetext != "": |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
999 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1000 |
self.Pos.y + (self.Size[1] - type_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1001 |
dc.DrawText(typetext, type_pos[0], type_pos[1]) |
0 | 1002 |
# Draw input and output connectors |
1003 |
self.Input.Draw(dc) |
|
1004 |
self.Output.Draw(dc) |
|
566
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1005 |
|
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1006 |
if not getattr(dc, "printing", False): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1007 |
for name, highlights in self.Highlights.iteritems(): |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1008 |
if name == "reference": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1009 |
DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1]) |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1010 |
elif typetext != "": |
6014ef82a98a
Adding support for searching text or regular expression in whole project
laurent
parents:
563
diff
changeset
|
1011 |
DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1]) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1012 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
1013 |