graphics/LD_Objects.py
changeset 1744 69dfdb26f600
parent 1743 c3c3d1318130
child 1782 5b6ad7a7fd9d
equal deleted inserted replaced
1743:c3c3d1318130 1744:69dfdb26f600
    52         for connector in self.Connectors:
    52         for connector in self.Connectors:
    53             connector.Flush()
    53             connector.Flush()
    54         self.Connectors = []
    54         self.Connectors = []
    55 
    55 
    56     # Make a clone of this LD_PowerRail
    56     # Make a clone of this LD_PowerRail
    57     def Clone(self, parent, id = None, pos = None):
    57     def Clone(self, parent, id=None, pos=None):
    58         powerrail = LD_PowerRail(parent, self.Type, id)
    58         powerrail = LD_PowerRail(parent, self.Type, id)
    59         powerrail.SetSize(self.Size[0], self.Size[1])
    59         powerrail.SetSize(self.Size[0], self.Size[1])
    60         if pos is not None:
    60         if pos is not None:
    61             powerrail.SetPosition(pos.x, pos.y)
    61             powerrail.SetPosition(pos.x, pos.y)
    62         else:
    62         else:
    69     def GetConnectorTranslation(self, element):
    69     def GetConnectorTranslation(self, element):
    70         return dict(zip([connector for connector in self.Connectors],
    70         return dict(zip([connector for connector in self.Connectors],
    71                         [connector for connector in element.Connectors]))
    71                         [connector for connector in element.Connectors]))
    72 
    72 
    73     # Returns the RedrawRect
    73     # Returns the RedrawRect
    74     def GetRedrawRect(self, movex = 0, movey = 0):
    74     def GetRedrawRect(self, movex=0, movey=0):
    75         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
    75         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
    76         for connector in self.Connectors:
    76         for connector in self.Connectors:
    77             rect = rect.Union(connector.GetRedrawRect(movex, movey))
    77             rect = rect.Union(connector.GetRedrawRect(movex, movey))
    78         if movex != 0 or movey != 0:
    78         if movex != 0 or movey != 0:
    79             for connector in self.Connectors:
    79             for connector in self.Connectors:
   106         self.Parent.DeletePowerRail(self)
   106         self.Parent.DeletePowerRail(self)
   107 
   107 
   108     # Unconnect all connectors
   108     # Unconnect all connectors
   109     def Clean(self):
   109     def Clean(self):
   110         for connector in self.Connectors:
   110         for connector in self.Connectors:
   111             connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   111             connector.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   112 
   112 
   113     # Refresh the power rail bounding box
   113     # Refresh the power rail bounding box
   114     def RefreshBoundingBox(self):
   114     def RefreshBoundingBox(self):
   115         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   115         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   116 
   116 
   193             elif self.Type == RIGHTRAIL:
   193             elif self.Type == RIGHTRAIL:
   194                 connector.SetPosition(wx.Point(0, position))
   194                 connector.SetPosition(wx.Point(0, position))
   195         self.RefreshConnected()
   195         self.RefreshConnected()
   196 
   196 
   197     # Refresh the position of wires connected to power rail
   197     # Refresh the position of wires connected to power rail
   198     def RefreshConnected(self, exclude = []):
   198     def RefreshConnected(self, exclude=[]):
   199         for connector in self.Connectors:
   199         for connector in self.Connectors:
   200             connector.MoveConnected(exclude)
   200             connector.MoveConnected(exclude)
   201 
   201 
   202     # Returns the power rail connector that starts with the point given if it exists
   202     # Returns the power rail connector that starts with the point given if it exists
   203     def GetConnector(self, position, name = None):
   203     def GetConnector(self, position, name=None):
   204         # if a name is given
   204         # if a name is given
   205         if name is not None:
   205         if name is not None:
   206             # Test each connector if it exists
   206             # Test each connector if it exists
   207             for connector in self.Connectors:
   207             for connector in self.Connectors:
   208                 if name == connector.GetName():
   208                 if name == connector.GetName():
   216             return {"inputs": [], "outputs": connectors}
   216             return {"inputs": [], "outputs": connectors}
   217         else:
   217         else:
   218             return {"inputs": connectors, "outputs": []}
   218             return {"inputs": connectors, "outputs": []}
   219 
   219 
   220     # Test if point given is on one of the power rail connectors
   220     # Test if point given is on one of the power rail connectors
   221     def TestConnector(self, pt, direction = None, exclude = True):
   221     def TestConnector(self, pt, direction=None, exclude=True):
   222         for connector in self.Connectors:
   222         for connector in self.Connectors:
   223             if connector.TestPoint(pt, direction, exclude):
   223             if connector.TestPoint(pt, direction, exclude):
   224                 return connector
   224                 return connector
   225         return None
   225         return None
   226 
   226 
   348     """
   348     """
   349     Class that implements the graphic representation of a contact
   349     Class that implements the graphic representation of a contact
   350     """
   350     """
   351 
   351 
   352     # Create a new contact
   352     # Create a new contact
   353     def __init__(self, parent, type, name, id = None):
   353     def __init__(self, parent, type, name, id=None):
   354         Graphic_Element.__init__(self, parent)
   354         Graphic_Element.__init__(self, parent)
   355         DebugDataConsumer.__init__(self)
   355         DebugDataConsumer.__init__(self)
   356         self.Type = type
   356         self.Type = type
   357         self.Name = name
   357         self.Name = name
   358         self.Id = id
   358         self.Id = id
   414             elif not spreading and self.PreviousSpreading:
   414             elif not spreading and self.PreviousSpreading:
   415                 self.Output.SpreadCurrent(False)
   415                 self.Output.SpreadCurrent(False)
   416             self.PreviousSpreading = spreading
   416             self.PreviousSpreading = spreading
   417 
   417 
   418     # Make a clone of this LD_Contact
   418     # Make a clone of this LD_Contact
   419     def Clone(self, parent, id = None, pos = None):
   419     def Clone(self, parent, id=None, pos=None):
   420         contact = LD_Contact(parent, self.Type, self.Name, id)
   420         contact = LD_Contact(parent, self.Type, self.Name, id)
   421         contact.SetSize(self.Size[0], self.Size[1])
   421         contact.SetSize(self.Size[0], self.Size[1])
   422         if pos is not None:
   422         if pos is not None:
   423             contact.SetPosition(pos.x, pos.y)
   423             contact.SetPosition(pos.x, pos.y)
   424         else:
   424         else:
   429 
   429 
   430     def GetConnectorTranslation(self, element):
   430     def GetConnectorTranslation(self, element):
   431         return {self.Input: element.Input, self.Output: element.Output}
   431         return {self.Input: element.Input, self.Output: element.Output}
   432 
   432 
   433     # Returns the RedrawRect
   433     # Returns the RedrawRect
   434     def GetRedrawRect(self, movex = 0, movey = 0):
   434     def GetRedrawRect(self, movex=0, movey=0):
   435         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   435         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   436         rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   436         rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   437         rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   437         rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   438         if movex != 0 or movey != 0:
   438         if movex != 0 or movey != 0:
   439             if self.Input.IsConnected():
   439             if self.Input.IsConnected():
   443         return rect
   443         return rect
   444 
   444 
   445     def ProcessDragging(self, movex, movey, event, scaling):
   445     def ProcessDragging(self, movex, movey, event, scaling):
   446         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   446         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   447             movex = movey = 0
   447             movex = movey = 0
   448         return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac = 2)
   448         return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac=2)
   449 
   449 
   450     # Forbids to change the contact size
   450     # Forbids to change the contact size
   451     def SetSize(self, width, height):
   451     def SetSize(self, width, height):
   452         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   452         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   453             Graphic_Element.SetSize(self, width, height)
   453             Graphic_Element.SetSize(self, width, height)
   457     def Delete(self):
   457     def Delete(self):
   458         self.Parent.DeleteContact(self)
   458         self.Parent.DeleteContact(self)
   459 
   459 
   460     # Unconnect input and output
   460     # Unconnect input and output
   461     def Clean(self):
   461     def Clean(self):
   462         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   462         self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   463         self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   463         self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   464 
   464 
   465     # Refresh the size of text for name
   465     # Refresh the size of text for name
   466     def RefreshNameSize(self):
   466     def RefreshNameSize(self):
   467         if self.Name != "":
   467         if self.Name != "":
   468             self.NameSize = self.Parent.GetTextExtent(self.Name)
   468             self.NameSize = self.Parent.GetTextExtent(self.Name)
   503     # Returns the block minimum size
   503     # Returns the block minimum size
   504     def GetMinSize(self):
   504     def GetMinSize(self):
   505         return LD_ELEMENT_SIZE
   505         return LD_ELEMENT_SIZE
   506 
   506 
   507     # Refresh the position of wire connected to contact
   507     # Refresh the position of wire connected to contact
   508     def RefreshConnected(self, exclude = []):
   508     def RefreshConnected(self, exclude=[]):
   509         self.Input.MoveConnected(exclude)
   509         self.Input.MoveConnected(exclude)
   510         self.Output.MoveConnected(exclude)
   510         self.Output.MoveConnected(exclude)
   511 
   511 
   512     # Returns the contact connector that starts with the point given if it exists
   512     # Returns the contact connector that starts with the point given if it exists
   513     def GetConnector(self, position, name = None):
   513     def GetConnector(self, position, name=None):
   514         # if a name is given
   514         # if a name is given
   515         if name is not None:
   515         if name is not None:
   516             # Test input and output connector
   516             # Test input and output connector
   517             #if name == self.Input.GetName():
   517             #if name == self.Input.GetName():
   518             #    return self.Input
   518             #    return self.Input
   523     # Returns input and output contact connectors
   523     # Returns input and output contact connectors
   524     def GetConnectors(self):
   524     def GetConnectors(self):
   525         return {"inputs": [self.Input], "outputs": [self.Output]}
   525         return {"inputs": [self.Input], "outputs": [self.Output]}
   526 
   526 
   527     # Test if point given is on contact input or output connector
   527     # Test if point given is on contact input or output connector
   528     def TestConnector(self, pt, direction = None, exclude=True):
   528     def TestConnector(self, pt, direction=None, exclude=True):
   529         # Test input connector
   529         # Test input connector
   530         if self.Input.TestPoint(pt, direction, exclude):
   530         if self.Input.TestPoint(pt, direction, exclude):
   531             return self.Input
   531             return self.Input
   532         # Test output connector
   532         # Test output connector
   533         if self.Output.TestPoint(pt, direction, exclude):
   533         if self.Output.TestPoint(pt, direction, exclude):
   694     """
   694     """
   695     Class that implements the graphic representation of a coil
   695     Class that implements the graphic representation of a coil
   696     """
   696     """
   697 
   697 
   698     # Create a new coil
   698     # Create a new coil
   699     def __init__(self, parent, type, name, id = None):
   699     def __init__(self, parent, type, name, id=None):
   700         Graphic_Element.__init__(self, parent)
   700         Graphic_Element.__init__(self, parent)
   701         self.Type = type
   701         self.Type = type
   702         self.Name = name
   702         self.Name = name
   703         self.Id = id
   703         self.Id = id
   704         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   704         self.Size = wx.Size(LD_ELEMENT_SIZE[0], LD_ELEMENT_SIZE[1])
   729                 self.Output.SpreadCurrent(False)
   729                 self.Output.SpreadCurrent(False)
   730             if self.Value != self.PreviousValue and self.Visible:
   730             if self.Value != self.PreviousValue and self.Visible:
   731                 self.Parent.ElementNeedRefresh(self)
   731                 self.Parent.ElementNeedRefresh(self)
   732 
   732 
   733     # Make a clone of this LD_Coil
   733     # Make a clone of this LD_Coil
   734     def Clone(self, parent, id = None, pos = None):
   734     def Clone(self, parent, id=None, pos=None):
   735         coil = LD_Coil(parent, self.Type, self.Name, id)
   735         coil = LD_Coil(parent, self.Type, self.Name, id)
   736         coil.SetSize(self.Size[0], self.Size[1])
   736         coil.SetSize(self.Size[0], self.Size[1])
   737         if pos is not None:
   737         if pos is not None:
   738             coil.SetPosition(pos.x, pos.y)
   738             coil.SetPosition(pos.x, pos.y)
   739         else:
   739         else:
   744 
   744 
   745     def GetConnectorTranslation(self, element):
   745     def GetConnectorTranslation(self, element):
   746         return {self.Input: element.Input, self.Output: element.Output}
   746         return {self.Input: element.Input, self.Output: element.Output}
   747 
   747 
   748     # Returns the RedrawRect
   748     # Returns the RedrawRect
   749     def GetRedrawRect(self, movex = 0, movey = 0):
   749     def GetRedrawRect(self, movex=0, movey=0):
   750         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   750         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   751         rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   751         rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   752         rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   752         rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   753         if movex != 0 or movey != 0:
   753         if movex != 0 or movey != 0:
   754             if self.Input.IsConnected():
   754             if self.Input.IsConnected():
   758         return rect
   758         return rect
   759 
   759 
   760     def ProcessDragging(self, movex, movey, event, scaling):
   760     def ProcessDragging(self, movex, movey, event, scaling):
   761         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   761         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   762             movex = movey = 0
   762             movex = movey = 0
   763         return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac = 2)
   763         return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, height_fac=2)
   764 
   764 
   765     # Forbids to change the Coil size
   765     # Forbids to change the Coil size
   766     def SetSize(self, width, height):
   766     def SetSize(self, width, height):
   767         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   767         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   768             Graphic_Element.SetSize(self, width, height)
   768             Graphic_Element.SetSize(self, width, height)
   772     def Delete(self):
   772     def Delete(self):
   773         self.Parent.DeleteCoil(self)
   773         self.Parent.DeleteCoil(self)
   774 
   774 
   775     # Unconnect input and output
   775     # Unconnect input and output
   776     def Clean(self):
   776     def Clean(self):
   777         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   777         self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   778         self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   778         self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   779 
   779 
   780     # Refresh the size of text for name
   780     # Refresh the size of text for name
   781     def RefreshNameSize(self):
   781     def RefreshNameSize(self):
   782         if self.Name != "":
   782         if self.Name != "":
   783             self.NameSize = self.Parent.GetTextExtent(self.Name)
   783             self.NameSize = self.Parent.GetTextExtent(self.Name)
   822     # Returns the block minimum size
   822     # Returns the block minimum size
   823     def GetMinSize(self):
   823     def GetMinSize(self):
   824         return LD_ELEMENT_SIZE
   824         return LD_ELEMENT_SIZE
   825 
   825 
   826     # Refresh the position of wire connected to coil
   826     # Refresh the position of wire connected to coil
   827     def RefreshConnected(self, exclude = []):
   827     def RefreshConnected(self, exclude=[]):
   828         self.Input.MoveConnected(exclude)
   828         self.Input.MoveConnected(exclude)
   829         self.Output.MoveConnected(exclude)
   829         self.Output.MoveConnected(exclude)
   830 
   830 
   831     # Returns the coil connector that starts with the point given if it exists
   831     # Returns the coil connector that starts with the point given if it exists
   832     def GetConnector(self, position, name = None):
   832     def GetConnector(self, position, name=None):
   833         # if a name is given
   833         # if a name is given
   834         if name is not None:
   834         if name is not None:
   835             # Test input and output connector
   835             # Test input and output connector
   836             #if self.Input and name == self.Input.GetName():
   836             #if self.Input and name == self.Input.GetName():
   837             #    return self.Input
   837             #    return self.Input
   842     # Returns input and output coil connectors
   842     # Returns input and output coil connectors
   843     def GetConnectors(self):
   843     def GetConnectors(self):
   844         return {"inputs": [self.Input], "outputs": [self.Output]}
   844         return {"inputs": [self.Input], "outputs": [self.Output]}
   845 
   845 
   846     # Test if point given is on coil input or output connector
   846     # Test if point given is on coil input or output connector
   847     def TestConnector(self, pt, direction = None, exclude=True):
   847     def TestConnector(self, pt, direction=None, exclude=True):
   848         # Test input connector
   848         # Test input connector
   849         if self.Input.TestPoint(pt, direction, exclude):
   849         if self.Input.TestPoint(pt, direction, exclude):
   850             return self.Input
   850             return self.Input
   851         # Test output connector
   851         # Test output connector
   852         if self.Output.TestPoint(pt, direction, exclude):
   852         if self.Output.TestPoint(pt, direction, exclude):