Fix load/save after https://codereview.scilab.org/#/c/15681/.
[scilab.git] / scilab / modules / graphics / macros / %h_load.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2004 - INRIA - Serge Steer
3 // Copyright (C) 2004-2006 - INRIA - Fabrice Leray
4 // Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
5 // Copyright (C) 2010 - DIGITEO - Manuel Juliachs
6 // This file must be used under the terms of the CeCILL.
7 // This source file is licensed as described in the file COPYING, which
8 // you should have received as part of this distribution.  The terms
9 // are also available at
10 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
11
12
13 function h=%h_load(fd)
14     global init_immediate_drawing
15     init_immediate_drawing = 0;
16
17     version=mget(4,"uc",fd)
18     // saving/loading character with 'c' is actually quite buggy
19     characterFormat = "uc";
20     stringFormat = "il";
21
22     immediate_drawing="";
23
24     h=[];
25
26     if is_higher_than([3 1 0 1]) then // case 3 1 0 2 and after
27         hsize = mget(2,characterFormat,fd)
28         for i=1:hsize(1)
29             for j=1:hsize(2)
30                 [htmp,immediate_drawing] = load_graphichandle(fd)
31                 h = [h htmp];
32             end
33         end
34     else
35         [h,immediate_drawing] = load_graphichandle(fd) // a single handle only can be loaded before 3 1 0 2
36     end
37     f=gcf();
38     f.immediate_drawing = immediate_drawing;
39     clearglobal init_immediate_drawing
40     clear init_immediate_drawing
41 endfunction
42
43 function [h,immediate_drawing] = load_graphichandle(fd)
44     global init_immediate_drawing
45     typ=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))
46     if typ<>"Figure"
47         f=gcf();
48         if init_immediate_drawing == 0
49             immediate_drawing = f.immediate_drawing;
50             f.immediate_drawing ="off";
51             init_immediate_drawing = 1;
52         end
53     end
54     //  mprintf('----------------------------- %s ----------------------\n',typ)
55     // Determines whether %h_load has been called by the xload macro
56     // in which case xload_mode is set to true
57     [lnums, fnames] = where();
58     ind = grep(fnames, "xload");
59     xload_mode = (ind ~= []);
60
61     select typ
62     case "Figure"
63         if xload_mode then
64             h=gcf()
65             visible=toggle(mget(1,characterFormat,fd)); // visible
66             figure_position=mget(2,"sl",fd); // figure_position
67             figure_size=mget(2,"sl",fd); // figure_size
68             axes_size=mget(2,"sl",fd); //axes_size
69             if ( is_higher_than([4 1 2 0]) ) then
70                 viewport = mget(2,"sl",fd) ; // viewport
71                 if is_higher_than([5 4 0 0]) then
72                     info_message = ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) ; // info_message
73                 else
74                     info_message = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // info_message
75                 end
76                 tag = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // tag
77             end
78             auto_resize=toggle(mget(1,characterFormat,fd)); // auto_resize
79             if is_higher_than([5 4 0 0]) then
80                 figure_name=ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) // figure_name
81             else
82                 figure_name=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // figure_name
83             end
84             figure_id=mget(1,"sl",fd); // figure_id
85             h.color_map=matrix(mget(mget(1,"il",fd),"dl",fd),-1,3) // color_map
86             if ~is_higher_than([5 4 0 1]) then
87                 pixmap=toggle(mget(1,characterFormat,fd)); // pixmap, removed from V5.5.0 on
88             end
89             pixel_drawing_mode=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // pixel_drawing_mode
90             if (is_higher_than([5 1 0 0])) then
91                 anti_aliasing=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // anti_aliasing
92             end
93             immediate_drawing=toggle(mget(1,characterFormat,fd));// immediate drawing // init. global variable immediate_drawing
94             h.immediate_drawing = "off";  // set it to 'off' to pass useless redraw due to several 'set' calls
95             h.background=mget(1,"il",fd) // background
96             rotation_style=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // rotation_style
97         else
98             visible=toggle(mget(1,characterFormat,fd)); // visible
99             figure_position=mget(2,"sl",fd); // figure_position
100             // if figure is iconified in old scilab version, its position is -32000, -32000]
101             figure_position = max(figure_position, [0,0]);
102             figure_size=mget(2,"sl",fd); // figure_size
103             axes_size=mget(2,"sl",fd); // axes_size
104             if ( is_higher_than([4 1 2 0]) ) then
105                 viewport = mget(2,"sl",fd) ; // viewport
106                 if is_higher_than([5 4 0 0]) then
107                     info_message = ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) ; // info_message
108                 else
109                     info_message = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // info_message
110                 end
111                 tag = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // tag
112             end
113             auto_resize=toggle(mget(1,characterFormat,fd)); // auto_resize
114             if is_higher_than([5 4 0 0]) then
115                 figure_name=ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) // figure_name
116             else
117                 figure_name=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // figure_name
118             end
119             figure_id=mget(1,"sl",fd); // figure_id
120             // create the figure
121             h=scf(figure_id);
122             h.visible=visible;  // can be set now as we act on immediate_drawing everywhere else F.Leray 18.02.05
123             h.figure_position=figure_position
124             // set auto_resize first otherwise viewport modification may not have any effect.
125             h.auto_resize = auto_resize;
126             h.figure_size = figure_size;
127             // set axes_size last because it's more important than figure_size
128             h.axes_size = axes_size;
129
130             if ( is_higher_than([4 1 2 0]) ) then
131                 h.viewport = viewport;
132                 h.info_message = info_message ;
133                 h.tag = tag ;
134             end
135             h.figure_name=figure_name
136             h.color_map=matrix(mget(mget(1,"il",fd),"dl",fd),-1,3) // color_map
137             if ~is_higher_than([5 4 0 1]) then
138                 pixmap=toggle(mget(1,characterFormat,fd)); // pixmap, removed from V5.5.0 on
139             end
140             h.pixel_drawing_mode=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // pixel_drawing_mode
141             if (is_higher_than([5 1 0 0])) then
142                 h.anti_aliasing=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // anti_aliasing
143             end
144             immediate_drawing=toggle(mget(1,characterFormat,fd)); // immediate_drawing  // init. global variable immediate_drawing
145             h.immediate_drawing = "off"; // set it to 'off' to pass useless redraw due to several 'set' calls
146             h.background=mget(1,"il",fd); // background
147             h.rotation_style = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // rotation_style
148
149         end
150
151         if ( is_higher_than([4 1 2 0]) ) then
152             h.event_handler = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // event_handler
153             h.event_handler_enable = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // event_handler_enable
154         end
155
156         if ( is_higher_than([5 2 0 0]) ) then // Added in 5.4.0 version
157             h.resizefcn = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // resizefcn
158             h.closerequestfcn = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // closerequestfcn
159         end
160
161         // children
162         n_axes=mget(1,"il",fd);
163         if n_axes==1 then
164             load_graphichandle(fd)
165         else
166             load_graphichandle(fd);
167             for k=2:n_axes
168                 xsetech(wrect=[0 0 .1 .1])
169                 load_graphichandle(fd)
170             end
171         end
172         load_user_data(fd); // user_data
173     case "Axes"
174         // Hack to determine whether %h_load has been called by the %h_copy macro
175         // in which case a new Axes object is created
176         [lnums, fnames]=where();
177         ind=grep(fnames, "%h_copy");
178
179         if(ind<>[]) then
180             newaxes();
181         end;
182
183         a=gca() ;
184         titl=a.title ;
185         x_label=a.x_label ;
186         y_label=a.y_label ;
187         set(a,"visible"              , toggle(mget(1,characterFormat,fd))) // visible
188         if and(version==[3 0 0 0]) then // axes_visible
189             axes_visible= toggle(mget(1,characterFormat,fd));
190             axes_visible=emptystr(1,3)+axes_visible
191         else
192             axes_visible= toggle(mget(mget(1,characterFormat,fd),characterFormat,fd)) ;
193         end
194
195         if is_higher_than( [3 1 0 1] ) then // axes_reverse
196             axes_reverse = toggle(mget(mget(1,characterFormat,fd),characterFormat,fd)) ;
197         end
198
199         set(a,"axes_visible", axes_visible)
200         set(a,"axes_reverse", axes_reverse)
201         set(a,"grid"        , mget(mget(1,characterFormat,fd),"il",fd)) //grid
202         if (is_higher_than([5 0 3 0])) then
203             set(a,"grid_position",ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))); // grid_position
204         else
205             set(a,"grid_position","background"); // grid_position
206         end
207         set(a,"x_location"  , ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))) // x_location
208         set(a,"y_location"  , ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))) // y_location
209
210         view            =  ascii(mget(2,characterFormat,fd)); // view
211
212         // title
213         set(titl,"visible"   , toggle(mget(1,characterFormat,fd))) // title.visible
214         if is_higher_than( [4 1 2 0] ) then
215             set(titl, "text", load_text_matrix( fd ) ) ;
216         else
217             set(titl,"text"      , ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))) // title.text
218         end
219         if is_higher_than([4 1 2 0]) then
220             set(titl,"font_foreground", mget(1,"il",fd)); // title.font_foreground
221             set(titl,"fractional_font", toggle(mget(1,characterFormat,fd))); //title.fractional_font
222         end
223         set(titl,"foreground", mget(1,"il",fd)); // title.foreground
224         if is_higher_than([3 1 0 0]) then
225             set(titl,"background"       , mget(1,"il",fd)); // title.background
226             set(titl,"fill_mode"        , toggle(mget(1,characterFormat,fd))); //title.fill_mode
227         end
228
229         set(titl,"font_style"       , mget(1,characterFormat,fd)); // title.font_style
230         set(titl,"font_size"        , mget(1,characterFormat,fd)); // title.font_size
231
232         if is_higher_than([3 1 0 0]) then
233             auto_rotation =  toggle(mget(1,characterFormat,fd)) ; // title.auto_rotation
234             set(titl,"font_angle"   , mget(1,"dl",fd)); // title.font_angle
235             auto_position = toggle(mget(1,characterFormat,fd)) ;  // title.auto_position
236             set(titl,"position"     , mget(2,"dl",fd)); // title.position
237             set( titl, "auto_rotation", auto_rotation ) ;
238             set( titl, "auto_position", auto_position ) ;
239         end
240
241         // x_label
242         set(x_label,"visible"   , toggle(mget(1,characterFormat,fd))) // x_label.visible
243         if is_higher_than( [4 1 2 0] ) then
244             set(x_label, "text", load_text_matrix( fd ) ) ;
245         else
246             set(x_label,"text"      , ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))) // title.text
247         end
248         if is_higher_than([4 1 2 0]) then
249             set(x_label,"font_foreground", mget(1,"il",fd)); // x_label.font_foreground
250             set(x_label,"fractional_font", toggle(mget(1,characterFormat,fd))); //x_label.fractional_font
251         end
252         set(x_label,"foreground", mget(1,"il",fd)); // x_label.foreground
253         if is_higher_than([3 0 0 0]) then
254             set(x_label,"background"       , mget(1,"il",fd)); // x_label.background
255             set(x_label,"fill_mode"        , toggle(mget(1,characterFormat,fd))); // x_label.fill_mode
256         end
257         set(x_label,"font_style"     , mget(1,characterFormat,fd)); // x_label.font_style
258         set(x_label,"font_size"      , mget(1,characterFormat,fd)); // x_label.font_size
259
260         if is_higher_than([3 0 0 0]) then
261             auto_rotation =  toggle(mget(1,characterFormat,fd)) ; // x_label.auto_rotation
262             set(x_label,"font_angle"   , mget(1,"dl",fd)); // x_label.font_angle
263             auto_position = toggle(mget(1,characterFormat,fd)) ; // x_label.auto_position
264             set( x_label,"position"     , mget(2,"dl",fd)); // x_label.position
265             set( x_label, "auto_rotation", auto_rotation ) ;
266             set( x_label, "auto_position", auto_position ) ;
267         end
268
269         // y_label
270         set(y_label,"visible"        , toggle(mget(1,characterFormat,fd)))
271         if is_higher_than( [4 1 2 0] ) then
272             set(y_label, "text", load_text_matrix( fd ) ) ;
273         else
274             set(y_label,"text"      , ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))) // title.text
275         end
276         if is_higher_than([4 1 2 0]) then
277             set(y_label,"font_foreground", mget(1,"il",fd)); // y_label.font_foreground
278             set(y_label,"fractional_font", toggle(mget(1,characterFormat,fd))); //y_label.fractional_font
279         end
280         set(y_label,"foreground"     , mget(1,"il",fd));
281         if is_higher_than([3 0 0 0]) then
282             set(y_label,"background"       , mget(1,"il",fd));
283             set(y_label,"fill_mode"        , toggle(mget(1,characterFormat,fd)));
284         end
285         set(y_label,"font_style"     , mget(1,characterFormat,fd));
286         set(y_label,"font_size"      , mget(1,characterFormat,fd));
287
288         if is_higher_than([3 0 0 0]) then
289             auto_rotation =  toggle(mget(1,characterFormat,fd)) ; // y_label.auto_rotation
290             set(y_label,"font_angle"   , mget(1,"dl",fd)); // y_label.font_angle
291             auto_position = toggle(mget(1,characterFormat,fd)) ; // y_label.auto_position
292             set( y_label,"position"     , mget(2,"dl",fd)); // y_label.position
293             set( y_label, "auto_rotation", auto_rotation ) ;
294             set( y_label, "auto_position", auto_position ) ;
295         end
296
297         if view=="3d" then
298             // z_label
299             z_label=a.z_label
300             set(z_label,"visible"        , toggle(mget(1,characterFormat,fd)))
301             if is_higher_than( [4 1 2 0] ) then
302                 set(z_label, "text", load_text_matrix( fd ) ) ;
303             else
304                 set(z_label,"text"      , ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))) // title.text
305             end
306             if is_higher_than([4 1 2 0]) then
307                 set(z_label,"font_foreground", mget(1,"il",fd)); // z_label.font_foreground
308                 set(z_label,"fractional_font", toggle(mget(1,characterFormat,fd))); //z_label.fractional_font
309             end
310             set(z_label,"foreground"     , mget(1,"il",fd));
311             if is_higher_than([3 0 0 0]) then
312                 set(z_label,"background"       , mget(1,"il",fd));
313                 set(z_label,"fill_mode"        , toggle(mget(1,characterFormat,fd)));
314             end
315             set(z_label,"font_style"     , mget(1,characterFormat,fd));
316             set(z_label,"font_size"      , mget(1,characterFormat,fd));
317
318             if is_higher_than([3 0 0 0]) then
319                 auto_rotation =  toggle(mget(1,characterFormat,fd)) ; // z_label.auto_rotation
320                 set(z_label,"font_angle"   , mget(1,"dl",fd)); // z_label.font_angle
321                 auto_position = toggle(mget(1,characterFormat,fd)) ; // z_label.auto_position
322                 set( z_label,"position"     , mget(2,"dl",fd)); // z_label.position
323                 set( z_label, "auto_rotation", auto_rotation ) ;
324                 set( z_label, "auto_position", auto_position ) ;
325             end
326         end
327
328
329         if is_higher_than([5 4 0 1]) then
330             auto_ticks=toggle(mget(mget(1,characterFormat,fd),characterFormat,fd)); // auto_ticks
331         end
332
333         if is_higher_than([3 0 0 0]) then
334
335             ticks=["ticks","locations","labels"]
336             sz=mget(1,"sl",fd) // x_ticks.locations
337             if sz>0 then
338                 x_ticks_locations=mget(sz,"dl",fd)'
339                 lz=mget(sz,characterFormat,fd) // x_ticks.label
340                 x_ticks_labels=[];for ks=1:sz,x_ticks_labels(ks)=ascii(mget(lz(ks),characterFormat,fd));end
341                 set(a,"x_ticks",tlist(ticks,x_ticks_locations,x_ticks_labels))
342             end
343
344             sz=mget(1,"sl",fd) // y_ticks.locations
345             if sz>0 then
346                 y_ticks_locations=mget(sz,"dl",fd)'
347                 lz=mget(sz,characterFormat,fd) // y_ticks.label
348                 y_ticks_labels=[];for ks=1:sz,y_ticks_labels(ks)=ascii(mget(lz(ks),characterFormat,fd));end
349                 set(a,"y_ticks",tlist(ticks,y_ticks_locations,y_ticks_labels))
350             end
351
352             sz=mget(1,"sl",fd) // z_ticks.locations
353             if sz>0 then
354                 z_ticks_locations=mget(sz,"dl",fd)'
355                 lz=mget(sz,characterFormat,fd) // z_ticks.labels
356                 z_ticks_labels=[];for ks=1:sz,z_ticks_labels(ks)=ascii(mget(lz(ks),characterFormat,fd));end
357                 set(a,"z_ticks",tlist(ticks,z_ticks_locations,z_ticks_labels))
358             end
359             set(a,"auto_ticks"           , auto_ticks)
360         end
361         if is_higher_than([4 1 2 0]) then
362             // migth be now 'off','hidden_axis','back_half' or 'on'
363             boxtype = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ;
364             set( a, "box", boxtype  ) // box
365             set(a,"filled",  toggle(mget(1,characterFormat,fd) )); // filled
366         else
367             set(a, "box", toggle(mget(1,characterFormat,fd) ) ) // box
368         end
369
370         set(a,"sub_tics"             , mget(mget(1,characterFormat,fd),characterFormat,fd)) // sub_tics
371         if ~(is_higher_than([3 1 0 1]) ) then
372             mget(1,"il",fd); // tics_color is removed F.Leray 15.03.05
373         end
374         set(a,"font_style"           , mget(1,characterFormat,fd));  // font_style
375         set(a,"font_size"            , mget(1,characterFormat,fd));  // font_size
376         set(a,"font_color"           , mget(1,"il",fd)); // font_color
377         if is_higher_than([4 1 2 0]) then
378             set(a,"fractional_font", toggle(mget(1,characterFormat,fd))); // fractional_font
379         end
380         set(a,"isoview"              , toggle(mget(1,characterFormat,fd))) // isoview
381
382         cube_scaling    = toggle(mget(1,characterFormat,fd)) // cube_scaling
383         rotation_angles = mget(2,"dl",fd); // rotation_angles
384
385         if a.view=="2d" then
386             set(a,"view"               , view);
387         end
388         if a.view=="3d" then
389             set(a,"cube_scaling"      , cube_scaling)
390             if view=="3d" then
391                 set(a,"rotation_angles"   , rotation_angles)
392             end
393         end
394
395         if is_higher_than([3 0 0 0]) then // log_flags
396             log_flags= ascii(mget(3,characterFormat,fd));
397         else
398             log_flags= ascii(mget(2,characterFormat,fd));
399         end
400
401         // tight_limits
402         if is_higher_than([5 5 0 0]) then
403             tight_limits=toggle(mget(mget(1,characterFormat,fd),characterFormat,fd));
404         else
405             tight_limits=toggle(mget(1,characterFormat,fd));
406         end
407         set(a,"tight_limits",tight_limits);
408         data_bounds = matrix(mget(mget(1,characterFormat,fd),"dl",fd),2,-1) // data_bounds
409
410
411         if view=="2d"& a.view=="3d" then
412             data_bounds(2,3)=0;
413         end
414         if xload_mode
415             // check if a had at least a child previously
416             // if not the axes is considered unused
417             // and we don't merge the data_bounds.
418             if a.children <> []  then
419                 old_bounds=a.data_bounds;
420                 for k=1:size(old_bounds,2)
421                     data_bounds(1,k)=min(data_bounds(1,k),old_bounds(1,k));
422                     data_bounds(2,k)=max(data_bounds(2,k),old_bounds(2,k));
423                 end
424             end
425         end
426         if is_higher_than([3 0 0 0]) then
427             zoom_box_size = mget(1,characterFormat,fd);
428             if zoom_box_size<>0 then
429                 set(a,"zoom_box"          , mget(zoom_box_size,"dl",fd))  // zoom_box
430             end
431         end
432         if is_higher_than([3 1 0 1]) then
433             set(a,"margins"              , mget(4,"dl",fd))  // margins
434         end
435
436         set(a,"axes_bounds"          , mget(4,"dl",fd))  // axes_bounds
437         set(a,"auto_clear"           , toggle(mget(1,characterFormat,fd))) // auto_clear
438         set(a,"auto_scale"           , toggle(mget(1,characterFormat,fd))) // auto_scale
439
440         if is_higher_than([4 1 2 0] ) then // 4 0 0 0 and after
441             set(a,"hidden_axis_color", mget(1,"il",fd)) ; // hidden_axis_color
442             set(a, "arc_drawing_method", ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))); // arc_drawing_method
443         else
444             set(a, "arc_drawing_method", "nurbs"); // default value, real circle
445         end
446
447         set(a,"hiddencolor"          , mget(1,"il",fd)), // hidden_color
448         set(a,"line_mode"            , toggle(mget(1,characterFormat,fd))), // line_mode
449         line_style = mget(1,characterFormat,fd);
450         if line_style==0 then // 0 and 1 are equivalents and 0 is obsolete since Scilab 5.4.0
451             line_style=1;
452         end
453         set(a,"line_style"           , line_style) // line_style
454         set(a,"thickness"            , mget(1,"sl",fd)), // thickness
455         set(a,"mark_mode"            , toggle(mget(1,characterFormat,fd))), //mark_mode
456         set(a,"mark_style"           , mget(1,characterFormat,fd)) // mark_style
457         set(a,"mark_size"            , mget(1,characterFormat,fd)) // mark_size
458         if is_higher_than([3 0 0 0]) then
459
460             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
461                 msu="tabulated" ;
462             else
463                 msu="point";
464             end
465
466             set(a,"mark_size_unit"   , msu)
467             set(a,"mark_foreground"      , mget(1,"il",fd)) ; // mark_foreground
468             set(a,"mark_background"      , mget(1,"il",fd)) ; // mark_background
469         else
470             set(a,"mark_size_unit"     , "tabulated")
471         end
472         set(a,"foreground"           , mget(1,"il",fd)), // foreground
473         set(a,"background"           , mget(1,"il",fd)), // background
474         clip_state                   = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
475         if clip_state=="on" then // clip_box
476             set(a,"clip_box",mget(4,"dl",fd)) ;
477         end
478         set(a,"clip_state"           ,clip_state);
479
480         // children
481         nbChildren = mget(1,"il",fd) ;
482         for k = 1 : nbChildren
483             load_graphichandle(fd) ;
484         end
485         //next lines because tools used to rebuild children change the
486         //data_bounds an axes_visible properties
487         set(a,"data_bounds"          , data_bounds) ;
488         set(a,"log_flags"            , log_flags);
489
490         set(a,"axes_visible"          , axes_visible) ;
491         if is_higher_than([4 1 2 0] ) then
492             set(a, "box", boxtype ) ;
493         end
494
495         h=a;
496         load_user_data(fd) ; // user_data
497         global %LEG
498
499         if %LEG<>[] then
500             //get handles from paths
501             links=get_links_from_path(a,%LEG.paths)
502             if links<>[] then
503                 L=captions(links,%LEG.text)
504                 L.visible         = %LEG.visible
505                 L.font_style      = %LEG.font_style
506                 L.font_size       = %LEG.font_size
507                 L.font_color      = %LEG.font_color
508                 L.fractional_font = %LEG.fractional_font
509                 L.mark_mode       = "off";
510                 L.legend_location = %LEG.legend_location
511                 L.position        = %LEG.position
512                 L.line_mode       = %LEG.line_mode
513                 L.thickness       = %LEG.thickness
514                 L.foreground      = %LEG.foreground
515                 L.fill_mode       = %LEG.fill_mode
516                 L.background      = %LEG.background
517                 L.clip_state      = %LEG.clip_state
518                 if %LEG.clip_state=="on" then
519                     L.clip_box      = %LEG.clip_box
520                 end
521                 L.user_data       = %LEG.user_data
522             else
523                 warning(msprintf(_("%s: Legend does not fit with the current context. Skipped\n"),"load"));
524             end
525         end
526         clearglobal %LEG
527
528     case "Polyline"
529
530         visible=toggle(mget(1,characterFormat,fd)) // visible
531         sz=mget(2,"il",fd); // data
532         data=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
533         if is_higher_than([3 1 0 0]) then
534             closed      = toggle(mget(1,characterFormat,fd)) // closed
535         end
536         line_mode      = toggle(mget(1,characterFormat,fd)) // line_mode
537         if is_higher_than([3 1 0 0]) then
538             fill_mode      = toggle(mget(1,characterFormat,fd)) // fill_mode
539         end
540         line_style     = mget(1,characterFormat,fd); // line_style
541         if line_style==0 then // 0 and 1 are equivalents and 0 is obsolete since Scilab 5.4.0
542             line_style=1;
543         end
544         thickness      = mget(1,"sl",fd); // thickness
545         if is_higher_than([3 1 0 1]) then
546             arrow_size_factor = mget(1,"sl",fd); // arrow_size_factor
547         end
548         polyline_style = mget(1,characterFormat,fd); // polyline_style
549
550         if is_higher_than([3 1 0 1] ) then
551             size_interp_color = mget(1,"sl",fd) ; // interp_color_vector
552             interp_color_vector = mget( size_interp_color, "dl", fd ) ;
553             interp_color_mode   = toggle( mget( 1, characterFormat, fd ) ) ; // interp_color_mode
554         end
555
556         mark_mode      = toggle(mget(1,characterFormat,fd)) // mark_mode
557         mark_style     = mget(1,characterFormat,fd); // mark_style
558         mark_size      = mget(1,characterFormat,fd); // mark_size
559
560         msu="tabulated"
561         if is_higher_than([3 0 0 0]) then
562             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
563                 msu="tabulated" ;
564             else
565                 msu="point";
566             end
567         end
568
569         foreground     = mget(1,"il",fd); // foreground
570
571         if is_higher_than([3 1 0 0]) then
572             background     = mget(1,"il",fd); // background
573         end
574
575         if is_higher_than([3 0 0 0]) then
576             mark_foreground=mget(1,"il",fd) // mark_foreground
577             mark_background=mget(1,"il",fd) // mark_background
578         end
579
580         if is_higher_than([5 4 0 1]) then
581             mark_offset=mget(1,"il",fd) // mark_offset
582             mark_stride=mget(1,"il",fd) // mark_stride
583         end
584
585         if is_higher_than([3 1 0 0]) then
586             sz_x_shift=mget(1,"sl",fd) // x_shift
587             x_shift=mget(sz_x_shift,"dl",fd)'
588
589             sz_y_shift=mget(1,"sl",fd) // y_shift
590             y_shift=mget(sz_y_shift,"dl",fd)'
591
592             sz_z_shift=mget(1,"sl",fd) // z_shift
593             z_shift=mget(sz_z_shift,"dl",fd)'
594         end
595
596         if is_higher_than([3 1 0 1]) then
597             bar_width = mget( 1, "dl", fd ) ; // bar_width
598         end
599
600         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
601
602         if clip_state=="on" then
603             clip_box     = mget(4,"dl",fd) ; // clip_box
604         else
605             clip_box = [] ;
606         end
607         // draw the polyline and set properties
608         xpoly(data(:,1),data(:,2))
609         //plot2d( data(:,1),data(:,2));
610         h=get("hdl")
611         set(h,"data",data)
612         set(h,"visible",visible)
613         set(h,"line_mode",line_mode),
614         set(h,"line_style",line_style)
615         set(h,"thickness",thickness)
616         set(h,"arrow_size_factor",arrow_size_factor);
617         set(h,"polyline_style",max(1,polyline_style)),
618         set(h,"mark_style",mark_style),
619         set(h,"mark_size",mark_size),
620         set(h,"mark_mode",mark_mode),
621         set(h,"foreground",foreground),
622         if is_higher_than([3 0 0 0]) then
623             set(h,"mark_size_unit",msu)
624             set(h,"mark_foreground",mark_foreground),
625             set(h,"mark_background",mark_background)
626         end
627         if is_higher_than([5 5 0 1]) then
628             set(h,"mark_offset",mark_offset)
629             set(h,"mark_stride",mark_stride)
630         end
631         if is_higher_than([3 1 0 0]) then
632             set(h,"background",background)
633             set(h,"fill_mode",fill_mode)
634             set(h,"closed",closed);
635             set(h,"x_shift",x_shift);
636             set(h,"y_shift",y_shift);
637             set(h,"z_shift",z_shift);
638         end
639
640         if is_higher_than([3 1 0 1]) then
641             if interp_color_mode == "on" & interp_color_vector~=[] then
642                 set(h,"interp_color_vector",interp_color_vector);
643                 set(h,"interp_color_mode","on");
644             else
645                 if interp_color_vector~=[]
646                     h.interp_color_vector = interp_color_vector
647                 end
648                 h.interp_color_mode = interp_color_mode
649             end
650             set(h,"bar_width",bar_width);
651         end
652
653         if clip_state =="" then clip_state="clipgrf",end
654         if clip_state=="on" then set(h,"clip_box",clip_box),end
655         set(h,"clip_state",clip_state);
656
657         load_user_data(fd) // user_data
658
659     case "Datatip"
660         if is_higher_than([5 4 0 1]) then
661             visible=toggle(mget(1,characterFormat,fd)) // visible
662             sz = mget(2,characterFormat,fd)
663             tip_data = matrix(mget(prod(sz),"dl",fd),sz(1),-1) // data
664             tip_box_mode = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // box_mode
665             tip_label_mode = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // label_mode
666             tip_orientation = mget(1,characterFormat,fd); // orientation
667             tip_3component = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // z_component
668             tip_auto_orientation = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // auto_orientation
669             tip_interp_mode = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // interp_mode
670             tip_disp_function = load_text_matrix(fd); // display_function
671             mark_mode = toggle(mget(1,characterFormat,fd)) // mark_mode
672             mark_style = mget(1,characterFormat,fd); // mark_style
673             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
674                 msu="tabulated"
675             else
676                 msu="point";
677             end
678             mark_size = mget(1,characterFormat,fd); // mark_size
679             mark_foreground=mget(1,"il",fd) // mark_foreground
680             mark_background=mget(1,"il",fd) // mark_background
681             tag = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // tag
682
683             h=get("hdl");
684             set(h, "font_foreground", mget(1, "il", fd)); // font_foreground
685             set(h,"foreground", mget(1,"il",fd)); // foreground
686             set(h, "background", mget(1, "il", fd)); // background
687             set(h,"mark_mode",mark_mode); // mark_mode
688             set(h,"mark_style",mark_style); // mark_style
689             set(h,"mark_size_unit",msu) // mark_size_unit
690             set(h,"mark_size",mark_size) // mark_size
691             set(h,"mark_foreground",mark_foreground) // mark_foreground
692             set(h,"mark_background",mark_background) // mark_background
693
694             load_user_data(fd) // user_data
695         end
696
697     case "Plot3d" then
698         visible=toggle(mget(1,characterFormat,fd)) // visible
699         surface_mode   = toggle(mget(1,characterFormat,fd)) // surface_mode
700         foreground     = mget(1,"il",fd); // foreground
701         thickness      = mget(1,"sl",fd); // thickness
702         mark_mode      = toggle(mget(1,characterFormat,fd)) // mark_mode
703         mark_style     = mget(1,characterFormat,fd); // mark_style
704         mark_size      = mget(1,characterFormat,fd); // mark_size
705
706         if is_higher_than([3 0 0 0]) then
707             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
708                 msu="tabulated" ;
709             else
710                 msu="point";
711             end
712             mark_foreground=mget(1,"il",fd) // mark_foreground
713             mark_background=mget(1,"il",fd) // mark_background
714         else
715             msu="tabulated"
716         end
717
718         if is_higher_than([5 1 1 0]) then
719             color_mode     = mget(1,"il",fd); // color_mode
720             color_flag     = mget(1,"il",fd); // color_flag
721         else
722             color_mode     = mget(1,characterFormat,fd);
723             color_flag     = mget(1,characterFormat,fd);
724         end
725
726         sz=mget(2,"il",fd); // data.x
727         x=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
728         sz=mget(2,"il",fd); // data.y
729         y=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
730         sz=mget(2,"il",fd); // data.z
731         z=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
732
733         if or(color_flag==[2,5]) then
734             sz=mget(2,"il",fd); // data.color
735             clr=matrix(mget(prod(sz),"il",fd),sz(1),-1);
736         end
737         hiddencolor    = mget(1,"il",fd); // hidden_color
738
739         // plot3d modify the given rotation angles
740         // trick to force keeping the good rotation angles F.Leray 18.02.05
741         // same issue with axes properties... B.Jofret 21.04.09
742         a=gca();
743         rotation_angles = a.rotation_angles;
744         axes_visible = a.axes_visible;
745         box = a.box;
746         margins = a.margins;
747         x_label_visible = a.x_label.visible;
748         y_label_visible = a.y_label.visible;
749         z_label_visible = a.z_label.visible;
750         x_label_text = a.x_label.text;
751         y_label_text = a.y_label.text;
752         z_label_text = a.z_label.text;
753         axes_isoview = a.isoview;
754
755
756         if or(color_flag==[2 5]) then
757             plot3d1(x,y,list(z,clr))
758         else
759             plot3d(x,y,z)
760         end
761
762         // Restore this properties after plot3d.
763         a.rotation_angles = rotation_angles;
764         a.axes_visible = axes_visible;
765         a.box = box;
766         a.margins = margins;
767         a.x_label.visible = x_label_visible;
768         a.y_label.visible = y_label_visible;
769         a.z_label.visible = z_label_visible;
770         a.x_label.text = x_label_text;
771         a.y_label.text = y_label_text;
772         a.z_label.text = z_label_text;
773         a.isoview = axes_isoview;
774
775
776         h=gce();
777         set(h,"visible",visible)
778         set(h,"surface_mode",surface_mode)
779         set(h,"thickness",thickness)
780         set(h,"foreground",foreground),
781         set(h,"color_mode",color_mode),
782         set(h,"mark_style",mark_style),
783         set(h,"mark_size",mark_size),
784         if is_higher_than([3 0 0 0]) then
785             set(h,"mark_size_unit",msu),
786             set(h,"mark_foreground",mark_foreground),
787             set(h,"mark_background",mark_background)
788         end
789         set(h,"mark_mode",mark_mode)
790         set(h,"color_flag",color_flag),
791         set(h,"hiddencolor",hiddencolor),
792
793         if is_higher_than([4 1 2 0])
794             clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
795             if clip_state=="on" then
796                 set(h,"clip_box", mget(4,"dl",fd)) // clip_box
797             end
798             set(h,"clip_state",clip_state);
799         end
800
801         load_user_data(fd)
802
803     case "Fac3d" then
804
805         visible=toggle(mget(1,characterFormat,fd)) // visible
806         surface_mode   = toggle(mget(1,characterFormat,fd)) // surface_mode
807         foreground     = mget(1,"il",fd); // foreground
808         thickness      = mget(1,"sl",fd); // thickness
809         mark_mode      = toggle(mget(1,characterFormat,fd)) // mark_mode
810         mark_style     = mget(1,characterFormat,fd); // mark_style
811         mark_size      = mget(1,characterFormat,fd); // mark_size
812         if is_higher_than([3 0 0 0]) then
813             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
814                 msu="tabulated";
815             else
816                 msu="point";
817             end
818             mark_foreground=mget(1,"il",fd) ; // mark_foreground
819             mark_background=mget(1,"il",fd) ; // mark_background
820         end
821         if is_higher_than([5 1 1 0]) then
822             color_mode     = mget(1,"il",fd); // color_mode
823             color_flag     = mget(1,"il",fd); // color_flag
824         else
825             color_mode     = mget(1,characterFormat,fd);
826             color_flag     = mget(1,characterFormat,fd);
827         end
828
829         sz=mget(2,"il",fd); // data.x
830         x=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
831         sz=mget(2,"il",fd); // data.y
832         y=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
833         sz=mget(2,"il",fd); // data.z
834         z=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
835
836         if is_higher_than([3 1 0 1]) & color_flag >= 2 then
837             sz=mget(2,"il",fd); // data.z
838             clr=matrix(mget(prod(sz),"il",fd),sz(1),-1);
839
840             if ascii(mget(1,characterFormat,fd)) == "s" then // cdata_mapping
841                 cdata_mapping = "scaled" ;
842             else
843                 cdata_mapping = "direct"  ;
844             end
845
846         elseif or(color_flag==[2 5]) then
847             // compatibility with old version
848             sz=mget(2,"il",fd); // data.z
849             clr=matrix(mget(prod(sz),"il",fd),sz(1),-1);
850         end
851         hiddencolor    = mget(1,"il",fd); // hiddencolor
852
853         // plot3d modify the given rotation angles
854         // trick to force keeping the good rotation angles F.Leray 18.02.05
855         // same issue with axes properties... B.Jofret 21.04.09
856         // and labels text and isoview
857         a=gca();
858         rotation_angles = a.rotation_angles;
859         axes_visible = a.axes_visible;
860         box = a.box;
861         margins = a.margins;
862         x_label_visible = a.x_label.visible;
863         y_label_visible = a.y_label.visible;
864         z_label_visible = a.z_label.visible;
865         x_label_text = a.x_label.text;
866         y_label_text = a.y_label.text;
867         z_label_text = a.z_label.text;
868         axes_isoview = a.isoview;
869
870         if is_higher_than([3 1 0 1]) & color_flag >= 2 then
871             plot3d1(x,y,list(z,clr))
872         elseif or(color_flag==[2 5]) then
873             plot3d1(x,y,list(z,clr))
874         else
875             plot3d(x,y,z)
876         end
877
878         // Restore this properties after plot3d.
879         a.rotation_angles = rotation_angles;
880         a.axes_visible = axes_visible;
881         a.box = box;
882         a.margins = margins;
883         a.x_label.visible = x_label_visible;
884         a.y_label.visible = y_label_visible;
885         a.z_label.visible = z_label_visible;
886         a.x_label.text = x_label_text;
887         a.y_label.text = y_label_text;
888         a.z_label.text = z_label_text;
889         a.isoview = axes_isoview;
890
891         h=gce();
892         set(h,"visible",visible)
893         set(h,"surface_mode",surface_mode)
894         set(h,"thickness",thickness)
895         set(h,"foreground",foreground),
896         set(h,"color_mode",color_mode),
897         set(h,"color_flag",color_flag),
898         set(h,"hiddencolor",hiddencolor),
899         set(h,"mark_style",mark_style),
900         set(h,"mark_size",mark_size),
901         set(h,"mark_mode",mark_mode)
902         if is_higher_than([3 0 0 0]) then
903             set(h,"mark_size_unit",msu),
904             set(h,"mark_foreground",mark_foreground),
905             set(h,"mark_background",mark_background)
906         end
907
908         if is_higher_than([3 1 0 1]) & color_flag >= 2 then
909             set(h,"cdata_mapping",cdata_mapping);
910         end
911
912         if is_higher_than([4 1 2 0])
913             clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
914             if clip_state=="on" then
915                 set(h,"clip_box", mget(4,"dl",fd)) // clip_box
916             end
917             set(h,"clip_state",clip_state);
918         end
919
920         load_user_data(fd) ; // user_data
921
922     case "Compound"
923         // children
924         n=mget(1,"il",fd)
925         H=[]
926         for k=1:n
927             htmp = load_graphichandle(fd)
928             H=[htmp H]
929         end
930         h=glue(H)
931         if is_higher_than([3 1 0 1]) then // visible
932             h.visible = toggle(mget(1,characterFormat,fd)) ;
933         end
934
935         load_user_data(fd) // user_data
936
937
938     case "Agregation" // for compatibility with old save
939
940         // children
941         n=mget(1,"il",fd)
942         H=[]
943         for k=1:n
944             htmp = load_graphichandle(fd)
945             H=[htmp H]
946         end
947         h=glue(H)
948
949         if is_higher_than([3 1 0 1]) then // visible
950             h.visible = toggle(mget(1,characterFormat,fd)) ;
951         end
952
953         load_user_data(fd) // user_data
954
955     case "Rectangle"
956         visible        = toggle(mget(1,characterFormat,fd)) // visible
957         thickness      = mget(1,"sl",fd); // thickness
958         mark_mode      = toggle(mget(1,characterFormat,fd)) // mark_mode
959         mark_style     = mget(1,characterFormat,fd); // mark_style
960         mark_size      = mget(1,characterFormat,fd); // mark_size
961         if is_higher_than([3 0 0 0]) then
962             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
963                 msu="tabulated" ;
964             else
965                 msu="point";
966             end
967             mark_foreground=mget(1,"il",fd) // mark_foreground
968             mark_background=mget(1,"il",fd) // mark_background
969         else
970             msu="tabulated"
971         end
972
973         line_mode      = toggle(mget(1,characterFormat,fd)) ; // line_mode
974         line_style     = mget(1,characterFormat,fd); // line_style
975         if line_style==0 then // 0 and 1 are equivalents and 0 is obsolete since Scilab 5.4.0
976             line_style=1;
977         end
978         fill_mode      = toggle(mget(1,characterFormat,fd)) ; // fill_mode
979         foreground     = mget(1,"il",fd); // foreground
980
981         if is_higher_than([3 1 0 1]) then
982             background = mget(1,"il",fd); // background
983         end
984         if (is_higher_than([5 0 3 0])) then
985             // data size might be 4 or 5
986             data = mget(mget(1,"il",fd),"dl",fd); // data
987         else
988             parentAxes = gca();
989             if (parentAxes.view == "2d") then
990                 data = mget(4,"dl",fd);
991             else
992                 data = mget(5,"dl",fd);
993             end
994         end
995         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // clip_stata
996         if clip_state=="on" then
997             clip_box     = mget(4,"dl",fd) // clip_box
998         else
999             clip_box=[]
1000         end
1001
1002         // draw the rectangle
1003         xrect(0,1,1,1); // create the rectangle with dummy values
1004         h=get("hdl")
1005         set(h,"data",data);
1006         set(h,"visible",visible)
1007         set(h,"thickness",thickness)
1008         set(h,"mark_style",mark_style),
1009         set(h,"mark_size",mark_size),
1010         set(h,"mark_size_unit",msu),
1011         if is_higher_than([3 0 0 0]) then
1012             set(h,"mark_foreground",mark_foreground) ;
1013             set(h,"mark_background",mark_background) ;
1014         end
1015         set(h,"mark_mode",mark_mode)
1016         set(h,"line_style",line_style)
1017         set(h,"fill_mode",fill_mode)
1018         set(h,"foreground",foreground) ;
1019         if is_higher_than([3 1 0 1]) then
1020             set(h,"background",background) ;
1021         end
1022         set(h,"line_mode",line_mode)
1023         if clip_state=="on" then set(h,"clip_box",clip_box),end
1024         set(h,"clip_state",clip_state);
1025
1026         load_user_data(fd) ; // user_data
1027
1028     case "Arc"
1029         visible        = toggle(mget(1,characterFormat,fd)) // visible
1030         thickness      = mget(1,"sl",fd); // thickness
1031         line_style     = mget(1,characterFormat,fd);  // line_style
1032         if line_style==0 then // 0 and 1 are equivalents and 0 is obsolete since Scilab 5.4.0
1033             line_style=1;
1034         end
1035
1036         if is_higher_than([3 1 0 1])
1037             line_mode = toggle(mget(1,characterFormat,fd)) ; // line_mode
1038         end
1039
1040         fill_mode      = toggle(mget(1,characterFormat,fd)) // fill_mode
1041         foreground     = mget(1,"il",fd); // foreground
1042
1043         if is_higher_than([3 1 0 1]) then
1044             background = mget(1,"il",fd) ; // background
1045         end
1046
1047         if (is_higher_than([5 0 3 0])) then
1048             // data size might be 6 or 7
1049             data = mget(mget(1,"il",fd),"dl",fd); // data
1050         else
1051             parentAxes = gca();
1052             if (parentAxes.view == "2d") then
1053                 data = mget(6,"dl",fd);
1054             else
1055                 data = mget(7,"dl",fd);
1056             end
1057         end
1058
1059         if is_higher_than([4 1 2 0]) then
1060             drawing_method = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // drawing_method
1061         else
1062             drawing_method = "nurbs";
1063         end
1064
1065         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1066         if clip_state=="on" then
1067             clip_box     = mget(4,"dl",fd) // clip_box
1068         else
1069             clip_box=[]
1070         end
1071         xarc(0,1,1,1,0,360); // create the arc dummy values
1072         h=get("hdl")
1073         if ~is_higher_than([4 1 2 0]) then
1074             // angle wass stored by 64th of degree
1075             data($) = data($) / 64;
1076             data($-1) = data($-1) / 64;
1077         end
1078         set(h,"data",data);
1079         set(h,"visible",visible)
1080         set(h,"thickness",thickness)
1081         set(h,"line_style",line_style)
1082         set(h,"line_mode",line_mode);
1083         set(h,"fill_mode",fill_mode)
1084         set(h,"foreground",foreground) ;
1085         set(h,"background",background) ;
1086         set(h,"arc_drawing_method", drawing_method) ;
1087         if clip_state=="on" then set(h,"clip_box",clip_box),end
1088         set(h,"clip_state",clip_state);
1089
1090         load_user_data(fd) // user_data
1091
1092     case "Champ"
1093         visible        = toggle(mget(1,characterFormat,fd)) // visible
1094         sz=mget(2,"il",fd); // data.x
1095         x=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1096         sz=mget(2,"il",fd); // data.y
1097         y=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1098         sz=mget(2,"il",fd); // data.fx
1099         fx=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1100         sz=mget(2,"il",fd); // data.fy
1101         fy=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1102
1103         // draw the champ
1104         champ(x,y,fx,fy);
1105         h=gce();
1106
1107         set(h,"visible",visible);
1108         line_style = mget(1,characterFormat,fd);
1109         if line_style==0 then // 0 and 1 are equivalents and 0 is obsolete since Scilab 5.4.0
1110             line_style=1;
1111         end
1112         set(h,"line_style",line_style); // line_style
1113         set(h,"thickness",mget(1,"sl",fd)) // thickness
1114         set(h,"colored",toggle(mget(1,characterFormat,fd))) // colored
1115         set(h,"arrow_size",mget(1,"dl",fd)) // arrow_size
1116
1117         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1118         if clip_state=="on" then
1119             set(h,"clip_box", mget(4,"dl",fd)) // clip_box
1120         end
1121         set(h,"clip_state",clip_state);
1122         load_user_data(fd) // user_data
1123
1124     case "Segs"
1125         visible        = toggle(mget(1,characterFormat,fd)) // visible
1126         sz             = mget(2,"il",fd) // data
1127         data           = matrix(mget(prod(sz),"dl",fd),sz(1),-1)
1128
1129         // draw the segs
1130         xsegs(data(:,1),data(:,2))
1131         h=gce()
1132         if size(data,2)==3 then
1133             h.data=data
1134         end
1135         set(h,"visible",visible);
1136         set(h,"line_mode" ,toggle(mget(1,characterFormat,fd))) // line_mode
1137         line_style = mget(1,characterFormat,fd);
1138         if line_style==0 then // 0 and 1 are equivalents and 0 is obsolete since Scilab 5.4.0
1139             line_style=1;
1140         end
1141         set(h,"line_style",line_style); // line_style
1142         set(h,"thickness",mget(1,"sl",fd)) // thickness
1143         set(h,"arrow_size",mget(1,"dl",fd)) // arrow_size
1144
1145         n=mget(1,"il",fd) // segs_color
1146         set(h,"segs_color",mget(n,"il",fd))
1147         // it is needed to set it at the end, ut I don't know why
1148         mark_mode = toggle(mget(1,characterFormat,fd)) ; // mark_mode
1149         set(h,"mark_style"           , mget(1,characterFormat,fd)) // mark_style
1150         set(h,"mark_size"            , mget(1,characterFormat,fd)) // mark_size
1151         if is_higher_than([3 0 0 0]) then
1152             if ascii(mget(1,characterFormat,fd))=="t" then // mark_size_unit
1153                 msu="tabulated"
1154             else
1155                 msu="point";
1156             end
1157             set(h,"mark_size_unit"     , msu) ;
1158             set(h,"mark_foreground"    , mget(1,"il",fd)) ; // mark_foreground
1159             set(h,"mark_background"    , mget(1,"il",fd)) ; // mark_background
1160         else
1161             set(h,"mark_size_unit"     , "tabulated") ; // mark_size_unit
1162         end
1163
1164         set(h,"mark_mode", mark_mode ) ;
1165
1166         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1167         if clip_state=="on" then
1168             set(h,"clip_box", mget(4,"dl",fd)) // clip_box
1169         end
1170         set(h,"clip_state",clip_state);
1171         load_user_data(fd) // user_data
1172
1173     case "Grayplot"
1174         visible        = toggle(mget(1,characterFormat,fd)) // visible
1175         if is_higher_than([3 0 0 0]) then
1176             sz=mget(2,"il",fd); // data.x
1177             x=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1178             sz=mget(2,"il",fd); // data.y
1179             y=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1180             sz=mget(2,"il",fd); // data.z
1181             z=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1182         else
1183             sz = mget(2,"il",fd) // data
1184             data = matrix(mget(prod(sz),"dl",fd),sz(1),-1)
1185         end
1186
1187         data_mapping   = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // data_mapping
1188         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1189         if clip_state=="on" then
1190             clip_box     = mget(4,"dl",fd) // clip_box
1191         else
1192             clip_box=[]
1193         end
1194
1195         // draw the grayplot
1196         if is_higher_than([3 0 0 0]) then
1197             grayplot(x,y,z)
1198         else
1199             grayplot(data(2:$,1),data(1,2:$),data(2:$,2:$))
1200         end
1201
1202         h=get("hdl")
1203         set(h,"visible",visible)
1204         set(h,"data_mapping",data_mapping)
1205         if clip_state=="on" then
1206             set(h,"clip_box",  clip_box)
1207         end
1208         set(h,"clip_state",clip_state);
1209
1210         load_user_data(fd) // user_data
1211
1212     case "Matplot"
1213         visible        = toggle(mget(1,characterFormat,fd)) // visible
1214         sz=mget(2,"il",fd); // data
1215         data=matrix(mget(prod(sz),"dl",fd),sz(1),-1);
1216         //    data_mapping   = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))
1217         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1218         if clip_state=="on" then
1219             clip_box     = mget(4,"dl",fd) // clip_box
1220         else
1221             clip_box=[]
1222         end
1223
1224         // draw the matplot
1225         Matplot(data);
1226
1227         h=get("hdl")
1228         set(h,"visible",visible)
1229         //    set(h,"data_mapping",data_mapping)
1230         if clip_state=="on" then
1231             set(h,"clip_box",  clip_box)
1232         end
1233         set(h,"clip_state",clip_state);
1234         // user_data
1235         load_user_data(fd)
1236
1237     case "Fec"
1238         visible        = toggle(mget(1,characterFormat,fd)) // visible
1239         sz             = mget(2,"il",fd) // data
1240         data           = matrix(mget(prod(sz),"dl",fd),sz(1),-1)
1241         sz             = mget(2,"il",fd) // triangles
1242         triangles      = matrix(mget(prod(sz),"dl",fd),sz(1),-1)
1243         z_bounds       = mget(2,"dl",fd) // z_bounds
1244         // draw the fec
1245         fec(data(:,1),data(:,2),triangles,data(:,3))
1246         h=unglue(get("hdl"))
1247         set(h,"visible",visible)
1248         set(h,"z_bounds",z_bounds)
1249         if is_higher_than( [5 0 3 0] ) then
1250             set(h,"color_range",mget(2,"dl",fd)); // color_range
1251             set(h,"outside_colors",mget(2,"dl",fd)); // color_range
1252             set(h,"line_mode" ,toggle(mget(1,characterFormat,fd))) // line_mode
1253             set(h,"foreground", mget(1,"il",fd)); // foreground
1254         end
1255         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1256         if clip_state=="on" then
1257             set(h,"clip_box", mget(4,"dl",fd)) // clip_box
1258         end
1259         set(h,"clip_state",clip_state);
1260         load_user_data(fd) // user_data
1261
1262     case "Legend"
1263         if is_higher_than( [5 0 0 0] ) then
1264             global %LEG
1265             %LEG=[];
1266             %LEG.visible         = toggle(mget(1,characterFormat,fd)) // visible
1267             %LEG.text            = load_text_vector(fd); // text
1268             %LEG.font_style      = mget(1,characterFormat,fd); // font_style
1269             %LEG.font_size       = mget(1,characterFormat,fd); // font_size
1270             %LEG.font_color      = mget(1,"il",fd); // font_size
1271             %LEG.fractional_font = toggle(mget(1,characterFormat,fd)); // fractional_font
1272             nlegends             = mget(1,characterFormat,fd);
1273             paths = list()
1274             for kl=1:nlegends
1275                 paths($+1)         = mget(mget(1,"il",fd),"il",fd);
1276             end
1277             %LEG.paths           = paths
1278             %LEG.legend_location = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd))
1279             %LEG.position        = mget(2,"dl",fd)
1280             %LEG.line_mode       = toggle(mget(1,characterFormat,fd))
1281             %LEG.thickness       = mget(1,"sl",fd)
1282             %LEG.foreground      = mget(1,"il",fd)
1283             %LEG.fill_mode       = toggle(mget(1,characterFormat,fd))
1284             %LEG.background      = mget(1,"il",fd)
1285
1286             %LEG.clip_state      = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1287             if %LEG.clip_state=="on" then
1288                 %LEG.clip_box      = mget(4,"dl",fd); // clip_box
1289             end
1290             %_load(fd,"user_data")
1291             %LEG.user_data       = user_data;
1292         else
1293             visible         = toggle(mget(1,characterFormat,fd)) // visible
1294             line_mode       = toggle(mget(1,characterFormat,fd)) // line_mode
1295             mark_mode       = toggle(mget(1,characterFormat,fd)) // mark_mode
1296             mark_foreground = mget(1,"il",fd) ; // mark_foreground
1297             mark_background = mget(1,"il",fd) ; // mark_background
1298
1299             //text=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // text
1300
1301             text = load_text_vector(fd); // text
1302
1303             //create the legend
1304             //get the number of lines of the legend
1305             lineFeedPosition = strindex(text,"@")
1306             nbLines = size( lineFeedPosition ) ;
1307             nbLines = nbLines(2) + 1
1308             //create as many curves as lines in the text
1309             nullVector = zeros(1,nbLines);
1310             //draw the legend
1311             plot2d(0,nullVector,leg=text) ;
1312             H=unglue(get("hdl"));
1313             h=H(1);
1314             delete(H(2));
1315
1316             set(h,"visible",visible)
1317             set(h,"line_mode",line_mode);
1318             set(h,"mark_mode",mark_mode);
1319             set(h,"mark_foreground",mark_foreground) ;
1320             set(h,"mark_background",mark_background) ;
1321             set(h,"foreground", mget(1,"il",fd)); // foreground
1322
1323             set(h,"font_style", mget(1,characterFormat,fd)); // font_style
1324             set(h,"font_size" , mget(1,characterFormat,fd)); // font_size
1325             if is_higher_than( [4 1 2 0] ) then
1326                 set(h,"fractional_font" , toggle(mget(1,characterFormat,fd))); // fractional_font
1327             end
1328             clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1329             if clip_state=="on" then
1330                 set(h,"clip_box",mget(4,"dl",fd)); // clip_box
1331             end
1332             set(h,"clip_state",clip_state);
1333         end
1334
1335     case "Text"
1336         visible         = toggle(mget(1,characterFormat,fd)) // visible
1337
1338         if is_higher_than( [4 1 2 0] ) then
1339             text            = load_text_matrix( fd ) ;
1340         else
1341             text            = load_text_vector(fd) // text
1342         end
1343         sz              = mget(2,characterFormat,fd)
1344         data            = matrix(mget(prod(sz),"dl",fd),sz(1),-1) // data
1345         text_box        = mget(2,"dl",fd) // text_box
1346         text_box_mode   = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)); // text_box_mode
1347
1348         // draw the text
1349         if text_box_mode == "off" then
1350             xstring(data(1),data(2),text)
1351         else
1352             xstringb(data(1),data(2),text,text_box(1),text_box(2))
1353         end
1354
1355         h=get("hdl");
1356         set(h,"data",data);
1357         set(h,"visible",visible) ;
1358         set(h,"text_box_mode",text_box_mode)
1359         set(h,"foreground"           , mget(1,"il",fd)); // foreground
1360         set(h,"font_style"           , mget(1,characterFormat,fd)); // font_style
1361
1362         if text_box_mode == "filled" then // font_size
1363             mget(1,characterFormat,fd) ;
1364         else
1365             set(h,"font_size", mget(1,characterFormat,fd));
1366         end
1367
1368         set(h,"font_angle"           , mget(1,"dl",fd)); // font_angle
1369
1370         //adding JB Silvy 28/11/05
1371         // box drawing
1372         if is_higher_than([3 1 0 1]) then
1373             set( h, "box"      , toggle( mget( 1, characterFormat, fd ) ) ) ; // box
1374             set( h, "line_mode", toggle( mget( 1, characterFormat, fd ) ) ) ; // line_mode
1375             set( h, "fill_mode", toggle( mget( 1, characterFormat, fd ) ) ) ; // fill_mode
1376
1377             set( h, "font_foreground", mget( 1, "il", fd ) ) ; // font_foreground
1378             set( h, "background"     , mget( 1, "il", fd ) ) ; // background
1379         end
1380
1381         if is_higher_than( [4 1 2 0] ) then
1382             set( h, "alignment", ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)  ) ) ; // alignment
1383             set( h, "fractional_font", toggle( mget( 1, characterFormat, fd ) ) ) ; // fractional_font
1384         end
1385
1386         clip_state     = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1387         if clip_state=="on" then
1388             clip_box     = mget(4,"dl",fd) // clip_box
1389             set(h,"clip_box",clip_box) ; // clip_box
1390         else
1391             clip_box=[]
1392         end
1393         set(h,"clip_state",clip_state);
1394         load_user_data(fd) // user_data
1395     case "Axis"
1396         if is_higher_than([3 1 0 0]) then
1397
1398             visible          = toggle(mget(1,characterFormat,fd)) // visible
1399             n                = mget(1,"il",fd) // tics_direction
1400             tics_direction   = ascii(mget(n,characterFormat,fd));
1401             nx               = mget(1,"il",fd) // xtics_coord
1402             xtics_coord      = mget(nx,"dl",fd)'
1403             ny               = mget(1,"il",fd) // ytics_coord
1404             ytics_coord      = mget(ny,"dl",fd)'
1405
1406             if tics_direction == "bottom" then axisdir="d";
1407             elseif tics_direction == "top" then axisdir="u";
1408             elseif tics_direction == "left" then axisdir="l";
1409             elseif tics_direction == "right" then axisdir="r";
1410             elseif nx>1 then axisdir="u";
1411             else axisdir="l";
1412             end
1413
1414             drawaxis(x=xtics_coord,y=ytics_coord,dir=axisdir);
1415             h=gce()
1416
1417             h.tics_color       = mget(1,"il",fd) // tics_color
1418             h.tics_segment     = toggle(mget(1,characterFormat,fd)) // tics_segment
1419             h.tics_style       = ascii(mget(1,characterFormat,fd)) // tics_style
1420             h.sub_tics         = mget(1,"il",fd) // sub_tics
1421             h.tics_labels     = load_text_vector(fd)' // tics_label
1422             labelfontsize = mget(1,"il",fd);
1423             // Bug fix: there was a bug in Scilab <=4.1.2 which used -1 as default value for labels_font_size
1424             // Scilab 5 needs font size to be >= 0 so we change the value to avoid an error message due to a Scilab bug...
1425             if labelfontsize == -1 then
1426                 //labelfontsize = 0;
1427             end
1428             h.labels_font_size = labelfontsize // label_font_size
1429             h.labels_font_color= mget(1,"il",fd); // labels_font_color
1430             if is_higher_than([5 4 0 1]) then
1431                 h.labels_font_style = mget(1,"il",fd);
1432             end
1433             if is_higher_than( [4 1 2 0] ) then
1434                 set( h, "fractional_font", toggle( mget( 1, characterFormat, fd ) ) ) ; // fractional_font
1435             end
1436             // h.tics_style=tics_style // jb Silvy apparently strange
1437
1438             clip_state       = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // clip_state
1439             if clip_state == "on" then
1440                 set(h,"clip_box",clip_box)
1441             end
1442             set(h,"clip_state",clip_state);
1443             load_user_data(fd) // user_data
1444         end
1445
1446     case "uimenu"
1447         if is_higher_than( [4 1 2 0] ) then
1448             h = uimenu("parent", gcf());
1449             h.enable = toggle(mget(1,"c",fd)); // Enable
1450             ncolors = mget(1,"il",fd); // Foregroundcolor (size)
1451             h.foregroundcolor = mget(ncolors,"dl",fd); // ForegroundColor (data)
1452             h.label = ascii(mget(mget(1,"c",fd),"c",fd)); // Label
1453             h.visible = toggle(mget(1,"c",fd)); // Visible
1454             if is_higher_than( [5 4 0 0] ) then
1455                 h.callback = ascii(mget(mget(1, stringFormat,fd),"c",fd)); // Callback
1456             else
1457                 h.callback = ascii(mget(mget(1,"c",fd),"c",fd)); // Callback
1458             end
1459             h.callback_type = mget(1,"il",fd); // Callback Type
1460             h.tag = ascii(mget(mget(1,"c",fd),"c",fd)); // Tag
1461         end
1462         if is_higher_than( [5 1 2 0] ) then // 5.2 and higher
1463             h.checked = toggle(mget(1,"c",fd)); // Checked
1464         end
1465         if is_higher_than( [5 1 1 0] ) then // 5.1.2 and higher
1466             // children
1467             nbChildren = mget(1,"il",fd) ;
1468             for k = 1 : nbChildren
1469                 htmp = load_graphichandle(fd) ;
1470                 set(htmp, "Parent", h);
1471             end
1472         end
1473
1474     case "uicontextmenu"
1475         h = uicontextmenu();
1476         // children
1477         nbChildren = mget(1,"il",fd) ;
1478         for k = 1 : nbChildren
1479             htmp = load_graphichandle(fd) ;
1480             set(htmp, "Parent", h);
1481         end
1482
1483     case "uicontrol"
1484         if is_higher_than( [4 1 2 0] ) then
1485             uistyle = ascii(mget(mget(1,"c",fd),"c",fd)); // Style
1486             h = uicontrol("parent",gcf(), "style", uistyle);
1487             ncolors = mget(1,"il",fd); // BackgroundColor (size)
1488             h.backgroundcolor = mget(ncolors,"dl",fd); // BackgroundColor (data)
1489             h.enable = toggle(mget(1,"c",fd)); // Enable
1490             h.fontangle = ascii(mget(mget(1,"c",fd),"c",fd)); // FontAngle
1491             h.fontname = ascii(mget(mget(1,"c",fd),"c",fd)); // FontName
1492             fontsize_in_units = mget(1,"dl",fd); // FontSize
1493             h.fontunits = ascii(mget(mget(1,"c",fd),"c",fd)); // FontUnits
1494             h.fontsize = fontsize_in_units; // FontSize written after 'FontUnits' to avoid them to be computed again
1495             h.fontweight = ascii(mget(mget(1,"c",fd),"c",fd)); // FontWeight
1496             ncolors = mget(1,"il",fd); // Foregroundcolor (size)
1497             h.foregroundcolor = mget(ncolors,"dl",fd); // ForegroundColor (data)
1498             h.horizontalalignment = ascii(mget(mget(1,"c",fd),"c",fd)); // HorizontalAlignment
1499             ndata = mget(1,"il",fd); // ListboxTop (size)
1500             h.listboxtop = mget(ndata,"dl",fd); // ListboxTop (data)
1501             h.max = mget(1,"dl",fd); // Max
1502             h.min = mget(1,"dl",fd); // Min
1503             ndata = mget(1,"il",fd); // Position (size)
1504             position_in_units = mget(ndata,"dl",fd); // Position (data)
1505             h.relief = ascii(mget(mget(1,"c",fd),"c",fd)); // Relief
1506             ndata = mget(1,"il",fd); // SliderStep (size)
1507             h.sliderstep = mget(ndata,"dl",fd); // SliderStep (data)
1508             h.string = load_text_matrix(fd) ; // String
1509             if ( is_higher_than([5 2 0 0]) ) then // Added in 5.4.0 version
1510                 h.tooltipstring = load_text_matrix(fd) ; // TooltipString
1511             end
1512             h.units = ascii(mget(mget(1,"c",fd),"c",fd)); // Units
1513             h.position = position_in_units; // Position written after 'Units' to avoid them to be computed again
1514             ndata = mget(1,"il",fd); // Value (size)
1515             h.value = mget(ndata,"dl",fd); // Value (data)
1516             h.verticalalignment = ascii(mget(mget(1,"c",fd),"c",fd)); // VerticalAlignment
1517             h.visible = toggle(mget(1,"c",fd)); // Visible
1518             if is_higher_than( [5 4 0 0] ) then
1519                 h.callback = ascii(mget(mget(1, stringFormat,fd),"c",fd)); // Callback
1520             else
1521                 h.callback = ascii(mget(mget(1,"c",fd),"c",fd)); // Callback
1522             end
1523             h.callback_type = mget(1,"il",fd); // Callback Type
1524             load_user_data(fd); // Userdata
1525             h.tag = ascii(mget(mget(1,"c",fd),"c",fd)); // Tag
1526         end
1527
1528     else
1529         warning("type " +typ+" unhandled");
1530     end
1531
1532 endfunction
1533
1534 function r=toggle(k)
1535     r=emptystr(k)+"on"
1536     r(k==0)="off"
1537 endfunction
1538
1539 function load_user_data(fd)
1540     if is_higher_than([3 1 0 0]) then
1541         h; //make a copy of the calling context h here
1542         %_load(fd,"user_data")
1543         if ~isempty(user_data) then
1544             set(h, "user_data", user_data);
1545         end
1546     end
1547 endfunction
1548
1549 function r=is_higher_than(v)
1550     //check if current version is strictly higher than the given one
1551     r=%f
1552     for k=1:4
1553         if version(k)>v(k) then r=%t,break,end
1554         if version(k)<v(k) then r=%f,break,end
1555     end
1556 endfunction
1557
1558 function text=load_text_vector(fd)
1559     T=mget(mget(1,"il",fd),characterFormat,fd)
1560     newline=[find(T==10) size(T,"*")+1];
1561     text=[]
1562     p=1
1563     for k=1:size(newline,"*")
1564         text=[text;ascii(T(p:newline(k)-1))];
1565         p=newline(k)+1
1566     end
1567 endfunction
1568
1569 // retrieve a string matrix saved by save_text_matrix
1570 function strMat = load_text_matrix( fd )
1571     nbRow = mget( 1, "il", fd ) ;
1572     nbCol = mget( 1, "il", fd ) ;
1573     for i = 1:nbRow
1574         for j = 1:nbCol
1575             if is_higher_than([5 4 0 0]) then
1576                 strMat(i,j) = ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) ;
1577             else
1578                 strMat(i,j) = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ;
1579             end
1580         end
1581     end
1582 endfunction
1583
1584 function links=get_links_from_path(ax,paths)
1585     //  ax is a  handle on an axes entity
1586     //  paths a list or row vector which gives the set of paths relative to
1587     //  the axes
1588     links=[];ok=%t
1589     for p=paths
1590         e=ax;
1591         p(1)=p(1)-1// the caption does not exists yet
1592         for kp=1:size(p,"*"),
1593             if or(e.type==["Axes","Compound"])&p(kp)<=size(e.children,"*") then
1594                 e=e.children(p(kp)),
1595             else
1596                 ok=%f
1597                 break
1598             end
1599         end
1600         if ~ok then break,end
1601         links=[links,e]
1602     end
1603     if ~ok then links=[],end
1604 endfunction