* Bug 16573 fixed: mfile2sci: sci_axis is now reliable
[scilab.git] / scilab / modules / m2sci / macros / sci_files / sci_axis.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2020 - Samuel GOUGEON
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13 function tree = sci_axis(tree)
14     // M2SCI function
15     // Conversion function for Matlab axis()
16     // Input: tree = Matlab funcall tree
17     // Ouput: tree = Scilab equivalent for tree
18
19     ax = Funcall("gca",1,list(),list())
20
21     i = 1
22     if rhs > 0 then
23         if tree.rhs(1).vtype==Handle  // The first argin is the target
24             ax = tree.rhs(1)
25             if typeof(ax) <> "variable"
26                 ax = gettempvar()
27                 m2sci_insert(Equal(list(ax), tree.rhs(1)))
28             end
29             i = 2
30         end
31     end
32     if rhs==(i-1) then
33         // v = axis
34         tree = Funcall("get",1,Rhs_tlist(ax,"data_bounds"),tree.lhs)
35         tree.lhs(1).dims = list(2,Unknown)
36         tree.lhs(1).type = Type(Double,Real)
37         return
38     end
39
40     keepInputSyntax = %f
41     for krhs = i:rhs
42         if tree.rhs(krhs).vtype==Double then
43
44             // axis([xmin xmax ymin ymax])
45             // axis([xmin xmax ymin ymax zmin zmax])
46             if or(tree.rhs(krhs).dims(2)==[4,6]) then
47                 mat = Funcall("matrix",1,list(tree.rhs(krhs),Cste(2),Cste(-1)),list())
48                 LHS = Operation("ins", list(ax,Cste("data_bounds")), list())
49                 m2sci_insert(Equal(list(LHS), tree.rhs(krhs)))
50
51                 // axis([xmin xmax ymin ymax zmin zmax cmin cmax])
52             elseif tree.rhs(krhs).dims(2)==8 then
53                 no_equiv(expression2code(tree))
54                 keepInputSyntax = %t
55
56                 // Unknown column number for tree.rhs(krhs)
57             else
58                 tree.name = "mtlb_axis"
59                 keepInputSyntax = %t
60             end
61         elseif tree.rhs(krhs).vtype==String then
62
63             // Option is a character string
64             if typeof(tree.rhs(krhs))=="cste" then
65
66                 // axis auto
67                 if tree.rhs(krhs).value=="auto" then
68                     LHS = Operation("ins", list(ax,Cste("auto_scale")), list())
69                     m2sci_insert(Equal(list(LHS), Cste("on")))
70
71                     // axis manual
72                 elseif tree.rhs(krhs).value=="manual" then
73                     LHS = Operation("ins", list(ax,Cste("auto_scale")), list())
74                     m2sci_insert(Equal(list(LHS), Cste("off")))
75
76                     // axis tight
77                 elseif tree.rhs(krhs).value=="tight" then
78                     LHS = Operation("ins", list(ax,Cste("tight_limits")), list())
79                     m2sci_insert(Equal(list(LHS), Cste("on")))
80
81                     // axis fill
82                 elseif tree.rhs(krhs).value=="fill" then
83                     no_equiv(expression2code(tree))
84                     keepInputSyntax = %t
85
86                     // axis ij
87                 elseif tree.rhs(krhs).value=="ij" then
88                     axis_ij_xy(ax, Cste("on")) // sets .axes_reverse(2)="on"
89
90                     // axis xy
91                 elseif tree.rhs(krhs).value=="xy" then
92                     axis_ij_xy(ax, Cste("off")) // sets .axes_reverse(2)="off"
93
94                     // axis equal
95                 elseif tree.rhs(krhs).value=="equal" then
96                     LHS = Operation("ins", list(ax,Cste("isoview")), list())
97                     m2sci_insert(Equal(list(LHS), Cste("on")))
98
99                     // axis image
100                 elseif tree.rhs(krhs).value=="image" then
101                     no_equiv(expression2code(tree))
102                     keepInputSyntax = %t
103
104                     // axis square
105                 elseif tree.rhs(krhs).value=="square" then
106                     set_infos(gettext("cube_scaling only used in 3d mode."),2);
107                     LHS = Operation("ins", list(ax,Cste("cube_scaling")), list())
108                     m2sci_insert(Equal(list(LHS), Cste("on")))
109
110                     // axis vis3d
111                 elseif tree.rhs(krhs).value=="vis3d" then
112                     LHS = Operation("ins", list(ax,Cste("view")), list())
113                     m2sci_insert(Equal(list(LHS), Cste("3d")))
114
115                     // axis normal
116                 elseif tree.rhs(krhs).value=="normal" then
117                     no_equiv(expression2code(tree))
118                     keepInputSyntax = %t
119
120                     // axis on
121                 elseif tree.rhs(krhs).value=="on" then
122                     LHS = Operation("ins", list(ax,Cste("axes_visible")), list())
123                     m2sci_insert(Equal(list(LHS), Cste("on")))
124
125                     // axis off
126                 elseif tree.rhs(krhs).value=="off" then
127                     LHS = Operation("ins", list(ax,Cste("axes_visible")), list())
128                     m2sci_insert(Equal(list(LHS), Cste("off")))
129
130                     // [mode,visibility,direction] = axis('state')
131                 elseif tree.rhs(krhs).value=="state" then
132                     tree.name = "mtlb_axis"
133                     keepInputSyntax = %t
134                     // Unknown character string
135                 else
136                     tree.name = "mtlb_axis"
137                     keepInputSyntax = %t
138                 end
139
140                 // Option is a variable
141             else
142                 tree.name = "mtlb_axis"
143                 keepInputSyntax = %t
144             end
145
146             // axis(axes_handles,...)
147         elseif tree.rhs(krhs).vtype==Handle then
148             no_equiv(expression2code(tree))
149             keepInputSyntax = %t
150
151             // Unknown type for tree.rhs(krhs)
152         else
153             tree.name = "mtlb_axis"
154             keepInputSyntax = %t
155         end
156     end
157     if ~keepInputSyntax then
158         tree = list()
159     end
160 endfunction
161
162 function axis_ij_xy(ax, value)
163     if typeof(ax) <> "variable" | is_a_scalar(ax) // gca()
164         LHS = Operation("ins", list(ax,Cste("axes_reverse")), list())
165         LHS = Operation("ins", list(LHS,Cste(2)), list())
166         m2sci_insert(Equal(list(LHS), value))
167     else
168         // handles(:) : (because .axes_reverse is a row)
169         LHS = Operation("ins", list(ax,Colon), list())
170         // handles(:).axes_reverse :
171         LHS = Operation("ins", list(LHS,Cste("axes_reverse")), list())
172         // handles(:).axes_reverse(:,2) :
173         LHS = Operation("ins", list(LHS,Colon,Cste(2)), list())
174         m2sci_insert(Equal(list(LHS), value))
175     end
176 endfunction