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