]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/clf.m
update packages
[CreaPhase.git] / octave_packages / m / plot / clf.m
1 ## Copyright (C) 2005-2012 John W. Eaton
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} {} clf ()
21 ## @deftypefnx {Function File} {} clf ("reset")
22 ## @deftypefnx {Function File} {} clf (@var{hfig})
23 ## @deftypefnx {Function File} {} clf (@var{hfig}, "reset")
24 ## @deftypefnx {Function File} {@var{h} =} clf (@dots{})
25 ## Clear the current figure window.  @code{clf} operates by deleting child
26 ## graphics objects with visible handles (@code{handlevisibility} = on).
27 ## If @var{hfig} is specified operate on it instead of the current figure.
28 ## If the optional argument @code{"reset"} is specified, all objects including
29 ## those with hidden handles are deleted.
30 ## 
31 ## The optional return value @var{h} is the graphics handle of the figure
32 ## window that was cleared.
33 ## @seealso{cla, close, delete}
34 ## @end deftypefn
35
36 ## Author: jwe
37
38 function retval = clf (varargin)
39
40   if (nargin > 2)
41     print_usage ();
42   elseif (nargin > 1)
43     if (isfigure (varargin{1}) && ischar (varargin{2})
44         && strcmpi (varargin{2}, "reset"))
45       oldfig = gcf;
46       hfig = varargin{1};
47       do_reset = true;
48     else
49       print_usage ();
50     endif
51   elseif (nargin == 1)
52     if (isfigure (varargin{1}))
53       oldfig = gcf;
54       hfig = varargin{1};
55       do_reset = false;
56     elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset"))
57       hfig = gcf;
58       oldfig = hfig;
59       do_reset = true;
60     else
61       print_usage ();
62     endif
63   else
64     hfig = gcf;
65     oldfig = hfig;
66     do_reset = false;
67   endif
68
69   if (do_reset)
70     ## Select all the children, including the one with hidden handles.
71     hc = allchild (hfig);
72     reset (hfig);
73   else
74     ## Select only the chilren with visible handles.
75     hc = get (hfig, "children");
76   endif
77
78   ## Delete the children.
79   delete (hc);
80
81   if (nargout > 0)
82     retval = hfig;
83   endif
84
85 endfunction
86
87
88 %!test
89 %! hf = figure ("visible", "off");
90 %! unwind_protect
91 %!   l = line;
92 %!   assert (!isempty (get (gcf, "children")));
93 %! unwind_protect_cleanup
94 %!   close (hf);
95 %! end_unwind_protect
96
97 %!test
98 %! hf = figure ("visible", "off");
99 %! unwind_protect
100 %!   clf;
101 %!   assert (isempty (get (gcf, "children")));
102 %! unwind_protect_cleanup
103 %!   close (hf);
104 %! end_unwind_protect
105