* Bug #13974 fixed - isoview(xmin, xmax, ymin, ymax) was unhandy.
[scilab.git] / scilab / modules / graphics / macros / isoview.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 // Copyright (C) 2010 - DIGITEO - Pierre Lando <pierre.lando@scilab.org>
4 // Copyright (C) 2016 - Samuel GOUGEON
5 //
6 // Copyright (C) 2012 - 2016 - Scilab Enterprises
7 //
8 // This file is hereby licensed under the terms of the GNU GPL v2.0,
9 // pursuant to article 5.3.4 of the CeCILL v.2.1.
10 // This file was originally licensed under the terms of the CeCILL v2.1,
11 // and continues to be available under such terms.
12 // For more information, see the COPYING file which you should have received
13 // along with this program.
14
15 function isoview(varargin)
16     //isoview
17     //isoview on
18     //isoview off
19     //isoview(idGraphics [,"on"|"off"])
20     //isoview(xmin, xmax, ymin, ymax)  // OBSOLETE
21
22     rhs = argn(2)
23     rhs0 = rhs
24     if rhs==3 | rhs>4 then
25         msg = _("%s: Wrong number of input argument(s): 0, 1, 2, or 4 arguments expected.\n")
26         error(msprintf(msg, "isoview"));
27     end
28
29     // isoview action to be performed: ""=switch, "on", "off"
30     action = ""
31     if rhs>0 & rhs<4 & typeof(varargin($))=="string" then
32         tmp = convstr(varargin($))
33         if tmp(1)=="on"
34             action = "on"
35         elseif tmp(1)=="off"
36             action = "off"
37         end
38     end
39
40     // Set of axes to be processed
41     // ---------------------------
42     if rhs==0 | rhs==4 | (rhs==1 & type(varargin(1))==10)
43         a = gca()
44     elseif rhs<3 // varargin(1) must be a graphics handle
45         a = varargin(1)
46         if type(a)~=9 then
47             msg = _("%s: Wrong type for input argument #%d: Graphic handle or string expected.\n")
48             error(msprintf(msg, "isoview", 1));
49         end
50
51         a0 = a  // vector of input handles
52         a = []  // vector of axes to be processed
53         for i=1:size(a0,"*")
54             thisH = a0(i)
55             if thisH.type=="Figure"
56                 // All the axes of the figure must be isoviewed
57                 tmp = thisH.children
58                 a = [a tmp(find(tmp.type=="Axes"))' ]
59             elseif thisH.type=="Axes"
60                 a = [a thisH]
61             else
62                 while thisH.type~="Axes" & thisH.type~="Figure"
63                     thisH = thisH.parent
64                 end
65                 if thisH.type=="Axes"
66                     a = [a thisH]
67                 end
68                 //no else: if thisH.type=="Figure" => no associated Axes
69             end
70         end
71     end
72
73     // isoview(xmin, xmax, ymin, ymax): checking input bounds
74     // ------------------------------------------------------
75     if rhs>2
76         msg = _("isoview: The syntax isoview(xmin, xmax, ymin, ymax) will be removed from Scilab 6.1\nPlease use replot([xmin xmax ymin ymax]) after isoview(..) instead.\n")
77         warning(msprintf(msg))
78         for i = 1:4
79             if type(varargin(i)) <> 1 then
80                 msg = _("%s: Wrong type for input argument #%d: A real expected.\n")
81                 error(msprintf(msg, "isoview", i))
82             end
83         end;
84         [xmin xmax ymin ymax] = varargin(1:4)
85     end
86
87     // Performing actions
88     // ------------------
89     for i = 1:size(a,"*")
90         tmp = a(i).isoview
91         if action=="on" | (action=="" & tmp=="off")
92             a(i).isoview = "on"
93         else
94             a(i).isoview = "off"
95         end
96         a(i).clip_state = "clipgrf"
97         if rhs>2 then
98             a(i).data_bounds = [xmin xmax ymin ymax]
99         end
100     end
101 endfunction
102