c331cb220930a7da6fcc4205ee2d84b4cb13c2f2
[scilab.git] / scilab / modules / graphics / macros / %h_save.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) 2012 - 2016 - Scilab Enterprises
6 //
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
13
14
15 function %h_save(h,fd)
16     version=[5 5 2 0]
17     mput(version,"uc",fd)
18
19     // There are issues when saving characters with 'c' format
20     // characterFormat format behave smoothly
21     characterFormat = "uc";
22     stringFormat = "il";
23
24     hsize = size(h);
25     mput(hsize,characterFormat,fd);
26     // introduced in version 3 1 0 2 to handle
27     // the case where we have a matrix of handles to save
28
29     if or(hsize>1)
30         for i=1:hsize(1)
31             for j=1:hsize(2)
32                 save_graphichandle(h(i,j),fd)
33             end
34         end
35     else
36         save_graphichandle(h,fd)
37     end
38 endfunction
39
40 function save_graphichandle(h,fd)
41     if ~is_handle_valid(h) then
42         warning(msprintf(gettext("%s: handle no more valid ignored.\n"),"save_graphichandle"));
43         return
44     end
45     typ=h.type
46     select h.type
47
48     case "Figure"
49         mput( length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
50         // handle => new style
51         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
52         mput(h.figure_position,"sl",fd) // figure_position
53         mput(h.figure_size,"sl",fd) // figure size
54         mput(h.axes_size,"sl",fd) // axes_size
55         mput(h.viewport,"sl",fd) // viewport
56         mput(length(ascii(h.info_message)),stringFormat,fd) ; // info_message
57         mput(ascii(h.info_message),characterFormat,fd) ;
58         mput(length(ascii(h.tag)),characterFormat,fd) ; // tag
59         mput(ascii(h.tag),characterFormat,fd) ;
60         mput(bool2s(h.auto_resize=="on"),characterFormat,fd) // auto_resize
61         mput(length(ascii(h.figure_name)),stringFormat,fd); // figure_name
62         mput(ascii(h.figure_name),characterFormat,fd);
63         mput(h.figure_id,"sl",fd); // figure_id
64
65         mput(size(h.color_map,"*"),"il",fd); // color_map
66         mput(h.color_map,"dl",fd) ;
67         mput(length(h.pixel_drawing_mode),characterFormat,fd); // pixel_drawing_mode
68         mput(ascii(h.pixel_drawing_mode),characterFormat,fd);
69         mput(length(h.anti_aliasing),characterFormat,fd); // anti_aliasing
70         mput(ascii(h.anti_aliasing),characterFormat,fd);
71         mput(bool2s(h.immediate_drawing=="on"),characterFormat,fd) // immediate_drawing
72         mput(h.background,"il",fd) // background
73         mput(length(h.rotation_style),characterFormat,fd); // rotation style
74         mput(ascii(h.rotation_style),characterFormat,fd);
75
76         mput(length(ascii(h.event_handler)),characterFormat,fd); // event_handler
77         mput(ascii(h.event_handler),characterFormat,fd);
78         mput(length(h.event_handler_enable),characterFormat,fd); // even_handler_enable
79         mput(ascii(h.event_handler_enable),characterFormat,fd); // need to be put after event_handler
80
81         mput(length(ascii(h.resizefcn)),characterFormat,fd) ; // resizefcn
82         mput(ascii(h.resizefcn),characterFormat,fd) ;
83         mput(length(ascii(h.closerequestfcn)),characterFormat,fd) ; // closerequestfcn
84         mput(ascii(h.closerequestfcn),characterFormat,fd) ;
85
86         // children
87         c=h.children;
88         n=size(c,"*")
89         mput(n,"il",fd)
90         for k=n:-1:1
91             save_graphichandle(c(k),fd)
92         end
93
94         user_data=h.user_data; // user_data
95         save(fd,user_data) ;
96
97
98     case "Axes"
99         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
100         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
101         mput(size(h.axes_visible,"*"),characterFormat,fd); // axes_visible
102         mput(bool2s(h.axes_visible=="on"),characterFormat,fd) ;
103         mput(size(h.axes_reverse,"*"),characterFormat,fd); // axes_reverse
104         mput(bool2s(h.axes_reverse=="on"),characterFormat,fd) ;
105         mput(size(h.grid,"*"),characterFormat,fd); mput(h.grid,"il",fd); // grid
106         mput(length(h.grid_position),characterFormat,fd); // grid_position
107         mput(ascii(h.grid_position),characterFormat,fd);
108         mput(length(h.x_location),characterFormat,fd); // x_location
109         mput(ascii(h.x_location),characterFormat,fd);
110         mput(length(h.y_location),characterFormat,fd); // y_location
111         mput(ascii(h.y_location),characterFormat,fd);
112         mput(ascii(h.view),characterFormat,fd) ; // view
113
114         // title
115         l=h.title;
116         mput(bool2s(l.visible=="on"),characterFormat,fd) ; // title.visible
117         save_text_matrix( l.text, fd ) ;
118         mput(l.font_foreground,"il",fd); // title_label.font_foreground
119         mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // title.fractional_font
120         mput(l.foreground,"il",fd) // title.foreground
121         mput(l.background,"il",fd) // title.background
122         mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // title.fill_mode
123         mput(l.font_style,characterFormat,fd) ; // title.font_style
124         mput(l.font_size,characterFormat,fd)  ; // title.font_size
125
126         mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // title.auto_rotation
127         mput(l.font_angle,"dl",fd) // title.font_angle
128         mput(bool2s(l.auto_position=="on"),characterFormat,fd) // title.auto_position
129         mput(l.position,"dl",fd) // title.position
130
131         // x_label
132         l=h.x_label
133         mput(bool2s(l.visible=="on"),characterFormat,fd) // x_label.visible
134         save_text_matrix( l.text, fd ) ;
135         mput(l.font_foreground,"il",fd); // x_label.font_foreground
136         mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // x_label.fractional_font
137         mput(l.foreground,"il",fd) // x_label.foreground
138         mput(l.background,"il",fd) // x_label.background
139         mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // x_label.fill_mode
140         mput(l.font_style,characterFormat,fd) // x_label.font_style
141         mput(l.font_size,characterFormat,fd)  // x_label.font_size
142
143         mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // x_label.auto_rotation
144         mput(l.font_angle,"dl",fd) // x_label.font_angle
145         mput(bool2s(l.auto_position=="on"),characterFormat,fd) // x_label.auto_position
146         mput(l.position,"dl",fd) // x_label.position
147
148         // y_label
149         l=h.y_label
150         mput(bool2s(l.visible=="on"),characterFormat,fd) // y_label.visible
151         save_text_matrix( l.text, fd ) ;
152         mput(l.font_foreground,"il",fd); // y_label.font_foreground
153         mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // y_label.fractional_font
154         mput(l.foreground,"il",fd) // y_label.foreground
155         mput(l.background,"il",fd) // y_label.background
156         mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // y_label.fill_mode
157         mput(l.font_style,characterFormat,fd) // y_label.font_style
158         mput(l.font_size,characterFormat,fd) // y_label.font_size
159
160         mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // y_label.auto_rotation
161         mput(l.font_angle,"dl",fd) // y_label.font_angle
162         mput(bool2s(l.auto_position=="on"),characterFormat,fd) // y_label.auto_position
163         mput(l.position,"dl",fd) // y_label.position
164
165         if h.view=="3d" then
166             // z_label
167             l=h.z_label
168             mput(bool2s(l.visible=="on"),characterFormat,fd) // z_label.visible
169             save_text_matrix( l.text, fd ) ;
170             mput(l.font_foreground,"il",fd); // z_label.font_foreground
171             mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // z_label.fractional_font
172             mput(l.foreground,"il",fd) // z_label.foreground
173             mput(l.background,"il",fd) // z_label.background
174             mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // z_label.fill_mode
175             mput(l.font_style,characterFormat,fd) // z_label.font_style
176             mput(l.font_size,characterFormat,fd) // z_label.font_size
177             mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // z_label.auto_rotation
178             mput(l.font_angle,"dl",fd) // z_label.font_angle
179             mput(bool2s(l.auto_position=="on"),characterFormat,fd) // z_label.auto_position
180             mput(l.position,"dl",fd) // z_label.position
181         end
182
183         mput(size(h.auto_ticks,"*"),characterFormat,fd); // auto_ticks
184         mput(bool2s(h.auto_ticks=="on"),characterFormat,fd)
185         // x_ticks
186         sz=size(h.x_ticks.locations,"*");
187         mput(sz,"sl",fd);
188         if sz>0 then
189             mput(h.x_ticks.locations,"dl",fd)
190             mput(length(h.x_ticks.labels),characterFormat,fd); // x_ticks.labels
191             mput(ascii(strcat(h.x_ticks.labels)),characterFormat,fd);
192         end
193         // y_ticks
194         sz=size(h.y_ticks.locations,"*");
195         mput(sz,"sl",fd);
196         if sz>0 then
197             mput(h.y_ticks.locations,"dl",fd)
198             mput(length(h.y_ticks.labels),characterFormat,fd); // y_ticks.labels
199             mput(ascii(strcat(h.y_ticks.labels)),characterFormat,fd);
200         end
201         // z_ticks
202         sz=size(h.z_ticks.locations,"*");
203         mput(sz,"sl",fd);
204         if sz>0 then
205             mput(h.z_ticks.locations,"dl",fd)
206             mput(length(h.z_ticks.labels),characterFormat,fd); // z_ticks.labels
207             mput(ascii(strcat(h.z_ticks.labels)),characterFormat,fd);
208         end
209         mput(length(h.box), characterFormat, fd ) ; // box
210         mput(ascii(h.box),  characterFormat, fd ) ;
211         mput(bool2s(h.filled == "on"),characterFormat,fd); // filled
212         mput(size(h.sub_tics,"*"),characterFormat,fd);mput(h.sub_tics,characterFormat,fd); // sub_ticks
213         //mput(-1,'il',fd) // tics_color is removed F.Leray 15.03.05
214         mput(h.font_style,characterFormat,fd) // font_style
215         mput(h.font_size,characterFormat,fd) //font_size
216         mput(h.font_color,"il",fd) // font_color
217         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
218         mput(bool2s(h.isoview=="on"),characterFormat,fd)    // isoview
219         mput(bool2s(h.cube_scaling=="on"),characterFormat,fd) // cube_scaling
220         mput(h.rotation_angles,"dl",fd) // rotation_angles
221         mput(ascii(h.log_flags),characterFormat,fd) // log_flags
222         mput(size(h.tight_limits,"*"),characterFormat,fd); // tight_limits
223         mput(bool2s(h.tight_limits=="on"),characterFormat,fd);
224         mput(size(h.data_bounds,"*"),characterFormat,fd); // data_bounds
225         mput(h.data_bounds,"dl",fd);
226         mput(size(h.zoom_box,"*"),characterFormat,fd);  // zoom_box
227         if size(h.zoom_box,"*")>0 then mput(h.zoom_box,"dl",fd);end
228         mput(h.margins,"dl",fd); // margins
229         mput(h.axes_bounds,"dl",fd); // axes_bounds
230         mput(bool2s(h.auto_clear=="on"),characterFormat,fd) // auto_clear
231         mput(bool2s(h.auto_scale=="on"),characterFormat,fd) // auto_scale
232         mput(h.hidden_axis_color,"il",fd); // hidden_axis_color
233         mput(length(h.arc_drawing_method),characterFormat,fd); // arc_drawing_method
234         mput(ascii(h.arc_drawing_method),characterFormat,fd);
235         mput(h.hiddencolor,"il",fd) // hidden_color
236         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
237         mput(h.line_style,characterFormat,fd) // line_style
238         mput(h.thickness,"sl",fd) // thickness
239         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
240         mput(h.mark_style,characterFormat,fd) // mark_style
241         mput(h.mark_size,characterFormat,fd) // mark_size
242         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
243         mput(h.mark_foreground,"il",fd) // mark_foreground
244         mput(h.mark_background,"il",fd) // mark_background
245
246         mput(h.foreground,"il",fd) // foreground
247         mput(h.background,"il",fd) // background
248
249         mput(length(h.clip_state),characterFormat,fd); // clip_state
250         mput(ascii(h.clip_state),characterFormat,fd);
251         if h.clip_state=="on" then
252             mput(h.clip_box,"dl",fd) // clip_box
253         end
254
255         // children
256         c=h.children;
257         n=size(c,"*")
258         mput(n,"il",fd)
259         for k=n:-1:1
260             save_graphichandle(c(k),fd)
261         end
262
263         user_data=h.user_data;save(fd,user_data) // user_data
264
265     case "Polyline"
266         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
267
268         mput(bool2s(h.visible=="on"),characterFormat,fd) ; // visible
269         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // data
270         mput(bool2s(h.closed=="on"),characterFormat,fd) // closed
271         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
272         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
273         mput(h.line_style,characterFormat,fd) // line_style
274         mput(h.thickness,"sl",fd) // thickness
275         mput(h.arrow_size_factor,"sl",fd) // arrow_size_factor
276         mput(max(1,h.polyline_style),characterFormat,fd) // ployline_style
277
278         mput( size( h.interp_color_vector, "*" ), "sl", fd ) ; // interp_color_vector
279         mput( h.interp_color_vector, "dl", fd ) ;
280         mput( bool2s(h.interp_color_mode=="on"), characterFormat, fd ) ; // interp_color_mode
281
282         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
283         mput(h.mark_style,characterFormat,fd) // mark_style
284         mput(h.mark_size,characterFormat,fd) // mark_size
285         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
286         mput(h.foreground,"il",fd) // foreground
287         mput(h.background,"il",fd) // background
288         mput(h.mark_foreground,"il",fd) // mark_foreground
289         mput(h.mark_background,"il",fd) // mark_background
290         mput(h.mark_offset,"il",fd) // mark_offset
291         mput(h.mark_stride,"il",fd) // mark_stride
292
293         mput(size(h.x_shift,"*"),"sl",fd); mput(h.x_shift,"dl",fd); // x_shift
294         mput(size(h.y_shift,"*"),"sl",fd); mput(h.y_shift,"dl",fd); // y_shift
295         mput(size(h.z_shift,"*"),"sl",fd); mput(h.z_shift,"dl",fd); // z_shift
296
297         mput( h.bar_width, "dl", fd ) ; // bar_width
298         mput(length(h.clip_state),characterFormat,fd); // clip_state
299         mput(ascii(h.clip_state),characterFormat,fd);
300         if h.clip_state=="on" then
301             mput(h.clip_box,"dl",fd) // clip_box
302         end
303         user_data=h.user_data;save(fd,user_data) // user_data
304
305     case "Datatip"
306         mput(length(h.type),characterFormat,fd); // type
307         mput(ascii(h.type),characterFormat,fd);
308         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
309         mput(size(h.data),characterFormat,fd); // data
310         mput(h.data,"dl",fd);
311         mput(length(h.box_mode),characterFormat,fd); // box_mode
312         mput(ascii(h.box_mode),characterFormat,fd);
313         mput(length(h.label_mode),characterFormat,fd); // label_mode
314         mput(ascii(h.label_mode),characterFormat,fd);
315         mput(h.orientation,characterFormat,fd) // orientation
316         mput(length(h.display_components),characterFormat,fd);
317         mput(h.display_components,characterFormat,fd) // display_components
318         mput(bool2s(h.auto_orientation=="on"),characterFormat,fd) // auto_orientation
319         mput(bool2s(h.interp_mode=="on"),characterFormat,fd) // interp_mode
320         mput(length(ascii(h.display_function)),stringFormat,fd); // display_function
321         mput(h.font_foreground, "il", fd) ; // font_foreground
322         mput(h.foreground,"il",fd) // foreground
323         mput(h.background, "il", fd) ; // background
324         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
325         mput(h.mark_style,characterFormat,fd) // mark_style
326         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
327         mput(h.mark_size,characterFormat,fd) // mark_size
328         mput(h.mark_foreground,"il",fd) // mark_foreground
329         mput(h.mark_background,"il",fd) // mark_background
330         user_data=h.user_data;save(fd,user_data) // user_data
331         mput(length(h.tag),"c",fd); // tag
332         mput(ascii(h.tag),"c",fd);
333
334     case "Plot3d";
335         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
336         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
337         mput(bool2s(h.surface_mode=="on"),characterFormat,fd) // surface_mode
338         mput(h.foreground,"il",fd) // foreground
339         mput(h.thickness,"sl",fd) // thickness
340         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
341         mput(h.mark_style,characterFormat,fd) // mark_style
342         mput(h.mark_size,characterFormat,fd) // mark_size
343         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
344         mput(h.mark_foreground,"il",fd) // mark_foreground
345         mput(h.mark_background,"il",fd) // mark_background
346         mput(h.color_mode,"il",fd) // color_mode
347         mput(h.color_flag,"il",fd) // color_flag
348         x=h.data.x;sz=size(x)
349         mput(sz,"il",fd) // data.x
350         mput(x,"dl",fd)
351         y=h.data.y;sz=size(y)
352         mput(sz,"il",fd) // data.y
353         mput(y,"dl",fd)
354         z=h.data.z;sz=size(z)
355         mput(sz,"il",fd) // data.z
356         mput(z,"dl",fd)
357         if or(h.color_flag==[2 5]) then
358             clr=h.data.color;sz=size(clr)
359             mput(sz,"il",fd) // data.color
360             mput(clr,"il",fd)
361         end
362         mput(h.hiddencolor,"il",fd) // hidden_color
363         mput(length(h.clip_state),characterFormat,fd); // clip_state
364         mput(ascii(h.clip_state),characterFormat,fd);
365         if h.clip_state=="on" then
366             mput(h.clip_box,"dl",fd) // clip_box
367         end
368         user_data=h.user_data;save(fd,user_data) // user_data
369
370     case "Fac3d";
371         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd) ; // type
372         mput(bool2s(h.visible=="on"),characterFormat,fd) ; // visible
373         mput(bool2s(h.surface_mode=="on"),characterFormat,fd) // surface_mode
374         mput(h.foreground,"il",fd) // foreground
375         mput(h.thickness,"sl",fd) // thickness
376         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
377         mput(h.mark_style,characterFormat,fd) // mark_style
378         mput(h.mark_size,characterFormat,fd) // mark_size
379         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
380         mput(h.mark_foreground,"il",fd) // mark_foreground
381         mput(h.mark_background,"il",fd) // mark_background
382         mput(h.color_mode,"il",fd) // color_mode
383         mput(h.color_flag,"il",fd) // color_flag
384         x=h.data.x;sz=size(x)
385         mput(sz,"il",fd) // data.x
386         mput(x,"dl",fd)
387         y=h.data.y;sz=size(y)
388         mput(sz,"il",fd) // data.y
389         mput(y,"dl",fd)
390         z=h.data.z;sz=size(z)
391         mput(sz,"il",fd) // data.z
392         mput(z,"dl",fd)
393         if h.color_flag >=2 then
394             clr=h.data.color;sz=size(clr) // data.color
395             mput(sz,"il",fd)
396             mput(clr,"il",fd)
397             mput(ascii(part(h.cdata_mapping,1)),characterFormat,fd) ; // cdata_mapping
398         end
399         mput(h.hiddencolor,"il",fd) // hidden_color
400         mput(length(h.clip_state),characterFormat,fd); // clip_state
401         mput(ascii(h.clip_state),characterFormat,fd);
402         if h.clip_state=="on" then
403             mput(h.clip_box,"dl",fd) // clip_box
404         end
405         user_data=h.user_data;save(fd,user_data) // user_data
406
407     case "Compound"
408         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
409
410         // children
411         children=h.children
412         n=size(children,"*")
413         mput(n,"il",fd)
414         for k=1:n
415             save_graphichandle(children(k),fd)
416         end
417         mput( bool2s( h.visible=="on"), characterFormat, fd ) ; // visible
418
419         user_data=h.user_data;save(fd,user_data) // user_data
420
421     case "Rectangle"
422         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
423         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
424         mput(h.thickness,"sl",fd) // thickness
425         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
426         mput(h.mark_style,characterFormat,fd) // mark_style
427         mput(h.mark_size,characterFormat,fd) // mark_size
428         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
429         mput(h.mark_foreground,"il",fd) // mark_foreground
430         mput(h.mark_background,"il",fd) // mark_background
431         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
432         mput(h.line_style,characterFormat,fd) // line_style
433         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
434         mput(h.foreground,"il",fd) // foreground
435         mput(h.background,"il",fd) // background
436         mput(size(h.data, "*"), "il", fd); // data
437         mput(h.data,"dl",fd);
438         mput(length(h.clip_state),characterFormat,fd); // clip_state
439         mput(ascii(h.clip_state),characterFormat,fd);
440         if h.clip_state=="on" then
441             mput(h.clip_box,"dl",fd) // clip_box
442         end
443
444         user_data=h.user_data;save(fd,user_data) ; // user_data
445
446     case "Arc"
447         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
448         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
449         mput(h.thickness,"sl",fd) // thickness
450         mput(h.line_style,characterFormat,fd) // line_style
451         mput(bool2s(h.line_mode=="on"),characterFormat,fd) ;// line_mode
452         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
453         mput(h.foreground,"il",fd) // foreground
454         mput(h.background,"il",fd) ; // background
455         mput(size(h.data, "*"), "il", fd); // data
456         mput(h.data,"dl",fd);
457         mput(length(h.arc_drawing_method),characterFormat,fd); // arc_drawing_method
458         mput(ascii(h.arc_drawing_method),characterFormat,fd);
459         mput(length(h.clip_state),characterFormat,fd); // clip_state
460         mput(ascii(h.clip_state),characterFormat,fd);
461         if h.clip_state=="on" then
462             mput(h.clip_box,"dl",fd) // clip_box
463         end
464         user_data=h.user_data;save(fd,user_data) // user_data
465
466     case "Champ"
467         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
468         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
469         x=h.data.x;sz=size(x)
470         mput(sz,"il",fd) // data.x
471         mput(x,"dl",fd)
472         y=h.data.y;sz=size(y)
473         mput(sz,"il",fd) // data.y
474         mput(y,"dl",fd)
475         fx=h.data.fx;sz=size(fx)
476         mput(sz,"il",fd) // data.fx
477         mput(fx,"dl",fd)
478         fy=h.data.fy;sz=size(fy)
479         mput(sz,"il",fd) // data.fz
480         mput(fy,"dl",fd)
481         mput(h.line_style,characterFormat,fd) // line_style
482         mput(h.thickness,"sl",fd) // thickness
483         mput(bool2s(h.colored=="on"),characterFormat,fd) // colored
484         mput(h.arrow_size,"dl",fd) // arrow_size
485         mput(length(h.clip_state),characterFormat,fd); // clip_state
486         mput(ascii(h.clip_state),characterFormat,fd);
487         if h.clip_state=="on" then
488             mput(h.clip_box,"dl",fd) // clip_box
489         end
490         user_data=h.user_data;save(fd,user_data) // user_data
491
492     case "Segs"
493         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
494         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
495         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // data
496         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
497         mput(h.line_style,characterFormat,fd) // line_style
498         mput(h.thickness,"sl",fd) // thickness
499         mput(h.arrow_size,"dl",fd) // arrow_size
500         mput(size(h.segs_color,"*"),"il",fd); // segs_color
501         mput(h.segs_color,"il",fd)
502         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
503         mput(h.mark_style,characterFormat,fd) // mark_style
504         mput(h.mark_size,characterFormat,fd) // mark_size
505         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
506         mput(h.mark_foreground,"il",fd) // mark_foreground
507         mput(h.mark_background,"il",fd) // mark_background
508         mput(length(h.clip_state),characterFormat,fd); // clip_state
509         mput(ascii(h.clip_state),characterFormat,fd); // clip_state
510         if h.clip_state=="on" then
511             mput(h.clip_box,"dl",fd) // clip_box
512         end
513         user_data=h.user_data;save(fd,user_data) // user_data
514
515     case "Grayplot"
516         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
517         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
518         x=h.data.x;sz=size(x)
519         mput(sz,"il",fd) // data.x
520         mput(x,"dl",fd)
521         y=h.data.y;sz=size(y)
522         mput(sz,"il",fd) // data.y
523         mput(y,"dl",fd)
524         z=h.data.z;sz=size(z)
525         mput(sz,"il",fd) // data.z
526         mput(z,"dl",fd)
527         mput(length(h.data_mapping),characterFormat,fd); // data_mapping
528         mput(ascii(h.data_mapping),characterFormat,fd);
529         mput(length(h.clip_state),characterFormat,fd); // clip_state
530         mput(ascii(h.clip_state),characterFormat,fd);
531         if h.clip_state=="on" then
532             mput(h.clip_box,"dl",fd) // clip_box
533         end
534         user_data=h.user_data;save(fd,user_data) // user_data
535
536     case "Matplot"
537         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
538         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
539         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // datat
540         //    mput(length(h.data_mapping),characterFormat,fd);mput(ascii(h.data_mapping),characterFormat,fd);
541         mput(length(h.clip_state),characterFormat,fd); // clip_state
542         mput(ascii(h.clip_state),characterFormat,fd);
543         if h.clip_state=="on" then
544             mput(h.clip_box,"dl",fd) // clip_box
545         end
546         user_data=h.user_data;save(fd,user_data) // user_data
547
548     case "Fec"
549         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
550         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
551         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // data
552         mput(size(h.triangles),"il",fd);mput(h.triangles,"dl",fd) // triangles
553         mput(h.z_bounds,"dl",fd); // z_bounds
554         mput(h.color_range,"dl",fd); // color_range
555         mput(h.outside_colors,"dl",fd); // outside_colors
556         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
557         mput(h.foreground,"il",fd) // foreground
558         mput(length(h.clip_state),characterFormat,fd); // clip_state
559         mput(ascii(h.clip_state),characterFormat,fd);
560         if h.clip_state=="on" then
561             mput(h.clip_box,"dl",fd) // clip_box
562         end
563         user_data=h.user_data;save(fd,user_data) // user_data
564
565     case "Legend"
566         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); //type
567         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
568         save_text_vector(h.text,fd); // text
569         mput(h.font_style,characterFormat,fd) // font_style
570         mput(h.font_size,characterFormat,fd) // font_size
571         mput(h.font_color,"il",fd) // font_color
572         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
573         //replace links by a path relative to the parent axes
574         links=h.links;nlegends=size(links,"*");
575         mput(nlegends,characterFormat,fd)
576         for kl=1:nlegends
577             p=get_entity_path(links(kl))
578             mput(size(p,"*"),"il",fd)
579             mput(p,"il",fd)
580         end
581         mput(length(h.legend_location),characterFormat,fd);mput(ascii(h.legend_location),characterFormat,fd); //legend_location
582         mput(h.position,"dl",fd);
583         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
584         mput(h.thickness,"sl",fd) // thickness
585         mput(h.foreground,"il",fd) // foreground
586         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
587         mput(h.background,"il",fd) ; // background
588
589         mput(length(h.clip_state),characterFormat,fd); // clip_state
590         mput(ascii(h.clip_state),characterFormat,fd);
591         if h.clip_state=="on" then
592             mput(h.clip_box,"dl",fd) // clip_box
593         end
594         user_data=h.user_data;save(fd,user_data) // user_data
595
596     case "Text"
597         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
598         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
599         //save_text_vector(h.text,fd) // text
600         save_text_matrix( h.text, fd ) ;
601         mput(size(h.data),characterFormat,fd); // data // size could be 2 or 3
602         mput(h.data,"dl",fd);
603         mput(h.text_box,"dl",fd); // text_box
604         mput(length(h.text_box_mode),characterFormat,fd);
605         mput(ascii(h.text_box_mode),characterFormat,fd); // text_box_mode
606
607         mput(h.foreground,"il",fd) // foreground
608         mput(h.font_style,characterFormat,fd) // font_style
609         mput(h.font_size,characterFormat,fd) // font_size
610         mput(h.font_angle,"dl",fd) // font_angle
611
612         //adding JB Silvy 28/11/05
613         // box drawing
614         mput( bool2s( h.box       == "on" ), characterFormat, fd ) ; // box
615         mput( bool2s( h.line_mode == "on" ), characterFormat, fd ) ; // line_mode
616         mput( bool2s( h.fill_mode == "on" ), characterFormat, fd ) ; // fill_mode
617
618         mput( h.font_foreground, "il", fd ) ; // font_foreground
619         mput( h.background     , "il", fd ) ; // background
620
621         mput(length(h.alignment),characterFormat,fd);
622         mput(ascii(h.alignment),characterFormat,fd) ; // alignment
623         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
624
625         mput(length(h.clip_state),characterFormat,fd); // clip_state
626         mput(ascii(h.clip_state),characterFormat,fd);
627         if h.clip_state=="on" then
628             mput(h.clip_box,"dl",fd) // clip_box
629         end
630         user_data=h.user_data;save(fd,user_data) // user_data
631
632     case "Axis"
633         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
634         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
635         mput(length(h.tics_direction),"il",fd); // ticks_direction
636         mput(ascii(h.tics_direction),characterFormat,fd);
637         mput(size(h.xtics_coord,"*"),"il",fd); // xtics_coord
638         mput(h.xtics_coord,"dl",fd)
639         mput(size(h.ytics_coord,"*"),"il",fd); // ytics_coord
640         mput(h.ytics_coord,"dl",fd)
641         mput(h.tics_color,"il",fd) // tics_color
642         mput(bool2s(h.tics_segment=="on"),characterFormat,fd) // tics_segment
643         mput(ascii(h.tics_style),characterFormat,fd) // tics_style
644         mput(h.sub_tics,"il",fd) // sub_tics
645         save_text_vector(h.tics_labels,fd) // tics_labels
646         mput(h.labels_font_size,"il",fd) // label_font_size
647         mput(h.labels_font_color,"il",fd) // labels_font_color
648         mput(h.labels_font_style,"il",fd) // labels_font_style
649         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
650         mput(length(h.clip_state),characterFormat,fd); // clip_state
651         mput(ascii(h.clip_state),characterFormat,fd);
652         if h.clip_state=="on" then
653             mput(h.clip_box,"dl",fd) // clip_box
654         end
655         user_data=h.user_data;save(fd,user_data) // user_data
656
657     case "uimenu"
658         mput(length(h.type),"c",fd);mput(ascii(h.type),"c",fd); // Type
659         mput(bool2s(h.enable=="on"),"c",fd); // Enable
660         mput(size(h.foregroundcolor,"*"),"il",fd); // ForegroundColor (size)
661         mput(h.foregroundcolor,"dl",fd); // ForegroundColor (data)
662         mput(length(h.label),"c",fd);mput(ascii(h.label),"c",fd); // Label
663         mput(bool2s(h.visible=="on"),"c",fd); // Visible
664         mput(length(h.callback),stringFormat,fd);mput(ascii(h.callback),"c",fd); // Callback
665         mput(h.callback_type,"il",fd); // Callback Type
666         mput(length(h.tag),"c",fd);mput(ascii(h.tag),"c",fd); // Tag
667         mput(bool2s(h.checked=="on"),"c",fd); // Checked
668         // children
669         c=h.children;
670         n=size(c,"*")
671         mput(n,"il",fd)
672         for k=n:-1:1
673             save_graphichandle(c(k),fd)
674         end
675
676     case "uicontextmenu"
677         mput(length(h.type),"c",fd);mput(ascii(h.type),"c",fd); // Type
678         // children
679         c=h.children;
680         n=size(c,"*")
681         mput(n,"il",fd)
682         for k=n:-1:1
683             save_graphichandle(c(k),fd)
684         end
685
686     case "uicontrol"
687         mput(length(h.type),"c",fd);mput(ascii(h.type),"c",fd); // Type
688         mput(length(h.style),"c",fd);mput(ascii(h.style),"c",fd); // Style
689         mput(size(h.backgroundcolor,"*"),"il",fd); // BackgroundColor (size)
690         mput(h.backgroundcolor,"dl",fd); // BackgroundColor (data)
691         mput(bool2s(h.enable=="on"),"c",fd); // Enable
692         mput(length(h.fontangle),"c",fd);mput(ascii(h.fontangle),"c",fd); // FontAngle
693         mput(length(h.fontname),"c",fd);mput(ascii(h.fontname),"c",fd); // FontName
694         mput(h.fontsize,"dl",fd); // FontSize
695         mput(length(h.fontunits),"c",fd);mput(ascii(h.fontunits),"c",fd); // FontUnits
696         mput(length(h.fontweight),"c",fd);mput(ascii(h.fontweight),"c",fd); // FontWeight
697         mput(size(h.foregroundcolor,"*"),"il",fd); // ForegroundColor (size)
698         mput(h.foregroundcolor,"dl",fd); // ForegroundColor (data)
699         mput(length(h.horizontalalignment),"c",fd);mput(ascii(h.horizontalalignment),"c",fd); // HorizontalAlignment
700         mput(size(h.listboxtop,"*"),"il",fd); // ListboxTop (size)
701         mput(h.listboxtop,"dl",fd); // ListboxTop (data)
702         mput(h.max,"dl",fd); // Max
703         mput(h.min,"dl",fd); // Min
704         mput(size(h.position,"*"),"il",fd); // Position (size)
705         mput(h.position,"dl",fd); // Position (data)
706         mput(length(h.relief),"c",fd);mput(ascii(h.relief),"c",fd); // Relief
707         mput(size(h.sliderstep,"*"),"il",fd); // SliderStep (size)
708         mput(h.sliderstep,"dl",fd); // SliderStep (data)
709         save_text_matrix( h.string, fd ) ; // String
710         save_text_matrix( h.tooltipstring, fd ) ; // TooltipString
711         mput(length(h.units),"c",fd);mput(ascii(h.units),"c",fd); // Units
712         mput(size(h.value,"*"),"il",fd); // Value (size)
713         mput(h.value,"dl",fd); // Value (data)
714         mput(length(h.verticalalignment),"c",fd);mput(ascii(h.verticalalignment),"c",fd); // VerticalAlignment
715         mput(bool2s(h.visible=="on"),"c",fd); // Visible
716         mput(length(h.callback),stringFormat,fd);mput(ascii(h.callback),"c",fd); // Callback
717         mput(h.callback_type,"il",fd); // Callback Type
718         user_data=h.user_data;save(fd,user_data); // Userdata
719         mput(length(h.tag),"c",fd);mput(ascii(h.tag),"c",fd); // Tag
720
721     else
722         warning("handle of type "+h.type+" unhandled")
723     end
724
725 endfunction
726
727 function save_text_vector(t,fd)
728     t=ascii(strcat(t,ascii(10)));
729     mput(length(t),"il",fd);mput(t,characterFormat,fd);
730 endfunction
731
732 // save a text matrix
733 function save_text_matrix(strMat,fd)
734     // put nbRow and nbCol
735     nbRow = size( strMat, 1 ) ;
736     nbCol = size( strMat, 2 ) ;
737     mput( nbRow, "il", fd ) ;
738     mput( nbCol, "il", fd ) ;
739     for i = 1:nbRow
740         for j = 1:nbCol
741             mput(length(ascii(strMat(i,j))), stringFormat, fd) ;
742             mput(ascii(strMat(i,j)),characterFormat,fd) ;
743         end
744     end
745 endfunction
746
747 function p=get_entity_path(e)
748     // given a handle e on an entity this function returns its path relative
749     // to its parent axes.
750     // the path is a vector of child index.
751     p=[];parent=e.parent;
752
753     while  %t
754         pos=find(parent.children==e,1)
755         if pos==[] then
756             error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend"))
757         end
758         p=[pos p]
759         if parent.type=="Axes" then break,end
760         e=parent
761         parent=e.parent;
762     end
763 endfunction