Home > functions > gui > project_mgr_dir > tool_launcher_dir > tool_launcher.m

tool_launcher

PURPOSE ^

tool_launcher(key, varargin)

SYNOPSIS ^

function [varargout] = tool_launcher(key, varargin)

DESCRIPTION ^

 tool_launcher(key, varargin)
    Tool launcher
    fig = tool_launcher('init', <id>)

      create figure to input parameter to launch tool.

        id : 1 % job_view_cortex
             2 % job_select_area
             3 % job_edit_area
             4 % job_plot_meg
             5 % job_plot_currentmap
             6 % job_edit_act

 brain_tool_launcher.fig
  --- job_view_cortex, job_select_area, job_edit_area用
 current_tool_launcher.fig
  --- job_plot_currentmap用
 meg_tool_launcher.fig
  --- job_plot_meg用

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [varargout] = tool_launcher(key, varargin)
0002 % tool_launcher(key, varargin)
0003 %    Tool launcher
0004 %    fig = tool_launcher('init', <id>)
0005 %
0006 %      create figure to input parameter to launch tool.
0007 %
0008 %        id : 1 % job_view_cortex
0009 %             2 % job_select_area
0010 %             3 % job_edit_area
0011 %             4 % job_plot_meg
0012 %             5 % job_plot_currentmap
0013 %             6 % job_edit_act
0014 %
0015 % brain_tool_launcher.fig
0016 %  --- job_view_cortex, job_select_area, job_edit_area用
0017 % current_tool_launcher.fig
0018 %  --- job_plot_currentmap用
0019 % meg_tool_launcher.fig
0020 %  --- job_plot_meg用
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
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                 % do nothing
0037             end
0038             delete(fig);
0039         end
0040     case 'callback'
0041         hObj = varargin{1};
0042         callback(hObj);
0043 end
0044 
0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0046 %
0047 % ABSTRUCT FUNCTIONS
0048 %
0049 function [fig] = create_figure(id)
0050 % Abstruct Create figure function
0051 % [IN]
0052 %    id : 1 % job_view_cortex
0053 %         2 % job_select_area
0054 %         3 % job_edit_area
0055 %         4 % job_plot_meg
0056 %         5 % job_plot_currentmap
0057 % [OUT]
0058 %    fig : figure handle
0059 
0060     %
0061     % --- Make figure
0062     %
0063     fig = [];
0064 
0065     % mapping from id to application type
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     % --- Set application data to Figure
0085     %
0086     if ishandle(fig)
0087         set_app_data(fig, pwd, guihandles(fig), app_type);
0088     end
0089 
0090 % end of create_figure()
0091 
0092 function callback(hObj)
0093 % Abstruct Callback function
0094 % [IN]
0095 %    hObj : action component
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 % end of callback()
0115 
0116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0117 %
0118 %  CONCRETE FUNCTIONS(create_figure)
0119 %
0120 
0121 function [fig] = job_view_cortex_launcher_figure
0122     % open figure
0123     fig = openfig('brain_tool_launcher.fig');
0124     set(fig, 'Name', 'View cortical model');
0125     h = guihandles(fig);
0126 
0127     % markup must parameter.
0128     set(h.brain_file_text, 'String', ...
0129                   ['*' get(h.brain_file_text, 'String')]);
0130 % end of job_view_cortex_launcher_figure()
0131 
0132 function [fig] = job_select_area_launcher_figure
0133     % open figure
0134     fig = openfig('brain_tool_launcher.fig');
0135     set(fig, 'Name', 'Make area data');
0136     h = guihandles(fig);
0137     
0138     % mark up must parameter.
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 % end of job_select_area_launcher_figure()
0146 
0147 function [fig] = job_edit_area_launcher_figure
0148     % open figure
0149     fig = openfig('brain_tool_launcher.fig');
0150     set(fig, 'Name', 'Edit area data');
0151     h = guihandles(fig);
0152 
0153     % Hide no need components
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     % mark up must parameter.
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 % end of job_edit_area_launcher_figure()
0165 
0166 function [fig] = job_plot_meg_launcher_figure
0167     % open figure
0168     fig = openfig('meg_tool_launcher.fig');
0169     set(fig, 'Name', 'View MEG/EEG data');
0170     h = guihandles(fig);
0171 
0172     % mark up must parameter.
0173     set(h.meg_file_text, 'String', ...
0174                   ['*' get(h.meg_file_text, 'String')]);
0175 % end of job_plot_meg_launcher_figure()
0176 
0177 function [fig] = job_plot_cmap_launcher_figure
0178     % open figure
0179     fig = openfig('current_tool_launcher.fig');
0180     set(fig, 'Name', 'View estimated current');
0181     h = guihandles(fig);
0182 
0183     % mark up must parameter.
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 % end of job_plot_cmap_launcher_figure()
0190 
0191 function [fig] = job_edit_act_launcher_figure
0192     % open figure
0193     fig = openfig('brain_tool_launcher.fig');
0194     set(fig, 'Name', 'Edit activity map');
0195     h = guihandles(fig);
0196 
0197     % Hide no need components
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     % Move component position(to area file)
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     % mark up must parameter.
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 % end of job_edit_area_launcher_figure()
0218 
0219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0220 %
0221 %  CONCRETE FUNTIONS(callback)
0222 %
0223 
0224 function job_view_cortex_callback(H, hObj)
0225 % Receive job_view_cortex launcher application input
0226 %
0227 % [IN]
0228 %       H : component handles
0229 %    hObj : action object
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; % This figure 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 % end of job_view_cortex_callback()
0270 
0271 function job_select_area_callback(H, hObj)
0272 % Receive job_select_area launcher application input
0273 %
0274 % [IN]
0275 %       H : component handles
0276 %    hObj : action object
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; % This figure 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 % end of job_select_area_callback()
0316 
0317 
0318 function job_edit_area_callback(H, hObj)
0319 % Receive job_edit_area launcher application input
0320 %
0321 % [IN]
0322 %       H : component handles
0323 %    hObj : action object
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; % This figure 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 % end of job_edit_area_callback()
0353 
0354 function job_plot_meg_callback(H, hObj)
0355 % Receive job_plot_meg launcher application input
0356 %
0357 % [IN]
0358 %       H : component handles
0359 %    hObj : action object
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; % This figure 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 % end of job_plot_meg_callback()
0379 
0380 function job_plot_cmap_callback(H, hObj)
0381 % Receive job_plot_cmap launcher application input
0382 %
0383 % [IN]
0384 %       H : component handles
0385 %    hObj : action object
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; % This figure 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 % end of job_plot_cmap_callback()
0416 
0417 function job_edit_act_callback(H, hObj)
0418 % Receive job_edit_area launcher application input
0419 %
0420 % [IN]
0421 %       H : component handles
0422 %    hObj : action object
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; % This figure 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 % end of job_edit_act_callback()
0452 
0453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0454 %
0455 %  APPLICATION DATA MANAGEMENT
0456 %
0457 function set_app_data(fig, startup_dir, components, app_type)
0458 % This function saves application data to figure.
0459 % [IN]
0460 %            fig : figure handle
0461 %    startup_dir : startup directory.
0462 %                  This application change current directory.
0463 %                  startup_dir is to rollback directory.
0464 %     components : component handles including this figure.
0465 %       app_type : application type
0466 
0467     data.pwd       = pwd;
0468     data.app_type  = app_type;
0469     data.H         = guihandles(fig);
0470     set(fig, 'UserData', data);
0471 
0472 % end of set_app_data()
0473 
0474 function [startup_dir, components, app_type] = get_app_data(fig)
0475 % This function loads application data from figure.
0476 % [IN]
0477 %    fig : figure handle.
0478 % [OUT]
0479 %    startup_dir : startup directory.
0480 %                  This application change current directory.
0481 %                  startup_dir is to rollback directory.
0482 %     components : component handles including this figure.
0483 %       app_type : application type
0484 
0485     data = get(fig, 'UserData');
0486     startup_dir = data.pwd;
0487     components = data.H;
0488     app_type    = data.app_type;
0489 
0490 % end of get_app_data()
0491 
0492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0493 %
0494 % UTILITY FOR THIS APPLICATION
0495 
0496 
0497 function [absolute_file, cancelled] = file_select(extension, caption)
0498 % This function gives FileSelection dialog.
0499 % [IN]
0500 %    extension : cell or character array.
0501 %                e.g. '.meg.mat', {'.meg.mat', '.eeg.mat'}
0502 %      caption : dialog title
0503 % [OUT]
0504 %    absolute_file : absolute file path
0505 %        cancelled : true or false. true means file selection is cancelled.
0506 %
0507     absolute_file = [];
0508     cancelled = false;
0509     
0510     % Open dialog
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     % Cancel pushed?
0524     if isempty(dirname)
0525         cancelled = true;
0526     else
0527         cd(dirname);
0528         absolute_file = fullfile(dirname, fnames{1});
0529     end
0530 
0531 % end of file_select()
0532 
0533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0534 %
0535 %  DEFINITION SECTION
0536 %
0537 
0538 function [app_type] = get_type(id)
0539 % This function do mapping between id and app_type.
0540 % [IN]
0541 %    id : application id
0542 % [OUT]
0543 %    app_type : application type
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 % end of get_type()
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

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005