Fixed loading of Blocks in Viewer when block interface have changed
authorLaurent Bessard
Mon, 13 May 2013 23:15:28 +0200
changeset 1130 f96e0254f0ce
parent 1129 189b49723f9f
child 1131 f794fbff8f02
Fixed loading of Blocks in Viewer when block interface have changed
editors/Viewer.py
graphics/FBD_Objects.py
--- a/editors/Viewer.py	Mon May 13 23:10:10 2013 +0200
+++ b/editors/Viewer.py	Mon May 13 23:15:28 2013 +0200
@@ -1242,21 +1242,34 @@
         element.SetSize(instance["width"], instance["height"])
         for i, output_connector in enumerate(instance["outputs"]):
             if i < len(connectors["outputs"]):
-                connector = connectors["outputs"][i]
+                if isinstance(element, FBD_Block):
+                    connector = element.GetConnector(
+                        wx.Point(*output_connector["position"]),
+                        output_name = output_connector["name"])
+                else:
+                    connector = connectors["outputs"][i]
                 if output_connector.get("negated", False):
                     connector.SetNegated(True)
                 if output_connector.get("edge", "none") != "none":
                     connector.SetEdge(output_connector["edge"])
-                connector.SetPosition(wx.Point(*output_connector["position"]))
+                if connectors["outputs"].index(connector) == i:
+                    connector.SetPosition(wx.Point(*output_connector["position"]))
         for i, input_connector in enumerate(instance["inputs"]):
             if i < len(connectors["inputs"]):
-                connector = connectors["inputs"][i]
-                connector.SetPosition(wx.Point(*input_connector["position"]))
+                if isinstance(element, FBD_Block):
+                    connector = element.GetConnector(
+                        wx.Point(*input_connector["position"]),
+                        input_name = input_connector["name"])
+                else:
+                    connector = connectors["inputs"][i]
+                if connectors["inputs"].index(connector) == i:
+                    connector.SetPosition(wx.Point(*input_connector["position"]))
                 if input_connector.get("negated", False):
                     connector.SetNegated(True)
                 if input_connector.get("edge", "none") != "none":
                     connector.SetEdge(input_connector["edge"])
                 self.CreateWires(connector, instance["id"], input_connector["links"], ids, selection)
+        element.RefreshConnectors()
         if selection is not None and selection[0].get(instance["id"], False):
             self.SelectInGroup(element)
 
@@ -1279,12 +1292,13 @@
                         end_connector.Connect((wire, -1), False)
                         wire.ConnectStartPoint(None, start_connector)
                         wire.ConnectEndPoint(None, end_connector)
+                        connected.RefreshConnectors()
                         self.AddWire(wire)
                         if selection is not None and (\
                            selection[1].get((id, refLocalId), False) or \
                            selection[1].get((refLocalId, id), False)):
                             self.SelectInGroup(wire)
-
+                        
     def IsOfType(self, type, reference):
         return self.Controler.IsOfType(type, reference, self.Debug)
     
--- a/graphics/FBD_Objects.py	Mon May 13 23:10:10 2013 +0200
+++ b/graphics/FBD_Objects.py	Mon May 13 23:15:28 2013 +0200
@@ -179,15 +179,16 @@
             output.MoveConnected(exclude)
     
     # Returns the block connector that starts with the point given if it exists 
-    def GetConnector(self, position, name = None):
-        # if a name is given
-        if name is not None:
-            # Test each input and output connector
-            #for input in self.Inputs:
-            #    if name == input.GetName():
-            #        return input
+    def GetConnector(self, position, output_name = None, input_name = None):
+        if input_name is not None:
+            # Test each input connector
+            for input in self.Inputs:
+                if input_name == input.GetName():
+                    return input
+        if output_name is not None:
+            # Test each output connector
             for output in self.Outputs:
-                if name == output.GetName():
+                if output_name == output.GetName():
                     return output
         return self.FindNearestConnector(position, self.Inputs + self.Outputs)