Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDAworkbench/rebuildLibrary.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 % REBUILDLIBRARY rebuilds the library on the workbench by processing the | |
2 % ltpda_versions cell-array. | |
3 % | |
4 % CALL: wb.rebuildLibrary | |
5 % | |
6 % M Hewitson 11-10-08 | |
7 % | |
8 % $Id: rebuildLibrary.m,v 1.17 2011/04/28 13:26:26 hewitson Exp $ | |
9 % | |
10 function varargout = rebuildLibrary(varargin) | |
11 % setup library | |
12 lib = mpipeline.jltpda.LTPDAlibrary('LTPDA'); | |
13 % Get current verbose level | |
14 prefs = getappdata(0, 'LTPDApreferences'); | |
15 vl = double(prefs.getDisplayPrefs.getDisplayVerboseLevel); | |
16 prefs.getDisplayPrefs.setDisplayVerboseLevel(java.lang.Integer(-1)); | |
17 % Add each user class | |
18 ucls = utils.helper.ltpda_userclasses; | |
19 | |
20 % Add any user-class subclasses from extension modules | |
21 searchPaths = prefs.getExtensionsPrefs.getSearchPaths; | |
22 for kk=0:searchPaths.size-1 | |
23 % path to the new classes | |
24 path = fullfile(char(searchPaths.get(kk)), 'classes'); | |
25 % get a list of class directories | |
26 classdirs = utils.prog.dirscan(path, '@.*'); | |
27 for jj=1:numel(classdirs) | |
28 parts = regexp(classdirs{jj}, '@', 'split'); | |
29 cldir = parts{end}; | |
30 md = meta.class.fromName(cldir); | |
31 if utils.helper.isSubclassOf(md, 'ltpda_uo') | |
32 fprintf('+ adding user-object class %s from extension %s\n', md.Name, path); | |
33 ucls = [ucls {md.Name}]; | |
34 end | |
35 end | |
36 end | |
37 | |
38 cats = utils.const.categories.list; | |
39 cats = cats(~strcmp(cats, 'Internal')); | |
40 cats = cats(~strcmp(cats, 'GUI function')); | |
41 warning off | |
42 | |
43 %% Build the infrastructure first | |
44 for jj=1:numel(ucls) | |
45 clcat = mpipeline.jltpda.LTPDAcategory(ucls{jj}); | |
46 lib.addCategory(clcat); | |
47 end | |
48 | |
49 % Now go through and add the contents | |
50 for jj=1:numel(ucls) | |
51 clcat = lib.getCategoryByName(ucls{jj}); | |
52 disp(sprintf('** Building: %s', ucls{jj})); | |
53 % add each algorithm for this class/category | |
54 [clmethods, infos] = getPublicMethods(ucls{jj}); | |
55 % add each method to its subcategory | |
56 for ll=1:numel(clmethods) | |
57 ii = infos(ll); | |
58 mthCategory = ii.mcategory; | |
59 cat = clcat.getCategoryByName(mthCategory); | |
60 if isempty(cat) | |
61 if ~strcmp(mthCategory, 'Internal') && ~strcmp(mthCategory, 'GUI function') | |
62 cat = mpipeline.jltpda.LTPDAcategory(mthCategory); | |
63 clcat.addSubCategory(cat); | |
64 end | |
65 end | |
66 % else | |
67 if ~isempty(cat) | |
68 disp(sprintf(' + adding method %s/%s to category %s', ucls{jj}, clmethods{ll}, char(cat.getName))) | |
69 a = LTPDAworkbench.minfo2algo(ii); | |
70 a.setParamsHTML(html(ii)); | |
71 cat.addAlgorithm(a); | |
72 end | |
73 end | |
74 end | |
75 warning on | |
76 if nargin > 0 | |
77 wb = varargin{1}; | |
78 awtinvoke(wb.mp, 'setLibrary', lib); | |
79 awtinvoke(wb.mp, 'refreshLibraryTree'); | |
80 end | |
81 % set verbose level again | |
82 prefs.getDisplayPrefs.setDisplayVerboseLevel(java.lang.Integer(vl)); | |
83 if nargout > 0 | |
84 varargout{1} = lib; | |
85 end | |
86 end | |
87 | |
88 | |
89 function [mths, infos] = getPublicMethods(cl) | |
90 | |
91 disp(sprintf(' collecting methods for %s class...', cl)); | |
92 mths = {}; | |
93 | |
94 cms = eval(['?' cl]); | |
95 infos = []; | |
96 for ll=1:numel(cms.Methods) | |
97 | |
98 mt = cms.Methods{ll}; | |
99 if ~mt.Static && ... | |
100 ~mt.Hidden && ... | |
101 strcmpi(mt.Access, 'public') && ... | |
102 ~strcmpi(cms.Methods{ll}.DefiningClass.Name, 'handle') | |
103 | |
104 % get category | |
105 try | |
106 cmd = sprintf('%s.getInfo(''%s'');', cl, mt.Name); | |
107 ii = eval(cmd); | |
108 % disp([' found method: ' mt.Name]); | |
109 mths = [mths {ii.mname}]; | |
110 infos = [infos ii]; | |
111 catch | |
112 warning('### could not get info about: %s', mt.Name); | |
113 end | |
114 end | |
115 | |
116 end | |
117 | |
118 [mths,i,j] = unique(mths); | |
119 infos = infos(i); | |
120 | |
121 | |
122 end | |
123 | |
124 % Make an html table of the minfo object suitable for display on the GUI | |
125 % help pane. | |
126 function txt = html(ii) | |
127 | |
128 txt = ''; | |
129 % Table of the minfo object | |
130 txt = [txt sprintf(' <table cellspacing="0" class="body" cellpadding="2" border="1" width="60%%">\n')]; | |
131 txt = [txt sprintf(' <thead>\n')]; | |
132 txt = [txt sprintf(' <tr valign="top">\n')]; | |
133 txt = [txt sprintf(' <th class="categorylist" colspan="2">Some information of the method %s/%s are listed below:</th>\n', ii.mclass, ii.mname)]; | |
134 txt = [txt sprintf(' </tr>\n')]; | |
135 txt = [txt sprintf(' </thead>\n')]; | |
136 txt = [txt sprintf(' <tbody>\n')]; | |
137 txt = [txt sprintf(' <tr valign="top">\n')]; | |
138 txt = [txt sprintf(' <td width="25%%" bgcolor="#f3f4f5">Class name</td>\n')]; | |
139 txt = [txt sprintf(' <td bgcolor="#f3f4f5">%s</td>\n', ii.mclass)]; | |
140 txt = [txt sprintf(' </tr>\n')]; | |
141 txt = [txt sprintf(' <tr valign="top">\n')]; | |
142 txt = [txt sprintf(' <td width="25%%" bgcolor="#ffffff">Method name</td>\n')]; | |
143 txt = [txt sprintf(' <td bgcolor="#ffffff">%s</td>\n', ii.mname)]; | |
144 txt = [txt sprintf(' </tr>\n')]; | |
145 txt = [txt sprintf(' <tr valign="top">\n')]; | |
146 txt = [txt sprintf(' <td width="25%%" bgcolor="#f3f4f5">Category</td>\n')]; | |
147 txt = [txt sprintf(' <td bgcolor="#f3f4f5">%s</td>\n', ii.mcategory)]; | |
148 txt = [txt sprintf(' </tr>\n')]; | |
149 txt = [txt sprintf(' <tr valign="top">\n')]; | |
150 txt = [txt sprintf(' <td width="25%%" bgcolor="#ffffff">CVS Version</td>\n')]; | |
151 txt = [txt sprintf(' <td bgcolor="#ffffff">%s</td>\n', ii.mversion)]; | |
152 txt = [txt sprintf(' </tr>\n')]; | |
153 txt = [txt sprintf(' <tr valign="top">\n')]; | |
154 txt = [txt sprintf(' <td width="25%%" bgcolor="#f3f4f5">Min input args</td>\n')]; | |
155 txt = [txt sprintf(' <td bgcolor="#f3f4f5">%d</td>\n', ii.argsmin)]; | |
156 txt = [txt sprintf(' </tr>\n')]; | |
157 txt = [txt sprintf(' <tr valign="top">\n')]; | |
158 txt = [txt sprintf(' <td width="25%%" bgcolor="#ffffff">Max input args</td>\n')]; | |
159 txt = [txt sprintf(' <td bgcolor="#ffffff">%d</td>\n', ii.argsmax)]; | |
160 txt = [txt sprintf(' </tr>\n')]; | |
161 txt = [txt sprintf(' <tr valign="top">\n')]; | |
162 txt = [txt sprintf(' <td width="25%%" bgcolor="#f3f4f5">Min output args</td>\n')]; | |
163 txt = [txt sprintf(' <td bgcolor="#f3f4f5">%d</td>\n', ii.outmin)]; | |
164 txt = [txt sprintf(' </tr>\n')]; | |
165 txt = [txt sprintf(' <tr valign="top">\n')]; | |
166 txt = [txt sprintf(' <td width="25%%" bgcolor="#ffffff">Max output args</td>\n')]; | |
167 txt = [txt sprintf(' <td bgcolor="#ffffff">%d</td>\n', ii.outmax)]; | |
168 txt = [txt sprintf(' </tr>\n')]; | |
169 txt = [txt sprintf(' </tbody>\n')]; | |
170 txt = [txt sprintf(' </table>\n')]; | |
171 | |
172 % Table of the sets | |
173 for ll=1:numel(ii.sets) | |
174 set = ii.sets{ll}; | |
175 pl = ii.plists(ll); | |
176 | |
177 txt = [txt sprintf(' <table cellspacing="0" class="body" cellpadding="4" summary="" width="100%%" border="2">\n')]; | |
178 | |
179 txt = [txt sprintf(' <thead>\n')]; | |
180 txt = [txt sprintf(' <tr valign="top">\n')]; | |
181 txt = [txt sprintf(' <th bgcolor="#B9C6DD" colspan="4"><h3>%s</h3></th>\n', set)]; | |
182 txt = [txt sprintf(' </tr>\n')]; | |
183 txt = [txt sprintf(' <tr valign="top">\n')]; | |
184 txt = [txt sprintf(' <th width="15%%" bgcolor="#D7D7D7">Key</th>\n')]; | |
185 txt = [txt sprintf(' <th width="25%%" bgcolor="#D7D7D7">Default Value</th>\n')]; | |
186 txt = [txt sprintf(' <th bgcolor="#D7D7D7">Options</th>\n')]; | |
187 txt = [txt sprintf(' <th bgcolor="#D7D7D7">Description</th>\n')]; | |
188 txt = [txt sprintf(' </tr>\n')]; | |
189 txt = [txt sprintf(' </thead>\n')]; | |
190 | |
191 | |
192 txt = [txt sprintf(' <tbody>\n')]; | |
193 for kk=1:pl.nparams | |
194 txt = [txt sprintf(' <tr valign="top">\n')]; | |
195 txt = [txt sprintf(' <td width="15%%" bgcolor="#F2F2F2">%s</td>\n', pl.params(kk).key)]; | |
196 ptxt = display(pl.params(kk)); | |
197 txt = [txt sprintf(' <td width="25%%" bgcolor="#F2F2F2">%s</td>\n', strtrim(strrep(ptxt{3}, 'val:', '')))]; | |
198 if numel(pl.params(kk).getOptions) > 1 | |
199 opts = pl.params(kk).getOptions; | |
200 optlist ='<ul>'; | |
201 for oo=1:numel(opts) | |
202 optlist = [optlist '<li><font color="#1111FF">' utils.helper.val2str(opts{oo}) '</font></li>']; | |
203 end | |
204 optlist = [optlist '</ul>']; | |
205 txt = [txt sprintf(' <td bgcolor="#F2F2F2">%s</td>\n', optlist)]; | |
206 else | |
207 txt = [txt sprintf(' <td bgcolor="#F2F2F2"><i>none</i></td>\n')]; | |
208 end | |
209 txt = [txt sprintf(' <td bgcolor="#F2F2F2">%s</td>\n', char(strrep(pl.params(kk).desc, '\n', '<br></br>')))]; | |
210 txt = [txt sprintf(' </tr>\n')]; | |
211 | |
212 end | |
213 txt = [txt sprintf(' </tbody>\n')]; | |
214 txt = [txt sprintf(' </table>\n')]; | |
215 | |
216 end | |
217 end | |
218 | |
219 |