1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
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 <vector>
17 #include <string>
18 #include <cfloat>
19 
20 #include "handle_properties.hxx"
21 #include "double.hxx"
22 
23 extern "C"
24 {
25 #include "h5_fileManagement.h"
26 #include "h5_writeDataToFile.h"
27 #include "h5_readDataFromFile.h"
28 #include "h5_attributeConstants.h"
29 
30 #include "setGraphicObjectProperty.h"
31 #include "getGraphicObjectProperty.h"
32 #include "graphicObjectProperties.h"
33 #include "createGraphicObject.h"
34 #include "FigureList.h"
35 #include "CurrentFigure.h"
36 #include "BuildObjects.h"
37 #include "Matplot.h"
38 #include "HandleManagement.h"
39 }
40 
41 extern types::InternalType* import_data(hid_t dataset);
42 extern int export_data(hid_t parent, const std::string& name, types::InternalType* data, hid_t xfer_plist_id);
43 
getHandleInt(hid_t dataset,const std::string & prop,int * val)44 static int getHandleInt(hid_t dataset, const std::string& prop, int* val)
45 {
46     hid_t node = 0;
47     node = getDataSetIdFromName(dataset, prop.data());
48     if (node < 0)
49     {
50         return -1;
51     }
52 
53     readInteger32Matrix(node, val);
54     return 0;
55 }
56 
getHandleIntVector(hid_t dataset,const std::string & prop,int * row,int * col,int ** vals)57 static int getHandleIntVector(hid_t dataset, const std::string& prop, int* row, int* col, int** vals)
58 {
59     hid_t node = 0;
60     node = getDataSetIdFromName(dataset, prop.data());
61     if (node < 0)
62     {
63         return -1;
64     }
65 
66     int complex = 0;
67     int dims = 0;;
68     int ret = getDatasetInfo(node, &complex, &dims, NULL);
69     if (ret < 0)
70     {
71         closeDataSet(dataset);
72         return -1;
73     }
74 
75 
76     std::vector<int> d(dims);
77     int size = getDatasetInfo(node, &complex, &dims, d.data());
78 
79     if (dims == 0 || size <= 0)
80     {
81         closeDataSet(node);
82         return -1;
83     }
84 
85     *row = d[0];
86     *col = d[1];
87     *vals = new int[size];
88     readInteger32Matrix(node, *vals);
89     return 0;
90 }
91 
getHandleBool(hid_t dataset,const std::string & prop,int * val)92 static int getHandleBool(hid_t dataset, const std::string& prop, int* val)
93 {
94     hid_t node = 0;
95     node = getDataSetIdFromName(dataset, prop.data());
96     if (node < 0)
97     {
98         return -1;
99     }
100 
101     readBooleanMatrix(node, val);
102     return 0;
103 }
104 
getHandleBoolVector(hid_t dataset,const std::string & prop,int * row,int * col,int ** vals)105 static int getHandleBoolVector(hid_t dataset, const std::string& prop, int* row, int* col, int** vals)
106 {
107     hid_t node = 0;
108     node = getDataSetIdFromName(dataset, prop.data());
109     if (node < 0)
110     {
111         return -1;
112     }
113 
114     int complex = 0;
115     int dims = 0;;
116     int ret = getDatasetInfo(node, &complex, &dims, NULL);
117     if (ret < 0)
118     {
119         closeDataSet(dataset);
120         return -1;
121     }
122 
123 
124     std::vector<int> d(dims);
125     int size = getDatasetInfo(node, &complex, &dims, d.data());
126 
127     if (dims == 0 || size <= 0)
128     {
129         closeDataSet(node);
130         return -1;
131     }
132 
133     *row = d[0];
134     *col = d[1];
135 
136     *vals = new int[size];
137     readBooleanMatrix(node, *vals);
138     return 0;
139 }
140 
getHandleDouble(hid_t dataset,const std::string & prop,double * val)141 static int getHandleDouble(hid_t dataset, const std::string& prop, double* val)
142 {
143     hid_t node = 0;
144     node = getDataSetIdFromName(dataset, prop.data());
145     if (node < 0)
146     {
147         return -1;
148     }
149 
150     readDoubleMatrix(node, val);
151     return 0;
152 }
153 
getHandleDoubleVector(hid_t dataset,const std::string & prop,int * row,int * col,double ** vals)154 static int getHandleDoubleVector(hid_t dataset, const std::string& prop, int* row, int* col, double** vals)
155 {
156     hid_t node = 0;
157     node = getDataSetIdFromName(dataset, prop.data());
158     if (node < 0)
159     {
160         return -1;
161     }
162 
163     int complex = 0;
164     int dims = 0;;
165     int ret = getDatasetInfo(node, &complex, &dims, NULL);
166     if (ret < 0)
167     {
168         closeDataSet(dataset);
169         return -1;
170     }
171 
172 
173     std::vector<int> d(dims);
174     int size = getDatasetInfo(node, &complex, &dims, d.data());
175 
176     if (dims == 0 || size <= 0)
177     {
178         closeDataSet(node);
179         return -1;
180     }
181 
182     *row = d[0];
183     *col = d[1];
184 
185     *vals = new double[size];
186     readDoubleMatrix(node, *vals);
187     return 0;
188 }
189 
getHandleString(hid_t dataset,const std::string & prop,char ** val)190 static int getHandleString(hid_t dataset, const std::string& prop, char** val)
191 {
192     hid_t node = 0;
193     node = getDataSetIdFromName(dataset, prop.data());
194     if (node < 0)
195     {
196         return -1;
197     }
198 
199     int complex = 0;
200     int dims = 0;;
201     int ret = getDatasetInfo(node, &complex, &dims, NULL);
202     if (ret < 0)
203     {
204         closeDataSet(dataset);
205         return -1;
206     }
207 
208 
209     std::vector<int> d(dims);
210     int size = getDatasetInfo(node, &complex, &dims, d.data());
211 
212     if (dims == 0 || size <= 0)
213     {
214         closeDataSet(node);
215         return -1;
216     }
217 
218     readStringMatrix(node, val);
219     return node;
220 }
221 
getHandleStringVector(hid_t dataset,const std::string & prop,int * row,int * col,char *** vals)222 static int getHandleStringVector(hid_t dataset, const std::string& prop, int* row, int* col, char*** vals)
223 {
224     hid_t node = 0;
225     node = getDataSetIdFromName(dataset, prop.data());
226     if (node < 0)
227     {
228         return -1;
229     }
230 
231     int complex = 0;
232     int dims = 0;;
233     int ret = getDatasetInfo(node, &complex, &dims, NULL);
234     if (ret < 0)
235     {
236         closeDataSet(dataset);
237         return -1;
238     }
239 
240 
241     std::vector<int> d(dims);
242     int size = getDatasetInfo(node, &complex, &dims, d.data());
243 
244     if (dims == 0 || size <= 0)
245     {
246         closeDataSet(node);
247         return -1;
248     }
249 
250     *row = d[0];
251     *col = d[1];
252 
253     *vals = new char*[size];
254     readStringMatrix(node, *vals);
255     return node;
256 }
257 
258 static int import_handle_generic(hid_t dataset, int uid, int parent, const HandleProp& props, bool childrenFirst);
259 
import_userdata(hid_t dataset,int uid)260 static void import_userdata(hid_t dataset, int uid)
261 {
262     types::InternalType* ud = nullptr;
263     hid_t node = 0;
264     node = getDataSetIdFromName(dataset, "userdata");
265     if (node < 0)
266     {
267         //no user data ?
268         //assign an empty matrix
269         ud = types::Double::Empty();
270     }
271     else
272     {
273         ud = import_data(node);
274     }
275 
276     //increase ref before trying to delete old value to avoid double free
277     ud->IncreaseRef();
278 
279     //get previous value
280     int size = 0;
281     int *psize = &size;
282     int *data = NULL;
283 
284     getGraphicObjectProperty(uid, __GO_USER_DATA_SIZE__, jni_int, (void **)&psize);
285     getGraphicObjectProperty(uid, __GO_USER_DATA__, jni_int_vector, (void **)&data);
286 
287     if (size != 0)
288     {
289         types::InternalType* previous = nullptr;
290         if (size == 1)
291         {
292             //32 bits
293             int* p = (int*)data;
294             previous = ((types::InternalType*) * p);
295         }
296         else
297         {
298             //64 bits
299             long long* p = (long long*)data;
300             previous = ((types::InternalType*) * p);
301         }
302 
303         previous->DecreaseRef();
304         previous->killMe();
305     }
306 
307     //set new value
308     size = sizeof(void*) / sizeof(int);
309     setGraphicObjectProperty(uid, __GO_USER_DATA__, &ud, jni_int_vector, size);
310 }
311 
import_handle_tag(hid_t dataset,int uid)312 static void import_handle_tag(hid_t dataset, int uid)
313 {
314     char* tag = nullptr;
315     int node = getHandleString(dataset, "tag", &tag);
316     setGraphicObjectProperty(uid, __GO_TAG__, tag, jni_string, 1);
317     freeStringMatrix(node, &tag);
318 }
319 
import_handle_children(hid_t dataset,int parent)320 static int import_handle_children(hid_t dataset, int parent)
321 {
322     //reload children
323     hid_t children = getDataSetIdFromName(dataset, "children");
324     int childcount = 0;
325     getListDims6(children, &childcount);
326 
327     //reverse order
328     for (int i = childcount - 1; i >= 0; --i)
329     {
330         hid_t c = getDataSetIdFromName(children, std::to_string(i).data());
331         int newChild = import_handle(c, parent);
332     }
333 
334     closeList6(children);
335     return parent;
336 }
337 
import_handle_generic(hid_t dataset,int uid,int parent,const HandleProp & props,bool childrenFirst)338 static int import_handle_generic(hid_t dataset, int uid, int parent, const HandleProp& props, bool childrenFirst)
339 {
340     //link current handle with its parent
341     if (parent != -1)
342     {
343         setGraphicObjectRelationship(parent, uid);
344     }
345     //restore children before other property in case of properties has an
346     //effect on children
347 
348     //reload children
349     if (childrenFirst)
350     {
351         import_handle_children(dataset, uid);
352     }
353 
354     for (auto & prop : props)
355     {
356         const char* name = prop.first.data();
357         std::vector<int> info(prop.second);
358 
359         if (info[0] == SAVE_ONLY)
360         {
361             continue;
362         }
363 
364         int go = info[1];
365         int type = info[2];
366         int row = 0;
367         int col = 0;
368 
369         switch (type)
370         {
371             case jni_bool:
372             {
373                 int val = 0;
374                 getHandleBool(dataset, name, &val);
375                 setGraphicObjectProperty(uid, go, &val, jni_bool, 1);
376                 break;
377             }
378             case jni_int:
379             {
380                 int val = 0;
381                 getHandleInt(dataset, name, &val);
382                 setGraphicObjectProperty(uid, go, &val, jni_int, 1);
383                 break;
384             }
385             case jni_double:
386             {
387                 double val = 0;
388                 getHandleDouble(dataset, name, &val);
389                 setGraphicObjectProperty(uid, go, &val, jni_double, 1);
390                 break;
391             }
392             case jni_string:
393             {
394                 char* data = nullptr;
395                 int node = getHandleString(dataset, name, &data);
396                 setGraphicObjectProperty(uid, go, data, jni_string, 1);
397                 freeStringMatrix(node, &data);
398                 break;
399             }
400             case jni_bool_vector:
401             {
402                 int* vals = nullptr;
403                 getHandleBoolVector(dataset, name, &row, &col, &vals);
404                 if (vals)
405                 {
406                     setGraphicObjectProperty(uid, go, vals, jni_bool_vector, row * col);
407                     delete[] vals;
408                 }
409                 break;
410             }
411             case jni_int_vector:
412             {
413                 int* vals = nullptr;
414                 getHandleIntVector(dataset, name, &row, &col, &vals);
415                 if (vals)
416                 {
417                     setGraphicObjectProperty(uid, go, vals, jni_int_vector, row * col);
418                     delete[] vals;
419                 }
420                 break;
421             }
422             case jni_double_vector:
423             {
424                 double* vals = nullptr;
425                 getHandleDoubleVector(dataset, name, &row, &col, &vals);
426                 if (vals)
427                 {
428                     setGraphicObjectProperty(uid, go, vals, jni_double_vector, row * col);
429                     delete[] vals;
430                 }
431                 break;
432             }
433             case jni_string_vector:
434             {
435                 char** vals = nullptr;
436                 int node = getHandleStringVector(dataset, name, &row, &col, &vals);
437                 if (vals)
438                 {
439                     setGraphicObjectProperty(uid, go, vals, jni_string_vector, row * col);
440                 }
441 
442                 freeStringMatrix(node, vals);
443                 delete[] vals;
444                 break;
445             }
446         }
447     }
448 
449     //userdata
450     import_userdata(dataset, uid);
451 
452     //tag
453     import_handle_tag(dataset, uid);
454 
455     //reload children
456     if (childrenFirst == false)
457     {
458         import_handle_children(dataset, uid);
459     }
460 
461     return uid;
462 }
463 
464 static int import_handle_border(hid_t dataset);
465 
import_handle_border_none(hid_t dataset,int border)466 static int import_handle_border_none(hid_t dataset, int border)
467 {
468     closeList6(dataset);
469     return border;
470 }
471 
import_handle_border_line(hid_t dataset,int border)472 static int import_handle_border_line(hid_t dataset, int border)
473 {
474     int status = 0;
475     //color
476     char* color = nullptr;
477     int nc = getHandleString(dataset, "color", &color);
478     setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_COLOR__, color, jni_string, 1);
479     freeStringMatrix(nc, &color);
480 
481     //thickness
482     int thickness = 0;
483     status = getHandleInt(dataset, "thickness", &thickness);
484     if (status != -1)
485     {
486         setGraphicObjectProperty(border, __GO_LINE_THICKNESS__, &thickness, jni_int, 1);
487     }
488 
489     //rounded
490     int rounded = 0;
491     status = getHandleBool(dataset, "rounded", &rounded);
492     if (status != -1)
493     {
494         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_ROUNDED__, &rounded, jni_bool, 1);
495     }
496 
497     closeList6(dataset);
498     return border;
499 }
500 
import_handle_border_bevel(hid_t dataset,int border)501 static int import_handle_border_bevel(hid_t dataset, int border)
502 {
503     char* data = nullptr;
504     int node = 0;
505     //type
506     int type = 0;
507     getHandleInt(dataset, "type", &type);
508     setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_TYPE__, &type, jni_int, 1);
509 
510     //highlight out
511     node = getHandleString(dataset, "highlight_out", &data);
512     if (data)
513     {
514         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, data, jni_string, 1);
515     }
516 
517     freeStringMatrix(node, &data);
518     data = nullptr;
519 
520     //highlight in
521     node = getHandleString(dataset, "highlight_in", &data);
522     if (data)
523     {
524         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, data, jni_string, 1);
525     }
526 
527     freeStringMatrix(node, &data);
528     data = nullptr;
529 
530     //shadow out
531     node = getHandleString(dataset, "shadow_out", &data);
532     if (data)
533     {
534         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_SHADOW_OUT__, data, jni_string, 1);
535     }
536 
537     freeStringMatrix(node, &data);
538     data = nullptr;
539 
540     //shadow in
541     node = getHandleString(dataset, "shadow_in", &data);
542     if (data)
543     {
544         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_SHADOW_IN__, data, jni_string, 1);
545     }
546 
547     freeStringMatrix(node, &data);
548     data = nullptr;
549 
550     closeList6(dataset);
551     return border;
552 }
553 
import_handle_border_soft_bevel(hid_t dataset,int border)554 static int import_handle_border_soft_bevel(hid_t dataset, int border)
555 {
556     return import_handle_border_bevel(dataset, border);
557 }
558 
import_handle_border_etched(hid_t dataset,int border)559 static int import_handle_border_etched(hid_t dataset, int border)
560 {
561     int status = 0;
562     char* data = nullptr;
563     int node = 0;
564 
565     //type
566     int type = 0;
567     status = getHandleInt(dataset, "type", &type);
568     if (status != -1)
569     {
570         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_TYPE__, &type, jni_int, 1);
571     }
572 
573     //highlight out
574     node = getHandleString(dataset, "highlight_out", &data);
575     if (data)
576     {
577         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, data, jni_string, 1);
578     }
579 
580     freeStringMatrix(node, &data);
581     data = nullptr;
582 
583     //shadow out
584     node = getHandleString(dataset, "shadow_out", &data);
585     if (data)
586     {
587         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_SHADOW_OUT__, data, jni_string, 1);
588     }
589 
590     freeStringMatrix(node, &data);
591     data = nullptr;
592 
593     closeList6(dataset);
594     return border;
595 }
596 
import_handle_border_titled(hid_t dataset,int border)597 static int import_handle_border_titled(hid_t dataset, int border)
598 {
599     char* data = nullptr;
600     int node = 0;
601     int status = 0;
602 
603     //title border
604     hid_t title_border = getDataSetIdFromName(dataset, "title_border");
605     if (title_border != -1)
606     {
607         int hidden = 1;
608         int uiborder = import_handle_border(title_border);
609         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_TITLE__, &uiborder, jni_int, 1);
610         //force new border to be hide in scilab view
611         setGraphicObjectProperty(uiborder, __GO_HIDDEN__, &hidden, jni_bool, 1);
612     }
613 
614     //title
615     node = getHandleString(dataset, "title", &data);
616     if (data)
617     {
618         setGraphicObjectProperty(border, __GO_TITLE__, data, jni_string, 1);
619     }
620 
621     freeStringMatrix(node, &data);
622     data = nullptr;
623 
624     //justification
625     int justification = 0;
626     status = getHandleInt(dataset, "justification", &justification);
627     if (status != -1)
628     {
629         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_JUSTIFICATION__, &justification, jni_int, 1);
630     }
631 
632     //fontname
633     node = getHandleString(dataset, "fontname", &data);
634     if (data)
635     {
636         setGraphicObjectProperty(border, __GO_UI_FONTNAME__, data, jni_string, 1);
637     }
638 
639     freeStringMatrix(node, &data);
640     data = nullptr;
641 
642     //fontangle
643     node = getHandleString(dataset, "fontangle", &data);
644     if (data)
645     {
646         setGraphicObjectProperty(border, __GO_UI_FONTANGLE__, data, jni_string, 1);
647     }
648 
649     freeStringMatrix(node, &data);
650     data = nullptr;
651 
652     //fontsize
653     int fontsize = 0;
654     status = getHandleInt(dataset, "fontsize", &fontsize);
655     if (status != -1)
656     {
657         setGraphicObjectProperty(border, __GO_UI_FONTSIZE__, &fontsize, jni_int, 1);
658     }
659 
660     //fontweight
661     node = getHandleString(dataset, "fontweight", &data);
662     if (data)
663     {
664         setGraphicObjectProperty(border, __GO_UI_FONTWEIGHT__, data, jni_string, 1);
665     }
666 
667     freeStringMatrix(node, &data);
668     data = nullptr;
669 
670     //position
671     int position = 0;
672     status = getHandleInt(dataset, "position", &position);
673     if (status != -1)
674     {
675         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_POSITION__, &position, jni_int, 1);
676     }
677 
678     //color
679     node = getHandleString(dataset, "color", &data);
680     if (data)
681     {
682         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_COLOR__, data, jni_string, 1);
683     }
684 
685     freeStringMatrix(node, &data);
686     data = nullptr;
687 
688     closeList6(dataset);
689     return border;
690 }
691 
import_handle_border_empty(hid_t dataset,int border)692 static int import_handle_border_empty(hid_t dataset, int border)
693 {
694     int row = 0;
695     int col = 0;
696     double* pos = nullptr;
697 
698     getHandleDoubleVector(dataset, "position", &row, &col, &pos);
699     if (pos && row * col == 4)
700     {
701         setGraphicObjectProperty(border, __GO_POSITION__, pos, jni_double_vector, row * col);
702     }
703     delete[] pos;
704 
705     closeList6(dataset);
706     return border;
707 }
708 
import_handle_border_compound(hid_t dataset,int border)709 static int import_handle_border_compound(hid_t dataset, int border)
710 {
711     //out_border
712     hid_t out_border = getDataSetIdFromName(dataset, "out_border");
713     if (out_border != -1)
714     {
715         int hidden = 1;
716         int uiborder = import_handle_border(out_border);
717         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_OUT_BORDER__, &uiborder, jni_int, 1);
718         //force new border to be hide in scilab view
719         setGraphicObjectProperty(uiborder, __GO_HIDDEN__, &hidden, jni_bool, 1);
720     }
721 
722     //in_border
723     hid_t in_border = getDataSetIdFromName(dataset, "in_border");
724     if (in_border != -1)
725     {
726         int hidden = 1;
727         int uiborder = import_handle_border(in_border);
728         setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_IN_BORDER__, &uiborder, jni_int, 1);
729         //force new border to be hide in scilab view
730         setGraphicObjectProperty(uiborder, __GO_HIDDEN__, &hidden, jni_bool, 1);
731     }
732 
733     closeList6(dataset);
734     return border;
735 }
736 
import_handle_border_matte(hid_t dataset,int border)737 static int import_handle_border_matte(hid_t dataset, int border)
738 {
739     int row = 0;
740     int col = 0;
741     double* pos = nullptr;
742 
743     getHandleDoubleVector(dataset, "position", &row, &col, &pos);
744     setGraphicObjectProperty(border, __GO_POSITION__, pos, jni_double_vector, row * col);
745     delete[] pos;
746 
747     //color
748     char* data = nullptr;
749     int nc = getHandleString(dataset, "color", &data);
750     setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_COLOR__, data, jni_string, 1);
751     freeStringMatrix(nc, &data);
752 
753     closeList6(dataset);
754     return border;
755 }
756 
import_handle_border(hid_t dataset)757 static int import_handle_border(hid_t dataset)
758 {
759     int border = createGraphicObject(__GO_UI_FRAME_BORDER__);
760     int style = 0;
761     getHandleInt(dataset, "style", &style);
762 
763     setGraphicObjectProperty(border, __GO_UI_FRAME_BORDER_STYLE__, &style, jni_int, 1);
764 
765     switch (style)
766     {
767         default:
768         case NONE:
769             return import_handle_border_none(dataset, border);
770         case LINE:
771             return import_handle_border_line(dataset, border);
772         case BEVEL:
773             return import_handle_border_bevel(dataset, border);
774         case SOFTBEVEL:
775             return import_handle_border_soft_bevel(dataset, border);
776         case ETCHED:
777             return import_handle_border_etched(dataset, border);
778         case TITLED:
779             return import_handle_border_titled(dataset, border);
780         case EMPTY:
781             return import_handle_border_empty(dataset, border);
782         case COMPOUND:
783             return import_handle_border_compound(dataset, border);
784         case MATTE:
785             return import_handle_border_matte(dataset, border);
786     }
787 }
788 
import_handle_uicontrol(hid_t dataset,int parent)789 static int import_handle_uicontrol(hid_t dataset, int parent)
790 {
791     int style = 0;
792     getHandleInt(dataset, "style", &style);
793     //uicontrol was created by their style instead of type like others graphic objects.
794     int uic = createGraphicObject(style);
795 
796     //some properties must be set before parent ( in import_handle_generic )
797 
798     //scrollable
799     int scrollable = 0;
800     getHandleBool(dataset, "scrollable", &scrollable);
801     setGraphicObjectProperty(uic, __GO_UI_SCROLLABLE__, &scrollable, jni_bool, 1);
802 
803     //margins
804     int row = 0;
805     int col = 0;
806 
807     double* margins = nullptr;
808     getHandleDoubleVector(dataset, "margins", &row, &col, &margins);
809     setGraphicObjectProperty(uic, __GO_MARGINS__, margins, jni_double_vector, row * col);
810     delete[] margins;
811 
812     //constraints
813 
814     //border_position
815     int border_position = 0;
816     getHandleInt(dataset, "border_position", &border_position);
817     setGraphicObjectProperty(uic, __GO_UI_BORDER_POSITION__, &border_position, jni_int, 1);
818 
819     //border_size
820     int* border_size = nullptr;
821     getHandleIntVector(dataset, "border_size", &row, &col, &border_size);
822     setGraphicObjectProperty(uic, __GO_UI_BORDER_PREFERREDSIZE__, border_size, jni_int_vector, row * col);
823     delete[] border_size;
824 
825     //gridbad_grid
826     int* gridbad_grid = nullptr;
827     getHandleIntVector(dataset, "gridbad_grid", &row, &col, &gridbad_grid);
828     setGraphicObjectProperty(uic, __GO_UI_GRIDBAG_GRID__, gridbad_grid, jni_int_vector, row * col);
829     delete[] gridbad_grid;
830 
831     //gridbad_weight
832     double* gridbad_weight = nullptr;
833     getHandleDoubleVector(dataset, "gridbad_weight", &row, &col, &gridbad_weight);
834     setGraphicObjectProperty(uic, __GO_UI_GRIDBAG_WEIGHT__, gridbad_weight, jni_double_vector, row * col);
835     delete[] gridbad_weight;
836 
837     //gridbad_fill
838     int gridbad_fill = 0;
839     getHandleInt(dataset, "gridbad_fill", &gridbad_fill);
840     setGraphicObjectProperty(uic, __GO_UI_GRIDBAG_FILL__, &gridbad_fill, jni_int, 1);
841 
842     //gridbad_anchor
843     int gridbad_anchor = 0;
844     getHandleInt(dataset, "gridbad_anchor", &gridbad_anchor);
845     setGraphicObjectProperty(uic, __GO_UI_GRIDBAG_ANCHOR__, &gridbad_anchor, jni_int, 1);
846 
847     //gridbad_padding
848     int* gridbad_padding = nullptr;
849     getHandleIntVector(dataset, "gridbad_padding", &row, &col, &gridbad_padding);
850     setGraphicObjectProperty(uic, __GO_UI_GRIDBAG_PADDING__, gridbad_padding, jni_int_vector, row * col);
851     delete[] gridbad_padding;
852 
853     //gridbad_size
854     int* gridbad_size = nullptr;
855     getHandleIntVector(dataset, "gridbad_size", &row, &col, &gridbad_size);
856     setGraphicObjectProperty(uic, __GO_UI_GRIDBAG_PREFERREDSIZE__, gridbad_size, jni_int_vector, row * col);
857     delete[] gridbad_size;
858 
859     //import "standards" properties
860     import_handle_generic(dataset, uic, parent, UicontrolHandle::getPropertyList(), false);
861 
862     //string
863     char** string = nullptr;
864     int node = getHandleStringVector(dataset, "string", &row, &col, &string);
865     setGraphicObjectProperty(uic, __GO_UI_STRING_COLNB__, &col, jni_int, 1);
866     setGraphicObjectProperty(uic, __GO_UI_STRING__, string, jni_string_vector, row * col);
867     freeStringMatrix(node, string);
868     delete[] string;
869 
870     //border
871     hid_t dborder = getDataSetIdFromName(dataset, "border");
872     int border = import_handle_border(dborder);
873     setGraphicObjectProperty(uic, __GO_UI_FRAME_BORDER__, &border, jni_int, 1);
874 
875 
876     //value
877     double* value = nullptr;
878     getHandleDoubleVector(dataset, "value", &row, &col, &value);
879     if (value)
880     {
881         setGraphicObjectProperty(uic, __GO_UI_VALUE__, value, jni_double_vector, row * col);
882         delete[] value;
883     }
884 
885     closeList6(dataset);
886     return uic;
887 }
888 
import_handle_uicontextmenu(hid_t dataset,int parent)889 static int import_handle_uicontextmenu(hid_t dataset, int parent)
890 {
891     int menu = createGraphicObject(__GO_UICONTEXTMENU__);
892 
893     //import "standards" properties
894     import_handle_generic(dataset, menu, parent, UicontextmenuHandle::getPropertyList(), false);
895 
896     closeList6(dataset);
897     return menu;
898 }
899 
import_handle_uimenu(hid_t dataset,int parent)900 static int import_handle_uimenu(hid_t dataset, int parent)
901 {
902     int menu = createGraphicObject(__GO_UIMENU__);
903 
904     //import "standards" properties
905     import_handle_generic(dataset, menu, parent, UimenuHandle::getPropertyList(), false);
906 
907     closeList6(dataset);
908     return menu;
909 }
910 
import_handle_light(hid_t dataset,int parent)911 static int import_handle_light(hid_t dataset, int parent)
912 {
913     int light = createGraphicObject(__GO_LIGHT__);
914 
915     //import "standards" properties
916     import_handle_generic(dataset, light, parent, LightHandle::getPropertyList(), true);
917 
918     closeList6(dataset);
919     return light;
920 }
921 
import_handle_axis(hid_t dataset,int parent)922 static int import_handle_axis(hid_t dataset, int parent)
923 {
924     int axis = createGraphicObject(__GO_AXIS__);
925 
926     //import "standards" properties
927     import_handle_generic(dataset, axis, parent, AxisHandle::getPropertyList(), true);
928 
929     closeList6(dataset);
930     return axis;
931 }
932 
import_handle_text(hid_t dataset,int parent)933 static int import_handle_text(hid_t dataset, int parent)
934 {
935     int t = createGraphicObject(__GO_TEXT__);
936 
937     //import "standards" properties
938     import_handle_generic(dataset, t, parent, TextHandle::getPropertyList(), true);
939 
940 
941     //text
942     int dims[2];
943     char** text = nullptr;
944     int textnode = getHandleStringVector(dataset, "text", &dims[0], &dims[1], &text);
945     setGraphicObjectProperty(t, __GO_TEXT_ARRAY_DIMENSIONS__, dims, jni_int_vector, 2);
946     setGraphicObjectProperty(t, __GO_TEXT_STRINGS__, text, jni_string_vector, dims[0] * dims[1]);
947     freeStringMatrix(textnode, text);
948     delete[] text;
949     closeList6(dataset);
950     return t;
951 }
952 
import_handle_legend(hid_t dataset,int parent)953 static int import_handle_legend(hid_t dataset, int parent)
954 {
955     int legend = createGraphicObject(__GO_LEGEND__);
956 
957     //import "standards" properties
958     import_handle_generic(dataset, legend, parent, LegendHandle::getPropertyList(), true);
959 
960 
961     //text
962     int dims[2];
963     char** text = nullptr;
964     int textnode = getHandleStringVector(dataset, "text", &dims[0], &dims[1], &text);
965     setGraphicObjectProperty(legend, __GO_TEXT_ARRAY_DIMENSIONS__, dims, jni_int_vector, 2);
966     setGraphicObjectProperty(legend, __GO_TEXT_STRINGS__, text, jni_string_vector, dims[0] * dims[1]);
967     freeStringMatrix(textnode, text);
968     delete[] text;
969     //links
970 
971     //to retore links we need to have the entire hierarchie loaded.
972     //store links information in a "global" variable and update variable at the end of process.
973     hid_t node = getDataSetIdFromName(dataset, "links");
974     int count = 0;
975     getListDims6(node, &count);
976 
977     Links::PathList paths;
978 
979     for (int i = 0; i < count; ++i)
980     {
981         int row = 0;
982         int col = 0;
983         int* path = nullptr;
984         getHandleIntVector(node, std::to_string(i).data(), &row, &col, &path);
985         std::vector<int> res(row * col);
986         for (int j = 0; j < row * col; ++j)
987         {
988             res[j] = path[j];
989         }
990 
991         delete[] path;
992 
993         paths.push_back(res);
994     }
995 
996     Links::add(legend, paths);
997 
998     closeList6(node);
999     closeList6(dataset);
1000     return legend;
1001 }
1002 
import_handle_fec(hid_t dataset,int parent)1003 static int import_handle_fec(hid_t dataset, int parent)
1004 {
1005     int fec = createGraphicObject(__GO_FEC__);
1006     createDataObject(fec, __GO_FEC__);
1007 
1008     //import "standards" properties
1009     import_handle_generic(dataset, fec, parent, FecHandle::getPropertyList(), true);
1010 
1011     //triangles
1012     int coordR = 0;
1013     int coordC = 0;
1014     int valuesR = 0;
1015     int valuesC = 0;
1016     int trianglesR = 0;
1017     int trianglesC = 0;
1018 
1019     double* coords = nullptr;
1020     getHandleDoubleVector(dataset, "coords", &coordR, &coordC, &coords);
1021     double* values = nullptr;
1022     getHandleDoubleVector(dataset, "values", &valuesR, &valuesC, &values);
1023     double* triangles = nullptr;
1024     getHandleDoubleVector(dataset, "triangles", &trianglesR, &trianglesC, &triangles);
1025     int realcol = trianglesC - 2;
1026 
1027     setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_NUM_VERTICES__, &valuesC, jni_int, 1);
1028     setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_NUM_VERTICES_BY_ELEM__, &realcol, jni_int, 1);
1029     setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_NUM_INDICES__, &trianglesR, jni_int, 1);
1030     //setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_X__, coords, jni_double_vector, coordR);
1031     //setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_Y__, coords + coordR, jni_double_vector, coordR);
1032     setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_COORDINATES__, coords, jni_double_vector, coordC);
1033     setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_FEC_ELEMENTS__, triangles, jni_double_vector, trianglesR);
1034     setGraphicObjectPropertyAndNoWarn(fec, __GO_DATA_MODEL_VALUES__, values, jni_double_vector, valuesC);
1035 
1036     delete[] coords;
1037     delete[] values;
1038     delete[] triangles;
1039 
1040     closeList6(dataset);
1041     return fec;
1042 }
1043 
import_handle_matplot(hid_t dataset,int parent)1044 static int import_handle_matplot(hid_t dataset, int parent)
1045 {
1046     int plot = createGraphicObject(__GO_MATPLOT__);
1047     createDataObject(plot, __GO_MATPLOT__);
1048 
1049     //import "standards" properties
1050     import_handle_generic(dataset, plot, parent, MatplotHandle::getPropertyList(), true);
1051 
1052     int row = 0;
1053     int col = 0;
1054     //rect
1055     double* rect = nullptr;
1056     getHandleDoubleVector(dataset, "rect", &row, &col, &rect);
1057     double tmp = rect[1];
1058     rect[1] = rect[2];
1059     rect[2] = tmp;
1060 
1061     //data
1062     int num_x = 0;
1063     int num_y = 0;
1064     getHandleInt(dataset, "num_x", &num_x);
1065     getHandleInt(dataset, "num_y", &num_y);
1066     double* data = nullptr;
1067     int data_x = 0;
1068     int data_y = 0;
1069     getHandleDoubleVector(dataset, "data", &data_x, &data_y, &data);
1070 
1071     int grid[4];
1072     grid[0] = num_x;
1073     grid[1] = 1;
1074     grid[2] = num_y;
1075     grid[3] = 1;
1076 
1077     setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_GRID_SIZE__, grid, jni_int_vector, 4);
1078 
1079     double scale[2];
1080     setGraphicObjectProperty(plot, __GO_MATPLOT_TRANSLATE__, rect, jni_double_vector, 2);
1081     scale[0] = (rect[2] - rect[0]) / (num_x - 1.0);
1082     scale[1] = (rect[3] - rect[1]) / (num_y - 1.0);
1083     setGraphicObjectProperty(plot, __GO_MATPLOT_SCALE__, scale, jni_double_vector, 2);
1084 
1085     setGraphicObjectProperty(plot, __GO_DATA_MODEL_MATPLOT_BOUNDS__, rect, jni_double_vector, 4);
1086 
1087     setGraphicObjectProperty(plot, __GO_DATA_MODEL_MATPLOT_IMAGE_DATA__, data, jni_double_vector, data_x * data_y);
1088 
1089     delete[] rect;
1090     delete[] data;
1091 
1092     closeList6(dataset);
1093     return plot;
1094 }
1095 
import_handle_grayplot(hid_t dataset,int parent)1096 static int import_handle_grayplot(hid_t dataset, int parent)
1097 {
1098     int plot = createGraphicObject(__GO_GRAYPLOT__);
1099     createDataObject(plot, __GO_GRAYPLOT__);
1100 
1101     //import "standards" properties
1102     import_handle_generic(dataset, plot, parent, GrayplotHandle::getPropertyList(), true);
1103 
1104     int row = 0;
1105     int col = 0;
1106     double* dataX = nullptr;
1107     double* dataY = nullptr;
1108     double* dataZ = nullptr;
1109     getHandleDoubleVector(dataset, "data_x", &row, &col, &dataX);
1110     getHandleDoubleVector(dataset, "data_y", &row, &col, &dataY);
1111     getHandleDoubleVector(dataset, "data_z", &row, &col, &dataZ);
1112 
1113     int grid[4];
1114     grid[0] = row;
1115     grid[1] = 1;
1116     grid[2] = col;
1117     grid[3] = 1;
1118 
1119     //set dimensions
1120     setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_GRID_SIZE__, grid, jni_int_vector, 4);
1121 
1122     //set data
1123     setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_X__, dataX, jni_double_vector, row);
1124     setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, col);
1125     setGraphicObjectProperty(plot, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, row * col);
1126 
1127     closeList6(dataset);
1128     return plot;
1129 }
1130 
import_handle_segs(hid_t dataset,int parent)1131 static int import_handle_segs(hid_t dataset, int parent)
1132 {
1133     int segs = createGraphicObject(__GO_SEGS__);
1134 
1135     //import "standards" properties
1136     import_handle_generic(dataset, segs, parent, SegsHandle::getPropertyList(), true);
1137 
1138     closeList6(dataset);
1139     return segs;
1140 }
1141 
import_handle_arc(hid_t dataset,int parent)1142 static int import_handle_arc(hid_t dataset, int parent)
1143 {
1144     int arc = createGraphicObject(__GO_ARC__);
1145 
1146     //import "standards" properties
1147     import_handle_generic(dataset, arc, parent, ArcHandle::getPropertyList(), true);
1148 
1149     closeList6(dataset);
1150     return arc;
1151 }
1152 
import_handle_rectangle(hid_t dataset,int parent)1153 static int import_handle_rectangle(hid_t dataset, int parent)
1154 {
1155     int rect = createGraphicObject(__GO_RECTANGLE__);
1156 
1157     //import "standards" properties
1158     import_handle_generic(dataset, rect, parent, RectangleHandle::getPropertyList(), true);
1159 
1160     closeList6(dataset);
1161     return rect;
1162 }
1163 
import_handle_compound(hid_t dataset,int parent)1164 static int import_handle_compound(hid_t dataset, int parent)
1165 {
1166     int compound = createGraphicObject(__GO_COMPOUND__);
1167 
1168     //import "standards" properties
1169     import_handle_generic(dataset, compound, parent, CompoundHandle::getPropertyList(), true);
1170 
1171     closeList6(dataset);
1172     return compound;
1173 }
1174 
import_handle_datatip(hid_t dataset,int parent)1175 static int import_handle_datatip(hid_t dataset, int parent)
1176 {
1177     int datatip = createGraphicObject(__GO_DATATIP__);
1178     //set parent manually, these no real releationship between datatip and parent
1179     setGraphicObjectProperty(datatip, __GO_PARENT__, &parent, jni_int, 1);
1180 
1181     //data
1182     int index = 0;
1183     getHandleInt(dataset, "data_index", &index);
1184     double indexes[2];
1185     indexes[0] = index;
1186     indexes[1] = 0;
1187 
1188     setGraphicObjectProperty(datatip, __GO_DATATIP_INDEXES__, indexes, jni_double_vector, 2);
1189 
1190     //import "standards" properties
1191     import_handle_generic(dataset, datatip, -1, DatatipHandle::getPropertyList(), true);
1192 
1193     closeList6(dataset);
1194     return datatip;
1195 }
1196 
import_handle_datatips(hid_t dataset,int uid)1197 static int import_handle_datatips(hid_t dataset, int uid)
1198 {
1199     hid_t datatip = getDataSetIdFromName(dataset, "datatips");
1200     int count = 0;
1201     getListDims6(datatip, &count);
1202 
1203     std::vector<int> datatips(count);
1204     for (int i = 0; i < count; ++i)
1205     {
1206         hid_t d = getDataSetIdFromName(datatip, std::to_string(i).data());
1207         datatips[i] = import_handle_datatip(d, uid);
1208     }
1209 
1210     setGraphicObjectProperty(uid, __GO_DATATIPS__, datatips.data(), jni_int_vector, count);
1211 
1212     closeList6(datatip);
1213     return uid;
1214 }
1215 
import_polyline_shift(hid_t dataset,int uid,const std::string & name,int go_set,int go_data)1216 static int import_polyline_shift(hid_t dataset, int uid, const std::string& name, int go_set, int go_data)
1217 {
1218     int row = 0;
1219     int col = 0;
1220     int set = 0;
1221     double* data = nullptr;
1222 
1223     getHandleDoubleVector(dataset, name.data(), &row, &col, &data);
1224     if (row * col != 0)
1225     {
1226         set = 1;
1227         setGraphicObjectProperty(uid, go_data, data, jni_double_vector, row * col);
1228     }
1229     else
1230     {
1231         set = 0;
1232     }
1233 
1234     delete[] data;
1235     setGraphicObjectProperty(uid, go_set, &set, jni_int, 1);
1236     return uid;
1237 }
1238 
updateXYDataBounds(double rect[6],int axes=-1)1239 static void updateXYDataBounds(double rect[6], int axes = -1)
1240 {
1241     int firstPlot = 0;
1242     int * piFirstPlot = &firstPlot;
1243     if (axes == -1)
1244     {
1245         axes = getOrCreateDefaultSubwin();
1246     }
1247 
1248     getGraphicObjectProperty(axes, __GO_FIRST_PLOT__, jni_bool, (void **)&piFirstPlot);
1249     if (firstPlot)
1250     {
1251         rect[4] = 0;
1252         rect[5] = 0;
1253     }
1254     else
1255     {
1256         double * dataBounds = NULL;
1257         getGraphicObjectProperty(axes, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);
1258 
1259         rect[0] = Min(rect[0], dataBounds[0]);
1260         rect[1] = Max(rect[1], dataBounds[1]);
1261         rect[2] = Min(rect[2], dataBounds[2]);
1262         rect[3] = Max(rect[3], dataBounds[3]);
1263         rect[4] = dataBounds[4];
1264         rect[5] = dataBounds[5];
1265     }
1266 
1267     setGraphicObjectProperty(axes, __GO_DATA_BOUNDS__, rect, jni_double_vector, 6);
1268 }
1269 
mustUpdate(int axes=-1)1270 static int mustUpdate(int axes = -1)
1271 {
1272     int iTmp = 0;
1273     int * piTmp = &iTmp;
1274     if (axes == -1)
1275     {
1276         axes = getOrCreateDefaultSubwin();
1277     }
1278 
1279     getGraphicObjectProperty(axes, __GO_AUTO_SCALE__, jni_bool, (void **)&piTmp);
1280     return iTmp;
1281 }
1282 
MiniMaxi(const double vect[],int n,double * const min,double * const max)1283 void MiniMaxi(const double vect[], int n, double * const min, double * const max)
1284 {
1285     int i = 0;
1286     double _min = DBL_MAX;
1287     double _max = -DBL_MAX;
1288     for (; i < n; i++)
1289     {
1290         /*    if ( isinf(vect[i])== 0 && isnan(vect[i])==0 && vect[i] < vmin)  */
1291         if (finite(vect[i]) == 1)
1292         {
1293             if (vect[i] < _min)
1294             {
1295                 _min = vect[i];
1296             }
1297             if (vect[i] > _max)
1298             {
1299                 _max = vect[i];
1300             }
1301         }
1302     }
1303 
1304     *min = _min;
1305     *max = _max;
1306 }
1307 
1308 
import_handle_polyline(hid_t dataset,int parent)1309 static int import_handle_polyline(hid_t dataset, int parent)
1310 {
1311     int polyline = createGraphicObject(__GO_POLYLINE__);
1312     createDataObject(polyline, __GO_POLYLINE__);
1313 
1314     //import "standards" properties
1315     import_handle_generic(dataset, polyline, parent, PolylineHandle::getPropertyList(), true);
1316 
1317     //x_shift
1318     import_polyline_shift(dataset, polyline, "x_shift", __GO_DATA_MODEL_X_COORDINATES_SHIFT_SET__, __GO_DATA_MODEL_X_COORDINATES_SHIFT__);
1319     //y_shift
1320     import_polyline_shift(dataset, polyline, "y_shift", __GO_DATA_MODEL_Y_COORDINATES_SHIFT_SET__, __GO_DATA_MODEL_Y_COORDINATES_SHIFT__);
1321     //z_shift
1322     import_polyline_shift(dataset, polyline, "z_shift", __GO_DATA_MODEL_Z_COORDINATES_SHIFT_SET__, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__);
1323 
1324 
1325     //interp_color_vector
1326     {
1327         int row = 0;
1328         int col = 0;
1329         int set = 0;
1330         int* data = nullptr;
1331 
1332         getHandleIntVector(dataset, "interp_color_vector", &row, &col, &data);
1333         if (row * col != 0)
1334         {
1335             set = 1;
1336             setGraphicObjectProperty(polyline, __GO_INTERP_COLOR_VECTOR__, data, jni_double_vector, row * col);
1337         }
1338         else
1339         {
1340             set = 0;
1341         }
1342 
1343         delete[] data;
1344         setGraphicObjectProperty(polyline, __GO_INTERP_COLOR_VECTOR_SET__, &set, jni_bool, 1);
1345     }
1346 
1347     //data
1348     {
1349         int numElementsArray[2];
1350         int size = 0;
1351         double* dataX = nullptr;
1352         double* dataY = nullptr;
1353         double* dataZ = nullptr;
1354         getHandleDoubleVector(dataset, "data_x", &numElementsArray[0], &numElementsArray[1], &dataX);
1355         size = numElementsArray[0] * numElementsArray[1];
1356         getHandleDoubleVector(dataset, "data_y", &numElementsArray[0], &numElementsArray[1], &dataY);
1357 
1358         if (numElementsArray[0] * numElementsArray[1] != size)
1359         {
1360             std::cout << "size trouble !!!" << std::endl;
1361         }
1362 
1363         setGraphicObjectPropertyAndNoWarn(polyline, __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__, numElementsArray, jni_int_vector, 2);
1364         setGraphicObjectPropertyAndNoWarn(polyline, __GO_DATA_MODEL_X__, dataX, jni_double_vector, size);
1365         setGraphicObjectPropertyAndNoWarn(polyline, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, size);
1366 
1367         //data z
1368         int zSet = 0;
1369         numElementsArray[0] = 0;
1370         numElementsArray[1] = 0;
1371         getHandleDoubleVector(dataset, "data_z", &numElementsArray[0], &numElementsArray[1], &dataZ);
1372         if (numElementsArray[0] * numElementsArray[1] != 0)
1373         {
1374             setGraphicObjectPropertyAndNoWarn(polyline, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, size);
1375             zSet = 1;
1376         }
1377 
1378         setGraphicObjectProperty(polyline, __GO_DATA_MODEL_Z_COORDINATES_SET__, &zSet, jni_int, 1);
1379 
1380         //update parent axes data_bounds
1381         if (mustUpdate())
1382         {
1383             double rect[6];
1384 
1385             MiniMaxi(dataX, size, rect, rect + 1);
1386             MiniMaxi(dataY, size, rect + 2, rect + 3);
1387 
1388             updateXYDataBounds(rect);
1389         }
1390 
1391         delete[] dataX;
1392         delete[] dataY;
1393         delete[] dataZ;
1394     }
1395 
1396     //datatips
1397     import_handle_datatips(dataset, polyline);
1398 
1399     closeList6(dataset);
1400     return polyline;
1401 }
1402 
import_handle_surface(hid_t dataset,int uid,int parent)1403 static int import_handle_surface(hid_t dataset, int uid, int parent)
1404 {
1405     //import "standards" properties
1406     import_handle_generic(dataset, uid, parent, SurfaceHandle::getPropertyList(), true);
1407     return uid;
1408 }
1409 
import_handle_plot3d(hid_t dataset,int parent)1410 static int import_handle_plot3d(hid_t dataset, int parent)
1411 {
1412     int plot = createGraphicObject(__GO_PLOT3D__);
1413     createDataObject(plot, __GO_PLOT3D__);
1414     import_handle_surface(dataset, plot, parent);
1415 
1416     //data
1417     int xR = 0, xC = 0;
1418     double* dataX = nullptr;
1419     int yR = 0, yC = 0;
1420     double* dataY = nullptr;
1421     int zR = 0, zC = 0;
1422     double* dataZ = nullptr;
1423 
1424     getHandleDoubleVector(dataset, "data_x", &xR, &xC, &dataX);
1425     getHandleDoubleVector(dataset, "data_y", &yR, &yC, &dataY);
1426     getHandleDoubleVector(dataset, "data_z", &zR, &zC, &dataZ);
1427 
1428     int gridSize[4];
1429     int result;
1430 
1431     gridSize[0] = xR;
1432     gridSize[1] = xC;
1433     gridSize[2] = yR;
1434     gridSize[3] = yC;
1435 
1436     result = setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_GRID_SIZE__, gridSize, jni_int_vector, 4);
1437 
1438     setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_X__, dataX, jni_double_vector, xR * xC);
1439     setGraphicObjectPropertyAndNoWarn(plot, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, yR * yC);
1440     setGraphicObjectProperty(plot, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, zR * zC);
1441 
1442     delete[] dataX;
1443     delete[] dataY;
1444     delete[] dataZ;
1445 
1446 
1447     closeList6(dataset);
1448     return plot;
1449 }
1450 
import_handle_fac3d(hid_t dataset,int parent)1451 static int import_handle_fac3d(hid_t dataset, int parent)
1452 {
1453     int fac = createGraphicObject(__GO_FAC3D__);
1454     createDataObject(fac, __GO_FAC3D__);
1455 
1456     import_handle_surface(dataset, fac, parent);
1457 
1458     //data
1459     int xR = 0, xC = 0;
1460     double* dataX = nullptr;
1461     int yR = 0, yC = 0;
1462     double* dataY = nullptr;
1463     int zR = 0, zC = 0;
1464     double* dataZ = nullptr;
1465 
1466     getHandleDoubleVector(dataset, "data_x", &xR, &xC, &dataX);
1467     getHandleDoubleVector(dataset, "data_y", &yR, &yC, &dataY);
1468     getHandleDoubleVector(dataset, "data_z", &zR, &zC, &dataZ);
1469 
1470     int cR = 0;
1471     int cC = 0;
1472     double* colors = nullptr;
1473     getHandleDoubleVector(dataset, "colors", &cR, &cC, &colors);
1474     int cSize = cR * cC;
1475 
1476     int numElementsArray[3];
1477 
1478     numElementsArray[0] = xC;
1479     numElementsArray[1] = xR;
1480     numElementsArray[2] = cSize;
1481 
1482     setGraphicObjectPropertyAndNoWarn(fac, __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__, numElementsArray, jni_int_vector, 3);
1483 
1484     setGraphicObjectPropertyAndNoWarn(fac, __GO_DATA_MODEL_X__, dataX, jni_double_vector, xR * xC);
1485     setGraphicObjectPropertyAndNoWarn(fac, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, yR * yC);
1486     setGraphicObjectPropertyAndNoWarn(fac, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, zR * zC);
1487     setGraphicObjectProperty(fac, __GO_DATA_MODEL_COLORS__, colors, jni_double_vector, cSize);
1488 
1489     delete[] dataX;
1490     delete[] dataY;
1491     delete[] dataZ;
1492     delete[] colors;
1493 
1494 
1495     //cdata_mapping
1496     int cdata = 0;
1497     getHandleInt(dataset, "cdata_mapping", &cdata);
1498     setGraphicObjectProperty(fac, __GO_DATA_MAPPING__, &cdata, jni_int, 1);
1499 
1500 
1501     closeList6(dataset);
1502     return fac;
1503 }
1504 
1505 
import_handle_champ(hid_t dataset,int parent)1506 static int import_handle_champ(hid_t dataset, int parent)
1507 {
1508     //need to get properties and call a "creator" :x
1509 
1510     int champ = createGraphicObject(__GO_CHAMP__);
1511 
1512     //data
1513     int row = 0;
1514     int col = 0;
1515     int dims[2];
1516     int num = 0;
1517     double* baseX = nullptr;
1518     getHandleDoubleVector(dataset, "base_x", &row, &col, &baseX);
1519     dims[0] = col;
1520 
1521     double* baseY = nullptr;
1522     getHandleDoubleVector(dataset, "base_y", &row, &col, &baseY);
1523     dims[1] = col;
1524     num = dims[0] * dims[1];
1525 
1526     double* directionX = nullptr;
1527     getHandleDoubleVector(dataset, "direction_x", &row, &col, &directionX);
1528 
1529     double* directionY = nullptr;
1530     getHandleDoubleVector(dataset, "direction_y", &row, &col, &directionY);
1531 
1532     setGraphicObjectProperty(champ, __GO_NUMBER_ARROWS__, &num, jni_int, 1);
1533     setGraphicObjectProperty(champ, __GO_CHAMP_DIMENSIONS__, dims, jni_int_vector, 2);
1534     setGraphicObjectProperty(champ, __GO_BASE_X__, baseX, jni_double_vector, dims[0]);
1535     setGraphicObjectProperty(champ, __GO_BASE_Y__, baseY, jni_double_vector, dims[1]);
1536     setGraphicObjectProperty(champ, __GO_DIRECTION_X__, directionX, jni_double_vector, dims[0] * dims[1]);
1537     setGraphicObjectProperty(champ, __GO_DIRECTION_Y__, directionY, jni_double_vector, dims[0] * dims[1]);
1538 
1539     delete[] baseX;
1540     delete[] baseY;
1541     delete[] directionX;
1542     delete[] directionY;
1543 
1544     //import "standards" properties
1545     import_handle_generic(dataset, champ, parent, ChampHandle::getPropertyList(), true);
1546 
1547     closeList6(dataset);
1548     return champ;
1549 }
import_handle_label(hid_t dataset,int uid)1550 static int import_handle_label(hid_t dataset, int uid)
1551 {
1552     //import "standards" properties
1553     //do not create releationship between parent
1554     import_handle_generic(dataset, uid, -1, LabelHandle::getPropertyList(), true);
1555 
1556     //text
1557     std::vector<int> dims(2);
1558     char** data = nullptr;
1559     int node = getHandleStringVector(dataset, "text", &dims[0], &dims[1], &data);
1560 
1561     setGraphicObjectProperty(uid, __GO_TEXT_ARRAY_DIMENSIONS__, dims.data(), jni_int_vector, 2);
1562     setGraphicObjectProperty(uid, __GO_TEXT_STRINGS__, data, jni_string_vector, dims[0] * dims[1]);
1563     freeStringMatrix(node, data);
1564     delete[] data;
1565 
1566     closeList6(dataset);
1567     return uid;
1568 }
1569 
import_handle_axes(hid_t dataset,int parent)1570 static int import_handle_axes(hid_t dataset, int parent)
1571 {
1572     //how to manage call by %h_copy ?
1573 
1574     int axes = createSubWin(parent);
1575 
1576     //hide current axes
1577     int visible = 0;
1578     setGraphicObjectProperty(axes, __GO_VISIBLE__, &visible, jni_bool, 1);
1579 
1580     //import "standards" properties
1581     import_handle_generic(dataset, axes, parent, AxesHandle::getPropertyList(), true);
1582 
1583     //title
1584     int title = 0;
1585     int *ptitle = &title;
1586     hid_t nodeTitle = getDataSetIdFromName(dataset, "title");
1587     getGraphicObjectProperty(axes, __GO_TITLE__, jni_int, (void **)&ptitle);
1588     import_handle_label(nodeTitle, title);
1589 
1590     //x_label
1591     int x_label = 0;
1592     int *px_label = &x_label;
1593     hid_t nodeX = getDataSetIdFromName(dataset, "x_label");
1594     getGraphicObjectProperty(axes, __GO_X_AXIS_LABEL__, jni_int, (void **)&px_label);
1595     import_handle_label(nodeX, x_label);
1596 
1597     //y_label
1598     int y_label = 0;
1599     int *py_label = &y_label;
1600     hid_t nodeY = getDataSetIdFromName(dataset, "y_label");
1601     getGraphicObjectProperty(axes, __GO_Y_AXIS_LABEL__, jni_int, (void **)&py_label);
1602     import_handle_label(nodeY, y_label);
1603 
1604     //z_label
1605     int z_label = 0;
1606     int *pz_label = &z_label;
1607     hid_t nodeZ = getDataSetIdFromName(dataset, "z_label");
1608     getGraphicObjectProperty(axes, __GO_Z_AXIS_LABEL__, jni_int, (void **)&pz_label);
1609     import_handle_label(nodeZ, z_label);
1610 
1611     //set real visible state
1612     getHandleInt(dataset, "visible", &visible);
1613     setGraphicObjectProperty(axes, __GO_VISIBLE__, &visible, jni_bool, 1);
1614 
1615     closeList6(dataset);
1616     return axes;
1617 }
1618 
import_handle_layout_options(hid_t dataset,int frame)1619 static int import_handle_layout_options(hid_t dataset, int frame)
1620 {
1621     int layout_type = 0;
1622     getHandleInt(dataset, "layout", &layout_type);
1623     int row = 0;
1624     int col = 0;
1625     int* data = nullptr;
1626 
1627     switch (layout_type)
1628     {
1629         case 2: //grid
1630         {
1631             hid_t node = getDataSetIdFromName(dataset, "layout_options");
1632             getHandleIntVector(node, "grid", &row, &col, &data);
1633             if (data && row * col == 2)
1634             {
1635                 setGraphicObjectProperty(frame, __GO_GRID_OPT_GRID__, data, jni_int_vector, 2);
1636             }
1637 
1638             delete[] data;
1639             data = nullptr;
1640 
1641             getHandleIntVector(node, "padding", &row, &col, &data);
1642             if (data && row * col == 2)
1643             {
1644                 setGraphicObjectProperty(frame, __GO_GRID_OPT_PADDING__, data, jni_int_vector, 2);
1645             }
1646 
1647             delete[] data;
1648             data = nullptr;
1649 
1650             closeList6(node);
1651             break;
1652         }
1653         case 3: //border
1654         {
1655             hid_t node = getDataSetIdFromName(dataset, "layout_options");
1656             getHandleIntVector(node, "padding", &row, &col, &data);
1657             if (data && row * col == 2)
1658             {
1659                 setGraphicObjectProperty(frame, __GO_BORDER_OPT_PADDING__, data, jni_int_vector, 2);
1660             }
1661 
1662             delete[] data;
1663             data = nullptr;
1664 
1665             closeList6(node);
1666             break;
1667         }
1668     }
1669 
1670     return frame;
1671 }
1672 
import_handle_figure(hid_t dataset,int parent)1673 static int import_handle_figure(hid_t dataset, int parent)
1674 {
1675     //some properties must be set @ creation time
1676     int menubar = 0;
1677     getHandleInt(dataset, "menubar", &menubar);
1678     int toolbar = 0;
1679     getHandleInt(dataset, "toolbar", &toolbar);
1680     int dockable = 0;
1681     getHandleBool(dataset, "dockable", &dockable);
1682     int default_axes = 0;
1683     getHandleBool(dataset, "default_axes", &default_axes);
1684 
1685     //force visible true FOR DEBUG ONLY
1686     int visible = 0;
1687 
1688     //create a new hidden figure without default_axes.
1689     int fig = createFigure(dockable, menubar, toolbar, 0, visible);
1690     //set default axes properties after creation to avoid useless axes creation
1691     setGraphicObjectProperty(fig, __GO_DEFAULT_AXES__, &default_axes, jni_bool, 1);
1692 
1693     int id = getValidDefaultFigureId();
1694     setGraphicObjectProperty(fig, __GO_ID__, &id, jni_int, 1);
1695 
1696     int menu = 0;
1697     getHandleBool(dataset, "menubar_visible", &menu);
1698     int notmenu = !menu;
1699     int info = 0;
1700     getHandleBool(dataset, "infobar_visible", &info);
1701     int notinfo = !info;
1702     int tool = 0;
1703     getHandleBool(dataset, "toolbar_visible", &tool);
1704     int nottool = !tool;
1705 
1706     //force inverse flag
1707     setGraphicObjectProperty(fig, __GO_MENUBAR_VISIBLE__, &notmenu, jni_bool, 1);
1708     setGraphicObjectProperty(fig, __GO_INFOBAR_VISIBLE__, &notinfo, jni_bool, 1);
1709     setGraphicObjectProperty(fig, __GO_TOOLBAR_VISIBLE__, &nottool, jni_bool, 1);
1710 
1711     //set real value
1712     setGraphicObjectProperty(fig, __GO_MENUBAR_VISIBLE__, &menu, jni_bool, 1);
1713     setGraphicObjectProperty(fig, __GO_INFOBAR_VISIBLE__, &info, jni_bool, 1);
1714     setGraphicObjectProperty(fig, __GO_TOOLBAR_VISIBLE__, &tool, jni_bool, 1);
1715 
1716     //import "standards" properties
1717     import_handle_generic(dataset, fig, -1, FigureHandle::getPropertyList(), true);
1718 
1719     import_handle_layout_options(dataset, fig);
1720     closeList6(dataset);
1721     return fig;
1722 }
1723 
import_handle(hid_t dataset,int parent)1724 int import_handle(hid_t dataset, int parent)
1725 {
1726     //get type
1727     int type = 0;
1728     getHandleInt(dataset, "type", &type);
1729     switch (type)
1730     {
1731         case __GO_FIGURE__:
1732         {
1733             return import_handle_figure(dataset, parent);
1734         }
1735         case __GO_AXES__:
1736         {
1737             return import_handle_axes(dataset, parent);
1738         }
1739         case __GO_CHAMP__:
1740         {
1741             return import_handle_champ(dataset, parent);
1742         }
1743         case __GO_FAC3D__:
1744         {
1745             return import_handle_fac3d(dataset, parent);
1746         }
1747         case __GO_PLOT3D__:
1748         {
1749             return import_handle_plot3d(dataset, parent);
1750         }
1751         case __GO_COMPOUND__:
1752         {
1753             return import_handle_compound(dataset, parent);
1754         }
1755         case __GO_POLYLINE__:
1756         {
1757             return import_handle_polyline(dataset, parent);
1758         }
1759         case __GO_RECTANGLE__:
1760         {
1761             return import_handle_rectangle(dataset, parent);
1762         }
1763         case __GO_ARC__:
1764         {
1765             return import_handle_arc(dataset, parent);
1766         }
1767         case __GO_SEGS__:
1768         {
1769             return import_handle_segs(dataset, parent);
1770         }
1771         case __GO_GRAYPLOT__:
1772         {
1773             return import_handle_grayplot(dataset, parent);
1774         }
1775         case __GO_MATPLOT__:
1776         {
1777             return import_handle_matplot(dataset, parent);
1778         }
1779         case __GO_FEC__:
1780         {
1781             return import_handle_fec(dataset, parent);
1782         }
1783         case __GO_LEGEND__:
1784         {
1785             return import_handle_legend(dataset, parent);
1786         }
1787         case __GO_TEXT__:
1788         {
1789             return import_handle_text(dataset, parent);
1790         }
1791         case __GO_AXIS__:
1792         {
1793             return import_handle_axis(dataset, parent);
1794         }
1795         case __GO_LIGHT__:
1796         {
1797             return import_handle_light(dataset, parent);
1798         }
1799         case __GO_UIMENU__:
1800         {
1801             return import_handle_uimenu(dataset, parent);
1802         }
1803         case __GO_UICONTEXTMENU__:
1804         {
1805             return import_handle_uicontextmenu(dataset, parent);
1806         }
1807         case __GO_UICONTROL__:
1808         {
1809             return import_handle_uicontrol(dataset, parent);
1810         }
1811     }
1812     return -1;
1813 }
1814 
update_link_path(int legend,Links::PathList & paths)1815 void update_link_path(int legend, Links::PathList& paths)
1816 {
1817     //find legend parent axes ( origin of path items )
1818     int type = 0;
1819     int* ptype = &type;
1820     int axes = legend; //start point
1821     int* paxes = &axes;
1822     getGraphicObjectProperty(legend, __GO_PARENT_AXES__, jni_int, (void**)&paxes);
1823     std::vector<int> links;
1824     //loop on child following path index
1825     for (auto & path : paths)
1826     {
1827         int current = axes;
1828         for (int j = 0; j < path.size(); ++j)
1829         {
1830             int index = path[path.size() - 1 - j];
1831             int count = 0;
1832             int* pcount = &count;
1833             getGraphicObjectProperty(current, __GO_CHILDREN_COUNT__, jni_int, (void**)&pcount);
1834             if (count == 0 || index >= count)
1835             {
1836                 getGraphicObjectProperty(current, __GO_TYPE__, jni_int, (void**)&ptype);
1837                 break;
1838             }
1839 
1840             int* children = nullptr;
1841             getGraphicObjectProperty(current, __GO_CHILDREN__, jni_int_vector, (void**)&children);
1842 
1843             current = children[index];
1844 
1845             releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, count);
1846         }
1847 
1848         links.push_back(current);
1849     }
1850 
1851     setGraphicObjectProperty(legend, __GO_LINKS__, links.data(), jni_int_vector, static_cast<int>(links.size()));
1852 }
1853 
getHandleBoolProperty(int uid,int prop,int * data)1854 static bool getHandleBoolProperty(int uid, int prop, int* data)
1855 {
1856     int val = 0;
1857     int* pVal = &val;
1858     getGraphicObjectProperty(uid, prop, jni_bool, (void **)&pVal);
1859     if (pVal == nullptr)
1860     {
1861         return false;
1862     }
1863 
1864     *data = val;
1865     return true;
1866 }
1867 
getHandleIntProperty(int uid,int prop,int * data)1868 static bool getHandleIntProperty(int uid, int prop, int* data)
1869 {
1870     int val = 0;
1871     int* pVal = &val;
1872     getGraphicObjectProperty(uid, prop, jni_int, (void **)&pVal);
1873     if (pVal == nullptr)
1874     {
1875         return false;
1876     }
1877 
1878     *data = val;
1879     return true;
1880 }
1881 
getHandleDoubleProperty(int uid,int prop,double * data)1882 static bool getHandleDoubleProperty(int uid, int prop, double* data)
1883 {
1884     double val = 0;
1885     double* pVal = &val;
1886     getGraphicObjectProperty(uid, prop, jni_double, (void **)&pVal);
1887     if (pVal == nullptr)
1888     {
1889         return false;
1890     }
1891 
1892     *data = val;
1893     return true;
1894 }
1895 
getHandleStringProperty(int uid,int prop,char ** str)1896 static void getHandleStringProperty(int uid, int prop, char** str)
1897 {
1898     getGraphicObjectProperty(uid, prop, jni_string, (void **)str);
1899 }
1900 
1901 
getHandleBoolVectorProperty(int uid,int prop,int ** vals)1902 static void getHandleBoolVectorProperty(int uid, int prop, int** vals)
1903 {
1904     getGraphicObjectProperty(uid, prop, jni_bool_vector, (void **)vals);
1905 }
1906 
getHandleIntVectorProperty(int uid,int prop,int ** vals)1907 static void getHandleIntVectorProperty(int uid, int prop, int** vals)
1908 {
1909     getGraphicObjectProperty(uid, prop, jni_int_vector, (void **)vals);
1910 }
1911 
getHandleDoubleVectorProperty(int uid,int prop,double ** vals)1912 static void getHandleDoubleVectorProperty(int uid, int prop, double** vals)
1913 {
1914     getGraphicObjectProperty(uid, prop, jni_double_vector, (void **)vals);
1915 }
1916 
getHandleStringVectorProperty(int uid,int prop,char *** vals)1917 static void getHandleStringVectorProperty(int uid, int prop, char*** vals)
1918 {
1919     getGraphicObjectProperty(uid, prop, jni_string_vector, (void **)vals);
1920 }
1921 
1922 static bool export_handle_generic(hid_t parent, int uid, const HandleProp& props, hid_t xfer_plist_id);
1923 static bool export_handle_layout_options(hid_t parent, int uid, hid_t xfer_plist_id);
1924 static bool export_handle_userdata(hid_t parent, int uid, hid_t xfer_plist_id);
1925 static bool export_handle_tag(hid_t parent, int uid, hid_t xfer_plist_id);
1926 static bool export_handle_figure(hid_t parent, int uid, hid_t xfer_plist_id);
1927 static bool export_handle_axes(hid_t parent, int uid, hid_t xfer_plist_id);
1928 static bool export_handle_label(hid_t parent, int uid, hid_t xfer_plist_id);
1929 static bool export_handle_champ(hid_t parent, int uid, hid_t xfer_plist_id);
1930 static bool export_handle_children(hid_t parent, int uid, hid_t xfer_plist_id);
1931 
export_handle_generic(hid_t parent,int uid,const HandleProp & props,hid_t xfer_plist_id)1932 static bool export_handle_generic(hid_t parent, int uid, const HandleProp& props, hid_t xfer_plist_id)
1933 {
1934     for (auto & prop : props)
1935     {
1936         const char* name = prop.first.data();
1937         std::vector<int> info(prop.second);
1938 
1939         //scalar variable
1940         if (info.size() == 3)
1941         {
1942             int go = info[1];
1943             int type = info[2];
1944 
1945             switch (type)
1946             {
1947                 case jni_bool:
1948                 {
1949                     std::vector<int> dims = {1, 1};
1950                     int val = 0;
1951                     getHandleBoolProperty(uid, go, &val);
1952                     writeBooleanMatrix6(parent, name, static_cast<int>(dims.size()), dims.data(), &val, xfer_plist_id);
1953                     break;
1954                 }
1955                 case jni_double:
1956                 {
1957                     std::vector<int> dims = {1, 1};
1958                     double val = 0;
1959                     getHandleDoubleProperty(uid, go, &val);
1960                     writeDoubleMatrix6(parent, name, static_cast<int>(dims.size()), dims.data(), &val, xfer_plist_id);
1961                     break;
1962                 }
1963                 case jni_int:
1964                 {
1965                     std::vector<int> dims = {1, 1};
1966                     int val = 0;
1967                     getHandleIntProperty(uid, go, &val);
1968                     writeIntegerMatrix6(parent, name, H5T_NATIVE_INT32, "32", static_cast<int>(dims.size()), dims.data(), &val, xfer_plist_id);
1969                     break;
1970                 }
1971                 case jni_string:
1972                 {
1973                     std::vector<int> dims = {1, 1};
1974                     char* val;
1975                     getHandleStringProperty(uid, go, &val);
1976                     writeStringMatrix6(parent, name, static_cast<int>(dims.size()), dims.data(), &val, xfer_plist_id);
1977                     releaseGraphicObjectProperty(go, val, jni_string, 1);
1978                     break;
1979                 }
1980             }
1981         }
1982         else //vector variable
1983         {
1984             int go = info[1];
1985             int type = info[2];
1986             int row = info[3];
1987             int col = info.size() > 3 ? info[4] : -1;
1988 
1989             if (row < 0)
1990             {
1991                 row = -row;
1992             }
1993             else
1994             {
1995                 getHandleIntProperty(uid, row, &row);
1996             }
1997 
1998             if (col < 0)
1999             {
2000                 col = -col;
2001             }
2002             else
2003             {
2004                 getHandleIntProperty(uid, col, &col);
2005             }
2006 
2007             switch (type)
2008             {
2009                 case jni_bool_vector:
2010                 {
2011                     std::vector<int> dims = {row, col};
2012                     int* vals;
2013                     getHandleBoolVectorProperty(uid, go, &vals);
2014                     writeBooleanMatrix6(parent, name, static_cast<int>(dims.size()), dims.data(), vals, xfer_plist_id);
2015                     releaseGraphicObjectProperty(go, vals, jni_bool_vector, row * col);
2016                     break;
2017                 }
2018                 case jni_double_vector:
2019                 {
2020                     std::vector<int> dims = {row, col};
2021                     double* vals;
2022                     getHandleDoubleVectorProperty(uid, go, &vals);
2023                     writeDoubleMatrix6(parent, name, static_cast<int>(dims.size()), dims.data(), vals, xfer_plist_id);
2024                     releaseGraphicObjectProperty(go, vals, jni_double_vector, row * col);
2025                     break;
2026                 }
2027                 case jni_int_vector:
2028                 {
2029                     std::vector<int> dims = {row, col};
2030                     int* vals;
2031                     getHandleIntVectorProperty(uid, go, &vals);
2032                     writeIntegerMatrix6(parent, name, H5T_NATIVE_INT32, "32", static_cast<int>(dims.size()), dims.data(), vals, xfer_plist_id);
2033                     releaseGraphicObjectProperty(go, vals, jni_int_vector, row * col);
2034                     break;
2035                 }
2036                 case jni_string_vector:
2037                 {
2038                     std::vector<int> dims = {row, col};
2039                     char** vals;
2040                     getHandleStringVectorProperty(uid, go, &vals);
2041                     writeStringMatrix6(parent, name, static_cast<int>(dims.size()), dims.data(), vals, xfer_plist_id);
2042                     releaseGraphicObjectProperty(go, vals, jni_string_vector, row * col);
2043                     break;
2044                 }
2045                 default:
2046                 {
2047                     break;
2048                 }
2049             }
2050         }
2051     }
2052 
2053     //user_data
2054     export_handle_userdata(parent, uid, xfer_plist_id);
2055     //tag
2056     export_handle_tag(parent, uid, xfer_plist_id);
2057     //children
2058     export_handle_children(parent, uid, xfer_plist_id);
2059     return true;
2060 }
2061 
export_handle_layout_options(hid_t parent,int uid,hid_t xfer_plist_id)2062 static bool export_handle_layout_options(hid_t parent, int uid, hid_t xfer_plist_id)
2063 {
2064     int layout_type = 0;
2065     getHandleIntProperty(uid, __GO_LAYOUT__, &layout_type);
2066     if (layout_type == 0 || layout_type == 1) //LAYOUT_NONE or LAYOUT_GRIDBAG
2067     {
2068         //nothing to save
2069         return true;
2070     }
2071 
2072     hid_t layout = openList6(parent, "layout_options", g_SCILAB_CLASS_HANDLE);
2073 
2074     switch (layout_type)
2075     {
2076         case 2: //grid
2077         {
2078             std::vector<int> dims = {1, 2};
2079             int* grid = nullptr;
2080             getHandleIntVectorProperty(uid, __GO_GRID_OPT_GRID__, &grid);
2081             writeIntegerMatrix6(layout, "grid", H5T_NATIVE_INT32, "32", 2, dims.data(), grid, xfer_plist_id);
2082             releaseGraphicObjectProperty(__GO_GRID_OPT_GRID__, grid, jni_int_vector, 2);
2083 
2084             int* pad = nullptr;
2085             getHandleIntVectorProperty(uid, __GO_GRID_OPT_PADDING__, &pad);
2086             writeIntegerMatrix6(layout, "padding", H5T_NATIVE_INT32, "32", 2, dims.data(), pad, xfer_plist_id);
2087             releaseGraphicObjectProperty(__GO_GRID_OPT_PADDING__, pad, jni_int_vector, 2);
2088             break;
2089         }
2090         case 3: //border
2091         {
2092             std::vector<int> dims = {1, 2};
2093             int* pad = nullptr;
2094             getHandleIntVectorProperty(uid, __GO_BORDER_OPT_PADDING__, &pad);
2095             writeIntegerMatrix6(layout, "padding", H5T_NATIVE_INT32, "32", 2, dims.data(), pad, xfer_plist_id);
2096             releaseGraphicObjectProperty(__GO_BORDER_OPT_PADDING__, pad, jni_int_vector, 2);
2097             break;
2098         }
2099     }
2100 
2101     closeList6(layout);
2102 
2103     return true;
2104 }
export_handle_tag(hid_t parent,int uid,hid_t xfer_plist_id)2105 static bool export_handle_tag(hid_t parent, int uid, hid_t xfer_plist_id)
2106 {
2107     char* tag = nullptr;
2108     getHandleStringProperty(uid, __GO_TAG__, &tag);
2109     int dims[2];
2110     dims[0] = 1;
2111     dims[1] = 1;
2112     writeStringMatrix6(parent, "tag", 2, dims, &tag, xfer_plist_id);
2113     releaseGraphicObjectProperty(__GO_TAG__, tag, jni_string, 1);
2114     return true;
2115 }
2116 
export_handle_userdata(hid_t parent,int uid,hid_t xfer_plist_id)2117 static bool export_handle_userdata(hid_t parent, int uid, hid_t xfer_plist_id)
2118 {
2119 
2120     int size = 0;
2121     getHandleIntProperty(uid, __GO_USER_DATA_SIZE__, &size);
2122 
2123     if (size == 0)
2124     {
2125         std::vector<int> dims = {0, 0};
2126         writeDoubleMatrix6(parent, "userdata", 2, dims.data(), NULL, xfer_plist_id);
2127     }
2128     else
2129     {
2130         int *data = NULL;
2131         getHandleIntVectorProperty(uid, __GO_USER_DATA__, &data);
2132 
2133         types::InternalType* pUD = nullptr;
2134         if (size == 1)
2135         {
2136             //32 bits
2137             int* p = (int*)data;
2138             pUD = ((types::InternalType*) * p);
2139         }
2140         else
2141         {
2142             //64 bits
2143             long long* p = (long long*)data;
2144             pUD = ((types::InternalType*) * p);
2145         }
2146 
2147         export_data(parent, "userdata", pUD, xfer_plist_id);
2148         //do not release, data is a reference on data in model
2149         //releaseGraphicObjectProperty(__GO_USER_DATA__, data, jni_int_vector, size);
2150     }
2151 
2152     return true;
2153 }
2154 
export_handle_datatips(hid_t parent,int uid,hid_t xfer_plist_id)2155 static bool export_handle_datatips(hid_t parent, int uid, hid_t xfer_plist_id)
2156 {
2157     int count = 0;
2158     getHandleIntProperty(uid, __GO_DATATIPS_COUNT__, &count);
2159     hid_t node = openList6(parent, "datatips", g_SCILAB_CLASS_HANDLE);
2160     int* datatips = nullptr;
2161 
2162     if (count != 0)
2163     {
2164         getHandleIntVectorProperty(uid, __GO_DATATIPS__, &datatips);
2165     }
2166 
2167     for (int i = 0; i < count; ++i)
2168     {
2169         if (export_handle(node, std::to_string(i), datatips[i], xfer_plist_id) == false)
2170         {
2171             releaseGraphicObjectProperty(__GO_DATATIPS__, datatips, jni_int_vector, count);
2172             closeList6(node);
2173             return false;
2174         }
2175     }
2176 
2177     releaseGraphicObjectProperty(__GO_DATATIPS__, datatips, jni_int_vector, count);
2178     closeList6(node);
2179     return true;
2180 }
2181 
2182 static bool export_handle_border(hid_t dataset, int uid, hid_t xfer_plist_id);
2183 
export_handle_border_none(hid_t dataset,int uid,hid_t xfer_plist_id)2184 static bool export_handle_border_none(hid_t dataset, int uid, hid_t xfer_plist_id)
2185 {
2186     //nothing to do
2187     closeList6(dataset);
2188     return true;
2189 }
2190 
export_handle_border_line(hid_t dataset,int uid,hid_t xfer_plist_id)2191 static bool export_handle_border_line(hid_t dataset, int uid, hid_t xfer_plist_id)
2192 {
2193     bool ret = false;
2194     int dims[2];
2195     dims[0] = 1;
2196     dims[1] = 1;
2197 
2198     //color
2199     char* color = nullptr;
2200     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_COLOR__, &color);
2201     writeStringMatrix6(dataset, "color", 2, dims, &color, xfer_plist_id);
2202     releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_COLOR__, color, jni_string, 1);
2203 
2204     //thickness
2205     int thickness = 0;
2206     ret = getHandleIntProperty(uid, __GO_LINE_THICKNESS__, &thickness);
2207     if (ret)
2208     {
2209         writeIntegerMatrix6(dataset, "thickness", H5T_NATIVE_INT32, "32", 2, dims, &thickness, xfer_plist_id);
2210     }
2211 
2212     //rounded
2213     int rounded = 0;
2214     ret = getHandleBoolProperty(uid, __GO_UI_FRAME_BORDER_ROUNDED__, &rounded);
2215     if (ret)
2216     {
2217         writeBooleanMatrix6(dataset, "rounded", 2, dims, &rounded, xfer_plist_id);
2218     }
2219 
2220     closeList6(dataset);
2221     return true;
2222 }
2223 
export_handle_border_bevel(hid_t dataset,int uid,hid_t xfer_plist_id)2224 static bool export_handle_border_bevel(hid_t dataset, int uid, hid_t xfer_plist_id)
2225 {
2226     bool ret = false;
2227     int dims[2];
2228     dims[0] = 1;
2229     dims[1] = 1;
2230     char* data = nullptr;
2231 
2232     //type
2233     int type = 0;
2234     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_TYPE__, &type);
2235     if (ret)
2236     {
2237         writeIntegerMatrix6(dataset, "type", H5T_NATIVE_INT32, "32", 2, dims, &type, xfer_plist_id);
2238     }
2239 
2240     //highlight out
2241     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, &data);
2242     if (data)
2243     {
2244         writeStringMatrix6(dataset, "highlight_out", 2, dims, &data, xfer_plist_id);
2245         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, data, jni_string, 1);
2246     }
2247 
2248     //highlight in
2249     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, &data);
2250     if (data)
2251     {
2252         writeStringMatrix6(dataset, "highlight_in", 2, dims, &data, xfer_plist_id);
2253         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, data, jni_string, 1);
2254     }
2255 
2256     //shadow out
2257     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_SHADOW_OUT__, &data);
2258     if (data)
2259     {
2260         writeStringMatrix6(dataset, "shadow_out", 2, dims, &data, xfer_plist_id);
2261         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_SHADOW_OUT__, data, jni_string, 1);
2262     }
2263 
2264     //shadow in
2265     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_SHADOW_IN__, &data);
2266     if (data)
2267     {
2268         writeStringMatrix6(dataset, "shadow_in", 2, dims, &data, xfer_plist_id);
2269         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_SHADOW_IN__, data, jni_string, 1);
2270     }
2271     closeList6(dataset);
2272     return true;
2273 }
2274 
export_handle_border_soft_bevel(hid_t dataset,int uid,hid_t xfer_plist_id)2275 static bool export_handle_border_soft_bevel(hid_t dataset, int uid, hid_t xfer_plist_id)
2276 {
2277     return export_handle_border_bevel(dataset, uid, xfer_plist_id);
2278 }
2279 
export_handle_border_etched(hid_t dataset,int uid,hid_t xfer_plist_id)2280 static bool export_handle_border_etched(hid_t dataset, int uid, hid_t xfer_plist_id)
2281 {
2282     bool ret = false;
2283     int dims[2];
2284     dims[0] = 1;
2285     dims[1] = 1;
2286     char* data = nullptr;
2287 
2288     //type
2289     int type = 0;
2290     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_TYPE__, &type);
2291     if (ret)
2292     {
2293         writeIntegerMatrix6(dataset, "type", H5T_NATIVE_INT32, "32", 2, dims, &type, xfer_plist_id);
2294     }
2295 
2296     //highlight out
2297     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, &data);
2298     if (data)
2299     {
2300         writeStringMatrix6(dataset, "highlight_out", 2, dims, &data, xfer_plist_id);
2301         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, data, jni_string, 1);
2302     }
2303 
2304     //shadow out
2305     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_SHADOW_OUT__, &data);
2306     if (data)
2307     {
2308         writeStringMatrix6(dataset, "shadow_out", 2, dims, &data, xfer_plist_id);
2309         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_SHADOW_OUT__, data, jni_string, 1);
2310     }
2311 
2312     closeList6(dataset);
2313     return true;
2314 }
2315 
export_handle_border_titled(hid_t dataset,int uid,hid_t xfer_plist_id)2316 static bool export_handle_border_titled(hid_t dataset, int uid, hid_t xfer_plist_id)
2317 {
2318     bool ret = false;
2319     int dims[2];
2320     dims[0] = 1;
2321     dims[1] = 1;
2322     char* data = nullptr;
2323 
2324     //title_border
2325     int title = 0;
2326     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_TITLE__, &title);
2327     if (ret)
2328     {
2329         hid_t node = openList6(dataset, "title_border", g_SCILAB_CLASS_HANDLE);
2330         export_handle_border(node, title, xfer_plist_id);
2331     }
2332 
2333     //title
2334     getHandleStringProperty(uid, __GO_TITLE__, &data);
2335     if (data)
2336     {
2337         writeStringMatrix6(dataset, "title", 2, dims, &data, xfer_plist_id);
2338         releaseGraphicObjectProperty(__GO_TITLE__, data, jni_string, 1);
2339     }
2340 
2341     //justification
2342     int justification = 0;
2343     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_JUSTIFICATION__, &justification);
2344     if (ret)
2345     {
2346         writeIntegerMatrix6(dataset, "justification", H5T_NATIVE_INT32, "32", 2, dims, &justification, xfer_plist_id);
2347     }
2348 
2349     //fontname
2350     getHandleStringProperty(uid, __GO_UI_FONTNAME__, &data);
2351     if (data)
2352     {
2353         writeStringMatrix6(dataset, "fontname", 2, dims, &data, xfer_plist_id);
2354         releaseGraphicObjectProperty(__GO_UI_FONTNAME__, data, jni_string, 1);
2355         data = nullptr;
2356     }
2357 
2358     //fontangle
2359     getHandleStringProperty(uid, __GO_UI_FONTANGLE__, &data);
2360     if (data)
2361     {
2362         writeStringMatrix6(dataset, "fontangle", 2, dims, &data, xfer_plist_id);
2363         releaseGraphicObjectProperty(__GO_UI_FONTANGLE__, data, jni_string, 1);
2364         data = nullptr;
2365     }
2366 
2367     //fontsize
2368     int fonsize = 0;
2369     ret = getHandleIntProperty(uid, __GO_UI_FONTSIZE__, &fonsize);
2370     if (ret)
2371     {
2372         writeIntegerMatrix6(dataset, "fontsize", H5T_NATIVE_INT32, "32", 2, dims, &fonsize, xfer_plist_id);
2373     }
2374 
2375     //fontweight
2376     getHandleStringProperty(uid, __GO_UI_FONTWEIGHT__, &data);
2377     if (data)
2378     {
2379         writeStringMatrix6(dataset, "fontweight", 2, dims, &data, xfer_plist_id);
2380         releaseGraphicObjectProperty(__GO_UI_FONTWEIGHT__, data, jni_string, 1);
2381         data = nullptr;
2382     }
2383 
2384     //position
2385     int position = 0;
2386     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_POSITION__, &position);
2387     if (ret)
2388     {
2389         writeIntegerMatrix6(dataset, "position", H5T_NATIVE_INT32, "32", 2, dims, &position, xfer_plist_id);
2390     }
2391 
2392     //color
2393     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_COLOR__, &data);
2394     if (data)
2395     {
2396         writeStringMatrix6(dataset, "color", 2, dims, &data, xfer_plist_id);
2397         releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_COLOR__, data, jni_string, 1);
2398         data = nullptr;
2399     }
2400 
2401     closeList6(dataset);
2402     return true;
2403 }
2404 
export_handle_border_empty(hid_t dataset,int uid,hid_t xfer_plist_id)2405 static bool export_handle_border_empty(hid_t dataset, int uid, hid_t xfer_plist_id)
2406 {
2407     int dims[2];
2408     dims[0] = 1;
2409     dims[1] = 4;
2410     double* pos = nullptr;
2411 
2412     //position
2413     getHandleDoubleVectorProperty(uid, __GO_POSITION__, &pos);
2414     if (pos)
2415     {
2416         writeDoubleMatrix6(dataset, "position", 2, dims, pos, xfer_plist_id);
2417         releaseGraphicObjectProperty(__GO_POSITION__, pos, jni_double_vector, 4);
2418     }
2419 
2420     closeList6(dataset);
2421     return true;
2422 }
2423 
export_handle_border_compound(hid_t dataset,int uid,hid_t xfer_plist_id)2424 static bool export_handle_border_compound(hid_t dataset, int uid, hid_t xfer_plist_id)
2425 {
2426     bool ret = false;
2427     //out_border
2428     int out_border = 0;
2429 
2430     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_OUT_BORDER__, &out_border);
2431     if (ret)
2432     {
2433         hid_t node = openList6(dataset, "out_border", g_SCILAB_CLASS_HANDLE);
2434         export_handle_border(node, out_border, xfer_plist_id);
2435 
2436         //title_border
2437         int in_border = 0;
2438         getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_IN_BORDER__, &in_border);
2439         node = openList6(dataset, "in_border", g_SCILAB_CLASS_HANDLE);
2440         export_handle_border(node, in_border, xfer_plist_id);
2441     }
2442 
2443     closeList6(dataset);
2444     return true;
2445 }
2446 
export_handle_border_matte(hid_t dataset,int uid,hid_t xfer_plist_id)2447 static bool export_handle_border_matte(hid_t dataset, int uid, hid_t xfer_plist_id)
2448 {
2449     int dims[2];
2450     dims[0] = 1;
2451     dims[1] = 4;
2452     char* data = nullptr;
2453     double* pos = nullptr;
2454 
2455     //position
2456     dims[0] = 1;
2457     dims[1] = 4;
2458     getHandleDoubleVectorProperty(uid, __GO_POSITION__, &pos);
2459     writeDoubleMatrix6(dataset, "position", 2, dims, pos, xfer_plist_id);
2460     releaseGraphicObjectProperty(__GO_POSITION__, pos, jni_double_vector, 4);
2461 
2462     //color
2463     dims[0] = 1;
2464     dims[1] = 1;
2465     getHandleStringProperty(uid, __GO_UI_FRAME_BORDER_COLOR__, &data);
2466     writeStringMatrix6(dataset, "color", 2, dims, &data, xfer_plist_id);
2467     releaseGraphicObjectProperty(__GO_UI_FRAME_BORDER_COLOR__, data, jni_string, 1);
2468 
2469     closeList6(dataset);
2470     return true;
2471 }
2472 
export_handle_border(hid_t dataset,int uid,hid_t xfer_plist_id)2473 static bool export_handle_border(hid_t dataset, int uid, hid_t xfer_plist_id)
2474 {
2475     int style = 0;
2476     getHandleIntProperty(uid, __GO_UI_FRAME_BORDER_STYLE__, &style);
2477     int dims[2];
2478     dims[0] = 1;
2479     dims[1] = 1;
2480 
2481     writeIntegerMatrix6(dataset, "style", H5T_NATIVE_INT32, "32", 2, dims, &style, xfer_plist_id);
2482 
2483     switch (style)
2484     {
2485         default:
2486         case NONE:
2487             return export_handle_border_none(dataset, uid, xfer_plist_id);
2488         case LINE:
2489             return export_handle_border_line(dataset, uid, xfer_plist_id);
2490         case BEVEL:
2491             return export_handle_border_bevel(dataset, uid, xfer_plist_id);
2492         case SOFTBEVEL:
2493             return export_handle_border_soft_bevel(dataset, uid, xfer_plist_id);
2494         case ETCHED:
2495             return export_handle_border_etched(dataset, uid, xfer_plist_id);
2496         case TITLED:
2497             return export_handle_border_titled(dataset, uid, xfer_plist_id);
2498         case EMPTY:
2499             return export_handle_border_empty(dataset, uid, xfer_plist_id);
2500         case COMPOUND:
2501             return export_handle_border_compound(dataset, uid, xfer_plist_id);
2502         case MATTE:
2503             return export_handle_border_matte(dataset, uid, xfer_plist_id);
2504     }
2505 }
2506 
export_handle_uicontrol(hid_t parent,int uid,hid_t xfer_plist_id)2507 static bool export_handle_uicontrol(hid_t parent, int uid, hid_t xfer_plist_id)
2508 {
2509     bool ret = false;
2510     if (export_handle_generic(parent, uid, UicontrolHandle::getPropertyList(), xfer_plist_id) == false)
2511     {
2512         return false;
2513     }
2514 
2515     //string
2516     int size = 0;
2517     getHandleIntProperty(uid, __GO_UI_STRING_SIZE__, &size);
2518     int col = 0;
2519     getHandleIntProperty(uid, __GO_UI_STRING_COLNB__, &col);
2520 
2521     int dims[2];
2522 
2523     if (col == 0)
2524     {
2525         dims[0] = 1;
2526         dims[1] = 1;
2527         char null_char = '\0';
2528         char* empty = &null_char;
2529         writeStringMatrix6(parent, "string", 2, dims, &empty, xfer_plist_id);
2530 
2531     }
2532     else
2533     {
2534         int row = size / col;
2535         dims[0] = row;
2536         dims[1] = col;
2537         char** string = nullptr;
2538         getHandleStringVectorProperty(uid, __GO_UI_STRING__, &string);
2539         writeStringMatrix6(parent, "string", 2, dims, string, xfer_plist_id);
2540         releaseGraphicObjectProperty(__GO_UI_STRING__, string, jni_string_vector, size);
2541     }
2542 
2543     //border
2544     int border = 0;
2545     ret = getHandleIntProperty(uid, __GO_UI_FRAME_BORDER__, &border);
2546     if (ret)
2547     {
2548         hid_t ub = openList6(parent, "border", g_SCILAB_CLASS_HANDLE);
2549         export_handle_border(ub, border, xfer_plist_id);
2550     }
2551 
2552     closeList6(parent);
2553     return true;
2554 }
2555 
export_handle_uicontextmenu(hid_t parent,int uid,hid_t xfer_plist_id)2556 static bool export_handle_uicontextmenu(hid_t parent, int uid, hid_t xfer_plist_id)
2557 {
2558     if (export_handle_generic(parent, uid, UicontextmenuHandle::getPropertyList(), xfer_plist_id) == false)
2559     {
2560         return false;
2561     }
2562 
2563     closeList6(parent);
2564     return true;
2565 }
2566 
export_handle_uimenu(hid_t parent,int uid,hid_t xfer_plist_id)2567 static bool export_handle_uimenu(hid_t parent, int uid, hid_t xfer_plist_id)
2568 {
2569     if (export_handle_generic(parent, uid, UimenuHandle::getPropertyList(), xfer_plist_id) == false)
2570     {
2571         return false;
2572     }
2573 
2574     closeList6(parent);
2575     return true;
2576 }
2577 
export_handle_light(hid_t parent,int uid,hid_t xfer_plist_id)2578 static bool export_handle_light(hid_t parent, int uid, hid_t xfer_plist_id)
2579 {
2580     if (export_handle_generic(parent, uid, LightHandle::getPropertyList(), xfer_plist_id) == false)
2581     {
2582         return false;
2583     }
2584 
2585     closeList6(parent);
2586     return true;
2587 }
2588 
export_handle_axis(hid_t parent,int uid,hid_t xfer_plist_id)2589 static bool export_handle_axis(hid_t parent, int uid, hid_t xfer_plist_id)
2590 {
2591     if (export_handle_generic(parent, uid, AxisHandle::getPropertyList(), xfer_plist_id) == false)
2592     {
2593         return false;
2594     }
2595 
2596     closeList6(parent);
2597     return true;
2598 }
2599 
export_handle_text(hid_t parent,int uid,hid_t xfer_plist_id)2600 static bool export_handle_text(hid_t parent, int uid, hid_t xfer_plist_id)
2601 {
2602     if (export_handle_generic(parent, uid, TextHandle::getPropertyList(), xfer_plist_id) == false)
2603     {
2604         return false;
2605     }
2606 
2607     //text
2608     int* dims = nullptr;
2609     getHandleIntVectorProperty(uid, __GO_TEXT_ARRAY_DIMENSIONS__, &dims);
2610     char** text;
2611     getHandleStringVectorProperty(uid, __GO_TEXT_STRINGS__, &text);
2612     writeStringMatrix6(parent, "text", 2, dims, text, xfer_plist_id);
2613     closeList6(parent);
2614     return true;
2615 }
2616 
2617 //find parent axes of a entity and return path ( via children index )
get_entity_path(int entity,std::vector<int> & path)2618 bool get_entity_path(int entity, std::vector<int>& path)
2619 {
2620     path.clear();
2621 
2622     while (true)
2623     {
2624         int parent = 0;
2625         getHandleIntProperty(entity, __GO_PARENT__, &parent);
2626         int count = 0;
2627         getHandleIntProperty(parent, __GO_CHILDREN_COUNT__, &count);
2628         //get children of parent to find "my" index
2629         int* children = nullptr;
2630         getHandleIntVectorProperty(parent, __GO_CHILDREN__, &children);
2631         bool find = false;
2632         for (int i = 0; i < count; ++i)
2633         {
2634             if (children[i] == entity)
2635             {
2636                 path.push_back(i);
2637                 find = true;
2638                 break;
2639             }
2640         }
2641 
2642         releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, count);
2643         if (find == false)
2644         {
2645             return false;
2646         }
2647 
2648         int type = 0;
2649         getHandleIntProperty(parent, __GO_TYPE__, &type);
2650         if (type == __GO_AXES__)
2651         {
2652             break;
2653         }
2654 
2655         entity = parent;
2656     }
2657 
2658     return true;
2659 }
2660 
export_handle_legend(hid_t parent,int uid,hid_t xfer_plist_id)2661 static bool export_handle_legend(hid_t parent, int uid, hid_t xfer_plist_id)
2662 {
2663     if (export_handle_generic(parent, uid, LegendHandle::getPropertyList(), xfer_plist_id) == false)
2664     {
2665         return false;
2666     }
2667 
2668     //links
2669     hid_t node = openList6(parent, "links", g_SCILAB_CLASS_HANDLE);
2670     int link = 0;
2671     getHandleIntProperty(uid, __GO_LINKS_COUNT__, &link);
2672     int* links = nullptr;
2673     getHandleIntVectorProperty(uid, __GO_LINKS__, &links);
2674     for (int i = 0; i < link; ++i)
2675     {
2676         std::vector<int> path;
2677         if (get_entity_path(links[i], path))
2678         {
2679             int dims[2];
2680             dims[0] = 1;
2681             dims[1] = static_cast<int>(path.size());
2682             writeIntegerMatrix6(node, std::to_string(i).data(), H5T_NATIVE_INT32, "32", 2, dims, path.data(), xfer_plist_id);
2683         }
2684     }
2685 
2686     releaseGraphicObjectProperty(__GO_LINKS__, links, jni_int_vector, link);
2687     closeList6(node);
2688 
2689     //text
2690     int* dims = nullptr;
2691     getHandleIntVectorProperty(uid, __GO_TEXT_ARRAY_DIMENSIONS__, &dims);
2692     char** text;
2693     getHandleStringVectorProperty(uid, __GO_TEXT_STRINGS__, &text);
2694     writeStringMatrix6(parent, "text", 2, dims, text, xfer_plist_id);
2695     closeList6(parent);
2696     return true;
2697 }
2698 
export_handle_fec(hid_t parent,int uid,hid_t xfer_plist_id)2699 static bool export_handle_fec(hid_t parent, int uid, hid_t xfer_plist_id)
2700 {
2701     if (export_handle_generic(parent, uid, FecHandle::getPropertyList(), xfer_plist_id) == false)
2702     {
2703         return false;
2704     }
2705 
2706     //triangles
2707     int indices = 0;
2708     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_INDICES__, &indices);
2709     int vect = 0;
2710     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_VERTICES_BY_ELEM__, &vect);
2711     double* triangles = nullptr;
2712     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_FEC_ELEMENTS__, &triangles);
2713 
2714     int dims[2];
2715     dims[0] = indices;
2716     dims[1] = vect + 2;
2717     writeDoubleMatrix6(parent, "triangles", 2, dims, triangles, xfer_plist_id);
2718     releaseGraphicObjectProperty(__GO_DATA_MODEL_FEC_ELEMENTS__, triangles, jni_double_vector, dims[0] * dims[1]);
2719 
2720     closeList6(parent);
2721     return true;
2722 }
2723 
export_handle_matplot(hid_t parent,int uid,hid_t xfer_plist_id)2724 static bool export_handle_matplot(hid_t parent, int uid, hid_t xfer_plist_id)
2725 {
2726     if (export_handle_generic(parent, uid, MatplotHandle::getPropertyList(), xfer_plist_id) == false)
2727     {
2728         return false;
2729     }
2730 
2731     int row = 0;
2732     int col = 0;
2733     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_X__, &col);
2734     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_Y__, &row);
2735     int datatype = 0;
2736     getHandleIntProperty(uid, __GO_DATA_MODEL_MATPLOT_DATA_TYPE__, &datatype);
2737     int imagetype = 0;
2738     getHandleIntProperty(uid, __GO_DATA_MODEL_MATPLOT_IMAGE_TYPE__, &imagetype);
2739     int size = (row - 1) * (col - 1);
2740 
2741     //data can be char, uchar, short, ushort, ... hide in a double*
2742     //save double like this but need to compute exact dimensions to
2743     //store it
2744 
2745     double* data = nullptr;
2746     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Z__, &data);
2747 
2748     switch (datatype)
2749     {
2750         case MATPLOT_Char:
2751         case MATPLOT_HM1_Char:
2752         case MATPLOT_HM1_UChar:
2753             size /= (sizeof(double) / sizeof(char));
2754             break;
2755         case MATPLOT_HM3_Char:
2756         case MATPLOT_HM3_UChar:
2757             size /= (sizeof(double) / sizeof(char));
2758             size *= 3;
2759             break;
2760 
2761         case MATPLOT_HM3_Double:
2762             size *= 3;
2763             break;
2764         case MATPLOT_HM4_Char:
2765         case MATPLOT_HM4_UChar:
2766             size /= (sizeof(double) / sizeof(char));
2767             size *= 4;
2768             break;
2769         case MATPLOT_HM4_Double:
2770             size *= 4;
2771             break;
2772         case MATPLOT_UChar:
2773             size /= (sizeof(double) / sizeof(char));
2774             if ((ImageType)imagetype == MATPLOT_RGB)
2775             {
2776                 size *= 3;
2777             }
2778             else if ((GLType)imagetype == MATPLOT_GL_RGBA)
2779             {
2780                 size *= 4;
2781             }
2782             break;
2783         case MATPLOT_Int:
2784         case MATPLOT_UInt:
2785             size /= (sizeof(double) / sizeof(int));
2786             break;
2787         case MATPLOT_Short:
2788         case MATPLOT_UShort:
2789             size /= (sizeof(double) / sizeof(short));
2790             break;
2791         case MATPLOT_Double:
2792         case MATPLOT_HM1_Double:
2793         default:
2794             break;
2795     }
2796 
2797     int dims[2];
2798     dims[0] = 1;
2799     dims[1] = size;
2800 
2801     writeDoubleMatrix6(parent, "data", 2, dims, data, xfer_plist_id);
2802     releaseGraphicObjectProperty(__GO_DATA_MODEL_Z__, data, jni_double_vector, size);
2803     closeList6(parent);
2804     return true;
2805 }
2806 
export_handle_grayplot(hid_t parent,int uid,hid_t xfer_plist_id)2807 static bool export_handle_grayplot(hid_t parent, int uid, hid_t xfer_plist_id)
2808 {
2809     if (export_handle_generic(parent, uid, GrayplotHandle::getPropertyList(), xfer_plist_id) == false)
2810     {
2811         return false;
2812     }
2813 
2814     int row = 0;
2815     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_X__, &row);
2816     int col = 0;
2817     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_Y__, &col);
2818 
2819     double* dataX = nullptr;
2820     double* dataY = nullptr;
2821     double* dataZ = nullptr;
2822 
2823     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_X__, &dataX);
2824     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Y__, &dataY);
2825     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Z__, &dataZ);
2826 
2827     int dims[2];
2828     dims[0] = 1;
2829     dims[1] = row;
2830     writeDoubleMatrix6(parent, "data_x", 2, dims, dataX, xfer_plist_id);
2831 
2832     dims[0] = 1;
2833     dims[1] = col;
2834     writeDoubleMatrix6(parent, "data_y", 2, dims, dataY, xfer_plist_id);
2835 
2836     dims[0] = row;
2837     dims[1] = col;
2838     writeDoubleMatrix6(parent, "data_z", 2, dims, dataZ, xfer_plist_id);
2839 
2840     closeList6(parent);
2841     return true;
2842 }
2843 
export_handle_segs(hid_t parent,int uid,hid_t xfer_plist_id)2844 static bool export_handle_segs(hid_t parent, int uid, hid_t xfer_plist_id)
2845 {
2846     if (export_handle_generic(parent, uid, SegsHandle::getPropertyList(), xfer_plist_id) == false)
2847     {
2848         return false;
2849     }
2850 
2851     closeList6(parent);
2852     return true;
2853 }
2854 
export_handle_arc(hid_t parent,int uid,hid_t xfer_plist_id)2855 static bool export_handle_arc(hid_t parent, int uid, hid_t xfer_plist_id)
2856 {
2857     if (export_handle_generic(parent, uid, ArcHandle::getPropertyList(), xfer_plist_id) == false)
2858     {
2859         return false;
2860     }
2861 
2862     closeList6(parent);
2863     return true;
2864 }
2865 
export_handle_rectangle(hid_t parent,int uid,hid_t xfer_plist_id)2866 static bool export_handle_rectangle(hid_t parent, int uid, hid_t xfer_plist_id)
2867 {
2868     if (export_handle_generic(parent, uid, RectangleHandle::getPropertyList(), xfer_plist_id) == false)
2869     {
2870         return false;
2871     }
2872 
2873     closeList6(parent);
2874     return true;
2875 }
2876 
export_handle_datatip(hid_t parent,int uid,hid_t xfer_plist_id)2877 static bool export_handle_datatip(hid_t parent, int uid, hid_t xfer_plist_id)
2878 {
2879     if (export_handle_generic(parent, uid, DatatipHandle::getPropertyList(), xfer_plist_id) == false)
2880     {
2881         return false;
2882     }
2883 
2884     closeList6(parent);
2885     return true;
2886 }
2887 
export_handle_polyline_shift(hid_t parent,int uid,const std::string & name,int go_set,int go_data,hid_t xfer_plist_id)2888 static bool export_handle_polyline_shift(hid_t parent, int uid, const std::string& name, int go_set, int go_data, hid_t xfer_plist_id)
2889 {
2890     int set = 0;
2891     getHandleBoolProperty(uid, go_set, &set);
2892     if (set)
2893     {
2894         int count = 0;
2895         getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_ELEMENTS__, &count);
2896         double* data = nullptr;
2897         getHandleDoubleVectorProperty(uid, go_data, &data);
2898 
2899         int dims[2];
2900         dims[0] = 1;
2901         dims[1] = count;
2902         writeDoubleMatrix6(parent, name.data(), 2, dims, data, xfer_plist_id);
2903 
2904         releaseGraphicObjectProperty(uid, data, jni_double_vector, count);
2905     }
2906     else
2907     {
2908         int dims[2];
2909         dims[0] = 0;
2910         dims[1] = 0;
2911         writeDoubleMatrix6(parent, name.data(), 2, dims, NULL, xfer_plist_id);
2912     }
2913 
2914     return true;
2915 }
2916 
export_handle_polyline(hid_t parent,int uid,hid_t xfer_plist_id)2917 static bool export_handle_polyline(hid_t parent, int uid, hid_t xfer_plist_id)
2918 {
2919     if (export_handle_datatips(parent, uid, xfer_plist_id) == false)
2920     {
2921         return false;
2922     }
2923 
2924     if (export_handle_generic(parent, uid, PolylineHandle::getPropertyList(), xfer_plist_id) == false)
2925     {
2926         return false;
2927     }
2928 
2929     //x_shift
2930     export_handle_polyline_shift(parent, uid, "x_shift", __GO_DATA_MODEL_X_COORDINATES_SHIFT_SET__, __GO_DATA_MODEL_X_COORDINATES_SHIFT__, xfer_plist_id);
2931     //y_shift
2932     export_handle_polyline_shift(parent, uid, "y_shift", __GO_DATA_MODEL_Y_COORDINATES_SHIFT_SET__, __GO_DATA_MODEL_Y_COORDINATES_SHIFT__, xfer_plist_id);
2933     //z_shift
2934     export_handle_polyline_shift(parent, uid, "z_shift", __GO_DATA_MODEL_Z_COORDINATES_SHIFT_SET__, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, xfer_plist_id);
2935 
2936     //interp_color_vector
2937     int set = 0;
2938     getHandleBoolProperty(uid, __GO_INTERP_COLOR_VECTOR_SET__, &set);
2939     if (set)
2940     {
2941         int count = 0;
2942         getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_ELEMENTS__, &count);
2943         int* data = nullptr;
2944         getHandleIntVectorProperty(uid, __GO_INTERP_COLOR_VECTOR__, &data);
2945 
2946         int dims[2];
2947         dims[0] = 1;
2948         dims[1] = count;
2949         writeIntegerMatrix6(parent, "interp_color_vector", H5T_NATIVE_INT32, "32", 2, dims, data, xfer_plist_id);
2950         releaseGraphicObjectProperty(uid, data, jni_int_vector, count);
2951     }
2952     else
2953     {
2954         int dims[2];
2955         dims[0] = 0;
2956         dims[1] = 0;
2957         writeIntegerMatrix6(parent, "interp_color_vector", H5T_NATIVE_INT32, "32", 2, dims, NULL, xfer_plist_id);
2958     }
2959 
2960     //data
2961     int count = 0;
2962     getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_ELEMENTS__, &count);
2963 
2964     int dims[2];
2965     dims[0] = 1;
2966     dims[1] = count;
2967 
2968     double* dataX = nullptr;
2969     double* dataY = nullptr;
2970     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_X__, &dataX);
2971     getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Y__, &dataY);
2972 
2973     writeDoubleMatrix6(parent, "data_x", 2, dims, dataX, xfer_plist_id);
2974     writeDoubleMatrix6(parent, "data_y", 2, dims, dataY, xfer_plist_id);
2975 
2976     releaseGraphicObjectProperty(__GO_DATA_MODEL_X__, dataX, jni_double_vector, count);
2977     releaseGraphicObjectProperty(__GO_DATA_MODEL_Y__, dataY, jni_double_vector, count);
2978 
2979     getHandleIntProperty(uid, __GO_DATA_MODEL_Z_COORDINATES_SET__, &set);
2980     if (set)
2981     {
2982         double* dataZ = nullptr;
2983         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Z__, &dataZ);
2984         writeDoubleMatrix6(parent, "data_z", 2, dims, dataZ, xfer_plist_id);
2985         releaseGraphicObjectProperty(__GO_DATA_MODEL_Z__, dataZ, jni_double_vector, count);
2986     }
2987     else
2988     {
2989         //[]
2990         dims[0] = 0;
2991         dims[1] = 0;
2992         writeDoubleMatrix6(parent, "data_z", 2, dims, NULL, xfer_plist_id);
2993     }
2994 
2995     closeList6(parent);
2996     return true;
2997 }
2998 
export_handle_surface(hid_t parent,int uid,hid_t xfer_plist_id)2999 static bool export_handle_surface(hid_t parent, int uid, hid_t xfer_plist_id)
3000 {
3001     return export_handle_generic(parent, uid, SurfaceHandle::getPropertyList(), xfer_plist_id);
3002 }
3003 
export_handle_plot3d(hid_t parent,int uid,hid_t xfer_plist_id)3004 static bool export_handle_plot3d(hid_t parent, int uid, hid_t xfer_plist_id)
3005 {
3006     bool ret = export_handle_surface(parent, uid, xfer_plist_id);
3007     if (ret)
3008     {
3009         double* colors = NULL;
3010         double* dataX = NULL;
3011         double* dataY = NULL;
3012         double* dataZ = NULL;
3013 
3014         //data
3015         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_X__, &dataX);
3016         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Y__, &dataY);
3017         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Z__, &dataZ);
3018 
3019         int row = 0;
3020         getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_X__, &row);
3021         int col = 0;
3022         getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_Y__, &col);
3023 
3024         int* xDims = nullptr;
3025         int* yDims = nullptr;
3026         getHandleIntVectorProperty(uid, __GO_DATA_MODEL_X_DIMENSIONS__, &xDims);
3027         getHandleIntVectorProperty(uid, __GO_DATA_MODEL_Y_DIMENSIONS__, &yDims);
3028 
3029         int dims[2];
3030         dims[0] = xDims[0];
3031         dims[1] = xDims[1];
3032         writeDoubleMatrix6(parent, "data_x", 2, dims, dataX, xfer_plist_id);
3033         releaseGraphicObjectProperty(__GO_DATA_MODEL_X__, dataX, jni_double_vector, dims[0] * dims[1]);
3034 
3035         dims[0] = yDims[0];
3036         dims[1] = yDims[1];
3037         writeDoubleMatrix6(parent, "data_y", 2, dims, dataY, xfer_plist_id);
3038         releaseGraphicObjectProperty(__GO_DATA_MODEL_Y__, dataY, jni_double_vector, dims[0] * dims[1]);
3039 
3040         dims[0] = row;
3041         dims[1] = col;
3042         writeDoubleMatrix6(parent, "data_z", 2, dims, dataZ, xfer_plist_id);
3043         releaseGraphicObjectProperty(__GO_DATA_MODEL_Z__, dataZ, jni_double_vector, dims[0] * dims[1]);
3044 
3045         releaseGraphicObjectProperty(__GO_DATA_MODEL_X_DIMENSIONS__, xDims, jni_int_vector, 2);
3046         releaseGraphicObjectProperty(__GO_DATA_MODEL_Y_DIMENSIONS__, dataZ, jni_int_vector, 2);
3047     }
3048 
3049     closeList6(parent);
3050     return ret;
3051 }
3052 
export_handle_fac3d(hid_t parent,int uid,hid_t xfer_plist_id)3053 static bool export_handle_fac3d(hid_t parent, int uid, hid_t xfer_plist_id)
3054 {
3055     bool ret = export_handle_surface(parent, uid, xfer_plist_id);
3056     if (ret)
3057     {
3058         double* colors = NULL;
3059         double* dataX = NULL;
3060         double* dataY = NULL;
3061         double* dataZ = NULL;
3062 
3063         //data
3064         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_X__, &dataX);
3065         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Y__, &dataY);
3066         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_Z__, &dataZ);
3067 
3068         int row = 0;
3069         getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_VERTICES_PER_GON__, &row);
3070         int col = 0;
3071         getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_GONS__, &col);
3072 
3073         int dims[2];
3074         dims[0] = row;
3075         dims[1] = col;
3076 
3077         writeDoubleMatrix6(parent, "data_x", 2, dims, dataX, xfer_plist_id);
3078         writeDoubleMatrix6(parent, "data_y", 2, dims, dataY, xfer_plist_id);
3079         writeDoubleMatrix6(parent, "data_z", 2, dims, dataZ, xfer_plist_id);
3080 
3081         releaseGraphicObjectProperty(__GO_DATA_MODEL_X__, dataX, jni_double_vector, dims[0] * dims[1]);
3082         releaseGraphicObjectProperty(__GO_DATA_MODEL_Y__, dataY, jni_double_vector, dims[0] * dims[1]);
3083         releaseGraphicObjectProperty(__GO_DATA_MODEL_Z__, dataZ, jni_double_vector, dims[0] * dims[1]);
3084 
3085         getHandleDoubleVectorProperty(uid, __GO_DATA_MODEL_COLORS__, &colors);
3086         if (colors)
3087         {
3088             int numColors = 0;
3089             getHandleIntProperty(uid, __GO_DATA_MODEL_NUM_COLORS__, &numColors);
3090             if (numColors == col)
3091             {
3092                 dims[0] = 1;
3093             }
3094             else
3095             {
3096                 dims[0] = row;
3097             }
3098 
3099             dims[1] = col;
3100         }
3101         else
3102         {
3103             //export []
3104             dims[0] = 0;
3105             dims[1] = 0;
3106         }
3107 
3108         writeDoubleMatrix6(parent, "colors", 2, dims, colors, xfer_plist_id);
3109         releaseGraphicObjectProperty(__GO_DATA_MODEL_COLORS__, colors, jni_double_vector, dims[0] * dims[1]);
3110 
3111         //cdata_mapping
3112         int cdata = 0;
3113         getHandleIntProperty(uid, __GO_DATA_MAPPING__, &cdata);
3114         dims[0] = 1;
3115         dims[1] = 1;
3116         writeIntegerMatrix6(parent, "cdata_mapping", H5T_NATIVE_INT32, "32", 2, dims, &cdata, xfer_plist_id);
3117 
3118     }
3119 
3120     closeList6(parent);
3121     return ret;
3122 }
3123 
3124 
export_handle_champ(hid_t parent,int uid,hid_t xfer_plist_id)3125 static bool export_handle_champ(hid_t parent, int uid, hid_t xfer_plist_id)
3126 {
3127     if (export_handle_generic(parent, uid, ChampHandle::getPropertyList(), xfer_plist_id) == false)
3128     {
3129         return false;
3130     }
3131 
3132     //data
3133     int* dimensions = NULL;
3134     double* arrowBasesX = NULL;
3135     double* arrowBasesY = NULL;
3136     double* arrowDirectionsX = NULL;
3137     double* arrowDirectionsY = NULL;
3138     int dims[2];
3139     getHandleIntVectorProperty(uid, __GO_CHAMP_DIMENSIONS__, &dimensions);
3140 
3141     //base X
3142     getHandleDoubleVectorProperty(uid, __GO_BASE_X__, &arrowBasesX);
3143     dims[0] = 1;
3144     dims[1] = dimensions[0];
3145     writeDoubleMatrix6(parent, "base_x", 2, dims, arrowBasesX, xfer_plist_id);
3146     releaseGraphicObjectProperty(__GO_BASE_X__, arrowBasesX, jni_double_vector, dims[1]);
3147 
3148     //base y
3149     getHandleDoubleVectorProperty(uid, __GO_BASE_Y__, &arrowBasesY);
3150     dims[0] = 1;
3151     dims[1] = dimensions[1];
3152     writeDoubleMatrix6(parent, "base_y", 2, dims, arrowBasesY, xfer_plist_id);
3153     releaseGraphicObjectProperty(__GO_BASE_Y__, arrowBasesY, jni_double_vector, dims[1]);
3154 
3155     //direction x
3156     getHandleDoubleVectorProperty(uid, __GO_DIRECTION_X__, &arrowDirectionsX);
3157     dims[0] = dimensions[0];
3158     dims[1] = dimensions[1];
3159     writeDoubleMatrix6(parent, "direction_x", 2, dims, arrowDirectionsX, xfer_plist_id);
3160     releaseGraphicObjectProperty(__GO_DIRECTION_X__, arrowDirectionsX, jni_double_vector, dims[0] * dims[1]);
3161 
3162     //direction y
3163     getHandleDoubleVectorProperty(uid, __GO_DIRECTION_Y__, &arrowDirectionsY);
3164     dims[0] = dimensions[0];
3165     dims[1] = dimensions[1];
3166     writeDoubleMatrix6(parent, "direction_y", 2, dims, arrowDirectionsY, xfer_plist_id);
3167     releaseGraphicObjectProperty(__GO_DIRECTION_Y__, arrowDirectionsY, jni_double_vector, dims[0] * dims[1]);
3168 
3169     releaseGraphicObjectProperty(__GO_CHAMP_DIMENSIONS__, dimensions, jni_int_vector, 2);
3170     closeList6(parent);
3171     return true;
3172 }
export_handle_label(hid_t parent,int uid,hid_t xfer_plist_id)3173 static bool export_handle_label(hid_t parent, int uid, hid_t xfer_plist_id)
3174 {
3175     if (export_handle_generic(parent, uid, LabelHandle::getPropertyList(), xfer_plist_id) == false)
3176     {
3177         return false;
3178     }
3179 
3180     //text
3181     int* dimensions = nullptr;
3182     char** text = nullptr;
3183 
3184     getHandleIntVectorProperty(uid, __GO_TEXT_ARRAY_DIMENSIONS__, &dimensions);
3185     getHandleStringVectorProperty(uid, __GO_TEXT_STRINGS__, &text);
3186 
3187     std::vector<int> dims = {dimensions[0], dimensions[1]};
3188     releaseGraphicObjectProperty(__GO_TEXT_ARRAY_DIMENSIONS__, dimensions, jni_int_vector, 2);
3189 
3190     writeStringMatrix6(parent, "text", 2, dims.data(), text, xfer_plist_id);
3191     releaseGraphicObjectProperty(__GO_TEXT_STRINGS__, text, jni_string_vector, dims[0] * dims[1]);
3192 
3193     closeList6(parent);
3194     return true;
3195 }
export_handle_axes(hid_t parent,int uid,hid_t xfer_plist_id)3196 static bool export_handle_axes(hid_t parent, int uid, hid_t xfer_plist_id)
3197 {
3198     if (export_handle_generic(parent, uid, AxesHandle::getPropertyList(), xfer_plist_id) == false)
3199     {
3200         return false;
3201     }
3202 
3203     //title
3204     int title = 0;
3205     getHandleIntProperty(uid, __GO_TITLE__, &title);
3206     export_handle(parent, "title", title, xfer_plist_id);
3207 
3208     //x_label
3209     int x_label = 0;
3210     getHandleIntProperty(uid, __GO_X_AXIS_LABEL__, &x_label);
3211     export_handle(parent, "x_label", x_label, xfer_plist_id);
3212 
3213     //y_label
3214     int y_label = 0;
3215     getHandleIntProperty(uid, __GO_Y_AXIS_LABEL__, &y_label);
3216     export_handle(parent, "y_label", y_label, xfer_plist_id);
3217 
3218     //z_label
3219     int z_label = 0;
3220     getHandleIntProperty(uid, __GO_Z_AXIS_LABEL__, &z_label);
3221     export_handle(parent, "z_label", z_label, xfer_plist_id);
3222 
3223 
3224     closeList6(parent);
3225     return true;
3226 }
3227 
export_handle_figure(hid_t parent,int uid,hid_t xfer_plist_id)3228 static bool export_handle_figure(hid_t parent, int uid, hid_t xfer_plist_id)
3229 {
3230     if (export_handle_generic(parent, uid, FigureHandle::getPropertyList(), xfer_plist_id) == false)
3231     {
3232         return false;
3233     }
3234 
3235     //layout_options
3236     export_handle_layout_options(parent, uid, xfer_plist_id);
3237 
3238     closeList6(parent);
3239     return true;
3240 }
3241 
export_handle_compound(hid_t parent,int uid,hid_t xfer_plist_id)3242 static bool export_handle_compound(hid_t parent, int uid, hid_t xfer_plist_id)
3243 {
3244     if (export_handle_generic(parent, uid, CompoundHandle::getPropertyList(), xfer_plist_id) == false)
3245     {
3246         return false;
3247     }
3248 
3249     closeList6(parent);
3250     return true;
3251 }
3252 
export_handle(hid_t parent,const std::string & name,int uid,hid_t xfer_plist_id)3253 bool export_handle(hid_t parent, const std::string& name, int uid, hid_t xfer_plist_id)
3254 {
3255     //get handle type
3256     int type = 0;
3257     getHandleIntProperty(uid, __GO_TYPE__, &type);
3258 
3259     //create handle node in __refs__
3260     hid_t h = openList6(parent, name.data(), g_SCILAB_CLASS_HANDLE);
3261 
3262     bool ret = false;
3263     switch (type)
3264     {
3265         case __GO_FIGURE__:
3266         {
3267             ret = export_handle_figure(h, uid, xfer_plist_id);
3268             break;
3269         }
3270         case __GO_AXES__:
3271         {
3272             ret = export_handle_axes(h, uid, xfer_plist_id);
3273             break;
3274         }
3275         case __GO_LABEL__:
3276         {
3277             ret = export_handle_label(h, uid, xfer_plist_id);
3278             break;
3279         }
3280         case __GO_CHAMP__:
3281         {
3282             ret = export_handle_champ(h, uid, xfer_plist_id);
3283             break;
3284         }
3285         case __GO_FAC3D__:
3286         {
3287             ret = export_handle_fac3d(h, uid, xfer_plist_id);
3288             break;
3289         }
3290         case __GO_PLOT3D__:
3291         {
3292             ret = export_handle_plot3d(h, uid, xfer_plist_id);
3293             break;
3294         }
3295         case __GO_POLYLINE__:
3296         {
3297             ret = export_handle_polyline(h, uid, xfer_plist_id);
3298             break;
3299         }
3300         case __GO_DATATIP__:
3301         {
3302             ret = export_handle_datatip(h, uid, xfer_plist_id);
3303             break;
3304         }
3305         case __GO_COMPOUND__:
3306         {
3307             ret = export_handle_compound(h, uid, xfer_plist_id);
3308             break;
3309         }
3310         case __GO_RECTANGLE__:
3311         {
3312             ret = export_handle_rectangle(h, uid, xfer_plist_id);
3313             break;
3314         }
3315         case __GO_ARC__:
3316         {
3317             ret = export_handle_arc(h, uid, xfer_plist_id);
3318             break;
3319         }
3320         case __GO_SEGS__:
3321         {
3322             ret = export_handle_segs(h, uid, xfer_plist_id);
3323             break;
3324         }
3325         case __GO_GRAYPLOT__:
3326         {
3327             ret = export_handle_grayplot(h, uid, xfer_plist_id);
3328             break;
3329         }
3330         case __GO_MATPLOT__:
3331         {
3332             ret = export_handle_matplot(h, uid, xfer_plist_id);
3333             break;
3334         }
3335         case __GO_FEC__:
3336         {
3337             ret = export_handle_fec(h, uid, xfer_plist_id);
3338             break;
3339         }
3340         case __GO_LEGEND__:
3341         {
3342             ret = export_handle_legend(h, uid, xfer_plist_id);
3343             break;
3344         }
3345         case __GO_TEXT__:
3346         {
3347             ret = export_handle_text(h, uid, xfer_plist_id);
3348             break;
3349         }
3350         case __GO_AXIS__:
3351         {
3352             ret = export_handle_axis(h, uid, xfer_plist_id);
3353             break;
3354         }
3355         case __GO_LIGHT__:
3356         {
3357             ret = export_handle_light(h, uid, xfer_plist_id);
3358             break;
3359         }
3360         case __GO_UIMENU__:
3361         {
3362             ret = export_handle_uimenu(h, uid, xfer_plist_id);
3363             break;
3364         }
3365         case __GO_UICONTEXTMENU__:
3366         {
3367             ret = export_handle_uicontextmenu(h, uid, xfer_plist_id);
3368             break;
3369         }
3370         case __GO_UICONTROL__:
3371         {
3372             ret = export_handle_uicontrol(h, uid, xfer_plist_id);
3373             break;
3374         }
3375         default:
3376         {
3377         }
3378 
3379     }
3380 
3381     return ret;
3382 }
3383 
export_handle_children(hid_t parent,int uid,hid_t xfer_plist_id)3384 static bool export_handle_children(hid_t parent, int uid, hid_t xfer_plist_id)
3385 {
3386     int count = 0;
3387     getHandleIntProperty(uid, __GO_CHILDREN_COUNT__, &count);
3388     hid_t node = openList6(parent, "children", g_SCILAB_CLASS_HANDLE);
3389     int* children = nullptr;
3390 
3391     if (count != 0)
3392     {
3393         getHandleIntVectorProperty(uid, __GO_CHILDREN__, &children);
3394     }
3395 
3396     int index = 0;
3397     for (int i = 0; i < count; ++i)
3398     {
3399         int child = children[i];
3400         int hidden = 0;
3401         getHandleBoolProperty(child, __GO_HIDDEN__, &hidden);
3402         if (hidden == 0)
3403         {
3404             if (export_handle(node, std::to_string(index), child, xfer_plist_id) == false)
3405             {
3406                 releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, count);
3407                 closeList6(node);
3408                 return false;
3409             }
3410 
3411             ++index;
3412         }
3413     }
3414 
3415     releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, count);
3416     closeList6(node);
3417     return true;
3418 }
3419 
add_current_entity(hid_t dataset)3420 int add_current_entity(hid_t dataset)
3421 {
3422     int type = 0;
3423     getHandleInt(dataset, "type", &type);
3424 
3425     switch (type)
3426     {
3427         case __GO_FIGURE__:
3428         {
3429             return import_handle(dataset, -1);
3430         }
3431         case __GO_AXES__:
3432         {
3433             //add handle to current figure
3434             getOrCreateDefaultSubwin();
3435             int iCurrentFigure = getCurrentFigure();
3436             return import_handle(dataset, iCurrentFigure);
3437         }
3438         case __GO_COMPOUND__:
3439         {
3440             int axes = getOrCreateDefaultSubwin();
3441             return import_handle(dataset, axes);
3442         }
3443         default:
3444             //add handle as child of current axes ( take care of compound ! )
3445             return -1;
3446     }
3447 }
3448