author | lbessard |
Fri, 18 Jul 2008 14:34:06 +0200 | |
changeset 222 | 8ce5c2635976 |
parent 213 | 4931959ea256 |
child 231 | fc2d6cbb8b39 |
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 |
|
41 |
def __init__(self, parent, type, id = None, connectors = [True]): |
|
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] |
48 |
if len(connectors) < 1: |
|
49 |
connectors = [True] |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
50 |
self.SetType(type, connectors) |
0 | 51 |
|
52 |
# Destructor |
|
53 |
def __del__(self): |
|
54 |
self.Connectors = [] |
|
55 |
||
112 | 56 |
# Make a clone of this LD_PowerRail |
162 | 57 |
def Clone(self, parent, id = None, pos = None): |
58 |
powerrail = LD_PowerRail(parent, self.Type, id) |
|
112 | 59 |
powerrail.SetSize(self.Size[0], self.Size[1]) |
60 |
if pos is not None: |
|
61 |
powerrail.SetPosition(pos.x, pos.y) |
|
62 |
powerrail.Connectors = [] |
|
63 |
for connector in self.Connectors: |
|
64 |
if connector is not None: |
|
65 |
powerrail.Connectors.append(connector.Clone(powerrail)) |
|
66 |
else: |
|
67 |
powerrail.Connectors.append(None) |
|
68 |
return powerrail |
|
69 |
||
144 | 70 |
# Returns the RedrawRect |
71 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
72 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
73 |
for connector in self.Connectors: |
|
74 |
if connector is not None: |
|
75 |
rect = rect.Union(connector.GetRedrawRect(movex, movey)) |
|
76 |
if movex != 0 or movey != 0: |
|
77 |
for connector in self.Connectors: |
|
78 |
if connector is not None and connector.IsConnected(): |
|
79 |
rect = rect.Union(connector.GetConnectedRedrawRect(movex, movey)) |
|
80 |
return rect |
|
81 |
||
0 | 82 |
# Forbids to change the power rail size |
83 |
def SetSize(self, width, height): |
|
42 | 84 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 85 |
Graphic_Element.SetSize(self, width, height) |
86 |
self.RefreshConnectors() |
|
0 | 87 |
|
88 |
# Forbids to select a power rail |
|
89 |
def HitTest(self, pt): |
|
42 | 90 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 91 |
return Graphic_Element.HitTest(self, pt) or self.TestConnector(pt, False) != None |
0 | 92 |
return False |
93 |
||
42 | 94 |
# Forbids to select a power rail |
95 |
def IsInSelection(self, rect): |
|
96 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
97 |
return Graphic_Element.IsInSelection(self, rect) |
42 | 98 |
return False |
99 |
||
0 | 100 |
# Deletes this power rail by calling the appropriate method |
101 |
def Delete(self): |
|
102 |
self.Parent.DeletePowerRail(self) |
|
103 |
||
104 |
# Unconnect all connectors |
|
105 |
def Clean(self): |
|
106 |
for connector in self.Connectors: |
|
107 |
if connector: |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
108 |
connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 109 |
|
110 |
# Refresh the power rail bounding box |
|
111 |
def RefreshBoundingBox(self): |
|
144 | 112 |
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
0 | 113 |
|
114 |
# Refresh the power rail size |
|
115 |
def RefreshSize(self): |
|
144 | 116 |
self.Size = wx.Size(LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors)) |
0 | 117 |
self.RefreshBoundingBox() |
118 |
||
27 | 119 |
# Returns the block minimum size |
120 |
def GetMinSize(self): |
|
96 | 121 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
144 | 122 |
return LD_POWERRAIL_WIDTH, self.Extensions[0] + self.Extensions[1] |
123 |
else: |
|
124 |
return LD_POWERRAIL_WIDTH, LD_LINE_SIZE * len(self.Connectors) |
|
27 | 125 |
|
0 | 126 |
# Add a connector or a blank to this power rail at the last place |
127 |
def AddConnector(self, connector = True): |
|
128 |
self.InsertConnector(len(self.Connectors), connector) |
|
129 |
||
130 |
# Add a connector or a blank to this power rail at the place given |
|
131 |
def InsertConnector(self, idx, connector = True): |
|
132 |
if connector: |
|
133 |
if self.Type == LEFTRAIL: |
|
80 | 134 |
connector = Connector(self, "", "BOOL", wx.Point(self.Size[0], 0), EAST) |
0 | 135 |
elif self.Type == RIGHTRAIL: |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
136 |
connector = Connector(self, "", "BOOL", wx.Point(0, 0), WEST) |
0 | 137 |
self.Connectors.insert(idx, connector) |
138 |
else: |
|
139 |
self.Connectors.insert(idx, None) |
|
140 |
self.RefreshSize() |
|
141 |
self.RefreshConnectors() |
|
142 |
||
27 | 143 |
# Moves the divergence connector given |
144 |
def MoveConnector(self, connector, movey): |
|
145 |
position = connector.GetRelPosition() |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
146 |
connector.SetPosition(wx.Point(position.x, position.y + movey)) |
27 | 147 |
miny = self.Size[1] |
148 |
maxy = 0 |
|
149 |
for connect in self.Connectors: |
|
150 |
connect_pos = connect.GetRelPosition() |
|
80 | 151 |
miny = min(miny, connect_pos.y - self.Extensions[0]) |
152 |
maxy = max(maxy, connect_pos.y - self.Extensions[0]) |
|
153 |
min_pos = self.Pos.y + miny |
|
27 | 154 |
self.Pos.y = min(min_pos, self.Pos.y) |
155 |
if min_pos == self.Pos.y: |
|
156 |
for connect in self.Connectors: |
|
157 |
connect_pos = connect.GetRelPosition() |
|
80 | 158 |
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
|
159 |
self.Connectors.sort(lambda x, y: x.Pos.y.__cmp__(y.Pos.y)) |
80 | 160 |
maxy = 0 |
161 |
for connect in self.Connectors: |
|
162 |
connect_pos = connect.GetRelPosition() |
|
163 |
maxy = max(maxy, connect_pos.y) |
|
164 |
self.Size[1] = max(maxy + self.Extensions[1], self.Size[1]) |
|
27 | 165 |
connector.MoveConnected() |
166 |
self.RefreshBoundingBox() |
|
167 |
||
0 | 168 |
# Returns the index in connectors list for the connector given |
169 |
def GetConnectorIndex(self, connector): |
|
170 |
if connector in self.Connectors: |
|
171 |
return self.Connectors.index(connector) |
|
172 |
return None |
|
173 |
||
174 |
# Returns if there is a connector in connectors list at the index given |
|
175 |
def IsNullConnector(self, idx): |
|
176 |
if idx < len(self.Connectors): |
|
177 |
return self.Connectors[idx] == None |
|
178 |
return False |
|
179 |
||
180 |
# Delete the connector or blank from connectors list at the index given |
|
181 |
def DeleteConnector(self, idx): |
|
182 |
self.Connectors.pop(idx) |
|
183 |
self.RefreshConnectors() |
|
184 |
self.RefreshSize() |
|
185 |
||
186 |
# Refresh the positions of the power rail connectors |
|
187 |
def RefreshConnectors(self): |
|
145 | 188 |
scaling = self.Parent.GetScaling() |
71 | 189 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
190 |
height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
80 | 191 |
interval = float(height) / float(max(len(self.Connectors) - 1, 1)) |
71 | 192 |
for i, connector in enumerate(self.Connectors): |
145 | 193 |
if self.RealConnectors: |
194 |
position = self.Extensions[0] + int(round(self.RealConnectors[i] * height)) |
|
195 |
else: |
|
196 |
position = self.Extensions[0] + int(round(i * interval)) |
|
197 |
if scaling is not None: |
|
198 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
80 | 199 |
if self.Type == LEFTRAIL: |
145 | 200 |
connector.SetPosition(wx.Point(self.Size[0], position)) |
80 | 201 |
elif self.Type == RIGHTRAIL: |
145 | 202 |
connector.SetPosition(wx.Point(0, position)) |
71 | 203 |
else: |
204 |
position = self.Extensions[0] |
|
205 |
for connector in self.Connectors: |
|
206 |
if connector: |
|
145 | 207 |
if scaling is not None: |
208 |
ypos = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
209 |
else: |
|
210 |
ypos = position |
|
71 | 211 |
if self.Type == LEFTRAIL: |
145 | 212 |
connector.SetPosition(wx.Point(self.Size[0], ypos)) |
71 | 213 |
elif self.Type == RIGHTRAIL: |
145 | 214 |
connector.SetPosition(wx.Point(0, ypos)) |
71 | 215 |
position += LD_LINE_SIZE |
0 | 216 |
self.RefreshConnected() |
217 |
||
7 | 218 |
# Refresh the position of wires connected to power rail |
0 | 219 |
def RefreshConnected(self, exclude = []): |
220 |
for connector in self.Connectors: |
|
8 | 221 |
if connector: |
222 |
connector.MoveConnected(exclude) |
|
0 | 223 |
|
224 |
# Returns the power rail connector that starts with the point given if it exists |
|
27 | 225 |
def GetConnector(self, position, name = None): |
226 |
# if a name is given |
|
227 |
if name: |
|
228 |
# Test each connector if it exists |
|
229 |
for connector in self.Connectors: |
|
230 |
if connector and name == connector.GetName(): |
|
231 |
return connector |
|
0 | 232 |
for connector in self.Connectors: |
233 |
if connector: |
|
234 |
connector_pos = connector.GetRelPosition() |
|
235 |
if position.x == self.Pos.x + connector_pos.x and position.y == self.Pos.y + connector_pos.y: |
|
236 |
return connector |
|
237 |
return None |
|
238 |
||
239 |
# Returns all the power rail connectors |
|
240 |
def GetConnectors(self): |
|
241 |
return [connector for connector in self.Connectors if connector] |
|
242 |
||
243 |
# Test if point given is on one of the power rail connectors |
|
244 |
def TestConnector(self, pt, exclude=True): |
|
245 |
for connector in self.Connectors: |
|
246 |
if connector and connector.TestPoint(pt, exclude): |
|
247 |
return connector |
|
248 |
return None |
|
249 |
||
250 |
# Returns the power rail type |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
251 |
def SetType(self, type, connectors): |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
252 |
if type != self.Type or len(self.Connectors) != len(connectors): |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
253 |
# 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
|
254 |
# the connectors list |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
255 |
self.Type = type |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
256 |
self.Clean() |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
257 |
self.Connectors = [] |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
258 |
for connector in connectors: |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
259 |
self.AddConnector(connector) |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
260 |
self.RefreshSize() |
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
261 |
|
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
262 |
# Returns the power rail type |
0 | 263 |
def GetType(self): |
264 |
return self.Type |
|
265 |
||
27 | 266 |
# Method called when a LeftDown event have been generated |
267 |
def OnLeftDown(self, event, dc, scaling): |
|
145 | 268 |
self.RealConnectors = [] |
269 |
height = self.Size[1] - self.Extensions[0] - self.Extensions[1] |
|
270 |
for connector in self.Connectors: |
|
271 |
position = connector.GetRelPosition() |
|
272 |
self.RealConnectors.append(float(position.y - self.Extensions[0])/float(max(1, height))) |
|
273 |
Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
274 |
||
275 |
# Method called when a LeftUp event have been generated |
|
276 |
def OnLeftUp(self, event, dc, scaling): |
|
277 |
Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
278 |
self.RealConnectors = None |
|
279 |
||
280 |
# Method called when a LeftDown event have been generated |
|
281 |
def OnRightDown(self, event, dc, scaling): |
|
27 | 282 |
pos = GetScaledEventPosition(event, dc, scaling) |
283 |
# Test if a connector have been handled |
|
284 |
connector = self.TestConnector(pos, False) |
|
285 |
if connector: |
|
286 |
self.Handle = (HANDLE_CONNECTOR, connector) |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
287 |
self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
27 | 288 |
self.Selected = False |
289 |
# Initializes the last position |
|
290 |
self.oldPos = GetScaledEventPosition(event, dc, scaling) |
|
291 |
else: |
|
145 | 292 |
Graphic_Element.OnRightDown(self, event, dc, scaling) |
293 |
||
294 |
# Method called when a LeftDClick event have been generated |
|
295 |
def OnLeftDClick(self, event, dc, scaling): |
|
296 |
# Edit the powerrail properties |
|
297 |
self.Parent.EditPowerRailContent(self) |
|
298 |
||
299 |
# Method called when a RightUp event have been generated |
|
300 |
def OnRightUp(self, event, dc, scaling): |
|
27 | 301 |
handle_type, handle = self.Handle |
302 |
if handle_type == HANDLE_CONNECTOR: |
|
303 |
wires = handle.GetWires() |
|
80 | 304 |
if len(wires) == 1: |
305 |
if handle == wires[0][0].StartConnected: |
|
306 |
block = wires[0][0].EndConnected.GetParentBlock() |
|
307 |
else: |
|
308 |
block = wires[0][0].StartConnected.GetParentBlock() |
|
309 |
block.RefreshModel(False) |
|
145 | 310 |
Graphic_Element.OnRightUp(self, event, dc, scaling) |
311 |
else: |
|
312 |
self.Parent.PopupDefaultMenu() |
|
27 | 313 |
|
175 | 314 |
def Resize(self, x, y, width, height): |
315 |
self.Move(x, y) |
|
316 |
self.SetSize(LD_POWERRAIL_WIDTH, height) |
|
317 |
||
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
96
diff
changeset
|
318 |
# Refreshes the powerrail state according to move defined and handle selected |
165 | 319 |
def ProcessDragging(self, movex, movey, centered, scaling): |
27 | 320 |
handle_type, handle = self.Handle |
321 |
# A connector has been handled |
|
322 |
if handle_type == HANDLE_CONNECTOR: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
323 |
movey = max(-self.BoundingBox.y, movey) |
145 | 324 |
if scaling is not None: |
325 |
position = handle.GetRelPosition() |
|
326 |
movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y |
|
27 | 327 |
self.MoveConnector(handle, movey) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
328 |
return 0, movey |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
96
diff
changeset
|
329 |
else: |
165 | 330 |
return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) |
27 | 331 |
|
0 | 332 |
# Refreshes the power rail model |
333 |
def RefreshModel(self, move=True): |
|
334 |
self.Parent.RefreshPowerRailModel(self) |
|
335 |
# If power rail has moved and power rail is of type LEFT, refresh the model |
|
336 |
# of wires connected to connectors |
|
337 |
if move and self.Type == LEFTRAIL: |
|
338 |
for connector in self.Connectors: |
|
339 |
if connector: |
|
340 |
connector.RefreshWires() |
|
341 |
||
342 |
# Draws power rail |
|
343 |
def Draw(self, dc): |
|
144 | 344 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
345 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
346 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 347 |
# Draw a rectangle with the power rail size |
175 | 348 |
if self.Type == LEFTRAIL: |
349 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - LD_POWERRAIL_WIDTH, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1) |
|
350 |
else: |
|
351 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, LD_POWERRAIL_WIDTH + 1, self.Size[1] + 1) |
|
0 | 352 |
# Draw connectors |
353 |
for connector in self.Connectors: |
|
354 |
if connector: |
|
355 |
connector.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
356 |
|
0 | 357 |
|
358 |
#------------------------------------------------------------------------------- |
|
359 |
# Ladder Diagram Contact |
|
360 |
#------------------------------------------------------------------------------- |
|
361 |
||
362 |
""" |
|
363 |
Class that implements the graphic representation of a contact |
|
364 |
""" |
|
365 |
||
366 |
class LD_Contact(Graphic_Element): |
|
367 |
||
368 |
# Create a new contact |
|
369 |
def __init__(self, parent, type, name, id = None): |
|
370 |
Graphic_Element.__init__(self, parent) |
|
371 |
self.Type = type |
|
372 |
self.Name = name |
|
373 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
374 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
0 | 375 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
376 |
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
|
377 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 378 |
self.RefreshNameSize() |
379 |
self.RefreshTypeSize() |
|
0 | 380 |
|
381 |
# Destructor |
|
382 |
def __del__(self): |
|
383 |
self.Input = None |
|
384 |
self.Output = None |
|
385 |
||
112 | 386 |
# Make a clone of this LD_Contact |
162 | 387 |
def Clone(self, parent, id = None, pos = None): |
388 |
contact = LD_Contact(parent, self.Type, self.Name, id) |
|
112 | 389 |
contact.SetSize(self.Size[0], self.Size[1]) |
390 |
if pos is not None: |
|
391 |
contact.SetPosition(pos.x, pos.y) |
|
392 |
contact.Input = self.Input.Clone(contact) |
|
393 |
contact.Output = self.Output.Clone(contact) |
|
394 |
return contact |
|
395 |
||
144 | 396 |
# Returns the RedrawRect |
397 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
398 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
399 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
400 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
401 |
if movex != 0 or movey != 0: |
|
402 |
if self.Input.IsConnected(): |
|
403 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
404 |
if self.Output.IsConnected(): |
|
405 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
406 |
return rect |
|
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
407 |
|
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
408 |
def ProcessDragging(self, movex, movey, centered, scaling): |
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
409 |
return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling, height_fac = 2) |
144 | 410 |
|
0 | 411 |
# Forbids to change the contact size |
412 |
def SetSize(self, width, height): |
|
42 | 413 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 414 |
Graphic_Element.SetSize(self, width, height) |
415 |
self.RefreshConnectors() |
|
0 | 416 |
|
417 |
# Delete this contact by calling the appropriate method |
|
418 |
def Delete(self): |
|
419 |
self.Parent.DeleteContact(self) |
|
420 |
||
421 |
# Unconnect input and output |
|
422 |
def Clean(self): |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
423 |
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
|
424 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 425 |
|
42 | 426 |
# Refresh the size of text for name |
427 |
def RefreshNameSize(self): |
|
428 |
if self.Name != "": |
|
165 | 429 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 430 |
else: |
431 |
self.NameSize = 0, 0 |
|
432 |
||
433 |
# Refresh the size of text for type |
|
434 |
def RefreshTypeSize(self): |
|
435 |
typetext = "" |
|
436 |
if self.Type == CONTACT_REVERSE: |
|
437 |
typetext = "/" |
|
438 |
elif self.Type == CONTACT_RISING: |
|
439 |
typetext = "P" |
|
440 |
elif self.Type == CONTACT_FALLING: |
|
441 |
typetext = "N" |
|
442 |
if typetext != "": |
|
165 | 443 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 444 |
else: |
445 |
self.TypeSize = 0, 0 |
|
446 |
||
0 | 447 |
# Refresh the contact bounding box |
448 |
def RefreshBoundingBox(self): |
|
449 |
# Calculate the size of the name outside the contact |
|
165 | 450 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 451 |
# Calculate the bounding box size |
452 |
if self.Name != "": |
|
453 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
454 |
bbx_width = max(self.Size[0], text_width) |
|
455 |
bbx_y = self.Pos.y - (text_height + 2) |
|
456 |
bbx_height = self.Size[1] + (text_height + 2) |
|
457 |
else: |
|
458 |
bbx_x = self.Pos.x |
|
459 |
bbx_width = self.Size[0] |
|
460 |
bbx_y = self.Pos.y |
|
461 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
462 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 463 |
|
27 | 464 |
# Returns the block minimum size |
465 |
def GetMinSize(self): |
|
466 |
return LD_ELEMENT_SIZE |
|
467 |
||
0 | 468 |
# Refresh the position of wire connected to contact |
469 |
def RefreshConnected(self, exclude = []): |
|
470 |
self.Input.MoveConnected(exclude) |
|
471 |
self.Output.MoveConnected(exclude) |
|
472 |
||
473 |
# Returns the contact connector that starts with the point given if it exists |
|
27 | 474 |
def GetConnector(self, position, name = None): |
475 |
# if a name is given |
|
476 |
if name: |
|
477 |
# Test input and output connector |
|
478 |
if name == self.Input.GetName(): |
|
479 |
return self.Input |
|
480 |
if name == self.Output.GetName(): |
|
481 |
return self.Output |
|
0 | 482 |
# Test input connector |
483 |
input_pos = self.Input.GetRelPosition() |
|
484 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
485 |
return self.Input |
|
486 |
# Test output connector |
|
487 |
output_pos = self.Output.GetRelPosition() |
|
488 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
489 |
return self.Output |
|
490 |
return None |
|
491 |
||
492 |
# Returns input and output contact connectors |
|
493 |
def GetConnectors(self): |
|
494 |
return {"input":self.Input,"output":self.Output} |
|
495 |
||
496 |
# Test if point given is on contact input or output connector |
|
497 |
def TestConnector(self, pt, exclude=True): |
|
498 |
# Test input connector |
|
499 |
if self.Input.TestPoint(pt, exclude): |
|
500 |
return self.Input |
|
501 |
# Test output connector |
|
502 |
if self.Output.TestPoint(pt, exclude): |
|
503 |
return self.Output |
|
504 |
return None |
|
505 |
||
27 | 506 |
# Refresh the positions of the block connectors |
507 |
def RefreshConnectors(self): |
|
145 | 508 |
scaling = self.Parent.GetScaling() |
509 |
position = self.Size[1] / 2 + 1 |
|
510 |
if scaling is not None: |
|
511 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
512 |
self.Input.SetPosition(wx.Point(0, position)) |
|
513 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 514 |
self.RefreshConnected() |
515 |
||
0 | 516 |
# Changes the contact name |
517 |
def SetName(self, name): |
|
518 |
self.Name = name |
|
42 | 519 |
self.RefreshNameSize() |
0 | 520 |
|
521 |
# Returns the contact name |
|
522 |
def GetName(self): |
|
523 |
return self.Name |
|
524 |
||
525 |
# Changes the contact type |
|
526 |
def SetType(self, type): |
|
527 |
self.Type = type |
|
50 | 528 |
self.RefreshTypeSize() |
0 | 529 |
|
530 |
# Returns the contact type |
|
531 |
def GetType(self): |
|
532 |
return self.Type |
|
533 |
||
534 |
# Method called when a LeftDClick event have been generated |
|
27 | 535 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 536 |
# Edit the contact properties |
537 |
self.Parent.EditContactContent(self) |
|
538 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
539 |
# 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
|
540 |
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
|
541 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
542 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
543 |
|
0 | 544 |
# Refreshes the contact model |
545 |
def RefreshModel(self, move=True): |
|
546 |
self.Parent.RefreshContactModel(self) |
|
547 |
# If contact has moved, refresh the model of wires connected to output |
|
548 |
if move: |
|
549 |
self.Output.RefreshWires() |
|
550 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
551 |
# 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
|
552 |
def DrawHighlightment(self, dc): |
144 | 553 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
554 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
555 |
dc.SetLogicalFunction(wx.AND) |
|
556 |
# Draw two rectangles for representing the contact |
|
557 |
dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
558 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
559 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
560 |
|
0 | 561 |
# Draws contact |
562 |
def Draw(self, dc): |
|
144 | 563 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
564 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
565 |
dc.SetBrush(wx.BLACK_BRUSH) |
213 | 566 |
|
567 |
# Compiling contact type modifier symbol |
|
0 | 568 |
typetext = "" |
569 |
if self.Type == CONTACT_REVERSE: |
|
570 |
typetext = "/" |
|
571 |
elif self.Type == CONTACT_RISING: |
|
572 |
typetext = "P" |
|
573 |
elif self.Type == CONTACT_FALLING: |
|
574 |
typetext = "N" |
|
213 | 575 |
|
576 |
if getattr(dc, "printing", False): |
|
577 |
name_size = dc.GetTextExtent(self.Name) |
|
578 |
if typetext != "": |
|
579 |
type_size = dc.GetTextExtent(typetext) |
|
580 |
else: |
|
581 |
name_size = self.NameSize |
|
582 |
if typetext != "": |
|
583 |
type_size = self.TypeSize |
|
584 |
||
585 |
# Draw two rectangles for representing the contact |
|
586 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
|
587 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
|
588 |
# Draw contact name |
|
589 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
|
590 |
self.Pos.y - (name_size[1] + 2)) |
|
591 |
# Draw the modifier symbol in the middle of contact |
|
0 | 592 |
if typetext != "": |
213 | 593 |
dc.DrawText(typetext, self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1, |
594 |
self.Pos.y + (self.Size[1] - type_size[1]) / 2) |
|
0 | 595 |
# Draw input and output connectors |
596 |
self.Input.Draw(dc) |
|
597 |
self.Output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
598 |
|
0 | 599 |
|
600 |
#------------------------------------------------------------------------------- |
|
601 |
# Ladder Diagram Coil |
|
602 |
#------------------------------------------------------------------------------- |
|
603 |
||
604 |
""" |
|
605 |
Class that implements the graphic representation of a coil |
|
606 |
""" |
|
607 |
||
608 |
class LD_Coil(Graphic_Element): |
|
609 |
||
610 |
# Create a new coil |
|
611 |
def __init__(self, parent, type, name, id = None): |
|
612 |
Graphic_Element.__init__(self, parent) |
|
613 |
self.Type = type |
|
614 |
self.Name = name |
|
615 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
616 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
0 | 617 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
618 |
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
|
619 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 620 |
self.RefreshNameSize() |
621 |
self.RefreshTypeSize() |
|
0 | 622 |
|
623 |
# Destructor |
|
624 |
def __del__(self): |
|
625 |
self.Input = None |
|
626 |
self.Output = None |
|
627 |
||
112 | 628 |
# Make a clone of this LD_Coil |
162 | 629 |
def Clone(self, parent, id = None, pos = None): |
630 |
coil = LD_Coil(parent, self.Type, self.Name, id) |
|
112 | 631 |
coil.SetSize(self.Size[0], self.Size[1]) |
632 |
if pos is not None: |
|
633 |
coil.SetPosition(pos.x, pos.y) |
|
634 |
coil.Input = self.Input.Clone(coil) |
|
635 |
coil.Output = self.Output.Clone(coil) |
|
636 |
return coil |
|
637 |
||
144 | 638 |
# Returns the RedrawRect |
639 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
640 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
641 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
642 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
643 |
if movex != 0 or movey != 0: |
|
644 |
if self.Input.IsConnected(): |
|
645 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
646 |
if self.Output.IsConnected(): |
|
647 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
648 |
return rect |
|
649 |
||
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
650 |
def ProcessDragging(self, movex, movey, centered, scaling): |
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
651 |
return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling, height_fac = 2) |
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
652 |
|
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
653 |
# Forbids to change the Coil size |
0 | 654 |
def SetSize(self, width, height): |
42 | 655 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 656 |
Graphic_Element.SetSize(self, width, height) |
657 |
self.RefreshConnectors() |
|
0 | 658 |
|
659 |
# Delete this coil by calling the appropriate method |
|
660 |
def Delete(self): |
|
661 |
self.Parent.DeleteCoil(self) |
|
662 |
||
663 |
# Unconnect input and output |
|
664 |
def Clean(self): |
|
665 |
self.Input.UnConnect() |
|
666 |
self.Output.UnConnect() |
|
667 |
||
42 | 668 |
# Refresh the size of text for name |
669 |
def RefreshNameSize(self): |
|
670 |
if self.Name != "": |
|
165 | 671 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 672 |
else: |
673 |
self.NameSize = 0, 0 |
|
674 |
||
675 |
# Refresh the size of text for type |
|
676 |
def RefreshTypeSize(self): |
|
677 |
typetext = "" |
|
678 |
if self.Type == COIL_REVERSE: |
|
679 |
typetext = "/" |
|
680 |
elif self.Type == COIL_SET: |
|
681 |
typetext = "S" |
|
682 |
elif self.Type == COIL_RESET: |
|
683 |
typetext = "R" |
|
684 |
if typetext != "": |
|
165 | 685 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 686 |
else: |
687 |
self.TypeSize = 0, 0 |
|
688 |
||
0 | 689 |
# Refresh the coil bounding box |
690 |
def RefreshBoundingBox(self): |
|
691 |
# Calculate the size of the name outside the coil |
|
165 | 692 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 693 |
# Calculate the bounding box size |
694 |
if self.Name != "": |
|
695 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
696 |
bbx_width = max(self.Size[0], text_width) |
|
697 |
bbx_y = self.Pos.y - (text_height + 2) |
|
698 |
bbx_height = self.Size[1] + (text_height + 2) |
|
699 |
else: |
|
700 |
bbx_x = self.Pos.x |
|
701 |
bbx_width = self.Size[0] |
|
702 |
bbx_y = self.Pos.y |
|
703 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
704 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
27 | 705 |
|
706 |
# Returns the block minimum size |
|
707 |
def GetMinSize(self): |
|
708 |
return LD_ELEMENT_SIZE |
|
0 | 709 |
|
710 |
# Refresh the position of wire connected to coil |
|
711 |
def RefreshConnected(self, exclude = []): |
|
712 |
self.Input.MoveConnected(exclude) |
|
713 |
self.Output.MoveConnected(exclude) |
|
714 |
||
715 |
# Returns the coil connector that starts with the point given if it exists |
|
27 | 716 |
def GetConnector(self, position, name = None): |
717 |
# if a name is given |
|
718 |
if name: |
|
719 |
# Test input and output connector |
|
720 |
if self.Input and name == self.Input.GetName(): |
|
721 |
return self.Input |
|
722 |
if self.Output and name == self.Output.GetName(): |
|
723 |
return self.Output |
|
0 | 724 |
# Test input connector |
725 |
input_pos = self.Input.GetRelPosition() |
|
726 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
727 |
return self.Input |
|
728 |
# Test output connector |
|
729 |
output_pos = self.Output.GetRelPosition() |
|
730 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
731 |
return self.Output |
|
732 |
return None |
|
733 |
||
734 |
# Returns input and output coil connectors |
|
735 |
def GetConnectors(self): |
|
736 |
return {"input":self.Input,"output":self.Output} |
|
737 |
||
738 |
# Test if point given is on coil input or output connector |
|
739 |
def TestConnector(self, pt, exclude=True): |
|
740 |
# Test input connector |
|
741 |
if self.Input.TestPoint(pt, exclude): |
|
742 |
return self.Input |
|
743 |
# Test output connector |
|
744 |
if self.Output.TestPoint(pt, exclude): |
|
745 |
return self.Output |
|
746 |
return None |
|
747 |
||
27 | 748 |
# Refresh the positions of the block connectors |
749 |
def RefreshConnectors(self): |
|
145 | 750 |
scaling = self.Parent.GetScaling() |
751 |
position = self.Size[1] / 2 + 1 |
|
752 |
if scaling is not None: |
|
753 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
754 |
self.Input.SetPosition(wx.Point(0, position)) |
|
755 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 756 |
self.RefreshConnected() |
757 |
||
0 | 758 |
# Changes the coil name |
759 |
def SetName(self, name): |
|
760 |
self.Name = name |
|
42 | 761 |
self.RefreshNameSize() |
0 | 762 |
|
763 |
# Returns the coil name |
|
764 |
def GetName(self): |
|
765 |
return self.Name |
|
766 |
||
767 |
# Changes the coil type |
|
768 |
def SetType(self, type): |
|
769 |
self.Type = type |
|
42 | 770 |
self.RefreshTypeSize() |
0 | 771 |
|
772 |
# Returns the coil type |
|
773 |
def GetType(self): |
|
774 |
return self.Type |
|
775 |
||
776 |
# Method called when a LeftDClick event have been generated |
|
27 | 777 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 778 |
# Edit the coil properties |
779 |
self.Parent.EditCoilContent(self) |
|
780 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
781 |
# 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
|
782 |
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
|
783 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
784 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
785 |
|
0 | 786 |
# Refreshes the coil model |
787 |
def RefreshModel(self, move=True): |
|
788 |
self.Parent.RefreshCoilModel(self) |
|
789 |
# If coil has moved, refresh the model of wires connected to output |
|
790 |
if move: |
|
791 |
self.Output.RefreshWires() |
|
792 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
793 |
# 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
|
794 |
def DrawHighlightment(self, dc): |
144 | 795 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) |
796 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
797 |
dc.SetLogicalFunction(wx.AND) |
|
798 |
# Draw a two circle arcs for representing the coil |
|
799 |
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) |
|
800 |
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) |
|
801 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
802 |
|
0 | 803 |
# Draws coil |
804 |
def Draw(self, dc): |
|
144 | 805 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
806 |
dc.SetPen(wx.Pen(wx.BLACK, 2, wx.SOLID)) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
807 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
213 | 808 |
|
809 |
# Compiling coil type modifier symbol |
|
0 | 810 |
typetext = "" |
811 |
if self.Type == COIL_REVERSE: |
|
812 |
typetext = "/" |
|
813 |
elif self.Type == COIL_SET: |
|
814 |
typetext = "S" |
|
815 |
elif self.Type == COIL_RESET: |
|
816 |
typetext = "R" |
|
213 | 817 |
|
818 |
if getattr(dc, "printing", False) and not isinstance(dc, wx.PostScriptDC): |
|
819 |
# Draw an clipped ellipse for representing the coil |
|
820 |
clipping_box = dc.GetClippingBox() |
|
821 |
dc.SetClippingRegion(self.Pos.x - 1, self.Pos.y, self.Size[0] + 2, self.Size[1] + 1) |
|
822 |
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) |
|
823 |
dc.DestroyClippingRegion() |
|
824 |
if clipping_box != (0, 0, 0, 0): |
|
825 |
dc.SetClippingRegion(*clipping_box) |
|
826 |
name_size = dc.GetTextExtent(self.Name) |
|
827 |
if typetext != "": |
|
828 |
type_size = dc.GetTextExtent(typetext) |
|
829 |
else: |
|
830 |
# Draw a two ellipse arcs for representing the coil |
|
831 |
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) |
|
832 |
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) |
|
833 |
# Draw a point to avoid hole in left arc |
|
834 |
if not getattr(dc, "printing", False): |
|
835 |
dc.SetPen(wx.BLACK_PEN) |
|
836 |
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
|
837 |
name_size = self.NameSize |
|
838 |
if typetext != "": |
|
839 |
type_size = self.TypeSize |
|
840 |
||
841 |
# Draw coil name |
|
842 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
|
843 |
self.Pos.y - (name_size[1] + 2)) |
|
844 |
# Draw the modifier symbol in the middle of coil |
|
0 | 845 |
if typetext != "": |
213 | 846 |
dc.DrawText(typetext, self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1, |
847 |
self.Pos.y + (self.Size[1] - type_size[1]) / 2) |
|
0 | 848 |
# Draw input and output connectors |
849 |
self.Input.Draw(dc) |
|
850 |
self.Output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
851 |