annotate scripts/plot/findobj.m @ 17238:3fd617363762

findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767). * scripts/plot/findobj.m: Use concatenation rather than union to join lists of handles together. Update %!tests to reflect new ordering. * scripts/plot/findall.m: Update %!tests to reflect new ordering.
author Rik <rik@octave.org>
date Tue, 13 Aug 2013 16:38:25 -0700
parents eaab03308c0b
children bc924baa2c4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14001
diff changeset
1 ## Copyright (C) 2007-2012 Ben Abbott
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
2 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
3 ## This file is part of Octave.
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
4 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 ## General Public License for more details.
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
14 ##
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
18
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {@var{h} =} findobj ()
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
21 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{prop_name}, @var{prop_value}, @dots{})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
22 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{prop_name}, @var{prop_value}, "-@var{logical_op}", @var{prop_name}, @var{prop_value})
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## @deftypefnx {Function File} {@var{h} =} findobj ("-property", @var{prop_name})
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
24 ## @deftypefnx {Function File} {@var{h} =} findobj ("-regexp", @var{prop_name}, @var{pattern})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
25 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{hlist}, @dots{})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
26 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{hlist}, "flat", @dots{})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
27 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{hlist}, "-depth", @var{d}, @dots{})
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
28 ## Find graphics object with specified property values.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
29 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
30 ## The simplest form is
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
31 ##
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
32 ## @example
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
33 ## findobj (@var{prop_name}, @var{prop_value})
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
34 ## @end example
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
35 ##
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
36 ## @noindent
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
37 ## which returns the handles of all objects which have a property named
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
38 ## @var{prop_name} that has the value @var{prop_value}. If multiple
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
39 ## property/value pairs are specified then only objects meeting all of the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
40 ## conditions are returned.
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
41 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
42 ## The search can be limited to a particular set of objects and their
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
43 ## descendants, by passing a handle or set of handles @var{hlist} as the first
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
44 ## argument.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
45 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
46 ## The depth of the object hierarchy to search can be limited with the "-depth"
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
47 ## argument. An example of searching only three generations of children is:
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
48 ##
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
49 ## @example
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
50 ## findobj (@var{hlist}, "-depth", @var{d}, @var{prop_name}, @var{prop_value})
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
51 ## @end example
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
52 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
53 ## Specifying a depth @var{d} of 0, limits the search to the set of objects
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
54 ## passed in @var{hlist}. A depth @var{d} of 0 is equivalent to the "flat"
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
55 ## argument.
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
56 ##
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 ## A specified logical operator may be applied to the pairs of @var{prop_name}
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
58 ## and @var{prop_value}. The supported logical operators are: "-and", "-or",
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 ## "-xor", "-not".
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
60 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
61 ## Objects may also be matched by comparing a regular expression to the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
62 ## property values, where property values that match
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
63 ## @code{regexp (@var{prop_value}, @var{pattern})} are returned.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
64 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
65 ## Finally, objects may be matched by property name only by using the
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
66 ## "-property" option.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
67 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
68 ## Implementation Note: The search only includes objects with visible
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
69 ## handles ("HandleVisibility" = "on"). @xref{XREFfindall,,findall}, to
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
70 ## search for all objects including hidden ones.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17119
diff changeset
71 ## @seealso{findall, allchild, get, set}
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
72 ## @end deftypefn
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
73
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
74 ## Author: Ben Abbott <bpabbott@mac.com>
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
75
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
76 function h = findobj (varargin)
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
77
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
78 depth = NaN;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
79 if (nargin == 0)
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
80 handles = 0;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
81 n1 = 0;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
82 else
8265
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
83 if (! isempty (varargin{1}))
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
84 if (ishandle (varargin{1}(1)))
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
85 handles = varargin{1};
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
86 n1 = 2;
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
87 else
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
88 handles = 0;
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
89 n1 = 1;
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
90 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
91 else
8265
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
92 ## Return [](0x1) for compatibility.
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
93 h = zeros (0, 1);
1c213dff76fc findobj.m: allow handle to be empty
Ben Abbott <bpabbott@mac.com>
parents: 8190
diff changeset
94 return;
7151
aeeb646f6538 [project @ 2007-11-09 19:34:17 by jwe]
jwe
parents: 7017
diff changeset
95 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
96 if (n1 <= nargin)
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
97 if (ischar (varargin{n1}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
98 if (strcmpi (varargin{n1}, "flat"))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
99 depth = 0;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
100 n1 = n1 + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
101 elseif (strcmpi (varargin{n1}, "-depth"))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
102 depth = varargin{n1+1};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
103 n1 = n1 + 2;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
104 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
105 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
106 error ("findobj: properties and options must be strings");
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
107 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
108 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
109 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
110
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
111 if (n1 <= nargin && nargin > 0)
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
112 args = varargin(n1 : nargin);
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
113 else
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
114 args = {};
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
115 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
116
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
117 regularexpression = [];
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
118 property = [];
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
119 logicaloperator = {};
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
120 pname = {};
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
121 pvalue = {};
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
122 np = 1;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
123 na = 1;
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
124 operatorprecedence = {"-not", "-and", "-or", "-xor"};
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
125
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
126 while (na <= numel (args))
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
127 regularexpression(np) = 0;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
128 property(np) = 0;
8190
73d6b71788c0 use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents: 7208
diff changeset
129 logicaloperator{np} = "and";
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7151
diff changeset
130 if (ischar (args{na}))
8190
73d6b71788c0 use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents: 7208
diff changeset
131 if (strcmpi (args{na}, "-regexp"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
132 if (na + 2 <= numel (args))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
133 regularexpression(np) = 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
134 na = na + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
135 pname{np} = args{na};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
136 na = na + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
137 pvalue{np} = args{na};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
138 na = na + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
139 np = np + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
140 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
141 error ("findobj: inconsistent number of arguments");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
142 endif
8190
73d6b71788c0 use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents: 7208
diff changeset
143 elseif (strcmpi (args{na}, "-property"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
144 if (na + 1 <= numel (args))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
145 na = na + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
146 property(np) = 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
147 pname{np} = args{na};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
148 na = na + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
149 pvalue{np} = [];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
150 np = np + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
151 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
152 error ("findobj: inconsistent number of arguments");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
153 endif
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8265
diff changeset
154 elseif (! strcmp (args{na}(1), "-"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
155 ## Parameter/value pairs.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
156 if (na + 1 <= numel (args))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
157 pname{np} = args{na};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
158 na = na + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
159 pvalue{np} = args{na};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
160 na = na + 1;
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
161 if (na <= numel (args))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
162 if (ischar (args{na}))
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
163 if (any (strcmpi (args{na}, operatorprecedence)))
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
164 logicaloperator{np} = args{na}(2:end);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
165 na = na+1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
166 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
167 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
168 error ("findobj: properties and options must be strings");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
169 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
170 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
171 logicaloperator{np} = "and";
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
172 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
173 np = np + 1;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
174 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
175 error ("findobj: inconsistent number of arguments");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
176 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
177 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
178 ## This is sloppy ... but works like Matlab.
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14327
diff changeset
179 if (strcmpi (args{na}, "-not"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
180 h = [];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
181 return
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
182 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
183 na = na + 1;
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
184 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
185 else
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
186 error ("findobj: properties and options must be strings");
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
187 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
188 endwhile
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
189
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
190 numpairs = np - 1;
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
191 if (~ isempty (logicaloperator))
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
192 logicaloperator = shift (logicaloperator, 1);
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
193 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
194
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8265
diff changeset
195 ## Load all objects which qualify for being searched.
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
196 idepth = 0;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
197 h = handles;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
198 while (numel (handles) && ! (idepth >= depth))
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
199 children = [];
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
200 for n = 1 : numel (handles)
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
201 children = [children; get(handles(n), "children")];
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
202 endfor
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
203 handles = children;
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
204 h = [h; children];
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
205 idepth = idepth + 1;
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
206 endwhile
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
207
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
208 if (numpairs > 0)
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
209 match = true (numel (h), numpairs);
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
210 for nh = 1 : numel (h)
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
211 p = get (h(nh));
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
212 for np = 1 : numpairs
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
213 fields = fieldnames (p);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
214 fieldindex = find (strcmpi (fields, pname{np}), 1);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
215 if (numel (fieldindex))
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
216 pname{np} = fields{fieldindex};
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
217 if (property(np))
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
218 match(nh,np) = true;
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
219 else
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
220 if (regularexpression(np))
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
221 foo = regexp (p.(pname{np}), pvalue{np}, "once");
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
222 if (isempty (foo))
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
223 match(nh,np) = false;
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
224 else
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
225 match(nh,np) = foo;
7151
aeeb646f6538 [project @ 2007-11-09 19:34:17 by jwe]
jwe
parents: 7017
diff changeset
226 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
227 elseif (numel (p.(pname{np})) == numel (pvalue{np}))
16895
b8c37a855074 Modify findobj() to work with cells and structures.
Ben Abbott <bpabbott@mac.com>
parents: 16673
diff changeset
228 if (ischar (pvalue{np}) && ischar (p.(pname{np})))
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
229 match(nh,np) = strcmpi (pvalue{np}, p.(pname{np}));
16895
b8c37a855074 Modify findobj() to work with cells and structures.
Ben Abbott <bpabbott@mac.com>
parents: 16673
diff changeset
230 elseif (isnumeric (pvalue{np} && isnumeric (p.(pname{np}))))
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
231 match(nh,np) = (pvalue{np} == p.(pname{np}));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
232 else
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
233 match(nh,np) = isequal (pvalue{np}, p.(pname{np}));
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
234 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
235 else
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
236 match(nh,np) = false;
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
237 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
238 endif
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
239 else
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
240 match(nh,np) = false;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9040
diff changeset
241 endif
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
242 endfor
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
243 endfor
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
244
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
245 if (numpairs > 1)
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
246 for no = 1 : numel (operatorprecedence)
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
247 pairs = find (strcmp (logicaloperator(2:end), ...
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
248 operatorprecedence{no}(2:end)));
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
249 for np = sort (pairs, "descend")
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
250 if (no == 1)
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
251 match(:,np+1) = ! match(:,np+1);
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
252 logicaloperator(np+1) = {"and"};
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
253 else
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
254 match(:,np) = feval (logicaloperator{np+1}, match(:,np), ...
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
255 match(:,np+1));
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
256 logicaloperator(np+1) = [];
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
257 match(:,np+1) = [];
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
258 numpairs = numpairs - 1;
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
259 endif
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
260 if (numpairs < 2)
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
261 break;
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
262 endif
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
263 endfor
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
264 if (numpairs < 2)
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
265 break;
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
266 endif
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
267 endfor
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
268 endif
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
269 else
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
270 match = true (numel (h), 1);
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
271 endif
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
272
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
273 h = h(match);
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
274 h = h(:);
6935
5cd272497aae [project @ 2007-09-30 19:16:49 by dbateman]
dbateman
parents:
diff changeset
275 endfunction
13096
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
276
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
277
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
278 %!test
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
279 %! hf = figure ("visible", "off");
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
280 %! unwind_protect
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
281 %! h = findobj (gca (), "-property", "foo");
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
282 %! assert (isempty (h));
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
283 %! unwind_protect_cleanup
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
284 %! close (hf);
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
285 %! end_unwind_protect
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
286
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
287 %!test
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
288 %! hf = figure ("visible", "off");
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
289 %! unwind_protect
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
290 %! h = plot (1:10);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
291 %! set (h, "tag", "foobar");
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
292 %! g = findobj (gcf (), "tag", "foobar", "type", "line", "color", [0 0 1]);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
293 %! assert (g, h);
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
294 %! unwind_protect_cleanup
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
295 %! close (hf);
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
296 %! end_unwind_protect
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
297
13096
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
298 %!test
13124
2ea1658ad049 Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents: 13111
diff changeset
299 %! hf = figure ("visible", "off");
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13124
diff changeset
300 %! unwind_protect
13096
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
301 %! l = line;
13111
ebb42fb2da04 Various fixes for tests in scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 13096
diff changeset
302 %! obj = findobj (hf, "type", "line");
13096
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
303 %! assert (l, obj);
13111
ebb42fb2da04 Various fixes for tests in scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 13096
diff changeset
304 %! assert (gca, findobj (hf, "type", "axes"));
13124
2ea1658ad049 Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents: 13111
diff changeset
305 %! assert (hf, findobj (hf, "type", "figure"));
13111
ebb42fb2da04 Various fixes for tests in scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 13096
diff changeset
306 %! assert (isempty (findobj (hf, "type", "xyzxyz")));
13096
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
307 %! unwind_protect_cleanup
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
308 %! close (hf);
5553412c6614 Tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
309 %! end_unwind_protect
14001
5f0bb45e615c doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
310
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
311 %!test
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
312 %! hf = figure ("visible", "off");
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
313 %! unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
314 %! subplot (2,2,1);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
315 %! imagesc (rand (10));
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
316 %! subplot (2,2,2);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
317 %! surf (peaks);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
318 %! subplot (2,2,3);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
319 %! contour (peaks);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
320 %! subplot (2,2,4);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
321 %! plot (peaks);
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
322 %! h1 = findobj (gcf (), "-regexp", "Type", "image|surface|hggroup");
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
323 %! h2 = findobj (gcf (), "Type", "image",
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
324 %! "-or", "Type", "surface",
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
325 %! "-or", "Type", "hggroup");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
326 %! assert (h2, h1);
16673
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
327 %! unwind_protect_cleanup
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
328 %! close (hf);
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
329 %! end_unwind_protect
092d0a685546 Fix bug # 38885.
Ben Abbott <bpabbott@mac.com>
parents: 14868
diff changeset
330
16895
b8c37a855074 Modify findobj() to work with cells and structures.
Ben Abbott <bpabbott@mac.com>
parents: 16673
diff changeset
331 %!test
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 16905
diff changeset
332 %! toolkit = graphics_toolkit ("gnuplot");
17119
bd50e0660545 test: Add missing semicolons to suppress output in some plot %!tests.
Rik <rik@octave.org>
parents: 17107
diff changeset
333 %! hf = figure ("visible", "off");
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
334 %! unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
335 %! h1 = subplot (2,2,1);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
336 %! h2 = subplot (2,2,2);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
337 %! h3 = subplot (2,2,3, "userdata", struct ("foo", "bar"));
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
338 %! h4 = subplot (2,2,4);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
339 %! h = findobj (hf, "userdata", struct ("foo", "bar"));
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
340 %! assert (h, h3);
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
341 %! unwind_protect_cleanup
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
342 %! close (hf);
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 16905
diff changeset
343 %! graphics_toolkit (toolkit);
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
344 %! end_unwind_protect
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
345
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
346 %!test
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 16905
diff changeset
347 %! toolkit = graphics_toolkit ("gnuplot");
17119
bd50e0660545 test: Add missing semicolons to suppress output in some plot %!tests.
Rik <rik@octave.org>
parents: 17107
diff changeset
348 %! hf = figure ("visible", "off");
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
349 %! unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
350 %! h1 = subplot (2,2,1, "tag", "1");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
351 %! h2 = subplot (2,2,2, "tag", "2");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
352 %! h3 = subplot (2,2,3, "tag", "3");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
353 %! h4 = subplot (2,2,4, "tag", "4");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
354 %! h = findobj (hf, "type", "axes", "-not", "tag", "1");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
355 %! assert (h, [h4; h3; h2])
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
356 %! unwind_protect_cleanup
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
357 %! close (hf);
17107
dbd64c9a16da Restore graphics toolkit after %!tests that alter it.
Rik <rik@octave.org>
parents: 16905
diff changeset
358 %! graphics_toolkit (toolkit);
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
359 %! end_unwind_protect
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
360
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
361 %!test
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
362 %! hf = figure ("visible", "off");
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
363 %! unwind_protect
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
364 %! h1 = subplot (2, 2, 1);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
365 %! set (h1, "userdata", struct ("column", 1, "row", 1));
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
366 %! h2 = subplot (2, 2, 2);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
367 %! set (h2, "userdata", struct ("column", 2, "row", 1));
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
368 %! h3 = subplot (2, 2, 3);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
369 %! set (h3, "userdata", struct ("column", 1, "row", 2));
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
370 %! h4 = subplot (2, 2, 4);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
371 %! set (h4, "userdata", struct ("column", 2, "row", 2));
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
372 %! h = findobj (hf, "type", "axes",
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
373 %! "-not", "userdata", struct ("column", 1, "row", 1));
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
374 %! unwind_protect_cleanup
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
375 %! close (hf);
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
376 %! end_unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
377 %! assert (h, [h4; h3; h2])
16897
21d5e76891fe Fix typo/bug for "-not" qualifier in findobj(). Add tests.
Ben Abbott <bpabbott@mac.com>
parents: 16895
diff changeset
378
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
379 %!test
16900
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
380 %! hf = figure ("visible", "off");
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
381 %! unwind_protect
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
382 %! ha = axes ();
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
383 %! plot (1:10);
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
384 %! h = findobj (hf, "type", "figure",
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
385 %! "-or", "parent", hf,
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
386 %! "-and", "type", "axes");
16900
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
387 %! unwind_protect_cleanup
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
388 %! close (hf)
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
389 %! end_unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
390 %! assert (h, [hf; ha])
16900
434a0b29ab12 Add xtest for findobj() for pecedence of logical operations.
Ben Abbott <bpabbott@mac.com>
parents: 16897
diff changeset
391
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
392 %!test
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
393 %! hf = figure ("visible", "off");
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
394 %! unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
395 %! set (hf, "tag", "foo");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
396 %! h1 = subplot (2,2,1, "tag", "foo");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
397 %! h2 = subplot (2,2,2, "tag", "bar");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
398 %! h3 = subplot (2,2,3, "tag", "foo");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
399 %! h4 = subplot (2,2,4, "tag", "bar");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
400 %! h = findobj (hf, "type", "axes", "-xor", "tag", "foo");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
401 %! assert (h, [hf; h4; h2]);
16905
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
402 %! unwind_protect_cleanup
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
403 %! close (hf);
562301c71bd3 Respect logical operator precedence for findobj()'s inputs.
Ben Abbott <bpabbott@mac.com>
parents: 16900
diff changeset
404 %! end_unwind_protect
17238
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
405
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
406 %!test
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
407 %! hf = figure ("visible", "off");
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
408 %! unwind_protect
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
409 %! hax1 = subplot (2,1,1);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
410 %! hl1 = plot (rand (10,1));
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
411 %! hax2 = subplot (2,1,2);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
412 %! hl2 = plot (rand (10,1));
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
413 %! hobj = findobj (hf);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
414 %! assert (hobj, [hf; hax2; hax1; hl2; hl1]);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
415 %! unwind_protect_cleanup
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
416 %! close (hf);
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
417 %! end_unwind_protect
3fd617363762 findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
Rik <rik@octave.org>
parents: 17122
diff changeset
418