* Bug 16374 fixed: BC error loading in 6.x datatips saved in 5.5
[scilab.git] / scilab / modules / io / macros / %_sodload.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
3 // Copyright (C) 2012 - DIGITEO - Vincent COUVERT
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 function varargout = %_sodload(%__varnameList__)
15
16     function varValue = %__convertVariable__(varValue, varName)
17         if typeof(varValue) == "ScilabMatrixHandle" then
18             //convert tlist to handle
19             varValue = createMatrixHandle(varValue);
20         elseif typeof(varValue) == "ScilabMacro" then
21             //convert tlist to macro
22             varValue = createMacro(varValue, varName);
23         elseif isList(varValue) then
24             //list container
25             varValue = parseList(varValue);
26         end
27     endfunction
28
29     function result = isList(var)
30         //15 : list
31         //16 : tlist
32         //17 : mlist
33         if or(type(var) == [15, 16, 17]) then
34             result  = %t;
35         else
36             result = %f;
37         end
38     endfunction
39
40     function varValue = parseList(varValue)
41
42         if or(typeof(varValue)==["ce","st"]) then
43             if typeof(varValue)=="st" then
44                 fieldNames = fieldnames(varValue);
45             else
46                 fieldNames = varValue;
47             end
48
49             for kField = 1:size(fieldNames,"*")
50
51                 if typeof(varValue)=="st" then
52                     fieldValue = varValue(fieldNames(kField));
53                 else
54                     fieldValue = varValue{kField};
55                 end
56
57                 if typeof(fieldValue) == "ScilabMatrixHandle" then
58                     fieldValue = createMatrixHandle(fieldValue);
59                 elseif typeof(fieldValue) == "ScilabMacro" then
60                     //convert tlist to macro
61                     fieldValue = createMacro(fieldValue, "function");
62                 elseif isList(fieldValue) then
63                     fieldValue = parseList(fieldValue);
64                 end
65
66                 if typeof(varValue)=="st" then
67                     s = size(varValue, "*");
68                     if s > 1 then
69                         if typeof(fieldValue) <> "list" then //houston !
70                         end
71
72                         for iDim = 1:s
73                             varValue(iDim)(fieldNames(kField)) = fieldValue(iDim);
74                         end
75                     else
76                         varValue(fieldNames(kField)) = fieldValue;
77                     end
78                 else
79                     varValue{kField} = fieldValue;
80                 end
81
82             end
83
84         elseif typeof(varValue)=="list" then
85             for i = definedfields(varValue)
86                 if typeof(varValue(i)) == "ScilabMatrixHandle" then
87                     varValue(i) = createMatrixHandle(varValue(i));
88                 elseif typeof(varValue(i)) == "ScilabMacro" then
89                     //convert tlist to macro
90                     varValue(i) = createMacro(varValue(i), "function");
91                 elseif isList(varValue(i)) then
92                     varValue(i) = parseList(varValue(i));
93                 else
94                     varValue(i) = varValue(i);
95                 end
96             end
97         else
98             fieldNb = size(getfield(1, varValue), "*");
99             for kField = 2:fieldNb // Do not inspect first field (field names)
100                 fieldValue = getfield(kField, varValue);
101                 if typeof(fieldValue) == "ScilabMatrixHandle" then
102                     fieldValue = createMatrixHandle(fieldValue);
103                 elseif typeof(fieldValue) == "ScilabMacro" then
104                     //convert tlist to macro
105                     fieldValue = createMacro(fieldValue, "function");
106                 elseif isList(fieldValue) then
107                     fieldValue = parseList(fieldValue);
108                 end
109                 varValue = setfield(kField, fieldValue, varValue);
110             end
111         end
112     endfunction
113
114     function h = createMatrixHandle(matrixHandle)
115         h = [];
116         if typeof(matrixHandle) <> "ScilabMatrixHandle" then
117             return;
118         end
119
120         for i = prod(matrixHandle.dims):-1:1
121
122             newItem = createSingleHandle(matrixHandle.values(i));
123             if newItem == [] then
124                 continue;
125             end
126
127             h($+1) = newItem;
128             if or(fieldnames(matrixHandle.values(i))=="user_data") then // TODO Remove after graphic branch merge
129                 if isList(matrixHandle.values(i).user_data) then
130                     set(h($), "user_data", parseList(matrixHandle.values(i).user_data));
131                 elseif typeof(matrixHandle.values(i).user_data) == "ScilabMatrixHandle" then
132                     set(h($), "user_data", createMatrixHandle(matrixHandle.values(i).user_data));
133                 end
134             end
135         end
136     endfunction
137
138     function h = createSingleHandle(item)
139         select item.type
140         case "Figure"
141             h = createFigure(item);
142         case "Axes"
143             h = createAxes(item);
144         case "Polyline"
145             h = createPolyline(item);
146         case "Plot3d"
147             h = createPlot3d(item);
148         case "Fac3d"
149             h = createFac3d(item);
150         case "Compound"
151             h = createCompound(item);
152         case "Rectangle"
153             h = createRectangle(item);
154         case "Arc"
155             h = createArc(item);
156         case "Champ"
157             h = createChamp(item);
158         case "Segs"
159             h = createSegs(item);
160         case "Grayplot"
161             h = createGrayplot(item);
162         case "Matplot"
163             h = createMatplot(item);
164         case "Fec"
165             h = createFec(item);
166         case "Legend"
167             h = createLegend(item);
168         case "Text"
169             h = createText(item);
170         case "Axis"
171             h = createAxis(item);
172         case "uimenu"
173             h = createuimenu(item);
174         case "uicontextmenu"
175             h = createuicontextmenu(item);
176         case "uicontrol"
177             h = createuicontrol(item);
178         case "Datatip"
179             h = createDatatip(item);
180         case "Light"
181             h = createLight(item);
182         else
183             error("handle of type " + item.type + " unhandled");
184             h = [];
185         end
186     endfunction
187
188     //
189     // FIGURE
190     //
191     function h = createFigure(figureProperties)
192         fields = fieldnames(figureProperties);
193         fields(1) = [];
194
195         if or(fields=="resize") then
196             if figureProperties.menubar<>"figure" ..
197                 | figureProperties.toolbar<>"figure" ..
198                 | figureProperties.dockable<>"on" ..
199                 | figureProperties.default_axes<>"on" then
200                 // File created by Scilab 5.5.0 or more
201                 h = figure("menubar", figureProperties.menubar, ...
202                 "toolbar", figureProperties.toolbar, ...
203                 "dockable", figureProperties.dockable, ...
204                 "default_axes", figureProperties.default_axes, ...
205                 "visible", "off");
206                 h.background = -2;
207                 fields(fields=="menubar") = [];
208                 fields(fields=="toolbar") = [];
209                 fields(fields=="dockable") = [];
210                 fields(fields=="default_axes") = [];
211                 fields(fields=="visible") = [];
212             else
213                 [lnums, fnames] = where();
214                 ind = grep(fnames, "xload");
215                 xload_mode = (ind ~= []);
216                 if xload_mode then // See bug #3975
217                     h = gcf();
218                 else
219                     h = scf();
220                 end
221                 h.visible = "off";
222             end
223         else
224             if isempty(winsid()) then
225                 h = figure("visible", "off");
226                 h.background = -2;
227             else
228                 h = gcf();
229                 h.visible = "off";
230             end
231         end
232
233         // Following propeties will be set after all other ones
234         isVisible = figureProperties.visible;
235         fields(fields=="visible") = [];
236         resizefcn = figureProperties.resizefcn;
237         fields(fields=="resizefcn") = [];
238         event_handler = figureProperties.event_handler;
239         fields(fields=="event_handler") = [];
240
241         // Ignore figure_id
242         fields(fields=="figure_id") = [];
243
244         h.figure_position=figureProperties.figure_position;
245         fields(fields=="figure_position") = [];
246         // set auto_resize first otherwise viewport modification may not have any effect.
247         h.auto_resize = figureProperties.auto_resize;
248         fields(fields=="auto_resize") = [];
249         h.figure_size = figureProperties.figure_size;
250         fields(fields=="figure_size") = [];
251         // set axes_size last because it's more important than figure_size
252         h.axes_size = figureProperties.axes_size;
253         fields(fields=="axes_size") = [];
254
255         for i = 1:size(fields, "*")
256             if fields(i) == "children" then
257                 c = figureProperties(fields(i));
258                 s = prod(c.dims);
259                 createSingleHandle(c.values(s));
260                 for  i = s-1:-1:1
261                     xsetech(wrect=[0 0 .1 .1])
262                     createSingleHandle(c.values(i));
263                 end
264             else
265                 if fields(i)<>"pixmap" then // See bug #13310
266                     set(h, fields(i), figureProperties(fields(i)));
267                 end
268             end
269         end
270
271         h.resizefcn = resizefcn;
272         h.event_handler = event_handler;
273         h.visible = isVisible;
274     endfunction
275
276     //
277     // LABEL
278     //
279     function h = createLabel(labelProperties, h)
280         fields = fieldnames(labelProperties);
281         fields(1) = [];
282         for i = 1:size(fields, "*")
283             set(h, fields(i), labelProperties(fields(i)));
284         end
285     endfunction
286
287     //
288     // TICKS
289     //
290     function h = createTicks(ticksProperties)
291         h = tlist(["ticks","locations","labels"], [], []);
292         fields = fieldnames(ticksProperties);
293         for i = 1:size(fields, "*")
294             h(fields(i)) = ticksProperties(fields(i));
295         end
296     endfunction
297
298     //
299     // AXES
300     //
301     function h = createAxes(axesProperties)
302         // Hack to determine whether %h_load has been called by the %h_copy macro
303         // in which case a new Axes object is created
304
305         [lnums, fnames] = where();
306         ind = grep(fnames, "%h_copy");
307         if ~isempty(ind) then
308             newaxes();
309         end;
310
311         h = gca();
312         fields = fieldnames(axesProperties);
313         fields(1) = [];
314
315         // Get log_flags to be sure to set them after data_bounds
316         log_flags = axesProperties.log_flags;
317         fields(fields=="log_flags") = [];
318
319         // Get mark_mode to be sure to set it after mark_style
320         mark_mode = axesProperties.mark_mode;
321         fields(fields=="mark_mode") = [];
322
323         // Get auto_ticks to be sure to set it after ticks labels
324         auto_ticks = axesProperties.auto_ticks;
325         fields(fields=="auto_ticks") = [];
326         automargins = %f;
327         if isfield(axesProperties, "auto_margins") then
328             auto_margins = axesProperties.auto_margins;
329             fields(fields=="auto_margins") = [];
330             automargins = %t;
331         end
332
333         for i = 1:size(fields, "*")
334             if or(fields(i) == ["title","x_label","y_label","z_label"]) then
335                 createLabel(axesProperties(fields(i)), h(fields(i)));
336             elseif or(fields(i) == ["x_ticks", "y_ticks", "z_ticks"]) then
337                 set(h, fields(i), createTicks(axesProperties(fields(i))));
338             elseif fields(i) == "children" then
339                 createMatrixHandle(axesProperties(fields(i)));
340             elseif fields(i) == "clip_state" then
341                 if axesProperties.clip_state=="on" then
342                     set(h,"clip_box",axesProperties.clip_box);
343                 end
344                 set(h,"clip_state", axesProperties.clip_state);
345             elseif fields(i) == "clip_box" then
346                 // managed with 'clip_state'
347             elseif fields(i) == "data_bounds" then
348                 set(h, "data_bounds", axesProperties.data_bounds);
349                 set(h, "log_flags", log_flags);
350             elseif fields(i) == "mark_style" then
351                 set(h, "mark_style", axesProperties.mark_style);
352                 set(h, "mark_mode", mark_mode);
353             else
354                 set(h, fields(i), axesProperties(fields(i)));;
355             end
356         end
357
358         set(h, "auto_ticks", auto_ticks);
359         if automargins then
360             set(h, "auto_margins", auto_margins);
361         end
362
363         // Legend management
364         global %LEG
365         if ~isempty(%LEG) then
366             // Get handles from paths
367             links=getlinksfrompath(h, %LEG.paths)
368             if ~isempty(links) then
369                 L = captions(links, %LEG.text)
370                 L.visible         = %LEG.visible
371                 L.font_style      = %LEG.font_style
372                 L.font_size       = %LEG.font_size
373                 L.font_color      = %LEG.font_color
374                 L.fractional_font = %LEG.fractional_font
375                 L.mark_mode       = "off";
376                 L.legend_location = %LEG.legend_location
377                 L.position        = %LEG.position
378                 L.line_mode       = %LEG.line_mode
379                 L.thickness       = %LEG.thickness
380                 L.foreground      = %LEG.foreground
381                 L.fill_mode       = %LEG.fill_mode
382                 L.background      = %LEG.background
383                 if %LEG.clip_state=="on" then
384                     L.clip_box      = %LEG.clip_box
385                 end
386                 L.clip_state      = %LEG.clip_state
387                 L.user_data       = %LEG.user_data
388             else
389                 warning(msprintf(_("%s: Legend does not fit with the current context. Skipped\n"), "load"));
390             end
391         end
392         clearglobal %LEG
393
394     endfunction
395
396     //
397     // POLYLINE
398     //
399     function h = createPolyline(polylineProperties)
400         fields = fieldnames(polylineProperties);
401         fields(1) = [];
402
403         xpoly(polylineProperties.data(:,1), polylineProperties.data(:,2))
404
405         h = gce();
406
407         if polylineProperties.clip_state=="on" then
408             set(h, "clip_box", polylineProperties.clip_box)
409         end
410         set(h, "clip_state", polylineProperties.clip_state);
411         fields(fields=="clip_box") = [];
412         fields(fields=="clip_state") = [];
413
414         if polylineProperties.interp_color_mode=="on" & ~isempty(polylineProperties.interp_color_vector) then
415             set(h, "interp_color_vector", polylineProperties.interp_color_vector);
416             set(h, "interp_color_mode", polylineProperties.interp_color_mode);
417         else
418             if ~isempty(polylineProperties.interp_color_vector) then
419                 h.interp_color_vector = polylineProperties.interp_color_vector;
420             end
421             h.interp_color_mode = polylineProperties.interp_color_mode;
422         end
423         fields(fields=="interp_color_vector") = [];
424         fields(fields=="interp_color_mode") = [];
425
426         // Get mark_mode to be sure to set it after mark_style
427         mark_mode = polylineProperties.mark_mode;
428         fields(fields=="mark_mode") = [];
429
430         global %POLYLINE
431         %POLYLINE = h
432
433         for i = 1:size(fields, "*")
434             if fields(i) == "mark_style" then
435                 set(h, "mark_style", polylineProperties.mark_style);
436                 set(h, "mark_mode", mark_mode);
437             elseif fields(i) == "children" then
438                 createMatrixHandle(polylineProperties(fields(i)));
439             elseif fields(i) == "datatips" then
440                 createMatrixHandle(polylineProperties(fields(i)));
441             else
442                 h(fields(i)) = polylineProperties(fields(i));
443             end
444         end
445
446         clearglobal %POLYLINE
447
448     endfunction
449
450     //
451     // PLOT3D
452     //
453     function h = createPlot3d(plot3dProperties)
454         h = createSurface(plot3dProperties);
455     endfunction
456
457     //
458     // FAC3D
459     //
460     function h = createFac3d(fac3dProperties)
461         h = createSurface(fac3dProperties);
462     endfunction
463
464     //
465     // SURFACE
466     //
467     function h = createSurface(surfaceProperties)
468         fields = fieldnames(surfaceProperties);
469         fields(1) = [];
470         // plot3d modify the axes properties
471         //  - Save it
472         // - Draw plot3d
473         // - Restore it
474         a=gca();
475         rotation_angles = a.rotation_angles;
476         axes_visible = a.axes_visible;
477         box = a.box;
478         margins = a.margins;
479         x_label_visible = a.x_label.visible;
480         y_label_visible = a.y_label.visible;
481         z_label_visible = a.z_label.visible;
482         x_label_text = a.x_label.text;
483         y_label_text = a.y_label.text;
484         z_label_text = a.z_label.text;
485         axes_isoview = a.isoview;
486
487         if (or(surfaceProperties.color_flag==[2 5]) & ~or(fields=="cdata_mapping")) | ..
488             ((surfaceProperties.color_flag>=2) & or(fields=="cdata_mapping")) then
489             plot3d1(surfaceProperties.data.x, surfaceProperties.data.y, list(surfaceProperties.data.z, surfaceProperties.data.color))
490         else
491             plot3d(surfaceProperties.data.x,surfaceProperties.data.y,surfaceProperties.data.z)
492         end
493         fields(fields=="data") = [];
494
495         // Restore this properties after plot3d.
496         a.rotation_angles = rotation_angles;
497         a.axes_visible = axes_visible;
498         a.box = box;
499         a.margins = margins;
500         a.x_label.visible = x_label_visible;
501         a.y_label.visible = y_label_visible;
502         a.z_label.visible = z_label_visible;
503         a.x_label.text = x_label_text;
504         a.y_label.text = y_label_text;
505         a.z_label.text = z_label_text;
506         a.isoview = axes_isoview;
507
508         // Get mark_mode to be sure to set it after mark_style
509         mark_mode = surfaceProperties.mark_mode;
510         fields(fields=="mark_mode") = [];
511
512         h=gce();
513
514         if or(fields=="cdata_mapping") then // Fac3d specific
515             if surfaceProperties.color_flag >= 2 then
516                 set(h, "cdata_mapping", surfaceProperties.cdata_mapping);
517             end
518             fields(fields=="cdata_mapping") = [];
519         end
520
521         if surfaceProperties.clip_state == "on" then
522             set(h,"clip_box", surfaceProperties.clip_box);
523         end
524         set(h,"clip_state",surfaceProperties.clip_state);
525         fields(fields=="clip_box") = [];
526         fields(fields=="clip_state") = [];
527
528         for i = 1:size(fields, "*")
529             if fields(i) == "mark_style" then
530                 set(h, "mark_style", surfaceProperties.mark_style);
531                 set(h, "mark_mode", mark_mode);
532             else
533                 h(fields(i)) = surfaceProperties(fields(i));
534             end
535         end
536     endfunction
537
538     //
539     // COMPOUND
540     //
541     function h = createCompound(compoundProperties)
542         fields = fieldnames(compoundProperties);
543         fields(1) = [];
544
545         h = glue(createMatrixHandle(compoundProperties.children));
546         fields(fields=="children") = [];
547
548         for i = 1:size(fields, "*")
549             set(h, fields(i), compoundProperties(fields(i)));
550         end
551     endfunction
552
553     //
554     // RECTANGLE
555     //
556     function h = createRectangle(rectangleProperties)
557         fields = fieldnames(rectangleProperties);
558         fields(1) = [];
559
560         xrect(0,1,1,1); // create the rectangle with dummy values
561         h = gce();
562
563         if rectangleProperties.clip_state == "on" then
564             set(h,"clip_box", rectangleProperties.clip_box);
565         end
566         set(h,"clip_state",rectangleProperties.clip_state);
567         fields(fields=="clip_box") = [];
568         fields(fields=="clip_state") = [];
569
570         // Get mark_mode to be sure to set it after mark_style
571         mark_mode = rectangleProperties.mark_mode;
572         fields(fields=="mark_mode") = [];
573
574         for i = 1:size(fields, "*")
575             if fields(i) == "mark_style" then
576                 set(h, "mark_style", rectangleProperties.mark_style);
577                 set(h, "mark_mode", mark_mode);
578             else
579                 h(fields(i)) = rectangleProperties(fields(i));
580             end
581         end
582     endfunction
583
584     //
585     // ARC
586     //
587     function h = createArc(arcProperties)
588         fields = fieldnames(arcProperties);
589         fields(1) = [];
590
591         xarc(0,1,1,1,0,360); // create the arc with dummy values
592         h = gce();
593
594         if arcProperties.clip_state == "on" then
595             set(h,"clip_box", arcProperties.clip_box);
596         end
597         set(h,"clip_state",arcProperties.clip_state);
598         fields(fields=="clip_box") = [];
599         fields(fields=="clip_state") = [];
600
601         for i = 1:size(fields, "*")
602             set(h, fields(i), arcProperties(fields(i)));
603         end
604     endfunction
605
606     //
607     // CHAMP
608     //
609     function h = createChamp(champProperties)
610         fields = fieldnames(champProperties);
611         fields(1) = [];
612
613         champ(champProperties.data.x, champProperties.data.y, champProperties.data.fx, champProperties.data.fy);
614         fields(fields=="data") = [];
615
616         h=gce();
617
618         if champProperties.clip_state == "on" then
619             set(h,"clip_box", champProperties.clip_box);
620         end
621         set(h,"clip_state",champProperties.clip_state);
622         fields(fields=="clip_box") = [];
623         fields(fields=="clip_state") = [];
624
625         for i = 1:size(fields, "*")
626             set(h, fields(i), champProperties(fields(i)));
627         end
628     endfunction
629
630     //
631     // SEG
632     //
633     function h = createSegs(segsProperties)
634         fields = fieldnames(segsProperties);
635         fields(1) = [];
636
637         xsegs(segsProperties.data(:,1), segsProperties.data(:,2))
638
639         h=gce()
640
641         if segsProperties.clip_state == "on" then
642             set(h,"clip_box", segsProperties.clip_box);
643         end
644         set(h,"clip_state",segsProperties.clip_state);
645         fields(fields=="clip_box") = [];
646         fields(fields=="clip_state") = [];
647
648         // Get mark_mode to be sure to set it after mark_style
649         mark_mode = segsProperties.mark_mode;
650         fields(fields=="mark_mode") = [];
651
652         for i = 1:size(fields, "*")
653             if fields(i) == "mark_style" then
654                 set(h, "mark_style", segsProperties.mark_style);
655                 set(h, "mark_mode", mark_mode);
656             else
657                 h(fields(i)) = segsProperties(fields(i));
658             end
659         end
660     endfunction
661
662     //
663     // GRAYPLOT
664     //
665     function h = createGrayplot(grayplotProperties)
666         fields = fieldnames(grayplotProperties);
667         fields(1) = [];
668
669         grayplot(grayplotProperties.data.x, grayplotProperties.data.y, grayplotProperties.data.z);
670         fields(fields=="data") = [];
671
672         h = gce();
673
674         if grayplotProperties.clip_state=="on" then
675             set(h, "clip_box", grayplotProperties.clip_box)
676         end
677         set(h, "clip_state", grayplotProperties.clip_state);
678         fields(fields=="clip_box") = [];
679         fields(fields=="clip_state") = [];
680
681         for i = 1:size(fields, "*")
682             set(h, fields(i), grayplotProperties(fields(i)));
683         end
684     endfunction
685
686     //
687     // MATPLOT
688     //
689     function h = createMatplot(matplotProperties)
690         fields = fieldnames(matplotProperties);
691         fields(1) = [];
692
693         Matplot(matplotProperties.data);
694         fields(fields=="data") = [];
695
696         h = gce();
697
698         if matplotProperties.clip_state=="on" then
699             set(h, "clip_box", matplotProperties.clip_box)
700         end
701         set(h, "clip_state", matplotProperties.clip_state);
702         fields(fields=="clip_box") = [];
703         fields(fields=="clip_state") = [];
704
705         for i = 1:size(fields, "*")
706             set(h, fields(i), matplotProperties(fields(i)));
707         end
708     endfunction
709
710     //
711     // FEC
712     //
713     function h = createFec(fecProperties)
714         fields = fieldnames(fecProperties);
715         fields(1) = [];
716
717         fec(fecProperties.data(:,1), fecProperties.data(:,2), fecProperties.triangles, fecProperties.data(:,3));
718         fields(fields=="data") = [];
719         fields(fields=="triangles") = [];
720
721         h = unglue(gce());
722
723         if fecProperties.clip_state=="on" then
724             set(h, "clip_box", fecProperties.clip_box)
725         end
726         set(h, "clip_state", fecProperties.clip_state);
727         fields(fields=="clip_box") = [];
728         fields(fields=="clip_state") = [];
729
730         for i = 1:size(fields, "*")
731             set(h, fields(i), fecProperties(fields(i)));
732         end
733     endfunction
734
735     //
736     // LEGEND
737     //
738     function h = createLegend(legendProperties)
739         global %LEG
740         %LEG = legendProperties;
741         h = [];
742     endfunction
743
744     //
745     // TEXT
746     //
747     function h = createText(textProperties)
748         fields = fieldnames(textProperties);
749         fields(1) = [];
750
751         if textProperties.text_box_mode == "off" then
752             xstring(textProperties.data(1), textProperties.data(2), textProperties.text)
753         else
754             xstringb(textProperties.data(1), textProperties.data(2), textProperties.text, textProperties.text_box(1), textProperties.text_box(2))
755         end
756
757         h = gce();
758
759         if textProperties.clip_state=="on" then
760             set(h, "clip_box", textProperties.clip_box)
761         end
762         set(h, "clip_state", textProperties.clip_state);
763         fields(fields=="clip_box") = [];
764         fields(fields=="clip_state") = [];
765
766         for i = 1:size(fields, "*")
767             set(h, fields(i), textProperties(fields(i)));
768         end
769     endfunction
770
771     //
772     // DATATIP
773     //
774     function h = createDatatip(datatipProperties)
775
776         fields = fieldnames(datatipProperties)';
777         fields(1) = [];
778
779         tip_data = datatipProperties("data");
780         h = datatipCreate(%POLYLINE, tip_data);
781         for f = fields
782             if f == "data" then
783                 continue
784             end
785             v = datatipProperties(f)
786             if f == "z_component" // up to 5.5.2: http://bugzilla.scilab.org/16374
787                 if v=="on"
788                     [f, v] = ("display_components", "xyz")
789                 else
790                     continue
791                 end
792             end
793             set(h, f, v);
794         end
795     endfunction
796
797     //
798     // AXIS
799     //
800     function h = createAxis(axisProperties)
801         fields = fieldnames(axisProperties);
802         fields(1) = [];
803
804         if axisProperties.tics_direction == "bottom" then
805             axisdir="d";
806         elseif axisProperties.tics_direction == "top" then
807             axisdir="u";
808         elseif axisProperties.tics_direction == "left" then
809             axisdir="l";
810         elseif axisProperties.tics_direction == "right" then
811             axisdir="r";
812         elseif size(axisProperties.xtics_coord, "*") > 1 then
813             axisdir="u";
814         else
815             axisdir="l";
816         end
817         fields(fields=="tics_direction") = [];
818
819         drawaxis(x=axisProperties.xtics_coord,y=axisProperties.ytics_coord,dir=axisdir);
820         fields(fields=="xtics_coord") = [];
821         fields(fields=="ytics_coord") = [];
822
823         h=gce()
824
825         if axisProperties.clip_state=="on" then
826             set(h, "clip_box", axisProperties.clip_box)
827         end
828         set(h, "clip_state", axisProperties.clip_state);
829         fields(fields=="clip_box") = [];
830         fields(fields=="clip_state") = [];
831
832         for i = 1:size(fields, "*")
833             set(h, fields(i), axisProperties(fields(i)));
834         end
835     endfunction
836
837     //
838     // uimenu
839     //
840     function h = createuimenu(uimenuProperties)
841         fields = fieldnames(uimenuProperties);
842         fields(1) = [];
843
844         h = uimenu();
845
846         for i = 1:size(fields, "*")
847             if fields(i) == "children" then
848                 children = createMatrixHandle(uimenuProperties(fields(i)));
849                 for k=1:size(children, "*")
850                     set(children(k), "parent", h);
851                 end
852             else
853                 set(h, fields(i), uimenuProperties(fields(i)));
854             end
855         end
856     endfunction
857
858     //
859     // UICONTEXTMENU
860     //
861     function h = createuicontextmenu(uicontextmenuProperties)
862         fields = fieldnames(uicontextmenuProperties);
863         fields(1) = [];
864
865         h = uicontextmenu();
866
867         for i = 1:size(fields, "*")
868             if fields(i) == "children" then
869                 children = createMatrixHandle(uicontextmenuProperties(fields(i)));
870                 for k=1:size(children, "*")
871                     set(children(k), "parent", h);
872                 end
873             else
874                 set(h, fields(i), uicontextmenuProperties(fields(i)));
875             end
876         end
877     endfunction
878
879     //
880     // uicontrol
881     //
882     function h = createuicontrol(uicontrolProperties)
883         fields = fieldnames(uicontrolProperties);
884         fields(1) = [];
885
886         if or(fields=="scrollable") then
887             // Properties added in Scilab 5.5.0
888             //  - scrollable must be set at creation (for frames)
889             //  - constraints & margins must be set before parent
890             h = uicontrol("style", uicontrolProperties.style, ...
891             "scrollable", uicontrolProperties.scrollable, ...
892             "constraints", uicontrolProperties.constraints, ...
893             "margins", uicontrolProperties.margins);
894             fields(fields=="scrollable") = [];
895             fields(fields=="constraints") = [];
896             fields(fields=="margins") = [];
897             h.layout_options = uicontrolProperties.layout_options;
898             fields(fields=="layout_options") = [];
899             h.layout = uicontrolProperties.layout;
900             fields(fields=="layout") = [];
901         else
902             h = uicontrol("style", uicontrolProperties.style);
903         end
904         fields(fields=="style") = [];
905
906         for i = 1:size(fields, "*")
907             if fields(i) == "children" then
908                 children = createMatrixHandle(uicontrolProperties(fields(i)));
909                 for k=1:size(children, "*")
910                     set(children(k), "parent", h);
911                 end
912             else
913                 set(h, fields(i), uicontrolProperties(fields(i)));
914             end
915         end
916     endfunction
917
918     //
919     // LIGHT
920     //
921     function h = createLight(lightProperties)
922         fields = fieldnames(lightProperties);
923         fields(1) = [];
924
925         h = light();
926         fields(fields=="children") = [];
927
928         for i = 1:size(fields, "*")
929             set(h, fields(i), lightProperties(fields(i)));
930         end
931     endfunction
932
933     // Utility function for legends, copy/paste from %h_load
934     function links=getlinksfrompath(ax,paths)
935         //  ax is a  handle on an axes entity
936         //  paths a list or row vector which gives the set of paths relative to
937         //  the axes
938         links=[];
939         ok=%t;
940         for p=paths
941             e=ax;
942             p(1)=p(1)-1// the caption does not exist yet
943             for kp=1:size(p,"*"),
944                 if or(e.type==["Axes","Compound"])&p(kp)<=size(e.children,"*") then
945                     e=e.children(p(kp)),
946                 else
947                     ok=%f
948                     break
949                 end
950             end
951             if ~ok then
952                 break
953             end
954             links=[links,e]
955         end
956         if ~ok then
957             links=[];
958         end
959     endfunction
960
961     function macro = createMacro(macroStr, macroName)
962         macroSt = macroStr(3);
963         header = strsubst(macroSt(1), "function ", "");
964         body = macroSt(2:$-1);
965         if body == [] then
966             body = "";
967         end
968         deff(header, body);
969         execstr("macro = " + macroName);
970     endfunction
971
972     varargout = list();
973     for i = 1:size(%__varnameList__, "*")
974         varargout(i) = %__convertVariable__(evstr(%__varnameList__(i)), %__varnameList__(i));
975         //printf("add %s: type %s become %s\n", %__varnameList__(i), typeof(evstr(%__varnameList__(i))), typeof(varargout(i)));
976     end
977 endfunction