Xcos MVC: blk.model.blocktype is a string 68/15168/2
Clément DAVID [Thu, 4 Sep 2014 18:15:38 +0000 (20:15 +0200)]
Change-Id: I16b76e7d48c53a5508718f4436869eadf331ea9b

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/ModelAdapter.cpp

index 1b1ec46..b26686e 100644 (file)
@@ -95,9 +95,6 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, int
             case SIM_FUNCTION_API:
                 o->getSimFunctionApi(v);
                 return true;
-            case SIM_BLOCKTYPE:
-                o->getSimBlocktype(v);
-                return true;
             case NZCROSS:
                 o->getNZcross(v);
                 return true;
@@ -218,6 +215,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case SIM_FUNCTION_NAME:
                 o->getSimFunctionName(v);
                 return true;
+            case SIM_BLOCKTYPE:
+                o->getSimBlocktype(v);
+                return true;
             case STYLE:
                 o->getStyle(v);
                 return true;
index 5ee3c91..74d1e2b 100644 (file)
@@ -93,8 +93,6 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
         {
             case SIM_FUNCTION_API:
                 return o->setSimFunctionApi(v);
-            case SIM_BLOCKTYPE:
-                return o->setSimBlocktype(v);
             case NZCROSS:
                 return o->setNZcross(v);
             case NMODE:
@@ -263,6 +261,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
                 return o->setInterfaceFunction(v);
             case SIM_FUNCTION_NAME:
                 return o->setSimFunctionName(v);
+            case SIM_BLOCKTYPE:
+                return o->setSimBlocktype(v);
             case STYLE:
                 return o->setStyle(v);
             case LABEL:
index e180da3..9fa8f80 100644 (file)
@@ -470,19 +470,26 @@ private:
         return SUCCESS;
     }
 
-    void getSimBlocktype(int& data) const
+    void getSimBlocktype(std::string& data) const
     {
-        data = sim.blocktype;
+        data = std::string(1, sim.blocktype);
     }
 
-    update_status_t setSimBlocktype(const int data)
+    update_status_t setSimBlocktype(const std::string data)
     {
-        if (data == sim.blocktype)
+        if (data.size() != 1)
+        {
+            return FAIL;
+        }
+
+        char c = *(data.c_str());
+
+        if (c == sim.blocktype)
         {
             return NO_CHANGES;
         }
 
-        switch (data)
+        switch (c)
         {
             case BLOCKTYPE_C:
             case BLOCKTYPE_D:
@@ -491,7 +498,7 @@ private:
             case BLOCKTYPE_M:
             case BLOCKTYPE_X:
             case BLOCKTYPE_Z:
-                sim.blocktype = data;
+                sim.blocktype = c;
                 return SUCCESS;
             default:
                 return FAIL;
index bad5764..c2c5c98 100644 (file)
@@ -542,12 +542,10 @@ struct blocktype
     {
         model::Block* adaptee = adaptor.getAdaptee();
 
-        int type;
+        std::string type;
         controller.getObjectProperty(adaptee->id(), adaptee->kind(), SIM_BLOCKTYPE, type);
 
-        wchar_t Type = type;
-        types::String* o = new types::String(&Type);
-
+        types::String* o = new types::String(type.c_str());
         return o;
     }
 
@@ -565,20 +563,13 @@ struct blocktype
         {
             return false;
         }
-        // The input must be a character
-        if (current->get(0)[0] == '\0')
-        {
-            return false;
-        }
-        if (current->get(0)[1] != '\0')
-        {
-            return false;
-        }
 
-        int type = current->get(0)[0];
+        char* c_str = wide_string_to_UTF8(current->get(0));
+        std::string type (c_str);
+        FREE(c_str);
 
-        controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_BLOCKTYPE, type);
-        return true;
+        // the value validation is performed on the model
+        return controller.setObjectProperty(adaptee->id(), adaptee->kind(), SIM_BLOCKTYPE, type) != FAIL;
     }
 };