Xcos MVC: implement in_style / out_style / in_label / out_label / style 56/14956/8
Paul Bignier [Mon, 28 Jul 2014 07:16:43 +0000 (09:16 +0200)]
Change-Id: Id3558d29487a5c0fe2def25994c0ab61d2692a43

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

index 9e88c5d..842debd 100644 (file)
@@ -85,7 +85,6 @@ 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
@@ -93,6 +92,8 @@ enum object_properties_t
     PARENT_BLOCK,       //!< model::Block::parentBlock value
     CHILDREN,           //!< model::Block::children for superblocks or model::Diagram::children value
     PORT_REFERENCE,     //!< model::Block::portReference value
+    STYLE,              //!< model::Block & Port::style value
+    LABEL,              //!< model::Block & Port::label value
     DESTINATION_PORT,   //!< model::Link::destinationPort value
     SOURCE_PORT,        //!< model::Link::sourcePort value
     CONTROL_POINTS,     //!< model::Link::controlPoints value
index 3db55a0..22bd132 100644 (file)
@@ -107,9 +107,6 @@ 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;
@@ -131,6 +128,12 @@ static std::ostream& operator<<(std::ostream& os, object_properties_t p)
         case PORT_REFERENCE:
             os << "PORT_REFERENCE";
             break;
+        case STYLE:
+            os << "STYLE";
+            break;
+        case LABEL:
+            os << "LABEL";
+            break;
         case DESTINATION_PORT:
             os << "DESTINATION_PORT";
             break;
index b7c93df..4bb2e78 100644 (file)
@@ -199,8 +199,11 @@ 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);
+            case STYLE:
+                o->getStyle(v);
+                return true;
+            case LABEL:
+                o->getLabel(v);
                 return true;
             default:
                 break;
@@ -229,6 +232,12 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
         model::Port* o = static_cast<model::Port*>(getObject(uid));
         switch (p)
         {
+            case STYLE:
+                o->getStyle(v);
+                return true;
+            case LABEL:
+                o->getLabel(v);
+                return true;
             default:
                 break;
         }
index 94b34dc..8332edc 100644 (file)
@@ -248,8 +248,10 @@ 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);
+            case STYLE:
+                return o->setStyle(v);
+            case LABEL:
+                return o->setLabel(v);
             default:
                 break;
         }
@@ -277,6 +279,10 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         model::Port* o = static_cast<model::Port*>(getObject(uid));
         switch (p)
         {
+            case STYLE:
+                return o->setStyle(v);
+            case LABEL:
+                return o->setLabel(v);
             default:
                 break;
         }
@@ -392,7 +398,7 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
     return FAIL;
 }
 
-update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector< std::string >& v)
+update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<std::string>& v)
 {
 
     if (k == ANNOTATION)
index d21a556..9d0561f 100644 (file)
@@ -121,10 +121,10 @@ private:
 
 private:
     Block() : BaseObject(BLOCK), parentDiagram(0), interfaceFunction(), geometry(),
-        angle(), exprs(), identifier(), style(), sim(), in(), out(), ein(), eout(),
+        angle(), exprs(), label(), 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),
+        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),
         parameter(o.parameter), state(o.state), parentBlock(o.parentBlock), children(o.children), portReference(o.portReference) {};
     ~Block() {}
 
@@ -198,19 +198,19 @@ private:
         return SUCCESS;
     }
 
-    void getIdentifier(std::string& data) const
+    void getLabel(std::string& data) const
     {
-        data = identifier;
+        data = label;
     }
 
-    update_status_t setIdentifier(const std::string& data)
+    update_status_t setLabel(const std::string& data)
     {
-        if (data == identifier)
+        if (data == label)
         {
             return NO_CHANGES;
         }
 
-        identifier = data;
+        label = data;
         return SUCCESS;
     }
 
@@ -334,22 +334,29 @@ private:
         this->sim = sim;
     }
 
-    const std::string& getStyle() const
+    void getStyle(std::string& data) const
     {
-        return style;
+        data = style;
     }
 
-    void setStyle(const std::string& style)
+    update_status_t setStyle(const std::string& data)
     {
-        this->style = style;
+        if (data == style)
+        {
+            return NO_CHANGES;
+        }
+
+        style = data;
+        return SUCCESS;
     }
+
 private:
     ScicosID parentDiagram;
     std::string interfaceFunction;
     Geometry geometry;
     Angle angle;
     std::vector<std::string> exprs;
-    std::string identifier;
+    std::string label;
     std::string style;
 
     Descriptor sim;
index 006ef0a..72d2e76 100644 (file)
@@ -33,8 +33,9 @@ class Port: public BaseObject
     friend class ::org_scilab_modules_scicos::Model;
 
 private:
-    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() : BaseObject(PORT), dataType(0), sourceBlock(0), kind(UNDEF), implicit(false), style(), label(), connectedSignals() {};
+    Port(const Port& o) : BaseObject(PORT), dataType(o.dataType), sourceBlock(o.sourceBlock),
+        kind(o.kind), implicit(o.implicit), style(o.style), label(o.label), connectedSignals(o.connectedSignals) {};
     ~Port() {};
 
     const std::vector<ScicosID>& getConnectedSignals() const
@@ -92,11 +93,43 @@ private:
         return SUCCESS;
     }
 
+    void getStyle(std::string& s) const
+    {
+        s = style;
+    }
+
+    update_status_t setStyle(const std::string& style)
+    {
+        if (style == this->style)
+        {
+            return NO_CHANGES;
+        }
+        this->style = style;
+        return SUCCESS;
+    }
+
+    void getLabel(std::string& l) const
+    {
+        l = style;
+    }
+
+    update_status_t setLabel(const std::string& label)
+    {
+        if (label == this->label)
+        {
+            return NO_CHANGES;
+        }
+        this->label = label;
+        return SUCCESS;
+    }
+
 private:
     Datatype* dataType;
     ScicosID sourceBlock;
     portKind kind;
     bool implicit;
+    std::string style;
+    std::string label;
 
     std::vector<ScicosID> connectedSignals;
 };
index fb78493..eb6a42c 100644 (file)
@@ -30,6 +30,9 @@ namespace org_scilab_modules_scicos
 namespace view_scilab
 {
 
+static const wchar_t E[] = L"E";
+static const wchar_t I[] = L"I";
+
 struct orig
 {
 
@@ -254,7 +257,7 @@ struct exprs
     }
 };
 
-static types::Double* get_port(const GraphicsAdapter& adaptor, object_properties_t p, const Controller& controller)
+static types::Double* create_port(const GraphicsAdapter& adaptor, object_properties_t p, const Controller& controller)
 {
     model::Block* adaptee = adaptor.getAdaptee();
 
@@ -321,20 +324,31 @@ static types::String* get_port(const GraphicsAdapter& adaptor, object_properties
 
     // 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)
+    switch (p2)
     {
-        if (p2 == IMPLICIT)
+        case IMPLICIT:
         {
-            bool v;
-            controller.getObjectProperty(*it, PORT, IMPLICIT, v);
-            o->set(i, (v == false) ? E : I);
+            for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+            {
+                bool v;
+                controller.getObjectProperty(*it, PORT, p2, v);
+                o->set(i, (v == false) ? E : I);
+            }
+            break;
         }
-        else
+        case STYLE:
+        case LABEL:
         {
-            // STYLE, LABEL
+            for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+            {
+                std::string s;
+                controller.getObjectProperty(*it, PORT, p2, s);
+                o->set(i, s.data());
+            }
+            break;
         }
+        default:
+            return false;
     }
 
     return o;
@@ -493,12 +507,92 @@ static bool set_port(const GraphicsAdapter& adaptor, types::InternalType* v, obj
     return true;
 }
 
+static bool set_port(const GraphicsAdapter& adaptor, types::InternalType* v, object_properties_t p, Controller& controller, object_properties_t p2)
+{
+    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(), p, ids);
+        if (rows != ids.size())
+        {
+            return false;
+        }
+
+        int i = 0;
+        switch (p2)
+        {
+            case IMPLICIT:
+            {
+                for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+                {
+                    if (current->get(i) == I)
+                    {
+                        controller.setObjectProperty(*it, PORT, p2, true);
+                    }
+                    else if (current->get(i) == E)
+                    {
+                        controller.setObjectProperty(*it, PORT, p2, false);
+                    }
+                    else
+                    {
+                        return false;
+                    }
+                }
+                break;
+            }
+            case STYLE:
+            case LABEL:
+            {
+                std::vector<std::string> style = std::vector<std::string>(current->getSize());
+                for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+                {
+                    char* c_str = wide_string_to_UTF8(current->get(i));
+                    style[i] = std::string(c_str);
+                    FREE(c_str);
+                    controller.setObjectProperty(*it, PORT, p2, style[i]);
+                }
+                break;
+            }
+            default:
+                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, p, controller, p2);
+        if (o->getSize() != 0)
+        {
+            return false;
+        }
+        // Do nothing, because if the sizes match, then there are already zero concerned ports, so no ports to update
+        delete o;
+        return true;
+    }
+    return false;
+}
+
 struct pin
 {
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        return get_port(adaptor, INPUTS, controller);
+        return create_port(adaptor, INPUTS, controller);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
@@ -512,7 +606,7 @@ struct pout
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        return get_port(adaptor, OUTPUTS, controller);
+        return create_port(adaptor, OUTPUTS, controller);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
@@ -526,7 +620,7 @@ struct pein
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        return get_port(adaptor, EVENT_INPUTS, controller);
+        return create_port(adaptor, EVENT_INPUTS, controller);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
@@ -540,7 +634,7 @@ struct peout
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        return get_port(adaptor, EVENT_OUTPUTS, controller);
+        return create_port(adaptor, EVENT_OUTPUTS, controller);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
@@ -572,7 +666,7 @@ struct id
         model::Block* adaptee = adaptor.getAdaptee();
 
         std::string id;
-        controller.getObjectProperty(adaptee->id(), adaptee->kind(), ID, id);
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
 
         types::String* o = new types::String(1, 1);
         o->set(0, id.data());
@@ -599,7 +693,7 @@ struct id
         id = std::string(c_str);
         FREE(c_str);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), ID, id);
+        controller.setObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
         return true;
     }
 };
@@ -614,62 +708,7 @@ struct in_implicit
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        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;
+        return set_port(adaptor, v, INPUTS, controller, IMPLICIT);
     }
 };
 
@@ -683,62 +722,7 @@ struct out_implicit
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        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;
+        return set_port(adaptor, v, OUTPUTS, controller, IMPLICIT);
     }
 };
 
@@ -747,14 +731,12 @@ struct in_style
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, INPUTS, controller, STYLE);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
-        return false;
+        return set_port(adaptor, v, INPUTS, controller, STYLE);
     }
 };
 
@@ -763,14 +745,12 @@ struct out_style
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, OUTPUTS, controller, STYLE);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
-        return false;
+        return set_port(adaptor, v, OUTPUTS, controller, STYLE);
     }
 };
 
@@ -779,14 +759,12 @@ struct in_label
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, INPUTS, controller, LABEL);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
-        return false;
+        return set_port(adaptor, v, INPUTS, controller, LABEL);
     }
 };
 
@@ -795,14 +773,12 @@ struct out_label
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        return get_port(adaptor, OUTPUTS, controller, LABEL);
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
-        return false;
+        return set_port(adaptor, v, OUTPUTS, controller, LABEL);
     }
 };
 
@@ -811,13 +787,55 @@ struct style
 
     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
     {
-        //FIXME: implement
-        return 0;
+        model::Block* adaptee = adaptor.getAdaptee();
+
+        std::string style;
+        controller.getObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
+
+        types::String* o;
+        if (style.empty())
+        {
+            o = new types::String(0, 0);
+        }
+        else
+        {
+            o = new types::String(1, 1);
+            o->set(0, style.data());
+        }
+        return o;
     }
 
     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
     {
-        //FIXME: implement
+        model::Block* adaptee = adaptor.getAdaptee();
+        if (v->getType() == types::InternalType::ScilabString)
+        {
+            types::String* current = v->getAs<types::String>();
+            if (current->getSize() != 1)
+            {
+                return false;
+            }
+
+            std::string style;
+            char* c_str = wide_string_to_UTF8(current->get(0));
+            style = std::string(c_str);
+            FREE(c_str);
+
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
+            return true;
+        }
+        else if (v->getType() == types::InternalType::ScilabDouble)
+        {
+            types::Double* current = v->getAs<types::Double>();
+            if (current->getSize() != 0)
+            {
+                return false;
+            }
+
+            std::string style;
+            controller.setObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
+            return true;
+        }
         return false;
     }
 };
@@ -834,7 +852,7 @@ GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
 {
     if (property<GraphicsAdapter>::properties_has_not_been_set())
     {
-        property<GraphicsAdapter>::fields.reserve(15);
+        property<GraphicsAdapter>::fields.reserve(17);
         property<GraphicsAdapter>::add_property(L"orig", &orig::get, &orig::set);
         property<GraphicsAdapter>::add_property(L"sz", &sz::get, &sz::set);
         property<GraphicsAdapter>::add_property(L"flip", &flip::get, &flip::set);