graphics/LD_Objects.py
changeset 61 dc7142ae9438
parent 58 39cd981ff242
child 64 dd6f693e46a1
--- a/graphics/LD_Objects.py	Fri Aug 03 18:00:24 2007 +0200
+++ b/graphics/LD_Objects.py	Fri Aug 03 18:01:56 2007 +0200
@@ -41,17 +41,13 @@
     # Create a new power rail
     def __init__(self, parent, type, id = None, connectors = [True]):
         Graphic_Element.__init__(self, parent)
-        self.Type = type
+        self.Type = None
+        self.Connectors = []
         self.Id = id
         self.Extensions = [LD_LINE_SIZE / 2, LD_LINE_SIZE / 2]
         if len(connectors) < 1:
             connectors = [True]
-        # Create a connector or a blank according to 'connectors' and add it in
-        # the connectors list
-        self.Connectors = []
-        for connector in connectors:
-            self.AddConnector(connector)
-        self.RefreshSize()
+        self.SetType(type, connectors)
         
     # Destructor
     def __del__(self):
@@ -72,7 +68,7 @@
     # Forbids to select a power rail
     def IsInSelection(self, rect):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
-            return Graphic_Element.IsInSelection(rect)
+            return Graphic_Element.IsInSelection(self, rect)
         return False
     
     # Deletes this power rail by calling the appropriate method
@@ -83,7 +79,7 @@
     def Clean(self):
         for connector in self.Connectors:
             if connector:
-                connector.UnConnect()
+                connector.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
                 
     # Refresh the power rail bounding box
     def RefreshBoundingBox(self):
@@ -199,6 +195,18 @@
         return None
     
     # Returns the power rail type
+    def SetType(self, type, connectors):
+        if type != self.Type or len(self.Connectors) != len(connectors):
+            # Create a connector or a blank according to 'connectors' and add it in
+            # the connectors list
+            self.Type = type
+            self.Clean()
+            self.Connectors = []
+            for connector in connectors:
+                self.AddConnector(connector)
+            self.RefreshSize()
+    
+    # Returns the power rail type
     def GetType(self):
         return self.Type
     
@@ -327,8 +335,8 @@
     
     # Unconnect input and output
     def Clean(self):
-        self.Input.UnConnect()
-        self.Output.UnConnect()
+        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):