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