Home > vbmeg > 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
             7 % vb_trial_extractor
             8 % vb_signal_processor
             9 % vb_view_head_2d
 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 %             7 % vb_trial_extractor
0015 %             8 % vb_signal_processor
0016 %             9 % vb_view_head_2d
0017 % brain_tool_launcher.fig
0018 %  --- job_view_cortex, job_select_area, job_edit_area??
0019 % current_tool_launcher.fig
0020 %  --- job_plot_currentmap??
0021 % meg_tool_launcher.fig
0022 %  --- job_plot_meg??
0023 %
0024 % Copyright (C) 2011, ATR All Rights Reserved.
0025 % License : New BSD License(see VBMEG_LICENSE.txt)
0026 
0027 switch(key)
0028     case 'init'
0029         id = varargin{1};
0030         varargout{1} = create_figure(id);
0031     case 'exit'
0032         fig = get(0, 'CurrentFigure');
0033         if ishandle(fig)
0034             try
0035                 [startup_dir, component_handles, app_type] = get_app_data(fig);
0036                 cd(startup_dir);
0037             catch
0038                 % do nothing
0039             end
0040             delete(fig);
0041         end
0042     case 'callback'
0043         hObj = varargin{1};
0044         callback(hObj);
0045 end
0046 
0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0048 %
0049 % ABSTRUCT FUNCTIONS
0050 %
0051 function [fig] = create_figure(id)
0052 % Abstruct Create figure function
0053 % [IN]
0054 %    id : 1 % job_view_cortex
0055 %         2 % job_select_area
0056 %         3 % job_edit_area
0057 %         4 % job_plot_meg
0058 %         5 % job_plot_currentmap
0059 %         7 % vb_trial_extractor
0060 %         8 % vb_signal_processor
0061 %         9 % vb_view_head_2d
0062 % [OUT]
0063 %    fig : figure handle
0064 
0065     %
0066     % --- Make figure
0067     %
0068     fig = [];
0069 
0070     % mapping from id to application type
0071     app_type = get_type(id);
0072 
0073     switch(app_type)
0074         case JOB_VIEW_CORTEX
0075             fig = job_view_cortex_launcher_figure;
0076         case JOB_SELECT_AREA
0077             fig = job_select_area_launcher_figure;
0078         case JOB_EDIT_AREA
0079             fig = job_edit_area_launcher_figure;
0080         case JOB_PLOT_MEG
0081             fig = job_plot_meg_launcher_figure;
0082         case JOB_PLOT_CMAP
0083             fig = job_plot_cmap_launcher_figure;
0084         case JOB_EDIT_ACT
0085             fig = job_edit_act_launcher_figure;
0086         case VB_TRIAL_EXTRACTOR
0087             fig = vb_trial_extractor;
0088         case VB_SIGNAL_PROCESSOR
0089             fig = vb_signal_processor;
0090         case VIEW_HEAD_2D
0091             fig = view_head_2d_launcher_figure;
0092     end
0093 
0094     %
0095     % --- Set application data to Figure
0096     %
0097     if ishandle(fig)
0098         set_app_data(fig, pwd, guihandles(fig), app_type);
0099     end
0100 
0101 % end of create_figure()
0102 
0103 function callback(hObj)
0104 % Abstruct Callback function
0105 % [IN]
0106 %    hObj : action component
0107 %
0108     fig = gcf;
0109     [startup_dir, H, app_type] = get_app_data(fig);
0110 
0111     switch(app_type)
0112         case JOB_VIEW_CORTEX
0113             job_view_cortex_callback(H, hObj);
0114         case JOB_SELECT_AREA
0115             job_select_area_callback(H, hObj);
0116         case JOB_EDIT_AREA
0117             job_edit_area_callback(H, hObj);
0118         case JOB_PLOT_MEG
0119             job_plot_meg_callback(H, hObj);
0120         case JOB_PLOT_CMAP
0121             job_plot_cmap_callback(H, hObj);
0122         case JOB_EDIT_ACT
0123             job_edit_act_callback(H, hObj);
0124         case VIEW_HEAD_2D
0125             view_head_2d_callback(H, hObj);
0126     end
0127 % end of callback()
0128 
0129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0130 %
0131 %  CONCRETE FUNCTIONS(create_figure)
0132 %
0133 
0134 function [fig] = job_view_cortex_launcher_figure
0135     % open figure
0136     fig = openfig('brain_tool_launcher.fig');
0137     set(fig, 'Name', 'View cortical model');
0138     h = guihandles(fig);
0139 
0140     % markup must parameter.
0141     set(h.brain_file_text, 'String', ...
0142                   ['*' get(h.brain_file_text, 'String')]);
0143 % end of job_view_cortex_launcher_figure()
0144 
0145 function [fig] = job_select_area_launcher_figure
0146     % open figure
0147     fig = openfig('brain_tool_launcher.fig');
0148     set(fig, 'Name', 'Make area data');
0149     h = guihandles(fig);
0150     
0151     % mark up must parameter.
0152     set(h.brain_file_text, 'String', ...
0153                   ['*' get(h.brain_file_text, 'String')]);
0154     set(h.act_file_text, 'String', ...
0155                   ['*' get(h.act_file_text, 'String')]);
0156     set(h.area_file_text, 'String', ...
0157                   ['*' get(h.area_file_text, 'String')]);
0158 % end of job_select_area_launcher_figure()
0159 
0160 function [fig] = job_edit_area_launcher_figure
0161     % open figure
0162     fig = openfig('brain_tool_launcher.fig');
0163     set(fig, 'Name', 'Edit area data');
0164     h = guihandles(fig);
0165 
0166     % Hide no need components
0167     set(h.act_file_text, 'Visible', 'off');
0168     set(h.act_file_edit, 'Visible', 'off');
0169     set(h.act_file_push, 'Visible', 'off');
0170 
0171     % mark up must parameter.
0172     set(h.brain_file_text, 'String', ...
0173                   ['*' get(h.brain_file_text, 'String')]);
0174     set(h.area_file_text, 'String', ...
0175                   ['*' get(h.area_file_text, 'String')]);
0176 
0177 % end of job_edit_area_launcher_figure()
0178 
0179 function [fig] = job_plot_meg_launcher_figure
0180     % open figure
0181     fig = openfig('meg_tool_launcher.fig');
0182     set(fig, 'Name', 'View MEG/EEG data');
0183     h = guihandles(fig);
0184 
0185     % mark up must parameter.
0186     set(h.meg_file_text, 'String', ...
0187                   ['*' get(h.meg_file_text, 'String')]);
0188 % end of job_plot_meg_launcher_figure()
0189 
0190 function [fig] = view_head_2d_launcher_figure
0191     % open figure
0192     fig = openfig('view_head_2d.fig');
0193     set(fig, 'Name', 'View Head model');
0194     h = guihandles(fig);
0195     
0196     set(h.mri_file_text, 'String', ...
0197                  ['*' get(h.mri_file_text, 'String')]);
0198     set(h.head_file_text, 'String', ...
0199                  ['*' get(h.head_file_text, 'String')]);
0200 
0201 function [fig] = job_plot_cmap_launcher_figure
0202     % open figure
0203     fig = openfig('current_tool_launcher.fig');
0204     set(fig, 'Name', 'View estimated current');
0205     h = guihandles(fig);
0206 
0207     % mark up must parameter.
0208     set(h.current_file_text, 'String', ...
0209                   ['*' get(h.current_file_text, 'String')]);
0210     set(h.brain_file_text, 'String', ...
0211                   ['*' get(h.brain_file_text, 'String')]);
0212 
0213 % end of job_plot_cmap_launcher_figure()
0214 
0215 function [fig] = job_edit_act_launcher_figure
0216     % open figure
0217     fig = openfig('brain_tool_launcher.fig');
0218     set(fig, 'Name', 'Edit activity map');
0219     h = guihandles(fig);
0220 
0221     % Hide no need components
0222     set(h.area_file_text, 'Visible', 'off');
0223     set(h.area_file_edit, 'Visible', 'off');
0224     set(h.area_file_push, 'Visible', 'off');
0225     
0226     % Move component position(to area file)
0227     t_pos = get(h.area_file_text, 'Position');
0228     e_pos = get(h.area_file_edit, 'Position');
0229     p_pos = get(h.area_file_push, 'Position');
0230     
0231     set(h.act_file_text, 'Position', t_pos);
0232     set(h.act_file_edit, 'Position', e_pos);
0233     set(h.act_file_push, 'Position', p_pos);
0234 
0235     % mark up must parameter.
0236     set(h.brain_file_text, 'String', ...
0237                   ['*' get(h.brain_file_text, 'String')]);
0238     set(h.act_file_text, 'String', ...
0239                   ['*' get(h.act_file_text, 'String')]);
0240 
0241 % end of job_edit_area_launcher_figure()
0242 
0243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0244 %
0245 %  CONCRETE FUNTIONS(callback)
0246 %
0247 
0248 function job_view_cortex_callback(H, hObj)
0249 % Receive job_view_cortex launcher application input
0250 %
0251 % [IN]
0252 %       H : component handles
0253 %    hObj : action object
0254 %
0255     switch(hObj)
0256         case H.ok_push
0257             brain_file = get(H.brain_file_edit, 'String');
0258             area_file  = get(H.area_file_edit, 'String');
0259             act_file   = get(H.act_file_edit, 'String');
0260             if ~exist(brain_file, 'file')
0261                 errordlg('Cortical model file is not specified.', 'error');
0262                 return;
0263             end
0264             close; % This figure close
0265             vb_act_area_viewer(brain_file, act_file, area_file);
0266         case H.brain_file_push
0267             [absolute_file, cancelled] = file_select('.brain.mat', ...
0268                                                      'Select cortical model file');
0269             if ~cancelled
0270                 set(H.brain_file_edit, 'String', absolute_file);
0271             end
0272         case H.area_file_push
0273             [absolute_file, cancelled] = file_select('.area.mat', ...
0274                                                      'Select cortical area file');
0275             if ~cancelled
0276                 set(H.area_file_edit, 'String', absolute_file);
0277             end
0278         case H.act_file_push
0279             [absolute_file, cancelled] = file_select('.act.mat', ...
0280                                                      'Select cortical activity file');
0281             if ~cancelled
0282                 set(H.act_file_edit, 'String', absolute_file);
0283             end
0284     end
0285 % end of job_view_cortex_callback()
0286 
0287 function job_select_area_callback(H, hObj)
0288 % Receive job_select_area launcher application input
0289 %
0290 % [IN]
0291 %       H : component handles
0292 %    hObj : action object
0293 %
0294     switch(hObj)
0295         case H.ok_push
0296             brain_file = get(H.brain_file_edit, 'String');
0297             area_file  = get(H.area_file_edit, 'String');
0298             act_file   = get(H.act_file_edit, 'String');
0299             if ~exist(brain_file, 'file')
0300                 errordlg('Cortical model file is not specified.', 'error');
0301                 return;
0302             elseif ~exist(area_file, 'file')
0303                 errordlg('Cortical area file is not specified.', 'error');
0304                 return;
0305             elseif ~exist(act_file, 'file')
0306                 errordlg('Cortical activity file is not specified.', 'error');
0307                 return;
0308             else
0309                 close; % This figure close
0310                 job_select_area(brain_file, area_file, act_file);
0311             end
0312         case H.brain_file_push
0313             [absolute_file, cancelled] = file_select('.brain.mat', ...
0314                                                      'Select cortical model file');
0315             if ~cancelled
0316                 set(H.brain_file_edit, 'String', absolute_file);
0317             end
0318         case H.area_file_push
0319             [absolute_file, cancelled] = file_select('.area.mat', ...
0320                                                      'Select cortical area file');
0321             if ~cancelled
0322                 set(H.area_file_edit, 'String', absolute_file);
0323             end
0324         case H.act_file_push
0325             [absolute_file, cancelled] = file_select('.act.mat', ...
0326                                                      'Select cortical activity file');
0327             if ~cancelled
0328                 set(H.act_file_edit, 'String', absolute_file);
0329             end            
0330     end
0331 % end of job_select_area_callback()
0332 
0333 
0334 function job_edit_area_callback(H, hObj)
0335 % Receive job_edit_area launcher application input
0336 %
0337 % [IN]
0338 %       H : component handles
0339 %    hObj : action object
0340 %
0341     switch(hObj)
0342         case H.ok_push
0343             brain_file = get(H.brain_file_edit, 'String');
0344             area_file  = get(H.area_file_edit, 'String');
0345             if ~exist(brain_file, 'file')
0346                 errordlg('Cortical model file is not specified.', 'error');
0347                 return;
0348             elseif ~exist(area_file, 'file')
0349                 errordlg('Cortical area file is not specified.', 'error');
0350                 return;
0351             else
0352                 close; % This figure close
0353                 job_edit_area(brain_file, area_file);
0354             end
0355         case H.brain_file_push
0356             [absolute_file, cancelled] = file_select('.brain.mat', ...
0357                                                      'Select cortical model file');
0358             if ~cancelled
0359                 set(H.brain_file_edit, 'String', absolute_file);
0360             end
0361         case H.area_file_push
0362             [absolute_file, cancelled] = file_select('.area.mat', ...
0363                                                      'Select cortical area file');
0364             if ~cancelled
0365                 set(H.area_file_edit, 'String', absolute_file);
0366             end
0367     end
0368 % end of job_edit_area_callback()
0369 
0370 function view_head_2d_callback(H, hObj)
0371 % Receive view_head_2d launcher application input
0372 %
0373 % [IN]
0374 %       H : component handles
0375 %    hObj : action object
0376 %
0377     switch(hObj)
0378         case H.ok_push
0379             head_file = get(H.head_file_edit, 'String');
0380             mri_file  = get(H.mri_file_edit, 'String');
0381             if exist(head_file, 'file') ~= 2
0382                 errordlg('HEAD file is not specified.', 'error');
0383                 return;
0384             end
0385             if exist(mri_file, 'file') ~= 2
0386                 errordlg('MRI file is not specified.', 'error');
0387                 return;
0388             end
0389             close; % This figure close
0390             drawnow;
0391             vb_view_head_2d(mri_file, head_file);
0392         case H.mri_file_push
0393             [absolute_file, cancelled] = file_select({'.nii', '.hdr'}, ...
0394                                                      'Select MRI file');
0395             if ~cancelled
0396                 set(H.mri_file_edit, 'String', absolute_file);
0397             end
0398         case H.head_file_push
0399             [absolute_file, cancelled] = file_select({'.head.mat'}, ...
0400                                                      'Select Head file');
0401             if ~cancelled
0402                 set(H.head_file_edit, 'String', absolute_file);
0403             end
0404     end
0405 % end of view_head_2d_callback()
0406             
0407 function job_plot_meg_callback(H, hObj)
0408 % Receive job_plot_meg launcher application input
0409 %
0410 % [IN]
0411 %       H : component handles
0412 %    hObj : action object
0413 %
0414     switch(hObj)
0415         case H.ok_push
0416             meg_file = get(H.meg_file_edit, 'String');
0417             if ~exist(meg_file, 'file')
0418                 errordlg('MEG(EEG)file is not specified.', 'error');
0419                 return;
0420             else
0421                 close; % This figure close
0422                 job_plot_meg(meg_file);
0423             end
0424         case H.meg_file_push
0425             [absolute_file, cancelled] = file_select({'.meg.mat', '.eeg.mat'}, ...
0426                                                      'Select MEG/EEG data');
0427             if ~cancelled
0428                 set(H.meg_file_edit, 'String', absolute_file);
0429             end
0430     end
0431 % end of job_plot_meg_callback()
0432 
0433 function job_plot_cmap_callback(H, hObj)
0434 % Receive job_plot_cmap launcher application input
0435 %
0436 % [IN]
0437 %       H : component handles
0438 %    hObj : action object
0439 %
0440     switch(hObj)
0441         case H.ok_push
0442             current_file  = get(H.current_file_edit, 'String');
0443             brain_file = get(H.brain_file_edit, 'String');
0444             if ~exist(current_file, 'file')
0445                 errordlg('Current file is not specified.', 'error');
0446                 return;
0447             elseif ~exist(brain_file, 'file')
0448                 errordlg('Cortical model file is not specified.', 'error');
0449                 return;
0450             else
0451                 close; % This figure close
0452                 job_plot_currentmap(current_file, brain_file);
0453             end
0454         case H.current_file_push
0455             [absolute_file, cancelled] = file_select('.curr.mat', ...
0456                                                      'Select current timecourse file');
0457             if ~cancelled
0458                 set(H.current_file_edit, 'String', absolute_file);
0459             end
0460         case H.brain_file_push
0461             [absolute_file, cancelled] = file_select('.brain.mat', ...
0462                                                      'Select cortical model file');
0463             if ~cancelled
0464                 set(H.brain_file_edit, 'String', absolute_file);
0465             end
0466 
0467     end
0468 % end of job_plot_cmap_callback()
0469 
0470 function job_edit_act_callback(H, hObj)
0471 % Receive job_edit_area launcher application input
0472 %
0473 % [IN]
0474 %       H : component handles
0475 %    hObj : action object
0476 %
0477     switch(hObj)
0478         case H.ok_push
0479             brain_file = get(H.brain_file_edit, 'String');
0480             act_file  = get(H.act_file_edit, 'String');
0481             if ~exist(brain_file, 'file')
0482                 errordlg('Cortical model file is not specified.', 'error');
0483                 return;
0484             elseif ~exist(act_file, 'file')
0485                 errordlg('Cortical activity file is not specified.', 'error');
0486                 return;
0487             else
0488                 close; % This figure close
0489                 job_edit_act(brain_file, act_file);
0490             end
0491         case H.brain_file_push
0492             [absolute_file, cancelled] = file_select('.brain.mat', ...
0493                                                      'Select cortical model file');
0494             if ~cancelled
0495                 set(H.brain_file_edit, 'String', absolute_file);
0496             end
0497         case H.act_file_push
0498             [absolute_file, cancelled] = file_select('.act.mat', ...
0499                                                      'Select cortical act file');
0500             if ~cancelled
0501                 set(H.act_file_edit, 'String', absolute_file);
0502             end
0503     end
0504 % end of job_edit_act_callback()
0505 
0506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0507 %
0508 %  APPLICATION DATA MANAGEMENT
0509 %
0510 function set_app_data(fig, startup_dir, components, app_type)
0511 % This function saves application data to figure.
0512 % [IN]
0513 %            fig : figure handle
0514 %    startup_dir : startup directory.
0515 %                  This application change current directory.
0516 %                  startup_dir is to rollback directory.
0517 %     components : component handles including this figure.
0518 %       app_type : application type
0519 
0520     data.pwd       = pwd;
0521     data.app_type  = app_type;
0522     data.H         = guihandles(fig);
0523     set(fig, 'UserData', data);
0524 
0525 % end of set_app_data()
0526 
0527 function [startup_dir, components, app_type] = get_app_data(fig)
0528 % This function loads application data from figure.
0529 % [IN]
0530 %    fig : figure handle.
0531 % [OUT]
0532 %    startup_dir : startup directory.
0533 %                  This application change current directory.
0534 %                  startup_dir is to rollback directory.
0535 %     components : component handles including this figure.
0536 %       app_type : application type
0537 
0538     data = get(fig, 'UserData');
0539     startup_dir = data.pwd;
0540     components = data.H;
0541     app_type    = data.app_type;
0542 
0543 % end of get_app_data()
0544 
0545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0546 %
0547 % UTILITY FOR THIS APPLICATION
0548 
0549 
0550 function [absolute_file, cancelled] = file_select(extension, caption)
0551 % This function gives FileSelection dialog.
0552 % [IN]
0553 %    extension : cell or character array.
0554 %                e.g. '.meg.mat', {'.meg.mat', '.eeg.mat'}
0555 %      caption : dialog title
0556 % [OUT]
0557 %    absolute_file : absolute file path
0558 %        cancelled : true or false. true means file selection is cancelled.
0559 %
0560     absolute_file = [];
0561     cancelled = false;
0562     
0563     % Open dialog
0564     h = file_dialog;
0565     if ischar(extension)
0566         extension = cellstr(extension);
0567     end
0568     h = set(h, 'file_extensions', extension);
0569     h = set(h, 'current_dir', pwd);
0570     if exist('caption', 'var')
0571         h = set(h, 'dialog_title', caption);
0572     end
0573         
0574     [dirname fnames] = visible(h);
0575     
0576     % Cancel pushed?
0577     if isempty(dirname)
0578         cancelled = true;
0579     else
0580         cd(dirname);
0581         absolute_file = fullfile(dirname, fnames{1});
0582     end
0583 
0584 % end of file_select()
0585 
0586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0587 %
0588 %  DEFINITION SECTION
0589 %
0590 
0591 function [app_type] = get_type(id)
0592 % This function do mapping between id and app_type.
0593 % [IN]
0594 %    id : application id
0595 % [OUT]
0596 %    app_type : application type
0597 
0598     switch(id)
0599         case 1
0600             app_type = JOB_VIEW_CORTEX;
0601         case 2
0602             app_type = JOB_SELECT_AREA;
0603         case 3
0604             app_type = JOB_EDIT_AREA;
0605         case 4
0606             app_type = JOB_PLOT_MEG;
0607         case 5
0608             app_type = JOB_PLOT_CMAP;
0609         case 6
0610             app_type = JOB_EDIT_ACT;
0611         case 7
0612             app_type = VB_TRIAL_EXTRACTOR;
0613         case 8
0614             app_type = VB_SIGNAL_PROCESSOR;
0615         case 9
0616             app_type = VIEW_HEAD_2D;
0617     end
0618 % end of get_type()
0619 
0620 function [def] = JOB_VIEW_CORTEX
0621     def = 1;
0622 function [def] = JOB_SELECT_AREA
0623     def = 2;
0624 function [def] = JOB_EDIT_AREA
0625     def = 3;
0626 function [def] = JOB_PLOT_MEG
0627     def = 4;
0628 function [def] = JOB_PLOT_CMAP
0629     def = 5;
0630 function [def] = JOB_EDIT_ACT
0631     def = 6;
0632 function [def] = VB_TRIAL_EXTRACTOR
0633     def = 7;
0634 function [def] = VB_SIGNAL_PROCESSOR
0635     def = 8;
0636 function [def] = VIEW_HEAD_2D
0637     def = 9; 
0638 
0639

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005