Mercurial > hg > ltpda
comparison m-toolbox/m/gui/gltpda/buildLibrary.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 function buildLibrary(varargin) | |
2 % Function to update the library with all the methods functions. | |
3 % $Id: buildLibrary.m,v 1.12 2009/01/22 21:40:14 nicola Exp $ | |
4 | |
5 % clear all | |
6 bdclose('all'); | |
7 disp('=====================================================') | |
8 disp('Updating the LTPDA Library...'); | |
9 | |
10 % Retrieve the list of all functions and methods: | |
11 ltpda_versions | |
12 | |
13 % This creates a variable named 'versions', so structured: | |
14 % | 1.filename | 2.functionName | 3.version | 4.date | 5.hour | 6.author | 7.folder | 8.hash | 9.category | 10.class | | |
15 % [The 'class' is set to None if it's not a method] | |
16 | |
17 origSize = size(versions,1); %#ok<NODEF> | |
18 disp(['The overall number of LTPDA functions is ',num2str(origSize),'.']) | |
19 | |
20 | |
21 % ========================================================================= | |
22 %% Remove functions not meant for the library: | |
23 % ========================================================================= | |
24 | |
25 % Remove all test functions: | |
26 for i=origSize:-1:1 | |
27 if numel(versions{i,2})>4 && strcmpi(versions{i,2}(1:5),'test_') | |
28 versions(i,:)=[]; | |
29 end | |
30 end | |
31 newSize = size(versions,1); | |
32 disp(['--- ',num2str(origSize-newSize),' test functions ignored']) | |
33 origSize = newSize; | |
34 | |
35 % Remove all Internal functions: | |
36 for i=origSize:-1:1 | |
37 if numel(versions{i,9})>7 && strcmpi(versions{i,9}(1:8),'Internal') | |
38 versions(i,:)=[]; | |
39 end | |
40 end | |
41 newSize = size(versions,1); | |
42 disp(['--- ',num2str(origSize-newSize),' Internal functions ignored']) | |
43 origSize = newSize; | |
44 | |
45 % Remove all private functions: | |
46 for i=origSize:-1:1 | |
47 x = numel(versions{i,10}); | |
48 if x>8 && strcmpi(versions{i,10}(x-7:x),'/private') | |
49 versions(i,:)=[]; | |
50 end | |
51 end | |
52 newSize = size(versions,1); | |
53 disp(['--- ',num2str(origSize-newSize),' private functions ignored']) | |
54 origSize = newSize; | |
55 | |
56 % Remove all remaining examples: | |
57 for i=origSize:-1:1 | |
58 x = numel(versions{i,7}); | |
59 if x>10 && strcmpi(versions{i,7}(x-9:x),'/examples/') | |
60 versions(i,:)=[]; | |
61 end | |
62 end | |
63 newSize = size(versions,1); | |
64 disp(['--- ',num2str(origSize-newSize),' examples ignored']) | |
65 origSize = newSize; | |
66 | |
67 % Remove templates: | |
68 for i=origSize:-1:1 | |
69 funcName = versions{i,2}; | |
70 x = numel(funcName); | |
71 if x>9 && strcmpi(funcName(x-8:x),'_template') | |
72 versions(i,:)=[]; | |
73 end | |
74 end | |
75 newSize = size(versions,1); | |
76 disp(['--- ',num2str(origSize-newSize),' templates ignored']) | |
77 origSize = newSize; | |
78 | |
79 % Remove all uncategorized functions: | |
80 for i=origSize:-1:1 | |
81 if isempty(versions{i,9}) | |
82 versions(i,:)=[]; | |
83 end | |
84 end | |
85 newSize = size(versions,1); | |
86 disp(['--- ',num2str(origSize-newSize),' uncategorized functions ignored']) | |
87 origSize = newSize; | |
88 | |
89 % Remove all functions with category 'GUI function': | |
90 for i=origSize:-1:1 | |
91 if strcmpi(versions{i,9},'GUI function') | |
92 versions(i,:)=[]; | |
93 end | |
94 end | |
95 newSize = size(versions,1); | |
96 disp(['--- ',num2str(origSize-newSize),' GUI functions ignored']) | |
97 origSize = newSize; | |
98 | |
99 % Remove all functions with no class: | |
100 for i=origSize:-1:1 | |
101 if strcmp(versions{i,10},'None') | |
102 versions(i,:)=[]; | |
103 end | |
104 end | |
105 newSize = size(versions,1); | |
106 disp(['--- ',num2str(origSize-newSize),' functions with class ''None'' ignored']) | |
107 origSize = newSize; | |
108 | |
109 % Remove all functions with non user classes: | |
110 for i=origSize:-1:1 | |
111 if numel(versions{i,10})>5 && strncmpi(versions{i,10},'ltpda_',6) | |
112 versions(i,:)=[]; | |
113 elseif numel(versions{i,10})>3 && strncmpi(versions{i,10},'data',4) | |
114 versions(i,:)=[]; | |
115 end | |
116 end | |
117 newSize = size(versions,1); | |
118 disp(['--- ',num2str(origSize-newSize),' functions with class ''ltpda_***'' ignored']) | |
119 origSize = newSize; | |
120 % ========================================================================= | |
121 %% Prepare the library for update: | |
122 % ========================================================================= | |
123 | |
124 disp(['The number of LTPDA functions for the library is ',num2str(origSize),'.']) | |
125 numbFunctions = 0; | |
126 funcCategories = {}; | |
127 for i=1:origSize | |
128 if numel(versions{i,10})>3 && strcmpi(versions{i,10}(1:4),'None') | |
129 numbFunctions = numbFunctions +1; | |
130 if ~ismember(versions{i,9},funcCategories) | |
131 funcCategories = [funcCategories,versions{i,9}]; | |
132 end | |
133 end | |
134 end | |
135 % These are the root level subsystems: | |
136 funcCategories = [funcCategories,'Methods']; | |
137 disp([num2str(numbFunctions),' are functions, ',num2str(origSize-numbFunctions),' are methods.']) | |
138 disp('=====================================================') | |
139 | |
140 load_system libraryBase.mdl | |
141 open ltpda_library.mdl | |
142 set(get_param(gcs,'Handle'),'Lock','off') | |
143 | |
144 % Delete all functions/methods folders in the root and create them anew: | |
145 for i=1:numel(funcCategories) | |
146 try %#ok<ALIGN> | |
147 subsystem = find_system(bdroot,'Name',funcCategories{i}); | |
148 subsysPos = get(get_param(subsystem{1},'Handle'),'Position'); | |
149 delete_block(subsystem); | |
150 catch end %#ok<CTCH> | |
151 SubSystemBlock = add_block('libraryBase/SubSystName',['ltpda_library/',funcCategories{i}]); | |
152 disp(['-- ',funcCategories{i},' updated']) | |
153 if ~isempty(subsystem), set(SubSystemBlock,'Position',subsysPos); end | |
154 set(SubSystemBlock,'LinkStatus','inactive') | |
155 set(SubSystemBlock,'MaskDisplay',['disp(''',funcCategories{i},''')']) | |
156 clear subsysPos subsystem SubSystemBlock | |
157 end | |
158 | |
159 % Creating the Methods/<class> folder for each class anew: | |
160 classes = utils.helper.ltpda_classes; | |
161 | |
162 % Remove improper classes: | |
163 for i=numel(classes):-1:1 | |
164 if (numel(classes{i})>5 && strncmpi(classes{i},'ltpda_',6)) || (numel(classes{i})>3 && strncmpi(classes{i},'data',4)), | |
165 classes(i)=[]; | |
166 end; | |
167 end | |
168 | |
169 for i=1:numel(classes) | |
170 classFolder = add_block('libraryBase/SubSystName',['ltpda_library/Methods/',classes{i}]); | |
171 set(classFolder,'LinkStatus','inactive') | |
172 set(classFolder,'MaskDisplay',['disp(''',classes{i},''')']) | |
173 % Cycle to set proper position: | |
174 x=1;y=1; | |
175 while ~isempty(find_system('ltpda_library/Methods','SearchDepth',1,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)])) | |
176 y=y+1; | |
177 if y==6, x=x+1; y=1; end | |
178 end | |
179 set(classFolder,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)]) | |
180 end | |
181 | |
182 % ========================================================================= | |
183 %% Rebuild the library contents: | |
184 % ========================================================================= | |
185 | |
186 for i=1:origSize | |
187 currMethod = versions{i,2}; | |
188 currCateg = versions{i,9}; | |
189 currClass = versions{i,10}; | |
190 | |
191 % Check to verify whether a folder for this category exists: | |
192 categFolder = find_system(['ltpda_library/Methods/',currClass],'SearchDepth',1,'Name',currCateg); | |
193 try categFolder = categFolder{1}; catch end %#ok<CTCH> | |
194 if isempty(categFolder) | |
195 categFolder = add_block('libraryBase/SubSystName',['ltpda_library/Methods/',currClass,'/',currCateg]); | |
196 set(categFolder,'LinkStatus','inactive') | |
197 set(categFolder,'MaskDisplay',['disp(''',currCateg,''')']) | |
198 % Cycle to set proper position: | |
199 x=1;y=1; | |
200 while ~isempty(find_system(['ltpda_library/Methods/',currClass],'SearchDepth',1,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)])) | |
201 aaa = find_system(['ltpda_library/Methods/',currClass],'SearchDepth',1,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)]); | |
202 if (strcmp(aaa{1},['ltpda_library/Methods/',currClass]) && numel(aaa)==1), break; end | |
203 y=y+1; | |
204 if y==5, x=x+1; y=1; end | |
205 end | |
206 set(categFolder,'Position',[30+80*(y-1) , 30+80*(x-1) , 80+80*(y-1) , 80+80*(x-1)]) | |
207 end | |
208 | |
209 % Adding the proper method block: | |
210 if strcmp(currCateg,'Constructor') | |
211 blockH = add_block('libraryBase/constructor',['ltpda_library/Methods/',currClass,'/',currCateg,'/',currMethod]); | |
212 elseif strcmp(currCateg,'Output') | |
213 blockH = add_block('libraryBase/output',['ltpda_library/Methods/',currClass,'/',currCateg,'/',currMethod]); | |
214 elseif ~strcmp(currMethod,'Contents') | |
215 blockH = add_block('libraryBase/function',['ltpda_library/Methods/',currClass,'/',currCateg,'/',currMethod]); | |
216 end | |
217 | |
218 % Cycle to set proper position: | |
219 x=1;y=1; | |
220 while ~isempty(find_system(['ltpda_library/Methods/',currClass,'/',currCateg],'SearchDepth',1,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)])) | |
221 aaa = find_system(['ltpda_library/Methods/',currClass,'/',currCateg],'SearchDepth',1,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)]); | |
222 if (strcmp(aaa{1},['ltpda_library/Methods/',currClass,'/',currCateg]) && numel(aaa)==1), break; end | |
223 y=y+1; | |
224 if y==5, x=x+1; y=1; end | |
225 end | |
226 set(blockH,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)]) | |
227 | |
228 set(blockH,'LinkStatus','inactive') | |
229 set(blockH,'MaskDisplay',['disp(''',currMethod,''')']) | |
230 set(blockH,'Tag',['method ',currClass]) | |
231 set(blockH,'Description','') | |
232 maskText = eval(['help(''',currClass,'/',currMethod,''');']); | |
233 maskText = strtok(maskText,'%%'); | |
234 set(blockH,'MaskDescription',maskText); | |
235 set(blockH,'OpenFcn','ltpdagui(''callback'',1,''redraw'',2); if (~strcmp(bdroot,''ltpda_library'') && ~isempty(findobj(''Tag'',''LTPDAGUI''))), figure(findobj(''Tag'',''LTPDAGUI'')); end'); | |
236 set(blockH,'CopyFcn','GUIprefs = getappdata(0, ''GUIpreferences''); GUIprefs.Copied = 1; setappdata(0, ''GUIpreferences'',GUIprefs);'); | |
237 childpath = find_system(blockH,'LookUnderMasks','all','BlockType','M-S-Function'); | |
238 set(childpath,'Tag',currMethod) | |
239 set(childpath,'Name',currMethod) | |
240 set(childpath,'Description','') | |
241 | |
242 argsMin = str2double(versions{i,11}); | |
243 if argsMin >1 | |
244 setInports(blockH,argsMin); | |
245 set(blockH,'Position',[30+70*(y-1) , 30+70*(x-1) , 80+70*(y-1) , 60+70*(x-1)]); | |
246 end | |
247 end | |
248 | |
249 % Setting proper position and size for subsystem folders in the root: | |
250 subsystems = find_system(bdroot,'LookUnderMasks','all','SearchDepth',1,'BlockType','SubSystem'); | |
251 x=1; y=1; | |
252 for i=1:numel(subsystems) | |
253 set_param(subsystems{i},'Position',[30+100*(y-1) , 30+100*(x-1) , 95+100*(y-1) , 90+100*(x-1)]) | |
254 y=y+1; | |
255 if y==4, x=x+1; y=1; end | |
256 end | |
257 | |
258 close_system libraryBase.mdl | |
259 | |
260 % Update the annotation: | |
261 annotationHandle = find_system(bdroot,'FindAll','on','SearchDepth',1,'type','annotation'); | |
262 caption1 = 'LTPDA Library'; | |
263 caption2 = ['v3.0 - ',datestr(now,1)]; | |
264 caption = strvcat(caption1,caption2); %#ok<VCAT> | |
265 set_param(annotationHandle, 'HorizontalAlignment','center','Text',caption) | |
266 | |
267 warning off all | |
268 save_system ltpda_library.mdl | |
269 warning on all | |
270 close_system ltpda_library.mdl | |
271 | |
272 | |
273 | |
274 | |
275 %---------------------------------------------------------------------- | |
276 function setInports(varargin) | |
277 % Called whenever the block to be added has argsmin>1, so it needs | |
278 % multiple data inputs: | |
279 | |
280 currBlock = varargin{1}; | |
281 newInports = varargin{2}; | |
282 prevInport = find_system(currBlock,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport'); | |
283 | |
284 % To remove previous data inport and line: | |
285 try %#ok<ALIGN> | |
286 blockLines = get_param(prevInport,'LineHandles'); | |
287 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end | |
288 delete_block(prevInport); | |
289 catch end | |
290 | |
291 % To add new inports, mux and lines: | |
292 if newInports>1 | |
293 muxblock = add_block('built-in/Mux', [getfullname(currBlock),'/Mux']); | |
294 set(muxblock,'Position',[70 , 10 , 73 , 150]) | |
295 set(muxblock,'Inputs',num2str(newInports)) | |
296 end | |
297 for ii=1:newInports | |
298 newBlock = add_block('built-in/Inport', [getfullname(currBlock),'/Inport1'],'MakeNameUnique','on'); | |
299 set_param(newBlock,'Port',num2str(ii)); | |
300 newBlock = get_param(newBlock,'Handle'); | |
301 set(newBlock,'Position',[10 , 10+30*(ii-1) , 30 , 30+30*(ii-1)]) | |
302 set(newBlock,'Tag',num2str(ii)) | |
303 add_line(currBlock,[get(newBlock,'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(ii)]); | |
304 end | |
305 | |
306 funcBlock = find_system(currBlock,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function'); | |
307 funcBlock = get_param(funcBlock,'Name'); | |
308 add_line(currBlock,[get(muxblock,'Name'),'/1'],[funcBlock,'/1']); | |
309 | |
310 | |
311 end | |
312 %---------------------------------------------------------------------- | |
313 | |
314 | |
315 end | |
316 |