--- a/graphics/LD_Objects.py Mon Aug 21 20:17:19 2017 +0000
+++ b/graphics/LD_Objects.py Mon Aug 21 23:22:58 2017 +0300
@@ -28,16 +28,17 @@
from graphics.DebugDataConsumer import DebugDataConsumer
from plcopen.structures import *
-#-------------------------------------------------------------------------------
+
+# -------------------------------------------------------------------------------
# Ladder Diagram PowerRail
-#-------------------------------------------------------------------------------
-
-"""
-Class that implements the graphic representation of a power rail
-"""
+# -------------------------------------------------------------------------------
+
class LD_PowerRail(Graphic_Element):
-
+ """
+ Class that implements the graphic representation of a power rail
+ """
+
# Create a new power rail
def __init__(self, parent, type, id=None, connectors=1):
Graphic_Element.__init__(self, parent)
@@ -47,14 +48,14 @@
self.Id = id
self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2]
self.SetType(type, connectors)
-
+
def Flush(self):
for connector in self.Connectors:
connector.Flush()
self.Connectors = []
-
+
# Make a clone of this LD_PowerRail
- def Clone(self, parent, id = None, pos = None):
+ def Clone(self, parent, id=None, pos=None):
powerrail = LD_PowerRail(parent, self.Type, id)
powerrail.SetSize(self.Size[0], self.Size[1])
if pos is not None:
@@ -65,13 +66,13 @@
for connector in self.Connectors:
powerrail.Connectors.append(connector.Clone(powerrail))
return powerrail
-
+
def GetConnectorTranslation(self, element):
return dict(zip([connector for connector in self.Connectors],
[connector for connector in element.Connectors]))
-
+
# Returns the RedrawRect
- def GetRedrawRect(self, movex = 0, movey = 0):
+ def GetRedrawRect(self, movex=0, movey=0):
rect = Graphic_Element.GetRedrawRect(self, movex, movey)
for connector in self.Connectors:
rect = rect.Union(connector.GetRedrawRect(movex, movey))
@@ -80,7 +81,7 @@
if connector.IsConnected():
rect = rect.Union(connector.GetConnectedRedrawRect(movex, movey))
return rect
-
+
# Forbids to change the power rail size
def SetSize(self, width, height):
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -88,47 +89,47 @@
else:
Graphic_Element.SetSize(self, LD_POWERRAIL_WIDTH, height)
self.RefreshConnectors()
-
+
# Forbids to select a power rail
def HitTest(self, pt, connectors=True):
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
- return Graphic_Element.HitTest(self, pt, connectors) or self.TestConnector(pt, exclude=False) != None
+ return Graphic_Element.HitTest(self, pt, connectors) or self.TestConnector(pt, exclude=False) is not None
return False
-
+
# Forbids to select a power rail
def IsInSelection(self, rect):
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
return Graphic_Element.IsInSelection(self, rect)
return False
-
+
# Deletes this power rail by calling the appropriate method
def Delete(self):
self.Parent.DeletePowerRail(self)
-
+
# Unconnect all connectors
def Clean(self):
for connector in self.Connectors:
- connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
-
+ connector.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
+
# Refresh the power rail bounding box
def RefreshBoundingBox(self):
self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
-
+
# Refresh the power rail size
def RefreshSize(self):
self.Size = wx.Size(LD_POWERRAIL_WIDTH, max(LD_LINE_SIZE * len(self.Connectors), self.Size[1]))
self.RefreshBoundingBox()
-
+
# Returns the block minimum size
def GetMinSize(self, default=False):
height = (LD_LINE_SIZE * (len(self.Connectors) - 1)
if default else 0)
return LD_POWERRAIL_WIDTH, height + self.Extensions[0] + self.Extensions[1]
-
+
# Add a connector or a blank to this power rail at the last place
def AddConnector(self):
self.InsertConnector(len(self.Connectors))
-
+
# Add a connector or a blank to this power rail at the place given
def InsertConnector(self, idx):
if self.Type == LEFTRAIL:
@@ -138,7 +139,7 @@
self.Connectors.insert(idx, connector)
self.RefreshSize()
self.RefreshConnectors()
-
+
# Moves the divergence connector given
def MoveConnector(self, connector, movey):
position = connector.GetRelPosition()
@@ -163,19 +164,19 @@
self.Size[1] = max(maxy + self.Extensions[1], self.Size[1])
connector.MoveConnected()
self.RefreshBoundingBox()
-
+
# Returns the index in connectors list for the connector given
def GetConnectorIndex(self, connector):
if connector in self.Connectors:
return self.Connectors.index(connector)
return None
-
+
# Delete the connector or blank from connectors list at the index given
def DeleteConnector(self, idx):
self.Connectors.pop(idx)
self.RefreshConnectors()
self.RefreshSize()
-
+
# Refresh the positions of the power rail connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
@@ -193,14 +194,14 @@
elif self.Type == RIGHTRAIL:
connector.SetPosition(wx.Point(0, position))
self.RefreshConnected()
-
+
# Refresh the position of wires connected to power rail
- def RefreshConnected(self, exclude = []):
+ def RefreshConnected(self, exclude=[]):
for connector in self.Connectors:
connector.MoveConnected(exclude)
-
- # Returns the power rail connector that starts with the point given if it exists
- def GetConnector(self, position, name = None):
+
+ # Returns the power rail connector that starts with the point given if it exists
+ def GetConnector(self, position, name=None):
# if a name is given
if name is not None:
# Test each connector if it exists
@@ -208,22 +209,22 @@
if name == connector.GetName():
return connector
return self.FindNearestConnector(position, [connector for connector in self.Connectors if connector is not None])
-
- # Returns all the power rail connectors
+
+ # Returns all the power rail connectors
def GetConnectors(self):
connectors = [connector for connector in self.Connectors if connector]
if self.Type == LEFTRAIL:
return {"inputs": [], "outputs": connectors}
else:
return {"inputs": connectors, "outputs": []}
-
+
# Test if point given is on one of the power rail connectors
- def TestConnector(self, pt, direction = None, exclude = True):
+ def TestConnector(self, pt, direction=None, exclude=True):
for connector in self.Connectors:
if connector.TestPoint(pt, direction, exclude):
return connector
return None
-
+
# Returns the power rail type
def SetType(self, type, connectors):
if type != self.Type or len(self.Connectors) != connectors:
@@ -235,11 +236,11 @@
for connector in xrange(connectors):
self.AddConnector()
self.RefreshSize()
-
+
# Returns the power rail type
def GetType(self):
return self.Type
-
+
# Method called when a LeftDown event have been generated
def OnLeftDown(self, event, dc, scaling):
self.RealConnectors = []
@@ -249,16 +250,16 @@
position = connector.GetRelPosition()
self.RealConnectors.append(max(0., min(float(position.y - self.Extensions[0]) / float(height), 1.)))
elif len(self.Connectors) > 1:
- self.RealConnectors = map(lambda x : x * 1 / (len(self.Connectors) - 1), xrange(len(self.Connectors)))
+ self.RealConnectors = map(lambda x: x * 1 / (len(self.Connectors) - 1), xrange(len(self.Connectors)))
else:
self.RealConnectors = [0.5]
Graphic_Element.OnLeftDown(self, event, dc, scaling)
-
+
# Method called when a LeftUp event have been generated
def OnLeftUp(self, event, dc, scaling):
Graphic_Element.OnLeftUp(self, event, dc, scaling)
self.RealConnectors = None
-
+
# Method called when a LeftDown event have been generated
def OnRightDown(self, event, dc, scaling):
pos = GetScaledEventPosition(event, dc, scaling)
@@ -272,12 +273,12 @@
self.oldPos = GetScaledEventPosition(event, dc, scaling)
else:
Graphic_Element.OnRightDown(self, event, dc, scaling)
-
+
# Method called when a LeftDClick event have been generated
def OnLeftDClick(self, event, dc, scaling):
# Edit the powerrail properties
self.Parent.EditPowerRailContent(self)
-
+
# Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
handle_type, handle = self.Handle
@@ -292,7 +293,7 @@
Graphic_Element.OnRightUp(self, event, dc, scaling)
else:
self.Parent.PopupDefaultMenu()
-
+
def Resize(self, x, y, width, height):
self.Move(x, y)
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -314,16 +315,16 @@
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling)
return 0, 0
-
+
# Refreshes the power rail model
def RefreshModel(self, move=True):
self.Parent.RefreshPowerRailModel(self)
- # If power rail has moved and power rail is of type LEFT, refresh the model
+ # If power rail has moved and power rail is of type LEFT, refresh the model
# of wires connected to connectors
if move and self.Type == LEFTRAIL:
for connector in self.Connectors:
connector.RefreshWires()
-
+
# Draws power rail
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
@@ -337,20 +338,20 @@
# Draw connectors
for connector in self.Connectors:
connector.Draw(dc)
-
-
-#-------------------------------------------------------------------------------
+
+
+# -------------------------------------------------------------------------------
# Ladder Diagram Contact
-#-------------------------------------------------------------------------------
-
-"""
-Class that implements the graphic representation of a contact
-"""
+# -------------------------------------------------------------------------------
+
class LD_Contact(Graphic_Element, DebugDataConsumer):
-
+ """
+ Class that implements the graphic representation of a contact
+ """
+
# Create a new contact
- def __init__(self, parent, type, name, id = None):
+ def __init__(self, parent, type, name, id=None):
Graphic_Element.__init__(self, parent)
DebugDataConsumer.__init__(self)
self.Type = type
@@ -365,7 +366,7 @@
self.PreviousSpreading = False
self.RefreshNameSize()
self.RefreshTypeSize()
-
+
def Flush(self):
if self.Input is not None:
self.Input.Flush()
@@ -373,13 +374,13 @@
if self.Output is not None:
self.Output.Flush()
self.Output = None
-
+
def SetForced(self, forced):
if self.Forced != forced:
self.Forced = forced
if self.Visible:
self.Parent.ElementNeedRefresh(self)
-
+
def SetValue(self, value):
if self.Type == CONTACT_RISING:
refresh = self.Value and not self.PreviousValue
@@ -393,7 +394,7 @@
if self.Visible:
self.Parent.ElementNeedRefresh(self)
self.SpreadCurrent()
-
+
def SpreadCurrent(self):
if self.Parent.Debug:
if self.Value is None:
@@ -414,9 +415,9 @@
elif not spreading and self.PreviousSpreading:
self.Output.SpreadCurrent(False)
self.PreviousSpreading = spreading
-
+
# Make a clone of this LD_Contact
- def Clone(self, parent, id = None, pos = None):
+ def Clone(self, parent, id=None, pos=None):
contact = LD_Contact(parent, self.Type, self.Name, id)
contact.SetSize(self.Size[0], self.Size[1])
if pos is not None:
@@ -426,12 +427,12 @@
contact.Input = self.Input.Clone(contact)
contact.Output = self.Output.Clone(contact)
return contact
-
+
def GetConnectorTranslation(self, element):
- return {self.Input : element.Input, self.Output : element.Output}
-
+ return {self.Input: element.Input, self.Output: element.Output}
+
# Returns the RedrawRect
- def GetRedrawRect(self, movex = 0, movey = 0):
+ def GetRedrawRect(self, movex=0, movey=0):
rect = Graphic_Element.GetRedrawRect(self, movex, movey)
rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
@@ -445,30 +446,30 @@
def ProcessDragging(self, movex, movey, event, scaling):
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
movex = movey = 0
- return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac = 2)
-
+ return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac=2)
+
# Forbids to change the contact size
def SetSize(self, width, height):
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
Graphic_Element.SetSize(self, width, height)
self.RefreshConnectors()
-
+
# Delete this contact by calling the appropriate method
def Delete(self):
self.Parent.DeleteContact(self)
-
+
# Unconnect input and output
def Clean(self):
- self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
- self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
-
+ self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
+ self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
+
# Refresh the size of text for name
def RefreshNameSize(self):
if self.Name != "":
self.NameSize = self.Parent.GetTextExtent(self.Name)
else:
self.NameSize = 0, 0
-
+
# Refresh the size of text for type
def RefreshTypeSize(self):
typetext = ""
@@ -482,7 +483,7 @@
self.TypeSize = self.Parent.GetTextExtent(typetext)
else:
self.TypeSize = 0, 0
-
+
# Refresh the contact bounding box
def RefreshBoundingBox(self):
# Calculate the size of the name outside the contact
@@ -499,33 +500,33 @@
bbx_y = self.Pos.y
bbx_height = self.Size[1]
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
-
+
# Returns the block minimum size
def GetMinSize(self):
return LD_ELEMENT_SIZE
-
+
# Refresh the position of wire connected to contact
- def RefreshConnected(self, exclude = []):
+ def RefreshConnected(self, exclude=[]):
self.Input.MoveConnected(exclude)
self.Output.MoveConnected(exclude)
-
- # Returns the contact connector that starts with the point given if it exists
- def GetConnector(self, position, name = None):
+
+ # Returns the contact connector that starts with the point given if it exists
+ def GetConnector(self, position, name=None):
# if a name is given
if name is not None:
# Test input and output connector
- #if name == self.Input.GetName():
+ # if name == self.Input.GetName():
# return self.Input
if name == self.Output.GetName():
return self.Output
return self.FindNearestConnector(position, [self.Input, self.Output])
-
- # Returns input and output contact connectors
+
+ # Returns input and output contact connectors
def GetConnectors(self):
return {"inputs": [self.Input], "outputs": [self.Output]}
-
+
# Test if point given is on contact input or output connector
- def TestConnector(self, pt, direction = None, exclude=True):
+ def TestConnector(self, pt, direction=None, exclude=True):
# Test input connector
if self.Input.TestPoint(pt, direction, exclude):
return self.Input
@@ -561,24 +562,24 @@
# Returns the contact type
def GetType(self):
return self.Type
-
+
# Method called when a LeftDClick event have been generated
def OnLeftDClick(self, event, dc, scaling):
# Edit the contact properties
self.Parent.EditContactContent(self)
-
+
# Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
# Popup the default menu
self.Parent.PopupDefaultMenu()
-
+
# Refreshes the contact model
def RefreshModel(self, move=True):
self.Parent.RefreshContactModel(self)
# If contact has moved, refresh the model of wires connected to output
if move:
self.Output.RefreshWires()
-
+
# Draws the highlightment of this element if it is highlighted
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
@@ -592,12 +593,12 @@
top = (self.Pos.y - 1) * scaley - 2
width = 4 * scalex + 5
height = (self.Size[1] + 3) * scaley + 5
-
+
dc.DrawRectangle(left_left, top, width, height)
dc.DrawRectangle(right_left, top, width, height)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
-
+
# Adds an highlight to the connection
def AddHighlight(self, infos, start, end, highlight_type):
highlights = self.Highlights.setdefault(infos[0], [])
@@ -606,13 +607,13 @@
AddHighlight(highlights, (start, end, highlight_type))
else:
AddHighlight(highlights, ((0, 0), (0, 1), highlight_type))
-
+
# Removes an highlight from the connection
def RemoveHighlight(self, infos, start, end, highlight_type):
highlights = self.Highlights.get(infos[0], [])
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
self.Highlights.pop(infos[0])
-
+
# Removes all the highlights of one particular type from the connection
def ClearHighlight(self, highlight_type=None):
if highlight_type is None:
@@ -623,11 +624,11 @@
highlights = ClearHighlights(highlight, highlight_type)
if len(highlights) == 0:
self.Highlights.pop(name)
-
+
# Draws contact
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
- if self.Value is not None:
+ if self.Value is not None:
if self.Type == CONTACT_NORMAL and self.Value or \
self.Type == CONTACT_REVERSE and not self.Value or \
self.Type == CONTACT_RISING and self.Value and not self.PreviousValue or \
@@ -643,7 +644,7 @@
else:
dc.SetPen(MiterPen(wx.BLACK))
dc.SetBrush(wx.BLACK_BRUSH)
-
+
# Compiling contact type modifier symbol
typetext = ""
if self.Type == CONTACT_REVERSE:
@@ -652,7 +653,7 @@
typetext = "P"
elif self.Type == CONTACT_FALLING:
typetext = "N"
-
+
if getattr(dc, "printing", False):
name_size = dc.GetTextExtent(self.Name)
if typetext != "":
@@ -661,7 +662,7 @@
name_size = self.NameSize
if typetext != "":
type_size = self.TypeSize
-
+
# Draw two rectangles for representing the contact
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1)
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1)
@@ -677,7 +678,7 @@
# Draw input and output connectors
self.Input.Draw(dc)
self.Output.Draw(dc)
-
+
if not getattr(dc, "printing", False):
for name, highlights in self.Highlights.iteritems():
if name == "reference":
@@ -685,18 +686,19 @@
elif typetext != "":
DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1])
-#-------------------------------------------------------------------------------
+
+# -------------------------------------------------------------------------------
# Ladder Diagram Coil
-#-------------------------------------------------------------------------------
-
-"""
-Class that implements the graphic representation of a coil
-"""
+# -------------------------------------------------------------------------------
+
class LD_Coil(Graphic_Element):
-
+ """
+ Class that implements the graphic representation of a coil
+ """
+
# Create a new coil
- def __init__(self, parent, type, name, id = None):
+ def __init__(self, parent, type, name, id=None):
Graphic_Element.__init__(self, parent)
self.Type = type
self.Name = name
@@ -710,7 +712,7 @@
self.PreviousValue = False
self.RefreshNameSize()
self.RefreshTypeSize()
-
+
def Flush(self):
if self.Input is not None:
self.Input.Flush()
@@ -718,7 +720,7 @@
if self.Output is not None:
self.Output.Flush()
self.Output = None
-
+
def SpreadCurrent(self):
if self.Parent.Debug:
self.PreviousValue = self.Value
@@ -729,9 +731,9 @@
self.Output.SpreadCurrent(False)
if self.Value != self.PreviousValue and self.Visible:
self.Parent.ElementNeedRefresh(self)
-
+
# Make a clone of this LD_Coil
- def Clone(self, parent, id = None, pos = None):
+ def Clone(self, parent, id=None, pos=None):
coil = LD_Coil(parent, self.Type, self.Name, id)
coil.SetSize(self.Size[0], self.Size[1])
if pos is not None:
@@ -741,12 +743,12 @@
coil.Input = self.Input.Clone(coil)
coil.Output = self.Output.Clone(coil)
return coil
-
+
def GetConnectorTranslation(self, element):
- return {self.Input : element.Input, self.Output : element.Output}
-
+ return {self.Input: element.Input, self.Output: element.Output}
+
# Returns the RedrawRect
- def GetRedrawRect(self, movex = 0, movey = 0):
+ def GetRedrawRect(self, movex=0, movey=0):
rect = Graphic_Element.GetRedrawRect(self, movex, movey)
rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
@@ -756,34 +758,34 @@
if self.Output.IsConnected():
rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
return rect
-
+
def ProcessDragging(self, movex, movey, event, scaling):
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
movex = movey = 0
- return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac = 2)
-
+ return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac=2)
+
# Forbids to change the Coil size
def SetSize(self, width, height):
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
Graphic_Element.SetSize(self, width, height)
self.RefreshConnectors()
-
+
# Delete this coil by calling the appropriate method
def Delete(self):
self.Parent.DeleteCoil(self)
-
+
# Unconnect input and output
def Clean(self):
- self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
- self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
-
+ self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
+ self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
+
# Refresh the size of text for name
def RefreshNameSize(self):
if self.Name != "":
self.NameSize = self.Parent.GetTextExtent(self.Name)
else:
self.NameSize = 0, 0
-
+
# Refresh the size of text for type
def RefreshTypeSize(self):
typetext = ""
@@ -801,7 +803,7 @@
self.TypeSize = self.Parent.GetTextExtent(typetext)
else:
self.TypeSize = 0, 0
-
+
# Refresh the coil bounding box
def RefreshBoundingBox(self):
# Calculate the size of the name outside the coil
@@ -818,33 +820,33 @@
bbx_y = self.Pos.y
bbx_height = self.Size[1]
self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
-
+
# Returns the block minimum size
def GetMinSize(self):
return LD_ELEMENT_SIZE
-
+
# Refresh the position of wire connected to coil
- def RefreshConnected(self, exclude = []):
+ def RefreshConnected(self, exclude=[]):
self.Input.MoveConnected(exclude)
self.Output.MoveConnected(exclude)
-
- # Returns the coil connector that starts with the point given if it exists
- def GetConnector(self, position, name = None):
+
+ # Returns the coil connector that starts with the point given if it exists
+ def GetConnector(self, position, name=None):
# if a name is given
if name is not None:
# Test input and output connector
- #if self.Input and name == self.Input.GetName():
+ # if self.Input and name == self.Input.GetName():
# return self.Input
if self.Output and name == self.Output.GetName():
return self.Output
return self.FindNearestConnector(position, [self.Input, self.Output])
-
- # Returns input and output coil connectors
+
+ # Returns input and output coil connectors
def GetConnectors(self):
return {"inputs": [self.Input], "outputs": [self.Output]}
-
+
# Test if point given is on coil input or output connector
- def TestConnector(self, pt, direction = None, exclude=True):
+ def TestConnector(self, pt, direction=None, exclude=True):
# Test input connector
if self.Input.TestPoint(pt, direction, exclude):
return self.Input
@@ -852,7 +854,7 @@
if self.Output.TestPoint(pt, direction, exclude):
return self.Output
return None
-
+
# Refresh the positions of the block connectors
def RefreshConnectors(self):
scaling = self.Parent.GetScaling()
@@ -862,7 +864,7 @@
self.Input.SetPosition(wx.Point(0, position))
self.Output.SetPosition(wx.Point(self.Size[0], position))
self.RefreshConnected()
-
+
# Changes the coil name
def SetName(self, name):
self.Name = name
@@ -871,33 +873,33 @@
# Returns the coil name
def GetName(self):
return self.Name
-
+
# Changes the coil type
def SetType(self, type):
self.Type = type
self.RefreshTypeSize()
-
+
# Returns the coil type
def GetType(self):
return self.Type
-
+
# Method called when a LeftDClick event have been generated
def OnLeftDClick(self, event, dc, scaling):
# Edit the coil properties
self.Parent.EditCoilContent(self)
-
+
# Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
# Popup the default menu
self.Parent.PopupDefaultMenu()
-
+
# Refreshes the coil model
def RefreshModel(self, move=True):
self.Parent.RefreshCoilModel(self)
# If coil has moved, refresh the model of wires connected to output
if move:
self.Output.RefreshWires()
-
+
# Draws the highlightment of this element if it is highlighted
def DrawHighlightment(self, dc):
scalex, scaley = dc.GetUserScale()
@@ -906,19 +908,19 @@
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.SetLogicalFunction(wx.AND)
# Draw a two circle arcs for representing the coil
- dc.DrawEllipticArc(round(self.Pos.x * scalex),
- round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
- round(self.Size[0] * scalex),
+ dc.DrawEllipticArc(round(self.Pos.x * scalex),
+ round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
+ round(self.Size[0] * scalex),
round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
135, 225)
- dc.DrawEllipticArc(round(self.Pos.x * scalex),
- round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
- round(self.Size[0] * scalex),
+ dc.DrawEllipticArc(round(self.Pos.x * scalex),
+ round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
+ round(self.Size[0] * scalex),
round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
-45, 45)
dc.SetLogicalFunction(wx.COPY)
dc.SetUserScale(scalex, scaley)
-
+
# Adds an highlight to the connection
def AddHighlight(self, infos, start, end, highlight_type):
highlights = self.Highlights.setdefault(infos[0], [])
@@ -927,13 +929,13 @@
AddHighlight(highlights, (start, end, highlight_type))
else:
AddHighlight(highlights, ((0, 0), (0, 1), highlight_type))
-
+
# Removes an highlight from the connection
def RemoveHighlight(self, infos, start, end, highlight_type):
highlights = self.Highlights.get(infos[0], [])
if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
self.Highlights.pop(infos[0])
-
+
# Removes all the highlights of one particular type from the connection
def ClearHighlight(self, highlight_type=None):
if highlight_type is None:
@@ -944,7 +946,7 @@
highlights = ClearHighlights(highlight, highlight_type)
if len(highlights) == 0:
self.Highlights.pop(name)
-
+
# Draws coil
def Draw(self, dc):
Graphic_Element.Draw(self, dc)
@@ -953,8 +955,8 @@
else:
dc.SetPen(MiterPen(wx.BLACK, 2, wx.SOLID))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
-
- # Compiling coil type modifier symbol
+
+ # Compiling coil type modifier symbol
typetext = ""
if self.Type == COIL_REVERSE:
typetext = "/"
@@ -966,7 +968,7 @@
typetext = "P"
elif self.Type == COIL_FALLING:
typetext = "N"
-
+
if getattr(dc, "printing", False) and not isinstance(dc, wx.PostScriptDC):
# Draw an clipped ellipse for representing the coil
clipping_box = dc.GetClippingBox()
@@ -992,7 +994,7 @@
name_size = self.NameSize
if typetext != "":
type_size = self.TypeSize
-
+
# Draw coil name
name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
self.Pos.y - (name_size[1] + 2))
@@ -1012,5 +1014,3 @@
DrawHighlightedText(dc, self.Name, highlights, name_pos[0], name_pos[1])
elif typetext != "":
DrawHighlightedText(dc, typetext, highlights, type_pos[0], type_pos[1])
-
-