Xcos MVC: implement in_style / out_style / in_label / out_label / style
[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-en.txt
10  *
11  */
12
13 #include <string>
14 #include <vector>
15 #include <cassert>
16
17 #include "int.hxx"
18 #include "double.hxx"
19 #include "string.hxx"
20
21 #include "Controller.hxx"
22 #include "GraphicsAdapter.hxx"
23
24 extern "C" {
25 #include "sci_malloc.h"
26 }
27
28 namespace org_scilab_modules_scicos
29 {
30 namespace view_scilab
31 {
32
33 static const wchar_t E[] = L"E";
34 static const wchar_t I[] = L"I";
35
36 struct orig
37 {
38
39     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
40     {
41         double* data;
42         types::Double* o = new types::Double(1, 2, &data);
43         model::Block* adaptee = adaptor.getAdaptee();
44
45         std::vector<double> geom;
46         controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
47
48         data[0] = geom[0];
49         data[1] = geom[1];
50
51         return o;
52     }
53
54     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
55     {
56
57         if (v->getType() != types::InternalType::ScilabDouble)
58         {
59             return false;
60         }
61
62         types::Double* current = v->getAs<types::Double>();
63         if (current->getRows() != 1 || current->getCols() != 2)
64         {
65             return false;
66         }
67
68         model::Block* adaptee = adaptor.getAdaptee();
69         std::vector<double> geom;
70         controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
71
72         geom[0] = current->get(0);
73         geom[1] = current->get(1);
74
75         controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
76         return true;
77     }
78 };
79
80 struct sz
81 {
82
83     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
84     {
85         double* data;
86         types::Double* o = new types::Double(1, 2, &data);
87         model::Block* adaptee = adaptor.getAdaptee();
88
89         std::vector<double> geom;
90         controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
91
92         data[0] = geom[2];
93         data[1] = geom[3];
94         return o;
95     }
96
97     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
98     {
99         if (v->getType() != types::InternalType::ScilabDouble)
100         {
101             return false;
102         }
103
104         types::Double* current = v->getAs<types::Double>();
105         if (current->getRows() != 1 || current->getCols() != 2)
106         {
107             return false;
108         }
109
110         model::Block* adaptee = adaptor.getAdaptee();
111         std::vector<double> geom;
112         controller.getObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
113
114         geom[2] = current->get(0);
115         geom[3] = current->get(1);
116
117         controller.setObjectProperty(adaptee->id(), adaptee->kind(), GEOMETRY, geom);
118         return true;
119     }
120 };
121
122 struct flip
123 {
124
125     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
126     {
127         int* data;
128         types::Bool* o = new types::Bool(1, 1, &data);
129         model::Block* adaptee = adaptor.getAdaptee();
130
131         std::vector<double> angle;
132         controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
133
134         data[0] = angle[0];
135         return o;
136     }
137
138     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
139     {
140         if (v->getType() != types::InternalType::ScilabBool)
141         {
142             return false;
143         }
144
145         types::Bool* current = v->getAs<types::Bool>();
146         if (current->isScalar() != true)
147         {
148             return false;
149         }
150
151         model::Block* adaptee = adaptor.getAdaptee();
152         std::vector<double> angle;
153         controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
154
155         angle[0] = (current->get(0) == false) ? 0 : 1;
156
157         controller.setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
158         return true;
159     }
160 };
161
162 struct theta
163 {
164
165     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
166     {
167         double* data;
168         types::Double* o = new types::Double(1, 1, &data);
169         model::Block* adaptee = adaptor.getAdaptee();
170
171         std::vector<double> angle;
172         controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
173
174         data[0] = angle[1];
175         return o;
176     }
177
178     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
179     {
180         if (v->getType() != types::InternalType::ScilabDouble)
181         {
182             return false;
183         }
184
185         types::Double* current = v->getAs<types::Double>();
186         if (current->isScalar() != true)
187         {
188             return false;
189         }
190
191         model::Block* adaptee = adaptor.getAdaptee();
192         std::vector<double> angle;
193         controller.getObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
194
195         angle[1] = current->get(0);
196
197         controller.setObjectProperty(adaptee->id(), adaptee->kind(), ANGLE, angle);
198         return true;
199     }
200 };
201
202 struct exprs
203 {
204
205     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
206     {
207         model::Block* adaptee = adaptor.getAdaptee();
208
209         std::vector<std::string> exprs;
210         controller.getObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
211
212         types::String* o = new types::String(exprs.size(), 1);
213         for (size_t i = 0; i < exprs.size(); ++i)
214         {
215             o->set(i, exprs[i].data());
216         }
217
218         return o;
219     }
220
221     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
222     {
223         if (v->getType() == types::InternalType::ScilabString)
224         {
225             types::String* current = v->getAs<types::String>();
226             if (current->getCols() != 0 && current->getCols() != 1)
227             {
228                 return false;
229             }
230
231             model::Block* adaptee = adaptor.getAdaptee();
232             std::vector<std::string> exprs = std::vector<std::string>(current->getSize());
233             for (size_t i = 0; i < exprs.size(); ++i)
234             {
235                 char* c_str = wide_string_to_UTF8(current->get(i));
236                 exprs[i] = std::string(c_str);
237                 FREE(c_str);
238             }
239
240             controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
241             return true;
242         }
243         else if (v->getType() == types::InternalType::ScilabDouble)
244         {
245             types::Double* current = v->getAs<types::Double>();
246             if (current->getRows() != 0 || current->getCols() != 0)
247             {
248                 return false;
249             }
250
251             model::Block* adaptee = adaptor.getAdaptee();
252             std::vector<std::string> exprs;
253             controller.setObjectProperty(adaptee->id(), adaptee->kind(), EXPRS, exprs);
254             return true;
255         }
256         return false;
257     }
258 };
259
260 static types::Double* create_port(const GraphicsAdapter& adaptor, object_properties_t p, const Controller& controller)
261 {
262     model::Block* adaptee = adaptor.getAdaptee();
263
264     // retrieve the identifiers
265     std::vector<ScicosID> ids;
266     controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, ids);
267
268     // allocate some space for the return value
269     double* ports;
270     types::Double* o = new types::Double(ids.size(), 1, &ports);
271
272     // translate identifiers to return values
273     for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++ports)
274     {
275         std::vector<ScicosID> connectedSignals;
276
277         controller.getObjectProperty(*it, PORT, CONNECTED_SIGNALS, connectedSignals);
278
279         // always return the first connected signals, at scilab level a port can only be connected to one signal at a time.
280         if (connectedSignals.empty())
281         {
282             // if the port is not connected returns 0
283             *ports = 0;
284         }
285         else
286         {
287             // if the port is connected, return the index of the link in the parent diagram
288             ScicosID link = connectedSignals[0];
289
290             ScicosID parentDiagram = 0;
291             controller.getObjectProperty(link, LINK, PARENT_DIAGRAM, parentDiagram);
292
293             std::vector<ScicosID> children;
294             controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
295
296             std::vector<ScicosID>::iterator it = std::find(children.begin(), children.end(), link);
297             if (it != children.end())
298             {
299                 int index = std::distance(children.begin(), it);
300                 *ports = index;
301             }
302             else
303             {
304                 *ports = 0;
305             }
306         }
307
308         ports++;
309     }
310
311     return o;
312 }
313
314 static types::String* get_port(const GraphicsAdapter& adaptor, object_properties_t p, const Controller& controller, object_properties_t p2)
315 {
316     model::Block* adaptee = adaptor.getAdaptee();
317
318     // Retrieve the identifiers
319     std::vector<ScicosID> ids;
320     controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, ids);
321
322     // Allocate some space for the return value
323     types::String* o = new types::String(ids.size(), 1);
324
325     // Translate identifiers to return values
326     int i = 0;
327     switch (p2)
328     {
329         case IMPLICIT:
330         {
331             for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
332             {
333                 bool v;
334                 controller.getObjectProperty(*it, PORT, p2, v);
335                 o->set(i, (v == false) ? E : I);
336             }
337             break;
338         }
339         case STYLE:
340         case LABEL:
341         {
342             for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
343             {
344                 std::string s;
345                 controller.getObjectProperty(*it, PORT, p2, s);
346                 o->set(i, s.data());
347             }
348             break;
349         }
350         default:
351             return false;
352     }
353
354     return o;
355 }
356
357 static bool set_port(const GraphicsAdapter& adaptor, types::InternalType* v, object_properties_t p, Controller& controller)
358 {
359     model::Block* adaptee = adaptor.getAdaptee();
360
361     if (v->getType() != types::InternalType::ScilabDouble)
362     {
363         return false;
364     }
365     types::Double* value = v->getAs<types::Double>();
366
367     ScicosID parentDiagram;
368     controller.getObjectProperty(adaptee->id(), BLOCK, PARENT_DIAGRAM, parentDiagram);
369
370     std::vector<ScicosID> children;
371     if (parentDiagram != 0)
372     {
373         controller.getObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
374     }
375
376     std::vector<int> newPorts = std::vector<int>(value->getSize());
377     double* d = value->getReal();
378     for (std::vector<int>::iterator it = newPorts.begin(); it != newPorts.end(); ++it, ++d)
379     {
380         if (0 > *d && *d >= children.size())
381         {
382             return false;
383         }
384
385         *it = (int) * d;
386     }
387     std::vector<ScicosID> deletedObjects;
388
389     // retrieve old data
390     std::vector<ScicosID> oldPorts;
391     controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, oldPorts);
392     std::vector<ScicosID> previousPorts = oldPorts;
393
394     // updated ports
395     while (!oldPorts.empty() || !newPorts.empty())
396     {
397         ScicosID oldPort = oldPorts.back();
398         oldPorts.pop_back();
399         int newPort = newPorts.back();
400         newPorts.pop_back();
401
402         ScicosID oldSignal;
403         controller.getObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, oldSignal);
404         ScicosID newSignal = children[newPort];
405
406         if (oldSignal != newSignal)
407         {
408             // disconnect the old link
409             ScicosID oldSignalSrc;
410             controller.getObjectProperty(oldSignal, LINK, SOURCE_PORT, oldSignalSrc);
411             ScicosID oldSignalDst;
412             controller.getObjectProperty(oldSignal, LINK, DESTINATION_PORT, oldSignalDst);
413
414             ScicosID unconnected = 0;
415             if (oldSignalSrc == oldPort)
416             {
417                 controller.setObjectProperty(oldSignalDst, PORT, CONNECTED_SIGNALS, unconnected);
418             }
419             else // oldSignalDst == oldPort
420             {
421                 controller.setObjectProperty(oldSignalSrc, PORT, CONNECTED_SIGNALS, unconnected);
422             }
423             // Link de-association is not performed as the link will be removed
424
425             // connect the new link
426             controller.setObjectProperty(newSignal, LINK, SOURCE_PORT, 0);
427             controller.setObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, newSignal);
428
429             children.erase(std::find(children.begin(), children.end(), oldSignal));
430             deletedObjects.push_back(oldSignal);
431         }
432     }
433
434     // removed ports
435     if (!oldPorts.empty())
436     {
437         previousPorts.erase(previousPorts.begin() + oldPorts.size(), previousPorts.end());
438
439         while (!oldPorts.empty())
440         {
441             ScicosID oldPort = oldPorts.back();
442             oldPorts.pop_back();
443
444             ScicosID signal;
445             controller.getObjectProperty(oldPort, PORT, CONNECTED_SIGNALS, signal);
446             if (signal != 0)
447             {
448                 // the link is connected, disconnect the other side
449                 ScicosID oldSignalSrc;
450                 controller.getObjectProperty(signal, LINK, SOURCE_PORT, oldSignalSrc);
451                 ScicosID oldSignalDst;
452                 controller.getObjectProperty(signal, LINK, DESTINATION_PORT, oldSignalDst);
453
454                 ScicosID unconnected = 0;
455                 if (oldSignalSrc == oldPort)
456                 {
457                     controller.setObjectProperty(oldSignalDst, PORT, CONNECTED_SIGNALS, unconnected);
458                 }
459                 else     // oldSignalDst == oldPort
460                 {
461                     controller.setObjectProperty(oldSignalSrc, PORT, CONNECTED_SIGNALS, unconnected);
462                 }
463
464                 children.erase(std::find(children.begin(), children.end(), signal));
465                 deletedObjects.push_back(signal);
466             }
467
468             deletedObjects.push_back(oldPort);
469         }
470
471         controller.setObjectProperty(adaptee->id(), BLOCK, p, previousPorts);
472     }
473
474     // added ports
475     if (!newPorts.empty())
476     {
477         while (!newPorts.empty())
478         {
479             int newPort = newPorts.back();
480             oldPorts.pop_back();
481
482             ScicosID id = controller.createObject(PORT);
483             controller.setObjectProperty(id, PORT, SOURCE_BLOCK, adaptee->id());
484             // set the connected signal if applicable
485             if (newPort != 0)
486             {
487                 ScicosID signal = children[newPort];
488                 controller.setObjectProperty(id, PORT, CONNECTED_SIGNALS, signal);
489             }
490
491             previousPorts.push_back(id);
492         }
493
494         controller.setObjectProperty(adaptee->id(), BLOCK, p, previousPorts);
495     }
496
497     // remove objects from the model after de-association
498     if (parentDiagram != 0)
499     {
500         controller.setObjectProperty(parentDiagram, DIAGRAM, CHILDREN, children);
501     }
502     for (std::vector<ScicosID>::iterator it = deletedObjects.begin(); it != deletedObjects.end(); ++it)
503     {
504         controller.deleteObject(*it);
505     }
506
507     return true;
508 }
509
510 static bool set_port(const GraphicsAdapter& adaptor, types::InternalType* v, object_properties_t p, Controller& controller, object_properties_t p2)
511 {
512     if (v->getType() == types::InternalType::ScilabString)
513     {
514         model::Block* adaptee = adaptor.getAdaptee();
515
516         types::String* current = v->getAs<types::String>();
517         if (current->getCols() != 0 && current->getCols() != 1)
518         {
519             return false;
520         }
521
522         // Retrieve the ports i dentifiers
523         std::vector<ScicosID> ids;
524         size_t rows = current->getRows();
525         controller.getObjectProperty(adaptee->id(), adaptee->kind(), p, ids);
526         if (rows != ids.size())
527         {
528             return false;
529         }
530
531         int i = 0;
532         switch (p2)
533         {
534             case IMPLICIT:
535             {
536                 for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
537                 {
538                     if (current->get(i) == I)
539                     {
540                         controller.setObjectProperty(*it, PORT, p2, true);
541                     }
542                     else if (current->get(i) == E)
543                     {
544                         controller.setObjectProperty(*it, PORT, p2, false);
545                     }
546                     else
547                     {
548                         return false;
549                     }
550                 }
551                 break;
552             }
553             case STYLE:
554             case LABEL:
555             {
556                 std::vector<std::string> style = std::vector<std::string>(current->getSize());
557                 for (std::vector<ScicosID>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
558                 {
559                     char* c_str = wide_string_to_UTF8(current->get(i));
560                     style[i] = std::string(c_str);
561                     FREE(c_str);
562                     controller.setObjectProperty(*it, PORT, p2, style[i]);
563                 }
564                 break;
565             }
566             default:
567                 return false;
568         }
569         return true;
570     }
571     else if (v->getType() == types::InternalType::ScilabDouble)
572     {
573         types::Double* current = v->getAs<types::Double>();
574         if (current->getRows() != 0 || current->getCols() != 0)
575         {
576             return false;
577         }
578         types::String* o = get_port(adaptor, p, controller, p2);
579         if (o->getSize() != 0)
580         {
581             return false;
582         }
583         // Do nothing, because if the sizes match, then there are already zero concerned ports, so no ports to update
584         delete o;
585         return true;
586     }
587     return false;
588 }
589
590 struct pin
591 {
592
593     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
594     {
595         return create_port(adaptor, INPUTS, controller);
596     }
597
598     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
599     {
600         return set_port(adaptor, v, INPUTS, controller);
601     }
602 };
603
604 struct pout
605 {
606
607     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
608     {
609         return create_port(adaptor, OUTPUTS, controller);
610     }
611
612     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
613     {
614         return set_port(adaptor, v, OUTPUTS, controller);
615     }
616 };
617
618 struct pein
619 {
620
621     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
622     {
623         return create_port(adaptor, EVENT_INPUTS, controller);
624     }
625
626     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
627     {
628         return set_port(adaptor, v, EVENT_INPUTS, controller);
629     }
630 };
631
632 struct peout
633 {
634
635     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
636     {
637         return create_port(adaptor, EVENT_OUTPUTS, controller);
638     }
639
640     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
641     {
642         return set_port(adaptor, v, EVENT_OUTPUTS, controller);
643     }
644 };
645
646 struct gr_i
647 {
648
649     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
650     {
651         return adaptor.getGrIContent();
652     }
653
654     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
655     {
656         adaptor.setGrIContent(v->clone());
657         return true;
658     }
659 };
660
661 struct id
662 {
663
664     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
665     {
666         model::Block* adaptee = adaptor.getAdaptee();
667
668         std::string id;
669         controller.getObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
670
671         types::String* o = new types::String(1, 1);
672         o->set(0, id.data());
673
674         return o;
675     }
676
677     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
678     {
679         if (v->getType() != types::InternalType::ScilabString)
680         {
681             return false;
682         }
683
684         types::String* current = v->getAs<types::String>();
685         if (current->getSize() != 1)
686         {
687             return false;
688         }
689
690         model::Block* adaptee = adaptor.getAdaptee();
691         std::string id;
692         char* c_str = wide_string_to_UTF8(current->get(0));
693         id = std::string(c_str);
694         FREE(c_str);
695
696         controller.setObjectProperty(adaptee->id(), adaptee->kind(), LABEL, id);
697         return true;
698     }
699 };
700
701 struct in_implicit
702 {
703
704     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
705     {
706         return get_port(adaptor, INPUTS, controller, IMPLICIT);
707     }
708
709     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
710     {
711         return set_port(adaptor, v, INPUTS, controller, IMPLICIT);
712     }
713 };
714
715 struct out_implicit
716 {
717
718     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
719     {
720         return get_port(adaptor, OUTPUTS, controller, IMPLICIT);
721     }
722
723     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
724     {
725         return set_port(adaptor, v, OUTPUTS, controller, IMPLICIT);
726     }
727 };
728
729 struct in_style
730 {
731
732     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
733     {
734         return get_port(adaptor, INPUTS, controller, STYLE);
735     }
736
737     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
738     {
739         return set_port(adaptor, v, INPUTS, controller, STYLE);
740     }
741 };
742
743 struct out_style
744 {
745
746     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
747     {
748         return get_port(adaptor, OUTPUTS, controller, STYLE);
749     }
750
751     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
752     {
753         return set_port(adaptor, v, OUTPUTS, controller, STYLE);
754     }
755 };
756
757 struct in_label
758 {
759
760     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
761     {
762         return get_port(adaptor, INPUTS, controller, LABEL);
763     }
764
765     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
766     {
767         return set_port(adaptor, v, INPUTS, controller, LABEL);
768     }
769 };
770
771 struct out_label
772 {
773
774     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
775     {
776         return get_port(adaptor, OUTPUTS, controller, LABEL);
777     }
778
779     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
780     {
781         return set_port(adaptor, v, OUTPUTS, controller, LABEL);
782     }
783 };
784
785 struct style
786 {
787
788     static types::InternalType* get(const GraphicsAdapter& adaptor, const Controller& controller)
789     {
790         model::Block* adaptee = adaptor.getAdaptee();
791
792         std::string style;
793         controller.getObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
794
795         types::String* o;
796         if (style.empty())
797         {
798             o = new types::String(0, 0);
799         }
800         else
801         {
802             o = new types::String(1, 1);
803             o->set(0, style.data());
804         }
805         return o;
806     }
807
808     static bool set(GraphicsAdapter& adaptor, types::InternalType* v, Controller& controller)
809     {
810         model::Block* adaptee = adaptor.getAdaptee();
811         if (v->getType() == types::InternalType::ScilabString)
812         {
813             types::String* current = v->getAs<types::String>();
814             if (current->getSize() != 1)
815             {
816                 return false;
817             }
818
819             std::string style;
820             char* c_str = wide_string_to_UTF8(current->get(0));
821             style = std::string(c_str);
822             FREE(c_str);
823
824             controller.setObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
825             return true;
826         }
827         else if (v->getType() == types::InternalType::ScilabDouble)
828         {
829             types::Double* current = v->getAs<types::Double>();
830             if (current->getSize() != 0)
831             {
832                 return false;
833             }
834
835             std::string style;
836             controller.setObjectProperty(adaptee->id(), adaptee->kind(), STYLE, style);
837             return true;
838         }
839         return false;
840     }
841 };
842
843 template<> property<GraphicsAdapter>::props_t property<GraphicsAdapter>::fields = property<GraphicsAdapter>::props_t();
844
845 GraphicsAdapter::GraphicsAdapter(const GraphicsAdapter& o) :
846     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o),
847     gr_i_content(o.gr_i_content->clone())
848 {}
849
850 GraphicsAdapter::GraphicsAdapter(org_scilab_modules_scicos::model::Block* o) :
851     BaseAdapter<GraphicsAdapter, org_scilab_modules_scicos::model::Block>(o)
852 {
853     if (property<GraphicsAdapter>::properties_has_not_been_set())
854     {
855         property<GraphicsAdapter>::fields.reserve(17);
856         property<GraphicsAdapter>::add_property(L"orig", &orig::get, &orig::set);
857         property<GraphicsAdapter>::add_property(L"sz", &sz::get, &sz::set);
858         property<GraphicsAdapter>::add_property(L"flip", &flip::get, &flip::set);
859         property<GraphicsAdapter>::add_property(L"theta", &theta::get, &theta::set);
860         property<GraphicsAdapter>::add_property(L"exprs", &exprs::get, &exprs::set);
861         property<GraphicsAdapter>::add_property(L"pin", &pin::get, &pin::set);
862         property<GraphicsAdapter>::add_property(L"pout", &pout::get, &pout::set);
863         property<GraphicsAdapter>::add_property(L"pein", &pein::get, &pein::set);
864         property<GraphicsAdapter>::add_property(L"peout", &peout::get, &peout::set);
865         property<GraphicsAdapter>::add_property(L"gr_i", &gr_i::get, &gr_i::set);
866         property<GraphicsAdapter>::add_property(L"id", &id::get, &id::set);
867         property<GraphicsAdapter>::add_property(L"in_implicit", &in_implicit::get, &in_implicit::set);
868         property<GraphicsAdapter>::add_property(L"out_implicit", &out_implicit::get, &out_implicit::set);
869         property<GraphicsAdapter>::add_property(L"in_style", &in_style::get, &in_style::set);
870         property<GraphicsAdapter>::add_property(L"in_label", &in_label::get, &in_label::set);
871         property<GraphicsAdapter>::add_property(L"out_label", &out_label::get, &out_label::set);
872         property<GraphicsAdapter>::add_property(L"style", &style::get, &style::set);
873     }
874
875     gr_i_content = new types::List();
876 }
877
878 GraphicsAdapter::~GraphicsAdapter()
879 {
880     delete gr_i_content;
881 }
882
883 bool GraphicsAdapter::toString(std::wostringstream& ostr)
884 {
885     ostr << L"GraphicsAdapter.hxx: Dunno what to display there" << std::endl;
886     return true;
887 }
888
889 std::wstring GraphicsAdapter::getTypeStr()
890 {
891     return getSharedTypeStr();
892 }
893
894 std::wstring GraphicsAdapter::getShortTypeStr()
895 {
896     return getSharedTypeStr();
897 }
898
899 types::InternalType* GraphicsAdapter::getGrIContent() const
900 {
901     return gr_i_content;
902 }
903
904 void GraphicsAdapter::setGrIContent(types::InternalType* v)
905 {
906     delete gr_i_content;
907     gr_i_content = v->clone();
908 }
909
910 } /* view_scilab */
911 } /* namespace org_scilab_modules_scicos */