Fix bug 4658 for xinfo,xsave,sd2sci,graduate,graypolarplot,legend,legends,nf3d ...
[scilab.git] / scilab / modules / graphics / macros / sd2sci.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution.  The terms
6 // are also available at    
7 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
8
9 function txt=sd2sci(sd,zoom,orig)
10 if rhs<1 then
11    error(msprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "sd2sci", 1));
12 end
13 [l,mac]=where()
14 scsmode=find(mac=='scicos')<>[]
15 [lhs,rhs]=argn(0)
16 pat=33
17 thick=1
18 fnt=[2 1]
19 dash=33
20 symb=[0 0]
21 if sd(1)<>'sd' then
22    error(msprintf(gettext("%s: Wrong type for input argument #%d.\n"), "sd2sci", 1));
23 end
24 if rhs<3 then orig=['0';'0'],end
25 if type(orig)==1 then orig=string(orig),end
26 if rhs<2 then zoom=['1';'1'],end
27 if type(zoom)==1 then zoom=string(zoom),end
28 if size(zoom,'*')==1 then zoom(2)=zoom(1),end
29 rect=sd(2)
30 xmx=rect(3);ymx=rect(4)
31 dx=abs(rect(3)-rect(1));dx=10^(-log(dx/100)/log(10))*10
32 dy=abs(rect(4)-rect(2));dy=10^(-log(dy/100)/log(10))*10
33 dxy=maxi(dx,dy)
34 txt=[]
35 txt='xsetech([0 0 1 1],'+sci2exp(sd(2))+')'
36 for k=3:size(sd)
37   o=sd(k)
38   if type(o)==15 then
39     select o(1)
40     case 'rect' then
41       [x1,x2,y1,y2]=o(2:5)
42       x1=round(dx*x1)/dx
43       x2=round(dx*x2)/dx
44       y1=round(dy*y1)/dy
45       y2=round(dy*y2)/dy
46       xi=string(mini(x1,x2));
47       w=string(abs(x1-x2));
48       yi=string(max(y1,y2));
49       h=string(abs(y1-y2));
50       txt=[txt;'xrect('+strcat([zsx(xi),zsy(yi),zx(w),zy(h)],',')+');']
51     case 'frect' then
52       [x1,x2,y1,y2]=o(2:5)
53       x1=round(dx*x1)/dx
54       x2=round(dx*x2)/dx
55       y1=round(dy*y1)/dy
56       y2=round(dy*y2)/dy
57       xi=string(mini(x1,x2));
58       w=string(abs(x1-x2));
59       yi=string(max(y1,y2));
60       h=string(abs(y1-y2));
61       Color=string(pat)
62       if scsmode then Color='scs_color('+Color+')',end
63       txt=[txt;'xrects(['+strcat([zsx(xi),zsy(yi),zx(w),zy(h)],';')+'],'+Color+');']  
64     case 'fleche' then
65       x=round(dx*o(2))/dx;y=round(dy*o(3))/dy
66       txt=[txt;'xarrows('+zsx(sci2exp(x))+','+zsy(sci2exp(y))+',-1,-1);']
67     case 'ligne' then
68       z=o(2)';
69       x=zsx(strcat(sci2exp(round(dx*z(:,1))/dx)))
70       y=zsy(strcat(sci2exp(round(dy*z(:,2))/dy)))
71       txt=[txt;'xpoly('+x+','+y+',""lines"");']
72     case 'cercle' then
73       c=o(2);r=round(dxy*o(3))/dxy
74       c1=round(dx*c(1))/dx
75       c2=round(dy*c(2))/dy
76       xx=zsx(string(c1-r))
77       yy=zsy(string(c2+r))
78       rx=zx(string(2*r))
79       ry=zy(string(2*r))
80       txt=[txt;'xarc('+strcat([xx,yy,rx,ry,'0','64*360'],',')+');']
81     case 'fcercle' then
82       c=o(2);r=round(dxy*o(3))/dxy
83       c1=round(dx*c(1))/dx
84       c2=round(dy*c(2))/dy
85       xx=zsx(string(c1-r))
86       yy=zsy(string(c2+r))
87       rx=zx(string(2*r))
88       ry=zy(string(2*r))
89       txt=[txt;'xfarc('+strcat([xx,yy,rx,ry,'0','64*360'],',')+');']      
90     case 'comm' then
91       z=o(2)
92       com=sci2exp(o(3))
93       x=zsx(string(round(dx*z(1))/dx))
94       y=zsy(string(round(dy*z(2))/dy))
95       txt=[txt;'xstring('+strcat([x,y,com,'0,0'],',')+');']
96     case 'patts' then
97       Color=string(o(2))
98       if scsmode then Color='scs_color('+Color+')',end
99       txt=[txt;'xset(''pattern'','+Color+')']
100       pat=o(2)
101     case 'thick' then
102       txt=[txt;'xset(''thickness'','+string(o(2))+')']  
103       thick=o(2)
104     case 'symbs' then
105       txt=[txt;'xset(''mark'','+string(o(2))+','+string(o(3))+')']
106       symb=[o(2),o(3)]
107     case 'dashs' then
108       Color=string(o(2))
109       if scsmode then Color='scs_color('+Color+')',end
110       txt=[txt;'xset(''dashes'','+Color+')']
111       dash=o(2)
112     case 'fligne' then
113       z=o(2)';
114       x=zsx(strcat(sci2exp(round(dx*z(:,1))/dx)))
115       y=zsy(strcat(sci2exp(round(dy*z(:,2))/dy)))
116       txt=[txt;
117           'xpoly('+x+','+y+',''lines'')';
118           'xfpoly('+x+','+y+',1)'];
119     case 'points' then 
120       z=o(2)';
121       x=zsx(strcat(sci2exp(round(dx*z(:,1))/dx)))
122       y=zsy(strcat(sci2exp(round(dy*z(:,2))/dy)))
123       txt=[txt;
124           'xpoly('+x+','+y+',""marks"")'];
125     case "clipon" then
126       txt=[txt;"axes = gca()"; "axes.clip_state = ''clipgrf''"]
127     case "clipoff" then
128       txt=[txt;"axes = gca()"; "axes.clip_state = ''off''"]     
129     else
130
131     end
132   end
133   
134 end
135 endfunction
136 function t=zx(t)
137 if zoom(1)<>'1' then t($)=mulf(t($),zoom(1)),end
138
139
140
141 endfunction
142 function t=zy(t)
143 if zoom(2)<>'1' then t($)=mulf(t($),zoom(2)),end
144
145
146 endfunction
147 function t=zsx(t)
148 if zoom(1)<>'1' then t($)=mulf(t($),zoom(1)),end
149 if orig(1)<>'0' then t(1)=addf(orig(1),t(1)),end
150
151 endfunction
152 function t=zsy(t)
153 if zoom(2)<>'1' then t($)=mulf(t($),zoom(2)),end
154 if orig(2)<>'0' then t(1)=addf(orig(2),t(1)),end
155 endfunction