Xcos MVC: check parentBlock before parentDiagram 87/17587/1
Paul Bignier [Thu, 17 Dec 2015 09:18:15 +0000 (10:18 +0100)]
 * All objects reference the root diagram, but superblocks elements reference their parentBlock

Change-Id: Ib2c99d92ed58a6e85986f191da38753746df886f

scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.cpp

index 0e4464c..2a804c2 100644 (file)
@@ -318,25 +318,22 @@ link_t getLinkEnd(const LinkAdapter& adaptor, const Controller& controller, cons
         controller.getObjectProperty(endID, PORT, SOURCE_BLOCK, sourceBlock);
 
         // Looking for the block number among the block IDs
-        ScicosID parentDiagram;
-        controller.getObjectProperty(adaptee, LINK, PARENT_DIAGRAM, parentDiagram);
+        ScicosID parent;
+        kind_t parentKind = BLOCK;
+        controller.getObjectProperty(adaptee, LINK, PARENT_BLOCK, parent);
         std::vector<ScicosID> children;
-        if (parentDiagram == 0)
+        // Added to a superblock
+        if (parent == 0)
         {
-            ScicosID parentBlock;
-            controller.getObjectProperty(adaptee, LINK, PARENT_BLOCK, parentBlock);
-            if (parentBlock == 0)
+            // Added to a diagram
+            controller.getObjectProperty(adaptee, LINK, PARENT_DIAGRAM, parent);
+            parentKind = DIAGRAM;
+            if (parent == 0)
             {
                 return ret;
             }
-            // Added to a superblock
-            controller.getObjectProperty(parentBlock, BLOCK, CHILDREN, children);
-        }
-        else
-        {
-            // Added to a diagram
-            controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
         }
+        controller.getObjectProperty(parent, parentKind, CHILDREN, children);
 
         ret.block = static_cast<int>(std::distance(children.begin(), std::find(children.begin(), children.end(), sourceBlock)) + 1);