0001 function bm_edit_app_callback(obj, hObj)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
0028
0029 const = define_bm_edit_app;
0030
0031
0032 H = guihandles(obj.h);
0033
0034
0035
0036 switch(hObj)
0037 case H.analyze_file_push
0038
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
0050 analyze_file = [];
0051 [analyze_file, cancelled] = ...
0052 bm_edit_app_util_get_file({'.hdr'}, 'Select analyze file');
0053 if ~cancelled
0054
0055 set(H.analyze_file_edit, 'String', analyze_file);
0056
0057 obj.view_setting2d = ...
0058 bm_view_parm2d_set_analyze_file(obj.view_setting2d, ...
0059 analyze_file);
0060
0061 index = bm_manager_get_bm_list_index(obj.bmm);
0062 if ~isempty(index)
0063 obj.bmm = bm_manager_delete_model(obj.bmm, index);
0064 set(H.brain_model_list_listbox, 'Value', 1);
0065 end
0066
0067
0068 obj = bm_edit_app_update_brain_model_listbox(obj);
0069 else
0070 return;
0071 end
0072
0073
0074
0075
0076 case { H.brain_file_push, H.head_file_push, ...
0077 H.curry_file_push, H.face_file_push, ...
0078 H.mask_file_push, H.spm_norm_file_push}
0079 opt_arg1 = []; opt_arg2 = []; opt_arg3 = [];
0080
0081
0082 if hObj == H.brain_file_push
0083 extension = {'.brain.mat'};
0084 caption = 'Select brain file';
0085 file_type = const.file_type.BRAIN_FILE
0086 elseif hObj == H.head_file_push
0087 extension = {'.head.mat'};
0088 caption = 'Select head file';
0089 file_type = const.file_type.HEAD_FILE;
0090 elseif hObj == H.curry_file_push
0091 extension = {'.*'};
0092 caption = 'Select Curry file';
0093 file_type = const.file_type.CURRY_FILE;
0094 elseif hObj == H.face_file_push
0095 extension = {'.face.mat'};
0096 caption = 'Select face file';
0097 file_type = const.file_type.FACE_FILE;
0098 elseif hObj == H.mask_file_push
0099 extension = {'.mat'};
0100 caption = 'Select mask file';
0101 file_type = const.file_type.MASK_FILE;
0102 elseif hObj == H.spm_norm_file_push
0103 extension = {'.mat'};
0104 caption = 'Select SPM normalization file';
0105 file_type = const.file_type.SPM_NORM_FILE;
0106 end
0107
0108
0109 [model_file, cancelled] = bm_edit_app_util_get_file(extension, caption);
0110 if cancelled, return; end
0111
0112
0113 if hObj == H.brain_file_push
0114 prompt = {'Select hemisphere'};
0115 parts = {const.str.BRAIN_FILE_IMPORT_LEFT_BRAIN, ...
0116 const.str.BRAIN_FILE_IMPORT_RIGHT_BRAIN, ...
0117 const.str.BRAIN_FILE_IMPORT_WHOLE_BRAIN};
0118 [selection, IsOK] = listdlg('PromptString', prompt,...
0119 'SelectionMode', 'multiple', ...
0120 'ListString', parts);
0121 if ~IsOK, return; end
0122 opt_arg1 = parts(selection);
0123 elseif hObj == H.mask_file_push
0124 prompt = {'Select hemisphere'};
0125 parts = {const.str.MASK_FILE_IMPORT_BRAIN, ...
0126 const.str.MASK_FILE_IMPORT_CORTEX};
0127 [selection, IsOK] = listdlg('PromptString', prompt,...
0128 'SelectionMode', 'multiple', ...
0129 'ListString', parts);
0130 if ~IsOK, return; end
0131 opt_arg1 = parts(selection);
0132 elseif hObj == H.spm_norm_file_push
0133 prompt = {'Select hemisphere'};
0134 parts = {const.str.SPM_NORM_FILE_IMPORT_BRAIN, ...
0135 const.str.SPM_NORM_FILE_IMPORT_CORTEX};
0136 [selection, IsOK] = listdlg('PromptString', prompt,...
0137 'SelectionMode', 'multiple', ...
0138 'ListString', parts);
0139 if ~IsOK, return; end
0140 opt_arg1 = parts(selection);
0141 end
0142
0143
0144 drawnow;
0145 h = msgbox('Please wait...');
0146
0147
0148 analyze_file = bm_view_parm2d_get_analyze_file(obj.view_setting2d);
0149
0150
0151 [obj.bmm, result, index] = bm_manager_import_file(obj.bmm, ...
0152 file_type, ...
0153 model_file, ...
0154 analyze_file, ...
0155 opt_arg1, ...
0156 opt_arg2, ...
0157 opt_arg3);
0158 if result == SUCCESS
0159
0160 set(H.brain_model_list_listbox, 'Value', 1);
0161 obj = bm_edit_app_update_brain_model_listbox(obj);
0162
0163 obj = bm_edit_app_close_all_view(obj);
0164 end
0165 if ishandle(h), close(h); end
0166
0167 case H.export_push
0168 index = get(H.brain_model_list_listbox, 'Value');
0169 [file_name, cancelled] = bm_edit_app_util_put_file({'.head.mat'}, '');
0170 if ~cancelled
0171 [obj.bmm, result] = bm_manager_export_file(obj.bmm, ...
0172 const.file_type.HEAD_FILE,...
0173 file_name, ...
0174 index);
0175 if result == FAILURE
0176 errordlg('head file export failed.', 'error');
0177 end
0178 end
0179
0180
0181
0182
0183 case H.load_menu
0184 [file_name, cancelled] = bm_edit_app_util_get_file(...
0185 {'.bme.mat'},...
0186 'Select application setting file.');
0187 if cancelled, return; end
0188 analyze_file = [];
0189 load(file_name, 'bmm', 'view_setting2d', 'view_setting3d', 'analyze_file');
0190 obj.bmm = bmm;
0191 obj.view_setting2d = view_setting2d;
0192 obj.view_setting3d = view_setting3d;
0193 set(H.analyze_file_edit, 'String', analyze_file);
0194 obj = bm_edit_app_update_brain_model_listbox(obj);
0195
0196 obj = bm_edit_app_close_all_view(obj);
0197
0198 case H.save_menu
0199 [file_name, cancelled] = bm_edit_app_util_put_file({'.bme.mat'}, 'Save application setting file.');
0200 if cancelled, return; end
0201 bmm = obj.bmm;
0202 analyze_file = get(H.analyze_file_edit, 'String');
0203 view_setting2d = obj.view_setting2d;
0204 view_setting3d = obj.view_setting3d;
0205 vb_save(file_name, 'bmm', 'view_setting2d', 'view_setting3d', 'analyze_file');
0206
0207
0208
0209
0210 case H.brain_model_list_listbox
0211 set(H.history_listbox, 'Value', 1);
0212 obj = bm_edit_app_update_brain_model_listbox(obj);
0213 case H.history_listbox
0214 obj = bm_edit_app_update_history_listbox(obj);
0215
0216
0217
0218
0219 case H.view2d_push
0220
0221 drawnow;
0222 h = msgbox('Please wait...');
0223
0224 if isempty(obj.view2d) || bm_edit_app_view_is_opening(obj.view2d) == false
0225 obj.view2d = bm_edit_app_view2d_new;
0226 end
0227 obj.view2d = bm_edit_app_view_update(obj.view2d, obj, ...
0228 @bm_edit_app_get_display_factor, ...
0229 obj.view_setting2d);
0230 if ishandle(h), close(h); end
0231 case H.view3d_push
0232
0233 drawnow;
0234 h = msgbox('Please wait...');
0235
0236 if isempty(obj.view3d) || bm_edit_app_view_is_opening(obj.view3d) == false
0237 obj.view3d = bm_edit_app_view3d_new;
0238 end
0239 obj.view3d = bm_edit_app_view_update(obj.view3d, obj, ...
0240 @bm_edit_app_get_display_factor, ...
0241 obj.view_setting3d);
0242 if ishandle(h), close(h); end
0243
0244
0245
0246 case {H.processing_surf_smooth_menu,...
0247 H.surf_smooth_push,...
0248 H.processing_surf_smooth_expand_menu,...
0249 H.surf_smooth_expand_push,...
0250 H.processing_surf_to_filled_mask_menu,...
0251 H.surf_to_filled_mask_push,...
0252 H.processing_separate_surf_menu,...
0253 H.close_surf_push, ...
0254 H.separate_surf_push,...
0255 H.processing_morphology_operation_menu,...
0256 H.morphology_operation_push,...
0257 H.processing_surf_extract_menu,...
0258 H.surf_extract_push}
0259
0260
0261 parm_type = bm_edit_app_menu_to_parm_type(obj, hObj);
0262
0263 parm = bm_manager_get_process_parameter(obj.bmm, parm_type);
0264 [parm, cancelled] = process_parm_editor_edit(obj.ppm, ...
0265 parm_type, ...
0266 parm);
0267 if cancelled, return; end
0268
0269 [obj.bmm, result] = bm_manager_set_process_parameter(obj.bmm, ...
0270 parm_type, ...
0271 parm);
0272 if result == FAILURE
0273 errordlg('Invalid parameter is inputted.', 'error');
0274 return;
0275 end
0276
0277 h = msgbox('Please wait...');
0278 drawnow;
0279
0280 index = get(H.brain_model_list_listbox, 'Value');
0281 obj.bmm = bm_manager_process_brain(obj.bmm, parm_type, index);
0282 if ishandle(h), close(h); end
0283 obj = bm_edit_app_update_brain_model_listbox(obj);
0284
0285
0286
0287 case H.color_setting_2d_menu
0288 color_cell = bm_view_parm2d_get_color(obj.view_setting2d);
0289 for k=1:length(color_cell)
0290 parm_name{k} = ['Layer' num2str(k)];
0291 end
0292 color_cell = inputdlg(parm_name, '2D color setting', 1, color_cell, 'on');
0293 if isempty(color_cell)
0294 return;
0295 else
0296
0297 for k=1:length(color_cell)
0298 color = color_cell{k};
0299 if isletter(color(2))
0300 errordlg('Inputted color is invalid.');
0301 return;
0302 end
0303 end
0304
0305 obj.view_setting2d = bm_view_parm2d_set_color(obj.view_setting2d, color_cell);
0306
0307 if isempty(obj.view2d) || bm_edit_app_view_is_opening(obj.view2d)
0308 bm_edit_app_callback(obj, H.view2d_push);
0309 end
0310 end
0311
0312
0313
0314 case H.delete_push
0315
0316 index = get(H.brain_model_list_listbox, 'Value');
0317 obj.bmm = bm_manager_delete_model(obj.bmm, index);
0318
0319 if index(1) == 1
0320 set(H.brain_model_list_listbox, 'Value', 1);
0321 else
0322 set(H.brain_model_list_listbox, 'Value', index(1)-1);
0323 end
0324
0325 obj = bm_edit_app_update_brain_model_listbox(obj);
0326 case H.rename_push
0327
0328 index = get(H.brain_model_list_listbox, 'Value');
0329 name = bm_manager_get_model_name(obj.bmm, index);
0330
0331 new_name = inputdlg('New name', 'Input new model name', 1, name);
0332
0333 if isempty(new_name), return; end
0334
0335 obj.bmm = bm_manager_rename_model(obj.bmm, index, new_name{1});
0336
0337 obj = bm_edit_app_update_brain_model_listbox(obj);
0338 case H.conductivity_push
0339
0340 index = get(H.brain_model_list_listbox, 'Value');
0341 new_conductivity = str2double(get(H.conductivity_edit, 'String'));
0342
0343 obj.bmm = bm_manager_change_conductivity(obj.bmm, index, new_conductivity);
0344
0345 obj = bm_edit_app_update_brain_model_listbox(obj);
0346 end
0347
0348
0349
0350
0351 guidata(obj.h, obj);