]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/ishold.m
update packages
[CreaPhase.git] / octave_packages / m / plot / ishold.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  {Command} {} ishold
21 ## @deftypefnx {Function File} {} ishold (@var{h})
22 ## Return true if the next plot will be added to the current plot, or
23 ## false if the plot device will be cleared before drawing the next plot.
24 ##
25 ## Optionally, operate on the graphics handle @var{h} rather than the current
26 ## plot.
27 ## @seealso{hold}
28 ## @end deftypefn
29
30 function retval = ishold (h)
31
32   if (nargin == 0)
33     fig = gcf ();
34     ax = get (fig, "currentaxes");
35   elseif (nargin == 1)
36     if (ishandle (h))
37       if (isfigure (h))
38         ax = get (h, "currentaxes");
39         fig = h;
40       elseif (strcmpi (get (h, "type"), "axes"))
41         ax = h;
42         fig = get (h, "parent");
43       else
44         error ("ishold: expecting argument to be axes or figure graphics handle");
45       endif
46     else
47       error ("ishold: expecting argument to be axes or figure graphics handle");
48     endif
49   else
50     print_usage ();
51   endif
52
53   retval = (strcmpi (get (fig, "nextplot"), "add")
54             && ! isempty (ax) && strcmpi (get (ax, "nextplot"), "add"));
55
56 endfunction
57
58 %!test
59 %! hf = figure ("visible", "off");
60 %! unwind_protect
61 %!   assert (!ishold);
62 %!   assert (isempty (get (hf, "currentaxes")));
63 %!   assert (get (hf, "NextPlot"), "add");
64 %!   l = plot ([0 1]);
65 %!   assert (!ishold);
66 %!   assert (!ishold (gca));
67 %!   assert (get (gca, "NextPlot"), "replace");
68 %!   assert (get (hf, "NextPlot"), "add");
69 %!   hold;
70 %!   assert (ishold);
71 %!   assert (ishold (gca));
72 %!   assert (get (gca, "NextPlot"), "add");
73 %!   assert (get (hf, "NextPlot"), "add");
74 %!   p = fill ([0 1 1], [0 0 1],"black");
75 %!   assert (length (get (hf, "children")), 1);
76 %!   assert (length (get (gca, "children")), 2);
77 %! unwind_protect_cleanup
78 %!   close (hf);
79 %! end_unwind_protect