Xcos MVC: allow smaller in_implicit 39/18439/2
Paul Bignier [Wed, 10 Aug 2016 14:08:53 +0000 (16:08 +0200)]
 * This fixes the error when resizing pin & pout. The missing ports are tagged as Explicit
 * This bug was detected when compiling the CPGE toolbox

Change-Id: Idd7ef586ca686e94e3edcd88cd45af84a9e5b4d1

scilab/modules/scicos/src/cpp/view_scilab/ports_management.hxx
scilab/modules/scicos/tests/unit_tests/model/pin_resize.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/model/pin_resize.tst [new file with mode: 0644]

index 372b7bf..a54e21c 100644 (file)
@@ -177,10 +177,10 @@ types::InternalType* get_ports_property(const Adaptor& adaptor, const object_pro
                 return new types::Double(1);
             }
             datatypeIndex++;
-        // no break
+            // no break
         case DATATYPE_COLS:
             datatypeIndex++;
-        // no break
+            // no break
         case DATATYPE_ROWS:
         {
             datatypeIndex++;
@@ -319,25 +319,23 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
             }
             case IMPLICIT:
             {
-                if (current->getSize() < static_cast<int>(ids.size()))
+                int maxSize = static_cast<int>(ids.size());
+                if (current->getSize() < maxSize)
                 {
-                    std::string adapter = adapterName<p>(port_kind);
-                    std::string field = adapterFieldName<p>(port_kind);
-                    get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s: %d-by-%d expected.\n"), adapter.data(), field.data(), ids.size(), 1);
-                    return false;
+                    maxSize = current->getSize();
                 }
 
                 std::wstring Explicit = L"E";
                 std::wstring Implicit = L"I";
-                for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
+                for (; i < maxSize; ++i)
                 {
                     if (current->get(i) == Implicit)
                     {
-                        controller.setObjectProperty(*it, PORT, p, true);
+                        controller.setObjectProperty(ids[i], PORT, p, true);
                     }
                     else if (current->get(i) == Explicit)
                     {
-                        controller.setObjectProperty(*it, PORT, p, false);
+                        controller.setObjectProperty(ids[i], PORT, p, false);
                     }
                     else
                     {
@@ -347,6 +345,11 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
                         return false;
                     }
                 }
+                for (i = maxSize; i < ids.size(); ++i)
+                {
+                    // Tag the missing ports as Explicit. This is done to fix the resizing of pin & pout.
+                    controller.setObjectProperty(ids[i], PORT, p, false);
+                }
                 return true;
             }
             default:
@@ -394,10 +397,10 @@ bool set_ports_property(const Adaptor& adaptor, const object_properties_t port_k
 
             case DATATYPE_TYPE:
                 datatypeIndex++;
-            // no break
+                // no break
             case DATATYPE_COLS:
                 datatypeIndex++;
-            // no break
+                // no break
             case DATATYPE_ROWS:
             {
                 datatypeIndex++;
@@ -563,10 +566,10 @@ inline bool updateNewPort(const ScicosID oldPort, int newPort, Controller& contr
         {
             case DATATYPE_TYPE:
                 datatypeIndex++;
-            // no break
+                // no break
             case DATATYPE_COLS:
                 datatypeIndex++;
-            // no break
+                // no break
             case DATATYPE_ROWS:
             {
                 datatypeIndex++;
@@ -613,10 +616,10 @@ inline bool addNewPort(const ScicosID newPortID, int newPort, const std::vector<
         {
             case DATATYPE_TYPE:
                 datatypeIndex++;
-            // no break
+                // no break
             case DATATYPE_COLS:
                 datatypeIndex++;
-            // no break
+                // no break
             case DATATYPE_ROWS:
             {
                 datatypeIndex++;
diff --git a/scilab/modules/scicos/tests/unit_tests/model/pin_resize.dia.ref b/scilab/modules/scicos/tests/unit_tests/model/pin_resize.dia.ref
new file mode 100644 (file)
index 0000000..9a916a1
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+loadXcosLibs();
+o = scicos_block();
+o.graphics.pin = [0; 0; 0; 0];
+assert_checkequal(size(o.graphics.pin, "*"), 4);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 4);
+o.graphics.pin = [0; 0];
+assert_checkequal(size(o.graphics.pin, "*"), 2);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 2);
+o.graphics.pin = [0; 0; 0];
+assert_checkequal(size(o.graphics.pin, "*"), 3);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 3);
+o.graphics.pin = 0;
+assert_checkequal(size(o.graphics.pin, "*"), 1);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 1);
+// Check that all the model items are freed
+clear
diff --git a/scilab/modules/scicos/tests/unit_tests/model/pin_resize.tst b/scilab/modules/scicos/tests/unit_tests/model/pin_resize.tst
new file mode 100644 (file)
index 0000000..2e432dd
--- /dev/null
@@ -0,0 +1,32 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+loadXcosLibs();
+
+o = scicos_block();
+
+o.graphics.pin = [0; 0; 0; 0];
+assert_checkequal(size(o.graphics.pin, "*"), 4);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 4);
+
+o.graphics.pin = [0; 0];
+assert_checkequal(size(o.graphics.pin, "*"), 2);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 2);
+
+o.graphics.pin = [0; 0; 0];
+assert_checkequal(size(o.graphics.pin, "*"), 3);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 3);
+
+o.graphics.pin = 0;
+assert_checkequal(size(o.graphics.pin, "*"), 1);
+assert_checkequal(size(o.graphics.in_implicit, "*"), 1);
+
+
+// Check that all the model items are freed
+clear