Xcos MVC: implement params 'doc' / 'options" and slight fixes 26/15126/6
Paul Bignier [Thu, 28 Aug 2014 16:06:59 +0000 (18:06 +0200)]
Change-Id: Iaa75965e76fb67bc886d0d6aba829c2b4a4bf623

scilab/modules/scicos/src/cpp/model/Diagram.hxx
scilab/modules/scicos/src/cpp/view_scilab/BaseAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.hxx

index 60c7290..a1e8cea 100644 (file)
@@ -70,7 +70,7 @@ class Diagram: public BaseObject
 private:
     friend class ::org_scilab_modules_scicos::Model;
 
-    Diagram() : BaseObject(DIAGRAM), title(), path(), properties(), context() {};
+    Diagram() : BaseObject(DIAGRAM), title("Untitled"), path(), properties(), context() {};
     Diagram(const Diagram& o)  : BaseObject(DIAGRAM), title(o.title), path(o.path), properties(o.properties), context(o.context) {};
     ~Diagram() {}
 
index 220bf26..dfa67a9 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "user.hxx"
 #include "internal.hxx"
+#include "tlist.hxx"
 #include "mlist.hxx"
 #include "tlist.hxx"
 #include "string.hxx"
index f8f0966..fe4a25d 100644 (file)
 
 #include "double.hxx"
 #include "string.hxx"
-#include "types.hxx"
+#include "tlist.hxx"
 
+#include "Controller.hxx"
 #include "ParamsAdapter.hxx"
 
+extern "C" {
+#include "sci_malloc.h"
+}
+
 namespace org_scilab_modules_scicos
 {
 namespace view_scilab
@@ -27,6 +32,8 @@ namespace view_scilab
 namespace
 {
 
+static const wchar_t* scsopt = L"scsopt";
+
 struct wpar
 {
 
@@ -241,6 +248,42 @@ struct context
     }
 };
 
+struct options
+{
+
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        // Return a dummy 'scsopt'-typed tlist.
+        types::String* header = new types::String(scsopt);
+
+        types::TList* Scsopt = new types::TList();
+        Scsopt->set(0, header);
+        return Scsopt;
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        // The model does not store 'options'.
+        return true;
+    }
+};
+
+struct doc
+{
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        return adaptor.getDocContent();
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        adaptor.setDocContent(v->clone());
+        return true;
+    }
+};
+
 } /* namespace */
 
 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
@@ -260,15 +303,18 @@ ParamsAdapter::ParamsAdapter(org_scilab_modules_scicos::model::Diagram* o) :
         property<ParamsAdapter>::add_property(L"tf", &tf::get, &tf::set);
         property<ParamsAdapter>::add_property(L"context", &context::get, &context::set);
         property<ParamsAdapter>::add_property(L"void1", &wpar::get, &wpar::set);
-        property<ParamsAdapter>::add_property(L"options", &wpar::get, &wpar::set);
+        property<ParamsAdapter>::add_property(L"options", &options::get, &options::set);
         property<ParamsAdapter>::add_property(L"void2", &wpar::get, &wpar::set);
         property<ParamsAdapter>::add_property(L"void3", &wpar::get, &wpar::set);
-        property<ParamsAdapter>::add_property(L"doc", &wpar::get, &wpar::set);
+        property<ParamsAdapter>::add_property(L"doc", &doc::get, &doc::set);
     }
+
+    doc_content = new types::List();
 }
 
 ParamsAdapter::~ParamsAdapter()
 {
+    delete doc_content;
 }
 
 std::wstring ParamsAdapter::getTypeStr()
@@ -280,5 +326,16 @@ std::wstring ParamsAdapter::getShortTypeStr()
     return getSharedTypeStr();
 }
 
+types::InternalType* ParamsAdapter::getDocContent() const
+{
+    return doc_content;
+}
+
+void ParamsAdapter::setDocContent(types::InternalType* v)
+{
+    delete doc_content;
+    doc_content = v->clone();
+}
+
 } /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
index b04105b..8473533 100644 (file)
@@ -38,6 +38,11 @@ public:
 
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
+
+    types::InternalType* getDocContent() const;
+    void setDocContent(types::InternalType* v);
+private:
+    types::InternalType* doc_content;
 };
 
 } /* namespace view_scilab */