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