fixed bug_10121 : pass the file in hdf5
[scilab.git] / scilab / modules / scicos / src / cpp / view_scilab / GraphicsAdapter.cpp
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2014-2014 - Scilab Enterprises - Clement DAVID
4  *
5  *  This file must be used under the terms of the CeCILL.
6  *  This source file is licensed as described in the file COPYING, which
7  *  you should have received as part of this distribution.  The terms
8  *  are also available at
9  *  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10  *
11  */
12
13 #include <cwchar>
14
15 #include <string>
16 #include <vector>
17 #include <sstream>
18
19 #include "list.hxx"
20 #include "tlist.hxx"
21 #include "double.hxx"
22 #include "string.hxx"
23
24 #include "utilities.hxx"
25 #include "Controller.hxx"
26 #include "GraphicsAdapter.hxx"
27 #include "ports_management.hxx"
28
29 extern "C" {
30 #include "sci_malloc.h"
31 #include "charEncoding.h"
32 }
33
34 namespace org_scilab_modules_scicos
35 {
36 namespace view_scilab
37 {
38 namespace
39 {
40
41 const std::wstring MBLOCK (L"MBLOCK");
42 const std::wstring MPBLOCK (L"MPBLOCK");
43 const std::wstring in (L"in");
44 const std::wstring intype (L"intype");
45 const std::wstring out (L"out");
46 const std::wstring outtype (L"outtype");
47 const std::wstring param (L"param");
48 const std::wstring paramv (L"paramv");
49 const std::wstring pprop (L"pprop");
50 const std::wstring nameF (L"nameF");
51 const std::wstring funtxt (L"funtxt");
52
53 struct orig
54 {
55
56     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
57     {
58         double* data;
59         types::Double* o = new types::Double(1, 2, &data);
60         ScicosID adaptee = adaptor.getAdaptee()->id();
61
62         std::vector<double> geom;
63         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
64
65         data[0] = geom[0];
66         data[1] = geom[1];
67
68         return o;
69     }
70
71     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
72     {
73
74         if (v->getType() != types::InternalType::ScilabDouble)
75         {
76             return false;
77         }
78
79         types::Double* current = v->getAs<types::Double>();
80         if (current->getSize() != 2)
81         {
82             return false;
83         }
84
85         ScicosID adaptee = adaptor.getAdaptee()->id();
86         std::vector<double> geom;
87         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
88
89         geom[0] = current->get(0);
90         geom[1] = current->get(1);
91
92         controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
93         return true;
94     }
95 };
96
97 struct sz
98 {
99
100     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
101     {
102         double* data;
103         types::Double* o = new types::Double(1, 2, &data);
104         ScicosID adaptee = adaptor.getAdaptee()->id();
105
106         std::vector<double> geom;
107         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
108
109         data[0] = geom[2];
110         data[1] = geom[3];
111         return o;
112     }
113
114     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
115     {
116         if (v->getType() != types::InternalType::ScilabDouble)
117         {
118             return false;
119         }
120
121         types::Double* current = v->getAs<types::Double>();
122         if (current->getSize() != 2)
123         {
124             return false;
125         }
126
127         ScicosID adaptee = adaptor.getAdaptee()->id();
128         std::vector<double> geom;
129         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
130
131         geom[2] = current->get(0);
132         geom[3] = current->get(1);
133
134         controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
135         return true;
136     }
137 };
138
139 struct flip
140 {
141
142     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
143     {
144         int* data;
145         types::Bool* o = new types::Bool(1, 1, &data);
146         ScicosID adaptee = adaptor.getAdaptee()->id();
147
148         std::vector<double> angle;
149         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
150
151         data[0] = static_cast<int>(angle[0]);
152         return o;
153     }
154
155     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
156     {
157         if (v->getType() != types::InternalType::ScilabBool)
158         {
159             return false;
160         }
161
162         types::Bool* current = v->getAs<types::Bool>();
163         if (current->isScalar() != true)
164         {
165             return false;
166         }
167
168         ScicosID adaptee = adaptor.getAdaptee()->id();
169         std::vector<double> angle;
170         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
171
172         angle[0] = (current->get(0) == false) ? 0 : 1;
173
174         controller.setObjectProperty(adaptee, BLOCK, ANGLE, angle);
175         return true;
176     }
177 };
178
179 struct theta
180 {
181
182     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
183     {
184         double* data;
185         types::Double* o = new types::Double(1, 1, &data);
186         ScicosID adaptee = adaptor.getAdaptee()->id();
187
188         std::vector<double> angle;
189         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
190
191         data[0] = angle[1];
192         return o;
193     }
194
195     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
196     {
197         if (v->getType() != types::InternalType::ScilabDouble)
198         {
199             return false;
200         }
201
202         types::Double* current = v->getAs<types::Double>();
203         if (current->isScalar() != true)
204         {
205             return false;
206         }
207
208         ScicosID adaptee = adaptor.getAdaptee()->id();
209         std::vector<double> angle;
210         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
211
212         angle[1] = current->get(0);
213
214         controller.setObjectProperty(adaptee, BLOCK, ANGLE, angle);
215         return true;
216     }
217 };
218
219 struct exprs
220 {
221
222     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
223     {
224         ScicosID adaptee = adaptor.getAdaptee()->id();
225
226         std::vector<std::string> exprs;
227         controller.getObjectProperty(adaptee, BLOCK, EXPRS, exprs);
228
229         if (exprs.empty())
230         {
231             return 0;
232         }
233         else if (exprs[0] == "List_fortran")
234         {
235             // Get and return a list
236             types::List* o = new types::List();
237
238             // Element #1: Block parameters
239             std::istringstream nParamsStr (exprs[1]);
240             int nParams;
241             nParamsStr >> nParams;
242             if (nParams == 0)
243             {
244                 types::Double* paramsField = types::Double::Empty();
245                 o->append(paramsField);
246             }
247             else
248             {
249                 types::String* paramsField = new types::String(nParams, 1);
250                 for (int i = 0; i < nParams; ++i)
251                 {
252                     paramsField->set(i, exprs[2 + i].c_str());
253                 }
254                 o->append(paramsField);
255             }
256
257             // Element #2: List containing an empty matrix (default value)
258             types::List* emptyMatrixList = new types::List();
259             types::Double* emptyMatrix = types::Double::Empty();
260             emptyMatrixList->append(emptyMatrix);
261             o->append(emptyMatrixList);
262
263             return o;
264         }
265         else if (exprs[0] == "List_scifunc")
266         {
267             // Get and return a list
268             types::List* o = new types::List();
269
270             // Element #1: Block parameters
271             std::istringstream nParamsStr (exprs[1]);
272             int nParams;
273             nParamsStr >> nParams;
274             if (nParams == 0)
275             {
276                 types::Double* paramsField = types::Double::Empty();
277                 o->append(paramsField);
278             }
279             else
280             {
281                 types::String* paramsField = new types::String(nParams, 1);
282                 for (int i = 0; i < nParams; ++i)
283                 {
284                     paramsField->set(i, exprs[2 + i].c_str());
285                 }
286                 o->append(paramsField);
287             }
288
289             // Element #2: Code parts
290             types::List* codePartsField = new types::List();
291
292             for (int i = 0; i < 7; ++i)
293             {
294                 std::istringstream nLinesStr (exprs[2 + nParams]);
295                 int nLines;
296                 nLinesStr >> nLines;
297                 if (nLines == 0)
298                 {
299                     // Null 'nLines' signals an empty matrix
300                     types::Double* empty_matrix = types::Double::Empty();
301                     codePartsField->append(empty_matrix);
302                 }
303                 else
304                 {
305                     types::String* part = new types::String(nLines, 1);
306                     for (int j = 0; j < nLines; ++j)
307                     {
308                         part->set(j, exprs[2 + nParams + 1 + j].c_str());
309                     }
310                     codePartsField->append(part);
311                 }
312
313                 nParams += nLines + 1;
314             }
315             o->append(codePartsField);
316
317             return o;
318         }
319         else if (exprs[0] == "List_code" || exprs[0] == "List_super")
320         {
321             // Get and return a list
322             types::List* o = new types::List();
323
324             // Element #1: Default values
325             std::istringstream nParamsStr (exprs[1]);
326             int nParams;
327             nParamsStr >> nParams;
328             if (nParams == 0)
329             {
330                 types::Double* defaultValuesField = types::Double::Empty();
331                 o->append(defaultValuesField);
332             }
333             else
334             {
335                 types::String* defaultValuesField = new types::String(nParams, 1);
336                 for (int i = 0; i < nParams; ++i)
337                 {
338                     defaultValuesField->set(i, exprs[2 + i].c_str());
339                 }
340                 o->append(defaultValuesField);
341             }
342
343             // Element #2 depends on the block kind
344             if (exprs[0] == "List_code")
345             {
346                 std::istringstream nLinesStr (exprs[2 + nParams]);
347                 int nLines;
348                 nLinesStr >> nLines;
349                 if (nLines == 0)
350                 {
351                     types::Double* functionBodyField = types::Double::Empty();
352                     o->append(functionBodyField);
353                 }
354                 else
355                 {
356                     types::String* functionBodyField = new types::String(nLines, 1);
357                     for (int i = 0; i < nLines; ++i)
358                     {
359                         functionBodyField->set(i, exprs[2 + nParams + 1 + i].c_str());
360                     }
361                     o->append(functionBodyField);
362                 }
363             }
364             else // List_super
365             {
366                 types::List* secondElement = new types::List();
367
368                 // Paramaters names
369                 if (nParams == 0)
370                 {
371                     types::Double* namesField = types::Double::Empty();
372                     secondElement->append(namesField);
373                 }
374                 else
375                 {
376                     types::String* namesField = new types::String(nParams, 1);
377                     for (int i = 0; i < nParams; ++i)
378                     {
379                         namesField->set(i, exprs[2 + nParams + i].c_str());
380                     }
381                     secondElement->append(namesField);
382                 }
383
384                 // Title message and paramaters decriptions
385                 types::String* titleField = new types::String(nParams + 1, 1);
386                 for (int i = 0; i < nParams + 1; ++i)
387                 {
388                     titleField->set(i, exprs[2 + 2 * nParams + i].c_str());
389                 }
390                 secondElement->append(titleField);
391
392                 // Parameters types and sizes
393                 types::List* typesAndSizes = new types::List();
394
395                 if (nParams == 0)
396                 {
397                     types::Double* typeSizeField = types::Double::Empty();
398                     typesAndSizes->append(typeSizeField);
399                 }
400                 else
401                 {
402                     for (int i = 0; i < nParams; ++i)
403                     {
404                         // Read type
405                         types::String* Type = new types::String(exprs[2 + 3 * nParams + 1 + i].c_str());
406                         typesAndSizes->append(Type);
407
408                         // Read size
409                         std::istringstream sizeStr (exprs[2 + 4 * nParams + 1 + i]);
410                         int size;
411                         sizeStr >> size;
412                         types::Double* Size = new types::Double(size);
413                         typesAndSizes->append(Size);
414                     }
415                 }
416                 secondElement->append(typesAndSizes);
417
418                 o->append(secondElement);
419             }
420
421             return o;
422         }
423         else if (exprs[0] == "List_MBLOCK" || exprs[0] == "List_MPBLOCK")
424         {
425             // Get and return a Modelica tlist
426             types::TList* o = new types::TList();
427
428             // Header, starting with "List_MBLOCK"
429             types::String* header = new types::String(1, 10);
430             if (exprs[0] == "List_MBLOCK")
431             {
432                 header->set(0, MBLOCK.c_str());
433             }
434             else
435             {
436                 header->set(0, MPBLOCK.c_str());
437             }
438             header->set(1, in.c_str());
439             header->set(2, intype.c_str());
440             header->set(3, out.c_str());
441             header->set(4, outtype.c_str());
442             header->set(5, param.c_str());
443             header->set(6, paramv.c_str());
444             header->set(7, pprop.c_str());
445             header->set(8, nameF.c_str());
446             header->set(9, funtxt.c_str());
447             o->append(header);
448
449             // 'in'
450             types::String* inField = new types::String(exprs[1].c_str());
451             o->append(inField);
452
453             // 'intype'
454             types::String* intypeField = new types::String(exprs[2].c_str());
455             o->append(intypeField);
456
457             // 'out'
458             types::String* outField = new types::String(exprs[3].c_str());
459             o->append(outField);
460
461             // 'outtype'
462             types::String* outtypeField = new types::String(exprs[4].c_str());
463             o->append(outtypeField);
464
465             // 'param'
466             types::String* paramField = new types::String(exprs[5].c_str());
467             o->append(paramField);
468
469             // 'paramv'
470             types::List* paramvField = new types::List();
471             std::istringstream paramvSizeStr (exprs[6]);
472             int paramvSize;
473             paramvSizeStr >> paramvSize;
474             for (int i = 0; i < paramvSize; ++i)
475             {
476                 types::String* paramvElement = new types::String(exprs[7 + i].c_str());
477                 paramvField->set(i, paramvElement);
478             }
479             o->append(paramvField);
480
481             // 'pprop'
482             types::String* ppropField = new types::String(exprs[7 + paramvSize].c_str());
483             o->append(ppropField);
484
485             // 'nameF'
486             types::String* nameFField = new types::String(exprs[7 + paramvSize + 1].c_str());
487             o->append(nameFField);
488
489             // 'funtxt'
490             std::istringstream funtxtSizeStr (exprs[7 + paramvSize + 2]);
491             int funtxtSize;
492             funtxtSizeStr >> funtxtSize;
493
494             if (funtxtSize == 0)
495             {
496                 // An empty 'funtxt' field returns an empty matrix
497                 o->append(types::Double::Empty());
498                 return o;
499             }
500             types::String* funtxtField = new types::String(funtxtSize, 1);
501             for (int i = 0; i < funtxtSize; ++i)
502             {
503                 funtxtField->set(i, exprs[7 + paramvSize + 3 + i].c_str());
504             }
505             o->append(funtxtField);
506
507             return o;
508         }
509         else if (exprs[0] == "List_PDE")
510         {
511             // Get and return a PDE list
512             types::List* o = new types::List();
513
514             // Parameters
515             types::TList* params = new types::TList();
516
517             // First, the header
518             std::istringstream nParamsStr (exprs[1]);
519             int nParams;
520             nParamsStr >> nParams;
521             types::String* header = new types::String(nParams + 1, 1); // The first element of the header is the TList type
522             for (int i = 0; i < nParams + 1; ++i)
523             {
524                 header->set(i, exprs[2 + i].c_str());
525             }
526             params->append(header);
527
528             // Then, the content
529             for (int i = 0; i < nParams - 1; ++i) // Stop at 'nParams-1' to get the last element as a string matrix
530             {
531                 types::String* paramsElement = new types::String(exprs[3 + nParams + i].c_str());
532                 params->append(paramsElement);
533             }
534             // Last element of the content (string matrix)
535             std::istringstream nColsStr (exprs[3 + 2 * nParams]);
536             int nCols;
537             nColsStr >> nCols;
538             types::String* last_string = new types::String(nCols, 1);
539             for (int i = 0; i < nCols; ++i)
540             {
541                 last_string->set(i, exprs[4 + 2 * nParams + i].c_str());
542             }
543             params->append(last_string);
544
545             o->append(params);
546
547             // Next, the code
548             std::istringstream nLinesStr (exprs[4 + 2 * nParams + nCols]);
549             int nLines;
550             nLinesStr >> nLines;
551             if (nLines == 0)
552             {
553                 types::Double* empty_matrix = types::Double::Empty();
554                 o->append(empty_matrix);
555             }
556             else
557             {
558                 types::String* code = new types::String(nLines, 1);
559                 for (int i = 0; i < nLines + 1; ++i)
560                 {
561                     code->set(i, exprs[5 + 2 * nParams + nCols + i].c_str());
562                 }
563                 o->append(code);
564             }
565
566             // Finally, the block name
567             types::String* name = new types::String(exprs[5 + 2 * nParams + nCols + nLines].c_str());
568             o->append(name);
569
570             return o;
571         }
572         else if (exprs[0] == "List_CONSTRAINT")
573         {
574             // Get and return a CONSTRAINT2_c list
575             types::List* o = new types::List();
576
577             // A "CONSTRAINT2_c" block has 3 strings in 'exprs'
578             for (int i = 1; i < 4; ++i)
579             {
580                 types::String* ithElement = new types::String(exprs[i].c_str());
581                 o->append(ithElement);
582             }
583             return o;
584         }
585         else if (exprs[0] == "List_LOOKUP2D")
586         {
587             // Get and return a LOOKUP2D list
588             types::List* o = new types::List();
589
590             // A "LOOKUP2D" block has 5 strings in 'exprs'
591             for (int i = 1; i < 6; ++i)
592             {
593                 types::String* ithElement = new types::String(exprs[i].c_str());
594                 o->append(ithElement);
595             }
596             return o;
597         }
598         else if (exprs[0] == "String")
599         {
600             // Simple case, 'exprs' is a string matrix (can be empty)
601             if (exprs.size() == 1)
602             {
603                 return types::Double::Empty();
604             }
605             types::String* o = new types::String((int)exprs.size() - 1, 1);
606             for (int i = 0; i < (int)exprs.size() - 1; ++i)
607             {
608                 o->set(i, exprs[i + 1].data());
609             }
610             return o;
611         }
612         else
613         {
614             return 0;
615         }
616     }
617
618     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
619     {
620         ScicosID adaptee = adaptor.getAdaptee()->id();
621
622         std::vector<std::string> exprs (1); // First element will contain "String", "List_code", "List_super, "List_scifunc", "List_fortran", "List_MBLOCK" or "List_PDE"
623
624         if (v->getType() == types::InternalType::ScilabString)
625         {
626             types::String* current = v->getAs<types::String>();
627
628             exprs[0] = "String";
629             exprs.resize(1 + current->getSize());
630             for (int i = 1; i < (int)exprs.size(); ++i)
631             {
632                 char* c_str = wide_string_to_UTF8(current->get(i - 1));
633                 exprs[i] = std::string(c_str);
634                 FREE(c_str);
635             }
636         }
637         else if (v->getType() == types::InternalType::ScilabDouble)
638         {
639             types::Double* current = v->getAs<types::Double>();
640             if (!current->isEmpty())
641             {
642                 return false;
643             }
644
645             exprs[0] = "String";
646         }
647         else if (v->getType() == types::InternalType::ScilabList)
648         {
649             types::List* initial_list = v->getAs<types::List>();
650
651             // Leave 'exprs[0]' empty for the moment, because we don't know yet what we are going to deal with
652             char* c_str; // Buffer
653
654             // All these blocks have two elements in 'exprs', except for blocks "PDE", "CONSTRAINT2_c" and "LOOKUP2D"
655             if (initial_list->getSize() == 2)
656             {
657                 size_t nParams = 0;
658                 // Whatever the block kind, the first element is necessarily a string matrix (can be empty)
659                 if (initial_list->get(0)->getType() == types::InternalType::ScilabDouble)
660                 {
661                     types::Double* empty_matrix_expected = initial_list->get(0)->getAs<types::Double>();
662                     if (empty_matrix_expected->getSize() != 0)
663                     {
664                         return false;
665                     }
666                     exprs.resize(2);
667                     exprs[1] = "0"; // Indicating empty matrix
668                 }
669                 else if (initial_list->get(0)->getType() == types::InternalType::ScilabString)
670                 {
671                     types::String* initial_string = initial_list->get(0)->getAs<types::String>();
672
673                     nParams = initial_string->getSize();
674                     exprs.resize(exprs.size() + 1 + nParams); // Allocation for the first string
675                     std::ostringstream strSize;
676                     strSize << nParams;
677                     std::string sizeStr = strSize.str();
678                     exprs[1] = sizeStr; // Saving the size of the initial string
679
680                     for (size_t i = 0; i < nParams; ++i)
681                     {
682                         c_str = wide_string_to_UTF8(initial_string->get(i));
683                         std::string stringElement(c_str);
684                         FREE(c_str);
685                         exprs[2 + i] = stringElement;
686                     }
687                 }
688                 else
689                 {
690                     return false;
691                 }
692
693                 // The second element determines the block kind
694                 if (initial_list->get(1)->getType() == types::InternalType::ScilabDouble)
695                 {
696                     types::Double* empty_matrix_expected = initial_list->get(1)->getAs<types::Double>();
697                     if (!empty_matrix_expected->isEmpty())
698                     {
699                         return false;
700                     }
701
702                     exprs[0] = "List_code"; // List coming from a C block
703                     exprs.push_back("0"); // Indicating empty matrix
704                 }
705                 else if (initial_list->get(1)->getType() == types::InternalType::ScilabString)
706                 {
707                     types::String* second_string = initial_list->get(1)->getAs<types::String>();
708
709                     exprs[0] = "List_code"; // List coming from a "user-defined function" block
710                     size_t second_size = second_string->getSize();
711                     int exprsSize = exprs.size(); // Saving last index before resizing
712                     exprs.resize(exprs.size() + 1 + second_size); // Allocation for the first string
713                     std::ostringstream strSize2;
714                     strSize2 << second_size;
715                     std::string sizeStr2 = strSize2.str();
716                     exprs[exprsSize] = sizeStr2; // Saving the size of the second string
717
718                     for (size_t i = 0; i < second_size; ++i)
719                     {
720                         c_str = wide_string_to_UTF8(second_string->get(i));
721                         std::string stringElement(c_str);
722                         FREE(c_str);
723                         exprs[exprsSize + 1 + i] = stringElement;
724                     }
725                 }
726                 else if (initial_list->get(1)->getType() == types::InternalType::ScilabList)
727                 {
728                     types::List* second_list = initial_list->get(1)->getAs<types::List>();
729
730                     if (second_list->getSize() == 1)
731                     {
732                         // Default fortran_block value: must contain an empty matrix
733                         if (second_list->get(0)->getType() != types::InternalType::ScilabDouble)
734                         {
735                             return false;
736                         }
737                         types::Double* empty = second_list->get(0)->getAs<types::Double>();
738                         if (!empty->isEmpty())
739                         {
740                             return false;
741                         }
742                         exprs[0] = "List_fortran"; // List coming from a fortran_block
743                     }
744                     else if (second_list->getSize() == 3)
745                     {
746                         // Parameter names, Title message and Parameters types & sizes
747                         exprs[0] = "List_super"; // List coming from a SuperBlock (masked or not)
748
749                         // Parameters Names (string matrix, can be empty)
750                         if (second_list->get(0)->getType() == types::InternalType::ScilabDouble)
751                         {
752                             types::Double* empty_matrix_expected = second_list->get(0)->getAs<types::Double>();
753                             if (empty_matrix_expected->getSize() != 0)
754                             {
755                                 return false;
756                             }
757                             // No parameters are present, so nothing needs to be saved
758                         }
759                         else if (second_list->get(0)->getType() == types::InternalType::ScilabString)
760                         {
761                             types::String* second_string = second_list->get(0)->getAs<types::String>();
762
763                             if (second_string->getSize() != static_cast<int>(nParams))
764                             {
765                                 return false;
766                             }
767
768                             int exprsSize = exprs.size(); // Saving last index before resizing
769                             exprs.resize(exprs.size() + nParams); // Allocation for the first string
770
771                             for (size_t i = 0; i < nParams; ++i)
772                             {
773                                 c_str = wide_string_to_UTF8(second_string->get(i));
774                                 std::string stringElement(c_str);
775                                 FREE(c_str);
776                                 exprs[exprsSize + i] = stringElement;
777                             }
778                         }
779                         else
780                         {
781                             return false;
782                         }
783
784                         // Title message (string matrix, can be empty)
785                         if (second_list->get(1)->getType() == types::InternalType::ScilabDouble)
786                         {
787                             types::Double* empty_matrix_expected = second_list->get(1)->getAs<types::Double>();
788                             if (empty_matrix_expected->getSize() != 0 || nParams != 0)
789                             {
790                                 return false;
791                             }
792                             // No parameters are present, so nothing needs to be saved
793                         }
794                         else if (second_list->get(1)->getType() == types::InternalType::ScilabString)
795                         {
796                             types::String* title_message = second_list->get(1)->getAs<types::String>();
797                             if (title_message->getSize() != static_cast<int>(nParams + 1))
798                             {
799                                 // There must be as many parameter descriptions as there are parameters, plus the title message
800                                 return false;
801                             }
802
803                             int exprsSize = exprs.size(); // Saving last index before resizing
804                             exprs.resize(exprs.size() + nParams + 1); // Allocation for the first string, minding the title message
805
806                             for (size_t i = 0; i < nParams + 1; ++i)
807                             {
808                                 c_str = wide_string_to_UTF8(title_message->get(i));
809                                 std::string stringElement(c_str);
810                                 FREE(c_str);
811                                 exprs[exprsSize + i] = stringElement;
812                             }
813                         }
814                         else
815                         {
816                             return false;
817                         }
818
819                         // Parameters types & sizes (list mixing strings and integers, can be empty)
820                         if (second_list->get(2)->getType() != types::InternalType::ScilabList)
821                         {
822                             return false;
823                         }
824                         types::List* third_list = second_list->get(2)->getAs<types::List>();
825
826                         if (third_list->getSize() != static_cast<int>(2 * nParams))
827                         {
828                             // There must be one type and one size for each parameter, so '2*nParams' elements
829                             if (!(third_list->getSize() == 1 && nParams == 0))
830                             {
831                                 // Allow third_list != 2*params only for the dummy case 'third_list=list([])'. Do nothing then
832                                 return false;
833                             }
834                         }
835
836                         // First, read all types
837                         for (size_t i = 0; i < nParams; ++i)
838                         {
839                             if (third_list->get(2 * i)->getType() != types::InternalType::ScilabString)
840                             {
841                                 return false;
842                             }
843                             types::String* paramType = third_list->get(2 * i)->getAs<types::String>();
844                             if (!paramType->isScalar())
845                             {
846                                 return false;
847                             }
848                             c_str = wide_string_to_UTF8(paramType->get(0));
849                             std::string paramTypeStored(c_str);
850                             FREE(c_str);
851
852                             exprs.push_back(paramTypeStored);
853                         }
854                         // Then, read all sizes
855                         for (size_t i = 0; i < nParams; ++i)
856                         {
857                             if (third_list->get(2 * i + 1)->getType() != types::InternalType::ScilabDouble)
858                             {
859                                 return false;
860                             }
861                             types::Double* paramSize = third_list->get(2 * i + 1)->getAs<types::Double>();
862                             if (!paramSize->isScalar())
863                             {
864                                 return false;
865                             }
866
867                             std::ostringstream paramSizeStored;
868                             paramSizeStored << paramSize->get(0);
869                             std::string paramSizeStr = paramSizeStored.str();
870                             exprs.push_back(paramSizeStr);
871                         }
872                     }
873                     else if (second_list->getSize() == 7)
874                     {
875                         exprs[0] = "List_scifunc"; // List coming from a scifunc block
876
877                         // Code parts (string matrices)
878                         for (int i = 0; i < 7; ++i)
879                         {
880                             if (second_list->get(i)->getType() == types::InternalType::ScilabDouble)
881                             {
882                                 types::Double* ith_double = second_list->get(i)->getAs<types::Double>();
883                                 if (!ith_double->isEmpty())
884                                 {
885                                     return false;
886                                 }
887                                 exprs.push_back(std::string("0"));
888                             }
889                             else if (second_list->get(i)->getType() == types::InternalType::ScilabString)
890                             {
891                                 types::String* ith_string = second_list->get(i)->getAs<types::String>();
892                                 size_t stringSize = ith_string->getSize();
893                                 int exprsSize = exprs.size(); // Saving last index before resizing
894                                 exprs.resize(exprs.size() + 1 + stringSize); // Allocation for the first string
895                                 std::ostringstream strSizeIth;
896                                 strSizeIth << stringSize;
897                                 std::string sizeStrIth = strSizeIth.str();
898                                 exprs[exprsSize] = sizeStrIth; // Saving the size of the ith string
899
900                                 for (size_t j = 0; j < stringSize; ++j)
901                                 {
902                                     c_str = wide_string_to_UTF8(ith_string->get(j));
903                                     std::string ithStringElement(c_str);
904                                     FREE(c_str);
905                                     exprs[exprsSize + 1 + j] = ithStringElement;
906                                 }
907                             }
908                             else
909                             {
910                                 return false;
911                             }
912                         }
913                     }
914                     else
915                     {
916                         return false;
917                     }
918                 }
919                 else
920                 {
921                     return false;
922                 }
923             }
924             else if (initial_list->getSize() == 3)
925             {
926                 if (initial_list->get(0)->getType() == types::InternalType::ScilabTList)
927                 {
928                     exprs[0] = "List_PDE"; // List coming from a PDE block
929                     types::TList* ParamsPDE = initial_list->get(0)->getAs<types::TList>();
930
931                     types::String* header = ParamsPDE->getFieldNames();
932                     int nParams = header->getSize() - 1; // The first element is the TList type
933                     exprs.resize(3 + 2 * nParams); // Allocation for the header size, the TList type and the header
934                     // Save the header size
935                     std::ostringstream strNParams;
936                     strNParams << nParams;
937                     std::string nParamsStr = strNParams.str();
938                     exprs[1] = nParamsStr; // Saving the header size
939                     // Save the TList type
940                     c_str = wide_string_to_UTF8(header->get(0));
941                     std::string tlistType(c_str);
942                     FREE(c_str);
943                     exprs[2] = tlistType;
944
945                     // Save the header
946                     for (int i = 1; i < nParams; ++i) // Stop at 'nParams-1' to treat the last element differently (string matrix)
947                     {
948                         // Header element
949                         c_str = wide_string_to_UTF8(header->get(i));
950                         std::string headerElement(c_str);
951                         FREE(c_str);
952                         exprs[2 + i] = headerElement;
953
954                         // Its corresponding element in the TList
955                         if (ParamsPDE->get(i)->getType() != types::InternalType::ScilabString)
956                         {
957                             return false;
958                         }
959                         types::String* ith_string = ParamsPDE->get(i)->getAs<types::String>();
960                         if (!ith_string->isScalar())
961                         {
962                             return false;
963                         }
964                         c_str = wide_string_to_UTF8(ith_string->get(0));
965                         std::string stringElement(c_str);
966                         FREE(c_str);
967                         exprs[2 + nParams + i] = stringElement;
968                     }
969                     // Header element for the last element of ParamsPDE
970                     c_str = wide_string_to_UTF8(header->get(nParams));
971                     std::string lastHeaderElement(c_str);
972                     FREE(c_str);
973                     exprs[2 + nParams] = lastHeaderElement;
974                     if (ParamsPDE->get(nParams)->getType() != types::InternalType::ScilabString)
975                     {
976                         return false;
977                     }
978                     types::String* last_string = ParamsPDE->get(nParams)->getAs<types::String>();
979
980                     int nCols = last_string->getSize();
981                     int exprsSize = exprs.size(); // Saving last index before resizing
982                     exprs.resize(exprs.size() + 1 + nCols); // Store the size of the last string because it can be a matrix
983                     std::ostringstream strSize;
984                     strSize << nCols;
985                     std::string sizeStr = strSize.str();
986                     exprs[exprsSize] = sizeStr;
987
988                     for (int i = 0; i < nCols; ++i)
989                     {
990                         c_str = wide_string_to_UTF8(last_string->get(i));
991                         std::string lastStringElement(c_str);
992                         FREE(c_str);
993                         exprs[exprsSize + 1 + i] = lastStringElement;
994                     }
995
996                     // Next comes some code
997                     if (initial_list->get(1)->getType() == types::InternalType::ScilabDouble)
998                     {
999                         types::Double* empty_matrix_expected = initial_list->get(1)->getAs<types::Double>();
1000                         if (!empty_matrix_expected->isEmpty())
1001                         {
1002                             return false;
1003                         }
1004                         exprs.push_back("0"); // Indicating empty matrix
1005                     }
1006                     else if (initial_list->get(1)->getType() == types::InternalType::ScilabString)
1007                     {
1008                         types::String* code = initial_list->get(1)->getAs<types::String>();
1009
1010                         int nLines = code->getSize();
1011                         exprsSize = exprs.size(); // Saving last index before resizing
1012                         exprs.resize(exprs.size() + 1 + nLines); // Store the size of the last string because it can be a matrix
1013                         std::ostringstream strLines;
1014                         strLines << nLines;
1015                         std::string linesStr = strLines.str();
1016                         exprs[exprsSize] = linesStr;
1017
1018                         for (int i = 0; i < nLines; ++i)
1019                         {
1020                             c_str = wide_string_to_UTF8(code->get(i));
1021                             std::string codeElement(c_str);
1022                             FREE(c_str);
1023                             exprs[exprsSize + 1 + i] = codeElement;
1024                         }
1025                     }
1026                     else
1027                     {
1028                         return false;
1029                     }
1030
1031                     // Finally, the block name
1032                     if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
1033                     {
1034                         return false;
1035                     }
1036                     types::String* name = initial_list->get(2)->getAs<types::String>();
1037                     if (!name->isScalar())
1038                     {
1039                         return false;
1040                     }
1041                     c_str = wide_string_to_UTF8(name->get(0));
1042                     std::string nameStr(c_str);
1043                     FREE(c_str);
1044                     exprs.push_back(nameStr);
1045                 }
1046                 else if (initial_list->get(0)->getType() == types::InternalType::ScilabString)
1047                 {
1048                     exprs[0] = "List_CONSTRAINT"; // List coming from a CONSTRAINT2_c block
1049
1050                     types::String* x = initial_list->get(0)->getAs<types::String>();
1051                     if (!x->isScalar())
1052                     {
1053                         return false;
1054                     }
1055                     c_str = wide_string_to_UTF8(x->get(0));
1056                     std::string xStr(c_str);
1057                     FREE(c_str);
1058                     exprs.push_back(xStr);
1059
1060                     if (initial_list->get(1)->getType() != types::InternalType::ScilabString)
1061                     {
1062                         return false;
1063                     }
1064                     types::String* xd = initial_list->get(1)->getAs<types::String>();
1065                     if (!xd->isScalar())
1066                     {
1067                         return false;
1068                     }
1069                     c_str = wide_string_to_UTF8(xd->get(0));
1070                     std::string xdStr(c_str);
1071                     FREE(c_str);
1072                     exprs.push_back(xdStr);
1073
1074                     if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
1075                     {
1076                         return false;
1077                     }
1078                     types::String* id = initial_list->get(2)->getAs<types::String>();
1079                     if (!id->isScalar())
1080                     {
1081                         return false;
1082                     }
1083                     c_str = wide_string_to_UTF8(id->get(0));
1084                     std::string idStr(c_str);
1085                     FREE(c_str);
1086                     exprs.push_back(idStr);
1087                 }
1088                 else
1089                 {
1090                     return false;
1091                 }
1092             }
1093             else if (initial_list->getSize() == 5)
1094             {
1095                 exprs[0] = "List_LOOKUP2D"; // List coming from a LOOKUP2D block
1096
1097                 types::String* xx = initial_list->get(0)->getAs<types::String>();
1098                 if (!xx->isScalar())
1099                 {
1100                     return false;
1101                 }
1102                 c_str = wide_string_to_UTF8(xx->get(0));
1103                 std::string xxStr(c_str);
1104                 FREE(c_str);
1105                 exprs.push_back(xxStr);
1106
1107                 if (initial_list->get(1)->getType() != types::InternalType::ScilabString)
1108                 {
1109                     return false;
1110                 }
1111                 types::String* yy = initial_list->get(1)->getAs<types::String>();
1112                 if (!yy->isScalar())
1113                 {
1114                     return false;
1115                 }
1116                 c_str = wide_string_to_UTF8(yy->get(0));
1117                 std::string yyStr(c_str);
1118                 FREE(c_str);
1119                 exprs.push_back(yyStr);
1120
1121                 if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
1122                 {
1123                     return false;
1124                 }
1125                 types::String* zz = initial_list->get(2)->getAs<types::String>();
1126                 if (!zz->isScalar())
1127                 {
1128                     return false;
1129                 }
1130                 c_str = wide_string_to_UTF8(zz->get(0));
1131                 std::string zzStr(c_str);
1132                 FREE(c_str);
1133                 exprs.push_back(zzStr);
1134
1135                 if (initial_list->get(3)->getType() != types::InternalType::ScilabString)
1136                 {
1137                     return false;
1138                 }
1139                 types::String* Method = initial_list->get(3)->getAs<types::String>();
1140                 if (!Method->isScalar())
1141                 {
1142                     return false;
1143                 }
1144                 c_str = wide_string_to_UTF8(Method->get(0));
1145                 std::string MethodStr(c_str);
1146                 FREE(c_str);
1147                 exprs.push_back(MethodStr);
1148
1149                 if (initial_list->get(4)->getType() != types::InternalType::ScilabString)
1150                 {
1151                     return false;
1152                 }
1153                 types::String* Graf = initial_list->get(4)->getAs<types::String>();
1154                 if (!Graf->isScalar())
1155                 {
1156                     return false;
1157                 }
1158                 c_str = wide_string_to_UTF8(Graf->get(0));
1159                 std::string GrafStr(c_str);
1160                 FREE(c_str);
1161                 exprs.push_back(GrafStr);
1162             }
1163             else
1164             {
1165                 return false;
1166             }
1167         }
1168         else if (v->getType() == types::InternalType::ScilabTList)
1169         {
1170             types::TList* current = v->getAs<types::TList>();
1171
1172             // Check the header
1173             types::String* header = current->getFieldNames();
1174             if (header->getSize() != 10)
1175             {
1176                 return false;
1177             }
1178             if (header->get(0) == MBLOCK)
1179             {
1180                 exprs[0] = "List_MBLOCK"; // TList coming from an MBLOCK
1181             }
1182             else if (header->get(0) == MPBLOCK)
1183             {
1184                 exprs[0] = "List_MPBLOCK"; // TList coming from an MPBLOCK
1185             }
1186             else
1187             {
1188                 return false;
1189             }
1190             if (header->get(1) != in)
1191             {
1192                 return false;
1193             }
1194             if (header->get(2) != intype)
1195             {
1196                 return false;
1197             }
1198             if (header->get(3) != out)
1199             {
1200                 return false;
1201             }
1202             if (header->get(4) != outtype)
1203             {
1204                 return false;
1205             }
1206             if (header->get(5) != param)
1207             {
1208                 return false;
1209             }
1210             if (header->get(6) != paramv)
1211             {
1212                 return false;
1213             }
1214             if (header->get(7) != pprop)
1215             {
1216                 return false;
1217             }
1218             if (header->get(8) != nameF)
1219             {
1220                 return false;
1221             }
1222             if (header->get(9) != funtxt)
1223             {
1224                 return false;
1225             }
1226
1227             char* c_str; // Buffer
1228
1229             // 'in'
1230             if (current->get(1)->getType() != types::InternalType::ScilabString)
1231             {
1232                 return false;
1233             }
1234             types::String* inField = current->get(1)->getAs<types::String>();
1235             if (!inField->isScalar())
1236             {
1237                 return false;
1238             }
1239             c_str = wide_string_to_UTF8(inField->get(0));
1240             std::string inFieldStored(c_str);
1241             FREE(c_str);
1242             exprs.push_back(inFieldStored);
1243
1244             // 'intype'
1245             if (current->get(2)->getType() != types::InternalType::ScilabString)
1246             {
1247                 return false;
1248             }
1249             types::String* intypeField = current->get(2)->getAs<types::String>();
1250             if (!intypeField->isScalar())
1251             {
1252                 return false;
1253             }
1254             c_str = wide_string_to_UTF8(intypeField->get(0));
1255             std::string intypeFieldStored(c_str);
1256             FREE(c_str);
1257             exprs.push_back(intypeFieldStored);
1258
1259             // 'out'
1260             if (current->get(3)->getType() != types::InternalType::ScilabString)
1261             {
1262                 return false;
1263             }
1264             types::String* outField = current->get(3)->getAs<types::String>();
1265             if (!inField->isScalar())
1266             {
1267                 return false;
1268             }
1269             c_str = wide_string_to_UTF8(outField->get(0));
1270             std::string outFieldStored(c_str);
1271             FREE(c_str);
1272             exprs.push_back(outFieldStored);
1273
1274             // 'outtype'
1275             if (current->get(4)->getType() != types::InternalType::ScilabString)
1276             {
1277                 return false;
1278             }
1279             types::String* outtypeField = current->get(4)->getAs<types::String>();
1280             if (!outtypeField->isScalar())
1281             {
1282                 return false;
1283             }
1284             c_str = wide_string_to_UTF8(outtypeField->get(0));
1285             std::string outtypeFieldStored(c_str);
1286             FREE(c_str);
1287             exprs.push_back(outtypeFieldStored);
1288
1289             // 'param'
1290             if (current->get(5)->getType() != types::InternalType::ScilabString)
1291             {
1292                 return false;
1293             }
1294             types::String* paramField = current->get(5)->getAs<types::String>();
1295             if (!paramField->isScalar())
1296             {
1297                 return false;
1298             }
1299             c_str = wide_string_to_UTF8(paramField->get(0));
1300             std::string paramFieldStored(c_str);
1301             FREE(c_str);
1302             exprs.push_back(paramFieldStored);
1303
1304             // 'paramv'
1305             if (current->get(6)->getType() != types::InternalType::ScilabList)
1306             {
1307                 return false;
1308             }
1309             types::List* list = current->get(6)->getAs<types::List>();
1310
1311             size_t paramvSize = list->getSize();
1312             exprs.resize(exprs.size() + 1 + paramvSize); // Allocation for the 'paramv' strings
1313             std::ostringstream strParamv;
1314             strParamv << paramvSize;
1315             std::string paramvSizeStr = strParamv.str();
1316             exprs[6] = paramvSizeStr; // Saving the size of the 'paramv' field'
1317
1318             for (size_t i = 0; i < paramvSize; ++i)
1319             {
1320                 if (list->get(static_cast<int>(i))->getType() != types::InternalType::ScilabString)
1321                 {
1322                     return false;
1323                 }
1324                 types::String* listElement = list->get(static_cast<int>(i))->getAs<types::String>();
1325                 c_str = wide_string_to_UTF8(listElement->get(0));
1326                 std::string paramvElement(c_str);
1327                 FREE(c_str);
1328                 exprs[7 + i] = paramvElement;
1329             }
1330
1331             // 'pprop'
1332             if (current->get(7)->getType() != types::InternalType::ScilabString)
1333             {
1334                 return false;
1335             }
1336             types::String* ppropField = current->get(7)->getAs<types::String>();
1337             if (!ppropField->isScalar())
1338             {
1339                 return false;
1340             }
1341             c_str = wide_string_to_UTF8(ppropField->get(0));
1342             std::string ppropFieldStored(c_str);
1343             FREE(c_str);
1344             exprs.push_back(ppropFieldStored);
1345
1346             // 'nameF'
1347             if (current->get(8)->getType() != types::InternalType::ScilabString)
1348             {
1349                 return false;
1350             }
1351             types::String* nameFField = current->get(8)->getAs<types::String>();
1352             if (!nameFField->isScalar())
1353             {
1354                 return false;
1355             }
1356             c_str = wide_string_to_UTF8(nameFField->get(0));
1357             std::string nameFFieldStored(c_str);
1358             FREE(c_str);
1359             exprs.push_back(nameFFieldStored);
1360
1361             // 'funtxt'
1362             size_t funtxtSize;
1363             std::ostringstream strFuntxt;
1364             if (current->get(9)->getType() == types::InternalType::ScilabDouble)
1365             {
1366                 types::Double* funtxtFieldDouble = current->get(9)->getAs<types::Double>();
1367                 if (funtxtFieldDouble->getSize() != 0)
1368                 {
1369                     return false;
1370                 }
1371                 // Allow empty matrix for 'funtxt', storing a size "0"
1372                 funtxtSize = 0;
1373                 strFuntxt << funtxtSize;
1374                 std::string funtxtSizeStr = strFuntxt.str();
1375                 exprs.push_back(funtxtSizeStr);
1376             }
1377             else
1378             {
1379                 if (current->get(9)->getType() != types::InternalType::ScilabString)
1380                 {
1381                     return false;
1382                 }
1383                 types::String* funtxtField = current->get(9)->getAs<types::String>();
1384
1385                 funtxtSize = funtxtField->getSize();
1386                 size_t exprsSize = exprs.size(); // Saving last index before resizing
1387                 exprs.resize(exprs.size() + 1 + funtxtSize); // Allocation for the 'funtxt' strings
1388                 strFuntxt << funtxtSize;
1389                 std::string funtxtSizeStr = strFuntxt.str();
1390                 exprs[exprsSize] = funtxtSizeStr; // Saving the size of the 'funtxt' field'
1391
1392                 for (size_t i = 0; i < funtxtSize; ++i)
1393                 {
1394                     c_str = wide_string_to_UTF8(funtxtField->get(static_cast<int>(i)));
1395                     std::string funtxtElement(c_str);
1396                     FREE(c_str);
1397                     exprs[exprsSize + 1 + i] = funtxtElement;
1398                 }
1399             }
1400         }
1401         else
1402         {
1403             return false;
1404         }
1405
1406         controller.setObjectProperty(adaptee, BLOCK, EXPRS, exprs);
1407         return true;
1408     }
1409 };
1410
1411 struct pin
1412 {
1413
1414     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1415     {
1416         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, INPUTS, controller);
1417     }
1418
1419     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1420     {
1421         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, INPUTS, controller, v);
1422     }
1423 };
1424
1425 struct pout
1426 {
1427
1428     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1429     {
1430         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, OUTPUTS, controller);
1431     }
1432
1433     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1434     {
1435         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, OUTPUTS, controller, v);
1436     }
1437 };
1438
1439 struct pein
1440 {
1441
1442     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1443     {
1444         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_INPUTS, controller);
1445     }
1446
1447     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1448     {
1449         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_INPUTS, controller, v);
1450     }
1451 };
1452
1453 struct peout
1454 {
1455
1456     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1457     {
1458         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_OUTPUTS, controller);
1459     }
1460
1461     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1462     {
1463         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_OUTPUTS, controller, v);
1464     }
1465 };
1466
1467 struct gr_i
1468 {
1469
1470     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& /*controller*/)
1471     {
1472         return adaptor.getGrIContent();
1473     }
1474
1475     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& /*controller*/)
1476     {
1477         adaptor.setGrIContent(v->clone());
1478         return true;
1479     }
1480 };
1481
1482 struct id
1483 {
1484
1485     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1486     {
1487         ScicosID adaptee = adaptor.getAdaptee()->id();
1488
1489         std::string id;
1490         controller.getObjectProperty(adaptee, BLOCK, LABEL, id);
1491
1492         types::String* o = new types::String(1, 1);
1493         o->set(0, id.data());
1494
1495         return o;
1496     }
1497
1498     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1499     {
1500         if (v->getType() != types::InternalType::ScilabString)
1501         {
1502             return false;
1503         }
1504
1505         types::String* current = v->getAs<types::String>();
1506         if (!current->isScalar())
1507         {
1508             return false;
1509         }
1510
1511         ScicosID adaptee = adaptor.getAdaptee()->id();
1512
1513         char* c_str = wide_string_to_UTF8(current->get(0));
1514         std::string id(c_str);
1515         FREE(c_str);
1516
1517         controller.setObjectProperty(adaptee, BLOCK, LABEL, id);
1518         return true;
1519     }
1520 };
1521
1522 struct in_implicit
1523 {
1524
1525     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1526     {
1527         return get_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, INPUTS, controller);
1528     }
1529
1530     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1531     {
1532         return set_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, INPUTS, controller, v);
1533     }
1534 };
1535
1536 struct out_implicit
1537 {
1538
1539     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1540     {
1541         return get_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, OUTPUTS, controller);
1542     }
1543
1544     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1545     {
1546         return set_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, OUTPUTS, controller, v);
1547     }
1548 };
1549
1550 struct in_style
1551 {
1552
1553     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1554     {
1555         return get_ports_property<GraphicsAdapter, STYLE>(adaptor, INPUTS, controller);
1556     }
1557
1558     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1559     {
1560         return set_ports_property<GraphicsAdapter, STYLE>(adaptor, INPUTS, controller, v);
1561     }
1562 };
1563
1564 struct out_style
1565 {
1566
1567     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1568     {
1569         return get_ports_property<GraphicsAdapter, STYLE>(adaptor, OUTPUTS, controller);
1570     }
1571
1572     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1573     {
1574         return set_ports_property<GraphicsAdapter, STYLE>(adaptor, OUTPUTS, controller, v);
1575     }
1576 };
1577
1578 struct in_label
1579 {
1580
1581     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1582     {
1583         return get_ports_property<GraphicsAdapter, LABEL>(adaptor, INPUTS, controller);
1584     }
1585
1586     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1587     {
1588         return set_ports_property<GraphicsAdapter, LABEL>(adaptor, INPUTS, controller, v);
1589     }
1590 };
1591
1592 struct out_label
1593 {
1594
1595     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1596     {
1597         return get_ports_property<GraphicsAdapter, LABEL>(adaptor, OUTPUTS, controller);
1598     }
1599
1600     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1601     {
1602         return set_ports_property<GraphicsAdapter, LABEL>(adaptor, OUTPUTS, controller, v);
1603     }
1604 };
1605
1606 struct style
1607 {
1608
1609     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
1610     {
1611         ScicosID adaptee = adaptor.getAdaptee()->id();
1612
1613         std::string style;
1614         controller.getObjectProperty(adaptee, BLOCK, STYLE, style);
1615
1616         return new types::String(style.c_str());
1617     }
1618
1619     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
1620     {
1621         ScicosID adaptee = adaptor.getAdaptee()->id();
1622         if (v->getType() == types::InternalType::ScilabString)
1623         {
1624             types::String* current = v->getAs<types::String>();
1625             if (!current->isScalar())
1626             {
1627                 return false;
1628             }
1629
1630             char* c_str = wide_string_to_UTF8(current->get(0));
1631             std::string style(c_str);
1632             FREE(c_str);
1633
1634             controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
1635             return true;
1636         }
1637         else if (v->getType() == types::InternalType::ScilabDouble)
1638         {
1639             types::Double* current = v->getAs<types::Double>();
1640             if (current->getSize() != 0)
1641             {
1642                 return false;
1643             }
1644
1645             std::string style;
1646             controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
1647             return true;
1648         }
1649         return false;
1650     }
1651 };
1652
1653 } /* namespace */
1654
1655 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
1656 static void initialize_fields()
1657 {
1658     if (property<GraphicsAdapter>::properties_have_not_been_set())
1659     {
1660         property<GraphicsAdapter>::fields.reserve(18);
1661         property<GraphicsAdapter>::add_property(L"orig", &orig::get, &orig::set);
1662         property<GraphicsAdapter>::add_property(L"sz", &sz::get, &sz::set);
1663         property<GraphicsAdapter>::add_property(L"flip", &flip::get, &flip::set);
1664         property<GraphicsAdapter>::add_property(L"theta", &theta::get, &theta::set);
1665         property<GraphicsAdapter>::add_property(L"exprs", &exprs::get, &exprs::set);
1666         property<GraphicsAdapter>::add_property(L"pin", &pin::get, &pin::set);
1667         property<GraphicsAdapter>::add_property(L"pout", &pout::get, &pout::set);
1668         property<GraphicsAdapter>::add_property(L"pein", &pein::get, &pein::set);
1669         property<GraphicsAdapter>::add_property(L"peout", &peout::get, &peout::set);
1670         property<GraphicsAdapter>::add_property(L"gr_i", &gr_i::get, &gr_i::set);
1671         property<GraphicsAdapter>::add_property(L"id", &id::get, &id::set);
1672         property<GraphicsAdapter>::add_property(L"in_implicit", &in_implicit::get, &in_implicit::set);
1673         property<GraphicsAdapter>::add_property(L"out_implicit", &out_implicit::get, &out_implicit::set);
1674         property<GraphicsAdapter>::add_property(L"in_style", &in_style::get, &in_style::set);
1675         property<GraphicsAdapter>::add_property(L"out_style", &out_style::get, &out_style::set);
1676         property<GraphicsAdapter>::add_property(L"in_label", &in_label::get, &in_label::set);
1677         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
1678         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
1679     }
1680 }
1681
1682 GraphicsAdapter::GraphicsAdapter() :
1683     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(),
1684     gr_i_content(types::Double::Empty())
1685 {
1686     initialize_fields();
1687 }
1688
1689 GraphicsAdapter::GraphicsAdapter(const Controller& c, model::Block* adaptee) :
1690     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(c, adaptee),
1691     gr_i_content(types::Double::Empty())
1692 {
1693     initialize_fields();
1694 }
1695
1696 GraphicsAdapter::~GraphicsAdapter()
1697 {
1698     gr_i_content->DecreaseRef();
1699     gr_i_content->killMe();
1700 }
1701
1702 std::wstring GraphicsAdapter::getTypeStr()
1703 {
1704     return getSharedTypeStr();
1705 }
1706
1707 std::wstring GraphicsAdapter::getShortTypeStr()
1708 {
1709     return getSharedTypeStr();
1710 }
1711
1712 types::InternalType* GraphicsAdapter::getGrIContent() const
1713 {
1714     gr_i_content->IncreaseRef();
1715     return gr_i_content;
1716 }
1717
1718 void GraphicsAdapter::setGrIContent(types::InternalType* v)
1719 {
1720     gr_i_content->DecreaseRef();
1721     gr_i_content->killMe();
1722
1723     v->IncreaseRef();
1724     gr_i_content = v;
1725 }
1726
1727 } /* namespace view_scilab */
1728 } /* namespace org_scilab_modules_scicos */