graphics/LD_Objects.py
changeset 61 dc7142ae9438
parent 58 39cd981ff242
child 64 dd6f693e46a1
equal deleted inserted replaced
60:ef940f442b8d 61:dc7142ae9438
    39 class LD_PowerRail(Graphic_Element):
    39 class LD_PowerRail(Graphic_Element):
    40     
    40     
    41     # Create a new power rail
    41     # Create a new power rail
    42     def __init__(self, parent, type, id = None, connectors = [True]):
    42     def __init__(self, parent, type, id = None, connectors = [True]):
    43         Graphic_Element.__init__(self, parent)
    43         Graphic_Element.__init__(self, parent)
    44         self.Type = type
    44         self.Type = None
       
    45         self.Connectors = []
    45         self.Id = id
    46         self.Id = id
    46         self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2]
    47         self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2]
    47         if len(connectors) < 1:
    48         if len(connectors) < 1:
    48             connectors = [True]
    49             connectors = [True]
    49         # Create a connector or a blank according to 'connectors' and add it in
    50         self.SetType(type, connectors)
    50         # the connectors list
       
    51         self.Connectors = []
       
    52         for connector in connectors:
       
    53             self.AddConnector(connector)
       
    54         self.RefreshSize()
       
    55         
    51         
    56     # Destructor
    52     # Destructor
    57     def __del__(self):
    53     def __del__(self):
    58         self.Connectors = []
    54         self.Connectors = []
    59     
    55     
    70         return False
    66         return False
    71     
    67     
    72     # Forbids to select a power rail
    68     # Forbids to select a power rail
    73     def IsInSelection(self, rect):
    69     def IsInSelection(self, rect):
    74         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
    70         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
    75             return Graphic_Element.IsInSelection(rect)
    71             return Graphic_Element.IsInSelection(self, rect)
    76         return False
    72         return False
    77     
    73     
    78     # Deletes this power rail by calling the appropriate method
    74     # Deletes this power rail by calling the appropriate method
    79     def Delete(self):
    75     def Delete(self):
    80         self.Parent.DeletePowerRail(self)
    76         self.Parent.DeletePowerRail(self)
    81     
    77     
    82     # Unconnect all connectors
    78     # Unconnect all connectors
    83     def Clean(self):
    79     def Clean(self):
    84         for connector in self.Connectors:
    80         for connector in self.Connectors:
    85             if connector:
    81             if connector:
    86                 connector.UnConnect()
    82                 connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
    87                 
    83                 
    88     # Refresh the power rail bounding box
    84     # Refresh the power rail bounding box
    89     def RefreshBoundingBox(self):
    85     def RefreshBoundingBox(self):
    90         dc = wxClientDC(self.Parent)
    86         dc = wxClientDC(self.Parent)
    91         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] + 1)
    87         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] + 1)
   197             if connector and connector.TestPoint(pt, exclude):
   193             if connector and connector.TestPoint(pt, exclude):
   198                 return connector
   194                 return connector
   199         return None
   195         return None
   200     
   196     
   201     # Returns the power rail type
   197     # Returns the power rail type
       
   198     def SetType(self, type, connectors):
       
   199         if type != self.Type or len(self.Connectors) != len(connectors):
       
   200             # Create a connector or a blank according to 'connectors' and add it in
       
   201             # the connectors list
       
   202             self.Type = type
       
   203             self.Clean()
       
   204             self.Connectors = []
       
   205             for connector in connectors:
       
   206                 self.AddConnector(connector)
       
   207             self.RefreshSize()
       
   208     
       
   209     # Returns the power rail type
   202     def GetType(self):
   210     def GetType(self):
   203         return self.Type
   211         return self.Type
   204     
   212     
   205     # Method called when a LeftDown event have been generated
   213     # Method called when a LeftDown event have been generated
   206     def OnLeftDown(self, event, dc, scaling):
   214     def OnLeftDown(self, event, dc, scaling):
   325     def Delete(self):
   333     def Delete(self):
   326         self.Parent.DeleteContact(self)
   334         self.Parent.DeleteContact(self)
   327     
   335     
   328     # Unconnect input and output
   336     # Unconnect input and output
   329     def Clean(self):
   337     def Clean(self):
   330         self.Input.UnConnect()
   338         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   331         self.Output.UnConnect()
   339         self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   332     
   340     
   333     # Refresh the size of text for name
   341     # Refresh the size of text for name
   334     def RefreshNameSize(self):
   342     def RefreshNameSize(self):
   335         dc = wxClientDC(self.Parent)
   343         dc = wxClientDC(self.Parent)
   336         if self.Name != "":
   344         if self.Name != "":