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