author | lbessard |
Wed, 16 Apr 2008 09:48:06 +0200 | |
changeset 203 | 76c407fb33fe |
parent 180 | 3b0d3ea35ee5 |
child 213 | 4931959ea256 |
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) |
0 | 566 |
# Draw two rectangles for representing the contact |
567 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
|
568 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
|
569 |
# Draw contact name |
|
42 | 570 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
571 |
self.Pos.y - (self.NameSize[1] + 2)) |
|
0 | 572 |
# Draw the modifier symbol in the middle of contact |
573 |
typetext = "" |
|
574 |
if self.Type == CONTACT_REVERSE: |
|
575 |
typetext = "/" |
|
576 |
elif self.Type == CONTACT_RISING: |
|
577 |
typetext = "P" |
|
578 |
elif self.Type == CONTACT_FALLING: |
|
579 |
typetext = "N" |
|
580 |
if typetext != "": |
|
42 | 581 |
dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1, |
582 |
self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2) |
|
0 | 583 |
# Draw input and output connectors |
584 |
self.Input.Draw(dc) |
|
585 |
self.Output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
586 |
|
0 | 587 |
|
588 |
#------------------------------------------------------------------------------- |
|
589 |
# Ladder Diagram Coil |
|
590 |
#------------------------------------------------------------------------------- |
|
591 |
||
592 |
""" |
|
593 |
Class that implements the graphic representation of a coil |
|
594 |
""" |
|
595 |
||
596 |
class LD_Coil(Graphic_Element): |
|
597 |
||
598 |
# Create a new coil |
|
599 |
def __init__(self, parent, type, name, id = None): |
|
600 |
Graphic_Element.__init__(self, parent) |
|
601 |
self.Type = type |
|
602 |
self.Name = name |
|
603 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
604 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
0 | 605 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
606 |
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
|
607 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 608 |
self.RefreshNameSize() |
609 |
self.RefreshTypeSize() |
|
0 | 610 |
|
611 |
# Destructor |
|
612 |
def __del__(self): |
|
613 |
self.Input = None |
|
614 |
self.Output = None |
|
615 |
||
112 | 616 |
# Make a clone of this LD_Coil |
162 | 617 |
def Clone(self, parent, id = None, pos = None): |
618 |
coil = LD_Coil(parent, self.Type, self.Name, id) |
|
112 | 619 |
coil.SetSize(self.Size[0], self.Size[1]) |
620 |
if pos is not None: |
|
621 |
coil.SetPosition(pos.x, pos.y) |
|
622 |
coil.Input = self.Input.Clone(coil) |
|
623 |
coil.Output = self.Output.Clone(coil) |
|
624 |
return coil |
|
625 |
||
144 | 626 |
# Returns the RedrawRect |
627 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
628 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
629 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
630 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
631 |
if movex != 0 or movey != 0: |
|
632 |
if self.Input.IsConnected(): |
|
633 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
634 |
if self.Output.IsConnected(): |
|
635 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
636 |
return rect |
|
637 |
||
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
638 |
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
|
639 |
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
|
640 |
|
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
641 |
# Forbids to change the Coil size |
0 | 642 |
def SetSize(self, width, height): |
42 | 643 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 644 |
Graphic_Element.SetSize(self, width, height) |
645 |
self.RefreshConnectors() |
|
0 | 646 |
|
647 |
# Delete this coil by calling the appropriate method |
|
648 |
def Delete(self): |
|
649 |
self.Parent.DeleteCoil(self) |
|
650 |
||
651 |
# Unconnect input and output |
|
652 |
def Clean(self): |
|
653 |
self.Input.UnConnect() |
|
654 |
self.Output.UnConnect() |
|
655 |
||
42 | 656 |
# Refresh the size of text for name |
657 |
def RefreshNameSize(self): |
|
658 |
if self.Name != "": |
|
165 | 659 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 660 |
else: |
661 |
self.NameSize = 0, 0 |
|
662 |
||
663 |
# Refresh the size of text for type |
|
664 |
def RefreshTypeSize(self): |
|
665 |
typetext = "" |
|
666 |
if self.Type == COIL_REVERSE: |
|
667 |
typetext = "/" |
|
668 |
elif self.Type == COIL_SET: |
|
669 |
typetext = "S" |
|
670 |
elif self.Type == COIL_RESET: |
|
671 |
typetext = "R" |
|
672 |
if typetext != "": |
|
165 | 673 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 674 |
else: |
675 |
self.TypeSize = 0, 0 |
|
676 |
||
0 | 677 |
# Refresh the coil bounding box |
678 |
def RefreshBoundingBox(self): |
|
679 |
# Calculate the size of the name outside the coil |
|
165 | 680 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 681 |
# Calculate the bounding box size |
682 |
if self.Name != "": |
|
683 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
684 |
bbx_width = max(self.Size[0], text_width) |
|
685 |
bbx_y = self.Pos.y - (text_height + 2) |
|
686 |
bbx_height = self.Size[1] + (text_height + 2) |
|
687 |
else: |
|
688 |
bbx_x = self.Pos.x |
|
689 |
bbx_width = self.Size[0] |
|
690 |
bbx_y = self.Pos.y |
|
691 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
692 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
27 | 693 |
|
694 |
# Returns the block minimum size |
|
695 |
def GetMinSize(self): |
|
696 |
return LD_ELEMENT_SIZE |
|
0 | 697 |
|
698 |
# Refresh the position of wire connected to coil |
|
699 |
def RefreshConnected(self, exclude = []): |
|
700 |
self.Input.MoveConnected(exclude) |
|
701 |
self.Output.MoveConnected(exclude) |
|
702 |
||
703 |
# Returns the coil connector that starts with the point given if it exists |
|
27 | 704 |
def GetConnector(self, position, name = None): |
705 |
# if a name is given |
|
706 |
if name: |
|
707 |
# Test input and output connector |
|
708 |
if self.Input and name == self.Input.GetName(): |
|
709 |
return self.Input |
|
710 |
if self.Output and name == self.Output.GetName(): |
|
711 |
return self.Output |
|
0 | 712 |
# Test input connector |
713 |
input_pos = self.Input.GetRelPosition() |
|
714 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
715 |
return self.Input |
|
716 |
# Test output connector |
|
717 |
output_pos = self.Output.GetRelPosition() |
|
718 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
719 |
return self.Output |
|
720 |
return None |
|
721 |
||
722 |
# Returns input and output coil connectors |
|
723 |
def GetConnectors(self): |
|
724 |
return {"input":self.Input,"output":self.Output} |
|
725 |
||
726 |
# Test if point given is on coil input or output connector |
|
727 |
def TestConnector(self, pt, exclude=True): |
|
728 |
# Test input connector |
|
729 |
if self.Input.TestPoint(pt, exclude): |
|
730 |
return self.Input |
|
731 |
# Test output connector |
|
732 |
if self.Output.TestPoint(pt, exclude): |
|
733 |
return self.Output |
|
734 |
return None |
|
735 |
||
27 | 736 |
# Refresh the positions of the block connectors |
737 |
def RefreshConnectors(self): |
|
145 | 738 |
scaling = self.Parent.GetScaling() |
739 |
position = self.Size[1] / 2 + 1 |
|
740 |
if scaling is not None: |
|
741 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
742 |
self.Input.SetPosition(wx.Point(0, position)) |
|
743 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 744 |
self.RefreshConnected() |
745 |
||
0 | 746 |
# Changes the coil name |
747 |
def SetName(self, name): |
|
748 |
self.Name = name |
|
42 | 749 |
self.RefreshNameSize() |
0 | 750 |
|
751 |
# Returns the coil name |
|
752 |
def GetName(self): |
|
753 |
return self.Name |
|
754 |
||
755 |
# Changes the coil type |
|
756 |
def SetType(self, type): |
|
757 |
self.Type = type |
|
42 | 758 |
self.RefreshTypeSize() |
0 | 759 |
|
760 |
# Returns the coil type |
|
761 |
def GetType(self): |
|
762 |
return self.Type |
|
763 |
||
764 |
# Method called when a LeftDClick event have been generated |
|
27 | 765 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 766 |
# Edit the coil properties |
767 |
self.Parent.EditCoilContent(self) |
|
768 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
769 |
# 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
|
770 |
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
|
771 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
772 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
773 |
|
0 | 774 |
# Refreshes the coil model |
775 |
def RefreshModel(self, move=True): |
|
776 |
self.Parent.RefreshCoilModel(self) |
|
777 |
# If coil has moved, refresh the model of wires connected to output |
|
778 |
if move: |
|
779 |
self.Output.RefreshWires() |
|
780 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
781 |
# 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
|
782 |
def DrawHighlightment(self, dc): |
144 | 783 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) |
784 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
785 |
dc.SetLogicalFunction(wx.AND) |
|
786 |
# Draw a two circle arcs for representing the coil |
|
787 |
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) |
|
788 |
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) |
|
789 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
790 |
|
0 | 791 |
# Draws coil |
792 |
def Draw(self, dc): |
|
144 | 793 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
794 |
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
|
795 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
0 | 796 |
# Draw a two circle arcs for representing the coil |
797 |
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) |
|
798 |
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
|
799 |
dc.SetPen(wx.BLACK_PEN) |
0 | 800 |
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
801 |
# Draw coil name |
|
42 | 802 |
dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2, |
803 |
self.Pos.y - (self.NameSize[1] + 2)) |
|
0 | 804 |
# Draw the modifier symbol in the middle of coil |
805 |
typetext = "" |
|
806 |
if self.Type == COIL_REVERSE: |
|
807 |
typetext = "/" |
|
808 |
elif self.Type == COIL_SET: |
|
809 |
typetext = "S" |
|
810 |
elif self.Type == COIL_RESET: |
|
811 |
typetext = "R" |
|
812 |
if typetext != "": |
|
42 | 813 |
dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1, |
814 |
self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2) |
|
0 | 815 |
# Draw input and output connectors |
816 |
self.Input.Draw(dc) |
|
817 |
self.Output.Draw(dc) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
818 |