1db0b3e7fa142e98a445ece93f10516ae19865dc
[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
18 #include "list.hxx"
19 #include "tlist.hxx"
20 #include "double.hxx"
21 #include "string.hxx"
22
23 #include "utilities.hxx"
24 #include "Controller.hxx"
25 #include "GraphicsAdapter.hxx"
26 #include "ports_management.hxx"
27 #include "controller_helpers.hxx"
28
29 #include "var2vec.hxx"
30 #include "vec2var.hxx"
31
32 extern "C" {
33 #include "localization.h"
34 #include "sci_malloc.h"
35 #include "charEncoding.h"
36 }
37
38 namespace org_scilab_modules_scicos
39 {
40 namespace view_scilab
41 {
42 namespace
43 {
44
45 const std::wstring MBLOCK (L"MBLOCK");
46 const std::wstring MPBLOCK (L"MPBLOCK");
47 const std::wstring in (L"in");
48 const std::wstring intype (L"intype");
49 const std::wstring out (L"out");
50 const std::wstring outtype (L"outtype");
51 const std::wstring param (L"param");
52 const std::wstring paramv (L"paramv");
53 const std::wstring pprop (L"pprop");
54 const std::wstring nameF (L"nameF");
55 const std::wstring funtxt (L"funtxt");
56
57 struct orig
58 {
59
60     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
61     {
62         double* data;
63         types::Double* o = new types::Double(1, 2, &data);
64         ScicosID adaptee = adaptor.getAdaptee()->id();
65
66         std::vector<double> geom;
67         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
68
69         data[0] = geom[0];
70         data[1] = geom[1];
71
72         return o;
73     }
74
75     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
76     {
77
78         if (v->getType() != types::InternalType::ScilabDouble)
79         {
80             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: Real matrix expected.\n"), "graphics", "orig");
81             return false;
82         }
83
84         types::Double* current = v->getAs<types::Double>();
85         if (current->getSize() != 2)
86         {
87             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s : %d-by-%d expected.\n"), "graphics", "orig", 1, 2);
88             return false;
89         }
90
91         ScicosID adaptee = adaptor.getAdaptee()->id();
92         std::vector<double> geom;
93         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
94
95         geom[0] = current->get(0);
96         geom[1] = current->get(1);
97
98         controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
99         return true;
100     }
101 };
102
103 struct sz
104 {
105
106     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
107     {
108         double* data;
109         types::Double* o = new types::Double(1, 2, &data);
110         ScicosID adaptee = adaptor.getAdaptee()->id();
111
112         std::vector<double> geom;
113         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
114
115         data[0] = geom[2];
116         data[1] = geom[3];
117         return o;
118     }
119
120     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
121     {
122         if (v->getType() != types::InternalType::ScilabDouble)
123         {
124             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: Real matrix expected.\n"), "graphics", "sz");
125             return false;
126         }
127
128         types::Double* current = v->getAs<types::Double>();
129         if (current->getSize() != 2)
130         {
131             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s : %d-by-%d expected.\n"), "graphics", "sz", 1, 2);
132             return false;
133         }
134
135         ScicosID adaptee = adaptor.getAdaptee()->id();
136         std::vector<double> geom;
137         controller.getObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
138
139         geom[2] = current->get(0);
140         geom[3] = current->get(1);
141
142         controller.setObjectProperty(adaptee, BLOCK, GEOMETRY, geom);
143         return true;
144     }
145 };
146
147 struct flip
148 {
149
150     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
151     {
152         int* data;
153         types::Bool* o = new types::Bool(1, 1, &data);
154         ScicosID adaptee = adaptor.getAdaptee()->id();
155
156         std::vector<double> angle;
157         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
158
159         data[0] = static_cast<int>(angle[0]);
160         return o;
161     }
162
163     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
164     {
165         if (v->getType() != types::InternalType::ScilabBool)
166         {
167             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: Boolean matrix expected.\n"), "graphics", "flip");
168             return false;
169         }
170
171         types::Bool* current = v->getAs<types::Bool>();
172         if (current->isScalar() != true)
173         {
174             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s : %d-by-%d expected.\n"), "graphics", "flip", 1, 1);
175             return false;
176         }
177
178         ScicosID adaptee = adaptor.getAdaptee()->id();
179         std::vector<double> angle;
180         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
181
182         angle[0] = (current->get(0) == false) ? 0 : 1;
183
184         controller.setObjectProperty(adaptee, BLOCK, ANGLE, angle);
185         return true;
186     }
187 };
188
189 struct theta
190 {
191
192     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
193     {
194         double* data;
195         types::Double* o = new types::Double(1, 1, &data);
196         ScicosID adaptee = adaptor.getAdaptee()->id();
197
198         std::vector<double> angle;
199         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
200
201         data[0] = angle[1];
202         return o;
203     }
204
205     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
206     {
207         if (v->getType() != types::InternalType::ScilabDouble)
208         {
209             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: Real matrix expected.\n"), "graphics", "theta");
210             return false;
211         }
212
213         types::Double* current = v->getAs<types::Double>();
214         if (current->isScalar() != true)
215         {
216             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s : %d-by-%d expected.\n"), "graphics", "theta", 1, 1);
217             return false;
218         }
219
220         ScicosID adaptee = adaptor.getAdaptee()->id();
221         std::vector<double> angle;
222         controller.getObjectProperty(adaptee, BLOCK, ANGLE, angle);
223
224         angle[1] = current->get(0);
225
226         controller.setObjectProperty(adaptee, BLOCK, ANGLE, angle);
227         return true;
228     }
229 };
230
231 struct exprs
232 {
233
234     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
235     {
236         ScicosID adaptee = adaptor.getAdaptee()->id();
237
238         std::vector<double> exprs;
239         controller.getObjectProperty(adaptee, BLOCK, EXPRS, exprs);
240
241         types::InternalType* res;
242         if (!vec2var(exprs, res))
243         {
244             return 0;
245         }
246         return res;
247     }
248
249     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
250     {
251         ScicosID adaptee = adaptor.getAdaptee()->id();
252
253         // From here on, only perform check on 'v'. If it is correct, encode it in the model via 'var2vec'
254         if (v->getType() == types::InternalType::ScilabString)
255         {
256             types::String* current = v->getAs<types::String>();
257             // FIXME: find a test case and check for this case
258         }
259         else if (v->getType() == types::InternalType::ScilabDouble)
260         {
261             types::Double* current = v->getAs<types::Double>();
262             if (!current->isEmpty())
263             {
264                 return false;
265             }
266         }
267
268         // All the following cases are meant for blocks:
269         // CBLOCK, fortran_block, EXPRESSION, scifunc_block_m, PDE, CONSTRAINT2_c, LOOKUP2D, MBLOCK and MPBLOCK
270         else if (v->getType() == types::InternalType::ScilabList)
271         {
272             types::List* initial_list = v->getAs<types::List>();
273
274             if (initial_list->getSize() == 2)
275             {
276                 size_t nParams = 0;
277                 // Whatever the block kind, the first element is necessarily a string matrix (can be empty)
278                 if (initial_list->get(0)->getType() == types::InternalType::ScilabDouble)
279                 {
280                     types::Double* empty_matrix_expected = initial_list->get(0)->getAs<types::Double>();
281                     if (empty_matrix_expected->getSize() != 0)
282                     {
283                         return false;
284                     }
285                 }
286                 else if (initial_list->get(0)->getType() == types::InternalType::ScilabString)
287                 {
288                     types::String* initial_string = initial_list->get(0)->getAs<types::String>();
289                     nParams = initial_string->getSize();
290                 }
291                 else
292                 {
293                     return false;
294                 }
295
296                 // The second element determines the block kind
297                 if (initial_list->get(1)->getType() == types::InternalType::ScilabDouble)
298                 {
299                     types::Double* empty_matrix_expected = initial_list->get(1)->getAs<types::Double>();
300                     if (!empty_matrix_expected->isEmpty())
301                     {
302                         return false;
303                     }
304                     // List coming from a C block
305                 }
306                 else if (initial_list->get(1)->getType() == types::InternalType::ScilabString)
307                 {
308                     types::String* second_string = initial_list->get(1)->getAs<types::String>();
309                     // List coming from a "user-defined function" block
310                     // FIXME: why retrieve and not used ?
311                 }
312                 else if (initial_list->get(1)->getType() == types::InternalType::ScilabList)
313                 {
314                     types::List* second_list = initial_list->get(1)->getAs<types::List>();
315
316                     if (second_list->getSize() == 1)
317                     {
318                         // Default fortran_block value: must contain an empty matrix
319                         if (second_list->get(0)->getType() != types::InternalType::ScilabDouble)
320                         {
321                             return false;
322                         }
323                         types::Double* empty = second_list->get(0)->getAs<types::Double>();
324                         if (!empty->isEmpty())
325                         {
326                             return false;
327                         }
328                         // List coming from a fortran_block
329                     }
330                     else if (second_list->getSize() == 3)
331                     {
332                         // List coming from a SuperBlock (masked or not)
333                         // The three elements are: parameter names, title message and parameters types & sizes
334
335                         // Parameters names (string matrix, can be empty)
336                         if (second_list->get(0)->getType() == types::InternalType::ScilabDouble)
337                         {
338                             types::Double* empty_matrix_expected = second_list->get(0)->getAs<types::Double>();
339                             if (empty_matrix_expected->getSize() != 0)
340                             {
341                                 return false;
342                             }
343                             // No parameters are present, so nothing needs to be saved
344                         }
345                         else if (second_list->get(0)->getType() == types::InternalType::ScilabString)
346                         {
347                             types::String* second_string = second_list->get(0)->getAs<types::String>();
348
349                             if (second_string->getSize() != static_cast<int>(nParams))
350                             {
351                                 return false;
352                             }
353                         }
354                         else
355                         {
356                             return false;
357                         }
358
359                         // Title message (string matrix, can be empty)
360                         if (second_list->get(1)->getType() == types::InternalType::ScilabDouble)
361                         {
362                             types::Double* empty_matrix_expected = second_list->get(1)->getAs<types::Double>();
363                             if (empty_matrix_expected->getSize() != 0 || nParams != 0)
364                             {
365                                 return false;
366                             }
367                             // No parameters are present, so nothing needs to be saved
368                         }
369                         else if (second_list->get(1)->getType() == types::InternalType::ScilabString)
370                         {
371                             types::String* title_message = second_list->get(1)->getAs<types::String>();
372                             if (title_message->getSize() != static_cast<int>(nParams + 1))
373                             {
374                                 // There must be as many parameter descriptions as there are parameters, plus the title message
375                                 return false;
376                             }
377                         }
378                         else
379                         {
380                             return false;
381                         }
382
383                         // Parameters types & sizes (list mixing strings and integers, can be empty)
384                         if (second_list->get(2)->getType() != types::InternalType::ScilabList)
385                         {
386                             return false;
387                         }
388                         types::List* third_list = second_list->get(2)->getAs<types::List>();
389
390                         if (third_list->getSize() != static_cast<int>(2 * nParams))
391                         {
392                             // There must be one type and one size for each parameter, so '2*nParams' elements
393                             if (!(third_list->getSize() == 1 && nParams == 0))
394                             {
395                                 // Allow third_list != 2*params only for the dummy case 'third_list=list([])'. Do nothing then
396                                 return false;
397                             }
398                         }
399                     }
400                     else if (second_list->getSize() == 7)
401                     {
402                         // List coming from a scifunc block
403
404                         // Code parts (string matrices)
405                         for (int i = 0; i < 7; ++i)
406                         {
407                             if (second_list->get(i)->getType() == types::InternalType::ScilabDouble)
408                             {
409                                 types::Double* ith_double = second_list->get(i)->getAs<types::Double>();
410                                 if (!ith_double->isEmpty())
411                                 {
412                                     return false;
413                                 }
414                             }
415                             else if (second_list->get(i)->getType() != types::InternalType::ScilabString)
416                             {
417                                 return false;
418                             }
419                         }
420                     }
421                     else
422                     {
423                         return false;
424                     }
425                 }
426                 else
427                 {
428                     return false;
429                 }
430             }
431             else if (initial_list->getSize() == 3)
432             {
433                 // List coming from a PDE block
434                 if (initial_list->get(0)->getType() == types::InternalType::ScilabTList)
435                 {
436                     types::TList* ParamsPDE = initial_list->get(0)->getAs<types::TList>();
437
438                     types::String* header = ParamsPDE->getFieldNames();
439                     int nParams = header->getSize() - 1; // The first element is the TList type
440                     // Check the header
441                     for (int i = 1; i < nParams; ++i) // Stop at 'nParams-1' to treat the last element differently (string matrix)
442                     {
443                         // Its corresponding element in the TList
444                         if (ParamsPDE->get(i)->getType() != types::InternalType::ScilabString)
445                         {
446                             return false;
447                         }
448                         types::String* ith_string = ParamsPDE->get(i)->getAs<types::String>();
449                         if (!ith_string->isScalar())
450                         {
451                             return false;
452                         }
453                     }
454                     // Header element for the last element of ParamsPDE
455                     if (ParamsPDE->get(nParams)->getType() != types::InternalType::ScilabString)
456                     {
457                         return false;
458                     }
459                     types::String* last_string = ParamsPDE->get(nParams)->getAs<types::String>();
460                     // FIXME: find a related test case
461
462                     // Next comes some code
463                     if (initial_list->get(1)->getType() == types::InternalType::ScilabDouble)
464                     {
465                         types::Double* empty_matrix_expected = initial_list->get(1)->getAs<types::Double>();
466                         if (!empty_matrix_expected->isEmpty())
467                         {
468                             return false;
469                         }
470                     }
471                     else if (initial_list->get(1)->getType() == types::InternalType::ScilabString)
472                     {
473                         types::String* code = initial_list->get(1)->getAs<types::String>();
474                         // FIXME: find a related test case
475                     }
476                     else
477                     {
478                         return false;
479                     }
480
481                     // Finally, the block name
482                     if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
483                     {
484                         return false;
485                     }
486                     types::String* name = initial_list->get(2)->getAs<types::String>();
487                     if (!name->isScalar())
488                     {
489                         return false;
490                     }
491                 }
492                 else if (initial_list->get(0)->getType() == types::InternalType::ScilabString)
493                 {
494                     // List coming from a CONSTRAINT2_c block
495                     types::String* x = initial_list->get(0)->getAs<types::String>();
496                     if (!x->isScalar())
497                     {
498                         return false;
499                     }
500
501                     if (initial_list->get(1)->getType() != types::InternalType::ScilabString)
502                     {
503                         return false;
504                     }
505                     types::String* xd = initial_list->get(1)->getAs<types::String>();
506                     if (!xd->isScalar())
507                     {
508                         return false;
509                     }
510
511                     if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
512                     {
513                         return false;
514                     }
515                     types::String* id = initial_list->get(2)->getAs<types::String>();
516                     if (!id->isScalar())
517                     {
518                         return false;
519                     }
520                 }
521                 else
522                 {
523                     return false;
524                 }
525             }
526             else if (initial_list->getSize() == 5)
527             {
528                 // List coming from a LOOKUP2D block
529                 types::String* xx = initial_list->get(0)->getAs<types::String>();
530                 if (!xx->isScalar())
531                 {
532                     return false;
533                 }
534
535                 if (initial_list->get(1)->getType() != types::InternalType::ScilabString)
536                 {
537                     return false;
538                 }
539                 types::String* yy = initial_list->get(1)->getAs<types::String>();
540                 if (!yy->isScalar())
541                 {
542                     return false;
543                 }
544
545                 if (initial_list->get(2)->getType() != types::InternalType::ScilabString)
546                 {
547                     return false;
548                 }
549                 types::String* zz = initial_list->get(2)->getAs<types::String>();
550                 if (!zz->isScalar())
551                 {
552                     return false;
553                 }
554
555                 if (initial_list->get(3)->getType() != types::InternalType::ScilabString)
556                 {
557                     return false;
558                 }
559                 types::String* Method = initial_list->get(3)->getAs<types::String>();
560                 if (!Method->isScalar())
561                 {
562                     return false;
563                 }
564
565                 if (initial_list->get(4)->getType() != types::InternalType::ScilabString)
566                 {
567                     return false;
568                 }
569                 types::String* Graf = initial_list->get(4)->getAs<types::String>();
570                 if (!Graf->isScalar())
571                 {
572                     return false;
573                 }
574             }
575             else
576             {
577                 return false;
578             }
579         }
580         else if (v->getType() == types::InternalType::ScilabTList)
581         {
582             types::TList* current = v->getAs<types::TList>();
583
584             // Check the header
585             types::String* header = current->getFieldNames();
586             if (header->getSize() != 10)
587             {
588                 return false;
589             }
590             if (header->get(0) != MBLOCK && header->get(0) != MPBLOCK)
591             {
592                 return false;
593             }
594             if (header->get(1) != in)
595             {
596                 return false;
597             }
598             if (header->get(2) != intype)
599             {
600                 return false;
601             }
602             if (header->get(3) != out)
603             {
604                 return false;
605             }
606             if (header->get(4) != outtype)
607             {
608                 return false;
609             }
610             if (header->get(5) != param)
611             {
612                 return false;
613             }
614             if (header->get(6) != paramv)
615             {
616                 return false;
617             }
618             if (header->get(7) != pprop)
619             {
620                 return false;
621             }
622             if (header->get(8) != nameF)
623             {
624                 return false;
625             }
626             if (header->get(9) != funtxt)
627             {
628                 return false;
629             }
630
631             // 'in'
632             if (current->get(1)->getType() != types::InternalType::ScilabString)
633             {
634                 return false;
635             }
636             types::String* inField = current->get(1)->getAs<types::String>();
637             if (!inField->isScalar())
638             {
639                 return false;
640             }
641
642             // 'intype'
643             if (current->get(2)->getType() != types::InternalType::ScilabString)
644             {
645                 return false;
646             }
647             types::String* intypeField = current->get(2)->getAs<types::String>();
648             if (!intypeField->isScalar())
649             {
650                 return false;
651             }
652
653             // 'out'
654             if (current->get(3)->getType() != types::InternalType::ScilabString)
655             {
656                 return false;
657             }
658             types::String* outField = current->get(3)->getAs<types::String>();
659             if (!outField->isScalar())
660             {
661                 return false;
662             }
663
664             // 'outtype'
665             if (current->get(4)->getType() != types::InternalType::ScilabString)
666             {
667                 return false;
668             }
669             types::String* outtypeField = current->get(4)->getAs<types::String>();
670             if (!outtypeField->isScalar())
671             {
672                 return false;
673             }
674
675             // 'param'
676             if (current->get(5)->getType() != types::InternalType::ScilabString)
677             {
678                 return false;
679             }
680             types::String* paramField = current->get(5)->getAs<types::String>();
681             if (!paramField->isScalar())
682             {
683                 return false;
684             }
685
686             // 'paramv'
687             if (current->get(6)->getType() != types::InternalType::ScilabList)
688             {
689                 return false;
690             }
691             types::List* list = current->get(6)->getAs<types::List>();
692
693             for (size_t i = 0; i < list->getSize(); ++i)
694             {
695                 if (list->get(static_cast<int>(i))->getType() != types::InternalType::ScilabString)
696                 {
697                     return false;
698                 }
699             }
700
701             // 'pprop'
702             if (current->get(7)->getType() != types::InternalType::ScilabString)
703             {
704                 return false;
705             }
706             types::String* ppropField = current->get(7)->getAs<types::String>();
707             if (!ppropField->isScalar())
708             {
709                 return false;
710             }
711
712             // 'nameF'
713             if (current->get(8)->getType() != types::InternalType::ScilabString)
714             {
715                 return false;
716             }
717             types::String* nameFField = current->get(8)->getAs<types::String>();
718             if (!nameFField->isScalar())
719             {
720                 return false;
721             }
722
723             // 'funtxt'
724             if (current->get(9)->getType() == types::InternalType::ScilabDouble)
725             {
726                 types::Double* funtxtFieldDouble = current->get(9)->getAs<types::Double>();
727                 if (funtxtFieldDouble->getSize() != 0)
728                 {
729                     return false;
730                 }
731             }
732             else
733             {
734                 if (current->get(9)->getType() != types::InternalType::ScilabString)
735                 {
736                     return false;
737                 }
738                 types::String* funtxtField = current->get(9)->getAs<types::String>();
739                 // FIXME: find a related test-case
740             }
741         }
742         else
743         {
744             return false;
745         }
746
747         // 'v' is OK, now perform the actual encoding
748         std::vector<double> exprs;
749         if (!var2vec(v, exprs))
750         {
751             return false;
752         }
753         controller.setObjectProperty(adaptee, BLOCK, EXPRS, exprs);
754         return true;
755     }
756 };
757
758 struct pin
759 {
760
761     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
762     {
763         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, INPUTS, controller);
764     }
765
766     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
767     {
768         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, INPUTS, controller, v);
769     }
770 };
771
772 struct pout
773 {
774
775     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
776     {
777         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, OUTPUTS, controller);
778     }
779
780     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
781     {
782         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, OUTPUTS, controller, v);
783     }
784 };
785
786 struct pein
787 {
788
789     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
790     {
791         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_INPUTS, controller);
792     }
793
794     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
795     {
796         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_INPUTS, controller, v);
797     }
798 };
799
800 struct peout
801 {
802
803     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
804     {
805         return get_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_OUTPUTS, controller);
806     }
807
808     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
809     {
810         return update_ports_property<GraphicsAdapter, CONNECTED_SIGNALS>(adaptor, EVENT_OUTPUTS, controller, v);
811     }
812 };
813
814 struct gr_i
815 {
816
817     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& /*controller*/)
818     {
819         return adaptor.getGrIContent();
820     }
821
822     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& /*controller*/)
823     {
824         adaptor.setGrIContent(v->clone());
825         return true;
826     }
827 };
828
829 struct id
830 {
831
832     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
833     {
834         ScicosID adaptee = adaptor.getAdaptee()->id();
835
836         std::string id;
837         controller.getObjectProperty(adaptee, BLOCK, LABEL, id);
838
839         types::String* o = new types::String(1, 1);
840         o->set(0, id.data());
841
842         return o;
843     }
844
845     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
846     {
847         if (v->getType() != types::InternalType::ScilabString)
848         {
849             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: String matrix expected.\n"), "graphics", "id");
850             return false;
851         }
852
853         types::String* current = v->getAs<types::String>();
854         if (!current->isScalar())
855         {
856             get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s: %d-by-%d expected.\n"), "graphics", "id", 1, 1);
857             return false;
858         }
859
860         ScicosID adaptee = adaptor.getAdaptee()->id();
861
862         char* c_str = wide_string_to_UTF8(current->get(0));
863         std::string id(c_str);
864         FREE(c_str);
865
866         controller.setObjectProperty(adaptee, BLOCK, LABEL, id);
867         return true;
868     }
869 };
870
871 struct in_implicit
872 {
873
874     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
875     {
876         return get_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, INPUTS, controller);
877     }
878
879     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
880     {
881         return set_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, INPUTS, controller, v);
882     }
883 };
884
885 struct out_implicit
886 {
887
888     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
889     {
890         return get_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, OUTPUTS, controller);
891     }
892
893     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
894     {
895         return set_ports_property<GraphicsAdapter, IMPLICIT>(adaptor, OUTPUTS, controller, v);
896     }
897 };
898
899 struct in_style
900 {
901
902     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
903     {
904         return get_ports_property<GraphicsAdapter, STYLE>(adaptor, INPUTS, controller);
905     }
906
907     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
908     {
909         return set_ports_property<GraphicsAdapter, STYLE>(adaptor, INPUTS, controller, v);
910     }
911 };
912
913 struct out_style
914 {
915
916     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
917     {
918         return get_ports_property<GraphicsAdapter, STYLE>(adaptor, OUTPUTS, controller);
919     }
920
921     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
922     {
923         return set_ports_property<GraphicsAdapter, STYLE>(adaptor, OUTPUTS, controller, v);
924     }
925 };
926
927 struct in_label
928 {
929
930     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
931     {
932         return get_ports_property<GraphicsAdapter, LABEL>(adaptor, INPUTS, controller);
933     }
934
935     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
936     {
937         return set_ports_property<GraphicsAdapter, LABEL>(adaptor, INPUTS, controller, v);
938     }
939 };
940
941 struct out_label
942 {
943
944     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
945     {
946         return get_ports_property<GraphicsAdapter, LABEL>(adaptor, OUTPUTS, controller);
947     }
948
949     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
950     {
951         return set_ports_property<GraphicsAdapter, LABEL>(adaptor, OUTPUTS, controller, v);
952     }
953 };
954
955 struct style
956 {
957
958     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
959     {
960         ScicosID adaptee = adaptor.getAdaptee()->id();
961
962         std::string style;
963         controller.getObjectProperty(adaptee, BLOCK, STYLE, style);
964
965         return new types::String(style.c_str());
966     }
967
968     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
969     {
970         ScicosID adaptee = adaptor.getAdaptee()->id();
971         if (v->getType() == types::InternalType::ScilabString)
972         {
973             types::String* current = v->getAs<types::String>();
974             if (!current->isScalar())
975             {
976                 get_or_allocate_logger()->log(LOG_ERROR, _("Wrong dimension for field %s.%s: %d-by-%d expected.\n"), "graphics", "style", 1, 1);
977                 return false;
978             }
979
980             char* c_str = wide_string_to_UTF8(current->get(0));
981             std::string style(c_str);
982             FREE(c_str);
983
984             controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
985             return true;
986         }
987         else if (v->getType() == types::InternalType::ScilabDouble)
988         {
989             types::Double* current = v->getAs<types::Double>();
990             if (current->getSize() != 0)
991             {
992                 get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: String matrix expected.\n"), "graphics", "style");
993                 return false;
994             }
995
996             std::string style;
997             controller.setObjectProperty(adaptee, BLOCK, STYLE, style);
998             return true;
999         }
1000
1001         get_or_allocate_logger()->log(LOG_ERROR, _("Wrong type for field %s.%s: String matrix expected.\n"), "graphics", "style");
1002         return false;
1003     }
1004 };
1005
1006 } /* namespace */
1007
1008 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
1009 static void initialize_fields()
1010 {
1011     if (property<GraphicsAdapter>::properties_have_not_been_set())
1012     {
1013         property<GraphicsAdapter>::fields.reserve(18);
1014         property<GraphicsAdapter>::add_property(L"orig", &orig::get, &orig::set);
1015         property<GraphicsAdapter>::add_property(L"sz", &sz::get, &sz::set);
1016         property<GraphicsAdapter>::add_property(L"flip", &flip::get, &flip::set);
1017         property<GraphicsAdapter>::add_property(L"theta", &theta::get, &theta::set);
1018         property<GraphicsAdapter>::add_property(L"exprs", &exprs::get, &exprs::set);
1019         property<GraphicsAdapter>::add_property(L"pin", &pin::get, &pin::set);
1020         property<GraphicsAdapter>::add_property(L"pout", &pout::get, &pout::set);
1021         property<GraphicsAdapter>::add_property(L"pein", &pein::get, &pein::set);
1022         property<GraphicsAdapter>::add_property(L"peout", &peout::get, &peout::set);
1023         property<GraphicsAdapter>::add_property(L"gr_i", &gr_i::get, &gr_i::set);
1024         property<GraphicsAdapter>::add_property(L"id", &id::get, &id::set);
1025         property<GraphicsAdapter>::add_property(L"in_implicit", &in_implicit::get, &in_implicit::set);
1026         property<GraphicsAdapter>::add_property(L"out_implicit", &out_implicit::get, &out_implicit::set);
1027         property<GraphicsAdapter>::add_property(L"in_style", &in_style::get, &in_style::set);
1028         property<GraphicsAdapter>::add_property(L"out_style", &out_style::get, &out_style::set);
1029         property<GraphicsAdapter>::add_property(L"in_label", &in_label::get, &in_label::set);
1030         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
1031         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
1032     }
1033 }
1034
1035 GraphicsAdapter::GraphicsAdapter() :
1036     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(),
1037     gr_i_content(types::Double::Empty())
1038 {
1039     initialize_fields();
1040 }
1041
1042 GraphicsAdapter::GraphicsAdapter(const Controller& c, model::Block* adaptee) :
1043     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(c, adaptee),
1044     gr_i_content(types::Double::Empty())
1045 {
1046     initialize_fields();
1047 }
1048
1049 GraphicsAdapter::~GraphicsAdapter()
1050 {
1051     gr_i_content->DecreaseRef();
1052     gr_i_content->killMe();
1053 }
1054
1055 std::wstring GraphicsAdapter::getTypeStr()
1056 {
1057     return getSharedTypeStr();
1058 }
1059
1060 std::wstring GraphicsAdapter::getShortTypeStr()
1061 {
1062     return getSharedTypeStr();
1063 }
1064
1065 types::InternalType* GraphicsAdapter::getGrIContent() const
1066 {
1067     gr_i_content->IncreaseRef();
1068     return gr_i_content;
1069 }
1070
1071 void GraphicsAdapter::setGrIContent(types::InternalType* v)
1072 {
1073     gr_i_content->DecreaseRef();
1074     gr_i_content->killMe();
1075
1076     v->IncreaseRef();
1077     gr_i_content = v;
1078 }
1079
1080 } /* namespace view_scilab */
1081 } /* namespace org_scilab_modules_scicos */