0001 function [varargout] = tool_launcher(key, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 switch(key)
0026 case 'init'
0027 id = varargin{1};
0028 varargout{1} = create_figure(id);
0029 case 'exit'
0030 fig = get(0, 'CurrentFigure');
0031 if ishandle(fig)
0032 try
0033 [startup_dir, component_handles, app_type] = get_app_data(fig);
0034 cd(startup_dir);
0035 catch
0036
0037 end
0038 delete(fig);
0039 end
0040 case 'callback'
0041 hObj = varargin{1};
0042 callback(hObj);
0043 end
0044
0045
0046
0047
0048
0049 function [fig] = create_figure(id)
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 fig = [];
0064
0065
0066 app_type = get_type(id);
0067
0068 switch(app_type)
0069 case JOB_VIEW_CORTEX
0070 fig = job_view_cortex_launcher_figure;
0071 case JOB_SELECT_AREA
0072 fig = job_select_area_launcher_figure;
0073 case JOB_EDIT_AREA
0074 fig = job_edit_area_launcher_figure;
0075 case JOB_PLOT_MEG
0076 fig = job_plot_meg_launcher_figure;
0077 case JOB_PLOT_CMAP
0078 fig = job_plot_cmap_launcher_figure;
0079 case JOB_EDIT_ACT
0080 fig = job_edit_act_launcher_figure;
0081 end
0082
0083
0084
0085
0086 if ishandle(fig)
0087 set_app_data(fig, pwd, guihandles(fig), app_type);
0088 end
0089
0090
0091
0092 function callback(hObj)
0093
0094
0095
0096
0097 fig = gcf;
0098 [startup_dir, H, app_type] = get_app_data(fig);
0099
0100 switch(app_type)
0101 case JOB_VIEW_CORTEX
0102 job_view_cortex_callback(H, hObj);
0103 case JOB_SELECT_AREA
0104 job_select_area_callback(H, hObj);
0105 case JOB_EDIT_AREA
0106 job_edit_area_callback(H, hObj);
0107 case JOB_PLOT_MEG
0108 job_plot_meg_callback(H, hObj);
0109 case JOB_PLOT_CMAP
0110 job_plot_cmap_callback(H, hObj);
0111 case JOB_EDIT_ACT
0112 job_edit_act_callback(H, hObj);
0113 end
0114
0115
0116
0117
0118
0119
0120
0121 function [fig] = job_view_cortex_launcher_figure
0122
0123 fig = openfig('brain_tool_launcher.fig');
0124 set(fig, 'Name', 'View cortical model');
0125 h = guihandles(fig);
0126
0127
0128 set(h.brain_file_text, 'String', ...
0129 ['*' get(h.brain_file_text, 'String')]);
0130
0131
0132 function [fig] = job_select_area_launcher_figure
0133
0134 fig = openfig('brain_tool_launcher.fig');
0135 set(fig, 'Name', 'Make area data');
0136 h = guihandles(fig);
0137
0138
0139 set(h.brain_file_text, 'String', ...
0140 ['*' get(h.brain_file_text, 'String')]);
0141 set(h.act_file_text, 'String', ...
0142 ['*' get(h.act_file_text, 'String')]);
0143 set(h.area_file_text, 'String', ...
0144 ['*' get(h.area_file_text, 'String')]);
0145
0146
0147 function [fig] = job_edit_area_launcher_figure
0148
0149 fig = openfig('brain_tool_launcher.fig');
0150 set(fig, 'Name', 'Edit area data');
0151 h = guihandles(fig);
0152
0153
0154 set(h.act_file_text, 'Visible', 'off');
0155 set(h.act_file_edit, 'Visible', 'off');
0156 set(h.act_file_push, 'Visible', 'off');
0157
0158
0159 set(h.brain_file_text, 'String', ...
0160 ['*' get(h.brain_file_text, 'String')]);
0161 set(h.area_file_text, 'String', ...
0162 ['*' get(h.area_file_text, 'String')]);
0163
0164
0165
0166 function [fig] = job_plot_meg_launcher_figure
0167
0168 fig = openfig('meg_tool_launcher.fig');
0169 set(fig, 'Name', 'View MEG/EEG data');
0170 h = guihandles(fig);
0171
0172
0173 set(h.meg_file_text, 'String', ...
0174 ['*' get(h.meg_file_text, 'String')]);
0175
0176
0177 function [fig] = job_plot_cmap_launcher_figure
0178
0179 fig = openfig('current_tool_launcher.fig');
0180 set(fig, 'Name', 'View estimated current');
0181 h = guihandles(fig);
0182
0183
0184 set(h.current_file_text, 'String', ...
0185 ['*' get(h.current_file_text, 'String')]);
0186 set(h.brain_file_text, 'String', ...
0187 ['*' get(h.brain_file_text, 'String')]);
0188
0189
0190
0191 function [fig] = job_edit_act_launcher_figure
0192
0193 fig = openfig('brain_tool_launcher.fig');
0194 set(fig, 'Name', 'Edit activity map');
0195 h = guihandles(fig);
0196
0197
0198 set(h.area_file_text, 'Visible', 'off');
0199 set(h.area_file_edit, 'Visible', 'off');
0200 set(h.area_file_push, 'Visible', 'off');
0201
0202
0203 t_pos = get(h.area_file_text, 'Position');
0204 e_pos = get(h.area_file_edit, 'Position');
0205 p_pos = get(h.area_file_push, 'Position');
0206
0207 set(h.act_file_text, 'Position', t_pos);
0208 set(h.act_file_edit, 'Position', e_pos);
0209 set(h.act_file_push, 'Position', p_pos);
0210
0211
0212 set(h.brain_file_text, 'String', ...
0213 ['*' get(h.brain_file_text, 'String')]);
0214 set(h.act_file_text, 'String', ...
0215 ['*' get(h.act_file_text, 'String')]);
0216
0217
0218
0219
0220
0221
0222
0223
0224 function job_view_cortex_callback(H, hObj)
0225
0226
0227
0228
0229
0230
0231 switch(hObj)
0232 case H.ok_push
0233 brain_file = get(H.brain_file_edit, 'String');
0234 area_file = get(H.area_file_edit, 'String');
0235 act_file = get(H.act_file_edit, 'String');
0236 if ~exist(brain_file, 'file')
0237 errordlg('Cortical model file is not specified.', 'error');
0238 return;
0239 end
0240 command = ['job_view_cortex_init(''', brain_file, ''''];
0241 if exist(area_file, 'file')
0242 command = [command ', ''--area'', ''' area_file, ''''];
0243 end
0244 if exist(act_file, 'file')
0245 command = [command ', ''--act'', ''', act_file, ''''];
0246 end
0247 command = [command, ');'];
0248 close;
0249 eval(command);
0250 case H.brain_file_push
0251 [absolute_file, cancelled] = file_select('.brain.mat', ...
0252 'Select cortical model file');
0253 if ~cancelled
0254 set(H.brain_file_edit, 'String', absolute_file);
0255 end
0256 case H.area_file_push
0257 [absolute_file, cancelled] = file_select('.area.mat', ...
0258 'Select cortical area file');
0259 if ~cancelled
0260 set(H.area_file_edit, 'String', absolute_file);
0261 end
0262 case H.act_file_push
0263 [absolute_file, cancelled] = file_select('.act.mat', ...
0264 'Select cortical activity file');
0265 if ~cancelled
0266 set(H.act_file_edit, 'String', absolute_file);
0267 end
0268 end
0269
0270
0271 function job_select_area_callback(H, hObj)
0272
0273
0274
0275
0276
0277
0278 switch(hObj)
0279 case H.ok_push
0280 brain_file = get(H.brain_file_edit, 'String');
0281 area_file = get(H.area_file_edit, 'String');
0282 act_file = get(H.act_file_edit, 'String');
0283 if ~exist(brain_file, 'file')
0284 errordlg('Cortical model file is not specified.', 'error');
0285 return;
0286 elseif ~exist(area_file, 'file')
0287 errordlg('Cortical area file is not specified.', 'error');
0288 return;
0289 elseif ~exist(act_file, 'file')
0290 errordlg('Cortical activity file is not specified.', 'error');
0291 return;
0292 else
0293 close;
0294 job_select_area(brain_file, area_file, act_file);
0295 end
0296 case H.brain_file_push
0297 [absolute_file, cancelled] = file_select('.brain.mat', ...
0298 'Select cortical model file');
0299 if ~cancelled
0300 set(H.brain_file_edit, 'String', absolute_file);
0301 end
0302 case H.area_file_push
0303 [absolute_file, cancelled] = file_select('.area.mat', ...
0304 'Select cortical area file');
0305 if ~cancelled
0306 set(H.area_file_edit, 'String', absolute_file);
0307 end
0308 case H.act_file_push
0309 [absolute_file, cancelled] = file_select('.act.mat', ...
0310 'Select cortical activity file');
0311 if ~cancelled
0312 set(H.act_file_edit, 'String', absolute_file);
0313 end
0314 end
0315
0316
0317
0318 function job_edit_area_callback(H, hObj)
0319
0320
0321
0322
0323
0324
0325 switch(hObj)
0326 case H.ok_push
0327 brain_file = get(H.brain_file_edit, 'String');
0328 area_file = get(H.area_file_edit, 'String');
0329 if ~exist(brain_file, 'file')
0330 errordlg('Cortical model file is not specified.', 'error');
0331 return;
0332 elseif ~exist(area_file, 'file')
0333 errordlg('Cortical area file is not specified.', 'error');
0334 return;
0335 else
0336 close;
0337 job_edit_area(area_file, brain_file);
0338 end
0339 case H.brain_file_push
0340 [absolute_file, cancelled] = file_select('.brain.mat', ...
0341 'Select cortical model file');
0342 if ~cancelled
0343 set(H.brain_file_edit, 'String', absolute_file);
0344 end
0345 case H.area_file_push
0346 [absolute_file, cancelled] = file_select('.area.mat', ...
0347 'Select cortical area file');
0348 if ~cancelled
0349 set(H.area_file_edit, 'String', absolute_file);
0350 end
0351 end
0352
0353
0354 function job_plot_meg_callback(H, hObj)
0355
0356
0357
0358
0359
0360
0361 switch(hObj)
0362 case H.ok_push
0363 meg_file = get(H.meg_file_edit, 'String');
0364 if ~exist(meg_file, 'file')
0365 errordlg('MEG(EEG)file is not specified.', 'error');
0366 return;
0367 else
0368 close;
0369 job_plot_meg(meg_file);
0370 end
0371 case H.meg_file_push
0372 [absolute_file, cancelled] = file_select({'.meg.mat', '.eeg.mat'}, ...
0373 'Select MEG/EEG data');
0374 if ~cancelled
0375 set(H.meg_file_edit, 'String', absolute_file);
0376 end
0377 end
0378
0379
0380 function job_plot_cmap_callback(H, hObj)
0381
0382
0383
0384
0385
0386
0387 switch(hObj)
0388 case H.ok_push
0389 current_file = get(H.current_file_edit, 'String');
0390 brain_file = get(H.brain_file_edit, 'String');
0391 if ~exist(current_file, 'file')
0392 errordlg('Current file is not specified.', 'error');
0393 return;
0394 elseif ~exist(brain_file, 'file')
0395 errordlg('Cortical model file is not specified.', 'error');
0396 return;
0397 else
0398 close;
0399 job_plot_currentmap(current_file, brain_file);
0400 end
0401 case H.current_file_push
0402 [absolute_file, cancelled] = file_select('.curr.mat', ...
0403 'Select current timecourse file');
0404 if ~cancelled
0405 set(H.current_file_edit, 'String', absolute_file);
0406 end
0407 case H.brain_file_push
0408 [absolute_file, cancelled] = file_select('.brain.mat', ...
0409 'Select cortical model file');
0410 if ~cancelled
0411 set(H.brain_file_edit, 'String', absolute_file);
0412 end
0413
0414 end
0415
0416
0417 function job_edit_act_callback(H, hObj)
0418
0419
0420
0421
0422
0423
0424 switch(hObj)
0425 case H.ok_push
0426 brain_file = get(H.brain_file_edit, 'String');
0427 act_file = get(H.act_file_edit, 'String');
0428 if ~exist(brain_file, 'file')
0429 errordlg('Cortical model file is not specified.', 'error');
0430 return;
0431 elseif ~exist(act_file, 'file')
0432 errordlg('Cortical activity file is not specified.', 'error');
0433 return;
0434 else
0435 close;
0436 job_edit_act(brain_file, act_file);
0437 end
0438 case H.brain_file_push
0439 [absolute_file, cancelled] = file_select('.brain.mat', ...
0440 'Select cortical model file');
0441 if ~cancelled
0442 set(H.brain_file_edit, 'String', absolute_file);
0443 end
0444 case H.act_file_push
0445 [absolute_file, cancelled] = file_select('.act.mat', ...
0446 'Select cortical act file');
0447 if ~cancelled
0448 set(H.act_file_edit, 'String', absolute_file);
0449 end
0450 end
0451
0452
0453
0454
0455
0456
0457 function set_app_data(fig, startup_dir, components, app_type)
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467 data.pwd = pwd;
0468 data.app_type = app_type;
0469 data.H = guihandles(fig);
0470 set(fig, 'UserData', data);
0471
0472
0473
0474 function [startup_dir, components, app_type] = get_app_data(fig)
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485 data = get(fig, 'UserData');
0486 startup_dir = data.pwd;
0487 components = data.H;
0488 app_type = data.app_type;
0489
0490
0491
0492
0493
0494
0495
0496
0497 function [absolute_file, cancelled] = file_select(extension, caption)
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 absolute_file = [];
0508 cancelled = false;
0509
0510
0511 h = file_dialog;
0512 if ischar(extension)
0513 extension = cellstr(extension);
0514 end
0515 h = set(h, 'file_extensions', extension);
0516 h = set(h, 'current_dir', pwd);
0517 if exist('caption', 'var')
0518 h = set(h, 'dialog_title', caption);
0519 end
0520
0521 [dirname fnames] = visible(h);
0522
0523
0524 if isempty(dirname)
0525 cancelled = true;
0526 else
0527 cd(dirname);
0528 absolute_file = fullfile(dirname, fnames{1});
0529 end
0530
0531
0532
0533
0534
0535
0536
0537
0538 function [app_type] = get_type(id)
0539
0540
0541
0542
0543
0544
0545 switch(id)
0546 case 1
0547 app_type = JOB_VIEW_CORTEX;
0548 case 2
0549 app_type = JOB_SELECT_AREA;
0550 case 3
0551 app_type = JOB_EDIT_AREA;
0552 case 4
0553 app_type = JOB_PLOT_MEG;
0554 case 5
0555 app_type = JOB_PLOT_CMAP;
0556 case 6
0557 app_type = JOB_EDIT_ACT;
0558 end
0559
0560
0561 function [def] = JOB_VIEW_CORTEX
0562 def = 1;
0563 function [def] = JOB_SELECT_AREA
0564 def = 2;
0565 function [def] = JOB_EDIT_AREA
0566 def = 3;
0567 function [def] = JOB_PLOT_MEG
0568 def = 4;
0569 function [def] = JOB_PLOT_CMAP
0570 def = 5;
0571 function [def] = JOB_EDIT_ACT
0572 def = 6;
0573