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