Mercurial > hg > octave-lyh
annotate scripts/plot/findobj.m @ 8347:fa78cb8d8a5c
corrections for typos
Here is a patch with some corrections for typos and missing/extra
words in the manual.
changeset: 8347:34fd1d1c2294
user: Brian Gough <bjg@gnu.org>
date: Wed Nov 26 11:00:15 2008 -0500
summary: [docs] can not => cannot
author | Brian Gough<bjg@network-theory.co.uk> |
---|---|
date | Thu, 27 Nov 2008 10:28:24 +0100 |
parents | 1c213dff76fc |
children | bc982528de11 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2007 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 -*- | |
20 ## @deftypefn {Function File} {@var{h} =} findobj () | |
21 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{propName}, @var{propValue}) | |
22 ## @deftypefnx {Function File} {@var{h} =} findobj ('-property', @var{propName}) | |
23 ## @deftypefnx {Function File} {@var{h} =} findobj ('-regexp', @var{propName},, @var{pattern}) | |
24 ## @deftypefnx {Function File} {@var{h} =} findobj ('flat', @dots{}) | |
25 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{h}, @dots{}) | |
26 ## @deftypefnx {Function File} {@var{h} =} findobj (@var{h}, '-depth', @var{d}, @dots{}) | |
7001 | 27 ## Find object with specified property values. The simplest form is |
6935 | 28 ## |
29 ## @example | |
30 ## findobj (@var{propName}, @var{propValue}) | |
31 ## @end example | |
32 ## | |
33 ## @noindent | |
34 ## which returns all of the handles to the objects with the name | |
35 ## @var{propName} and the name @var{propValue}. The search can be limited | |
36 ## to a particular object or set of objects and their descendants by | |
37 ## passing a handle or set of handles @var{h} as the first argument to | |
38 ## @code{findobj}. | |
39 ## | |
40 ## The depth of hierarchy of objects to which to search to can be limited | |
41 ## with the '-depth' argument. To limit the number depth of the hierarchy | |
42 ## to search to @var{d} generations of children, and example is | |
43 ## | |
44 ## @example | |
45 ## findobj (@var{h}, '-depth', @var{d}, @var{propName}, @var{propValue}) | |
46 ## @end example | |
47 ## | |
48 ## Specifying a depth @var{d} of 0, limits the search to the set of object | |
49 ## passed in @var{h}. A depth @var{d} of 0 is equivalent to the '-flat' | |
50 ## argument. | |
51 ## | |
52 ## A specified logical operator may be applied to the pairs of @var{propName} | |
53 ## and @var{propValue}. The supported logical operators are '-and', '-or', | |
54 ## '-xor', '-not'. | |
55 ## | |
56 ## The objects may also be matched by comparing a regular expression to the | |
57 ## property values, where property values that match @code{regexp | |
58 ## (@var{propValue}, @var{pattern})} are returned. Finally, objects may be | |
59 ## matched by property name only, using the '-property' option. | |
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})) | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
87 if (strcmpi (varargin{n1}, "flat")) |
6935 | 88 depth = 0; |
89 n1 = n1 + 1; | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
90 elseif (strcmpi (varargin{n1}, "-depth")) |
6935 | 91 depth = varargin{n1+1}; |
92 n1 = n1 + 2; | |
93 endif | |
94 else | |
95 error ("findobj: properties and options must be strings"); | |
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; | |
113 | |
114 while (na <= numel (args)) | |
115 regularexpression(np) = 0; | |
116 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
|
117 logicaloperator{np} = "and"; |
7208 | 118 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
|
119 if (strcmpi (args{na}, "-regexp")) |
6935 | 120 if (na + 2 <= numel (args)) |
121 regularexpression(np) = 1; | |
122 na = na + 1; | |
123 pname{np} = args{na}; | |
124 na = na + 1; | |
125 pvalue{np} = args{na}; | |
126 na = na + 1; | |
127 np = np + 1; | |
128 else | |
129 error ("findobj: inconsistent number of arguments"); | |
130 endif | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
131 elseif (strcmpi (args{na}, "-property")) |
6935 | 132 if (na + 1 <= numel (args)) |
133 na = na + 1; | |
134 property(np) = 1; | |
135 pname{np} = args{na}; | |
136 na = na + 1; | |
137 pvalue{np} = []; | |
138 np = np + 1; | |
139 else | |
140 error ("findobj: inconsistent number of arguments"); | |
141 endif | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
142 elseif (! strcmp (args{na}(1), "-")) # parameter/value pairs |
6935 | 143 if (na + 1 <= numel (args)) |
144 pname{np} = args{na}; | |
145 na = na + 1; | |
146 pvalue{np} = args{na}; | |
147 na = na + 1; | |
148 if (na <= numel(args)) | |
149 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
|
150 if strcmpi(args{na}, "-and") |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
151 logicaloperator{np} = "and"; |
6935 | 152 na = na+1; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
153 elseif strcmpi(args{na}, "-or") |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
154 logicaloperator{np} = "or"; |
6935 | 155 na = na+1; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
156 elseif strcmpi(args{na}, "-xor") |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
157 logicaloperator{np} = "xor"; |
6935 | 158 na = na+1; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
159 elseif strcmpi(args{na}, "-not") |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
160 logicaloperator{np} = "not"; |
6935 | 161 na = na+1; |
162 endif | |
163 else | |
164 error ("findobj: properties and options must be strings"); | |
165 endif | |
166 else | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
167 logicaloperator{np} = "and"; |
6935 | 168 endif |
169 np = np + 1; | |
170 else | |
171 error ("findobj: inconsistent number of arguments"); | |
172 endif | |
173 else | |
174 ## this is sloppy ... but works like matlab | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
175 if strcmpi(args{na}, "-not") |
6935 | 176 h = []; |
177 return | |
178 endif | |
179 na = na + 1; | |
180 endif | |
181 else | |
182 error ("findobj: properties and options must be strings"); | |
183 endif | |
184 endwhile | |
185 | |
186 numpairs = np - 1; | |
187 | |
188 ## load all objects which qualify for being searched | |
189 idepth = 0; | |
190 h = handles; | |
191 while (numel (handles) && ! (idepth >= depth)) | |
192 children = []; | |
193 for n = 1 : numel (handles) | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
194 children = union (children, get(handles(n), "children")); |
6935 | 195 endfor |
196 handles = children; | |
197 h = union (h, children); | |
198 idepth = idepth + 1; | |
199 endwhile | |
200 | |
201 keepers = ones (size (h)); | |
202 if (numpairs > 0) | |
203 for nh = 1 : numel(h) | |
204 p = get (h (nh)); | |
205 for np = 1 : numpairs | |
206 fields = fieldnames (p); | |
207 fieldindex = find (strcmpi (fields, pname{np}), 1); | |
208 if (numel (fieldindex)) | |
209 pname{np} = fields{fieldindex}; | |
210 if (property(np)) | |
211 match = 1; | |
212 else | |
213 if (regularexpression(np)) | |
214 match = regexp (p.(pname{np}), pvalue{np}); | |
215 if isempty (match) | |
216 match = 0; | |
7151 | 217 endif |
6935 | 218 elseif (numel (p.(pname{np})) == numel (pvalue{np})) |
219 if (ischar (pvalue{np})) | |
220 match = strcmpi (pvalue{np}, p.(pname{np})); | |
221 else | |
222 match = (pvalue{np} == p.(pname{np})); | |
223 endif | |
224 else | |
225 match = 0; | |
226 endif | |
227 match = all (match); | |
228 endif | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
7208
diff
changeset
|
229 if (strcmpi (logicaloperator{np}, "not")) |
6935 | 230 keepers(nh) = ! keepers(nh) & ! match; |
231 else | |
232 keepers(nh) = feval (logicaloperator{np}, keepers(nh), match); | |
233 endif | |
234 else | |
235 keepers(nh) = 0; | |
236 endif | |
237 endfor | |
238 endfor | |
239 endif | |
240 | |
241 h = h (keepers != 0); | |
242 h = reshape (h, [numel(h), 1]); | |
243 endfunction |