Mercurial > hg > octave-lyh
comparison scripts/plot/hdl2struct.m @ 15011:f34bea431e4f
maint: Use Octave coding standards for copyobj.m, hdl2struct.m, struct2hdl.m.
* copyobj.m, hdl2struct.m, struct2hdl.m: Use Octave coding standards.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 24 Jul 2012 13:41:41 -0700 |
parents | 8f0e3c5bfa5f |
children | dd4ad69e4ab9 |
comparison
equal
deleted
inserted
replaced
15010:f7bcfb3b96e7 | 15011:f34bea431e4f |
---|---|
24 ## @end deftypefn | 24 ## @end deftypefn |
25 | 25 |
26 ## Author: pdiribarne <pdiribarne@new-host.home> | 26 ## Author: pdiribarne <pdiribarne@new-host.home> |
27 ## Created: 2012-03-04 | 27 ## Created: 2012-03-04 |
28 | 28 |
29 function hgS = hdl2struct (h) | 29 function s = hdl2struct (h) |
30 | |
30 if (nargin != 1 || !ishandle (h)) | 31 if (nargin != 1 || !ishandle (h)) |
31 print_usage (); | 32 print_usage (); |
32 endif | 33 endif |
33 | 34 |
34 hiddenh = get (0, "showhiddenhandles"); | 35 hiddenh = get (0, "showhiddenhandles"); |
36 set (0, "showhiddenhandles", "off"); | 37 set (0, "showhiddenhandles", "off"); |
37 endif | 38 endif |
38 | 39 |
39 ## main object | 40 ## main object |
40 main = get (h); | 41 main = get (h); |
41 hgS.handle = h; | 42 s.handle = h; |
42 hgS.type = main.type; | 43 s.type = main.type; |
43 hgS.properties = getprops (h); | 44 s.properties = getprops (h); |
44 hgS.children = []; | 45 s.children = []; |
45 hgS.special = []; | 46 s.special = []; |
46 | 47 |
47 ## sweep all children but legends, colorbars, uimenu and hggroup children | 48 ## sweep all children but legends, colorbars, uimenu and hggroup children |
48 ## in reverse order | 49 ## in reverse order |
49 kids = main.children; | 50 kids = main.children; |
50 lg = findobj (h, "-depth", 1, "tag", "legend"); | 51 lg = findobj (h, "-depth", 1, "tag", "legend"); |
51 cb = findobj (h, "-depth", 1, "tag", "colorbar"); | 52 cb = findobj (h, "-depth", 1, "tag", "colorbar"); |
52 ui = findobj (h, "-depth", 1, "type", "uimenu"); | 53 ui = findobj (h, "-depth", 1, "type", "uimenu"); |
53 nkids = length (kids); | 54 nkids = length (kids); |
54 ii = 0; | 55 ii = 0; |
55 while nkids | 56 while (nkids) |
56 if (! any (kids (nkids) == lg) && !any (kids (nkids) == cb) | 57 if (! any (kids (nkids) == lg) && ! any (kids (nkids) == cb) |
57 && ! any (kids (nkids) == ui) && !strcmpi (main.type, "hggroup")) | 58 && ! any (kids (nkids) == ui) && ! strcmp (main.type, "hggroup")) |
58 ii++; | 59 ii++; |
59 hgS.children(ii) = hdl2struct(kids(nkids)); | 60 s.children(ii) = hdl2struct (kids(nkids)); |
60 endif | 61 endif |
61 nkids--; | 62 nkids--; |
62 endwhile | 63 endwhile |
63 | 64 |
64 ## add non "children" children objects (title, xlabel, ...) and | 65 ## add non "children" children objects (title, xlabel, ...) and |
65 ## hggroup children and tag theim in "special" | 66 ## hggroup children and tag theim in "special" |
66 special = []; | 67 special = []; |
67 if (strcmpi (main.type, "hggroup")) | 68 if (strcmp (main.type, "hggroup")) |
68 special = main.children; | 69 special = main.children; |
69 endif | 70 endif |
70 special = [special getspecial(h)]; | 71 special = [special getspecial(h)]; |
71 nsp = length (special); | 72 nsp = length (special); |
72 while nsp | 73 while (nsp) |
73 ii++; | 74 ii++; |
74 hgS.children(ii) = hdl2struct (special(nsp)); | 75 s.children(ii) = hdl2struct (special(nsp)); |
75 hgS.special(nsp) = ii; | 76 s.special(nsp) = ii; |
76 nsp--; | 77 nsp--; |
77 endwhile | 78 endwhile |
78 | 79 |
79 ## look for legends and colorbars among "main"'s brothers and add them | 80 ## look for legends and colorbars among "main"'s brothers and add them |
80 ## to the children list | 81 ## to the children list |
81 if (strcmpi (main.type, "axes")) | 82 if (strcmp (main.type, "axes")) |
82 par = main.parent; | 83 par = main.parent; |
83 lg = findobj (par, "-depth", 1, "tag", "legend"); | 84 lg = findobj (par, "-depth", 1, "tag", "legend"); |
84 if !isempty (lg) | 85 if !isempty (lg) |
85 idx = arrayfun (@(x) get(x).userdata.handle(end) == h, lg); | 86 idx = arrayfun (@(x) get(x).userdata.handle(end) == h, lg); |
86 lg = lg(find(idx)); | 87 lg = lg(find (idx)); |
87 endif | 88 endif |
88 nlg = length (lg); | 89 nlg = length (lg); |
89 if nlg == 1 | 90 if (nlg == 1) |
90 ii++; | 91 ii++; |
91 hgS.children(ii) = hdl2struct (lg); | 92 s.children(ii) = hdl2struct (lg); |
92 elseif (nlg > 1) | 93 elseif (nlg > 1) |
93 error ("hdl2struct: more than one legend found") | 94 error ("hdl2struct: more than one legend found") |
94 endif | 95 endif |
95 | 96 |
96 cb = findobj (par, "-depth", 1, "tag", "colorbar"); | 97 cb = findobj (par, "-depth", 1, "tag", "colorbar"); |
97 if (! isempty (cb)) | 98 if (! isempty (cb)) |
98 idx = arrayfun (@(x) get(x).axes == h, cb); | 99 idx = arrayfun (@(x) get(x).axes == h, cb); |
99 cb = cb(find(idx)); | 100 cb = cb(find (idx)); |
100 endif | 101 endif |
101 | 102 |
102 ncb = length (cb); | 103 ncb = length (cb); |
103 if (ncb == 1) | 104 if (ncb == 1) |
104 ii++; | 105 ii++; |
105 hgS.children(ii) = hdl2struct(cb); | 106 s.children(ii) = hdl2struct (cb); |
106 elseif (nlg > 1) | 107 elseif (nlg > 1) |
107 error ("hdl2struct: more than one colorbar found") | 108 error ("hdl2struct: more than one colorbar found") |
108 endif | 109 endif |
109 endif | 110 endif |
110 | 111 |
160 for ii = 1:numel (hidden) | 161 for ii = 1:numel (hidden) |
161 if (isprop (h, hidden{ii})) | 162 if (isprop (h, hidden{ii})) |
162 prpstr.(hidden{ii}) = get (h, hidden{ii}); | 163 prpstr.(hidden{ii}) = get (h, hidden{ii}); |
163 endif | 164 endif |
164 endfor | 165 endfor |
166 | |
165 endfunction | 167 endfunction |
166 | 168 |
169 | |
170 ## FIXME: need validation tests |