Xcos MVC: implement firing / dep_ut / label / nzcross / nmode 69/14969/8
Paul Bignier [Fri, 1 Aug 2014 13:42:59 +0000 (15:42 +0200)]
Change-Id: I195dc8cb4ce43bb2ae867f3bb41c942f1e3aa458

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/Block.hxx
scilab/modules/scicos/src/cpp/model/Port.hxx
scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ModelAdapter.cpp
scilab/modules/scicos/src/cpp/view_scilab/ports_management.hxx

index a755397..2f05542 100644 (file)
@@ -62,6 +62,7 @@ enum object_properties_t
     SIM_FUNCTION_API,   //!< model::Descriptor::functionApi value (stored into model::Block::sim)
     SIM_SCHEDULE,       //!< model::Descriptor::schedulingProperties value (stored into model::Block::sim)
     SIM_BLOCKTYPE,      //!< model::Descriptor::blocktype value (stored into model::Block::sim)
+    SIM_DEP_UT,         //!< model::Descriptor::dep_ut value (stored into model::Block::sim)
     ANGLE,              //!< model::Block::flip and theta values
     EXPRS,              //!< model::Block::exprs value
     INPUTS,             //!< model::Block::in value
@@ -71,6 +72,8 @@ enum object_properties_t
     STATE,              //!< model::Block::state value
     DSTATE,             //!< model::Block::dstate value
     ODSTATE,            //!< model::Block::odstate value
+    NZCROSS,            //!< model::Block::nzcross value
+    NMODE,              //!< model::Block::nmode value
     PARENT_BLOCK,       //!< model::Block::parentBlock value
     CHILDREN,           //!< model::Block::children for superblocks or model::Diagram::children value
     PORT_REFERENCE,     //!< model::Block::portReference value
@@ -83,6 +86,7 @@ enum object_properties_t
     DATATYPE_ROWS,      //!< model::Port::dataType adapter helper
     DATATYPE_COLS,      //!< model::Port::dataType adapter helper
     DATATYPE_TYPE,      //!< model::Port::dataType adapter helper
+    FIRING,             //!< model::Port::firing value
     SOURCE_BLOCK,       //!< model::Port::sourceBlock value
     PORT_KIND,          //!< model::Port::kind value
     IMPLICIT,           //!< model::Port::implicit value
index dc5c138..0d92758 100644 (file)
@@ -104,6 +104,9 @@ std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case SIM_BLOCKTYPE:
             os << "SIM_BLOCKTYPE";
             break;
+        case SIM_DEP_UT:
+            os << "SIM_DEP_UT";
+            break;
         case ANGLE:
             os << "ANGLE";
             break;
@@ -131,6 +134,12 @@ std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case ODSTATE:
             os << "ODSTATE";
             break;
+        case NZCROSS:
+            os << "NZCROSS";
+            break;
+        case NMODE:
+            os << "NMODE";
+            break;
         case PARENT_BLOCK:
             os << "PARENT_BLOCK";
             break;
@@ -167,6 +176,9 @@ std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case DATATYPE_TYPE:
             os << "DATATYPE_TYPE";
             break;
+        case FIRING:
+            os << "FIRING";
+            break;
         case SOURCE_BLOCK:
             os << "SOURCE_BLOCK";
             break;
index 0ef0b3c..e1effc0 100644 (file)
@@ -70,6 +70,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, dou
         model::Port* o = static_cast<model::Port*>(getObject(uid));
         switch (p)
         {
+            case FIRING:
+                o->getFiring(v);
+                return true;
             default:
                 break;
         }
@@ -100,6 +103,12 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int
             case SIM_BLOCKTYPE:
                 o->getSimBlocktype(v);
                 return true;
+            case NZCROSS:
+                o->getNZcross(v);
+                return true;
+            case NMODE:
+                o->getNMode(v);
+                return true;
             default:
                 break;
         }
@@ -396,6 +405,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         model::Block* o = static_cast<model::Block*>(getObject(uid));
         switch (p)
         {
+            case SIM_DEP_UT:
+                o->getSimDepUT(v);
+                return true;
             default:
                 break;
         }
index 774b7aa..b1f1695 100644 (file)
@@ -67,6 +67,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Port* o = static_cast<model::Port*>(getObject(uid));
         switch (p)
         {
+            case FIRING:
+                return o->setFiring(v);
             default:
                 break;
         }
@@ -95,6 +97,10 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
                 return o->setSimFunctionApi(v);
             case SIM_BLOCKTYPE:
                 return o->setSimBlocktype(v);
+            case NZCROSS:
+                return o->setNZcross(v);
+            case NMODE:
+                return o->setNMode(v);
             default:
                 break;
         }
@@ -374,6 +380,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Block* o = static_cast<model::Block*>(getObject(uid));
         switch (p)
         {
+            case SIM_DEP_UT:
+                return o->setSimDepUT(v);
             default:
                 break;
         }
index acf7f73..37d6d03 100644 (file)
@@ -61,7 +61,7 @@ struct State
  *  * CONST_m == 0
  *  * SUMMATION == DEP_U
  *  * CLR == DEP_T
- *  * SWITCH_f == DEP_U & DEP_T
+ *  * SWITCH_f == DEP_U | DEP_T
  */
 enum dep_ut_t
 {
@@ -120,10 +120,10 @@ private:
 
 private:
     Block() : BaseObject(BLOCK), parentDiagram(0), interfaceFunction(), geometry(),
-        angle(), exprs(), label(), style(), sim(), in(), out(), ein(), eout(),
+        angle(), exprs(), label(), style(), nzcross(0), nmode(0), 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), sim(o.sim), in(o.in), out(o.out), ein(o.ein), eout(o.eout),
+        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) {};
     ~Block() {}
 
@@ -349,6 +349,38 @@ private:
         return SUCCESS;
     }
 
+    void getNZcross(int& data) const
+    {
+        data = nzcross;
+    }
+
+    update_status_t setNZcross(const int data)
+    {
+        if (data == nzcross)
+        {
+            return NO_CHANGES;
+        }
+
+        nzcross = data;
+        return SUCCESS;
+    }
+
+    void getNMode(int& data) const
+    {
+        data = nmode;
+    }
+
+    update_status_t setNMode(const int data)
+    {
+        if (data == nmode)
+        {
+            return NO_CHANGES;
+        }
+
+        nmode = data;
+        return SUCCESS;
+    }
+
     void getSimFunctionName(std::string& data) const
     {
         data = sim.functionName;
@@ -403,10 +435,64 @@ private:
             case BLOCKTYPE_X:
             case BLOCKTYPE_Z:
                 sim.blocktype = data;
-                break;
+                return SUCCESS;
             default:
                 return FAIL;
         }
+    }
+
+    void getSimDepUT(std::vector<int>& data) const
+    {
+        data.resize(2, 0);
+        switch (sim.dep_ut)
+        {
+            case DEP_U & DEP_T:
+                // data is already set to [0 0] here.
+                return;
+            case DEP_U:
+                data[0] = 1;
+                return;
+            case DEP_T:
+                data[1] = 1;
+                return;
+            case DEP_U | DEP_T:
+                data[0] = 1;
+                data[1] = 1;
+            default:
+                return;
+        }
+    }
+
+    update_status_t setSimDepUT(const std::vector<int>& data)
+    {
+        if (data.size() != 2)
+        {
+            return FAIL;
+        }
+
+        int dep = DEP_U & DEP_T;
+        if (data[0])
+        {
+            if (data[1])
+            {
+                dep = DEP_U | DEP_T;
+            }
+            else
+            {
+                dep = DEP_U;
+            }
+        }
+        else if (data[1])
+        {
+            dep = DEP_T;
+        }
+
+        if (dep == sim.dep_ut)
+        {
+            return NO_CHANGES;
+        }
+
+        sim.dep_ut = dep;
         return SUCCESS;
     }
 
@@ -450,6 +536,8 @@ private:
     std::vector<std::string> exprs;
     std::string label;
     std::string style;
+    int nzcross;
+    int nmode;
 
     Descriptor sim;
 
index 764d7dc..0a65045 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef PORT_HXX_
 #define PORT_HXX_
 
+#include <string>
 #include <vector>
 
 #include "Model.hxx"
@@ -152,6 +153,21 @@ private:
         return SUCCESS;
     }
 
+    void getFiring(double& f) const
+    {
+        f = firing;
+    }
+
+    update_status_t setFiring(double firing)
+    {
+        if (firing == this->firing)
+        {
+            return NO_CHANGES;
+        }
+        this->firing = firing;
+        return SUCCESS;
+    }
+
 private:
     Datatype* dataType;
     ScicosID sourceBlock;
@@ -159,6 +175,7 @@ private:
     bool implicit;
     std::string style;
     std::string label;
+    double firing;
 
     std::vector<ScicosID> connectedSignals;
 };
index 2e02ac6..ee28012 100644 (file)
@@ -358,6 +358,7 @@ struct id
         }
 
         model::Block* adaptee = adaptor.getAdaptee();
+
         std::string id;
         char* c_str = wide_string_to_UTF8(current->get(0));
         id = std::string(c_str);
index 884d9bf..ba15da6 100644 (file)
@@ -400,6 +400,188 @@ struct blocktype
     }
 };
 
+struct firing
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        return get_ports_property<ModelAdapter, FIRING>(adaptor, OUTPUTS, controller);
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        return set_ports_property<ModelAdapter, FIRING>(adaptor, OUTPUTS, controller, v);
+    }
+};
+
+struct dep_ut
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<int> dep_ut;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), SIM_DEP_UT, dep_ut);
+
+        int* dep;
+        types::Bool* o = new types::Bool(1, 2, &dep);
+
+        dep[0] = dep_ut[0];
+        dep[1] = dep_ut[1];
+
+        return o;
+    }
+
+    static bool set(ModelAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        if (v->getType() != types::InternalType::ScilabBool)
+        {
+            return false;
+        }
+
+        types::Bool* current = v->getAs<types::Bool>();
+        if (current->getRows() != 1 || current->getCols() != 2)
+        {
+            return false;
+        }
+
+        std::vector<int> dep_ut (2);
+        dep_ut[0] = current->get(0);
+        dep_ut[1] = current->get(1);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_DEP_UT, dep_ut);
+        return true;
+    }
+};
+
+struct label
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::string label;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), LABEL, label);
+
+        types::String* o = new types::String(1, 1);
+        o->set(0, label.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 label;
+        char* c_str = wide_string_to_UTF8(current->get(0));
+        label = std::string(c_str);
+        FREE(c_str);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), LABEL, label);
+        return true;
+    }
+};
+
+struct nzcross
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        int nzcross;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), NZCROSS, nzcross);
+
+        types::Double* o = new types::Double(static_cast<double>(nzcross));
+
+        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->getSize() != 1)
+        {
+            return false;
+        }
+        if (floor(current->get(0)) != current->get(0))
+        {
+            return false;
+        }
+
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        int nzcross = static_cast<int>(current->get(0));
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), NZCROSS, nzcross);
+        return true;
+    }
+};
+
+struct nmode
+{
+
+    static types::InternalType* get(const ModelAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        int nmode;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), NMODE, nmode);
+
+        types::Double* o = new types::Double(static_cast<double>(nmode));
+
+        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->getSize() != 1)
+        {
+            return false;
+        }
+        if (floor(current->get(0)) != current->get(0))
+        {
+            return false;
+        }
+
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        int nmode = static_cast<int>(current->get(0));
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), NMODE, nmode);
+        return true;
+    }
+};
+
 } /* namespace */
 
 template<> property<ModelAdapter>::props_t property<ModelAdapter>::fields = property<ModelAdapter>::props_t();
@@ -412,7 +594,7 @@ ModelAdapter::ModelAdapter(org_scilab_modules_scicos::model::Block* o) :
 {
     if (property<ModelAdapter>::properties_has_not_been_set())
     {
-        property<ModelAdapter>::fields.reserve(13);
+        property<ModelAdapter>::fields.reserve(18);
         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);
@@ -426,6 +608,11 @@ ModelAdapter::ModelAdapter(org_scilab_modules_scicos::model::Block* o) :
         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"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);
     }
 }
 
index 110125b..dfeb57e 100644 (file)
@@ -61,10 +61,10 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, object_propertie
         }
         case DATATYPE_ROWS:
             datatypeIndex = 0;
-        // no break
+            // no break
         case DATATYPE_COLS:
             datatypeIndex = 1;
-        // no break
+            // no break
         case DATATYPE_TYPE:
         {
             datatypeIndex = 2;
@@ -218,6 +218,14 @@ bool set_ports_property(const Adaptor& adaptor, object_properties_t port_kind, C
         // Translate identifiers from values
         switch (p)
         {
+            case FIRING:
+                for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+                {
+                    double firing = current->get(i);
+
+                    controller.setObjectProperty(*it, PORT, p, firing);
+                }
+                return true;
             case STYLE:
             case LABEL:
                 // Do nothing, because if the sizes match, then there are already zero concerned ports, so no ports to update
@@ -225,10 +233,10 @@ bool set_ports_property(const Adaptor& adaptor, object_properties_t port_kind, C
 
             case DATATYPE_ROWS:
                 datatypeIndex = 0;
-            // no break
+                // no break
             case DATATYPE_COLS:
                 datatypeIndex = 1;
-            // no break
+                // no break
             case DATATYPE_TYPE:
             {
                 datatypeIndex = 2;