view_scilab: relax graphics.exprs checking 12/18112/2
Clément DAVID [Mon, 25 Apr 2016 14:11:27 +0000 (16:11 +0200)]
Change-Id: I8c2b3f3e193181c2f13078a49949c8348513d116

scilab/modules/scicos/src/cpp/view_scilab/GraphicsAdapter.cpp

index 939d4af..15c8ef2 100644 (file)
@@ -171,13 +171,8 @@ struct exprs
     {
         ScicosID adaptee = adaptor.getAdaptee()->id();
 
-        // From here on, only perform check on 'v'. If it is correct, encode it in the model via 'var2vec'
-        if (v->getType() == types::InternalType::ScilabString)
-        {
-            types::String* current = v->getAs<types::String>();
-            // FIXME: find a test case and check for this case
-        }
-        else if (v->getType() == types::InternalType::ScilabDouble)
+        // Corner-case the content is an empty matrix
+        if (v->getType() == types::InternalType::ScilabDouble)
         {
             types::Double* current = v->getAs<types::Double>();
             if (!current->isEmpty())
@@ -186,486 +181,6 @@ struct exprs
             }
         }
 
-        // All the following cases are meant for blocks:
-        // CBLOCK, fortran_block, EXPRESSION, scifunc_block_m, PDE, CONSTRAINT2_c, LOOKUP2D, MBLOCK and MPBLOCK
-        else if (v->getType() == types::InternalType::ScilabList)
-        {
-            types::List* initial_list = v->getAs<types::List>();
-
-            if (initial_list->getSize() == 2)
-            {
-                size_t nParams = 0;
-                // Whatever the block kind, the first element is necessarily a string matrix (can be empty)
-                if (initial_list->get(0)->getType() == types::InternalType::ScilabDouble)
-                {
-                    types::Double* empty_matrix_expected = initial_list->get(0)->getAs<types::Double>();
-                    if (empty_matrix_expected->getSize() != 0)
-                    {
-                        return false;
-                    }
-                }
-                else if (initial_list->get(0)->getType() == types::InternalType::ScilabString)
-                {
-                    types::String* initial_string = initial_list->get(0)->getAs<types::String>();
-                    nParams = initial_string->getSize();
-                }
-                else
-                {
-                    return false;
-                }
-
-                // The second element determines the block kind
-                if (initial_list->get(1)->getType() == types::InternalType::ScilabDouble)
-                {
-                    types::Double* empty_matrix_expected = initial_list->get(1)->getAs<types::Double>();
-                    if (!empty_matrix_expected->isEmpty())
-                    {
-                        return false;
-                    }
-                    // List coming from a C block
-                }
-                else if (initial_list->get(1)->getType() == types::InternalType::ScilabString)
-                {
-                    types::String* second_string = initial_list->get(1)->getAs<types::String>();
-                    // List coming from a "user-defined function" block
-                    // FIXME: why retrieve and not used ?
-                }
-                else if (initial_list->get(1)->getType() == types::InternalType::ScilabList)
-                {
-                    types::List* second_list = initial_list->get(1)->getAs<types::List>();
-
-                    if (second_list->getSize() == 1)
-                    {
-                        // Default fortran_block value: must contain an empty matrix
-                        if (second_list->get(0)->getType() != types::InternalType::ScilabDouble)
-                        {
-                            return false;
-                        }
-                        types::Double* empty = second_list->get(0)->getAs<types::Double>();
-                        if (!empty->isEmpty())
-                        {
-                            return false;
-                        }
-                        // List coming from a fortran_block
-                    }
-                    else if (second_list->getSize() == 3)
-                    {
-                        // List coming from a SuperBlock (masked or not)
-                        // The three elements are: parameter names, title message and parameters types & sizes
-
-                        // Parameters names (string matrix, can be empty)
-                        if (second_list->get(0)->getType() == types::InternalType::ScilabDouble)
-                        {
-                            types::Double* empty_matrix_expected = second_list->get(0)->getAs<types::Double>();
-                            if (empty_matrix_expected->getSize() != 0)
-                            {
-                                return false;
-                            }
-                            // No parameters are present, so nothing needs to be saved
-                        }
-                        else if (second_list->get(0)->getType() == types::InternalType::ScilabString)
-                        {
-                            types::String* second_string = second_list->get(0)->getAs<types::String>();
-
-                            if (second_string->getSize() != static_cast<int>(nParams))
-                            {
-                                return false;
-                            }
-                        }
-                        else
-                        {
-                            return false;
-                        }
-
-                        // Title message (string matrix, can be empty)
-                        if (second_list->get(1)->getType() == types::InternalType::ScilabDouble)
-                        {
-                            types::Double* empty_matrix_expected = second_list->get(1)->getAs<types::Double>();
-                            if (empty_matrix_expected->getSize() != 0 || nParams != 0)
-                            {
-                                return false;
-                            }
-                            // No parameters are present, so nothing needs to be saved
-                        }
-                        else if (second_list->get(1)->getType() == types::InternalType::ScilabString)
-                        {
-                            types::String* title_message = second_list->get(1)->getAs<types::String>();
-                            if (title_message->getSize() != static_cast<int>(nParams + 1))
-                            {
-                                // There must be as many parameter descriptions as there are parameters, plus the title message
-                                return false;
-                            }
-                        }
-                        else
-                        {
-                            return false;
-                        }
-
-                        // Parameters types & sizes (list mixing strings and integers, can be empty)
-                        if (second_list->get(2)->getType() != types::InternalType::ScilabList)
-                        {
-                            return false;
-                        }
-                        types::List* third_list = second_list->get(2)->getAs<types::List>();
-
-                        if (third_list->getSize() != static_cast<int>(2 * nParams))
-                        {
-                            // There must be one type and one size for each parameter, so '2*nParams' elements
-                            if (!(third_list->getSize() == 1 && nParams == 0))
-                            {
-                                // Allow third_list != 2*params only for the dummy case 'third_list=list([])'. Do nothing then
-                                return false;
-                            }
-                        }
-                    }
-                    else if (second_list->getSize() == 7)
-                    {
-                        // List coming from a scifunc block
-
-                        // Code parts (string matrices)
-                        for (int i = 0; i < 7; ++i)
-                        {
-                            if (second_list->get(i)->getType() == types::InternalType::ScilabDouble)
-                            {
-                                types::Double* ith_double = second_list->get(i)->getAs<types::Double>();
-                                if (!ith_double->isEmpty())
-                                {
-                                    return false;
-                                }
-                            }
-                            else if (second_list->get(i)->getType() != types::InternalType::ScilabString)
-                            {
-                                return false;
-                            }
-                        }
-                    }
-                    else
-                    {
-                        return false;
-                    }
-                }
-                else
-                {
-                    return false;
-                }
-            }
-            else if (initial_list->getSize() == 3)
-            {
-                // List coming from a PDE block
-                if (initial_list->get(0)->getType() == types::InternalType::ScilabTList)
-                {
-                    types::TList* ParamsPDE = initial_list->get(0)->getAs<types::TList>();
-
-                    types::String* header = ParamsPDE->getFieldNames();
-                    int nParams = header->getSize() - 1; // The first element is the TList type
-                    // Check the header
-                    for (int i = 1; i < nParams; ++i) // Stop at 'nParams-1' to treat the last element differently (string matrix)
-                    {
-                        // Its corresponding element in the TList
-                        if (ParamsPDE->get(i)->getType() != types::InternalType::ScilabString)
-                        {
-                            return false;
-                        }
-                        types::String* ith_string = ParamsPDE->get(i)->getAs<types::String>();
-                        if (!ith_string->isScalar())
-                        {
-                            return false;
-                        }
-                    }
-                    // Header element for the last element of ParamsPDE
-                    if (ParamsPDE->get(nParams)->getType() != types::InternalType::ScilabString)
-                    {
-                        return false;
-                    }
-                    types::String* last_string = ParamsPDE->get(nParams)->getAs<types::String>();
-                    // FIXME: find a related test case
-
-                    // Next comes some code
-                    if (initial_list->get(1)->getType() == types::InternalType::ScilabDouble)
-                    {
-                        types::Double* empty_matrix_expected = initial_list->get(1)->getAs<types::Double>();
-                        if (!empty_matrix_expected->isEmpty())
-                        {
-                            return false;
-                        }
-                    }
-                    else if (initial_list->get(1)->getType() == types::InternalType::ScilabString)
-                    {
-                        types::String* code = initial_list->get(1)->getAs<types::String>();
-                        // FIXME: find a related test case
-                    }
-                    else
-                    {
-                        return false;
-                    }
-
-                    // Finally, the block name
-                    if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
-                    {
-                        return false;
-                    }
-                    types::String* name = initial_list->get(2)->getAs<types::String>();
-                    if (!name->isScalar())
-                    {
-                        return false;
-                    }
-                }
-                else if (initial_list->get(0)->getType() == types::InternalType::ScilabString)
-                {
-                    // List coming from a CONSTRAINT2_c block
-                    types::String* x = initial_list->get(0)->getAs<types::String>();
-                    if (!x->isScalar())
-                    {
-                        return false;
-                    }
-
-                    if (initial_list->get(1)->getType() != types::InternalType::ScilabString)
-                    {
-                        return false;
-                    }
-                    types::String* xd = initial_list->get(1)->getAs<types::String>();
-                    if (!xd->isScalar())
-                    {
-                        return false;
-                    }
-
-                    if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
-                    {
-                        return false;
-                    }
-                    types::String* id = initial_list->get(2)->getAs<types::String>();
-                    if (!id->isScalar())
-                    {
-                        return false;
-                    }
-                }
-                else
-                {
-                    return false;
-                }
-            }
-            else if (initial_list->getSize() == 5)
-            {
-                // List coming from a LOOKUP2D block
-                types::String* xx = initial_list->get(0)->getAs<types::String>();
-                if (!xx->isScalar())
-                {
-                    return false;
-                }
-
-                if (initial_list->get(1)->getType() != types::InternalType::ScilabString)
-                {
-                    return false;
-                }
-                types::String* yy = initial_list->get(1)->getAs<types::String>();
-                if (!yy->isScalar())
-                {
-                    return false;
-                }
-
-                if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
-                {
-                    return false;
-                }
-                types::String* zz = initial_list->get(2)->getAs<types::String>();
-                if (!zz->isScalar())
-                {
-                    return false;
-                }
-
-                if (initial_list->get(3)->getType() != types::InternalType::ScilabString)
-                {
-                    return false;
-                }
-                types::String* Method = initial_list->get(3)->getAs<types::String>();
-                if (!Method->isScalar())
-                {
-                    return false;
-                }
-
-                if (initial_list->get(4)->getType() != types::InternalType::ScilabString)
-                {
-                    return false;
-                }
-                types::String* Graf = initial_list->get(4)->getAs<types::String>();
-                if (!Graf->isScalar())
-                {
-                    return false;
-                }
-            }
-            else
-            {
-                return false;
-            }
-        }
-        else if (v->getType() == types::InternalType::ScilabTList)
-        {
-            types::TList* current = v->getAs<types::TList>();
-
-            // Check the header
-            types::String* header = current->getFieldNames();
-            if (header->getSize() != 10)
-            {
-                return false;
-            }
-            if (header->get(0) != MBLOCK && header->get(0) != MPBLOCK)
-            {
-                return false;
-            }
-            if (header->get(1) != in)
-            {
-                return false;
-            }
-            if (header->get(2) != intype)
-            {
-                return false;
-            }
-            if (header->get(3) != out)
-            {
-                return false;
-            }
-            if (header->get(4) != outtype)
-            {
-                return false;
-            }
-            if (header->get(5) != param)
-            {
-                return false;
-            }
-            if (header->get(6) != paramv)
-            {
-                return false;
-            }
-            if (header->get(7) != pprop)
-            {
-                return false;
-            }
-            if (header->get(8) != nameF)
-            {
-                return false;
-            }
-            if (header->get(9) != funtxt)
-            {
-                return false;
-            }
-
-            // 'in'
-            if (current->get(1)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* inField = current->get(1)->getAs<types::String>();
-            if (!inField->isScalar())
-            {
-                return false;
-            }
-
-            // 'intype'
-            if (current->get(2)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* intypeField = current->get(2)->getAs<types::String>();
-            if (!intypeField->isScalar())
-            {
-                return false;
-            }
-
-            // 'out'
-            if (current->get(3)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* outField = current->get(3)->getAs<types::String>();
-            if (!outField->isScalar())
-            {
-                return false;
-            }
-
-            // 'outtype'
-            if (current->get(4)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* outtypeField = current->get(4)->getAs<types::String>();
-            if (!outtypeField->isScalar())
-            {
-                return false;
-            }
-
-            // 'param'
-            if (current->get(5)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* paramField = current->get(5)->getAs<types::String>();
-            if (!paramField->isScalar())
-            {
-                return false;
-            }
-
-            // 'paramv'
-            if (current->get(6)->getType() != types::InternalType::ScilabList)
-            {
-                return false;
-            }
-            types::List* list = current->get(6)->getAs<types::List>();
-
-            for (int i = 0; i < list->getSize(); ++i)
-            {
-                if (list->get(i)->getType() != types::InternalType::ScilabString)
-                {
-                    return false;
-                }
-            }
-
-            // 'pprop'
-            if (current->get(7)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* ppropField = current->get(7)->getAs<types::String>();
-            if (!ppropField->isScalar())
-            {
-                return false;
-            }
-
-            // 'nameF'
-            if (current->get(8)->getType() != types::InternalType::ScilabString)
-            {
-                return false;
-            }
-            types::String* nameFField = current->get(8)->getAs<types::String>();
-            if (!nameFField->isScalar())
-            {
-                return false;
-            }
-
-            // 'funtxt'
-            if (current->get(9)->getType() == types::InternalType::ScilabDouble)
-            {
-                types::Double* funtxtFieldDouble = current->get(9)->getAs<types::Double>();
-                if (funtxtFieldDouble->getSize() != 0)
-                {
-                    return false;
-                }
-            }
-            else
-            {
-                if (current->get(9)->getType() != types::InternalType::ScilabString)
-                {
-                    return false;
-                }
-                types::String* funtxtField = current->get(9)->getAs<types::String>();
-                // FIXME: find a related test-case
-            }
-        }
-        else
-        {
-            return false;
-        }
-
-        // 'v' is OK, now perform the actual encoding
         std::vector<double> exprs;
         if (!var2vec(v, exprs))
         {