Xcos MVC: implement gr_i / id / in_implicit / out_implicit 42/14942/10
Paul Bignier [Wed, 23 Jul 2014 14:57:10 +0000 (16:57 +0200)]
Change-Id: I1dfdb2449ee2026405c81a1156507d546ce42c11

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/GraphicsAdapter.hxx

index 5ffda49..9e88c5d 100644 (file)
@@ -85,6 +85,7 @@ enum object_properties_t
     SIM_SCHEDULE,       //!< model::Descriptor::schedulingProperties value (stored into model::Block::sim)
     ANGLE,              //!< model::Block::flip and theta values
     EXPRS,              //!< model::Block::exprs value
+    ID,                 //!< model::Block::id value
     INPUTS,             //!< model::Block::in value
     OUTPUTS,            //!< model::Block::out value
     EVENT_INPUTS,       //!< model::Block::ein value
@@ -98,6 +99,7 @@ enum object_properties_t
     DATATYPE,           //!< model::Port::dataType value
     SOURCE_BLOCK,       //!< model::Port::sourceBlock value
     PORT_KIND,          //!< model::Port::kind value
+    IMPLICIT,           //!< model::Port::implicit value
     PORT_NUMBER,        //!< model::Port::portNumber value
     CONNECTED_SIGNALS,  //!< model::Port::connectedSignals value
 };
index 4d15fa5..3db55a0 100644 (file)
@@ -107,6 +107,9 @@ static std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case EXPRS:
             os << "EXPRS";
             break;
+        case ID:
+            os << "ID";
+            break;
         case INPUTS:
             os << "INPUTS";
             break;
@@ -146,6 +149,9 @@ static std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case PORT_KIND:
             os << "PORT_KIND";
             break;
+        case IMPLICIT:
+            os << "IMPLICIT";
+            break;
         case PORT_NUMBER:
             os << "PORT_NUMBER";
             break;
index b6b75e0..b7c93df 100644 (file)
@@ -172,6 +172,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, boo
         model::Port* o = static_cast<model::Port*>(getObject(uid));
         switch (p)
         {
+            case IMPLICIT:
+                o->getImplicit(v);
+                return true;
             default:
                 break;
         }
@@ -196,6 +199,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 ID:
+                o->getIdentifier(v);
+                return true;
             default:
                 break;
         }
index f3649e1..94b34dc 100644 (file)
@@ -169,6 +169,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 IMPLICIT:
+                return o->setImplicit(v);
             default:
                 break;
         }
@@ -246,6 +248,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 ID:
+                return o->setIdentifier(v);
             default:
                 break;
         }
index 5f33a61..d21a556 100644 (file)
@@ -120,8 +120,12 @@ private:
     friend class ::org_scilab_modules_scicos::Model;
 
 private:
-    Block() : BaseObject(BLOCK), parentDiagram(0), interfaceFunction(), geometry(), parentBlock(0), portReference(0) {};
-    Block(const Block& o) : BaseObject(BLOCK), parentDiagram(o.parentDiagram), interfaceFunction(o.interfaceFunction), geometry(o.geometry), parentBlock(o.parentBlock), portReference(o.portReference) {};
+    Block() : BaseObject(BLOCK), parentDiagram(0), interfaceFunction(), geometry(),
+        angle(), exprs(), identifier(), style(), 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), identifier(o.identifier), style(o.style), 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
@@ -194,6 +198,22 @@ private:
         return SUCCESS;
     }
 
+    void getIdentifier(std::string& data) const
+    {
+        data = identifier;
+    }
+
+    update_status_t setIdentifier(const std::string& data)
+    {
+        if (data == identifier)
+        {
+            return NO_CHANGES;
+        }
+
+        identifier = data;
+        return SUCCESS;
+    }
+
     void getIn(std::vector<ScicosID>& v) const
     {
         v = in;
@@ -329,6 +349,7 @@ private:
     Geometry geometry;
     Angle angle;
     std::vector<std::string> exprs;
+    std::string identifier;
     std::string style;
 
     Descriptor sim;
index 1b4b2b8..006ef0a 100644 (file)
@@ -33,8 +33,8 @@ class Port: public BaseObject
     friend class ::org_scilab_modules_scicos::Model;
 
 private:
-    Port() : BaseObject(PORT), dataType(0), sourceBlock(0), kind(UNDEF) {};
-    Port(const Port& o) : BaseObject(PORT), dataType(o.dataType), sourceBlock(o.sourceBlock), kind(o.kind) {};
+    Port() : BaseObject(PORT), dataType(0), sourceBlock(0), kind(UNDEF), implicit(false) {};
+    Port(const Port& o) : BaseObject(PORT), dataType(o.dataType), sourceBlock(o.sourceBlock), kind(o.kind), implicit(o.implicit) {};
     ~Port() {};
 
     const std::vector<ScicosID>& getConnectedSignals() const
@@ -77,10 +77,26 @@ private:
         this->sourceBlock = sourceBlock;
     }
 
+    void getImplicit(bool& v) const
+    {
+        v = implicit;
+    }
+
+    update_status_t setImplicit(bool implicit)
+    {
+        if (implicit == this->implicit)
+        {
+            return NO_CHANGES;
+        }
+        this->implicit = implicit;
+        return SUCCESS;
+    }
+
 private:
     Datatype* dataType;
     ScicosID sourceBlock;
     portKind kind;
+    bool implicit;
 
     std::vector<ScicosID> connectedSignals;
 };
index 7e7a484..fb78493 100644 (file)
@@ -219,7 +219,6 @@ struct exprs
     {
         if (v->getType() == types::InternalType::ScilabString)
         {
-
             types::String* current = v->getAs<types::String>();
             if (current->getCols() != 0 && current->getCols() != 1)
             {
@@ -309,6 +308,38 @@ static types::Double* get_port(const GraphicsAdapter& adaptor, object_properties
     return o;
 }
 
+static types::String* get_port(const GraphicsAdapter& adaptor, object_properties_t p, const Controller& controller, object_properties_t p2)
+{
+    model::Block* adaptee = adaptor.getAdaptee();
+
+    // Retrieve the identifiers
+    std::vector<ScicosID> ids;
+    controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, ids);
+
+    // Allocate some space for the return value
+    types::String* o = new types::String(ids.size(), 1);
+
+    // Translate identifiers to return values
+    int i = 0;
+    static const wchar_t E[] = L"E";
+    static const wchar_t I[] = L"I";
+    for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+    {
+        if (p2 == IMPLICIT)
+        {
+            bool v;
+            controller.getObjectProperty(*it, PORT, IMPLICIT, v);
+            o->set(i, (v == false) ? E : I);
+        }
+        else
+        {
+            // STYLE, LABEL
+        }
+    }
+
+    return o;
+}
+
 static bool set_port(const GraphicsAdapter& adaptor, types::InternalType* v, object_properties_t p, Controller& controller)
 {
     model::Block* adaptee = adaptor.getAdaptee();
@@ -518,18 +549,126 @@ struct peout
     }
 };
 
+struct gr_i
+{
+
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
+    {
+        return adaptor.getGrIContent();
+    }
+
+    static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
+    {
+        adaptor.setGrIContent(v->clone());
+        return true;
+    }
+};
+
+struct id
+{
+
+    static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
+    {
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::string id;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ID, id);
+
+        types::String* o = new types::String(1, 1);
+        o->set(0, id.data());
+
+        return o;
+    }
+
+    static bool set(GraphicsAdapter& 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 id;
+        char* c_str = wide_string_to_UTF8(current->get(0));
+        id = std::string(c_str);
+        FREE(c_str);
+
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), ID, id);
+        return true;
+    }
+};
+
 struct in_implicit
 {
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, INPUTS, controller, IMPLICIT);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
+        if (v->getType() == types::InternalType::ScilabString)
+        {
+            model::Block* adaptee = adaptor.getAdaptee();
+
+            types::String* current = v->getAs<types::String>();
+            if (current->getCols() != 0 && current->getCols() != 1)
+            {
+                return false;
+            }
+
+            // Retrieve the ports i dentifiers
+            std::vector<ScicosID> ids;
+            size_t rows = current->getRows();
+            controller.getObjectProperty(adaptee->id(), adaptee->kind(), INPUTS, ids);
+            if (rows != ids.size())
+            {
+                return false;
+            }
+
+            int i = 0;
+            static const wchar_t E[] = L"E";
+            static const wchar_t I[] = L"I";
+            for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+            {
+                if (current->get(i) == I)
+                {
+                    controller.setObjectProperty(*it, PORT, IMPLICIT, true);
+                }
+                else if (current->get(i) == E)
+                {
+                    controller.setObjectProperty(*it, PORT, IMPLICIT, false);
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            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;
+            }
+            types::String* o = get_port(adaptor, INPUTS, controller, IMPLICIT);
+            if (o->getSize() != 0)
+            {
+                return false;
+            }
+            // Do nothing, because if the sizes match, then there are already zero input ports, so no input ports to update
+            delete o;
+            return true;
+        }
         return false;
     }
 };
@@ -539,13 +678,66 @@ struct out_implicit
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, OUTPUTS, controller, IMPLICIT);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
+        if (v->getType() == types::InternalType::ScilabString)
+        {
+            model::Block* adaptee = adaptor.getAdaptee();
+
+            types::String* current = v->getAs<types::String>();
+            if (current->getCols() != 0 && current->getCols() != 1)
+            {
+                return false;
+            }
+
+            // Retrieve the ports i dentifiers
+            std::vector<ScicosID> ids;
+            size_t rows = current->getRows();
+            controller.getObjectProperty(adaptee->id(), adaptee->kind(), OUTPUTS, ids);
+            if (rows != ids.size())
+            {
+                return false;
+            }
+
+            int i = 0;
+            static const wchar_t E[] = L"E";
+            static const wchar_t I[] = L"I";
+            for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+            {
+                if (current->get(i) == I)
+                {
+                    controller.setObjectProperty(*it, PORT, IMPLICIT, true);
+                }
+                else if (current->get(i) == E)
+                {
+                    controller.setObjectProperty(*it, PORT, IMPLICIT, false);
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            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;
+            }
+            types::String* o = get_port(adaptor, OUTPUTS, controller, IMPLICIT);
+            if (o->getSize() != 0)
+            {
+                return false;
+            }
+            // Do nothing, because if the sizes match, then there are already zero output ports, so no output ports to update
+            delete o;
+            return true;
+        }
         return false;
     }
 };
@@ -633,7 +825,9 @@ struct style
 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
 
 GraphicsAdapter::GraphicsAdapter(const GraphicsAdapter& o) :
-    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o) { }
+    BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o),
+    gr_i_content(o.gr_i_content->clone())
+{}
 
 GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o)
@@ -650,6 +844,8 @@ GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
         property<GraphicsAdapter>::add_property(L"pout", &pout::get, &pout::set);
         property<GraphicsAdapter>::add_property(L"pein", &pein::get, &pein::set);
         property<GraphicsAdapter>::add_property(L"peout", &peout::get, &peout::set);
+        property<GraphicsAdapter>::add_property(L"gr_i", &gr_i::get, &gr_i::set);
+        property<GraphicsAdapter>::add_property(L"id", &id::get, &id::set);
         property<GraphicsAdapter>::add_property(L"in_implicit", &in_implicit::get, &in_implicit::set);
         property<GraphicsAdapter>::add_property(L"out_implicit", &out_implicit::get, &out_implicit::set);
         property<GraphicsAdapter>::add_property(L"in_style", &in_style::get, &in_style::set);
@@ -657,10 +853,13 @@ GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
     }
+
+    gr_i_content = new types::List();
 }
 
 GraphicsAdapter::~GraphicsAdapter()
 {
+    delete gr_i_content;
 }
 
 bool GraphicsAdapter::toString(std::wostringstream& ostr)
@@ -679,5 +878,16 @@ std::wstring GraphicsAdapter::getShortTypeStr()
     return getSharedTypeStr();
 }
 
+types::InternalType* GraphicsAdapter::getGrIContent() const
+{
+    return gr_i_content;
+}
+
+void GraphicsAdapter::setGrIContent(types::InternalType* v)
+{
+    delete gr_i_content;
+    gr_i_content = v->clone();
+}
+
 } /* view_scilab */
 } /* namespace org_scilab_modules_scicos */
index dcf911c..1f393b2 100644 (file)
@@ -41,6 +41,11 @@ public:
     bool toString(std::wostringstream& ostr);
     std::wstring getTypeStr();
     std::wstring getShortTypeStr();
+
+    types::InternalType* getGrIContent() const;
+    void setGrIContent(types::InternalType* v);
+private:
+    types::InternalType* gr_i_content;
 };
 
 } /* view_scilab */