Home > functions > gui > batch > batch_list > vb_batch_list_callback.m

vb_batch_list_callback

PURPOSE ^

callback function for batch list gui.

SYNOPSIS ^

function vb_batch_list_callback(fig, hObj)

DESCRIPTION ^

 callback function for batch list gui.
 [USAGE]
    vb_batch_list_calback(<fig>, <hObj>);
 [IN]
     fig : figure handle of batch list gui.
    hObj : event component handle.
 [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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_batch_list_callback(fig, hObj)
0002 % callback function for batch list gui.
0003 % [USAGE]
0004 %    vb_batch_list_calback(<fig>, <hObj>);
0005 % [IN]
0006 %     fig : figure handle of batch list gui.
0007 %    hObj : event component handle.
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('fig', 'var') || isempty(fig) || ~ishandle(fig)
0018     error('invalid figure handle is specified.');
0019 end
0020 if ~exist('fig', 'var') || isempty(hObj)
0021     error('hObj is a required parameter.');
0022 end
0023 
0024 %
0025 % --- Main Procedure
0026 %
0027 
0028 % load data (@see vb_batch_list_new.m)
0029 data = guidata(fig);
0030 H = data.H; % component handles
0031 
0032 
0033 switch(hObj)
0034     case H.builder_name_edit
0035         name = get(H.builder_name_edit, 'String');
0036         data.bmgr = vb_batch_mgr_set_name(data.bmgr, name);
0037     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038     % Template parameter editor
0039     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0040     case H.insert_mkdir_push
0041         [data.bmgr] = vb_batch_mgr_add_tool_mkdir(data.bmgr);
0042     case H.upper_push
0043         idx1 = get(H.template_parameter_listbox, 'Value');
0044         idx2 = idx1-1;
0045         if idx2 == 0
0046             return;
0047         else
0048             [data.bmgr] = vb_batch_mgr_swap_parm(data.bmgr, 0, idx1, idx2);
0049             set(H.template_parameter_listbox, 'Value', idx2);
0050         end
0051     case H.lower_push
0052         [last] = vb_batch_mgr_get_num_of_parm(data.bmgr, 0);
0053         idx1 = get(H.template_parameter_listbox, 'Value');
0054         idx2 = idx1+1;
0055         if idx1 == last
0056             return;
0057         else
0058             [data.bmgr] = vb_batch_mgr_swap_parm(data.bmgr, 0, idx1, idx2);
0059             set(H.template_parameter_listbox, 'Value', idx2);
0060         end
0061     case H.remove_push
0062         res = questdlg('Selected parameter will be removed. continue?',...
0063                  'Confirm', 'Yes', 'No', 'Yes');
0064         if strcmpi(res, 'yes')
0065             n = get(H.template_parameter_listbox, 'Value');
0066             [data.bmgr] = vb_batch_mgr_remove_parm(data.bmgr, 0, n);
0067         end
0068     case H.copy_push
0069         n = get(H.template_parameter_listbox, 'Value');
0070         [data.bmgr] = vb_batch_mgr_duplicate_parm(data.bmgr, 0, n);
0071     case {H.edit_push, H.template_parameter_listbox}
0072         if hObj == H.template_parameter_listbox
0073             if strcmpi(get(fig, 'SelectionType'), 'open')
0074                 % If listbox is double clicked, edit parameter
0075             else
0076                % single click
0077                 return;
0078             end
0079         end
0080         n = get(H.template_parameter_listbox, 'Value');
0081         [data.bmgr, errmsg] = vb_batch_mgr_edit_parm(data.bmgr, 0, n);
0082 
0083     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0084     % Variable and Table definition
0085     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0086     case H.variable_add_push
0087         add_name = '';
0088         while(1)
0089             % input variable name
0090             add_name = inputdlg('Input variable name', 'Add variable', ...
0091                                      1, {add_name});
0092             if isempty(add_name), return; end
0093             % make '$VALUE$'
0094             add_name = strrep(add_name{1}, '$', '');
0095             add_name = ['$' add_name '$'];
0096             % add variable to the table
0097             [data.bmgr, errmsg] = vb_batch_mgr_add_variable(data.bmgr, add_name);
0098             if ~isempty(errmsg)
0099                 h = errordlg(errmsg, 'Error');
0100                 waitfor(h);
0101             else
0102                 break;
0103             end
0104         end
0105     case {H.variable_rename_push, H.variable_listbox}
0106         if hObj == H.variable_listbox
0107             if strcmpi(get(fig, 'SelectionType'), 'open')
0108                 % If listbox is double clicked, rename variable
0109             else
0110                % single click
0111                 return;
0112             end
0113         end
0114 
0115         selected = get(H.variable_listbox, 'Value');
0116         strs     = get(H.variable_listbox, 'String');
0117         old_name = strs{selected};
0118         new_name = old_name;
0119         while(1)
0120             % INPUT new name
0121             new_name = ...
0122                 inputdlg('Input variable name', 'Rename variable', ...
0123                          1, {new_name});
0124             if isempty(new_name), return; end
0125             % make '$VALUE$'
0126             new_name = strrep(new_name{1}, '$', '');
0127             new_name = ['$' new_name '$'];
0128             % Register
0129             [data.bmgr, errmsg] = ...
0130               vb_batch_mgr_change_variable_name(data.bmgr, old_name, new_name);
0131             if ~isempty(errmsg)
0132                 h = errordlg(errmsg, 'Error');
0133                 waitfor(h);
0134             else
0135                 break;
0136             end
0137         end
0138     case H.variable_remove_push
0139         % selected variable name
0140         listbox_contents = get(H.variable_listbox, 'String');
0141         selected = get(H.variable_listbox, 'Value');
0142         if ischar(listbox_contents)
0143             listbox_contents = {listbox_contents};
0144         end
0145         remove_name = listbox_contents{selected};
0146         head = sprintf('Variable(%s)', remove_name);
0147         res = questdlg([head ' and its table data will be removed. continue?'],...
0148                  'Confirm', 'Yes', 'No', 'Yes');
0149         if strcmpi(res, 'yes')
0150             % remove variable from the table
0151             [data.bmgr] = vb_batch_mgr_remove_variable(data.bmgr, remove_name);
0152         end
0153     case H.edit_table_push
0154         components = [H.variable_add_push;
0155                       H.variable_remove_push;
0156                       H.variable_rename_push;
0157                       H.create_concrete_parm_push];
0158         set(components, 'Enable', 'off');
0159         [data.bmgr] = vb_batch_mgr_edit_table(data.bmgr);
0160         set(components, 'Enable', 'on');
0161     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0162     % Make Parameter button
0163     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0164     case H.create_concrete_parm_push
0165         % Clean up output ids
0166         [data.bmgr] = vb_batch_mgr_set_output_index_list(data.bmgr, []);
0167         % Create concrete parameters from Table and Template
0168         [data.bmgr, cancelled] = vb_batch_mgr_create_concrete_parm(data.bmgr);
0169         if cancelled
0170             vb_batch_list_put_log(fig, 'Cancelled operation(Create parameter set).');
0171         else
0172             vb_batch_list_put_log(fig, ['Parameter set were created.(' datestr(now,31) ')']);
0173         end
0174     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0175     % Created parameter set
0176     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0177     case H.concrete_parm_upper_push
0178         ix_main = get(H.concrete_parm_id_listbox, 'Value');
0179         idx1 = get(H.concrete_parm_listbox, 'Value');
0180         idx2 = idx1-1;
0181         if idx2 == 0
0182             return;
0183         else
0184             [data.bmgr] = vb_batch_mgr_swap_parm(data.bmgr, ix_main, idx1, idx2);
0185             set(H.concrete_parm_listbox, 'Value', idx2);
0186         end
0187     case H.concrete_parm_lower_push
0188         ix_main = get(H.concrete_parm_id_listbox, 'Value');
0189         [last] = vb_batch_mgr_get_num_of_parm(data.bmgr, ix_main);
0190         idx1 = get(H.concrete_parm_listbox, 'Value');
0191         idx2 = idx1+1;
0192         if idx1 == last
0193             return;
0194         else
0195             [data.bmgr] = vb_batch_mgr_swap_parm(data.bmgr, ix_main, idx1, idx2);
0196             set(H.concrete_parm_listbox, 'Value', idx2);
0197         end
0198     case H.concrete_parm_remove_push
0199         ix_main = get(H.concrete_parm_id_listbox, 'Value');
0200         ix_sub  = get(H.concrete_parm_listbox, 'Value');
0201         res = questdlg('Selected parameter will be removed. continue?',...
0202                  'Confirm', 'Yes', 'No', 'Yes');
0203         if strcmpi(res, 'yes')
0204             [data.bmgr] = vb_batch_mgr_remove_parm(data.bmgr, ix_main, ix_sub);
0205         end
0206     case H.concrete_parm_copy_push
0207         ix_main = get(H.concrete_parm_id_listbox, 'Value');
0208         ix_sub  = get(H.concrete_parm_listbox, 'Value');
0209         [data.bmgr] = vb_batch_mgr_duplicate_parm(data.bmgr, ix_main, ix_sub);
0210     case {H.concrete_parm_edit_push, H.concrete_parm_listbox}
0211         if hObj == H.concrete_parm_listbox
0212             if strcmpi(get(fig, 'SelectionType'), 'open')
0213                 % If listbox is double clicked, edit parameter
0214             else
0215                % single click
0216                 return;
0217             end
0218         end
0219         ix_main = get(H.concrete_parm_id_listbox, 'Value');
0220         ix_sub  = get(H.concrete_parm_listbox, 'Value');
0221         if ~isempty(ix_main) && ~isempty(ix_sub)
0222             [data.bmgr, errmsg] = ...
0223                 vb_batch_mgr_edit_parm(data.bmgr, ix_main, ix_sub);
0224         end
0225     %%%%%%%%%%%%%%%%%%%%
0226     % Build batch file
0227     %%%%%%%%%%%%%%%%%%%%
0228     case H.choose_id_list_push
0229         Nparm_set = vb_batch_mgr_get_num_of_parm_set(data.bmgr);
0230         id_strings = cell(Nparm_set, 1);
0231         for k=1:Nparm_set
0232             ix_main = k; ix_sub = 1;
0233             [p, p_type, id_strings{k,1}] = ...
0234                     vb_batch_mgr_get_parm(data.bmgr, ix_main, ix_sub);
0235         end
0236         [id_list, IsOK] = listdlg('PromptString', 'Choose IDs for output', ...
0237                               'ListString', id_strings, ...
0238                               'InitialValue', [1:length(id_strings)], ...
0239                               'ListSize', [160, 300]);
0240         if IsOK
0241             [data.bmgr] = vb_batch_mgr_set_output_index_list(...
0242                                                       data.bmgr, id_list');
0243         end
0244     case H.build_batch_push
0245         define = vb_define_extension;
0246         [dir, fnames] = vb_file_select({define.VBMEG_BATCH_EXTENSION},...
0247                                        'Save VBMEG batch file', true);
0248         if ~isempty(dir)
0249             output_file = fullfile(dir, fnames{1});
0250             if exist(output_file, 'file') == 2
0251                 res = questdlg('File already exists. Overwrite?', ...
0252                             'Confirm', 'Yes', 'No', 'Yes');
0253                 if strcmpi(res, 'no'), return; end
0254             end
0255             proj_info = struct;
0256             proj_info.proj_name = data.proj_name;
0257             proj_info.proj_root = data.proj_root;
0258             proj_info.proj_file = data.proj_file;
0259             [result, msg] = ...
0260                 vb_batch_mgr_build_batch_file(data.bmgr, ...
0261                                               proj_info, output_file);
0262             if result == FAILURE
0263                 errordlg('Failed to save file.');
0264                 vb_batch_list_put_log(fig, msg);
0265             else
0266                 vb_batch_list_put_log(fig, ...
0267                           ['batchfile : ' output_file ' was created!']);
0268                 vb_batch_list_put_log(fig, ...
0269                           ['run script : vb_run_batch(batchfile, logfile);']);
0270             end
0271         end
0272     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0273     % Other buttons(save, cancel, help..)
0274     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0275     case H.save_push
0276         save = true;
0277         inner_close_batch_list(fig, data.bmgr, save);
0278         return;
0279     case {H.cancel_push, H.figure}
0280         if isequal(data.initial_state, data.bmgr) == false
0281             res = questdlg('Save current settings?',...
0282                           'Confirm', 'Yes', 'No', 'Cancel', 'Yes');
0283             if strcmpi(res, 'yes')
0284                 save = true;
0285                 inner_close_batch_list(fig, data.bmgr, save);
0286             elseif strcmpi(res, 'no');
0287                 save = false;
0288                 inner_close_batch_list(fig, data.bmgr, save);
0289             end
0290         else
0291             save = false;
0292             inner_close_batch_list(fig, data.bmgr, save);
0293         end
0294         return;
0295     case H.help_push
0296         h = vb_batch_list_help;
0297 end
0298 
0299 % save data
0300 guidata(fig, data);
0301 vb_batch_list_update_screen(fig);
0302 
0303 
0304 function inner_close_batch_list(fig, bmgr, save)
0305 
0306 % save current settings to project file.
0307 if save
0308     [result, errmsg] = project_mgr_builder_close(bmgr);
0309     while(1)
0310         if result == SUCCESS
0311             closereq;
0312             return;
0313         else
0314             vb_batch_list_put_log(fig, errmsg);
0315             res = questdlg('Failed to save file. Do you retry?', ...
0316                      'Confirm', ...
0317                      'Yes', 'No', 'Yes');
0318             if strcmpi(res, 'yes')
0319                 [result, errmsg] = project_mgr_builder_close(bmgr);
0320             elseif strcmpi(res, 'no')
0321                 return;
0322             end
0323         end
0324     end
0325 else
0326     project_mgr_builder_close([]);
0327     closereq;
0328 end

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