Xcos MVC: implement params wpar / title / tol / tf / context 25/15125/4
Paul Bignier [Thu, 28 Aug 2014 15:43:35 +0000 (17:43 +0200)]
Also, prepared the remaining properties for the test to pass.

Change-Id: Ib5b32fd24f68e5bbad308007f1e55d720d75e8ac

scilab/modules/scicos/includes/utilities.hxx
scilab/modules/scicos/src/cpp/LoggerView.cpp
scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/Model_setObjectProperties.cpp
scilab/modules/scicos/src/cpp/model/Diagram.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/DiagramAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/DiagramAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ParamsAdapter.cpp
scilab/modules/xcos/src/java/org/scilab/modules/xcos/ObjectProperties.java

index 69c54a0..1e4a439 100644 (file)
@@ -102,6 +102,10 @@ enum object_properties_t
     IMPLICIT,           //!< model::Port::implicit value
     PORT_NUMBER,        //!< model::Port::portNumber value
     CONNECTED_SIGNALS,  //!< model::Port::connectedSignals value
+    TITLE,              //!< model::Diagram::title file name value
+    PATH,               //!< model::Diagram::title file path value
+    PROPERTIES,         //!< model::Diagram::tol & tf values
+    CONTEXT,            //!< model::Diagram::context value
 };
 
 #endif /* UTILITIES_HXX_ */
index 8a2c07d..a636d40 100644 (file)
@@ -223,6 +223,18 @@ std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case CONNECTED_SIGNALS:
             os << "CONNECTED_SIGNALS";
             break;
+        case TITLE:
+            os << "TITLE";
+            break;
+        case PATH:
+            os << "PATH";
+            break;
+        case PROPERTIES:
+            os << "PROPERTIES";
+            break;
+        case CONTEXT:
+            os << "CONTEXT";
+            break;
     }
     return os;
 }
index d41b0cb..741245e 100644 (file)
@@ -247,6 +247,12 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
         switch (p)
         {
+            case TITLE:
+                o->getTitle(v);
+                return true;
+            case PATH:
+                o->getPath(v);
+                return true;
             default:
                 break;
         }
@@ -394,6 +400,14 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
     else if (k == DIAGRAM)
     {
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
+        switch (p)
+        {
+            case PROPERTIES:
+                o->getProperties(v);
+                return true;
+            default:
+                break;
+        }
     }
     else if (k == LINK)
     {
@@ -509,6 +523,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
         switch (p)
         {
+            case CONTEXT:
+                o->getContext(v);
+                return true;
             default:
                 break;
         }
index d91e23a..e02870b 100644 (file)
@@ -294,6 +294,10 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
         switch (p)
         {
+            case TITLE:
+                return o->setTitle(v);
+            case PATH:
+                return o->setPath(v);
             default:
                 break;
         }
@@ -363,6 +367,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
         switch (p)
         {
+            case PROPERTIES:
+                return o->setProperties(v);
             default:
                 break;
         }
@@ -477,6 +483,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Diagram* o = static_cast<model::Diagram*>(getObject(uid));
         switch (p)
         {
+            case CONTEXT:
+                return o->setContext(v);
             default:
                 break;
         }
index ad5491d..60c7290 100644 (file)
@@ -34,6 +34,35 @@ struct SimulationConfig
     double delta_h;             //!< Maximum step interval.
     double realtime_scale;      //!< Real-time scaling; the value 0 corresponds to no real-time scaling.
     double solver;              //!< Current numerical solver.
+
+    SimulationConfig() : final_time(100000), absolute_tolerance(1e-6), relative_tolerance(1e-6),
+        time_tolerance(1e-10), delta_t(final_time + 1), delta_h(0), realtime_scale(1), solver(0) {};
+
+    SimulationConfig(const SimulationConfig& p) :  final_time(p.final_time), absolute_tolerance(p.absolute_tolerance),
+        relative_tolerance(p.relative_tolerance), time_tolerance(p.time_tolerance), delta_t(p.delta_t),
+        delta_h(p.delta_h), realtime_scale(p.realtime_scale), solver(p.solver) {};
+
+    SimulationConfig(const std::vector<double>& p) : final_time(p[0]), absolute_tolerance(p[1]), relative_tolerance(p[2]),
+        time_tolerance(p[3]), delta_t(p[4]), delta_h(p[5]), realtime_scale(p[6]), solver(p[7]) {};
+
+    void fill(std::vector<double>& p) const
+    {
+        p.resize(8);
+        p[0] = final_time;
+        p[1] = absolute_tolerance;
+        p[2] = relative_tolerance;
+        p[3] = time_tolerance;
+        p[4] = delta_t;
+        p[5] = delta_h;
+        p[6] = realtime_scale;
+        p[7] = solver;
+    }
+    bool operator==(const SimulationConfig& p) const
+    {
+        return final_time == p.final_time && absolute_tolerance == p.absolute_tolerance &&
+               relative_tolerance == p.relative_tolerance && time_tolerance == p.time_tolerance &&
+               delta_t == p.delta_t && delta_h == p.delta_h && realtime_scale == p.realtime_scale && solver == p.solver;
+    }
 };
 
 class Diagram: public BaseObject
@@ -41,8 +70,8 @@ class Diagram: public BaseObject
 private:
     friend class ::org_scilab_modules_scicos::Model;
 
-    Diagram() : BaseObject(DIAGRAM) {};
-    Diagram(const Diagram& o)  : BaseObject(DIAGRAM) {};
+    Diagram() : BaseObject(DIAGRAM), title(), path(), properties(), context() {};
+    Diagram(const Diagram& o)  : BaseObject(DIAGRAM), title(o.title), path(o.path), properties(o.properties), context(o.context) {};
     ~Diagram() {}
 
     const std::vector<ScicosID>& getChildren() const
@@ -55,14 +84,20 @@ private:
         this->children = children;
     }
 
-    const std::vector<std::string>& getContext() const
+    void getContext(std::vector<std::string>& data) const
     {
-        return context;
+        data = context;
     }
 
-    void setContext(const std::vector<std::string>& context)
+    update_status_t setContext(const std::vector<std::string>& data)
     {
-        this->context = context;
+        if (data == context)
+        {
+            return NO_CHANGES;
+        }
+
+        context = data;
+        return SUCCESS;
     }
 
     const std::vector<Datatype*>& getDatatypes() const
@@ -75,24 +110,58 @@ private:
         this->datatypes = datatypes;
     }
 
-    const SimulationConfig& getProperties() const
+    void getProperties(std::vector<double>& v) const
     {
-        return properties;
+        properties.fill(v);
     }
 
-    void setProperties(const SimulationConfig& properties)
+    update_status_t setProperties(const std::vector<double>& v)
     {
-        this->properties = properties;
+        if (v.size() != 8)
+        {
+            return FAIL;
+        }
+
+        SimulationConfig p = SimulationConfig(v);
+        if (p == properties)
+        {
+            return NO_CHANGES;
+        }
+
+        properties = p;
+        return SUCCESS;
     }
 
-    const std::string& getTitle() const
+    void getTitle(std::string& data) const
     {
-        return title;
+        data = title;
     }
 
-    void setTitle(const std::string& title)
+    update_status_t setTitle(const std::string& data)
     {
-        this->title = title;
+        if (data == title)
+        {
+            return NO_CHANGES;
+        }
+
+        title = data;
+        return SUCCESS;
+    }
+
+    void getPath(std::string& data) const
+    {
+        data = path;
+    }
+
+    update_status_t setPath(const std::string& data)
+    {
+        if (data == path)
+        {
+            return NO_CHANGES;
+        }
+
+        path = data;
+        return SUCCESS;
     }
 
     const std::string& getVersion() const
@@ -107,6 +176,7 @@ private:
 
 private:
     std::string title;
+    std::string path;
     SimulationConfig properties;
     std::vector<std::string> context;
 
index c0430db..220bf26 100644 (file)
@@ -21,6 +21,7 @@
 #include "user.hxx"
 #include "internal.hxx"
 #include "mlist.hxx"
+#include "tlist.hxx"
 #include "string.hxx"
 
 #include "Controller.hxx"
@@ -133,13 +134,11 @@ public:
     }
 
     /**
-     * property as MList accessors
+     * property as TList accessors
      */
 
-    types::InternalType* getAsMList(const Controller& controller)
+    types::InternalType* getAsTList(types::TList* tlist, const Controller& controller)
     {
-        types::MList* mlist = new types::MList();
-
         typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
         std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
 
@@ -151,28 +150,28 @@ public:
         {
             header->set(index, it->name.c_str());
         }
-        mlist->set(0, header);
+        tlist->set(0, header);
 
-        // set the mlist field value
+        // set the tlist field value
         index = 1;
         for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it, ++index)
         {
-            mlist->set(index, it->get(*static_cast<Adaptor*>(this), controller));
+            tlist->set(index, it->get(*static_cast<Adaptor*>(this), controller));
         }
 
-        return mlist;
+        return tlist;
     }
 
-    bool setAsMList(types::InternalType* v, Controller& controller)
+    bool setAsTList(types::InternalType* v, Controller& controller)
     {
         typename property<Adaptor>::props_t properties = property<Adaptor>::fields;
         std::sort(properties.begin(), properties.end(), property<Adaptor>::original_index_cmp);
 
-        if (v->getType() != types::InternalType::ScilabMList)
+        if (v->getType() != types::InternalType::ScilabTList)
         {
             return false;
         }
-        types::MList* current = v->getAs<types::MList>();
+        types::TList* current = v->getAs<types::TList>();
         if (current->getSize() != static_cast<int>(1 + properties.size()))
         {
             return false;
@@ -197,7 +196,7 @@ public:
             }
         }
 
-        // this is a valid mlist, get each mlist field value and pass it to the right property decoder
+        // this is a valid tlist, get each tlist field value and pass it to the right property decoder
         index = 1;
         for (typename property<Adaptor>::props_t_it it = properties.begin(); it != properties.end(); ++it, ++index)
         {
index 58a7f82..7db953e 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "internal.hxx"
 #include "list.hxx"
+#include "mlist.hxx"
 #include "string.hxx"
 #include "types.hxx"
 #include "user.hxx"
@@ -41,13 +42,13 @@ struct graphics
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         GraphicsAdapter localAdaptor = GraphicsAdapter(adaptor.getAdaptee());
-        return localAdaptor.getAsMList(controller);
+        return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         GraphicsAdapter localAdaptor = GraphicsAdapter(adaptor.getAdaptee());
-        return localAdaptor.setAsMList(v, controller);
+        return localAdaptor.setAsTList(v, controller);
     }
 };
 
@@ -56,13 +57,13 @@ struct model
     static types::InternalType* get(const BlockAdapter& adaptor, const Controller& controller)
     {
         ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
-        return localAdaptor.getAsMList(controller);
+        return localAdaptor.getAsTList(new types::MList(), controller);
     }
 
     static bool set(BlockAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
         ModelAdapter localAdaptor = ModelAdapter(adaptor.getAdaptee());
-        return localAdaptor.setAsMList(v, controller);
+        return localAdaptor.setAsTList(v, controller);
     }
 };
 
index c97349a..2c7d9ce 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "internal.hxx"
 #include "list.hxx"
+#include "tlist.hxx"
 #include "string.hxx"
 #include "types.hxx"
 #include "user.hxx"
@@ -39,20 +40,14 @@ struct props
 
     static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
     {
-
-        return new ParamsAdapter(adaptor.getAdaptee());
+        ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
+        return localAdaptor.getAsTList(new types::TList(), controller);
     }
 
     static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        if (v->getType() == types::InternalType::ScilabUserType
-                && v->getShortTypeStr() == ParamsAdapter::getSharedTypeStr())
-        {
-            ParamsAdapter* props = v->getAs<ParamsAdapter>();
-            adaptor.setAdaptee(props->getAdaptee());
-            return true;
-        }
-        return false;
+        ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
+        return localAdaptor.setAsTList(v, controller);
     }
 };
 
index 9d421eb..7bf4ebc 100644 (file)
@@ -33,7 +33,7 @@ public:
 
     static const std::wstring getSharedTypeStr()
     {
-        return L"Diagram";
+        return L"diagram";
     }
 
     std::wstring getTypeStr();
index 3fd2619..f8f0966 100644 (file)
  *
  */
 
+#include <string>
+#include <vector>
+#include <algorithm>
+
+#include "double.hxx"
+#include "string.hxx"
+#include "types.hxx"
+
 #include "ParamsAdapter.hxx"
 
 namespace org_scilab_modules_scicos
@@ -19,6 +27,220 @@ namespace view_scilab
 namespace
 {
 
+struct wpar
+{
+
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        return 0;
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        // The model does not stock wpar.
+        return true;
+    }
+};
+
+struct title
+{
+
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        std::string title;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
+        std::string path;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
+
+        types::String* o = new types::String(2, 1);
+        o->set(0, title.data());
+        o->set(1, path.data());
+
+        return o;
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        if (v->getType() != types::InternalType::ScilabString)
+        {
+            return false;
+        }
+
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        std::string path;
+        std::string title;
+        types::String* current = v->getAs<types::String>();
+        if (current->getSize() == 1)
+        {
+            // Pass an empty path
+        }
+        else if (current->getSize() == 2)
+        {
+            char* Path = wide_string_to_UTF8(current->get(1));
+            title = std::string(Path);
+            FREE(Path);
+        }
+        else
+        {
+            return false;
+        }
+
+        char* Title = wide_string_to_UTF8(current->get(0));
+        title = std::string(Title);
+        FREE(Title);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
+        return true;
+    }
+};
+
+struct tol
+{
+
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        double* data;
+        types::Double* o = new types::Double(7, 1, &data);
+
+        std::vector<double> tol;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+
+        std::copy(tol.begin() + 1, tol.end(), data);
+
+        return o;
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+
+        if (v->getType() != types::InternalType::ScilabDouble)
+        {
+            return false;
+        }
+
+        types::Double* current = v->getAs<types::Double>();
+        if (current->getSize() != 7)
+        {
+            return false;
+        }
+
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        std::vector<double> tol;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+
+        std::copy(current->getReal(), current->getReal() + current->getSize(), tol.begin() + 1);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        return true;
+    }
+};
+
+struct tf
+{
+
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        std::vector<double> tf;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tf);
+
+        return new types::Double(tf[0]);
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+
+        if (v->getType() != types::InternalType::ScilabDouble)
+        {
+            return false;
+        }
+
+        types::Double* current = v->getAs<types::Double>();
+        if (current->getSize() != 1)
+        {
+            return false;
+        }
+
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        std::vector<double> tol;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+
+        tol[0] = current->get(0);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
+        return true;
+    }
+};
+
+struct context
+{
+
+    static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
+    {
+        model::Diagram* adaptee = adaptor.getAdaptee();
+
+        std::vector<std::string> context;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
+
+        types::String* o = new types::String(context.size(), 1);
+        for (size_t i = 0; i < context.size(); ++i)
+        {
+            o->set(i, context[i].data());
+        }
+
+        return o;
+    }
+
+    static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        if (v->getType() == types::InternalType::ScilabString)
+        {
+            types::String* current = v->getAs<types::String>();
+            if (current->getCols() != 0 && current->getCols() != 1)
+            {
+                return false;
+            }
+
+            model::Diagram* adaptee = adaptor.getAdaptee();
+
+            std::vector<std::string> context (current->getSize());
+            for (size_t i = 0; i < context.size(); ++i)
+            {
+                char* c_str = wide_string_to_UTF8(current->get(i));
+                context[i] = std::string(c_str);
+                FREE(c_str);
+            }
+
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
+            return true;
+        }
+        else if (v->getType() == types::InternalType::ScilabDouble)
+        {
+            types::Double* current = v->getAs<types::Double>();
+            if (current->getRows() != 0 || current->getCols() != 0)
+            {
+                return false;
+            }
+
+            model::Diagram* adaptee = adaptor.getAdaptee();
+
+            std::vector<std::string> context;
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
+            return true;
+        }
+        return false;
+    }
+};
+
 } /* namespace */
 
 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
@@ -31,7 +253,17 @@ ParamsAdapter::ParamsAdapter(org_scilab_modules_scicos::model::Diagram* o) :
 {
     if (property<ParamsAdapter>::properties_have_not_been_set())
     {
-        // FIXME: add some properties
+        property<ParamsAdapter>::fields.reserve(10);
+        property<ParamsAdapter>::add_property(L"wpar", &wpar::get, &wpar::set);
+        property<ParamsAdapter>::add_property(L"title", &title::get, &title::set);
+        property<ParamsAdapter>::add_property(L"tol", &tol::get, &tol::set);
+        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"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);
     }
 }
 
index 233046a..e19d81a 100644 (file)
@@ -57,6 +57,10 @@ public enum ObjectProperties {
   PORT_KIND,
   IMPLICIT,
   PORT_NUMBER,
-  CONNECTED_SIGNALS;
+  CONNECTED_SIGNALS,
+  TITLE,
+  PATH,
+  PROPERTIES,
+  CONTEXT;
 }