Mercurial > hg > ltpda
comparison m-toolbox/classes/@repogui/cb_treegui.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % TREEGUI for exploring objects in memory | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: TREEGUI builds a tree visual structure to explore objects in | |
5 % memory; this is an optimized version of the ltpda_explorer | |
6 % tree object to explore inside structs, and it's meant to be | |
7 % implemented into the repoGUI. | |
8 % | |
9 % CALL: treegui; | |
10 % | |
11 % VERSION: $Id: cb_treegui.m,v 1.3 2009/07/29 16:19:38 nicola Exp $ | |
12 % | |
13 % HISTORY: 15-02-09 N Tateo | |
14 % Creation | |
15 % | |
16 % NOTE: The idea and the core source code are taken from: | |
17 % Hassan Lahdili (hassan.lahdili@crc.ca) | |
18 % Communications Research Centre (CRC) | Advanced Audio Systems (AAS) | |
19 % www.crc.ca | www.crc.ca/aas | |
20 % Ottawa. Canada | |
21 % CRC Advanced Audio Systems - Ottawa 16/02/2005 2004-2005 | |
22 % | |
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
24 | |
25 function tree = cb_treegui(varargin) | |
26 | |
27 prefs = getappdata(0, 'LTPDApreferences'); | |
28 fontsize = prefs.repository.fontsize; | |
29 | |
30 tree_name = 'Workspace'; | |
31 obj_value = {}; | |
32 obj_name = {}; | |
33 | |
34 % % if nargin==0 | |
35 % % Define figure | |
36 % fig_name = 'Variables in workspace'; | |
37 % fig_position = [150 150 400 600]; | |
38 % fig = figure('NumberTitle','off', 'Toolbar','none', 'name',fig_name, 'Color','w', 'ToolBar','none',... | |
39 % 'NextPlot','new', 'MenuBar','none', 'Position',fig_position); | |
40 % treeSize = [.01 .07 .98 .92]; | |
41 % % else fig = gcf; treeSize = varargin{1}; | |
42 % % end | |
43 | |
44 fig = gcf; | |
45 treeSize = [0.025 1-2*0.025-0.55 0.3 0.5]; | |
46 | |
47 | |
48 % Read the objects from the 'base' workspace | |
49 | |
50 ws_vars = evalin('base','whos'); | |
51 | |
52 % Only ltpda_user_classes and common structs are shown: | |
53 accepted_classes = [utils.helper.ltpda_userclasses(), 'struct']; | |
54 for ii=numel(ws_vars):-1:1 | |
55 if ~ismember(ws_vars(ii).class,accepted_classes) | |
56 ws_vars(ii)=[]; | |
57 end | |
58 end | |
59 clear accepted_classes | |
60 | |
61 for ii=1:length(ws_vars) | |
62 | |
63 obj = evalin('base', ws_vars(ii).name); | |
64 | |
65 if numel(obj) == 1 | |
66 obj_value{end+1} = obj; | |
67 obj_name{end+1} = ws_vars(ii).name; | |
68 | |
69 else | |
70 % the ao in the workspace is a vector | |
71 [n,m] = size(obj); | |
72 if n == 1 || m == 1 | |
73 for jj=1:length(obj) | |
74 obj_value{end+1} = obj(jj); | |
75 obj_name{end+1} = [ws_vars(ii).name '(' num2str(jj) ')']; | |
76 end | |
77 elseif n > 1 && m > 1 | |
78 % the ao in the workspace is a matrix | |
79 for gg = 1:n | |
80 for hh = 1:m | |
81 obj_value{end+1} = obj(gg,hh); | |
82 obj_name{end+1} = [ws_vars(ii).name '(' num2str(gg) ',' num2str(hh) ')']; | |
83 end | |
84 end | |
85 | |
86 else | |
87 error ('### This should not happen: not scalar, nor vector, nor matrix?'); | |
88 end | |
89 | |
90 end | |
91 end | |
92 | |
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
94 % Define the tree % | |
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
96 | |
97 root = uitreenode('v0', tree_name, tree_name, [], false); | |
98 tree = uitree('v0',fig, 'Root',root, 'ExpandFcn', @myExpfcn4); | |
99 set(tree, 'Units', 'normalized') | |
100 set(tree,'MultipleSelectionEnabled',1) | |
101 drawnow; | |
102 set(tree, 'position', treeSize); | |
103 set(tree, 'NodeWillExpandCallback', @nodeWillExpand_cb4); %, ... | |
104 %'NodeSelectedCallback', @nodeSelected_cb4); | |
105 | |
106 % assignin('base','tree',tree) | |
107 tmp = tree.FigureComponent; | |
108 cell_Data = cell(3,1); | |
109 | |
110 | |
111 cell_Data{1} = obj_value; | |
112 cell_Data{2} = root.getRoot; | |
113 cell_Data{3} = obj_name; | |
114 set(tmp, 'UserData', cell_Data); | |
115 | |
116 nodeWillExpand_cb4(tree,[],root); | |
117 myExpfcn4(tree); | |
118 | |
119 end | |
120 | |
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
123 function nodes = myExpfcn4(tree,varargin) | |
124 | |
125 tmp = tree.FigureComponent; | |
126 S = get(tmp, 'UserData'); | |
127 s = S{1}; | |
128 cNode = S{2}; | |
129 [val, cNode] = getcNodevalue(cNode, s); | |
130 ltpda_user_classes = utils.helper.ltpda_userclasses(); | |
131 | |
132 if numel(val)==1 && utils.helper.isobject(val) | |
133 newVal = struct(); | |
134 allfields = fieldnames(val); | |
135 for kk=numel(allfields):-1:1 | |
136 if ismember(allfields{kk},ltpda_user_classes), newVal.(allfields{kk}) = val.(allfields{kk}); end | |
137 end | |
138 val = newVal; | |
139 clear newVal | |
140 end | |
141 [n,m] = size(val); | |
142 count = 0; | |
143 | |
144 %%% Vector or Matrix | |
145 if m>1 || n>1 | |
146 | |
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
148 %%% Vector | |
149 if m==1 || n==1 | |
150 L = length(val); | |
151 | |
152 for J = 1:L | |
153 count = count + 1; | |
154 cNode = S{2}; | |
155 | |
156 iconpath = setIconPath(val{J}); | |
157 if ismember(class(val{J}),ltpda_user_classes), isLeaf = 1; | |
158 else isLeaf = 0; | |
159 end | |
160 | |
161 % disp('--- Running vector') | |
162 level = cNode.getLevel; | |
163 fname = strcat(cNode.getValue, '(', num2str(J),')'); | |
164 if level==0 && ~isempty(S{3}) && numel(S{3}) == numel(S{1}) | |
165 node_str = S{3}(J); | |
166 else | |
167 node_str = fname; | |
168 end | |
169 nodes(count) = uitreenode('v0',fname, node_str, iconpath, isLeaf); | |
170 end | |
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
172 %%% Matrix | |
173 else | |
174 for ii=1:n | |
175 for jj=1:m | |
176 count = count + 1; | |
177 cNode = S{2}; | |
178 % disp('--- Running matrix') | |
179 iconpath = setIconPath(val{ii,jj}); | |
180 if ismember(class(val{ii,jj}),ltpda_user_classes), isLeaf = 1; | |
181 else isLeaf = 0; | |
182 end | |
183 fname = [cNode.getValue '(' num2str(ii) ',' num2str(jj) ')']; | |
184 nodes(count) = uitreenode('v0',fname, fname, iconpath, isLeaf); | |
185 end | |
186 end | |
187 end | |
188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
189 %%% Struct, Object or single value | |
190 else | |
191 %%% | |
192 % val = val; | |
193 if ~isempty(val) | |
194 fnames = fieldnames(val); | |
195 else | |
196 fnames = {}; | |
197 end | |
198 | |
199 for i=1:length(fnames) | |
200 count = count + 1; | |
201 % disp('--- Running else') | |
202 x = val.(fnames{i}); | |
203 if iscell(x), x = x{1}; end | |
204 | |
205 if isstruct(x), isLeaf = 0; | |
206 else isLeaf = 1; | |
207 end | |
208 iconpath = setIconPath(x); | |
209 nodes(count) = uitreenode('v0',fnames{i}, fnames{i}, iconpath, isLeaf); | |
210 | |
211 end | |
212 end | |
213 | |
214 if (count == 0) | |
215 nodes = []; | |
216 end | |
217 end | |
218 | |
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
220 | |
221 function cNode = nodeWillExpand_cb4(tree,ev,varargin) | |
222 if isempty(ev) && nargin ==3 | |
223 cNode = varargin{1}.getRoot; | |
224 else | |
225 cNode = ev.getCurrentNode; | |
226 end | |
227 tmp = tree.FigureComponent; | |
228 cell_Data = get(tmp, 'UserData'); | |
229 cell_Data{2} = cNode; | |
230 set(tmp, 'UserData', cell_Data); | |
231 | |
232 end | |
233 | |
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
235 function [val, displayed, cNode] = getcNodevalue(cNode, s) | |
236 | |
237 % disp('------- Running getcNodevalue ') | |
238 fields = {}; | |
239 while cNode.getLevel ~=0 | |
240 fields = [fields; cNode.getValue]; | |
241 c = findstr(cNode.getValue, '('); | |
242 if ~isempty(c) && cNode.getLevel ~=0 | |
243 cNode = cNode.getParent; | |
244 end | |
245 | |
246 if cNode.getLevel ==0, break; end | |
247 cNode = cNode.getParent; | |
248 end | |
249 val = s; | |
250 | |
251 if ~isempty(fields) | |
252 L=length(fields); | |
253 displayed = fields{L}; | |
254 % create the variable: displayed | |
255 for j = L-1:-1:1 | |
256 displayed = strcat(displayed, '.', fields{j}); | |
257 end | |
258 | |
259 for i = L:-1:1 | |
260 field = fields{i}; | |
261 von = findstr(field,'('); | |
262 bis = findstr(field,')'); | |
263 if ~isempty(von) | |
264 | |
265 idx = field(von+1:bis-1); | |
266 field = field(1:von-1); | |
267 if (strcmp(field, cNode.getValue)) | |
268 cmd = sprintf('val = val(%s);',idx); | |
269 eval(cmd); | |
270 if iscell(val) && numel(val) == 1 | |
271 val = val{1}; | |
272 else | |
273 error('################'); | |
274 end | |
275 else | |
276 | |
277 cmd = sprintf('val = getfield(val, field, {%s});',idx); | |
278 eval(cmd); | |
279 if iscell(val) && numel(val) == 1 | |
280 val = val{1}; | |
281 end | |
282 | |
283 end | |
284 | |
285 else | |
286 if iscell(val) && numel(val) == 1 | |
287 val = val{1}; | |
288 elseif numel(val) ~= 1 | |
289 error('################ MAch mich neu'); | |
290 end | |
291 val = val.(field); | |
292 end | |
293 end | |
294 else | |
295 displayed = cNode.getValue; | |
296 if iscell(val) && numel(val) == 1 | |
297 val = val{1}; | |
298 else | |
299 end | |
300 return; | |
301 end | |
302 end | |
303 | |
304 | |
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
306 function iconpath = setIconPath(val) | |
307 % Set the path to the *.gif files | |
308 % This is the current path of this function + 'exp_struct_icons' | |
309 pth = ''; | |
310 eval (sprintf('pth = which(''%s'');',mfilename)) | |
311 index = find(pth==filesep, 1, 'last'); | |
312 pth = pth(1:index); | |
313 pth = [pth 'exp_struct_icons' filesep]; | |
314 | |
315 if isa(val, 'ao') | |
316 iconpath =[pth,'analysis_object.gif']; | |
317 elseif isa(val, 'tsdata') | |
318 iconpath =[pth,'ts_data.gif']; | |
319 elseif isa(val, 'fsdata') | |
320 iconpath =[pth,'fs_data.gif']; | |
321 elseif isa(val, 'xydata') | |
322 iconpath =[pth,'xy_data.gif']; | |
323 elseif isa(val, 'cdata') | |
324 iconpath =[pth,'c_data.gif']; | |
325 elseif isa(val, 'plist') | |
326 iconpath =[pth,'plist.gif']; | |
327 elseif isstruct(val) | |
328 iconpath =[pth,'obj_icon.gif']; | |
329 else | |
330 iconpath =[pth,'unknown_icon.gif']; | |
331 end | |
332 | |
333 end | |
334 | |
335 |