Home > vbmeg > functions > gui > bm_editor > bm_edit_app > bm_edit_app_callback.m

bm_edit_app_callback

PURPOSE ^

callback function. This funcion is called when gui is operated.

SYNOPSIS ^

function bm_edit_app_callback(obj, hObj)

DESCRIPTION ^

 callback function. This funcion is called when gui is operated.
 [USAGE]
     bm_edit_app_callback(<obj>, <hObj>);
 [IN]
     obj : bm_edit_app object
    hObj : action component.
 [OUT]
    none

 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:

SOURCE CODE ^

0001 function bm_edit_app_callback(obj, hObj)
0002 % callback function. This funcion is called when gui is operated.
0003 % [USAGE]
0004 %     bm_edit_app_callback(<obj>, <hObj>);
0005 % [IN]
0006 %     obj : bm_edit_app object
0007 %    hObj : action component.
0008 % [OUT]
0009 %    none
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 %
0015 % --- Previous check
0016 %
0017 if ~exist('obj', 'var'),
0018     error('obj is a required parameter.');
0019 end
0020 if ~strcmp(obj.class_type, 'bm_edit_app')
0021     error('class type is invalid.');
0022 end
0023 if ~exist('hObj', 'var'), error('hObj is a required parameter.'); end
0024 
0025 
0026 %
0027 % --- Main Procedure
0028 %
0029 const = define_bm_edit_app;
0030 
0031 % get component handles
0032 H = guihandles(obj.h);
0033 
0034 % disp(get(hObj, 'Tag'));
0035 
0036 switch(hObj)
0037     case H.analyze_file_push
0038         % When analyze file reselection occurs models destruction.
0039         index = bm_manager_get_bm_list_index(obj.bmm);
0040         read_ok = true;
0041         if ~isempty(index)
0042             res = questdlg('Models are deleted, OK?', 'confirm', ...
0043                             'Yes', 'No', ...
0044                             'Yes');
0045             if strcmp(res, 'No'), read_ok = false; end
0046         end
0047         if ~read_ok, return; end
0048 
0049         % Select analyze_file
0050         [mri_file, cancelled] = ...
0051                     bm_edit_app_util_get_file({'.nii', '.hdr'}, 'Select MRI file');
0052         if ~cancelled
0053             % display filename
0054             set(H.analyze_file_edit, 'String', mri_file);
0055             % set view setting
0056             obj.view_setting2d = ...
0057                 bm_view_parm2d_set_analyze_file(obj.view_setting2d, ...
0058                                                 mri_file);
0059             % all model delete
0060             index = bm_manager_get_bm_list_index(obj.bmm);
0061             if ~isempty(index)
0062                 obj.bmm = bm_manager_delete_model(obj.bmm, index);
0063                 set(H.brain_model_list_listbox, 'Value', 1);
0064             end
0065 
0066             % update listbox state
0067             obj = bm_edit_app_update_brain_model_listbox(obj);
0068         else
0069             return;
0070         end
0071 
0072     %
0073     % --- Import brain model
0074     %
0075     case { H.brain_file_push, H.head_file_push, ...
0076            H.curry_file_push, H.face_file_push, ...
0077            H.mask_file_push,  H.spm_norm_file_push}
0078         opt_arg1 = []; opt_arg2 = []; opt_arg3 = [];
0079 
0080         % judge extension type
0081         if hObj == H.brain_file_push
0082             extension = {'.brain.mat'};
0083             caption   = 'Select brain file';
0084             file_type = const.file_type.BRAIN_FILE
0085         elseif hObj == H.head_file_push
0086             extension = {'.head.mat'};
0087             caption   = 'Select head file';
0088             file_type = const.file_type.HEAD_FILE;
0089         elseif hObj == H.curry_file_push
0090             extension = {'.*'};
0091             caption   = 'Select Curry file';
0092             file_type = const.file_type.CURRY_FILE;
0093         elseif hObj == H.face_file_push
0094             extension = {'.face.mat'};
0095             caption   = 'Select face file';
0096             file_type = const.file_type.FACE_FILE;
0097         elseif hObj == H.mask_file_push
0098             extension = {'.mat'};
0099             caption   = 'Select mask file';
0100             file_type = const.file_type.MASK_FILE;
0101         elseif hObj == H.spm_norm_file_push
0102             extension = {'.mat'};
0103             caption   = 'Select SPM normalization file';
0104             file_type = const.file_type.SPM_NORM_FILE;
0105         end
0106 
0107         % get model file
0108         [model_file, cancelled] = bm_edit_app_util_get_file(extension, caption);
0109         if cancelled, return; end
0110 
0111         % selection
0112         if hObj == H.brain_file_push
0113             prompt = {'Select hemisphere'};
0114             parts = {const.str.BRAIN_FILE_IMPORT_LEFT_BRAIN, ...
0115                      const.str.BRAIN_FILE_IMPORT_RIGHT_BRAIN, ...
0116                      const.str.BRAIN_FILE_IMPORT_WHOLE_BRAIN};
0117             [selection, IsOK] = listdlg('PromptString', prompt,...
0118                                         'SelectionMode', 'multiple', ...
0119                                         'ListString', parts);
0120             if ~IsOK, return; end
0121             opt_arg1 = parts(selection);
0122         elseif hObj == H.mask_file_push
0123             prompt = {'Select hemisphere'};
0124             parts = {const.str.MASK_FILE_IMPORT_BRAIN, ...
0125                      const.str.MASK_FILE_IMPORT_CORTEX};
0126             [selection, IsOK] = listdlg('PromptString', prompt,...
0127                                         'SelectionMode', 'multiple', ...
0128                                         'ListString', parts);
0129             if ~IsOK, return; end
0130             opt_arg1 = parts(selection);
0131         elseif hObj == H.spm_norm_file_push
0132             prompt = {'Select hemisphere'};
0133             parts = {const.str.SPM_NORM_FILE_IMPORT_BRAIN, ...
0134                      const.str.SPM_NORM_FILE_IMPORT_CORTEX};
0135             [selection, IsOK] = listdlg('PromptString', prompt,...
0136                                         'SelectionMode', 'multiple', ...
0137                                         'ListString', parts);
0138             if ~IsOK, return; end
0139             opt_arg1 = parts(selection);
0140         end
0141 
0142         % Wait dialog
0143         drawnow;
0144         h = msgbox('Please wait...');
0145         
0146         % get analyze file for coordinate change
0147         analyze_file = bm_view_parm2d_get_analyze_file(obj.view_setting2d);
0148 
0149         % Data import
0150         [obj.bmm, result, index] = bm_manager_import_file(obj.bmm, ...
0151                                                         file_type, ...
0152                                                         model_file, ...
0153                                                         analyze_file, ...
0154                                                         opt_arg1, ...
0155                                                         opt_arg2, ...
0156                                                         opt_arg3);
0157         if result == SUCCESS
0158             % update screen
0159             set(H.brain_model_list_listbox, 'Value', 1);
0160             obj = bm_edit_app_update_brain_model_listbox(obj);
0161             % View close
0162             obj = bm_edit_app_close_all_view(obj);
0163         end
0164         if ishandle(h), close(h); end
0165 
0166     case H.export_push
0167         index = get(H.brain_model_list_listbox, 'Value');
0168         [file_name, cancelled] = bm_edit_app_util_put_file({'.head.mat'}, '');
0169         if ~cancelled
0170             [obj.bmm, result] = bm_manager_export_file(obj.bmm, ...
0171                                                 const.file_type.HEAD_FILE,...
0172                                                 file_name, ...
0173                                                 index);
0174             if result == FAILURE
0175                 errordlg('head file export failed.', 'error');
0176             end
0177         end
0178         
0179     %
0180     % --- Load / Save Application info
0181     %
0182     case H.load_menu
0183         [file_name, cancelled] = bm_edit_app_util_get_file(...
0184                                             {'.bme.mat'},...
0185                                             'Select application setting file.');
0186         if cancelled, return; end
0187         analyze_file = [];
0188         load(file_name, 'bmm', 'view_setting2d', 'view_setting3d', 'analyze_file');
0189         obj.bmm = bmm;
0190         obj.view_setting2d = view_setting2d;
0191         obj.view_setting3d = view_setting3d;
0192         set(H.analyze_file_edit, 'String', analyze_file);
0193         obj = bm_edit_app_update_brain_model_listbox(obj);
0194         % View close
0195         obj = bm_edit_app_close_all_view(obj);
0196 
0197     case H.save_menu
0198         [file_name, cancelled] = bm_edit_app_util_put_file({'.bme.mat'}, 'Save application setting file.');
0199         if cancelled, return; end
0200         bmm = obj.bmm;
0201         analyze_file = get(H.analyze_file_edit, 'String');
0202         view_setting2d = obj.view_setting2d;
0203         view_setting3d = obj.view_setting3d;
0204         vb_save(file_name, 'bmm', 'view_setting2d', 'view_setting3d', 'analyze_file');
0205     
0206     %
0207     % --- listbox click
0208     %
0209     case H.brain_model_list_listbox
0210         set(H.history_listbox, 'Value', 1);
0211         obj = bm_edit_app_update_brain_model_listbox(obj);
0212     case H.history_listbox
0213         obj = bm_edit_app_update_history_listbox(obj);
0214     
0215     %
0216     % --- View button push
0217     %
0218     case H.view2d_push
0219         % Wait dialog
0220         drawnow;
0221         h = msgbox('Please wait...');
0222         % Singleton check
0223         if isempty(obj.view2d) || bm_edit_app_view_is_opening(obj.view2d) == false
0224             obj.view2d = bm_edit_app_view2d_new;
0225         end
0226         obj.view2d = bm_edit_app_view_update(obj.view2d, obj, ...
0227                                              @bm_edit_app_get_display_factor, ...
0228                                              obj.view_setting2d);
0229         if ishandle(h), close(h); end
0230     case H.view3d_push
0231         % Wait dialog
0232         drawnow;
0233         h = msgbox('Please wait...');
0234         % Singleton check
0235         if isempty(obj.view3d) || bm_edit_app_view_is_opening(obj.view3d) == false
0236             obj.view3d = bm_edit_app_view3d_new;
0237         end
0238         obj.view3d = bm_edit_app_view_update(obj.view3d, obj, ...
0239                                              @bm_edit_app_get_display_factor, ...
0240                                              obj.view_setting3d);
0241         if ishandle(h), close(h); end
0242     %
0243     % --- Processing menu
0244     %
0245     case {H.processing_surf_smooth_menu,...
0246           H.surf_smooth_push,...
0247           H.processing_surf_smooth_expand_menu,...
0248           H.surf_smooth_expand_push,...
0249           H.processing_surf_to_filled_mask_menu,...
0250           H.surf_to_filled_mask_push,...
0251           H.processing_separate_surf_menu,...
0252           H.close_surf_push, ...
0253           H.separate_surf_push,...
0254           H.processing_morphology_operation_menu,...
0255           H.morphology_operation_push,...
0256           H.processing_surf_extract_menu,...
0257           H.surf_extract_push}
0258 
0259         % Convert key to parm_type
0260         parm_type = bm_edit_app_menu_to_parm_type(obj, hObj);
0261         % edit parameter
0262         parm = bm_manager_get_process_parameter(obj.bmm, parm_type);
0263         [parm, cancelled] = process_parm_editor_edit(obj.ppm, ...
0264                                                     parm_type, ...
0265                                                     parm);
0266         if cancelled, return; end
0267         % set parameter
0268         [obj.bmm, result] = bm_manager_set_process_parameter(obj.bmm, ...
0269                                                             parm_type, ...
0270                                                             parm);
0271         if result == FAILURE
0272             errordlg('Invalid parameter is inputted.', 'error');
0273             return;
0274         end
0275         % wait dialog
0276         h = msgbox('Please wait...');
0277         drawnow;
0278         % execute processing
0279         index = get(H.brain_model_list_listbox, 'Value');
0280         obj.bmm = bm_manager_process_brain(obj.bmm, parm_type, index);
0281         if ishandle(h), close(h); end
0282         obj = bm_edit_app_update_brain_model_listbox(obj);
0283    %
0284    % --- Setting color
0285    %
0286     case H.color_setting_2d_menu
0287         color_cell = bm_view_parm2d_get_color(obj.view_setting2d);
0288         for k=1:length(color_cell)
0289             parm_name{k} = ['Layer' num2str(k)];
0290         end
0291         color_cell = inputdlg(parm_name, '2D color setting', 1, color_cell, 'on');
0292         if isempty(color_cell)
0293             return;
0294         else
0295             % Check inputted color
0296             for k=1:length(color_cell)
0297                 color = color_cell{k};
0298                 if isletter(color(2))
0299                     errordlg('Inputted color is invalid.');
0300                     return;
0301                 end
0302             end
0303             % Save Color setting
0304             obj.view_setting2d = bm_view_parm2d_set_color(obj.view_setting2d, color_cell);
0305             % update 2D view
0306             if isempty(obj.view2d) || bm_edit_app_view_is_opening(obj.view2d)
0307                 bm_edit_app_callback(obj, H.view2d_push);
0308             end
0309         end
0310     %
0311     % --- Other command
0312     %
0313     case H.delete_push
0314         % Selected model delete
0315         index = get(H.brain_model_list_listbox, 'Value');
0316         obj.bmm = bm_manager_delete_model(obj.bmm, index);
0317         % Adjust listbox line
0318         if index(1) == 1
0319             set(H.brain_model_list_listbox, 'Value', 1);
0320         else
0321             set(H.brain_model_list_listbox, 'Value', index(1)-1);
0322         end
0323         % Display update
0324         obj = bm_edit_app_update_brain_model_listbox(obj);
0325     case H.rename_push
0326         % get selected model name
0327         index = get(H.brain_model_list_listbox, 'Value');
0328         name = bm_manager_get_model_name(obj.bmm, index);
0329         % Input new model name
0330         new_name = inputdlg('New name', 'Input new model name', 1, name);
0331         % cancel check
0332         if isempty(new_name), return; end
0333         % Rename
0334         obj.bmm = bm_manager_rename_model(obj.bmm, index, new_name{1});
0335         % update display
0336         obj = bm_edit_app_update_brain_model_listbox(obj);
0337     case H.conductivity_push
0338         % Selected model is changed
0339         index = get(H.brain_model_list_listbox, 'Value');
0340         new_conductivity = str2double(get(H.conductivity_edit, 'String'));
0341         % Change conductivity
0342         obj.bmm = bm_manager_change_conductivity(obj.bmm, index, new_conductivity);
0343         % update display
0344         obj = bm_edit_app_update_brain_model_listbox(obj);
0345 end
0346 
0347 %
0348 % --- Save bm_edit_app object to figure
0349 %
0350 guidata(obj.h, obj);

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