author | lbessard |
Thu, 28 Aug 2008 14:32:42 +0200 | |
changeset 244 | 05f6e0d7710c |
parent 243 | c5da8b706cde |
child 249 | d8425712acef |
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: |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
91 |
return Graphic_Element.HitTest(self, pt) or self.TestConnector(pt, exclude=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 |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
244 |
def TestConnector(self, pt, direction = None, exclude = True): |
0 | 245 |
for connector in self.Connectors: |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
246 |
if connector and connector.TestPoint(pt, direction, exclude): |
0 | 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 |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
284 |
connector = self.TestConnector(pos, exclude=False) |
27 | 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]) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
375 |
self.Errors = {} |
0 | 376 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
377 |
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
|
378 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 379 |
self.RefreshNameSize() |
380 |
self.RefreshTypeSize() |
|
0 | 381 |
|
382 |
# Destructor |
|
383 |
def __del__(self): |
|
384 |
self.Input = None |
|
385 |
self.Output = None |
|
386 |
||
112 | 387 |
# Make a clone of this LD_Contact |
162 | 388 |
def Clone(self, parent, id = None, pos = None): |
389 |
contact = LD_Contact(parent, self.Type, self.Name, id) |
|
112 | 390 |
contact.SetSize(self.Size[0], self.Size[1]) |
391 |
if pos is not None: |
|
392 |
contact.SetPosition(pos.x, pos.y) |
|
393 |
contact.Input = self.Input.Clone(contact) |
|
394 |
contact.Output = self.Output.Clone(contact) |
|
395 |
return contact |
|
396 |
||
144 | 397 |
# Returns the RedrawRect |
398 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
399 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
400 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
401 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
402 |
if movex != 0 or movey != 0: |
|
403 |
if self.Input.IsConnected(): |
|
404 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
405 |
if self.Output.IsConnected(): |
|
406 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
407 |
return rect |
|
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
408 |
|
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
409 |
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
|
410 |
return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling, height_fac = 2) |
144 | 411 |
|
0 | 412 |
# Forbids to change the contact size |
413 |
def SetSize(self, width, height): |
|
42 | 414 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 415 |
Graphic_Element.SetSize(self, width, height) |
416 |
self.RefreshConnectors() |
|
0 | 417 |
|
418 |
# Delete this contact by calling the appropriate method |
|
419 |
def Delete(self): |
|
420 |
self.Parent.DeleteContact(self) |
|
421 |
||
422 |
# Unconnect input and output |
|
423 |
def Clean(self): |
|
61
dc7142ae9438
Adding possibility to change Type and Pin number of power rails
lbessard
parents:
58
diff
changeset
|
424 |
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
|
425 |
self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) |
0 | 426 |
|
42 | 427 |
# Refresh the size of text for name |
428 |
def RefreshNameSize(self): |
|
429 |
if self.Name != "": |
|
165 | 430 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 431 |
else: |
432 |
self.NameSize = 0, 0 |
|
433 |
||
434 |
# Refresh the size of text for type |
|
435 |
def RefreshTypeSize(self): |
|
436 |
typetext = "" |
|
437 |
if self.Type == CONTACT_REVERSE: |
|
438 |
typetext = "/" |
|
439 |
elif self.Type == CONTACT_RISING: |
|
440 |
typetext = "P" |
|
441 |
elif self.Type == CONTACT_FALLING: |
|
442 |
typetext = "N" |
|
443 |
if typetext != "": |
|
165 | 444 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 445 |
else: |
446 |
self.TypeSize = 0, 0 |
|
447 |
||
0 | 448 |
# Refresh the contact bounding box |
449 |
def RefreshBoundingBox(self): |
|
450 |
# Calculate the size of the name outside the contact |
|
165 | 451 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 452 |
# Calculate the bounding box size |
453 |
if self.Name != "": |
|
454 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
455 |
bbx_width = max(self.Size[0], text_width) |
|
456 |
bbx_y = self.Pos.y - (text_height + 2) |
|
457 |
bbx_height = self.Size[1] + (text_height + 2) |
|
458 |
else: |
|
459 |
bbx_x = self.Pos.x |
|
460 |
bbx_width = self.Size[0] |
|
461 |
bbx_y = self.Pos.y |
|
462 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
463 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
0 | 464 |
|
27 | 465 |
# Returns the block minimum size |
466 |
def GetMinSize(self): |
|
467 |
return LD_ELEMENT_SIZE |
|
468 |
||
0 | 469 |
# Refresh the position of wire connected to contact |
470 |
def RefreshConnected(self, exclude = []): |
|
471 |
self.Input.MoveConnected(exclude) |
|
472 |
self.Output.MoveConnected(exclude) |
|
473 |
||
474 |
# Returns the contact connector that starts with the point given if it exists |
|
27 | 475 |
def GetConnector(self, position, name = None): |
476 |
# if a name is given |
|
477 |
if name: |
|
478 |
# Test input and output connector |
|
479 |
if name == self.Input.GetName(): |
|
480 |
return self.Input |
|
481 |
if name == self.Output.GetName(): |
|
482 |
return self.Output |
|
0 | 483 |
# Test input connector |
484 |
input_pos = self.Input.GetRelPosition() |
|
485 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
486 |
return self.Input |
|
487 |
# Test output connector |
|
488 |
output_pos = self.Output.GetRelPosition() |
|
489 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
490 |
return self.Output |
|
491 |
return None |
|
492 |
||
493 |
# Returns input and output contact connectors |
|
494 |
def GetConnectors(self): |
|
495 |
return {"input":self.Input,"output":self.Output} |
|
496 |
||
497 |
# Test if point given is on contact input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
498 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 499 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
500 |
if self.Input.TestPoint(pt, direction, exclude): |
0 | 501 |
return self.Input |
502 |
# Test output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
503 |
if self.Output.TestPoint(pt, direction, exclude): |
0 | 504 |
return self.Output |
505 |
return None |
|
506 |
||
27 | 507 |
# Refresh the positions of the block connectors |
508 |
def RefreshConnectors(self): |
|
145 | 509 |
scaling = self.Parent.GetScaling() |
510 |
position = self.Size[1] / 2 + 1 |
|
511 |
if scaling is not None: |
|
512 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
513 |
self.Input.SetPosition(wx.Point(0, position)) |
|
514 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 515 |
self.RefreshConnected() |
516 |
||
0 | 517 |
# Changes the contact name |
518 |
def SetName(self, name): |
|
519 |
self.Name = name |
|
42 | 520 |
self.RefreshNameSize() |
0 | 521 |
|
522 |
# Returns the contact name |
|
523 |
def GetName(self): |
|
524 |
return self.Name |
|
525 |
||
526 |
# Changes the contact type |
|
527 |
def SetType(self, type): |
|
528 |
self.Type = type |
|
50 | 529 |
self.RefreshTypeSize() |
0 | 530 |
|
531 |
# Returns the contact type |
|
532 |
def GetType(self): |
|
533 |
return self.Type |
|
534 |
||
535 |
# Method called when a LeftDClick event have been generated |
|
27 | 536 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 537 |
# Edit the contact properties |
538 |
self.Parent.EditContactContent(self) |
|
539 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
540 |
# 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
|
541 |
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
|
542 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
543 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
544 |
|
0 | 545 |
# Refreshes the contact model |
546 |
def RefreshModel(self, move=True): |
|
547 |
self.Parent.RefreshContactModel(self) |
|
548 |
# If contact has moved, refresh the model of wires connected to output |
|
549 |
if move: |
|
550 |
self.Output.RefreshWires() |
|
551 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
552 |
# 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
|
553 |
def DrawHighlightment(self, dc): |
144 | 554 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) |
555 |
dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) |
|
556 |
dc.SetLogicalFunction(wx.AND) |
|
557 |
# Draw two rectangles for representing the contact |
|
558 |
dc.DrawRectangle(self.Pos.x - 2, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
559 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 3, self.Pos.y - 2, 6, self.Size[1] + 5) |
|
560 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
561 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
562 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
563 |
self.Errors[infos[0]] = (start[1], end[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
564 |
|
0 | 565 |
# Draws contact |
566 |
def Draw(self, dc): |
|
144 | 567 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
568 |
dc.SetPen(wx.BLACK_PEN) |
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
569 |
dc.SetBrush(wx.BLACK_BRUSH) |
213 | 570 |
|
571 |
# Compiling contact type modifier symbol |
|
0 | 572 |
typetext = "" |
573 |
if self.Type == CONTACT_REVERSE: |
|
574 |
typetext = "/" |
|
575 |
elif self.Type == CONTACT_RISING: |
|
576 |
typetext = "P" |
|
577 |
elif self.Type == CONTACT_FALLING: |
|
578 |
typetext = "N" |
|
213 | 579 |
|
580 |
if getattr(dc, "printing", False): |
|
581 |
name_size = dc.GetTextExtent(self.Name) |
|
582 |
if typetext != "": |
|
583 |
type_size = dc.GetTextExtent(typetext) |
|
584 |
else: |
|
585 |
name_size = self.NameSize |
|
586 |
if typetext != "": |
|
587 |
type_size = self.TypeSize |
|
588 |
||
589 |
# Draw two rectangles for representing the contact |
|
590 |
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1) |
|
591 |
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1) |
|
592 |
# Draw contact name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
593 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
594 |
self.Pos.y - (name_size[1] + 2)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
595 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
213 | 596 |
# Draw the modifier symbol in the middle of contact |
0 | 597 |
if typetext != "": |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
598 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
599 |
self.Pos.y + (self.Size[1] - type_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
600 |
dc.DrawText(typetext, type_pos[0], type_pos[1]) |
0 | 601 |
# Draw input and output connectors |
602 |
self.Input.Draw(dc) |
|
603 |
self.Output.Draw(dc) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
604 |
if "reference" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
605 |
HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
606 |
if typetext != "" and ("negated" in self.Errors or "rising" in self.Errors or "falling" in self.Errors): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
607 |
HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1]) |
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
608 |
|
0 | 609 |
|
610 |
#------------------------------------------------------------------------------- |
|
611 |
# Ladder Diagram Coil |
|
612 |
#------------------------------------------------------------------------------- |
|
613 |
||
614 |
""" |
|
615 |
Class that implements the graphic representation of a coil |
|
616 |
""" |
|
617 |
||
618 |
class LD_Coil(Graphic_Element): |
|
619 |
||
620 |
# Create a new coil |
|
621 |
def __init__(self, parent, type, name, id = None): |
|
622 |
Graphic_Element.__init__(self, parent) |
|
623 |
self.Type = type |
|
624 |
self.Name = name |
|
625 |
self.Id = id |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
626 |
self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1]) |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
627 |
self.Errors = {} |
0 | 628 |
# Create an input and output connector |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
629 |
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
|
630 |
self.Output = Connector(self, "", "BOOL", wx.Point(self.Size[0], self.Size[1] / 2 + 1), EAST) |
42 | 631 |
self.RefreshNameSize() |
632 |
self.RefreshTypeSize() |
|
0 | 633 |
|
634 |
# Destructor |
|
635 |
def __del__(self): |
|
636 |
self.Input = None |
|
637 |
self.Output = None |
|
638 |
||
112 | 639 |
# Make a clone of this LD_Coil |
162 | 640 |
def Clone(self, parent, id = None, pos = None): |
641 |
coil = LD_Coil(parent, self.Type, self.Name, id) |
|
112 | 642 |
coil.SetSize(self.Size[0], self.Size[1]) |
643 |
if pos is not None: |
|
644 |
coil.SetPosition(pos.x, pos.y) |
|
645 |
coil.Input = self.Input.Clone(coil) |
|
646 |
coil.Output = self.Output.Clone(coil) |
|
647 |
return coil |
|
648 |
||
144 | 649 |
# Returns the RedrawRect |
650 |
def GetRedrawRect(self, movex = 0, movey = 0): |
|
651 |
rect = Graphic_Element.GetRedrawRect(self, movex, movey) |
|
652 |
rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) |
|
653 |
rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) |
|
654 |
if movex != 0 or movey != 0: |
|
655 |
if self.Input.IsConnected(): |
|
656 |
rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) |
|
657 |
if self.Output.IsConnected(): |
|
658 |
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) |
|
659 |
return rect |
|
660 |
||
180
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
661 |
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
|
662 |
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
|
663 |
|
3b0d3ea35ee5
Fixed bad handle initialisation, causing exception on rightup event in some cases.
etisserant
parents:
175
diff
changeset
|
664 |
# Forbids to change the Coil size |
0 | 665 |
def SetSize(self, width, height): |
42 | 666 |
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: |
27 | 667 |
Graphic_Element.SetSize(self, width, height) |
668 |
self.RefreshConnectors() |
|
0 | 669 |
|
670 |
# Delete this coil by calling the appropriate method |
|
671 |
def Delete(self): |
|
672 |
self.Parent.DeleteCoil(self) |
|
673 |
||
674 |
# Unconnect input and output |
|
675 |
def Clean(self): |
|
676 |
self.Input.UnConnect() |
|
677 |
self.Output.UnConnect() |
|
678 |
||
42 | 679 |
# Refresh the size of text for name |
680 |
def RefreshNameSize(self): |
|
681 |
if self.Name != "": |
|
165 | 682 |
self.NameSize = self.Parent.GetTextExtent(self.Name) |
42 | 683 |
else: |
684 |
self.NameSize = 0, 0 |
|
685 |
||
686 |
# Refresh the size of text for type |
|
687 |
def RefreshTypeSize(self): |
|
688 |
typetext = "" |
|
689 |
if self.Type == COIL_REVERSE: |
|
690 |
typetext = "/" |
|
691 |
elif self.Type == COIL_SET: |
|
692 |
typetext = "S" |
|
693 |
elif self.Type == COIL_RESET: |
|
694 |
typetext = "R" |
|
695 |
if typetext != "": |
|
165 | 696 |
self.TypeSize = self.Parent.GetTextExtent(typetext) |
42 | 697 |
else: |
698 |
self.TypeSize = 0, 0 |
|
699 |
||
0 | 700 |
# Refresh the coil bounding box |
701 |
def RefreshBoundingBox(self): |
|
702 |
# Calculate the size of the name outside the coil |
|
165 | 703 |
text_width, text_height = self.Parent.GetTextExtent(self.Name) |
0 | 704 |
# Calculate the bounding box size |
705 |
if self.Name != "": |
|
706 |
bbx_x = self.Pos.x - max(0, (text_width - self.Size[0]) / 2) |
|
707 |
bbx_width = max(self.Size[0], text_width) |
|
708 |
bbx_y = self.Pos.y - (text_height + 2) |
|
709 |
bbx_height = self.Size[1] + (text_height + 2) |
|
710 |
else: |
|
711 |
bbx_x = self.Pos.x |
|
712 |
bbx_width = self.Size[0] |
|
713 |
bbx_y = self.Pos.y |
|
714 |
bbx_height = self.Size[1] |
|
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
715 |
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) |
27 | 716 |
|
717 |
# Returns the block minimum size |
|
718 |
def GetMinSize(self): |
|
719 |
return LD_ELEMENT_SIZE |
|
0 | 720 |
|
721 |
# Refresh the position of wire connected to coil |
|
722 |
def RefreshConnected(self, exclude = []): |
|
723 |
self.Input.MoveConnected(exclude) |
|
724 |
self.Output.MoveConnected(exclude) |
|
725 |
||
726 |
# Returns the coil connector that starts with the point given if it exists |
|
27 | 727 |
def GetConnector(self, position, name = None): |
728 |
# if a name is given |
|
729 |
if name: |
|
730 |
# Test input and output connector |
|
731 |
if self.Input and name == self.Input.GetName(): |
|
732 |
return self.Input |
|
733 |
if self.Output and name == self.Output.GetName(): |
|
734 |
return self.Output |
|
0 | 735 |
# Test input connector |
736 |
input_pos = self.Input.GetRelPosition() |
|
737 |
if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: |
|
738 |
return self.Input |
|
739 |
# Test output connector |
|
740 |
output_pos = self.Output.GetRelPosition() |
|
741 |
if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: |
|
742 |
return self.Output |
|
743 |
return None |
|
744 |
||
745 |
# Returns input and output coil connectors |
|
746 |
def GetConnectors(self): |
|
747 |
return {"input":self.Input,"output":self.Output} |
|
748 |
||
749 |
# Test if point given is on coil input or output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
750 |
def TestConnector(self, pt, direction = None, exclude=True): |
0 | 751 |
# Test input connector |
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
752 |
if self.Input.TestPoint(pt, direction, exclude): |
0 | 753 |
return self.Input |
754 |
# Test output connector |
|
243
c5da8b706cde
Adding support for allowing connections only between an input and an output connector
lbessard
parents:
237
diff
changeset
|
755 |
if self.Output.TestPoint(pt, direction, exclude): |
0 | 756 |
return self.Output |
757 |
return None |
|
758 |
||
27 | 759 |
# Refresh the positions of the block connectors |
760 |
def RefreshConnectors(self): |
|
145 | 761 |
scaling = self.Parent.GetScaling() |
762 |
position = self.Size[1] / 2 + 1 |
|
763 |
if scaling is not None: |
|
764 |
position = round(float(self.Pos.y + position) / float(scaling[1])) * scaling[1] - self.Pos.y |
|
765 |
self.Input.SetPosition(wx.Point(0, position)) |
|
766 |
self.Output.SetPosition(wx.Point(self.Size[0], position)) |
|
27 | 767 |
self.RefreshConnected() |
768 |
||
0 | 769 |
# Changes the coil name |
770 |
def SetName(self, name): |
|
771 |
self.Name = name |
|
42 | 772 |
self.RefreshNameSize() |
0 | 773 |
|
774 |
# Returns the coil name |
|
775 |
def GetName(self): |
|
776 |
return self.Name |
|
777 |
||
778 |
# Changes the coil type |
|
779 |
def SetType(self, type): |
|
780 |
self.Type = type |
|
42 | 781 |
self.RefreshTypeSize() |
0 | 782 |
|
783 |
# Returns the coil type |
|
784 |
def GetType(self): |
|
785 |
return self.Type |
|
786 |
||
787 |
# Method called when a LeftDClick event have been generated |
|
27 | 788 |
def OnLeftDClick(self, event, dc, scaling): |
0 | 789 |
# Edit the coil properties |
790 |
self.Parent.EditCoilContent(self) |
|
791 |
||
127
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
792 |
# 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
|
793 |
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
|
794 |
# Popup the default menu |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
795 |
self.Parent.PopupDefaultMenu() |
436268f31dae
Adding contextual menu on LD_Contact, LD_Coil, LD_PowerRail and SFC_ActionBlock
lbessard
parents:
112
diff
changeset
|
796 |
|
0 | 797 |
# Refreshes the coil model |
798 |
def RefreshModel(self, move=True): |
|
799 |
self.Parent.RefreshCoilModel(self) |
|
800 |
# If coil has moved, refresh the model of wires connected to output |
|
801 |
if move: |
|
802 |
self.Output.RefreshWires() |
|
803 |
||
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
804 |
# 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
|
805 |
def DrawHighlightment(self, dc): |
144 | 806 |
dc.SetPen(wx.Pen(HIGHLIGHTCOLOR, 6, wx.SOLID)) |
807 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
|
808 |
dc.SetLogicalFunction(wx.AND) |
|
809 |
# Draw a two circle arcs for representing the coil |
|
810 |
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) |
|
811 |
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) |
|
812 |
dc.SetLogicalFunction(wx.COPY) |
|
140
06d28f03f6f4
Adding highlighting on group or element when mouse is over
lbessard
parents:
138
diff
changeset
|
813 |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
814 |
def AddError(self, infos, start, end): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
815 |
self.Errors[infos[0]] = (start[1], end[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
816 |
|
0 | 817 |
# Draws coil |
818 |
def Draw(self, dc): |
|
144 | 819 |
Graphic_Element.Draw(self, dc) |
64
dd6f693e46a1
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
61
diff
changeset
|
820 |
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
|
821 |
dc.SetBrush(wx.TRANSPARENT_BRUSH) |
213 | 822 |
|
823 |
# Compiling coil type modifier symbol |
|
0 | 824 |
typetext = "" |
825 |
if self.Type == COIL_REVERSE: |
|
826 |
typetext = "/" |
|
827 |
elif self.Type == COIL_SET: |
|
828 |
typetext = "S" |
|
829 |
elif self.Type == COIL_RESET: |
|
830 |
typetext = "R" |
|
213 | 831 |
|
832 |
if getattr(dc, "printing", False) and not isinstance(dc, wx.PostScriptDC): |
|
833 |
# Draw an clipped ellipse for representing the coil |
|
834 |
clipping_box = dc.GetClippingBox() |
|
835 |
dc.SetClippingRegion(self.Pos.x - 1, self.Pos.y, self.Size[0] + 2, self.Size[1] + 1) |
|
836 |
dc.DrawEllipse(self.Pos.x, self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1, self.Size[0], int(self.Size[1] * sqrt(2)) - 1) |
|
837 |
dc.DestroyClippingRegion() |
|
838 |
if clipping_box != (0, 0, 0, 0): |
|
839 |
dc.SetClippingRegion(*clipping_box) |
|
840 |
name_size = dc.GetTextExtent(self.Name) |
|
841 |
if typetext != "": |
|
842 |
type_size = dc.GetTextExtent(typetext) |
|
843 |
else: |
|
844 |
# Draw a two ellipse arcs for representing the coil |
|
845 |
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) |
|
846 |
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) |
|
847 |
# Draw a point to avoid hole in left arc |
|
848 |
if not getattr(dc, "printing", False): |
|
849 |
dc.SetPen(wx.BLACK_PEN) |
|
850 |
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1) |
|
851 |
name_size = self.NameSize |
|
852 |
if typetext != "": |
|
853 |
type_size = self.TypeSize |
|
854 |
||
855 |
# Draw coil name |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
856 |
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
857 |
self.Pos.y - (name_size[1] + 2)) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
858 |
dc.DrawText(self.Name, name_pos[0], name_pos[1]) |
213 | 859 |
# Draw the modifier symbol in the middle of coil |
0 | 860 |
if typetext != "": |
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
861 |
type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2 + 1, |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
862 |
self.Pos.y + (self.Size[1] - type_size[1]) / 2) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
863 |
dc.DrawText(typetext, type_pos[0], type_pos[1]) |
0 | 864 |
# Draw input and output connectors |
865 |
self.Input.Draw(dc) |
|
866 |
self.Output.Draw(dc) |
|
231
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
867 |
if "reference" in self.Errors: |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
868 |
HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
869 |
if typetext != "" and ("negated" in self.Errors or "rising" in self.Errors or "falling" in self.Errors): |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
870 |
HighlightErrorZone(dc, type_pos[0], type_pos[1], type_size[0], type_size[1]) |
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
871 |
|
fc2d6cbb8b39
Adding support for highlighing compiling errors from matiec
lbessard
parents:
213
diff
changeset
|
872 |