author | lbessard |
Tue, 26 Feb 2008 15:32:19 +0100 | |
changeset 172 | 198f7949f737 |
parent 165 | e464a4e4e06d |
child 175 | cc78572dfbbc |
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 |
|
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
96
diff
changeset
|
314 |
# Refreshes the powerrail state according to move defined and handle selected |
165 | 315 |
def ProcessDragging(self, movex, movey, centered, scaling): |
27 | 316 |
handle_type, handle = self.Handle |
317 |
# A connector has been handled |
|
318 |
if handle_type == HANDLE_CONNECTOR: |
|
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
319 |
movey = max(-self.BoundingBox.y, movey) |
145 | 320 |
if scaling is not None: |
321 |
position = handle.GetRelPosition() |
|
322 |
movey = round(float(self.Pos.y + position.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - position.y |
|
27 | 323 |
self.MoveConnector(handle, movey) |
138
9c74d00ce93e
Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents:
127
diff
changeset
|
324 |
return 0, movey |
110
29b6b70e1721
Bug that makes element resizing acting strongly fixed
lbessard
parents:
96
diff
changeset
|
325 |
else: |
165 | 326 |
return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) |
27 | 327 |
|
0 | 328 |
# Refreshes the power rail model |
329 |
def RefreshModel(self, move=True): |
|
330 |
self.Parent.RefreshPowerRailModel(self) |
|
331 |
# If power rail has moved and power rail is of type LEFT, refresh the model |
|
332 |
# of wires connected to connectors |
|
333 |
if move and self.Type == LEFTRAIL: |
|
334 |
for connector in self.Connectors: |
|
335 |
if connector: |
|
336 |
connector.RefreshWires() |
|
337 |
||
338 |
# Draws power rail |
|
339 |
def Draw(self, dc): |
|
144 | 340 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
341 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
342 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 343 |
# Draw a rectangle with the power rail size |
344 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) |
|
345 |
# Draw connectors |
|
346 |
for connector in self.Connectors: |
|
347 |
if connector: |
|
348 |
connector.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
349 |
|
0 | 350 |
|
351 |
#------------------------------------------------------------------------------- |
|
352 |
# Ladder Diagram Contact |
|
353 |
#------------------------------------------------------------------------------- |
|
354 |
||
355 |
""" |
|
356 |
Class that implements the graphic representation of a contact |
|
357 |
""" |
|
358 |
||
359 |
class LD_Contact(Graphic_Element): |
|
360 |
||
361 |
# Create a new contact |
|
362 |
def __init__(self, parent, type, name, id = None): |
|
363 |
Graphic_Element.__init__(self, parent) |
|
364 |
self.Type = type |
|
365 |
self.Name = name |
|
366 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
367 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
0 | 368 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
369 |
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
|
370 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 371 |
self.RefreshNameSize() |
372 |
self.RefreshTypeSize() |
|
0 | 373 |
|
374 |
# Destructor |
|
375 |
def __del__(self): |
|
376 |
self.Input = None |
|
377 |
self.Output = None |
|
378 |
||
112 | 379 |
# Make a clone of this LD_Contact |
162 | 380 |
def Clone(self, parent, id = None, pos = None): |
381 |
contact = LD_Contact(parent, self.Type, self.Name, id) |
|
112 | 382 |
contact.SetSize(self.Size[0], self.Size[1]) |
383 |
if pos is not None: |
|
384 |
contact.SetPosition(pos.x, pos.y) |
|
385 |
contact.Input = self.Input.Clone(contact) |
|
386 |
contact.Output = self.Output.Clone(contact) |
|
387 |
return contact |
|
388 |
||
144 | 389 |
# Returns the RedrawRect |
390 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
391 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
392 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
393 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
394 |
if movex != 0 or movey != 0: |
|
395 |
if self.Input.IsConnected(): |
|
396 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
397 |
if self.Output.IsConnected(): |
|
398 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
399 |
return rect |
|
400 |
||
0 | 401 |
# Forbids to change the contact size |
402 |
def SetSize(self, width, height): |
|
42 | 403 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 404 |
Graphic_Element.SetSize(self, width, height) |
405 |
self.RefreshConnectors() |
|
0 | 406 |
|
407 |
# Delete this contact by calling the appropriate method |
|
408 |
def Delete(self): |
|
409 |
self.Parent.DeleteContact(self) |
|
410 |
||
411 |
# Unconnect input and output |
|
412 |
def Clean(self): |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
413 |
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
|
414 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 415 |
|
42 | 416 |
# Refresh the size of text for name |
417 |
def RefreshNameSize(self): |
|
418 |
if self.Name != "": |
|
165 | 419 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 420 |
else: |
421 |
self.NameSize = 0, 0 |
|
422 |
||
423 |
# Refresh the size of text for type |
|
424 |
def RefreshTypeSize(self): |
|
425 |
typetext = "" |
|
426 |
if self.Type == CONTACT_REVERSE: |
|
427 |
typetext = "/" |
|
428 |
elif self.Type == CONTACT_RISING: |
|
429 |
typetext = "P" |
|
430 |
elif self.Type == CONTACT_FALLING: |
|
431 |
typetext = "N" |
|
432 |
if typetext != "": |
|
165 | 433 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 434 |
else: |
435 |
self.TypeSize = 0, 0 |
|
436 |
||
0 | 437 |
# Refresh the contact bounding box |
438 |
def RefreshBoundingBox(self): |
|
439 |
# Calculate the size of the name outside the contact |
|
165 | 440 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 441 |
# Calculate the bounding box size |
442 |
if self.Name != "": |
|
443 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
444 |
bbx_width = max(self.Size[0], text_width) |
|
445 |
bbx_y = self.Pos.y - (text_height + 2) |
|
446 |
bbx_height = self.Size[1] + (text_height + 2) |
|
447 |
else: |
|
448 |
bbx_x = self.Pos.x |
|
449 |
bbx_width = self.Size[0] |
|
450 |
bbx_y = self.Pos.y |
|
451 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
452 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 453 |
|
27 | 454 |
# Returns the block minimum size |
455 |
def GetMinSize(self): |
|
456 |
return LD_ELEMENT_SIZE |
|
457 |
||
0 | 458 |
# Refresh the position of wire connected to contact |
459 |
def RefreshConnected(self, exclude = []): |
|
460 |
self.Input.MoveConnected(exclude) |
|
461 |
self.Output.MoveConnected(exclude) |
|
462 |
||
463 |
# Returns the contact connector that starts with the point given if it exists |
|
27 | 464 |
def GetConnector(self, position, name = None): |
465 |
# if a name is given |
|
466 |
if name: |
|
467 |
# Test input and output connector |
|
468 |
if name == self.Input.GetName(): |
|
469 |
return self.Input |
|
470 |
if name == self.Output.GetName(): |
|
471 |
return self.Output |
|
0 | 472 |
# Test input connector |
473 |
input_pos = self.Input.GetRelPosition() |
|
474 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
475 |
return self.Input |
|
476 |
# Test output connector |
|
477 |
output_pos = self.Output.GetRelPosition() |
|
478 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
479 |
return self.Output |
|
480 |
return None |
|
481 |
||
482 |
# Returns input and output contact connectors |
|
483 |
def GetConnectors(self): |
|
484 |
return {"input":self.Input,"output":self.Output} |
|
485 |
||
486 |
# Test if point given is on contact input or output connector |
|
487 |
def TestConnector(self, pt, exclude=True): |
|
488 |
# Test input connector |
|
489 |
if self.Input.TestPoint(pt, exclude): |
|
490 |
return self.Input |
|
491 |
# Test output connector |
|
492 |
if self.Output.TestPoint(pt, exclude): |
|
493 |
return self.Output |
|
494 |
return None |
|
495 |
||
27 | 496 |
# Refresh the positions of the block connectors |
497 |
def RefreshConnectors(self): |
|
145 | 498 |
scaling = self.Parent.GetScaling() |
499 |
position = self.Size[1] / 2 + 1 |
|
500 |
if scaling is not None: |
|
501 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
502 |
self.Input.SetPosition(wx.Point(0, position)) |
|
503 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 504 |
self.RefreshConnected() |
505 |
||
0 | 506 |
# Changes the contact name |
507 |
def SetName(self, name): |
|
508 |
self.Name = name |
|
42 | 509 |
self.RefreshNameSize() |
0 | 510 |
|
511 |
# Returns the contact name |
|
512 |
def GetName(self): |
|
513 |
return self.Name |
|
514 |
||
515 |
# Changes the contact type |
|
516 |
def SetType(self, type): |
|
517 |
self.Type = type |
|
50 | 518 |
self.RefreshTypeSize() |
0 | 519 |
|
520 |
# Returns the contact type |
|
521 |
def GetType(self): |
|
522 |
return self.Type |
|
523 |
||
524 |
# Method called when a LeftDClick event have been generated |
|
27 | 525 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 526 |
# Edit the contact properties |
527 |
self.Parent.EditContactContent(self) |
|
528 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
529 |
# 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
|
530 |
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
|
531 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
532 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
533 |
|
0 | 534 |
# Refreshes the contact model |
535 |
def RefreshModel(self, move=True): |
|
536 |
self.Parent.RefreshContactModel(self) |
|
537 |
# If contact has moved, refresh the model of wires connected to output |
|
538 |
if move: |
|
539 |
self.Output.RefreshWires() |
|
540 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
541 |
# 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
|
542 |
def DrawHighlightment(self, dc): |
144 | 543 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
544 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
545 |
dc.SetLogicalFunction(wx.AND) |
|
546 |
# Draw two rectangles for representing the contact |
|
547 |
dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
548 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
549 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
550 |
|
0 | 551 |
# Draws contact |
552 |
def Draw(self, dc): |
|
144 | 553 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
554 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
555 |
dc.SetBrush(wx.BLACK_BRUSH) |
0 | 556 |
# Draw two rectangles for representing the contact |
557 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
|
558 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
|
559 |
# Draw contact name |
|
42 | 560 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
561 |
self.Pos.y - (self.NameSize[1] + 2)) |
|
0 | 562 |
# Draw the modifier symbol in the middle of contact |
563 |
typetext = "" |
|
564 |
if self.Type == CONTACT_REVERSE: |
|
565 |
typetext = "/" |
|
566 |
elif self.Type == CONTACT_RISING: |
|
567 |
typetext = "P" |
|
568 |
elif self.Type == CONTACT_FALLING: |
|
569 |
typetext = "N" |
|
570 |
if typetext != "": |
|
42 | 571 |
dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1, |
572 |
self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2) |
|
0 | 573 |
# Draw input and output connectors |
574 |
self.Input.Draw(dc) |
|
575 |
self.Output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
576 |
|
0 | 577 |
|
578 |
#------------------------------------------------------------------------------- |
|
579 |
# Ladder Diagram Coil |
|
580 |
#------------------------------------------------------------------------------- |
|
581 |
||
582 |
""" |
|
583 |
Class that implements the graphic representation of a coil |
|
584 |
""" |
|
585 |
||
586 |
class LD_Coil(Graphic_Element): |
|
587 |
||
588 |
# Create a new coil |
|
589 |
def __init__(self, parent, type, name, id = None): |
|
590 |
Graphic_Element.__init__(self, parent) |
|
591 |
self.Type = type |
|
592 |
self.Name = name |
|
593 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
594 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
0 | 595 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
596 |
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
|
597 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 598 |
self.RefreshNameSize() |
599 |
self.RefreshTypeSize() |
|
0 | 600 |
|
601 |
# Destructor |
|
602 |
def __del__(self): |
|
603 |
self.Input = None |
|
604 |
self.Output = None |
|
605 |
||
112 | 606 |
# Make a clone of this LD_Coil |
162 | 607 |
def Clone(self, parent, id = None, pos = None): |
608 |
coil = LD_Coil(parent, self.Type, self.Name, id) |
|
112 | 609 |
coil.SetSize(self.Size[0], self.Size[1]) |
610 |
if pos is not None: |
|
611 |
coil.SetPosition(pos.x, pos.y) |
|
612 |
coil.Input = self.Input.Clone(coil) |
|
613 |
coil.Output = self.Output.Clone(coil) |
|
614 |
return coil |
|
615 |
||
144 | 616 |
# Returns the RedrawRect |
617 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
618 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
619 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
620 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
621 |
if movex != 0 or movey != 0: |
|
622 |
if self.Input.IsConnected(): |
|
623 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
624 |
if self.Output.IsConnected(): |
|
625 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
626 |
return rect |
|
627 |
||
0 | 628 |
# Forbids to change the contact size |
629 |
def SetSize(self, width, height): |
|
42 | 630 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 631 |
Graphic_Element.SetSize(self, width, height) |
632 |
self.RefreshConnectors() |
|
0 | 633 |
|
634 |
# Delete this coil by calling the appropriate method |
|
635 |
def Delete(self): |
|
636 |
self.Parent.DeleteCoil(self) |
|
637 |
||
638 |
# Unconnect input and output |
|
639 |
def Clean(self): |
|
640 |
self.Input.UnConnect() |
|
641 |
self.Output.UnConnect() |
|
642 |
||
42 | 643 |
# Refresh the size of text for name |
644 |
def RefreshNameSize(self): |
|
645 |
if self.Name != "": |
|
165 | 646 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 647 |
else: |
648 |
self.NameSize = 0, 0 |
|
649 |
||
650 |
# Refresh the size of text for type |
|
651 |
def RefreshTypeSize(self): |
|
652 |
typetext = "" |
|
653 |
if self.Type == COIL_REVERSE: |
|
654 |
typetext = "/" |
|
655 |
elif self.Type == COIL_SET: |
|
656 |
typetext = "S" |
|
657 |
elif self.Type == COIL_RESET: |
|
658 |
typetext = "R" |
|
659 |
if typetext != "": |
|
165 | 660 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 661 |
else: |
662 |
self.TypeSize = 0, 0 |
|
663 |
||
0 | 664 |
# Refresh the coil bounding box |
665 |
def RefreshBoundingBox(self): |
|
666 |
# Calculate the size of the name outside the coil |
|
165 | 667 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 668 |
# Calculate the bounding box size |
669 |
if self.Name != "": |
|
670 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
671 |
bbx_width = max(self.Size[0], text_width) |
|
672 |
bbx_y = self.Pos.y - (text_height + 2) |
|
673 |
bbx_height = self.Size[1] + (text_height + 2) |
|
674 |
else: |
|
675 |
bbx_x = self.Pos.x |
|
676 |
bbx_width = self.Size[0] |
|
677 |
bbx_y = self.Pos.y |
|
678 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
679 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
27 | 680 |
|
681 |
# Returns the block minimum size |
|
682 |
def GetMinSize(self): |
|
683 |
return LD_ELEMENT_SIZE |
|
0 | 684 |
|
685 |
# Refresh the position of wire connected to coil |
|
686 |
def RefreshConnected(self, exclude = []): |
|
687 |
self.Input.MoveConnected(exclude) |
|
688 |
self.Output.MoveConnected(exclude) |
|
689 |
||
690 |
# Returns the coil connector that starts with the point given if it exists |
|
27 | 691 |
def GetConnector(self, position, name = None): |
692 |
# if a name is given |
|
693 |
if name: |
|
694 |
# Test input and output connector |
|
695 |
if self.Input and name == self.Input.GetName(): |
|
696 |
return self.Input |
|
697 |
if self.Output and name == self.Output.GetName(): |
|
698 |
return self.Output |
|
0 | 699 |
# Test input connector |
700 |
input_pos = self.Input.GetRelPosition() |
|
701 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
702 |
return self.Input |
|
703 |
# Test output connector |
|
704 |
output_pos = self.Output.GetRelPosition() |
|
705 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
706 |
return self.Output |
|
707 |
return None |
|
708 |
||
709 |
# Returns input and output coil connectors |
|
710 |
def GetConnectors(self): |
|
711 |
return {"input":self.Input,"output":self.Output} |
|
712 |
||
713 |
# Test if point given is on coil input or output connector |
|
714 |
def TestConnector(self, pt, exclude=True): |
|
715 |
# Test input connector |
|
716 |
if self.Input.TestPoint(pt, exclude): |
|
717 |
return self.Input |
|
718 |
# Test output connector |
|
719 |
if self.Output.TestPoint(pt, exclude): |
|
720 |
return self.Output |
|
721 |
return None |
|
722 |
||
27 | 723 |
# Refresh the positions of the block connectors |
724 |
def RefreshConnectors(self): |
|
145 | 725 |
scaling = self.Parent.GetScaling() |
726 |
position = self.Size[1] / 2 + 1 |
|
727 |
if scaling is not None: |
|
728 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
729 |
self.Input.SetPosition(wx.Point(0, position)) |
|
730 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 731 |
self.RefreshConnected() |
732 |
||
0 | 733 |
# Changes the coil name |
734 |
def SetName(self, name): |
|
735 |
self.Name = name |
|
42 | 736 |
self.RefreshNameSize() |
0 | 737 |
|
738 |
# Returns the coil name |
|
739 |
def GetName(self): |
|
740 |
return self.Name |
|
741 |
||
742 |
# Changes the coil type |
|
743 |
def SetType(self, type): |
|
744 |
self.Type = type |
|
42 | 745 |
self.RefreshTypeSize() |
0 | 746 |
|
747 |
# Returns the coil type |
|
748 |
def GetType(self): |
|
749 |
return self.Type |
|
750 |
||
751 |
# Method called when a LeftDClick event have been generated |
|
27 | 752 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 753 |
# Edit the coil properties |
754 |
self.Parent.EditCoilContent(self) |
|
755 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
756 |
# 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
|
757 |
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
|
758 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
759 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
760 |
|
0 | 761 |
# Refreshes the coil model |
762 |
def RefreshModel(self, move=True): |
|
763 |
self.Parent.RefreshCoilModel(self) |
|
764 |
# If coil has moved, refresh the model of wires connected to output |
|
765 |
if move: |
|
766 |
self.Output.RefreshWires() |
|
767 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
768 |
# 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
|
769 |
def DrawHighlightment(self, dc): |
144 | 770 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) |
771 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
772 |
dc.SetLogicalFunction(wx.AND) |
|
773 |
# Draw a two circle arcs for representing the coil |
|
774 |
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) |
|
775 |
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) |
|
776 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
777 |
|
0 | 778 |
# Draws coil |
779 |
def Draw(self, dc): |
|
144 | 780 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
781 |
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
|
782 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
0 | 783 |
# Draw a two circle arcs for representing the coil |
784 |
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) |
|
785 |
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
|
786 |
dc.SetPen(wx.BLACK_PEN) |
0 | 787 |
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
788 |
# Draw coil name |
|
42 | 789 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
790 |
self.Pos.y - (self.NameSize[1] + 2)) |
|
0 | 791 |
# Draw the modifier symbol in the middle of coil |
792 |
typetext = "" |
|
793 |
if self.Type == COIL_REVERSE: |
|
794 |
typetext = "/" |
|
795 |
elif self.Type == COIL_SET: |
|
796 |
typetext = "S" |
|
797 |
elif self.Type == COIL_RESET: |
|
798 |
typetext = "R" |
|
799 |
if typetext != "": |
|
42 | 800 |
dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1, |
801 |
self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2) |
|
0 | 802 |
# Draw input and output connectors |
803 |
self.Input.Draw(dc) |
|
804 |
self.Output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
805 |