comparison m-toolbox/classes/@workspaceBrowser/cb_buildModel.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 % CB_BUILDMODEL build the tree model
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 %
5 % $Id: cb_buildModel.m,v 1.5 2010/01/29 09:31:47 hewitson Exp $
6 %
7 function cb_buildModel(varargin)
8
9 wb = getappdata(0, 'WorkspaceBrowser');
10
11 buildModel(wb.hdl);
12
13
14
15 end
16
17
18 function buildModel(wb)
19
20 %% Build workspace
21 ws = mpipeline.workspace.Workspace();
22
23 wvars = evalin('base', 'whos');
24
25 for ll=1:numel(wvars)
26
27 wvar = wvars(ll);
28
29 % get the variable
30 cmd = sprintf('obj = evalin(''base'', ''%s'');', wvar.name);
31 eval(cmd);
32
33 % user object classes
34 if isa(obj, 'ltpda_uoh')
35 ws = addVar(ws, obj, wvar.name);
36 end
37
38 if isstruct(obj)
39 Nobj = numel(obj);
40 for kk=1:Nobj
41 if Nobj > 1
42 ws = addStruct(ws, obj(kk), [wvar.name '(' num2str(kk) ')']);
43 else
44 ws = addStruct(ws, obj, wvar.name);
45 end
46 end
47 end
48
49 end
50
51 %% make and setmodel
52
53 mdl = mpipeline.workspace.WorkspaceTreeModel(ws);
54
55 wb.getWorkspaceTree.setModel(mdl);
56
57 end
58
59 function ws = addStruct(ws, ss, name)
60
61 if ~shouldAddStruct(ss)
62 return
63 end
64
65 % make a new struct
66 wsstruct = mpipeline.workspace.WorkspaceStruct(name);
67
68 % add each field
69 fields = fieldnames(ss);
70
71 for kk=1:numel(fields)
72 field = fields{kk};
73 objs = ss.(field);
74 if ~isnumeric(objs)
75 for ll=1:numel(objs)
76 if isa(objs(ll), 'ltpda_uoh')
77 wsstruct = addVar(wsstruct, ss.(field), field);
78 end
79
80 if isstruct(objs(ll))
81 wsstruct = addStruct(wsstruct, ss.(field), field);
82 end
83 end
84 end
85 end
86
87 % add struct
88 ws.addStruct(wsstruct);
89
90 end
91
92 function res = shouldAddStruct(s)
93 sfields = fieldnames(s);
94 res = false;
95 for pp=1:numel(sfields)
96 sfield = sfields{pp};
97 sobj = s.(sfield);
98 if isstruct(sobj) || isa(sobj, 'ltpda_uoh')
99 res = true;
100 break;
101 end
102 if ~ischar(sobj) && ~isnumeric(sobj) && ~islogical(sobj) && numel(sobj)>1
103 res = true;
104 break;
105 end
106 end
107
108 end
109
110 function ws = addVar(ws, obj, name)
111
112 % make a new var
113 wsvar = mpipeline.workspace.WorkspaceVar(name, class(obj));
114
115 dtxt = display(obj);
116 info = '';
117 for kk=1:numel(dtxt)
118 info = [info [dtxt{kk} '<br>']];
119 end
120
121 wsvar.setInfo(info);
122 % add to the workspace/workspacestruct
123 ws.addVar(wsvar);
124
125 end
126