Xcos MVC: properly clone model objects to access sub-diagrams 81/15581/18
Paul Bignier [Fri, 21 Nov 2014 16:49:30 +0000 (17:49 +0100)]
 * Fixed 'getfield(1, scs_m)' to add the type of 'scs_m' at the beginning of the return

Change-Id: I8c378f2d9532b1dd1e837d8a9eed8144f7d1a890

24 files changed:
scilab/modules/data_structures/sci_gateway/cpp/sci_getfield.cpp
scilab/modules/scicos/includes/adapters_utilities.hxx
scilab/modules/scicos/macros/scicos_scicos/%Link_p.sci
scilab/modules/scicos/macros/scicos_scicos/%diagram_p.sci
scilab/modules/scicos/macros/scicos_scicos/%model_p.sci
scilab/modules/scicos/src/cpp/Controller.cpp
scilab/modules/scicos/src/cpp/view_scilab/BlockAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/BlockAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.cpp
scilab/modules/scicos/tests/unit_tests/model/Block_copy_list.dia.ref
scilab/modules/scicos/tests/unit_tests/model/Diagram.dia.ref
scilab/modules/scicos/tests/unit_tests/model/LV_load.tst
scilab/modules/scicos/tests/unit_tests/model/SuperBlock.dia.ref
scilab/modules/scicos/tests/unit_tests/model/SuperBlock_in_SuperBlock.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/model/SuperBlock_in_SuperBlock.tst [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/model/link_preservation.dia.ref
scilab/modules/scicos/tests/unit_tests/model/simple_delete.dia.ref
scilab/modules/string/macros/sci2exp.sci

index 61867f6..cf3313c 100644 (file)
@@ -177,13 +177,24 @@ static types::Function::ReturnValue sci_getfieldUserType(types::typed_list &in,
         if (pIndex->get(0) == 1)
         {
             types::InternalType* properties = pUT->extract(&in);
-
             if (!properties->isString())
             {
                 Scierror(999, _("%s: Could not read the argument #%d properties.\n"), "getfield", 2);
                 return types::Function::Error;
             }
-            out.push_back(properties->getAs<types::String>());
+            types::String* propertiesStr = properties->getAs<types::String>();
+
+            types::String* ret = new types::String(1, 1 + propertiesStr->getSize());
+            ret->set(0, pUT->getTypeStr().c_str());
+            for (int i = 0; i < propertiesStr->getSize(); ++i)
+            {
+                ret->set(i + 1, propertiesStr->get(i));
+            }
+
+            properties->DecreaseRef();
+            properties->killMe();
+
+            out.push_back(ret);
             return types::Function::OK;
         }
         else
index 1044d38..a25aa0f 100644 (file)
@@ -10,8 +10,8 @@
  *
  */
 
-#ifndef PRIVATE_UTILITIES_HXX_
-#define PRIVATE_UTILITIES_HXX_
+#ifndef ADAPTERS_UTILITIES_HXX_
+#define ADAPTERS_UTILITIES_HXX_
 
 enum startOrEnd
 {
@@ -26,4 +26,4 @@ struct link_t
     enum startOrEnd kind;
 };
 
-#endif /* PRIVATE_UTILITIES_HXX_ */
+#endif /* ADAPTERS_UTILITIES_HXX_ */
index 25d437e..8c0643b 100644 (file)
@@ -25,7 +25,7 @@ function %Link_p(l)
 
     fn = getfield(1, l);
 
-    for i=1:size(fn,"*")
+    for i=2:size(fn,"*")
         field = string(eval("l."+fn(i)));
 
         fieldSize = size(field, "*");
index 96d277a..6df388f 100644 (file)
@@ -26,7 +26,7 @@ function %diagram_p(scs_m)
     for o=scs_m.objs
         if typeof(o)=="Block" then
             mprintf("%s%s\n", part(string(i), 1:6), o.gui)
+            i = i + 1;
         end
-        i = i + 1;
     end
 endfunction
index 9401cdf..f39f9db 100644 (file)
@@ -42,6 +42,18 @@ function %model_p(model)
             newModel = scicos_model( sim=model.sim,in=model.in,in2=model.in2,intyp=model.intyp,out=model.out,out2=model.out2,outtyp=model.outtyp,evtin=model.evtin,evtout=model.evtout,state=model.state,dstate=model.dstate,odstate=model.odstate,ipar=model.ipar,opar=model.opar,blocktype=model.blocktype,firing=model.firing,dep_ut=model.dep_ut,label=model.label,nzcross=model.nzcross,nmode=model.nmode,equations=model.equations,uid=model.uid );
             newModel.rpar = rpar;
 
+            for i=1:size(newModel.rpar.objs)
+                newModelObj = newModel.rpar.objs(i);
+                if typeof(newModelObj) == "Block" && typeof(newModelObj.model.rpar) == "diagram"
+                    subRpar = diagram2mlist(newModelObj.model.rpar);
+                    // Define a new model omitting 'rpar' because writing 'model.rpar=l' triggers cloning.
+                    newSubModel = scicos_model( sim=newModel.sim,in=newModel.in,in2=newModel.in2,intyp=newModel.intyp,out=newModel.out,out2=newModel.out2,outtyp=newModel.outtyp,evtin=newModel.evtin,evtout=newModel.evtout,state=newModel.state,dstate=newModel.dstate,odstate=newModel.odstate,ipar=newModel.ipar,opar=newModel.opar,blocktype=newModel.blocktype,firing=newModel.firing,dep_ut=newModel.dep_ut,label=newModel.label,nzcross=newModel.nzcross,nmode=newModel.nmode,equations=newModel.equations,uid=newModel.uid );
+                    newSubModel.rpar = subRpar;
+                    newModelObj.model = newSubModel;
+                    newModel.rpar.objs(i) = newModelObj;
+                end
+            end
+
             for k=3:size(fn,"*")
                 mprintf("%s\n", sci2exp(newModel(fn(k)),fn(k)))
             end
index 7df9061..100fc19 100644 (file)
@@ -102,6 +102,7 @@ void Controller::deleteObject(ScicosID uid)
     }
     else if (k == DIAGRAM)
     {
+        deleteVector(uid, k, CHILDREN);
     }
     else if (k == LINK)
     {
index ecdb52d..ea95544 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <string>
+#include <vector>
 #include <memory>
 
 #include "internal.hxx"
@@ -25,7 +26,9 @@
 #include "BlockAdapter.hxx"
 #include "DiagramAdapter.hxx"
 #include "GraphicsAdapter.hxx"
+#include "LinkAdapter.hxx"
 #include "ModelAdapter.hxx"
+#include "TextAdapter.hxx"
 
 extern "C" {
 #include "sci_malloc.h"
@@ -39,8 +42,6 @@ namespace view_scilab
 namespace
 {
 
-std::wstring rpar(L"rpar");
-
 struct graphics
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
@@ -61,18 +62,9 @@ struct model
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
-        types::MList* ret = localAdaptor.getAsTList(new types::MList(), controller)->getAs<types::MList>();
+        localAdaptor.setDiagram(adaptor.getDiagram());
 
-        // If the Block is a SuperBlock, set its 'rpar' property with the saved Diagram
-        DiagramAdapter* rpar_content = adaptor.getRpar()->getAs<DiagramAdapter>();
-        if (rpar_content != 0 && localAdaptor.getDiagram() == 0)
-        {
-            // Decrease rpar_content's ref count to counter the increases from the other Adapters
-            rpar_content->DecreaseRef();
-            ret->set(rpar, rpar_content);
-        }
-
-        return ret;
+        return localAdaptor.getAsTList(new types::MList(), controller)->getAs<types::MList>();
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
@@ -83,7 +75,8 @@ struct model
             return false;
         }
 
-        adaptor.setRpar(localAdaptor.getDiagram());
+        adaptor.setDiagram(localAdaptor.getRpar());
+
         return true;
     }
 };
@@ -143,7 +136,7 @@ template<> property<BlockAdapter>::props_t property<BlockAdapter>::fields = prop
 
 BlockAdapter::BlockAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Block> adaptee) :
     BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(adaptee),
-    rpar_content(nullptr),
+    diagramAdapter(nullptr),
     doc_content(new types::List())
 {
     if (property<BlockAdapter>::properties_have_not_been_set())
@@ -158,17 +151,107 @@ BlockAdapter::BlockAdapter(std::shared_ptr<org_scilab_modules_scicos::model::Blo
 
 BlockAdapter::BlockAdapter(const BlockAdapter& adapter) :
     BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(adapter),
-    rpar_content(adapter.getRpar()),
+    diagramAdapter(),
     doc_content(adapter.getDocContent())
 {
+    Controller controller;
+    std::vector<ScicosID> diagramChild;
+    controller.getObjectProperty(getAdaptee()->id(), BLOCK, CHILDREN, diagramChild);
+
+    if (!diagramChild.empty())
+    {
+        std::shared_ptr<org_scilab_modules_scicos::model::Diagram> diagram = std::static_pointer_cast<org_scilab_modules_scicos::model::Diagram>(controller.getObject(diagramChild[0]));
+        diagramAdapter = new DiagramAdapter(diagram);
+
+        // Extract the information of the old cloned diagram
+        DiagramAdapter* oldDiagram = adapter.getDiagram();
+        types::List* oldList_objects = oldDiagram->getListObjects()->getAs<types::List>();
+        std::vector<link_t> from_vec = oldDiagram->getFrom();
+        std::vector<link_t> to_vec = oldDiagram->getTo();
+
+        std::vector<ScicosID> diagramChildren;
+        controller.getObjectProperty(diagram->id(), DIAGRAM, CHILDREN, diagramChildren);
+
+        // FIXME: factor the following code with DiagramAdapter copy constructor?
+        std::vector<LinkAdapter*> linkListView; // Store the new LinkAdapters to make the linking at model-level after the loop
+        types::List* List_objects = new types::List();
+        for (int i = 0; i < static_cast<int>(diagramChildren.size()); ++i)
+        {
+            std::shared_ptr<org_scilab_modules_scicos::model::BaseObject> item = controller.getObject(diagramChildren[i]);
+            switch (item->kind())
+            {
+                case ANNOTATION:
+                {
+                    std::shared_ptr<org_scilab_modules_scicos::model::Annotation> annotation = std::static_pointer_cast<org_scilab_modules_scicos::model::Annotation>(item);
+                    TextAdapter* localAdaptor = new TextAdapter(annotation);
+
+                    List_objects->set(i, localAdaptor);
+                    continue;
+                }
+                case BLOCK:
+                {
+                    std::shared_ptr<org_scilab_modules_scicos::model::Block> block = std::static_pointer_cast<org_scilab_modules_scicos::model::Block>(item);
+                    BlockAdapter* localAdaptor = new BlockAdapter(block);
+
+                    // If the diagram's block was a SuperBlock, make its new adapter point to its old diagram
+                    if (i < oldList_objects->getSize())
+                    {
+                        BlockAdapter* oldBlock = oldList_objects->get(i)->getAs<BlockAdapter>();
+                        DiagramAdapter* oldBlockDiagram = oldBlock->getDiagram();
+                        if (oldBlockDiagram != nullptr)
+                        {
+                            oldBlockDiagram->IncreaseRef();
+                        }
+                        localAdaptor->setDiagram(oldBlockDiagram);
+                    }
+
+                    List_objects->set(i, localAdaptor);
+                    continue;
+                }
+                case LINK:
+                {
+                    std::shared_ptr<org_scilab_modules_scicos::model::Link> link = std::static_pointer_cast<org_scilab_modules_scicos::model::Link>(item);
+                    LinkAdapter* localAdaptor = new LinkAdapter(link);
+
+                    // Do the model linking in the next loop, in case the Link points to a Block that has not been added yet
+                    linkListView.push_back(localAdaptor);
+
+                    List_objects->set(i, localAdaptor);
+                    continue;
+                }
+                default:
+                {
+                }
+            }
+        }
+
+        // Do the linking at model-level, from the old 'from_vec' and 'to_vec'
+        for (int i = 0; i < static_cast<int>(linkListView.size()); ++i)
+        {
+            // Trigger 'from' and 'to' properties
+            linkListView[i]->setFromInModel(from_vec[i], controller);
+            linkListView[i]->setToInModel(to_vec[i], controller);
+        }
+
+        diagramAdapter->setListObjects(List_objects);
+        diagramAdapter->setFrom(from_vec);
+        diagramAdapter->setTo(to_vec);
+    }
 }
 
 BlockAdapter::~BlockAdapter()
 {
-    if (rpar_content != nullptr)
+    if (diagramAdapter != nullptr)
     {
-        rpar_content->DecreaseRef();
-        rpar_content->killMe();
+        // Update the model if the adaptee is being deleted
+        if (getAdaptee().use_count() == 3)
+        {
+            Controller controller;
+            controller.setObjectProperty(getAdaptee()->id(), BLOCK, CHILDREN, std::vector<ScicosID>());
+        }
+
+        diagramAdapter->DecreaseRef();
+        diagramAdapter->killMe();
     }
 
     doc_content->DecreaseRef();
@@ -185,24 +268,23 @@ std::wstring BlockAdapter::getShortTypeStr()
     return getSharedTypeStr();
 }
 
-types::InternalType* BlockAdapter::getRpar() const
+DiagramAdapter* BlockAdapter::getDiagram() const
 {
-    if (rpar_content != nullptr)
+    if (diagramAdapter != nullptr)
     {
-        rpar_content->IncreaseRef();
+        diagramAdapter->IncreaseRef();
     }
-    return rpar_content;
+    return diagramAdapter;
 }
 
-void BlockAdapter::setRpar(types::InternalType* v)
+void BlockAdapter::setDiagram(DiagramAdapter* v)
 {
     if (v != nullptr)
     {
-        // The old 'rpar_content' needs to be freed after setting it to 'v'
-        types::InternalType* temp = rpar_content;
+        // The old 'diagramAdapter' needs to be freed after setting it to 'v'
+        DiagramAdapter* temp = diagramAdapter;
 
-        v->IncreaseRef();
-        rpar_content = v;
+        diagramAdapter = v;
 
         if (temp != nullptr)
         {
index c1e5430..edb4021 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "utilities.hxx"
 #include "BaseAdapter.hxx"
+#include "DiagramAdapter.hxx"
 #include "model/Block.hxx"
 
 namespace org_scilab_modules_scicos
@@ -40,14 +41,15 @@ public:
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 
-    types::InternalType* getRpar() const;
-    void setRpar(types::InternalType* v);
+    DiagramAdapter* getDiagram() const;
+    void setDiagram(DiagramAdapter* newDiagram);
 
     types::InternalType* getDocContent() const;
     void setDocContent(types::InternalType* v);
 
 private:
-    types::InternalType* rpar_content;
+    DiagramAdapter* diagramAdapter;
+
     types::InternalType* doc_content;
 };
 
index 73c3c43..7f81602 100644 (file)
@@ -69,7 +69,71 @@ struct objs
 
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
-        return adaptor.getListObjects();
+        model::Diagram* adaptee = adaptor.getAdaptee().get();
+
+        std::vector<ScicosID> children;
+        controller.getObjectProperty(adaptee->id(), DIAGRAM, CHILDREN, children);
+
+        types::List* o = new types::List();
+
+        std::vector<link_t> from = adaptor.getFrom();
+        std::vector<link_t> to = adaptor.getTo();
+
+        int link_number = 0;
+        Controller newController = Controller();
+        for (int i = 0; i < static_cast<int>(children.size()); ++i)
+        {
+            std::shared_ptr<model::BaseObject> item = newController.getObject(children[i]);
+            switch (item->kind())
+            {
+                case ANNOTATION:
+                {
+                    std::shared_ptr<model::Annotation> annotation = std::static_pointer_cast<model::Annotation>(item);
+                    TextAdapter* localAdaptor = new TextAdapter(annotation);
+                    o->set(i, localAdaptor);
+                    continue;
+                }
+                case BLOCK:
+                {
+                    std::shared_ptr<model::Block> block = std::static_pointer_cast<model::Block>(item);
+                    BlockAdapter* localAdaptor = new BlockAdapter(block);
+
+                    types::List* list_objects = adaptor.getListObjects()->getAs<types::List>();
+                    if (i < list_objects->getSize())
+                    {
+                        BlockAdapter* oldBlock = list_objects->get(i)->getAs<BlockAdapter>();
+                        DiagramAdapter* oldBlockDiagram = oldBlock->getDiagram();
+                        if (oldBlockDiagram != nullptr)
+                        {
+                            oldBlockDiagram->IncreaseRef();
+                        }
+                        localAdaptor->setDiagram(oldBlockDiagram);
+                    }
+
+                    o->set(i, localAdaptor);
+                    continue;
+                }
+                case LINK:
+                {
+                    std::shared_ptr<model::Link> link = std::static_pointer_cast<model::Link>(item);
+                    LinkAdapter* localAdaptor = new LinkAdapter(link);
+
+                    // In case a Link points to a Block that has not been added yet,
+                    // retrieve the 'from' and 'to' values from the Diagram Adapter if they have been saved
+                    if (link_number < static_cast<int>(from.size()))
+                    {
+                        localAdaptor->setFrom(from[link_number]);
+                        localAdaptor->setTo(to[link_number]);
+                        link_number++;
+                    }
+                    o->set(i, localAdaptor);
+                    continue;
+                }
+                default:
+                    return 0;
+            }
+        }
+        return o;
     }
 
     static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
@@ -94,8 +158,6 @@ struct objs
             controller.setObjectProperty(id, o->kind(), PARENT_DIAGRAM, 0ll);
         }
         diagramChildren.clear();
-        adaptor.getFrom().clear();
-        adaptor.getTo().clear();
 
         // Set the children to the right IDs
         std::vector<LinkAdapter*> linkListView;
@@ -129,7 +191,7 @@ struct objs
 
                         controller.setObjectProperty(id, LINK, PARENT_DIAGRAM, adaptee->id());
 
-                        // Hold Links information, to try the linking at model-level once all the elements have been added to the Diagram
+                        // Do the linking in the next loop, in case the Link points to a Block that has not been added yet
                         linkListView.push_back(modelElement);
 
                         diagramChildren.push_back(id);
@@ -183,23 +245,26 @@ struct objs
 
         adaptor.setListObjects(v);
 
+        std::vector<link_t> from_content (linkListView.size());
+        std::vector<link_t> to_content (linkListView.size());
         // Do the linking at model-level
         for (int i = 0; i < static_cast<int>(linkListView.size()); ++i)
         {
             // Trigger 'from' and 'to' properties
-            link_t from_content = linkListView[i]->getFrom();
-            if (!linkListView[i]->setFrom(from_content, controller))
+            from_content[i] = linkListView[i]->getFrom();
+            if (!linkListView[i]->setFromInModel(from_content[i], controller) && (from_content[i].block != 0 && from_content[i].port != 0))
             {
                 return false;
             }
-            adaptor.getFrom().push_back(from_content);
-            link_t to_content = linkListView[i]->getTo();
-            if (!linkListView[i]->setTo(to_content, controller))
+            to_content[i] = linkListView[i]->getTo();
+            if (!linkListView[i]->setToInModel(to_content[i], controller) && (to_content[i].block != 0 && to_content[i].port != 0))
             {
                 return false;
             }
-            adaptor.getTo().push_back(to_content);
         }
+        adaptor.setFrom(from_content);
+        adaptor.setTo(to_content);
+
         return true;
     }
 };
@@ -293,11 +358,78 @@ DiagramAdapter::DiagramAdapter(std::shared_ptr<org_scilab_modules_scicos::model:
 
 DiagramAdapter::DiagramAdapter(const DiagramAdapter& adapter) :
     BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(adapter),
-    list_objects(adapter.getListObjects()),
+    list_objects(),
     from_vec(adapter.from_vec),
     to_vec(adapter.to_vec),
     contrib_content(adapter.getContribContent())
 {
+    // Generate an Adapter for each child of the cloned Diagram and store them all in 'list_objects'
+    Controller controller;
+    std::vector<ScicosID> children;
+    controller.getObjectProperty(getAdaptee()->id(), DIAGRAM, CHILDREN, children);
+
+    std::vector<LinkAdapter*> linkListView; // Store the new LinkAdapters to make the linking at model-level after the loop
+    types::List* List_objects = new types::List();
+    for (int i = 0; i < static_cast<int>(children.size()); ++i)
+    {
+        std::shared_ptr<model::BaseObject> item = controller.getObject(children[i]);
+        switch (item->kind())
+        {
+            case ANNOTATION:
+            {
+                std::shared_ptr<model::Annotation> annotation = std::static_pointer_cast<model::Annotation>(item);
+                TextAdapter* localAdaptor = new TextAdapter(annotation);
+
+                List_objects->set(i, localAdaptor);
+                continue;
+            }
+            case BLOCK:
+            {
+                std::shared_ptr<model::Block> block = std::static_pointer_cast<model::Block>(item);
+                BlockAdapter* localAdaptor = new BlockAdapter(block);
+
+                // If the diagram's block was a SuperBlock, make its new adapter point to its old diagram
+                types::List* oldList_objects = adapter.getListObjects()->getAs<types::List>();
+                if (i < oldList_objects->getSize())
+                {
+                    BlockAdapter* oldBlock = oldList_objects->get(i)->getAs<BlockAdapter>();
+                    DiagramAdapter* oldBlockDiagram = oldBlock->getDiagram();
+                    if (oldBlockDiagram != nullptr)
+                    {
+                        oldBlockDiagram->IncreaseRef();
+                    }
+                    localAdaptor->setDiagram(oldBlockDiagram);
+                }
+
+                List_objects->set(i, localAdaptor);
+                continue;
+            }
+            case LINK:
+            {
+                std::shared_ptr<model::Link> link = std::static_pointer_cast<model::Link>(item);
+                LinkAdapter* localAdaptor = new LinkAdapter(link);
+
+                // Do the model linking in the next loop, in case the Link points to a Block that has not been added yet
+                linkListView.push_back(localAdaptor);
+
+                List_objects->set(i, localAdaptor);
+                continue;
+            }
+            default:
+            {
+            }
+        }
+    }
+
+    // Do the linking at model-level, from the old 'from_vec' and 'to_vec'
+    for (int i = 0; i < static_cast<int>(linkListView.size()); ++i)
+    {
+        // Trigger 'from' and 'to' properties
+        linkListView[i]->setFromInModel(from_vec[i], controller);
+        linkListView[i]->setToInModel(to_vec[i], controller);
+    }
+
+    list_objects = List_objects;
 }
 
 DiagramAdapter::~DiagramAdapter()
@@ -313,6 +445,8 @@ DiagramAdapter::~DiagramAdapter()
             auto o = controller.getObject(id);
             controller.setObjectProperty(id, o->kind(), PARENT_DIAGRAM, 0ll);
         }
+        diagramChildren.clear();
+        controller.setObjectProperty(getAdaptee()->id(), DIAGRAM, CHILDREN, diagramChildren);
     }
 
     list_objects->DecreaseRef();
@@ -363,15 +497,25 @@ void DiagramAdapter::setListObjects(types::InternalType* v)
     temp->killMe();
 }
 
-std::vector<link_t>& DiagramAdapter::getFrom()
+std::vector<link_t> DiagramAdapter::getFrom() const
 {
     return from_vec;
 }
 
-std::vector<link_t>& DiagramAdapter::getTo()
+void DiagramAdapter::setFrom(const std::vector<link_t>& from)
+{
+    from_vec = from;
+}
+
+std::vector<link_t> DiagramAdapter::getTo() const
 {
     return to_vec;
 }
 
+void DiagramAdapter::setTo(const std::vector<link_t>& to)
+{
+    to_vec = to;
+}
+
 } /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
index d69acf7..969801f 100644 (file)
@@ -45,8 +45,10 @@ public:
     types::InternalType* getListObjects() const;
     void setListObjects(types::InternalType* v);
 
-    std::vector<link_t>& getFrom();
-    std::vector<link_t>& getTo();
+    std::vector<link_t> getFrom() const;
+    void setFrom(const std::vector<link_t>& from);
+    std::vector<link_t> getTo() const;
+    void setTo(const std::vector<link_t>& to);
 
     types::InternalType* getContribContent() const;
     void setContribContent(types::InternalType* v);
index 8123ba1..709f061 100644 (file)
@@ -403,18 +403,15 @@ void setLinkEnd(const ScicosID id, Controller& controller, const object_properti
     controller.getObjectProperty(id, LINK, DESTINATION_PORT, to);
     ScicosID concernedPort;
     ScicosID otherPort;
-    object_properties_t otherEnd;
     switch (end)
     {
         case SOURCE_PORT:
             concernedPort = from;
             otherPort = to;
-            otherEnd = DESTINATION_PORT;
             break;
         case DESTINATION_PORT:
             concernedPort = to;
             otherPort = from;
-            otherEnd = SOURCE_PORT;
             break;
         default:
             return;
@@ -736,7 +733,7 @@ struct from
             from_content.kind = (current->get(2) == 0.) ? Start : End;
         }
 
-        return adaptor.setFrom(from_content, controller);
+        return adaptor.setFromInModel(from_content, controller);
     }
 };
 
@@ -787,7 +784,7 @@ struct to
             to_content.kind = (current->get(2) == 0.) ? Start : End;
         }
 
-        return adaptor.setTo(to_content, controller);
+        return adaptor.setToInModel(to_content, controller);
     }
 };
 
@@ -850,7 +847,12 @@ link_t LinkAdapter::getFrom() const
     return m_from;
 }
 
-bool LinkAdapter::setFrom(const link_t& v, Controller& controller)
+void LinkAdapter::setFrom(const link_t& v)
+{
+    m_from = v;
+}
+
+bool LinkAdapter::setFromInModel(const link_t& v, Controller& controller)
 {
     m_from = v;
 
@@ -872,7 +874,12 @@ link_t LinkAdapter::getTo() const
     return m_to;
 }
 
-bool LinkAdapter::setTo(const link_t& v, Controller& controller)
+void LinkAdapter::setTo(const link_t& v)
+{
+    m_to = v;
+}
+
+bool LinkAdapter::setToInModel(const link_t& v, Controller& controller)
 {
     m_to = v;
 
index 8995a6e..fa067b2 100644 (file)
@@ -43,9 +43,11 @@ public:
     std::wstring getShortTypeStr();
 
     link_t getFrom() const;
-    bool setFrom(const link_t& v, Controller& controller);
+    void setFrom(const link_t& v);
+    bool setFromInModel(const link_t& v, Controller& controller);
     link_t getTo() const;
-    bool setTo(const link_t& v, Controller& controller);
+    void setTo(const link_t& v);
+    bool setToInModel(const link_t& v, Controller& controller);
 
 private:
     link_t m_from;
index 920ec65..aac7f1e 100644 (file)
@@ -892,10 +892,10 @@ struct rpar
     {
         ScicosID adaptee = adaptor.getAdaptee()->id();
 
-        std::vector<ScicosID> children;
-        controller.getObjectProperty(adaptee, BLOCK, CHILDREN, children);
+        std::vector<ScicosID> diagramChild;
+        controller.getObjectProperty(adaptee, BLOCK, CHILDREN, diagramChild);
 
-        if (children.empty())
+        if (diagramChild.empty())
         {
             std::vector<double> rpar;
             controller.getObjectProperty(adaptee, BLOCK, RPAR, rpar);
@@ -911,7 +911,16 @@ struct rpar
         }
         else // SuperBlock, return the contained diagram
         {
-            return adaptor.getDiagram();
+            std::shared_ptr<model::Diagram> super = std::static_pointer_cast<model::Diagram>(controller.getObject(diagramChild[0]));
+            DiagramAdapter* localAdaptor = new DiagramAdapter(super);
+            //model::Diagram* super = static_cast<model::Diagram*>(controller.getObject(diagramC[0]).get());
+            //DiagramAdapter* localAdapter = new DiagramAdapter(std::shared_ptr<model::Diagram>(super));
+
+            DiagramAdapter* diagram = adaptor.getRpar();
+            localAdaptor->setListObjects(diagram->getListObjects());
+            localAdaptor->setFrom(diagram->getFrom());
+            localAdaptor->setTo(diagram->getTo());
+            return localAdaptor;
         }
     }
 
@@ -948,18 +957,17 @@ struct rpar
 
             // Translate 'v' to an DiagramAdapter, save it and update the Block's children list
             DiagramAdapter* diagram = v->getAs<DiagramAdapter>();
-            diagram->IncreaseRef();
 
             adaptor.setDiagram(diagram);
 
-            // Save the children list, adding the new diagram ID at the end so it is deleted on 'clear'
-            std::vector<ScicosID> children;
-            controller.getObjectProperty(diagram->getAdaptee()->id(), DIAGRAM, CHILDREN, children);
-            children.push_back(diagram->getAdaptee()->id());
-            controller.setObjectProperty(adaptee, BLOCK, CHILDREN, children);
+            // Save the child diagram's ID so it is deleted on 'clear'
+            std::vector<ScicosID> diagramChild (1, diagram->getAdaptee()->id());
+            controller.setObjectProperty(adaptee, BLOCK, CHILDREN, diagramChild);
 
             // Link the Superblock ports to their inner "port blocks"
-            return setInnerBlocksRefs(adaptor, children, controller);
+            std::vector<ScicosID> diagramChildren;
+            controller.getObjectProperty(diagram->getAdaptee()->id(), DIAGRAM, CHILDREN, diagramChildren);
+            return setInnerBlocksRefs(adaptor, diagramChildren, controller);
         }
         else
         {
@@ -1740,7 +1748,7 @@ ModelAdapter::ModelAdapter(std::shared_ptr<model::Block> adaptee) :
 
 ModelAdapter::ModelAdapter(const ModelAdapter& adapter) :
     BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(adapter),
-    diagramAdapter(adapter.getDiagram())
+    diagramAdapter(adapter.getRpar())
 {
 }
 
@@ -1763,7 +1771,7 @@ std::wstring ModelAdapter::getShortTypeStr()
     return getSharedTypeStr();
 }
 
-DiagramAdapter* ModelAdapter::getDiagram() const
+DiagramAdapter* ModelAdapter::getRpar() const
 {
     if (diagramAdapter != nullptr)
     {
@@ -1774,16 +1782,19 @@ DiagramAdapter* ModelAdapter::getDiagram() const
 
 void ModelAdapter::setDiagram(DiagramAdapter* newDiagram)
 {
-    // The old 'diagramAdapter' needs to be freed after setting it to 'newDiagram'
-    types::InternalType* temp = diagramAdapter;
+    if (newDiagram != nullptr)
+    {
+        // The old 'diagramAdapter' needs to be freed after setting it to 'v'
+        DiagramAdapter* temp = diagramAdapter;
 
-    newDiagram->IncreaseRef();
-    diagramAdapter = newDiagram;
+        newDiagram->IncreaseRef();
+        diagramAdapter = newDiagram;
 
-    if (temp != nullptr)
-    {
-        temp->DecreaseRef();
-        temp->killMe();
+        if (temp != nullptr)
+        {
+            temp->DecreaseRef();
+            temp->killMe();
+        }
     }
 }
 
index a7636e3..9fac105 100644 (file)
@@ -40,7 +40,7 @@ public:
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
 
-    DiagramAdapter* getDiagram() const;
+    DiagramAdapter* getRpar() const;
     void setDiagram(DiagramAdapter* newDiagram);
 
 private:
index 10a0f6e..d56df8b 100644 (file)
@@ -91,7 +91,7 @@ struct title
         else if (current->getSize() == 2)
         {
             char* Path = wide_string_to_UTF8(current->get(1));
-            title = std::string(Path);
+            path = std::string(Path);
             FREE(Path);
         }
         else
index 9036943..2deffb9 100644 (file)
@@ -106,7 +106,7 @@ Model   :
 clear Sum
 // Sum2's refCount must have been affected by "clear Sum"
 Sum2
-Sum2  = (2)
+Sum2  = 
 GUI     : BIGSOM_f
 Graphics: 
           orig = [0,0]
index db7242e..323770f 100644 (file)
@@ -49,6 +49,7 @@ scs_m.contrib
  ans  =
      ()
 clear scs_m
+propertyUpdated( 1 , DIAGRAM , CHILDREN ) : NO_CHANGES
 objectDeleted( 1 , DIAGRAM )
 // Create a dummy diagram with one undefined block then clear it
 scs_m = scicos_diagram(objs=list(scicos_block()));
@@ -86,6 +87,7 @@ propertyUpdated( 3 , DIAGRAM , CHILDREN ) : SUCCESS
 propertyUpdated( 3 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
 clear scs_m
 propertyUpdated( 2 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 3 , DIAGRAM , CHILDREN ) : SUCCESS
 objectDeleted( 2 , BLOCK )
 objectDeleted( 3 , DIAGRAM )
 // Create a diagram containing 2 summation blocks and two links
@@ -640,6 +642,7 @@ propertyUpdated( 8 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 11 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 14 , LINK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 15 , LINK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 16 , DIAGRAM , CHILDREN ) : SUCCESS
 objectDeleted( 16 , DIAGRAM )
 lnk   = scicos_link( from=[1 1 0],to=[2 1 1] );
 objectCreated( 19 , LINK )
@@ -677,6 +680,7 @@ clear scs_m;
 propertyUpdated( 4 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 8 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 19 , LINK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 20 , DIAGRAM , CHILDREN ) : SUCCESS
 objectDeleted( 20 , DIAGRAM )
 lnk   = scicos_link( from=[1 1 0],to=[2 1 1] );
 objectCreated( 21 , LINK )
@@ -837,6 +841,7 @@ clear scs_m;
 propertyUpdated( 4 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 8 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 23 , LINK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
 propertyUpdated( 7 , PORT , CONNECTED_SIGNALS ) : SUCCESS
 propertyUpdated( 9 , PORT , CONNECTED_SIGNALS ) : SUCCESS
 objectDeleted( 23 , LINK )
@@ -1233,6 +1238,7 @@ objectDeleted( 24 , LINK )
 propertyUpdated( 26 , LINK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 27 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
 propertyUpdated( 31 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 25 , DIAGRAM , CHILDREN ) : SUCCESS
 propertyUpdated( 30 , PORT , CONNECTED_SIGNALS ) : SUCCESS
 propertyUpdated( 32 , PORT , CONNECTED_SIGNALS ) : SUCCESS
 objectDeleted( 26 , LINK )
index ee12db9..6bb20d2 100644 (file)
@@ -1380,7 +1380,7 @@ void3 = []
 doc = list()
 1     CLKOUT_f
 2     EVTDLY_c
-4     CLKSPLIT_f
+3     CLKSPLIT_f
 clk.model.rpar.props
  ans  =
 wpar = []
@@ -1712,6 +1712,7 @@ clk.model.rpar.objs(6).to
     2.    1.    1.
 // Check that all the model items are freed
 clear sb clk
+propertyUpdated( 10 , BLOCK , CHILDREN ) : SUCCESS
 propertyUpdated( 10 , BLOCK , INPUTS ) : SUCCESS
 propertyUpdated( 10 , BLOCK , OUTPUTS ) : NO_CHANGES
 propertyUpdated( 10 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
@@ -1722,79 +1723,11 @@ propertyUpdated( 10 , BLOCK , OUTPUTS ) : SUCCESS
 propertyUpdated( 10 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
 propertyUpdated( 10 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
 objectDeleted( 12 , PORT )
-propertyUpdated( 1 , DIAGRAM , CHILDREN ) : SUCCESS
-propertyUpdated( 6 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 6 , BLOCK , OUTPUTS ) : SUCCESS
-propertyUpdated( 6 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
-propertyUpdated( 6 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
-objectDeleted( 7 , PORT )
-propertyUpdated( 10 , BLOCK , CHILDREN ) : SUCCESS
-objectDeleted( 6 , BLOCK )
-propertyUpdated( 1 , DIAGRAM , CHILDREN ) : SUCCESS
-propertyUpdated( 8 , BLOCK , INPUTS ) : SUCCESS
-propertyUpdated( 8 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 8 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
-propertyUpdated( 8 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
-objectDeleted( 9 , PORT )
-propertyUpdated( 10 , BLOCK , CHILDREN ) : SUCCESS
-objectDeleted( 8 , BLOCK )
-objectDeleted( 1 , DIAGRAM )
 objectDeleted( 10 , BLOCK )
+propertyUpdated( 38 , BLOCK , CHILDREN ) : SUCCESS
 propertyUpdated( 38 , BLOCK , INPUTS ) : NO_CHANGES
 propertyUpdated( 38 , BLOCK , OUTPUTS ) : NO_CHANGES
 propertyUpdated( 38 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
 propertyUpdated( 38 , BLOCK , EVENT_OUTPUTS ) : SUCCESS
 objectDeleted( 39 , PORT )
-propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
-propertyUpdated( 23 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 23 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 23 , BLOCK , EVENT_INPUTS ) : SUCCESS
-propertyUpdated( 23 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
-propertyUpdated( 35 , LINK , DESTINATION_PORT ) : SUCCESS
-objectDeleted( 24 , PORT )
-propertyUpdated( 38 , BLOCK , CHILDREN ) : SUCCESS
-objectDeleted( 23 , BLOCK )
-propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
-propertyUpdated( 25 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 25 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 25 , BLOCK , EVENT_INPUTS ) : SUCCESS
-propertyUpdated( 25 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
-propertyUpdated( 37 , LINK , DESTINATION_PORT ) : SUCCESS
-objectDeleted( 26 , PORT )
-propertyUpdated( 25 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 25 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 25 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
-propertyUpdated( 25 , BLOCK , EVENT_OUTPUTS ) : SUCCESS
-propertyUpdated( 29 , LINK , SOURCE_PORT ) : SUCCESS
-objectDeleted( 27 , PORT )
-propertyUpdated( 38 , BLOCK , CHILDREN ) : SUCCESS
-objectDeleted( 25 , BLOCK )
-propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
-propertyUpdated( 31 , PORT , CONNECTED_SIGNALS ) : SUCCESS
-objectDeleted( 29 , LINK )
-propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
-propertyUpdated( 30 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , EVENT_INPUTS ) : SUCCESS
-propertyUpdated( 30 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
-objectDeleted( 31 , PORT )
-propertyUpdated( 30 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , EVENT_OUTPUTS ) : SUCCESS
-propertyUpdated( 35 , LINK , SOURCE_PORT ) : SUCCESS
-objectDeleted( 32 , PORT )
-propertyUpdated( 30 , BLOCK , INPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , OUTPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
-propertyUpdated( 30 , BLOCK , EVENT_OUTPUTS ) : SUCCESS
-propertyUpdated( 37 , LINK , SOURCE_PORT ) : SUCCESS
-objectDeleted( 33 , PORT )
-propertyUpdated( 38 , BLOCK , CHILDREN ) : SUCCESS
-objectDeleted( 30 , BLOCK )
-propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
-objectDeleted( 35 , LINK )
-propertyUpdated( 22 , DIAGRAM , CHILDREN ) : SUCCESS
-objectDeleted( 37 , LINK )
-objectDeleted( 22 , DIAGRAM )
 objectDeleted( 38 , BLOCK )
diff --git a/scilab/modules/scicos/tests/unit_tests/model/SuperBlock_in_SuperBlock.dia.ref b/scilab/modules/scicos/tests/unit_tests/model/SuperBlock_in_SuperBlock.dia.ref
new file mode 100644 (file)
index 0000000..cd095d0
--- /dev/null
@@ -0,0 +1,359 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+loadXcosLibs();
+link = scicos_link(from=[2,1,0],to=[3,1,1]);
+objectCreated( 1 , LINK )
+propertyUpdated( 1 , LINK , CONTROL_POINTS ) : NO_CHANGES
+propertyUpdated( 1 , LINK , CONTROL_POINTS ) : NO_CHANGES
+propertyUpdated( 1 , LINK , LABEL ) : NO_CHANGES
+propertyUpdated( 1 , LINK , THICK ) : NO_CHANGES
+propertyUpdated( 1 , LINK , COLOR ) : NO_CHANGES
+propertyUpdated( 1 , LINK , KIND ) : NO_CHANGES
+subDiag = scicos_diagram( objs=list(link) );
+objectCreated( 2 , DIAGRAM )
+propertyUpdated( 2 , DIAGRAM , TITLE ) : NO_CHANGES
+propertyUpdated( 2 , DIAGRAM , PATH ) : NO_CHANGES
+propertyUpdated( 2 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 2 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 2 , DIAGRAM , CONTEXT ) : NO_CHANGES
+propertyUpdated( 1 , LINK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 2 , DIAGRAM , CHILDREN ) : SUCCESS
+propertyUpdated( 2 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
+Super1 = scicos_block(,..
+model=scicos_model(sim="super",in=[],in2=[],intyp=1,out=[],out2=[],outtyp=[],evtin=[],evtout=[],state=[],dstate=[],odstate=list(),..
+rpar=subDiag,..
+ipar=[],opar=list(),blocktype="h",firing=[],dep_ut=[%f,%f],label="Quat_Conj",nzcross=0,nmode=0,equations=list())..
+);
+objectCreated( 3 , BLOCK )
+propertyUpdated( 3 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , EXPRS ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , LABEL ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , STYLE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , SIM_FUNCTION_NAME ) : SUCCESS
+propertyUpdated( 3 , BLOCK , SIM_FUNCTION_API ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , STATE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , DSTATE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , ODSTATE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , CHILDREN ) : SUCCESS
+propertyUpdated( 3 , BLOCK , IPAR ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , OPAR ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , SIM_BLOCKTYPE ) : SUCCESS
+propertyUpdated( 3 , BLOCK , SIM_DEP_UT ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , LABEL ) : SUCCESS
+propertyUpdated( 3 , BLOCK , NZCROSS ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , NMODE ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , UID ) : NO_CHANGES
+propertyUpdated( 3 , BLOCK , INTERFACE_FUNCTION ) : NO_CHANGES
+diag = scicos_diagram();
+objectCreated( 4 , DIAGRAM )
+propertyUpdated( 4 , DIAGRAM , TITLE ) : NO_CHANGES
+propertyUpdated( 4 , DIAGRAM , PATH ) : NO_CHANGES
+propertyUpdated( 4 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 4 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 4 , DIAGRAM , CONTEXT ) : NO_CHANGES
+propertyUpdated( 4 , DIAGRAM , CHILDREN ) : NO_CHANGES
+propertyUpdated( 4 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
+diag.objs(1) = Super1;
+objectCreated( 5 , BLOCK )
+propertyUpdated( 5 , BLOCK , SIM_FUNCTION_API ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , NZCROSS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , NMODE ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , INTERFACE_FUNCTION ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , SIM_FUNCTION_NAME ) : SUCCESS
+propertyUpdated( 5 , BLOCK , SIM_BLOCKTYPE ) : SUCCESS
+propertyUpdated( 5 , BLOCK , UID ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , STYLE ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , LABEL ) : SUCCESS
+propertyUpdated( 5 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , STATE ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , DSTATE ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , RPAR ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , SIM_DEP_UT ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , ODSTATE ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , IPAR ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , OPAR ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , EXPRS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , EQUATIONS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , PARENT_DIAGRAM ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , INPUTS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , OUTPUTS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , EVENT_INPUTS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , EVENT_OUTPUTS ) : NO_CHANGES
+propertyUpdated( 5 , BLOCK , PARENT_BLOCK ) : NO_CHANGES
+objectCreated( 6 , DIAGRAM )
+propertyUpdated( 6 , DIAGRAM , TITLE ) : NO_CHANGES
+propertyUpdated( 6 , DIAGRAM , PATH ) : NO_CHANGES
+propertyUpdated( 6 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
+propertyUpdated( 6 , DIAGRAM , PROPERTIES ) : NO_CHANGES
+propertyUpdated( 6 , DIAGRAM , CONTEXT ) : NO_CHANGES
+objectCreated( 7 , LINK )
+propertyUpdated( 7 , LINK , COLOR ) : NO_CHANGES
+propertyUpdated( 7 , LINK , KIND ) : NO_CHANGES
+propertyUpdated( 7 , LINK , LABEL ) : NO_CHANGES
+propertyUpdated( 7 , LINK , CONTROL_POINTS ) : NO_CHANGES
+propertyUpdated( 7 , LINK , THICK ) : NO_CHANGES
+propertyUpdated( 7 , LINK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 7 , LINK , SOURCE_PORT ) : NO_CHANGES
+propertyUpdated( 7 , LINK , DESTINATION_PORT ) : NO_CHANGES
+propertyUpdated( 6 , DIAGRAM , CHILDREN ) : SUCCESS
+propertyUpdated( 5 , BLOCK , CHILDREN ) : SUCCESS
+propertyUpdated( 5 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 4 , DIAGRAM , CHILDREN ) : SUCCESS
+diag.objs(1)
+ ans  =
+GUI     : 
+Graphics: 
+          orig = [0,0]
+          sz = [20,20]
+          flip = %t
+          theta = 0
+          exprs = 
+          pin = []
+          pout = []
+          pein = []
+          peout = []
+          gr_i = []
+          id = "Quat_Conj"
+          in_implicit = []
+          out_implicit = []
+          in_style = 
+          out_style = 
+          in_label = 
+          out_label = 
+          style = ""
+Model   : 
+          super type: 0
+          in = []
+          in2 = []
+          intyp = 1
+          out = []
+          out2 = []
+          outtyp = 1
+          evtin = []
+          evtout = []
+          state = []
+          dstate = []
+          odstate = list()
+          rpar : SuperBlock
+          ipar = []
+          opar = list()
+          blocktype = "h"
+          firing = []
+          dep_ut = [%f,%f]
+          label = "Quat_Conj"
+          nzcross = 0
+          nmode = 0
+          equations = list()
+          uid = ""
+diag.objs(1).model
+ ans  =
+super type: 0
+in = []
+in2 = []
+intyp = 1
+out = []
+out2 = []
+outtyp = 1
+evtin = []
+evtout = []
+state = []
+dstate = []
+odstate = list()
+rpar = mlist(["diagram","props","objs","version","contrib"],tlist(["params","wpar","title","tol","tf","context","void1","options","void2","void3","doc"],[],["Untitled";""],[0.000001,0.000001,1.000D-10,100001,0,1,0],100000,[],[],tlist("scsopt"),[],[],list()),list(mlist(["Link","xx","yy","id","thick","ct","from","to"],[],[],"",[0,0],[1,1],[2,1,0],[3,1,1])),"",list())
+ipar = []
+opar = list()
+blocktype = "h"
+firing = []
+dep_ut = [%f,%f]
+label = "Quat_Conj"
+nzcross = 0
+nmode = 0
+equations = list()
+uid = ""
+diag.objs(1).model.rpar.objs(1)
+ ans  =
+Link    :
+          xx: []
+          yy: []
+          id: 
+          thick: 0 0
+          ct: 1 1
+          from: 2 1 0
+          to: 3 1 1
+Super2 = scicos_block(,..
+model=scicos_model(sim="super",in=[],in2=[],intyp=1,out=[],out2=[],outtyp=[],evtin=[],evtout=[],state=[],dstate=[],odstate=list(),..
+rpar=diag,..
+ipar=[],opar=list(),blocktype="h",firing=[],dep_ut=[%f,%f],label="Quat_Conj",nzcross=0,nmode=0,equations=list())..
+);
+objectCreated( 8 , BLOCK )
+propertyUpdated( 8 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , GEOMETRY ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , ANGLE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , EXPRS ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , LABEL ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , STYLE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , SIM_FUNCTION_NAME ) : SUCCESS
+propertyUpdated( 8 , BLOCK , SIM_FUNCTION_API ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , STATE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , DSTATE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , ODSTATE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , CHILDREN ) : SUCCESS
+propertyUpdated( 5 , BLOCK , PARENT_BLOCK ) : SUCCESS
+propertyUpdated( 8 , BLOCK , IPAR ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , OPAR ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , SIM_BLOCKTYPE ) : SUCCESS
+propertyUpdated( 8 , BLOCK , SIM_DEP_UT ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , LABEL ) : SUCCESS
+propertyUpdated( 8 , BLOCK , NZCROSS ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , NMODE ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , UID ) : NO_CHANGES
+propertyUpdated( 8 , BLOCK , INTERFACE_FUNCTION ) : NO_CHANGES
+Super2.model
+ ans  =
+super type: 0
+in = []
+in2 = []
+intyp = 1
+out = []
+out2 = []
+outtyp = 1
+evtin = []
+evtout = []
+state = []
+dstate = []
+odstate = list()
+rpar = mlist(["diagram","props","objs","version","contrib"],tlist(["params","wpar","title","tol","tf","context","void1","options","void2","void3","doc"],[],["Untitled";""],[0.000001,0.000001,1.000D-10,100001,0,1,0],100000,[],[],tlist("scsopt"),[],[],list()),list(mlist(["Block","graphics","model","gui","doc"],mlist(["graphics","orig","sz","flip","theta","exprs","pin","pout","pein","peout","gr_i","id","in_implicit","out_implicit","in_style","out_style","in_label","out_label","style"],[0,0],[20,20],%t,0,..,[],[],[],[],[],"Quat_Conj",[],[],..,..,..,..,""),mlist(["model","sim","in","in2","intyp","out","out2","outtyp","evtin","evtout","state","dstate","odstate","rpar","ipar","opar","blocktype","firing","dep_ut","label","nzcross","nmode","equations","uid"],"super",[],[],1,[],[],1,[],[],[],[],list(),mlist(["diagram","props","objs","version","contrib"],tlist(["params","wpar","title","tol","tf","context","void1","options","void2","void3","doc"],[],["Untitled";""],[0.000001,0.000001,1.000D-10,100001,0,1,0],100000,[],[],tlist("scsopt"),[],[],list()),list(mlist(["Link","xx","yy","id","thick","ct","from","to"],[],[],"",[0,0],[1,1],[2,1,0],[3,1,1])),"",list()),[],list(),"h",[],[%f,%f],"Quat_Conj",0,0,list(),""),"",list())),"",list())
+ipar = []
+opar = list()
+blocktype = "h"
+firing = []
+dep_ut = [%f,%f]
+label = "Quat_Conj"
+nzcross = 0
+nmode = 0
+equations = list()
+uid = ""
+Super2.model.rpar
+ ans  =
+wpar = []
+title = ["Untitled";""]
+tol = [0.000001,0.000001,1.000D-10,100001,0,1,0]
+tf = 100000
+context = []
+void1 = []
+options = tlist("scsopt")
+void2 = []
+void3 = []
+doc = list()
+1     
+Super2.model.rpar.objs(1)
+ ans  =
+GUI     : 
+Graphics: 
+          orig = [0,0]
+          sz = [20,20]
+          flip = %t
+          theta = 0
+          exprs = 
+          pin = []
+          pout = []
+          pein = []
+          peout = []
+          gr_i = []
+          id = "Quat_Conj"
+          in_implicit = []
+          out_implicit = []
+          in_style = 
+          out_style = 
+          in_label = 
+          out_label = 
+          style = ""
+Model   : 
+          super type: 0
+          in = []
+          in2 = []
+          intyp = 1
+          out = []
+          out2 = []
+          outtyp = 1
+          evtin = []
+          evtout = []
+          state = []
+          dstate = []
+          odstate = list()
+          rpar : SuperBlock
+          ipar = []
+          opar = list()
+          blocktype = "h"
+          firing = []
+          dep_ut = [%f,%f]
+          label = "Quat_Conj"
+          nzcross = 0
+          nmode = 0
+          equations = list()
+          uid = ""
+Super2.model.rpar.objs(1).model
+ ans  =
+super type: 0
+in = []
+in2 = []
+intyp = 1
+out = []
+out2 = []
+outtyp = 1
+evtin = []
+evtout = []
+state = []
+dstate = []
+odstate = list()
+rpar = mlist(["diagram","props","objs","version","contrib"],tlist(["params","wpar","title","tol","tf","context","void1","options","void2","void3","doc"],[],["Untitled";""],[0.000001,0.000001,1.000D-10,100001,0,1,0],100000,[],[],tlist("scsopt"),[],[],list()),list(mlist(["Link","xx","yy","id","thick","ct","from","to"],[],[],"",[0,0],[1,1],[2,1,0],[3,1,1])),"",list())
+ipar = []
+opar = list()
+blocktype = "h"
+firing = []
+dep_ut = [%f,%f]
+label = "Quat_Conj"
+nzcross = 0
+nmode = 0
+equations = list()
+uid = ""
+Super2.model.rpar.objs(1).model.rpar
+ ans  =
+wpar = []
+title = ["Untitled";""]
+tol = [0.000001,0.000001,1.000D-10,100001,0,1,0]
+tf = 100000
+context = []
+void1 = []
+options = tlist("scsopt")
+void2 = []
+void3 = []
+doc = list()
+Super2.model.rpar.objs(1).model.rpar.objs(1)
+ ans  =
+Link    :
+          xx: []
+          yy: []
+          id: 
+          thick: 0 0
+          ct: 1 1
+          from: 2 1 0
+          to: 3 1 1
+assert_checkequal(Super2.model.rpar.objs(1).model.rpar.objs(1).from, [2 1 0]);
+assert_checkequal(Super2.model.rpar.objs(1).model.rpar.objs(1).to,   [3 1 1]);
+// Check that all the model items are freed
+clear
+propertyUpdated( 3 , BLOCK , CHILDREN ) : SUCCESS
+objectDeleted( 3 , BLOCK )
+propertyUpdated( 8 , BLOCK , CHILDREN ) : SUCCESS
+objectDeleted( 8 , BLOCK )
diff --git a/scilab/modules/scicos/tests/unit_tests/model/SuperBlock_in_SuperBlock.tst b/scilab/modules/scicos/tests/unit_tests/model/SuperBlock_in_SuperBlock.tst
new file mode 100644 (file)
index 0000000..1191bf2
--- /dev/null
@@ -0,0 +1,43 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+loadXcosLibs();
+
+link = scicos_link(from=[2,1,0],to=[3,1,1]);
+subDiag = scicos_diagram( objs=list(link) );
+
+Super1 = scicos_block(,..
+model=scicos_model(sim="super",in=[],in2=[],intyp=1,out=[],out2=[],outtyp=[],evtin=[],evtout=[],state=[],dstate=[],odstate=list(),..
+rpar=subDiag,..
+ipar=[],opar=list(),blocktype="h",firing=[],dep_ut=[%f,%f],label="Quat_Conj",nzcross=0,nmode=0,equations=list())..
+);
+diag = scicos_diagram();
+diag.objs(1) = Super1;
+diag.objs(1)
+diag.objs(1).model
+diag.objs(1).model.rpar.objs(1)
+
+Super2 = scicos_block(,..
+model=scicos_model(sim="super",in=[],in2=[],intyp=1,out=[],out2=[],outtyp=[],evtin=[],evtout=[],state=[],dstate=[],odstate=list(),..
+rpar=diag,..
+ipar=[],opar=list(),blocktype="h",firing=[],dep_ut=[%f,%f],label="Quat_Conj",nzcross=0,nmode=0,equations=list())..
+);
+
+Super2.model
+Super2.model.rpar
+Super2.model.rpar.objs(1)
+Super2.model.rpar.objs(1).model
+Super2.model.rpar.objs(1).model.rpar
+Super2.model.rpar.objs(1).model.rpar.objs(1)
+assert_checkequal(Super2.model.rpar.objs(1).model.rpar.objs(1).from, [2 1 0]);
+assert_checkequal(Super2.model.rpar.objs(1).model.rpar.objs(1).to,   [3 1 1]);
+
+
+// Check that all the model items are freed
+clear
index 0319b56..d4a449f 100644 (file)
@@ -67,7 +67,5 @@ assert_checkequal(b.model.rpar.objs(1).from, [3 3 0]);
 assert_checkequal(b.model.rpar.objs(1).to, [5 2 1]);
 // Check that all the model items are freed
 clear
-propertyUpdated( 3 , DIAGRAM , CHILDREN ) : SUCCESS
-objectDeleted( 2 , LINK )
-objectDeleted( 3 , DIAGRAM )
+propertyUpdated( 1 , BLOCK , CHILDREN ) : SUCCESS
 objectDeleted( 1 , BLOCK )
index 61a9f74..1af93f8 100644 (file)
@@ -42,6 +42,7 @@ propertyUpdated( 2 , DIAGRAM , CHILDREN ) : SUCCESS
 propertyUpdated( 2 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
 clear scs_m
 propertyUpdated( 1 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 2 , DIAGRAM , CHILDREN ) : SUCCESS
 objectDeleted( 1 , BLOCK )
 objectDeleted( 2 , DIAGRAM )
 // Test #2: the block is deleted after the diagram
@@ -81,6 +82,7 @@ propertyUpdated( 4 , DIAGRAM , CHILDREN ) : SUCCESS
 propertyUpdated( 4 , DIAGRAM , VERSION_NUMBER ) : NO_CHANGES
 clear scs_m
 propertyUpdated( 3 , BLOCK , PARENT_DIAGRAM ) : SUCCESS
+propertyUpdated( 4 , DIAGRAM , CHILDREN ) : SUCCESS
 objectDeleted( 4 , DIAGRAM )
 clear blk
 objectDeleted( 3 , BLOCK )
index 6431794..86ecaa0 100644 (file)
@@ -824,8 +824,8 @@ function ml = user2mlist(u)
     fn = getfield(1, u);
     ml = mlist(fn);
 
-    for k=2:size(fn,"*")
-        ml(i) = eval("u."+fn(k));
+    for k=1:size(fn,"*")
+        ml(k) = eval("u."+fn(k));
     end
 
 endfunction