Xcos MVC: implement clone / delete on the Model side 57/15257/4
Clément DAVID [Fri, 19 Sep 2014 13:19:20 +0000 (15:19 +0200)]
Change-Id: Ib067d1f5a6d89dcf940d4763462556fd752ae38b

30 files changed:
scilab/modules/ast/includes/exps/ast.hxx
scilab/modules/ast/includes/types/user.hxx
scilab/modules/scicos/includes/Controller.hxx
scilab/modules/scicos/sci_gateway/cpp/sci_scicos_new.cpp
scilab/modules/scicos/src/cpp/Controller.cpp
scilab/modules/scicos/src/cpp/Model.cpp
scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/model/Block.hxx
scilab/modules/scicos/src/cpp/view_scilab/BaseAdapter.hxx
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/CprAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/CprAdapter.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/GraphicsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.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/src/cpp/view_scilab/ParamsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ScsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ScsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/StateAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/StateAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/TextAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/TextAdapter.hxx
scilab/modules/scicos/tests/unit_tests/scicos_new.tst

index 2670e53..8e44250 100644 (file)
@@ -33,7 +33,7 @@ class Ast
 public:
     /** \brief Construct an Ast node.
     ** \param location scanner position informations */
-    Ast (const Location& location) : _location (location), decorator(), parent(NULL)
+    Ast (const Location& location) : decorator(), _location (location)
     {
         nodeNumber = globalNodeNumber++;
     }
index 86ca492..2a68639 100644 (file)
@@ -65,7 +65,7 @@ public :
     // insertion by value
     // _pArs is a list of scilab types:: of where we want to extract
     // _pSource is what we wan to insert
-    virtual InternalType*   insert(typed_list* /*_pArgs*/, InternalType* /*_pSource*/)
+    virtual InternalType* insert(typed_list* /*_pArgs*/, InternalType* /*_pSource*/)
     {
         return NULL;
     }
@@ -82,7 +82,7 @@ public :
     // _pArs is a list of scilab types:: of where we want to extract
     // return all element extracted, in case when multiple elements returned
     // these elements must be stored in a types::List
-    virtual InternalType*   extract(typed_list* /*_pArgs*/)
+    virtual InternalType* extract(typed_list* /*_pArgs*/)
     {
         return NULL;
     }
index 29e06a1..67b4e95 100644 (file)
@@ -14,6 +14,7 @@
 #define CONTROLLER_HXX_
 
 #include <vector>
+#include <map>
 
 #include "utilities.hxx"
 #include "Model.hxx"
@@ -94,6 +95,32 @@ private:
      * This will be allocated on-demand be Controller::get_instance()
      */
     static SharedData* _instance;
+
+    /*
+     * Methods
+     */
+
+    ScicosID cloneObject(std::map<ScicosID, ScicosID>& mapped, ScicosID uid);
+
+    template<typename T>
+    void cloneProperties(model::BaseObject* initial, ScicosID clone)
+    {
+        for (int i = 0; i < MAX_OBJECT_PROPERTIES; ++i)
+        {
+            enum object_properties_t p = static_cast<enum object_properties_t>(i);
+
+            T value;
+            bool status = getObjectProperty(initial->id(), initial->kind(), p, value);
+            if (status)
+            {
+                setObjectProperty(clone, initial->kind(), p, value);
+            }
+        }
+
+    };
+
+    void deepClone(std::map<ScicosID, ScicosID>& mapped, ScicosID uid, ScicosID clone, kind_t k, object_properties_t p, bool cloneIfNotFound);
+    void deepCloneVector(std::map<ScicosID, ScicosID>& mapped, ScicosID uid, ScicosID clone, kind_t k, object_properties_t p, bool cloneIfNotFound);
 };
 
 } /* namespace org_scilab_modules_scicos */
index 6806263..2adbc60 100644 (file)
@@ -57,7 +57,7 @@ types::InternalType * alloc_and_set(kind_t k, types::String* type_name, types::t
 
     // create the associated object
     ScicosID o = controller.createObject(k);
-    Adaptor* adaptor = new Adaptor(static_cast<Adaptee*>(controller.getObject(o)));
+    Adaptor* adaptor = new Adaptor(true, static_cast<Adaptee*>(controller.getObject(o)));
 
     // the first header entry is the type
     for (int i = 1; i < (int)in.size(); i++)
@@ -78,7 +78,7 @@ template<class Adaptor, class Adaptee>
 types::InternalType * alloc_and_set_as_mlist(types::String* type_name, types::typed_list &in)
 {
     // check header
-    Adaptor adaptor = Adaptor(0);
+    Adaptor adaptor = Adaptor(false, 0);
     for (int i = 1; i < (int)in.size(); i++)
     {
         std::wstring name(type_name->get(i));
index a4dfb46..57fea37 100644 (file)
@@ -22,7 +22,8 @@ namespace org_scilab_modules_scicos
 /*
  * Implement SharedData methods
  */
-Controller::SharedData::SharedData() : model(), allViews()
+Controller::SharedData::SharedData() :
+    model(), allViews()
 {
     LoggerView* v = new LoggerView();
     allViews.push_back(v);
@@ -104,8 +105,81 @@ ScicosID Controller::createObject(kind_t k)
     return id;
 }
 
+static void unlink_vector(Controller& controller, ScicosID uid, kind_t k, object_properties_t uid_prop, object_properties_t ref_prop)
+{
+    ScicosID v;
+    controller.getObjectProperty(uid, k, uid_prop, v);
+    if (v != 0)
+    {
+        model::BaseObject* o = controller.getObject(v);
+
+        std::vector<ScicosID> children;
+        controller.getObjectProperty(o->id(), o->kind(), ref_prop, children);
+
+        std::vector<ScicosID>::iterator it = std::find(children.begin(), children.end(), uid);
+        if (it != children.end())
+        {
+            children.erase(it);
+        }
+
+        controller.setObjectProperty(o->id(), o->kind(), ref_prop, children);
+    }
+}
+
+static void unlink(Controller& controller, ScicosID uid, kind_t k, object_properties_t uid_prop, object_properties_t ref_prop)
+{
+    ScicosID v;
+    controller.getObjectProperty(uid, k, uid_prop, v);
+    if (v != 0)
+    {
+        model::BaseObject* o = controller.getObject(v);
+        controller.setObjectProperty(o->id(), o->kind(), ref_prop, 0);
+    }
+}
+
 void Controller::deleteObject(ScicosID uid)
 {
+    // disconnect / remove references first
+    model::BaseObject* initial = getObject(uid);
+    const kind_t k = initial->kind();
+    if (k == ANNOTATION)
+    {
+        unlink_vector(*this, uid, k, PARENT_DIAGRAM, CHILDREN);
+        // RELATED_TO is not referenced back
+    }
+    else if (k == BLOCK)
+    {
+        unlink_vector(*this, uid, k, PARENT_DIAGRAM, CHILDREN);
+        // INPUTS will be removed on delete
+        // OUTPUTS will be removed on delete
+        // EVENT_INPUTS will be removed on delete
+        // EVENT_OUTPUTS will be removed on delete
+        unlink_vector(*this, uid, k, PARENT_BLOCK, CHILDREN);
+        // CHILDREN will be removed on delete
+        // FIXME what about REFERENCED_PORT ?
+    }
+    else if (k == DIAGRAM)
+    {
+        // CHILDREN will be removed on delete
+    }
+    else if (k == LINK)
+    {
+        unlink_vector(*this, uid, k, PARENT_DIAGRAM, CHILDREN);
+        unlink_vector(*this, uid, k, SOURCE_PORT, CONNECTED_SIGNALS);
+        unlink_vector(*this, uid, k, DESTINATION_PORT, CONNECTED_SIGNALS);
+    }
+    else if (k == PORT)
+    {
+        unlink(*this, uid, k, SOURCE_BLOCK, INPUTS);
+        unlink(*this, uid, k, SOURCE_BLOCK, OUTPUTS);
+        unlink(*this, uid, k, SOURCE_BLOCK, EVENT_INPUTS);
+        unlink(*this, uid, k, SOURCE_BLOCK, EVENT_OUTPUTS);
+
+        unlink(*this, uid, k, CONNECTED_SIGNALS, SOURCE_PORT);
+        unlink(*this, uid, k, CONNECTED_SIGNALS, DESTINATION_PORT);
+    }
+
+    // delete the object
     _instance->model.deleteObject(uid);
 
     for (view_set_t::iterator iter = _instance->allViews.begin(); iter != _instance->allViews.end(); ++iter)
@@ -114,40 +188,135 @@ void Controller::deleteObject(ScicosID uid)
     }
 }
 
-template<typename T>
-void cloneProperties(Controller* controller, model::BaseObject* initial, ScicosID clone)
+ScicosID Controller::cloneObject(std::map<ScicosID, ScicosID>& mapped, ScicosID uid)
+{
+    model::BaseObject* initial = getObject(uid);
+    const kind_t k = initial->kind();
+    ScicosID o = createObject(k);
+    mapped.insert(std::make_pair(uid, o));
+
+    // Get then set all properties per type that do not manage ScicosID
+    cloneProperties<double>(initial, o);
+    cloneProperties<int>(initial, o);
+    cloneProperties<bool>(initial, o);
+    cloneProperties<std::string>(initial, o);
+    cloneProperties<std::vector<double> >(initial, o);
+    cloneProperties<std::vector<int> >(initial, o);
+    cloneProperties<std::vector<std::string> >(initial, o);
+
+    // deep copy children, manage ScicosID and std::vector<ScicosID>
+    if (k == ANNOTATION)
+    {
+        deepClone(mapped, uid, o, k, PARENT_DIAGRAM, false);
+        deepClone(mapped, uid, o, k, RELATED_TO, true);
+    }
+    else if (k == BLOCK)
+    {
+        deepClone(mapped, uid, o, k, PARENT_DIAGRAM, false);
+        deepCloneVector(mapped, uid, o, k, INPUTS, true);
+        deepCloneVector(mapped, uid, o, k, OUTPUTS, true);
+        deepCloneVector(mapped, uid, o, k, EVENT_INPUTS, true);
+        deepCloneVector(mapped, uid, o, k, EVENT_OUTPUTS, true);
+        deepClone(mapped, uid, o, k, PARENT_BLOCK, false);
+        deepCloneVector(mapped, uid, o, k, CHILDREN, true);
+        // FIXME what about REFERENCED_PORT ?
+    }
+    else if (k == DIAGRAM)
+    {
+        deepCloneVector(mapped, uid, o, k, CHILDREN, true);
+    }
+    else if (k == LINK)
+    {
+        deepClone(mapped, uid, o, k, PARENT_DIAGRAM, false);
+        deepClone(mapped, uid, o, k, SOURCE_PORT, true);
+        deepClone(mapped, uid, o, k, DESTINATION_PORT, true);
+    }
+    else if (k == PORT)
+    {
+        deepClone(mapped, uid, o, k, SOURCE_BLOCK, true);
+        deepCloneVector(mapped, uid, o, k, CONNECTED_SIGNALS, true);
+    }
+
+    return o;
+}
+
+void Controller::deepClone(std::map<ScicosID, ScicosID>& mapped, ScicosID uid, ScicosID clone, kind_t k, object_properties_t p, bool cloneIfNotFound)
 {
-    for (int i = 0; i < MAX_OBJECT_PROPERTIES; ++i)
+    ScicosID v;
+    getObjectProperty(uid, k, p, v);
+
+    ScicosID cloned = 0;
+
+    std::map<ScicosID, ScicosID>::iterator it = mapped.find(v);
+    if (it != mapped.end())
     {
-        enum object_properties_t p = static_cast<enum object_properties_t>(i);
+        cloned = it->second;
+    }
+    else
+    {
+        if (cloneIfNotFound)
+        {
+            if (v != 0)
+            {
+                cloned = cloneObject(mapped, v);
+            }
+            else
+            {
+                cloned = 0;
+            }
+        }
+        else
+        {
+            cloned = 0;
+        }
+    }
+
+    setObjectProperty(clone, k, p, cloned);
+}
+
+void Controller::deepCloneVector(std::map<ScicosID, ScicosID>& mapped, ScicosID uid, ScicosID clone, kind_t k, object_properties_t p, bool cloneIfNotFound)
+{
+    std::vector<ScicosID> v;
+    getObjectProperty(uid, k, p, v);
+
+    std::vector<ScicosID> cloned;
+    cloned.reserve(v.size());
 
-        T value;
-        bool status = controller->getObjectProperty(initial->id(), initial->kind(), p, value);
-        if (status)
+    for (const ScicosID& id : v)
+    {
+
+        std::map<ScicosID, ScicosID>::iterator it = mapped.find(id);
+        if (it != mapped.end())
+        {
+            cloned.push_back(it->second);
+        }
+        else
         {
-            controller->setObjectProperty(clone, initial->kind(), p, value);
+            if (cloneIfNotFound)
+            {
+                if (id != 0)
+                {
+                    cloned.push_back(cloneObject(mapped, id));
+                }
+                else
+                {
+                    cloned.push_back(0);
+                }
+            }
+            else
+            {
+                cloned.push_back(0);
+            }
         }
     }
 
-};
+    setObjectProperty(clone, k, p, cloned);
+}
 
 ScicosID Controller::cloneObject(ScicosID uid)
 {
-    model::BaseObject* initial = getObject(uid);
-    ScicosID o = createObject(initial->kind());
-
-    // Get then set all properties per type
-    cloneProperties<double>(this, initial, o);
-    cloneProperties<int>(this, initial, o);
-    cloneProperties<bool>(this, initial, o);
-    cloneProperties<std::string>(this, initial, o);
-    cloneProperties<ScicosID>(this, initial, o);
-    cloneProperties< std::vector<double> >(this, initial, o);
-    cloneProperties< std::vector<int> >(this, initial, o);
-    cloneProperties< std::vector<std::string> >(this, initial, o);
-    cloneProperties< std::vector<ScicosID> >(this, initial, o);
-
-    return o;
+    std::map<ScicosID, ScicosID> mapped;
+    return cloneObject(mapped, uid);
 }
 
 model::BaseObject* Controller::getObject(ScicosID uid)
index fb0a63b..727ebff 100644 (file)
@@ -119,8 +119,8 @@ void Model::deleteObject(ScicosID uid)
         throw std::string("key has not been found");
     }
 
-    allObjects.erase(iter);
     delete iter->second;
+    allObjects.erase(iter);
 }
 
 model::BaseObject* Model::getObject(ScicosID uid) const
index c92fc09..8fe74ee 100644 (file)
@@ -315,6 +315,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, Sci
             case PARENT_DIAGRAM:
                 o->getParentDiagram(v);
                 return true;
+            case PARENT_BLOCK:
+                o->getParentBlock(v);
+                return true;
             default:
                 break;
         }
index 10b2319..9ebddc6 100644 (file)
@@ -302,14 +302,20 @@ private:
         this->parameter = parameter;
     }
 
-    ScicosID getParentBlock() const
+    void getParentBlock(ScicosID& v) const
     {
-        return parentBlock;
+        v = parentBlock;
     }
 
-    void setParentBlock(ScicosID parentBlock)
+    update_status_t setParentBlock(ScicosID parentBlock)
     {
+        if (parentBlock == this->parentBlock)
+        {
+            return NO_CHANGES;
+        }
+
         this->parentBlock = parentBlock;
+        return SUCCESS;
     }
 
     void getParentDiagram(ScicosID& v) const
index 3f64f94..67200b2 100644 (file)
@@ -99,9 +99,15 @@ class BaseAdapter : public types::UserType
 {
 
 public:
-    BaseAdapter(Adaptee* o) : adaptee(o) {};
-    BaseAdapter(const BaseAdapter& o) : adaptee(o.adaptee) {};
-    virtual ~BaseAdapter() {};
+    BaseAdapter(bool ownAdaptee, Adaptee* adaptee) : ownAdaptee(ownAdaptee), adaptee(adaptee) {};
+    virtual ~BaseAdapter()
+    {
+        if (ownAdaptee)
+        {
+            Controller controller;
+            controller.deleteObject(getAdaptee()->id());
+        }
+    };
 
     /*
      * property accessors
@@ -219,33 +225,22 @@ public:
     Adaptee* getAdaptee() const
     {
         return adaptee;
-    };
-
-    /**
-     * set the adaptee
-     */
-    void setAdaptee(Adaptee* adaptee)
-    {
-        this->adaptee = adaptee;
     }
 
     /*
      * All following methods should be implemented by each template instance
      */
 
-    std::wstring getTypeStr()
-    {
-        return L"ba";
-    }
+    virtual std::wstring getTypeStr() = 0;
+    virtual std::wstring getShortTypeStr() = 0;
 
-    std::wstring getShortTypeStr()
-    {
-        return L"BaseAdapter";
-    }
+private:
 
     types::InternalType* clone()
     {
-        return new Adaptor(*static_cast<Adaptor*>(this));
+        Controller controller = Controller();
+        ScicosID clone = controller.cloneObject(getAdaptee()->id());
+        return new Adaptor(false, static_cast<Adaptee*>(controller.getObject(clone)));
     }
 
     /*
@@ -306,6 +301,7 @@ public:
             {
                 types::String* pStr = (*_pArgs)[i]->getAs<types::String>();
                 std::wstring name = pStr->get(0);
+
                 Controller controller = Controller();
                 typename property<Adaptor>::props_t_it found = std::lower_bound(property<Adaptor>::fields.begin(), property<Adaptor>::fields.end(), name);
                 if (found != property<Adaptor>::fields.end() && !(name < found->name))
@@ -315,10 +311,6 @@ public:
 
                 return this;
             }
-            //else if(_pArgs[i]->isDouble())
-            //{
-            //
-            //}
             else
             {
                 return NULL;
@@ -355,6 +347,7 @@ public:
 
 
 private:
+    const bool ownAdaptee;
     Adaptee* adaptee;
 };
 
index 758f8fa..50afe48 100644 (file)
@@ -41,13 +41,13 @@ struct graphics
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
-        GraphicsAdapter localAdaptor = GraphicsAdapter(adaptor.getAdaptee());
+        GraphicsAdapter localAdaptor = GraphicsAdapter(false, adaptor.getAdaptee());
         return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        GraphicsAdapter localAdaptor = GraphicsAdapter(adaptor.getAdaptee());
+        GraphicsAdapter localAdaptor = GraphicsAdapter(false, adaptor.getAdaptee());
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -56,13 +56,13 @@ struct model
 {
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
-        ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
+        ModelAdapter localAdaptor = ModelAdapter(false, adaptor.getAdaptee());
         return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
+        ModelAdapter localAdaptor = ModelAdapter(false, adaptor.getAdaptee());
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -126,11 +126,8 @@ struct doc
 
 template<> property<BlockAdapter>::props_t property<BlockAdapter>::fields = property<BlockAdapter>::props_t();
 
-BlockAdapter::BlockAdapter(const BlockAdapter& o) :
-    BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(o), doc_content(o.doc_content->clone()) {}
-
-BlockAdapter::BlockAdapter(org_scilab_modules_scicos::model::Block* o) :
-    BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(o)
+BlockAdapter::BlockAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee) :
+    BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>(ownAdaptee, adaptee)
 {
     if (property<BlockAdapter>::properties_have_not_been_set())
     {
index 165a78a..45295e3 100644 (file)
@@ -27,9 +27,7 @@ namespace view_scilab
 class BlockAdapter : public BaseAdapter<BlockAdapter, org_scilab_modules_scicos::model::Block>
 {
 public:
-    BlockAdapter(const BlockAdapter& o);
-    BlockAdapter(org_scilab_modules_scicos::model::Block* o);
-    BlockAdapter(ScicosID uid, kind_t k);
+    BlockAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee);
     ~BlockAdapter();
 
     static const std::wstring getSharedTypeStr()
index 4bf052b..e80fcc7 100644 (file)
@@ -31,11 +31,8 @@ namespace
 
 template<> property<CprAdapter>::props_t property<CprAdapter>::fields = property<CprAdapter>::props_t();
 
-CprAdapter::CprAdapter(const CprAdapter& o) :
-    BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>(o) {}
-
-CprAdapter::CprAdapter(org_scilab_modules_scicos::model::Diagram* o) :
-    BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>(o)
+CprAdapter::CprAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
+    BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
 {
     if (property<CprAdapter>::properties_have_not_been_set())
     {
index 3e4812d..090acb0 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class CprAdapter : public BaseAdapter<CprAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    CprAdapter(const CprAdapter& o);
-    CprAdapter(org_scilab_modules_scicos::model::Diagram* o);
+    CprAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
     ~CprAdapter();
 
     static const std::wstring getSharedTypeStr()
index 6ce5353..59103c9 100644 (file)
@@ -49,13 +49,13 @@ struct props
 
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
-        ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
+        ParamsAdapter localAdaptor = ParamsAdapter(false, adaptor.getAdaptee());
         return localAdaptor.getAsTList(new types::TList(), controller);
     }
 
     static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
+        ParamsAdapter localAdaptor = ParamsAdapter(false, adaptor.getAdaptee());
         return localAdaptor.setAsTList(v, controller);
     }
 };
@@ -81,21 +81,21 @@ struct objs
                 case ANNOTATION:
                 {
                     model::Annotation* annotation = static_cast<model::Annotation*>(item);
-                    TextAdapter* localAdaptor = new TextAdapter(annotation);
+                    TextAdapter* localAdaptor = new TextAdapter(false, annotation);
                     o->set(i, localAdaptor);
                     continue;
                 }
                 case BLOCK:
                 {
                     model::Block* block = static_cast<model::Block*>(item);
-                    BlockAdapter* localAdaptor = new BlockAdapter(block);
+                    BlockAdapter* localAdaptor = new BlockAdapter(false, block);
                     o->set(i, localAdaptor);
                     continue;
                 }
                 case LINK:
                 {
                     model::Link* link = static_cast<model::Link*>(item);
-                    LinkAdapter* localAdaptor = new LinkAdapter(link);
+                    LinkAdapter* localAdaptor = new LinkAdapter(false, link);
                     o->set(i, localAdaptor);
                     continue;
                 }
@@ -138,7 +138,7 @@ struct objs
                     BlockAdapter* modelElement = list->get(i)->getAs<BlockAdapter>();
                     model::Block* subAdaptee = modelElement->getAdaptee();
 
-                    controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
+                    controller.setObjectProperty(id, subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
                     id = subAdaptee->id();
                     break;
                 }
@@ -249,14 +249,8 @@ struct contrib
 
 template<> property<DiagramAdapter>::props_t property<DiagramAdapter>::fields = property<DiagramAdapter>::props_t();
 
-DiagramAdapter::DiagramAdapter(const DiagramAdapter& o) :
-    BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(o)
-{
-    contrib_content = new types::List();
-}
-
-DiagramAdapter::DiagramAdapter(org_scilab_modules_scicos::model::Diagram* o) :
-    BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(o)
+DiagramAdapter::DiagramAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
+    BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
 {
     if (property<DiagramAdapter>::properties_have_not_been_set())
     {
index fd40c85..028eea8 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class DiagramAdapter : public BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    DiagramAdapter(const DiagramAdapter& o);
-    DiagramAdapter(org_scilab_modules_scicos::model::Diagram* o);
+    DiagramAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
     ~DiagramAdapter();
 
     static const std::wstring getSharedTypeStr()
index 3925f2f..e1f2d9b 100644 (file)
@@ -512,13 +512,8 @@ struct style
 
 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
 
-GraphicsAdapter::GraphicsAdapter(const GraphicsAdapter& o) :
-    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o),
-    gr_i_content(o.gr_i_content->clone())
-{}
-
-GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
-    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o)
+GraphicsAdapter::GraphicsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee) :
+    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(ownAdaptee, adaptee)
 {
     if (property<GraphicsAdapter>::properties_have_not_been_set())
     {
index 4700cab..19555fe 100644 (file)
@@ -26,8 +26,7 @@ namespace view_scilab
 class GraphicsAdapter : public BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>
 {
 public:
-    GraphicsAdapter(const GraphicsAdapter& o);
-    GraphicsAdapter(org_scilab_modules_scicos::model::Block* o);
+    GraphicsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee);
     ~GraphicsAdapter();
 
     static const std::wstring getSharedTypeStr()
index cc4f055..a38174f 100644 (file)
@@ -649,11 +649,8 @@ struct to
 
 template<> property<LinkAdapter>::props_t property<LinkAdapter>::fields = property<LinkAdapter>::props_t();
 
-LinkAdapter::LinkAdapter(const LinkAdapter& o) :
-    BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>(o) {}
-
-LinkAdapter::LinkAdapter(org_scilab_modules_scicos::model::Link* o) :
-    BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>(o)
+LinkAdapter::LinkAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Link* adaptee) :
+    BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>(ownAdaptee, adaptee)
 {
     if (property<LinkAdapter>::properties_have_not_been_set())
     {
index 040dc98..b25c006 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class LinkAdapter : public BaseAdapter<LinkAdapter, org_scilab_modules_scicos::model::Link>
 {
 public:
-    LinkAdapter(const LinkAdapter& o);
-    LinkAdapter(org_scilab_modules_scicos::model::Link* o);
+    LinkAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Link* adaptee);
     ~LinkAdapter();
 
     static const std::wstring getSharedTypeStr()
index de91f3f..e7ff406 100644 (file)
@@ -853,11 +853,8 @@ struct uid
 
 template<> property<ModelAdapter>::props_t property<ModelAdapter>::fields = property<ModelAdapter>::props_t();
 
-ModelAdapter::ModelAdapter(const ModelAdapter& o) :
-    BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(o) { }
-
-ModelAdapter::ModelAdapter(org_scilab_modules_scicos::model::Block* o) :
-    BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(o)
+ModelAdapter::ModelAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee) :
+    BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>(ownAdaptee, adaptee)
 {
     if (property<ModelAdapter>::properties_have_not_been_set())
     {
index 1961b15..e5856b8 100644 (file)
@@ -26,8 +26,7 @@ namespace view_scilab
 class ModelAdapter : public BaseAdapter<ModelAdapter, org_scilab_modules_scicos::model::Block>
 {
 public:
-    ModelAdapter(const ModelAdapter& o);
-    ModelAdapter(org_scilab_modules_scicos::model::Block* o);
+    ModelAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Block* adaptee);
     ~ModelAdapter();
 
     static const std::wstring getSharedTypeStr()
index 865b149..2d46589 100644 (file)
@@ -311,14 +311,8 @@ struct doc
 
 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
 
-ParamsAdapter::ParamsAdapter(const ParamsAdapter& o) :
-    BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(o)
-{
-    doc_content = new types::List();
-}
-
-ParamsAdapter::ParamsAdapter(org_scilab_modules_scicos::model::Diagram* o) :
-    BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(o)
+ParamsAdapter::ParamsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
+    BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
 {
     if (property<ParamsAdapter>::properties_have_not_been_set())
     {
index 8473533..1ae40e5 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class ParamsAdapter : public BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    ParamsAdapter(const ParamsAdapter& o);
-    ParamsAdapter(org_scilab_modules_scicos::model::Diagram* o);
+    ParamsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
     ~ParamsAdapter();
 
     static const std::wstring getSharedTypeStr()
index cb1485c..00f5523 100644 (file)
@@ -31,11 +31,8 @@ namespace
 
 template<> property<ScsAdapter>::props_t property<ScsAdapter>::fields = property<ScsAdapter>::props_t();
 
-ScsAdapter::ScsAdapter(const ScsAdapter& o) :
-    BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>(o) {}
-
-ScsAdapter::ScsAdapter(org_scilab_modules_scicos::model::Diagram* o) :
-    BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>(o)
+ScsAdapter::ScsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
+    BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
 {
     if (property<ScsAdapter>::properties_have_not_been_set())
     {
index a2852c9..37d026d 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class ScsAdapter : public BaseAdapter<ScsAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    ScsAdapter(const ScsAdapter& o);
-    ScsAdapter(org_scilab_modules_scicos::model::Diagram* o);
+    ScsAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
     ~ScsAdapter();
 
     static const std::wstring getSharedTypeStr()
index eb725cb..ad4184e 100644 (file)
@@ -31,11 +31,8 @@ namespace
 
 template<> property<StateAdapter>::props_t property<StateAdapter>::fields = property<StateAdapter>::props_t();
 
-StateAdapter::StateAdapter(const StateAdapter& o) :
-    BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>(o) {}
-
-StateAdapter::StateAdapter(org_scilab_modules_scicos::model::Diagram* o) :
-    BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>(o)
+StateAdapter::StateAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee) :
+    BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>(ownAdaptee, adaptee)
 {
     if (property<StateAdapter>::properties_have_not_been_set())
     {
index 0e347c5..d0df2ea 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class StateAdapter : public BaseAdapter<StateAdapter, org_scilab_modules_scicos::model::Diagram>
 {
 public:
-    StateAdapter(const StateAdapter& o);
-    StateAdapter(org_scilab_modules_scicos::model::Diagram* o);
+    StateAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Diagram* adaptee);
     ~StateAdapter();
 
     static const std::wstring getSharedTypeStr()
index a5121c5..846386e 100644 (file)
@@ -256,11 +256,8 @@ struct dummy_property
 
 template<> property<TextAdapter>::props_t property<TextAdapter>::fields = property<TextAdapter>::props_t();
 
-TextAdapter::TextAdapter(const TextAdapter& o) :
-    BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>(o) {}
-
-TextAdapter::TextAdapter(org_scilab_modules_scicos::model::Annotation* o) :
-    BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>(o)
+TextAdapter::TextAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Annotation* adaptee) :
+    BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>(ownAdaptee, adaptee)
 {
     if (property<TextAdapter>::properties_have_not_been_set())
     {
index 61f25d2..ed340a5 100644 (file)
@@ -27,8 +27,7 @@ namespace view_scilab
 class TextAdapter : public BaseAdapter<TextAdapter, org_scilab_modules_scicos::model::Annotation>
 {
 public:
-    TextAdapter(const TextAdapter& o);
-    TextAdapter(org_scilab_modules_scicos::model::Annotation* o);
+    TextAdapter(bool ownAdaptee, org_scilab_modules_scicos::model::Annotation* adaptee);
     ~TextAdapter();
 
     static const std::wstring getSharedTypeStr()
index 1217bd5..1b6edc6 100644 (file)
@@ -16,12 +16,15 @@ o = scicos_model()
 
 // allocate an Annotation
 o = TEXT_f("define");
+clear o;
 
 // allocate a Block
 o = scicos_block()
+clear o;
 
 // allocate a Link
 o = scicos_link()
+clear o;
 
 // allocate a Diagram
 scs_m = scicos_diagram()