3183a2d13c93bf46bbef4517cbdaabaa9479846b
[scilab.git] / scilab / modules / scicos / demos / scicos_play.sci
1 function scicos_play(fil)
2 // Copyright INRIA
3 funcprot(0)
4
5 if exists('scicos_scicoslib')==0 then
6   load("SCI/modules/scicos/macros/scicos_scicos/lib") ;
7 end
8
9 if exists('scicos_autolib')==0 then
10   load("SCI/modules/scicos/macros/scicos_auto/lib") ;
11 end
12
13 if exists('scicos_utilslib')==0 then
14   load("SCI/modules/scicos/macros/scicos_utils/lib") ;
15 end
16
17 global LineCount
18
19 //x_mess=funptr('x_message');clearfun('x_message')
20 x_dia=funptr('x_dialog');clearfun('x_dialog')
21 x_mdia=funptr('x_mdialog');clearfun('x_mdialog')
22 c_cho=funptr('x_choose');clearfun('x_choose')
23 xcli=funptr('xclick');clearfun('xclick')
24 xgetm=funptr('xgetmouse');clearfun('xgetmouse')
25 //xgetf=funptr('xgetfile');clearfun('xgetfile')
26
27
28 //reload the functions using the redefined primitive functions
29 names=[
30     'scicos'
31     'getvalue';
32     'choosefile';
33     'do_addnew';
34     'do_block';
35     'do_color';
36     'do_copy';
37     'do_copy_region';
38     'do_delete';
39     'do_delete_region';
40     'do_help';
41     'do_move';
42     'do_stupidmove';
43     'do_palettes';
44     'do_replace';
45     'do_run';
46     'do_SaveAs';
47     'do_tild';
48     'do_view';
49     'getlink';
50     'prt_align';
51     'cosclick';
52     'SaveasInterfFunc_'
53     'do_addnew'
54     'do_export'
55     'do_load' 
56     'do_exit'
57     'x_matrix']
58 for k=1:size(names,'r')
59   exec(get_function_path(names(k)))
60 end
61
62
63 global %fig_counter
64 %fig_counter=0;
65 %scicos_short;
66 %scicos_short($+1,1)='x';
67 %scicos_short($,2)='GrabScope'
68 %scicos_menu;
69 %scicos_menu($)($+1)=['GrabScope'];
70
71
72 %scicos_short;
73 %scicos_short($+1,1)='y';
74 %scicos_short($,2)='Snapshot'
75 %scicos_menu;
76 %scicos_menu($)($+1)=['Snapshot'];
77
78 %scicos_short;
79 %scicos_short($+1,1)='w';
80 %scicos_short($,2)='GrabPalette'
81 %scicos_menu;
82 %scicos_menu($)($+1)=['GrabPalette'];
83
84
85 %scicos_short;
86 %scicos_short($+1,1)='z';
87 %scicos_short($,2)='Comment'
88 %scicos_menu;
89 %scicos_menu($)($+1)=['Comment'];
90
91
92 deff('Snapshot_()',..
93      ['global %fig_counter'
94       '%fig_counter=%fig_counter+1;'
95       'scs_m1=scs_m;scs_m1.props.title(1)='' '' '
96       'do_export(scs_m1,''fig''+string(%fig_counter));'
97       'rect_=dig_bound(scs_m)'
98       'rect_=min((rect_(3)-rect_(1))*12/400,12)'
99       'txti=[''\begin{center}'';''\includegraphics[angle=270,width=''+string(rect_)+''cm]{fig''+string(%fig_counter)+''.eps}'';''\end{center}'']'
100       'txti=[''  '';txti;''  '']'
101       '//mputl(txti,%J)'
102       'Cmenu=''Replot'''])
103
104 deff('GrabPalette_()',..
105      ['global %fig_counter'
106       '[c_i,c_x,c_y,c_w]=xclick()'
107       '%fig_counter=%fig_counter+1;'
108       'dr=driver();driver(''Pos'');'
109       'fname=''fig''+string(%fig_counter)'
110       'xinit(fname)';
111       'xtape(''replay'',c_w);xend();driver(dr)'
112       'if MSDOS then'
113       '  comm=pathconvert(SCI+''\bin\BEpsf'',%f,%f,''w'')'
114       '  rep=unix_g('''''"''+comm+'''''" ''+fname)'
115       'else'
116       '  rep=unix_g(SCI+''/bin/BEpsf ''+fname)'
117       'end'
118       'txt2=x_dialog([''Enter caption''],'''');'
119       'txti=[''\begin{figure}\begin{center}'';''\fbox{\includegraphics[angle=0,width=12cm]{fig''+string(%fig_counter)+''.eps}}'';''\end{center}\caption{\label{labyy''+string(%fig_counter)+''}''+txt2+''}'';''\end{figure}'']'
120       'txti=[''  '';txti;''  '']'
121       '//mputl(txti,%J)'
122       'Cmenu=''Replot'''])
123
124 deff('GrabScope_()',..
125      ['global %fig_counter'
126       '[c_i,c_x,c_y,c_w]=xclick()'
127       'xset(''default'')'
128       '%fig_counter=%fig_counter+1;'
129       'dr=driver();driver(''Pos'');'
130       'fname=''fig''+string(%fig_counter)'
131       'xinit(fname)';
132       'xtape(''replay'',c_w);xend();driver(dr)'
133       'if MSDOS then'
134       '  comm=pathconvert(SCI+''\bin\BEpsf'',%f,%f,''w'')'
135       '  rep=unix_g('''''"''+comm+'''''" ''+fname)'
136       'else'
137       '  rep=unix_g(SCI+''/bin/BEpsf ''+fname)'
138       'end'
139       'txt2=x_dialog([''Enter caption''],'''');'
140       'txti=[''\begin{figure}\begin{center}'';''\includegraphics[angle=0,width=12cm]{fig''+string(%fig_counter)+''.eps}'';''\end{center}\caption{\label{labyy''+string(%fig_counter)+''}''+txt2+''}'';''\end{figure}'']'
141       'txti=[''  '';txti;''  '']'
142       '//mputl(txti,%J)'
143       'Cmenu=''Replot'''])
144
145
146 deff('Comment_()',..
147      ['txt=x_dialog([''Comments''],'''');'
148       '//mputl(txt,%J)'
149       'Cmenu=''Open/Set'''])
150
151
152
153 exec('SCI/demos/scicos/dialogs_play.sci')
154 execstr('tk_getfile=xgetfile')
155 execstr('tk_savefile=xgetfile')
156 tk_getcolor=getcolor
157
158 clear('%scicos_gui_mode_back')
159 if exists('%scicos_gui_mode') then
160   %scicos_gui_mode_back=%scicos_gui_mode
161 end
162 %scicos_gui_mode=0
163 //%J=mopen(fil+".tex",'w')
164 %I=mopen(fil,'r');ierr=execstr('scicos();','errcatch');mclose(%I);
165 //mclose(%J)
166
167 if exists('%scicos_gui_mode_back') then
168   %scicos_gui_mode=%scicos_gui_mode_back
169 end
170
171
172 //retore the primitives
173 //newfun('x_message',x_mess)
174 newfun('x_dialog',x_dia)
175 newfun('x_mdialog',x_mdia)
176 newfun('x_choose',c_cho)
177 newfun('xclick',xcli)
178 newfun('xgetmouse',xgetm)
179 //newfun('xgetfile',xgetf)
180 if ierr<>0 then 
181  write(%io(2),'Error had occurred at line '+string(LineCount)+' of file '+fil)
182 end
183 endfunction