Adding possibility to change Type and Pin number of power rails
authorlbessard
Fri, 03 Aug 2007 18:01:56 +0200
changeset 61 dc7142ae9438
parent 60 ef940f442b8d
child 62 1908c45f21ef
Adding possibility to change Type and Pin number of power rails
Viewer.py
graphics/LD_Objects.py
--- a/Viewer.py	Fri Aug 03 18:00:24 2007 +0200
+++ b/Viewer.py	Fri Aug 03 18:01:56 2007 +0200
@@ -1284,7 +1284,7 @@
         dialog.SetVariables(varlist)
         values = {"name" : coil.GetName(), "type" : coil.GetType()}
         dialog.SetValues(values)
-        dialog.SetElementSize(contact.GetSize())
+        dialog.SetElementSize(coil.GetSize())
         if dialog.ShowModal() == wxID_OK:
             values = dialog.GetValues()
             coil.SetName(values["name"])
@@ -1302,7 +1302,7 @@
         if dialog.ShowModal() == wxID_OK:
             old_type = powerrail.GetType()
             values = dialog.GetValues()
-            powerrail.SetType(values["type"])
+            powerrail.SetType(values["type"], [True for i in xrange(values["number"])])
             powerrail.SetSize(values["width"], values["height"])
             if old_type != values["type"]:
                 id = powerrail.GetId()
--- 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):