comparison m-toolbox/classes/@LTPDAworkbench/LTPDAworkbench.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children a26669b59d7e
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % LTPDAWORKBENCH creates a new LTPDA Workbench.
2 %
3 % CALL:
4 % >> LTPDAworkbench
5 % >> wb = LTPDAworkbench % returns a handle to the object
6 %
7 % M Hewitson 23-11-08
8 %
9 % $Id: LTPDAworkbench.m,v 1.52 2011/02/22 15:47:04 hewitson Exp $
10 %
11
12 % >> wb = LTPDAworkbench('foo.lwb') % load a workbench from file
13 % >> wb = LTPDAworkbench('foo.m') % Create a workbench with a
14 % pipeline constructed from the M-file of LTPDA commands.
15 % >> wb = LTPDAworkbench(objs) % create a workbench with one
16 % pipeline for each of the objects.
17
18
19 classdef LTPDAworkbench < handle
20 %------------------------------------------------
21 %---------- Private read-only Properties --------
22 %------------------------------------------------
23 properties (SetAccess = public)
24 mp = [];
25 name = '';
26 executing = false;
27 UUID = [];
28 end
29
30 %-----------------------------------------
31 % Public methods
32 %-----------------------------------------
33 methods
34
35 % Construct a new workbench
36 function wb = LTPDAworkbench(varargin)
37
38 % c = mfilename('fullpath');
39 % d = fileparts(c);
40 % % add jar file to the java path
41 % mpipelineJar = fullfile(d, 'MPipeline.jar');
42 % javaaddpath(mpipelineJar);
43
44 twb = [];
45 twb = getappdata(0, 'LTPDAworkbench');
46 wb.UUID = ['LWB_' num2str(round(cputime.*100))];
47
48 if isa(twb, 'LTPDAworkbench')
49
50 disp('*** Found existing workbench.')
51 wb = twb;
52 awtinvoke(wb.mp, 'setVisible', 'true');
53
54 else
55
56 wfile = which(mfilename);
57 [path, name, ext] = fileparts(wfile);
58 libpath = fullfile(path, '');
59 libfile = fullfile(libpath, 'lib.mat');
60
61 switch nargin
62 case 0
63 % Create a new LTPDAworkbench
64 prefs = getappdata(0, 'LTPDApreferences');
65 wb.mp = awtcreate('mpipeline.main.MainWindow', 'Ljava.lang.String;Lmpipeline.ltpdapreferences.LTPDAPreferences;', prefdir, prefs);
66 if isempty(wb.mp)
67 error('Failed to create the workbench java object. Contact your nearest LTPDA developer.');
68 end
69 pause(0.1);
70 % load library 'lib'
71 try
72 in = load(libfile);
73 % set library
74 awtinvoke(wb.mp, 'setLibrary', in.lib);
75 % javaMethodEDT('setLibrary', wb.mp, in.lib);
76 pause(0.1);
77 catch
78 warning('!!! Can''t open library, rebuilding it');
79 lib = wb.rebuildLibrary();
80 pause(0.1);
81 save(libfile, 'lib')
82 end
83
84 % Set the repository manager to the workbench
85 rm = LTPDARepositoryManager();
86 awtinvoke(wb.mp, 'setRepositoryManager', rm.manager);
87 % javaMethodEDT('setRepositoryManager', wb.mp, rm.manager);
88 pause(0.1);
89
90 % refresh library tree
91 awtinvoke(wb.mp, 'refreshLibraryTree');
92 % javaMethodEDT('refreshLibraryTree', wb.mp);
93 pause(0.1);
94
95 % set instance identifier to the workbench
96 awtinvoke(wb.mp, 'setInstanceIdentifier', wb.UUID);
97 % javaMethodEDT('setInstanceIdentifier', wb.mp, wb.UUID);
98 pause(0.1);
99
100 % Set the instance identifier
101 awtinvoke(wb.mp, 'setInstanceIdentifier', wb.UUID);
102
103 % Show the workbench
104 awtinvoke(wb.mp, 'setVisible', 'true');
105 % javaMethodEDT('setVisible', wb.mp, true);
106 pause(0.1);
107
108
109
110 end
111
112 %%%%%%%%%% Controls-tab (main) buttons %%%%%%%%%%
113
114 %--- Run button
115 h = handle(wb.mp.getRunBtn, 'callbackproperties');
116 set(h, 'ActionPerformedCallback', {@wb.cb_runPipeline});
117
118 %--- Stepforward button
119 h = handle(wb.mp.getStepForwardBtn, 'callbackproperties');
120 set(h, 'ActionPerformedCallback', {@wb.cb_stepForward});
121
122 %--- Stepbackward button
123 h = handle(wb.mp.getStepBackwardsBtn, 'callbackproperties');
124 set(h, 'ActionPerformedCallback', {@wb.cb_stepBackwards});
125
126 %--- Skipforward button
127 h = handle(wb.mp.getSkipForwardBtn, 'callbackproperties');
128 set(h, 'ActionPerformedCallback', {@wb.cb_skipForward});
129
130 %--- Reset button
131 h = handle(wb.mp.getResetBtn, 'callbackproperties');
132 set(h, 'ActionPerformedCallback', {@wb.cb_reset});
133
134 %%%%%%%%%% Controls-tab (helper) buttons %%%%%%%%%%
135
136 %----Save objects button
137 h = handle(wb.mp.getSaveObjectBtn, 'callbackproperties');
138 set(h, 'ActionPerformedCallback', {@wb.cb_saveObjects});
139
140 %---- Export to WS button
141 h = handle(wb.mp.getExportWorkspaceBtn, 'callbackproperties');
142 set(h, 'ActionPerformedCallback', {@wb.cb_exportWS});
143
144 %--- Explore button
145 h = handle(wb.mp.getExploreBtn, 'callbackproperties');
146 set(h, 'ActionPerformedCallback', {@wb.cb_explore});
147
148 %--- Plot button
149 h = handle(wb.mp.getPlotBtn, 'callbackproperties');
150 set(h, 'ActionPerformedCallback', {@wb.cb_plot});
151
152 %---- Plot history of selected object button
153 h = handle(wb.mp.getHistoryBtn, 'callbackproperties');
154 set(h, 'ActionPerformedCallback', {@wb.cb_plotHistory});
155
156 %---- Display selected objects to terminal button
157 h = handle(wb.mp.getDisplayBtn, 'callbackproperties');
158 set(h, 'ActionPerformedCallback', {@wb.cb_display});
159
160 %----Table button
161 h = handle(wb.mp.getTableBtn, 'callbackproperties');
162 set(h, 'ActionPerformedCallback', {@wb.cb_table});
163
164 %----Report
165 h = handle(wb.mp.getReportBtn, 'callbackproperties');
166 set(h, 'ActionPerformedCallback', {@wb.cb_report});
167
168 % %---- Verbosity combo
169 % h = handle(wb.mp.getVebosityCombo, 'callbackproperties');
170 % set(h, 'ActionPerformedCallback', {@wb.cb_changeVerbosity});
171
172 %%%%%%%%%% 'Tools' Menu %%%%%%%%%%
173
174 %---- 'Plot selected' menu item
175 h = handle(wb.mp.getPlotSelectedMenuItem, 'callbackproperties');
176 set(h, 'ActionPerformedCallback', {@wb.cb_plot});
177
178 %---- 'Explore selected' menu item
179 h = handle(wb.mp.getExploreSelectedMenuItem, 'callbackproperties');
180 set(h, 'ActionPerformedCallback', {@wb.cb_explore});
181
182 %---- 'LTPDA Preferences' menu item
183 h = handle(wb.mp.getLtpdaPreferencesMenuItem, 'callbackproperties');
184 set(h, 'ActionPerformedCallback', {@wb.cb_launchLTPDApreferences});
185
186 %---- 'LTPDA Repository GUI' menu item
187 h = handle(wb.mp.getLtpdaRepoGuiMenuItem, 'callbackproperties');
188 set(h, 'ActionPerformedCallback', {@wb.cb_launchRepogui});
189
190 %---- 'Spectral Window Viewer' menu item
191 h = handle(wb.mp.getLtpdaSpecwinViewerMenuItem, 'callbackproperties');
192 set(h, 'ActionPerformedCallback', {@wb.cb_launchSpecwinViewer});
193
194 %---- 'Object Constructor Helper' menu item
195 h = handle(wb.mp.getLtpdaConstructorHelperMenuItem, 'callbackproperties');
196 set(h, 'ActionPerformedCallback', {@wb.cb_launchConstructor});
197
198 %---- 'LTPDA Signal Builder' menu item
199 h = handle(wb.mp.getLtpdaSignalBuilderMenuItem, 'callbackproperties');
200 set(h, 'ActionPerformedCallback', {@wb.cb_launchSigBuilder});
201
202 %---- 'Rebuild LTPDA Library' menu item
203 h = handle(wb.mp.getRebuildLibraryMenuItem, 'callbackproperties');
204 set(h, 'ActionPerformedCallback', {@wb.cb_rebuildLibrary});
205
206 %%%%%%%%%% 'Pipeline' Menu %%%%%%%%%%
207
208 %---- Export pipeline to terminal item
209 h = handle(wb.mp.getExportToTerminalMenuItem, 'callbackproperties');
210 set(h, 'ActionPerformedCallback', {@wb.cb_export2terminal});
211
212 %---- Export pipeline to m-file
213 h = handle(wb.mp.getExportToMFileMenuItem, 'callbackproperties');
214 set(h, 'ActionPerformedCallback', {@wb.cb_export2mfile});
215
216 %%%%%%%%%% 'Help' Menu %%%%%%%%%%
217
218 %---- Block Doc
219 h = handle(wb.mp.getHelpBlockDocMenuItem, 'callbackproperties');
220 set(h, 'ActionPerformedCallback', {@wb.cb_blockdoc});
221
222 %%%%%%%%%% 'File' Menu %%%%%%%%%%
223
224 %----Run execution plan
225 h = handle(wb.mp.getPlanRunMenuItem, 'callbackproperties');
226 set(h, 'ActionPerformedCallback', {@wb.cb_executePlan});
227
228 %----Import from objects
229 h = handle(wb.mp.getWBOpenFromObjectMenuItem, 'callbackproperties');
230 set(h, 'ActionPerformedCallback', {@wb.cb_importWBfromObjects});
231
232 %---- Import pipeline from M-file
233 h = handle(wb.mp.getImportFromMfileMenuItem, 'callbackproperties');
234 % set(h, 'ActionPerformedCallback', {@wb.cb_importFromMfile});
235
236 %---- Import pipeline from workspace
237 h = handle(wb.mp.getImportFromWorkspaceMenuItem, 'callbackproperties');
238 % set(h, 'ActionPerformedCallback', {@wb.cb_importFromWorkspace});
239
240 %%%%%%%%%% Repository buttons %%%%%%%%%%
241
242 %----Submit to workspace
243 h = handle(wb.mp.getRepoSubmitTBB, 'callbackproperties');
244 set(h, 'ActionPerformedCallback', {@wb.cb_submitObjects});
245
246 %----Open repository manager
247 h = handle(wb.mp.getRepoConnectTBB, 'callbackproperties');
248 set(h, 'ActionPerformedCallback', {@wb.cb_openRepoManagerGUI});
249
250 %%%%%%%%%% other %%%%%%%%%%
251
252 %--- called when window is closed
253 h = handle(wb.mp, 'callbackproperties');
254 set(h, 'WindowClosedCallback', {@wb.cb_guiClosed});
255 set(h, 'PropertyChangeCallback', {@wb.cb_applyprefs});
256
257 % set the spectral window types
258 wtl = wb.mp.getWindowTypes();
259 wtl.clear();
260 winTypes = specwin.getTypes;
261 for kk=1:numel(winTypes)
262 wtl.add(winTypes{kk});
263 end
264
265 % create progress bar when loading built-in models
266 pd = mpipeline.dialogs.ProgressDialog(wb.mp, false, 'starting', 1);
267 warning('off', 'MATLAB:JavaEDTAutoDelegation')
268 pd.setTitle('Uploading built-in models...');
269 pd.setVisible(true);
270 warning('on', 'MATLAB:JavaEDTAutoDelegation')
271
272 amdls = wb.mp.getBuiltinModels('');
273 amdls.clear();
274 cls = utils.helper.ltpda_userclasses;
275 for jj=1:numel(cls)
276 cl = cls{jj};
277 if ~any(strcmp(cl, {'plist'}))
278 mdls = eval([cl '.getBuiltInModels;']);
279 pd.setMessage(['Adding ' cl ' models']);
280 pd.setMaxValue(size(mdls,1));
281 pd.setValue(0);
282 for kk=1:size(mdls,1)
283 pd.increment();
284 htxt = help([cl '_model_' mdls{kk,1}]);
285 pl = [];
286 try
287 pl = eval([cl '_model_' mdls{kk,1} '(''plist'')']);
288 end
289 if ~isa(pl, 'plist')
290 pl = plist;
291 end
292 try
293 wb.mp.addBuiltInModel(cl, mdls{kk,1}, ['<html><p>' htxt '</p></html>'], LTPDAworkbench.mpl2jpl(pl))
294 catch err
295 fprintf(2, '\n### Failure in uploading the model %s.\n\n', mdls{kk,1});
296 end
297 end
298 end
299 end
300 % get rid of progress bar
301 pd.dispose();
302 clear pd;
303
304 % Set LTPDA prefs
305 % pl = LTPDAprefs.getPrefsPlist();
306 % wb.mp.uploadLtpdaPreferences(LTPDAworkbench.mpl2jpl(pl));
307
308 % Set units
309 units = unit.supportedUnits;
310 prefixes = unit.supportedPrefixes;
311 wb.mp.clearUnits;
312 wb.mp.clearPrefixes;
313 for ii=1:numel(units)
314 wb.mp.addUnit(units{ii});
315 end
316 for ii=1:numel(prefixes)
317 wb.mp.addPrefix(prefixes{ii});
318 end
319
320
321 % set working directory
322 wb.mp.setWorkingDir(pwd);
323
324 end
325
326 % setappdata(0, 'LTPDAworkbench', wb);
327 end % End constructor
328
329 end % End public methods
330
331 methods (Access=public)
332 varargout = addErrorMessage(varargin)
333 varargout = addMessage(varargin)
334 varargout = addWarningMessage(varargin)
335
336 % Display method to make a quiet output
337 function display(varargin)
338 wb = varargin{1};
339 end
340 end
341
342 methods(Access=private)
343
344 % Controls tab (main) buttons
345 varargout = cb_runPipeline(varargin)
346 varargout = cb_stepForward(varargin)
347 varargout = cb_skipForward(varargin)
348 varargout = cb_stepBackwards(varargin)
349 varargout = cb_reset(varargin)
350
351 % Controls tab (helper) buttons
352 varargout = cb_saveObjects(varargin)
353 varargout = cb_exportWS(varargin)
354 varargout = cb_explore(varargin)
355 varargout = cb_plot(varargin)
356 varargout = cb_plotHistory(varargin)
357 varargout = cb_display(varargin)
358 varargout = cb_table(varargin)
359 varargout = cb_report(varargin)
360 varargout = cb_changeVerbosity(varargin)
361
362 % 'Tools' Menu
363 varargout = cb_launchLTPDApreferences(varargin)
364 varargout = cb_launchRepogui(varargin)
365 varargout = cb_launchSpecwinViewer(varargin)
366 varargout = cb_launchConstructor(varargin)
367 varargout = cb_launchSigBuilder(varargin)
368 varargout = cb_rebuildLibrary(varargin)
369
370 % 'Pipeline' Menu
371 varargout = cb_export2terminal(varargin)
372 varargout = cb_export2mfile(varargin)
373
374 % 'File' Menu
375 varargout = cb_importFromMfile(varargin)
376 varargout = cb_importFromWorkspace(varargin)
377 varargout = cb_executePlan(varargin)
378 varargout = cb_importWBfromObjects(varargin)
379
380 % 'Help' Menu
381 varargout = cb_blockdoc(varargin)
382
383 % Repository Buttons
384 varargout = cb_submitObjects(varargin)
385 varargout = cb_openRepoManagerGUI(varargin)
386
387 % other
388 varargout = cb_guiClosed(varargin)
389 varargout = cb_applyprefs(varargin);
390
391 end
392
393 methods (Static=true)
394
395 varargout = getWS_VarName(varargin);
396
397 varargout = parseBlocks(varargin);
398 varargout = clearBlockVariables(varargin);
399 varargout = executeCommands(varargin)
400 varargout = executeConstants(varargin)
401 varargout = run(varargin)
402
403 varargout = mpl2jpl(varargin)
404 varargout = jpl2mpl(varargin)
405 varargout = parseCmd(varargin)
406 varargout = rebuildLibrary(varargin);
407
408 end
409 %------------------------------------------------
410 % Private static methods
411 %------------------------------------------------
412 methods(Access=private, Static=true)
413 varargout = minfo2algo(varargin)
414 varargout = parse(varargin)
415 end
416
417 end
418