Xcos MVC: fix Diagrams's 'objs' property getter and setter 87/15187/8
Paul Bignier [Tue, 9 Sep 2014 13:19:37 +0000 (15:19 +0200)]
Implemented double-linkage of the diagram with its children.

Change-Id: Ia7a236eb7e38b6b2793a768f01d16e4e918772ee

scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/Model_setObjectProperties.cpp
scilab/modules/scicos/src/cpp/model/Annotation.hxx
scilab/modules/scicos/src/cpp/model/Block.hxx
scilab/modules/scicos/src/cpp/model/Link.hxx
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.cpp
scilab/modules/scicos/tests/unit_tests/model/Diagram.dia.ref
scilab/modules/scicos/tests/unit_tests/model/Diagram.tst

index 693feb4..91b2360 100644 (file)
@@ -298,7 +298,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
         switch (p)
         {
             case PARENT_DIAGRAM:
-                v = o->getParentDiagram();
+                o->getParentDiagram(v);
                 return true;
             case RELATED_TO:
                 v = o->getRelatedTo();
@@ -313,7 +313,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
         switch (p)
         {
             case PARENT_DIAGRAM:
-                v = o->getParentDiagram();
+                o->getParentDiagram(v);
                 return true;
             default:
                 break;
@@ -329,7 +329,7 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
         switch (p)
         {
             case PARENT_DIAGRAM:
-                v = o->getParentDiagram();
+                o->getParentDiagram(v);
                 return true;
             case SOURCE_PORT:
                 o->getSourcePort(v);
index 450ad25..1dc7d62 100644 (file)
@@ -190,16 +190,22 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
 
     if (k == ANNOTATION)
     {
+        model::Annotation* o = static_cast<model::Annotation*>(getObject(uid));
         switch (p)
         {
+            case PARENT_DIAGRAM:
+                return o->setParentDiagram(v);
             default:
                 break;
         }
     }
     else if (k == BLOCK)
     {
+        model::Block* o = static_cast<model::Block*>(getObject(uid));
         switch (p)
         {
+            case PARENT_DIAGRAM:
+                return o->setParentDiagram(v);
             default:
                 break;
         }
@@ -217,6 +223,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Link* o = static_cast<model::Link*>(getObject(uid));
         switch (p)
         {
+            case PARENT_DIAGRAM:
+                return o->setParentDiagram(v);
             case SOURCE_PORT:
                 return o->setSourcePort(v);
             case DESTINATION_PORT:
index 99cb8d4..5efd68f 100644 (file)
@@ -111,19 +111,19 @@ private:
         return SUCCESS;
     }
 
-    ScicosID getParentDiagram() const
+    void getParentDiagram(ScicosID& v) const
     {
-        return parentDiagram;
+        v = parentDiagram;
     }
 
-    update_status_t setParentDiagram(ScicosID parentDiagram)
+    update_status_t setParentDiagram(const ScicosID v)
     {
-        if (this->parentDiagram == parentDiagram)
+        if (v == parentDiagram)
         {
             return NO_CHANGES;
         }
 
-        this->parentDiagram = parentDiagram;
+        parentDiagram = v;
         return SUCCESS;
     }
 
index 489c11a..10b2319 100644 (file)
@@ -312,14 +312,20 @@ private:
         this->parentBlock = parentBlock;
     }
 
-    ScicosID getParentDiagram() const
+    void getParentDiagram(ScicosID& v) const
     {
-        return parentDiagram;
+        v = parentDiagram;
     }
 
-    void setParentDiagram(ScicosID parentDiagram)
+    update_status_t setParentDiagram(const ScicosID v)
     {
-        this->parentDiagram = parentDiagram;
+        if (v == parentDiagram)
+        {
+            return NO_CHANGES;
+        }
+
+        parentDiagram = v;
+        return SUCCESS;
     }
 
     ScicosID getPortReference() const
index 83d7b9d..23f6285 100644 (file)
@@ -45,14 +45,20 @@ private:
         controlPoints(o.controlPoints), label(o.label), thick(o.thick), color(o.color), linkKind(o.linkKind) {};
     ~Link() {}
 
-    ScicosID getParentDiagram() const
+    void getParentDiagram(ScicosID& v) const
     {
-        return parentDiagram;
+        v = parentDiagram;
     }
 
-    void setParentDiagram(ScicosID parentDiagram)
+    update_status_t setParentDiagram(const ScicosID v)
     {
-        this->parentDiagram = parentDiagram;
+        if (v == parentDiagram)
+        {
+            return NO_CHANGES;
+        }
+
+        parentDiagram = v;
+        return SUCCESS;
     }
 
     void getControlPoints(std::vector<double>& v) const
index e2fe547..6ce5353 100644 (file)
@@ -25,6 +25,7 @@
 #include "utilities.hxx"
 #include "Controller.hxx"
 #include "DiagramAdapter.hxx"
+#include "Adapters.hxx"
 #include "ParamsAdapter.hxx"
 #include "TextAdapter.hxx"
 #include "BlockAdapter.hxx"
@@ -43,10 +44,6 @@ namespace view_scilab
 namespace
 {
 
-const std::wstring AnnotationStr (L"Text");
-const std::wstring BlockStr (L"Block");
-const std::wstring LinkStr (L"Link");
-
 struct props
 {
 
@@ -76,7 +73,7 @@ struct objs
 
         types::List* o = new types::List();
 
-        for (int i = 0; i < (int)children.size(); ++i)
+        for (int i = 0; i < static_cast<int>(children.size()); ++i)
         {
             model::BaseObject* item = Controller().getObject(children[i]);
             switch (item->kind())
@@ -84,23 +81,23 @@ struct objs
                 case ANNOTATION:
                 {
                     model::Annotation* annotation = static_cast<model::Annotation*>(item);
-                    TextAdapter localAdaptor = TextAdapter(annotation);
-                    o->set(i, localAdaptor.getAsTList(new types::MList(), controller));
-                    break;
+                    TextAdapter* localAdaptor = new TextAdapter(annotation);
+                    o->set(i, localAdaptor);
+                    continue;
                 }
                 case BLOCK:
                 {
                     model::Block* block = static_cast<model::Block*>(item);
-                    BlockAdapter localAdaptor = BlockAdapter(block);
-                    o->set(i, localAdaptor.getAsTList(new types::MList(), controller));
-                    break;
+                    BlockAdapter* localAdaptor = new BlockAdapter(block);
+                    o->set(i, localAdaptor);
+                    continue;
                 }
                 case LINK:
                 {
                     model::Link* link = static_cast<model::Link*>(item);
-                    LinkAdapter localAdaptor = LinkAdapter(link);
-                    o->set(i, localAdaptor.getAsTList(new types::MList(), controller));
-                    break;
+                    LinkAdapter* localAdaptor = new LinkAdapter(link);
+                    o->set(i, localAdaptor);
+                    continue;
                 }
                 default:
                     return 0;
@@ -123,48 +120,48 @@ struct objs
         std::vector<ScicosID> diagramChildren (list->getSize());
         for (int i = 0; i < list->getSize(); ++i)
         {
-            if (list->get(i)->getType() != types::InternalType::ScilabMList)
+            if (list->get(i)->getType() != types::InternalType::ScilabUserType)
             {
                 return false;
             }
-            types::MList* modelElement = list->get(i)->getAs<types::MList>();
 
-            std::wstring modelElementType = modelElement->getTypeStr();
-            ScicosID id;
+            // Find the type of the input object through Adapters' mapping.
+            const Adapters::adapters_index_t adapter_index = Adapters::instance().lookup_by_typename(list->get(i)->getShortTypeStr());
 
-            if (modelElementType == AnnotationStr)
+            // Then, each adapter gets linked to the diagram through its adaptee (PARENT_DIAGRAM)
+            // and the diagram's adaptee lists its adaptees (CHILDREN).
+            ScicosID id;
+            switch (adapter_index)
             {
-                id = controller.createObject(ANNOTATION);
-
-                TextAdapter localAdaptor = TextAdapter(static_cast<model::Annotation*>(controller.getObject(id)));
-                if (!localAdaptor.setAsTList(modelElement, controller))
+                case Adapters::BLOCK_ADAPTER:
                 {
-                    return false;
-                }
-            }
-            else if (modelElementType == BlockStr)
-            {
-                id = controller.createObject(BLOCK);
+                    BlockAdapter* modelElement = list->get(i)->getAs<BlockAdapter>();
+                    model::Block* subAdaptee = modelElement->getAdaptee();
 
-                BlockAdapter localAdaptor = BlockAdapter(static_cast<model::Block*>(controller.getObject(id)));
-                if (!localAdaptor.setAsTList(modelElement, controller))
-                {
-                    return false;
+                    controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
+                    id = subAdaptee->id();
+                    break;
                 }
-            }
-            else if (modelElementType == LinkStr)
-            {
-                id = controller.createObject(LINK);
+                case Adapters::LINK_ADAPTER:
+                {
+                    LinkAdapter* modelElement = list->get(i)->getAs<LinkAdapter>();
+                    model::Link* subAdaptee = modelElement->getAdaptee();
 
-                LinkAdapter localAdaptor = LinkAdapter(static_cast<model::Link*>(controller.getObject(id)));
-                if (!localAdaptor.setAsTList(modelElement, controller))
+                    controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
+                    id = subAdaptee->id();
+                    break;
+                }
+                case Adapters::TEXT_ADAPTER:
                 {
-                    return false;
+                    TextAdapter* modelElement = list->get(i)->getAs<TextAdapter>();
+                    model::Annotation* subAdaptee = modelElement->getAdaptee();
+
+                    controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
+                    id = subAdaptee->id();
+                    break;
                 }
-            }
-            else
-            {
-                return false;
+                default:
+                    return false;
             }
 
             diagramChildren[i] = id;
index 8374878..50104f2 100644 (file)
@@ -42,3 +42,139 @@ scs_m.version
 scs_m.contrib
  ans  =
 ()
+// Create a diagram containing 2 summation blocks and an empty link
+blk  = BIGSOM_f("define");
+objectCreated( 2 , BLOCK )
+propertyUpdated( 2 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , GEOMETRY ) : SUCCESS
+propertyUpdated( 2 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , EXPRS ) : SUCCESS
+objectCreated( 3 , PORT )
+propertyUpdated( 3 , PORT , SOURCE_BLOCK ) : SUCCESS
+objectCreated( 4 , PORT )
+propertyUpdated( 4 , PORT , SOURCE_BLOCK ) : SUCCESS
+propertyUpdated( 2 , BLOCK , INPUTS ) : SUCCESS
+objectCreated( 5 , PORT )
+propertyUpdated( 5 , PORT , SOURCE_BLOCK ) : SUCCESS
+propertyUpdated( 2 , BLOCK , OUTPUTS ) : SUCCESS
+propertyUpdated( 2 , BLOCK , LABEL ) : NO_CHANGES
+propertyUpdated( 3 , PORT , IMPLICIT ) : NO_CHANGES
+propertyUpdated( 4 , PORT , IMPLICIT ) : NO_CHANGES
+propertyUpdated( 5 , PORT , IMPLICIT ) : NO_CHANGES
+propertyUpdated( 3 , PORT , STYLE ) : NO_CHANGES
+propertyUpdated( 4 , PORT , STYLE ) : NO_CHANGES
+propertyUpdated( 5 , PORT , STYLE ) : NO_CHANGES
+propertyUpdated( 3 , PORT , LABEL ) : NO_CHANGES
+propertyUpdated( 4 , PORT , LABEL ) : NO_CHANGES
+propertyUpdated( 5 , PORT , LABEL ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , STYLE ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , SIM_FUNCTION_NAME ) : SUCCESS
+propertyUpdated( 2 , BLOCK , SIM_FUNCTION_API ) : SUCCESS
+propertyUpdated( 4 , PORT , DATATYPE ) : SUCCESS
+propertyUpdated( 3 , PORT , DATATYPE ) : SUCCESS
+propertyUpdated( 5 , PORT , DATATYPE ) : SUCCESS
+propertyUpdated( 2 , BLOCK , STATE ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , DSTATE ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , RPAR ) : SUCCESS
+propertyUpdated( 2 , BLOCK , IPAR ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , SIM_BLOCKTYPE ) : SUCCESS
+propertyUpdated( 2 , BLOCK , SIM_DEP_UT ) : SUCCESS
+propertyUpdated( 2 , BLOCK , LABEL ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , NZCROSS ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , NMODE ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , UID ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , INTERFACE_FUNCTION ) : SUCCESS
+blk2 = BIGSOM_f("define");
+objectCreated( 6 , BLOCK )
+propertyUpdated( 6 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , GEOMETRY ) : SUCCESS
+propertyUpdated( 6 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , EXPRS ) : SUCCESS
+objectCreated( 7 , PORT )
+propertyUpdated( 7 , PORT , SOURCE_BLOCK ) : SUCCESS
+objectCreated( 8 , PORT )
+propertyUpdated( 8 , PORT , SOURCE_BLOCK ) : SUCCESS
+propertyUpdated( 6 , BLOCK , INPUTS ) : SUCCESS
+objectCreated( 9 , PORT )
+propertyUpdated( 9 , PORT , SOURCE_BLOCK ) : SUCCESS
+propertyUpdated( 6 , BLOCK , OUTPUTS ) : SUCCESS
+propertyUpdated( 6 , BLOCK , LABEL ) : NO_CHANGES
+propertyUpdated( 7 , PORT , IMPLICIT ) : NO_CHANGES
+propertyUpdated( 8 , PORT , IMPLICIT ) : NO_CHANGES
+propertyUpdated( 9 , PORT , IMPLICIT ) : NO_CHANGES
+propertyUpdated( 7 , PORT , STYLE ) : NO_CHANGES
+propertyUpdated( 8 , PORT , STYLE ) : NO_CHANGES
+propertyUpdated( 9 , PORT , STYLE ) : NO_CHANGES
+propertyUpdated( 7 , PORT , LABEL ) : NO_CHANGES
+propertyUpdated( 8 , PORT , LABEL ) : NO_CHANGES
+propertyUpdated( 9 , PORT , LABEL ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , STYLE ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , SIM_FUNCTION_NAME ) : SUCCESS
+propertyUpdated( 6 , BLOCK , SIM_FUNCTION_API ) : SUCCESS
+propertyUpdated( 8 , PORT , DATATYPE ) : SUCCESS
+propertyUpdated( 7 , PORT , DATATYPE ) : SUCCESS
+propertyUpdated( 9 , PORT , DATATYPE ) : SUCCESS
+propertyUpdated( 6 , BLOCK , STATE ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , DSTATE ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , RPAR ) : SUCCESS
+propertyUpdated( 6 , BLOCK , IPAR ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , SIM_BLOCKTYPE ) : SUCCESS
+propertyUpdated( 6 , BLOCK , SIM_DEP_UT ) : SUCCESS
+propertyUpdated( 6 , BLOCK , LABEL ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , NZCROSS ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , NMODE ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , UID ) : NO_CHANGES
+propertyUpdated( 6 , BLOCK , INTERFACE_FUNCTION ) : SUCCESS
+lnk  = scicos_link();
+objectCreated( 10 , LINK )
+propertyUpdated( 10 , LINK , CONTROL_POINTS ) : NO_CHANGES
+propertyUpdated( 10 , LINK , CONTROL_POINTS ) : NO_CHANGES
+propertyUpdated( 10 , LINK , LABEL ) : NO_CHANGES
+propertyUpdated( 10 , LINK , THICK ) : NO_CHANGES
+propertyUpdated( 10 , LINK , COLOR ) : NO_CHANGES
+propertyUpdated( 10 , LINK , KIND ) : NO_CHANGES
+propertyUpdated( 10 , LINK , SOURCE_PORT ) : NO_CHANGES
+propertyUpdated( 10 , LINK , DESTINATION_PORT ) : NO_CHANGES
+scs_m = scicos_diagram( objs=list(blk,blk2,lnk) )
+objectCreated( 11 , DIAGRAM )
+propertyUpdated( 11 , DIAGRAM , TITLE ) : NO_CHANGES
+propertyUpdated( 11 , DIAGRAM , PATH ) : NO_CHANGES
+propertyUpdated( 11 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 11 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 11 , DIAGRAM , CONTEXT ) : NO_CHANGES
+propertyUpdated( 2 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 6 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 10 , LINK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 11 , DIAGRAM , CHILDREN ) : SUCCESS
+propertyUpdated( 11 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
+scs_m  = 
+scicos_diagram type :
+  props
+  objs
+  version
+  contrib
+scs_m.objs
+ ans  =
+     (1)
+scicos_Block type :
+  graphics
+  model
+  gui
+  doc
+     (2)
+scicos_Block type :
+  graphics
+  model
+  gui
+  doc
+     (3)
+scicos_Link type :
+  xx
+  yy
+  id
+  thick
+  ct
+  from
+  to
index 5c6d711..079269b 100644 (file)
@@ -13,3 +13,11 @@ scs_m.props
 scs_m.objs
 scs_m.version
 scs_m.contrib
+
+// Create a diagram containing 2 summation blocks and an empty link
+blk  = BIGSOM_f("define");
+blk2 = BIGSOM_f("define");
+lnk  = scicos_link();
+
+scs_m = scicos_diagram( objs=list(blk,blk2,lnk) )
+scs_m.objs