02f11046e439f1604b206fa07f77fad6483f4c21
[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 [l,mac]=where()
11 scsmode=find(mac=='scicos')<>[]
12 [lhs,rhs]=argn(0)
13 pat=33
14 thick=1
15 fnt=[2 1]
16 dash=33
17 symb=[0 0]
18 if sd(1)<>'sd' then error('first argument has incorrect data type'),end
19 if rhs<3 then orig=['0';'0'],end
20 if type(orig)==1 then orig=string(orig),end
21 if rhs<2 then zoom=['1';'1'],end
22 if type(zoom)==1 then zoom=string(zoom),end
23 if size(zoom,'*')==1 then zoom(2)=zoom(1),end
24 rect=sd(2)
25 xmx=rect(3);ymx=rect(4)
26 dx=abs(rect(3)-rect(1));dx=10^(-log(dx/100)/log(10))*10
27 dy=abs(rect(4)-rect(2));dy=10^(-log(dy/100)/log(10))*10
28 dxy=maxi(dx,dy)
29 txt=[]
30 txt='xsetech([0 0 1 1],'+sci2exp(sd(2))+')'
31 for k=3:size(sd)
32   o=sd(k)
33   if type(o)==15 then
34     select o(1)
35     case 'rect' then
36       [x1,x2,y1,y2]=o(2:5)
37       x1=round(dx*x1)/dx
38       x2=round(dx*x2)/dx
39       y1=round(dy*y1)/dy
40       y2=round(dy*y2)/dy
41       xi=string(mini(x1,x2));
42       w=string(abs(x1-x2));
43       yi=string(max(y1,y2));
44       h=string(abs(y1-y2));
45       txt=[txt;'xrect('+strcat([zsx(xi),zsy(yi),zx(w),zy(h)],',')+');']
46     case 'frect' then
47       [x1,x2,y1,y2]=o(2:5)
48       x1=round(dx*x1)/dx
49       x2=round(dx*x2)/dx
50       y1=round(dy*y1)/dy
51       y2=round(dy*y2)/dy
52       xi=string(mini(x1,x2));
53       w=string(abs(x1-x2));
54       yi=string(max(y1,y2));
55       h=string(abs(y1-y2));
56       Color=string(pat)
57       if scsmode then Color='scs_color('+Color+')',end
58       txt=[txt;'xrects(['+strcat([zsx(xi),zsy(yi),zx(w),zy(h)],';')+'],'+Color+');']  
59     case 'fleche' then
60       x=round(dx*o(2))/dx;y=round(dy*o(3))/dy
61       txt=[txt;'xarrows('+zsx(sci2exp(x))+','+zsy(sci2exp(y))+',-1,-1);']
62     case 'ligne' then
63       z=o(2)';
64       x=zsx(strcat(sci2exp(round(dx*z(:,1))/dx)))
65       y=zsy(strcat(sci2exp(round(dy*z(:,2))/dy)))
66       txt=[txt;'xpoly('+x+','+y+',""lines"");']
67     case 'cercle' then
68       c=o(2);r=round(dxy*o(3))/dxy
69       c1=round(dx*c(1))/dx
70       c2=round(dy*c(2))/dy
71       xx=zsx(string(c1-r))
72       yy=zsy(string(c2+r))
73       rx=zx(string(2*r))
74       ry=zy(string(2*r))
75       txt=[txt;'xarc('+strcat([xx,yy,rx,ry,'0','64*360'],',')+');']
76     case 'fcercle' then
77       c=o(2);r=round(dxy*o(3))/dxy
78       c1=round(dx*c(1))/dx
79       c2=round(dy*c(2))/dy
80       xx=zsx(string(c1-r))
81       yy=zsy(string(c2+r))
82       rx=zx(string(2*r))
83       ry=zy(string(2*r))
84       txt=[txt;'xfarc('+strcat([xx,yy,rx,ry,'0','64*360'],',')+');']      
85     case 'comm' then
86       z=o(2)
87       com=sci2exp(o(3))
88       x=zsx(string(round(dx*z(1))/dx))
89       y=zsy(string(round(dy*z(2))/dy))
90       txt=[txt;'xstring('+strcat([x,y,com,'0,0'],',')+');']
91     case 'patts' then
92       Color=string(o(2))
93       if scsmode then Color='scs_color('+Color+')',end
94       txt=[txt;'xset(''pattern'','+Color+')']
95       pat=o(2)
96     case 'thick' then
97       txt=[txt;'xset(''thickness'','+string(o(2))+')']  
98       thick=o(2)
99     case 'symbs' then
100       txt=[txt;'xset(''mark'','+string(o(2))+','+string(o(3))+')']
101       symb=[o(2),o(3)]
102     case 'dashs' then
103       Color=string(o(2))
104       if scsmode then Color='scs_color('+Color+')',end
105       txt=[txt;'xset(''dashes'','+Color+')']
106       dash=o(2)
107     case 'fligne' then
108       z=o(2)';
109       x=zsx(strcat(sci2exp(round(dx*z(:,1))/dx)))
110       y=zsy(strcat(sci2exp(round(dy*z(:,2))/dy)))
111       txt=[txt;
112           'xpoly('+x+','+y+',''lines'')';
113           'xfpoly('+x+','+y+',1)'];
114     case 'points' then 
115       z=o(2)';
116       x=zsx(strcat(sci2exp(round(dx*z(:,1))/dx)))
117       y=zsy(strcat(sci2exp(round(dy*z(:,2))/dy)))
118       txt=[txt;
119           'xpoly('+x+','+y+',""marks"")'];
120     case "clipon" then
121       txt=[txt;"axes = gca()"; "axes.clip_state = ''clipgrf''"]
122     case "clipoff" then
123       txt=[txt;"axes = gca()"; "axes.clip_state = ''off''"]     
124     else
125
126     end
127   end
128   
129 end
130 endfunction
131 function t=zx(t)
132 if zoom(1)<>'1' then t($)=mulf(t($),zoom(1)),end
133
134
135
136 endfunction
137 function t=zy(t)
138 if zoom(2)<>'1' then t($)=mulf(t($),zoom(2)),end
139
140
141 endfunction
142 function t=zsx(t)
143 if zoom(1)<>'1' then t($)=mulf(t($),zoom(1)),end
144 if orig(1)<>'0' then t(1)=addf(orig(1),t(1)),end
145
146 endfunction
147 function t=zsy(t)
148 if zoom(2)<>'1' then t($)=mulf(t($),zoom(2)),end
149 if orig(2)<>'0' then t(1)=addf(orig(2),t(1)),end
150 endfunction