Adding support for not removing connection of blocks when changing block type
authorlaurent
Fri, 04 May 2012 11:12:08 +0200
changeset 679 91e8ff268e96
parent 678 9d58192e823a
child 680 b693147fb2c3
Adding support for not removing connection of blocks when changing block type
graphics/FBD_Objects.py
graphics/GraphicCommons.py
--- a/graphics/FBD_Objects.py	Fri May 04 10:12:11 2012 +0200
+++ b/graphics/FBD_Objects.py	Fri May 04 11:12:08 2012 +0200
@@ -261,25 +261,41 @@
                 inputs.insert(0, ("EN","BOOL","none"))
                 outputs.insert(0, ("ENO","BOOL","none"))
             self.Pen = MiterPen(self.Colour)
-            self.Clean()
-            # Extract the inputs properties and create the corresponding connector
-            self.Inputs = []
-            for input_name, input_type, input_modifier in inputs:
-                connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True)
+            
+            # Extract the inputs properties and create or modify the corresponding connector
+            for idx, (input_name, input_type, input_modifier) in enumerate(inputs):
+                if idx < len(self.Inputs):
+                    connector = self.Inputs[idx]
+                    connector.SetName(input_name)
+                    connector.SetType(input_type)
+                else:
+                    connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True)
+                    self.Inputs.append(connector)
                 if input_modifier == "negated":
                     connector.SetNegated(True)
                 elif input_modifier != "none":
                     connector.SetEdge(input_modifier)
-                self.Inputs.append(connector)
-            # Extract the outputs properties and create the corresponding connector
-            self.Outputs = []
-            for output_name, output_type, output_modifier in outputs:
-                connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST)
+            for i in xrange(idx + 1, len(self.Inputs)):
+                self.Inputs[i].UnConnect(delete = True)
+            self.Inputs = self.Inputs[:idx + 1]
+            
+            # Extract the outputs properties and create or modify the corresponding connector
+            for idx, (output_name, output_type, output_modifier) in enumerate(outputs):
+                if idx < len(self.Outputs):
+                    connector = self.Outputs[idx]
+                    connector.SetName(output_name)
+                    connector.SetType(output_type)
+                else:
+                    connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST)
+                    self.Outputs.append(connector)
                 if output_modifier == "negated":
                     connector.SetNegated(True)
                 elif output_modifier != "none":
                     connector.SetEdge(output_modifier)
-                self.Outputs.append(connector)
+            for i in xrange(idx + 1, len(self.Outputs)):
+                self.Outputs[i].UnConnect(delete = True)
+            self.Outputs = self.Outputs[:idx + 1]
+                
             self.RefreshMinSize()
             self.RefreshConnectors()
             self.RefreshBoundingBox()
--- a/graphics/GraphicCommons.py	Fri May 04 10:12:11 2012 +0200
+++ b/graphics/GraphicCommons.py	Fri May 04 11:12:08 2012 +0200
@@ -1523,6 +1523,8 @@
     # Changes the connector name
     def SetType(self, type):
         self.Type = type
+        for wire, handle in self.Wires:
+            wire.SetValid(wire.IsConnectedCompatible())
     
     # Returns the connector name
     def GetName(self):