Xcos MVC: implement rpar / ipar / uid 73/14973/4
Paul Bignier [Mon, 4 Aug 2014 13:56:53 +0000 (15:56 +0200)]
Also, laid the groundwork for the 'opar' and 'equations' properties.

Change-Id: I4257d54c72a1c8c634910eff07ddc8894927c3a8

scilab/modules/scicos/includes/utilities.hxx
scilab/modules/scicos/src/cpp/LoggerView.cpp
scilab/modules/scicos/src/cpp/Model.cpp
scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/Model_setObjectProperties.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/GraphicsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.hxx
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.hxx

index 2f05542..a17c34b 100644 (file)
@@ -74,6 +74,11 @@ enum object_properties_t
     ODSTATE,            //!< model::Block::odstate value
     NZCROSS,            //!< model::Block::nzcross value
     NMODE,              //!< model::Block::nmode value
+    RPAR,               //!< model::Block::rpar value
+    IPAR,               //!< model::Block::ipar value
+    OPAR,               //!< model::Block::opar value
+    EQUATIONS,          //!< model::Block::equations value
+    UID,                //!< model::Block::uid value
     PARENT_BLOCK,       //!< model::Block::parentBlock value
     CHILDREN,           //!< model::Block::children for superblocks or model::Diagram::children value
     PORT_REFERENCE,     //!< model::Block::portReference value
index 0d92758..ae2bffd 100644 (file)
@@ -139,6 +139,21 @@ std::ostream& operator<<(std::ostream& os, object_properties_t p)
             break;
         case NMODE:
             os << "NMODE";
+            break;;
+        case RPAR:
+            os << "RPAR";
+            break;
+        case IPAR:
+            os << "IPAR";
+            break;
+        case OPAR:
+            os << "OPAR";
+            break;
+        case EQUATIONS:
+            os << "EQUATIONS";
+            break;
+        case UID:
+            os << "UID";
             break;
         case PARENT_BLOCK:
             os << "PARENT_BLOCK";
index 51bdf3e..2772d4c 100644 (file)
@@ -10,6 +10,7 @@
  *
  */
 
+#include <utility>
 #include <algorithm>
 
 #include "Model.hxx"
index e1effc0..0c77548 100644 (file)
@@ -223,6 +223,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case LABEL:
                 o->getLabel(v);
                 return true;
+            case UID:
+                o->getUID(v);
+                return true;
             default:
                 break;
         }
@@ -366,6 +369,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case DSTATE:
                 o->getDState(v);
                 return true;
+            case RPAR:
+                o->getRpar(v);
+                return true;
             default:
                 break;
         }
@@ -408,6 +414,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case SIM_DEP_UT:
                 o->getSimDepUT(v);
                 return true;
+            case IPAR:
+                o->getIpar(v);
+                return true;
             default:
                 break;
         }
@@ -528,6 +537,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case EVENT_OUTPUTS:
                 o->getEout(v);
                 return true;
+            case CHILDREN:
+                o->getChildren(v);
+                return true;
             default:
                 break;
         }
index b1f1695..a345e4d 100644 (file)
@@ -10,6 +10,9 @@
  *
  */
 
+#include <string>
+#include <vector>
+
 #include "Model.hxx"
 #include "utilities.hxx"
 
@@ -264,6 +267,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
                 return o->setStyle(v);
             case LABEL:
                 return o->setLabel(v);
+            case UID:
+                return o->setUID(v);
             default:
                 break;
         }
@@ -329,6 +334,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
                 return o->setState(v);
             case DSTATE:
                 return o->setDState(v);
+            case RPAR:
+                return o->setRpar(v);
             default:
                 break;
         }
@@ -382,6 +389,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         {
             case SIM_DEP_UT:
                 return o->setSimDepUT(v);
+            case IPAR:
+                return o->setIpar(v);
             default:
                 break;
         }
index 37d6d03..ef8e75f 100644 (file)
@@ -15,8 +15,6 @@
 
 #include <string>
 #include <vector>
-#include <bitset>
-#include <utility>
 
 #include "Model.hxx"
 #include "model/BaseObject.hxx"
@@ -120,16 +118,17 @@ private:
 
 private:
     Block() : BaseObject(BLOCK), parentDiagram(0), interfaceFunction(), geometry(),
-        angle(), exprs(), label(), style(), nzcross(0), nmode(0), sim(), in(), out(), ein(), eout(),
+        angle(), exprs(), label(), style(), nzcross(0), nmode(0), equations(), uid(), sim(), in(), out(), ein(), eout(),
         parameter(), state(), parentBlock(0), children(), portReference(0) {};
     Block(const Block& o) : BaseObject(BLOCK), parentDiagram(o.parentDiagram), interfaceFunction(o.interfaceFunction), geometry(o.geometry),
-        angle(o.angle), exprs(o.exprs), label(o.label), style(o.style), nzcross(o.nzcross), nmode(o.nmode), sim(o.sim), in(o.in), out(o.out), ein(o.ein), eout(o.eout),
-        parameter(o.parameter), state(o.state), parentBlock(o.parentBlock), children(o.children), portReference(o.portReference) {};
+        angle(o.angle), exprs(o.exprs), label(o.label), style(o.style), nzcross(o.nzcross), nmode(o.nmode), equations(o.equations), uid(o.uid),
+        sim(o.sim), in(o.in), out(o.out), ein(o.ein), eout(o.eout), parameter(o.parameter), state(o.state), parentBlock(o.parentBlock),
+        children(o.children), portReference(o.portReference) {};
     ~Block() {}
 
-    const std::vector<ScicosID>& getChildren() const
+    void getChildren(std::vector<ScicosID>& c) const
     {
-        return children;
+        c = children;
     }
 
     void setChildren(const std::vector<ScicosID>& children)
@@ -381,6 +380,54 @@ private:
         return SUCCESS;
     }
 
+    void getUID(std::string& data) const
+    {
+        data = uid;
+    }
+
+    update_status_t setUID(const std::string& data)
+    {
+        if (data == uid)
+        {
+            return NO_CHANGES;
+        }
+
+        uid = data;
+        return SUCCESS;
+    }
+
+    void getRpar(std::vector<double>& data) const
+    {
+        data = parameter.rpar;
+    }
+
+    update_status_t setRpar(const std::vector<double>& data)
+    {
+        if (data == parameter.rpar)
+        {
+            return NO_CHANGES;
+        }
+
+        parameter.rpar = data;
+        return SUCCESS;
+    }
+
+    void getIpar(std::vector<int>& data) const
+    {
+        data = parameter.ipar;
+    }
+
+    update_status_t setIpar(const std::vector<int>& data)
+    {
+        if (data == parameter.ipar)
+        {
+            return NO_CHANGES;
+        }
+
+        parameter.ipar = data;
+        return SUCCESS;
+    }
+
     void getSimFunctionName(std::string& data) const
     {
         data = sim.functionName;
@@ -538,6 +585,9 @@ private:
     std::string style;
     int nzcross;
     int nmode;
+    // FIXME: find an appropriate way to store 'equations'
+    std::vector<std::string> equations;
+    std::string uid;
 
     Descriptor sim;
 
index 4d84b0d..8a02bf1 100644 (file)
@@ -15,8 +15,7 @@
 
 #include <algorithm>
 #include <string>
-#include <utility>
-#include <iostream>
+#include <sstream>
 
 #include "user.hxx"
 #include "internal.hxx"
index ee28012..e8f4781 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <string>
 #include <vector>
-#include <cassert>
+#include <sstream>
 
 #include "list.hxx"
 #include "double.hxx"
index 70a543e..b921954 100644 (file)
 #ifndef GRAPHICSADAPTER_HXX_
 #define GRAPHICSADAPTER_HXX_
 
-#include <sstream>
 #include <string>
-#include <vector>
-#include <utility>
+#include <sstream>
 
 #include "BaseAdapter.hxx"
 #include "model/Block.hxx"
index ba15da6..ac563ce 100644 (file)
 #include <string>
 #include <vector>
 #include <algorithm>
+#include <sstream>
 
 #include "list.hxx"
+#include "mlist.hxx"
 #include "double.hxx"
 #include "string.hxx"
 
@@ -29,6 +31,8 @@ namespace view_scilab
 namespace
 {
 
+static const wchar_t* diagram = L"diagram";
+
 struct sim
 {
 
@@ -353,6 +357,152 @@ struct odstate
     }
 };
 
+struct rpar
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<ScicosID> children;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
+
+        if (children.empty())
+        {
+            std::vector<double> rpar;
+            controller.getObjectProperty(adaptee->id(), adaptee->kind(), RPAR, rpar);
+
+            double *data;
+            types::Double* o = new types::Double(rpar.size(), 1, &data);
+            std::copy(rpar.begin(), rpar.end(), data);
+
+            return o;
+        }
+        else
+        {
+            types::MList* o = new types::MList();
+            types::String* Diagram = new types::String(1, 1);
+            Diagram->set(0, diagram);
+            o->set(0, Diagram);
+
+            // FIXME: return the full diagram contained in children
+            return o;
+        }
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        if (v->getType() == types::InternalType::ScilabDouble)
+        {
+            types::Double* current = v->getAs<types::Double>();
+            if (current->getCols() != 0 && current->getCols() != 1)
+            {
+                return false;
+            }
+
+            std::vector<double> rpar (current->getSize());
+            for (int i = 0; i < current->getSize(); ++i)
+            {
+                rpar[i] = current->get(i);
+            }
+
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), RPAR, rpar);
+            return true;
+        }
+        else
+        {
+            // FIXME: set rpar when input is a diagram (MList)
+            return false;
+        }
+    }
+};
+
+static double toDouble(const int a)
+{
+    return static_cast<double>(a);
+}
+
+struct ipar
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<int> ipar;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), IPAR, ipar);
+
+        double *data;
+        types::Double* o = new types::Double(ipar.size(), 1, &data);
+
+        std::transform(ipar.begin(), ipar.end(), data, toDouble);
+
+        return o;
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+
+        if (v->getType() != types::InternalType::ScilabDouble)
+        {
+            return false;
+        }
+
+        types::Double* current = v->getAs<types::Double>();
+        if (current->getCols() != 0 && current->getCols() != 1)
+        {
+            return false;
+        }
+
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<int> ipar (current->getSize());
+        for (int i = 0; i < current->getSize(); ++i)
+        {
+            if (floor(current->get(i)) != current->get(i))
+            {
+                return false;
+            }
+            ipar[i] = static_cast<int>(current->get(i));
+        }
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), IPAR, ipar);
+        return true;
+    }
+};
+
+struct opar
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        // FIXME: get opar
+        return 0;
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        if (v->getType() != types::InternalType::ScilabList)
+        {
+            return false;
+        }
+
+        types::List* current = v->getAs<types::List>();
+
+        if (current->getSize() == 0)
+        {
+            return true;
+        }
+        else
+        {
+            // FIXME: get the input list and store it in the opar field
+            return false;
+        }
+    }
+};
+
 struct blocktype
 {
 
@@ -582,6 +732,77 @@ struct nmode
     }
 };
 
+struct equations
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        // FIXME: get equations
+        return 0;
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        if (v->getType() != types::InternalType::ScilabList)
+        {
+            return false;
+        }
+
+        types::List* current = v->getAs<types::List>();
+
+        if (current->getSize() == 0)
+        {
+            return true;
+        }
+        else
+        {
+            // FIXME: get the input list and store it in the equations field
+            return false;
+        }
+    }
+};
+
+struct uid
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::string uid;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), UID, uid);
+
+        types::String* o = new types::String(1, 1);
+        o->set(0, uid.data());
+
+        return o;
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        if (v->getType() != types::InternalType::ScilabString)
+        {
+            return false;
+        }
+
+        types::String* current = v->getAs<types::String>();
+        if (current->getSize() != 1)
+        {
+            return false;
+        }
+
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::string uid;
+        char* c_str = wide_string_to_UTF8(current->get(0));
+        uid = std::string(c_str);
+        FREE(c_str);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), UID, uid);
+        return true;
+    }
+};
+
 } /* namespace */
 
 template<> property<ModelAdapter>::props_t property<ModelAdapter>::fields = property<ModelAdapter>::props_t();
@@ -594,7 +815,7 @@ ModelAdapter::ModelAdapter(org_scilab_modules_scicos::model::Block* o) :
 {
     if (property<ModelAdapter>::properties_has_not_been_set())
     {
-        property<ModelAdapter>::fields.reserve(18);
+        property<ModelAdapter>::fields.reserve(23);
         property<ModelAdapter>::add_property(L"sim", &sim::get, &sim::set);
         property<ModelAdapter>::add_property(L"in", &in::get, &in::set);
         property<ModelAdapter>::add_property(L"in2", &in2::get, &in2::set);
@@ -607,12 +828,17 @@ ModelAdapter::ModelAdapter(org_scilab_modules_scicos::model::Block* o) :
         property<ModelAdapter>::add_property(L"state", &state::get, &state::set);
         property<ModelAdapter>::add_property(L"dstate", &dstate::get, &dstate::set);
         property<ModelAdapter>::add_property(L"odstate", &odstate::get, &odstate::set);
+        property<ModelAdapter>::add_property(L"rpar", &rpar::get, &rpar::set);
+        property<ModelAdapter>::add_property(L"ipar", &ipar::get, &ipar::set);
+        property<ModelAdapter>::add_property(L"opar", &opar::get, &opar::set);
         property<ModelAdapter>::add_property(L"blocktype", &blocktype::get, &blocktype::set);
         property<ModelAdapter>::add_property(L"firing", &firing::get, &firing::set);
         property<ModelAdapter>::add_property(L"dep_ut", &dep_ut::get, &dep_ut::set);
         property<ModelAdapter>::add_property(L"label", &label::get, &label::set);
         property<ModelAdapter>::add_property(L"nzcross", &nzcross::get, &nzcross::set);
         property<ModelAdapter>::add_property(L"nmode", &nmode::get, &nmode::set);
+        property<ModelAdapter>::add_property(L"equations", &equations::get, &equations::set);
+        property<ModelAdapter>::add_property(L"uid", &uid::get, &uid::set);
     }
 }
 
index 3dcb0de..0a51508 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 
 #include "BaseAdapter.hxx"
-
 #include "model/Block.hxx"
 
 namespace org_scilab_modules_scicos