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