Xcos MVC: implement graphics.flip, theta, exprs, pin, pout 78/14878/9
Paul Bignier [Tue, 22 Jul 2014 12:45:54 +0000 (14:45 +0200)]
Change-Id: Id60c274af0dde3d71001bde407d0de39b7007f1d

scilab/modules/scicos/Makefile.am
scilab/modules/scicos/Makefile.in
scilab/modules/scicos/includes/utilities.hxx
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/GraphicsAdapter.cpp

index bff5a98..0fd4a6e 100644 (file)
@@ -153,6 +153,7 @@ libsciscicos_algo_la_CPPFLAGS= -I$(srcdir)/includes/ \
                        -I$(top_srcdir)/modules/ast/includes/operations/ \
                        -I$(top_srcdir)/modules/ast/includes/system_env/ \
                        -I$(top_srcdir)/modules/ast/includes/types/ \
+                       -I$(top_srcdir)/modules/threads/includes/ \
                        $(EIGEN_CPPFLAGS) \
                        $(AM_CPPFLAGS)
 else
index ac9f925..faa2faa 100644 (file)
@@ -1006,6 +1006,7 @@ libsciscicos_la_LDFLAGS = $(AM_LDFLAGS)
 @XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/operations/ \
 @XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/system_env/ \
 @XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/types/ \
+@XCOS_TRUE@                    -I$(top_srcdir)/modules/threads/includes/ \
 @XCOS_TRUE@                    $(EIGEN_CPPFLAGS) \
 @XCOS_TRUE@                    $(AM_CPPFLAGS)
 
index 6b509e4..6823958 100644 (file)
@@ -83,6 +83,8 @@ enum object_properties_t
     SIM_FUNCTION_NAME,  //!< model::Descriptor::functionName value (stored into model::Block::sim)
     SIM_FUNCTION_API,   //!< model::Descriptor::functionApi value (stored into model::Block::sim)
     SIM_SCHEDULE,       //!< model::Descriptor::schedulingProperties value (stored into model::Block::sim)
+    ANGLE,              //!< model::Block::flip and theta values
+    EXPRS,              //!< model::Block::exprs value
     INPUTS,             //!< model::Block::in value
     OUTPUTS,            //!< model::Block::out value
     EVENT_INPUTS,       //!< model::Block::ein value
index 5707c1d..cd362b5 100644 (file)
@@ -310,6 +310,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case GEOMETRY:
                 o->getGeometry(v);
                 return true;
+            case ANGLE:
+                o->getAngle(v);
+                return true;
             default:
                 break;
         }
@@ -400,6 +403,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 EXPRS:
+                o->getExprs(v);
+                return true;
             default:
                 break;
         }
@@ -451,6 +457,12 @@ 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 INPUTS:
+                v = o->getIn();
+                return true;
+            case OUTPUTS:
+                v = o->getOut();
+                return true;
             default:
                 break;
         }
index 97790e3..5215849 100644 (file)
@@ -301,6 +301,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         {
             case GEOMETRY:
                 return o->setGeometry(v);
+            case ANGLE:
+                return o->setAngle(v);
             default:
                 break;
         }
@@ -403,6 +405,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 EXPRS:
+                return o->setExprs(v);
             default:
                 break;
         }
@@ -454,6 +458,20 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Block* o = static_cast<model::Block*>(getObject(uid));
         switch (p)
         {
+            case INPUTS:
+                if (v.size() > o->in.size()); // FIXME: Input port creation
+                if (v.size() < o->in.size()); // FIXME: Input port deletion
+                {
+                    o->setIn(v);
+                }
+                return SUCCESS;
+            case OUTPUTS:
+                if (v.size() > o->out.size()); // FIXME: Output port creation
+                if (v.size() < o->out.size()); // FIXME: Output port deletion
+                {
+                    o->setOut(v);
+                }
+                return SUCCESS;
             default:
                 break;
         }
index ad55dd8..b1579b8 100644 (file)
@@ -90,6 +90,30 @@ struct Descriptor
     char blocktype;         //!< one of blocktype_t value
 };
 
+/*
+ * Flip and theta
+ */
+struct Angle
+{
+    bool flip;
+    double theta;
+
+    Angle() : flip(0), theta(0) {};
+    Angle(const Angle& a) : flip(a.flip), theta(a.theta) {};
+    Angle(const std::vector<double>& a) : flip((a[0] == 0) ? false : true), theta(a[1]) {};
+
+    void fill(std::vector<double>& a) const
+    {
+        a.resize(2);
+        a[0] = (flip == false) ? 0 : 1;
+        a[1] = theta;
+    }
+    bool operator==(const Angle& a) const
+    {
+        return flip == a.flip && theta == a.theta;
+    }
+};
+
 class Block: public BaseObject
 {
 private:
@@ -152,6 +176,44 @@ private:
         return SUCCESS;
     }
 
+    void getAngle(std::vector<double>& data) const
+    {
+        angle.fill(data);
+    }
+
+    update_status_t setAngle(const std::vector<double>& data)
+    {
+        if (data.size() != 2)
+        {
+            return FAIL;
+        }
+
+        Angle a = Angle(data);
+        if (a == angle)
+        {
+            return NO_CHANGES;
+        }
+
+        angle = a;
+        return SUCCESS;
+    }
+
+    void getExprs(std::vector<std::string>& data) const
+    {
+        data = exprs;
+    }
+
+    update_status_t setExprs(const std::vector<std::string>& data)
+    {
+        if (data == exprs)
+        {
+            return NO_CHANGES;
+        }
+
+        exprs = data;
+        return SUCCESS;
+    }
+
     const std::vector<ScicosID>& getIn() const
     {
         return in;
@@ -245,6 +307,8 @@ private:
     ScicosID parentDiagram;
     std::string interfaceFunction;
     Geometry geometry;
+    Angle angle;
+    std::vector<std::string> exprs;
     std::string style;
 
     Descriptor sim;
index 85875d2..4f93e59 100644 (file)
@@ -14,7 +14,9 @@
 #include <vector>
 #include <cassert>
 
+#include "int.hxx"
 #include "double.hxx"
+#include "string.hxx"
 
 #include "Controller.hxx"
 #include "GraphicsAdapter.hxx"
@@ -114,14 +116,38 @@ struct flip
 
     static types::InternalType* get(const GraphicsAdapter& adaptor)
     {
-        //FIXME: implement
-        return 0;
+        int* data;
+        types::Bool* o = new types::Bool(1, 1, &data);
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<double> angle;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+
+        data[0] = angle[0];
+        return o;
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
     {
-        //FIXME: implement
-        return false;
+        if (v->getType() != types::InternalType::ScilabBool)
+        {
+            return false;
+        }
+
+        types::Bool* current = v->getAs<types::Bool>();
+        if (current->isScalar() != true)
+        {
+            return false;
+        }
+
+        model::Block* adaptee = adaptor.getAdaptee();
+        std::vector<double> angle;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+
+        angle[0] = (current->get(0) == false) ? 0 : 1;
+
+        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        return true;
     }
 };
 
@@ -130,14 +156,38 @@ struct theta
 
     static types::InternalType* get(const GraphicsAdapter& adaptor)
     {
-        //FIXME: implement
-        return 0;
+        double* data;
+        types::Double* o = new types::Double(1, 1, &data);
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<double> angle;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+
+        data[0] = angle[1];
+        return o;
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
     {
-        //FIXME: implement
-        return false;
+        if (v->getType() != types::InternalType::ScilabDouble)
+        {
+            return false;
+        }
+
+        types::Double* current = v->getAs<types::Double>();
+        if (current->isScalar() != true)
+        {
+            return false;
+        }
+
+        model::Block* adaptee = adaptor.getAdaptee();
+        std::vector<double> angle;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+
+        angle[1] = current->get(0);
+
+        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
+        return true;
     }
 };
 
@@ -146,14 +196,63 @@ struct exprs
 
     static types::InternalType* get(const GraphicsAdapter& adaptor)
     {
-        //FIXME: implement
-        return 0;
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<std::string> exprs;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+
+        types::String* o = new types::String(exprs.size(), 1);
+
+        for (size_t i = 0; i < exprs.size(); ++i)
+        {
+            o->set(i, exprs[i].data());
+        }
+        return o;
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
     {
-        //FIXME: implement
-        return false;
+        if (v->getType() == types::InternalType::ScilabString)
+        {
+
+            types::String* current = v->getAs<types::String>();
+            if (current->getCols() != 0 && current->getCols() != 1)
+            {
+                return false;
+            }
+
+            model::Block* adaptee = adaptor.getAdaptee();
+            std::vector<std::string> exprs;
+            Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+
+            exprs.resize(current->getRows());
+            for (int i = 0; i < exprs.size(); ++i)
+            {
+                exprs[i] = (char*) current->get(i);
+            }
+
+            Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            return true;
+        }
+
+        if (v->getType() == types::InternalType::ScilabDouble)
+        {
+
+            types::Double* current = v->getAs<types::Double>();
+            if (current->getRows() != 0 || current->getCols() != 0)
+            {
+                return false;
+            }
+
+            model::Block* adaptee = adaptor.getAdaptee();
+            std::vector<std::string> exprs;
+            Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+
+            exprs.clear();
+
+            Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
+            return true;
+        }
     }
 };
 
@@ -162,14 +261,41 @@ struct pin
 
     static types::InternalType* get(const GraphicsAdapter& adaptor)
     {
-        //FIXME: implement
-        return 0;
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<ScicosID> ids;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
+
+        types::Double* o = new types::Double(ids.size(), 1);
+
+        for (size_t i = 0; i < ids.size(); ++i)
+        {
+            o->set(i, ids[i]);
+        }
+        return o;
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
     {
-        //FIXME: implement
-        return false;
+        if (v->getType() != types::InternalType::ScilabDouble)
+        {
+            return false;
+        }
+
+        types::Double* current = v->getAs<types::Double>();
+
+        model::Block* adaptee = adaptor.getAdaptee();
+        std::vector<ScicosID> ids;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
+
+        ids.resize(current->getSize());
+        for (int i = 0; i < ids.size(); ++i)
+        {
+            ids[i] = current->get(i);
+        }
+
+        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
+        return true;
     }
 };
 
@@ -178,14 +304,41 @@ struct pout
 
     static types::InternalType* get(const GraphicsAdapter& adaptor)
     {
-        //FIXME: implement
-        return 0;
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::vector<ScicosID> ids;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
+
+        types::Double* o = new types::Double(ids.size(), 1);
+
+        for (size_t i = 0; i < ids.size(); ++i)
+        {
+            o->set(i, ids[i]);
+        }
+        return o;
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v)
     {
-        //FIXME: implement
-        return false;
+        if (v->getType() != types::InternalType::ScilabDouble)
+        {
+            return false;
+        }
+
+        types::Double* current = v->getAs<types::Double>();
+
+        model::Block* adaptee = adaptor.getAdaptee();
+        std::vector<ScicosID> ids;
+        Controller::get_instance()->getObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
+
+        ids.resize(current->getSize());
+        for (int i = 0; i < ids.size(); ++i)
+        {
+            ids[i] = current->get(i);
+        }
+
+        Controller::get_instance()->setObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
+        return true;
     }
 };