Xcos MVC: implement firing / dep_ut / label / nzcross / nmode
[scilab.git] / scilab / modules / scicos / src / cpp / view_scilab / ModelAdapter.cpp
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);
     }
 }