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