]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/cla.m
update packages
[CreaPhase.git] / octave_packages / m / plot / cla.m
1 ## Copyright (C) 2008-2012 Ben Abbott
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} cla ()
21 ## @deftypefnx {Function File} {} cla ("reset")
22 ## @deftypefnx {Function File} {} cla (@var{hax})
23 ## @deftypefnx {Function File} {} cla (@var{hax}, "reset")
24 ## Delete the children of the current axes with visible handles.
25 ## If @var{hax} is specified and is an axes object handle, operate on it
26 ## instead of the current axes.  If the optional argument @code{"reset"}
27 ## is specified, also delete the children with hidden handles.
28 ## @seealso{clf}
29 ## @end deftypefn
30
31 ## Author: Ben Abbott <bpabbott@mac.com>
32 ## Created: 2008-10-03
33
34 function cla (varargin)
35
36   if (nargin > 2)
37     print_usage ();
38   elseif (nargin > 1)
39     if (ishandle (varargin{1})
40         && strcmp (get (varargin{1}, "type"), "axes")
41         && ischar (varargin{2}) && strcmpi (varargin{2}, "reset"))
42       oldhax = gca;
43       hax = varargin{1};
44       do_reset = true;
45     else
46       print_usage ();
47     endif
48   elseif (nargin == 1)
49     if (ishandle (varargin{1})
50         && strcmp (get (varargin{1}, "type"), "axes"))
51       oldhax = gca;
52       hax = varargin{1};
53       do_reset = false;
54     elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset"))
55       hax = gca;
56       oldhax = hax;
57       do_reset = true;
58     else
59       print_usage ();
60     endif
61   else
62     hax = gca;
63     oldhax = hax;
64     do_reset = false;
65   endif
66
67   hc = get (hax, "children");
68
69   if (! do_reset && ! isempty (hc))
70     hc = findobj (hc, "flat", "visible", "on");
71     hc = setdiff (hc, hax);
72   endif
73
74   if (! isempty (hc))
75     ## Delete the children of the axis.
76     delete (hc);
77   endif
78
79   ## FIXME: The defaults should be "reset()" below, but so far there is
80   ## no method to determine the defaults, much less return an object's
81   ## properties to their default values.  Instead make a close
82   ## approximation.
83
84   axes (hax);
85   axis ("auto");
86
87   ## Set the current axis back to where it was upon entry.
88   axes (oldhax);
89
90 endfunction
91
92 %!test
93 %! hf = figure ("visible", "off");
94 %! unwind_protect
95 %!   plot (1:10)
96 %!   cla ()
97 %!   kids = get (gca, "children");
98 %!   cla ()
99 %! unwind_protect_cleanup
100 %!   close (hf)
101 %! end_unwind_protect
102 %! assert (numel (kids), 0)