0001 function [current_parm, cancelled] = current_gui_advanced(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if nargin == 0
0016 key = 'init';
0017 else
0018 key = varargin{1};
0019 end
0020
0021 if ~strcmp(key, 'init')
0022 h = get(0, 'CurrentFigure');
0023 data = figure_load_data(h);
0024 end
0025
0026
0027 switch(key)
0028
0029
0030
0031 case 'init'
0032 if nargin < 2
0033 current_parm = [];
0034 else
0035 current_parm = varargin{2};
0036 end
0037
0038 h = findobj('Name', APPLICATION_NAME);
0039 if ~isempty(h)
0040 res = questdlg('Already opened. Reopen?',...
0041 'confirm', 'Yes', 'No', 'Yes');
0042 if strcmp(res, 'Yes')
0043 destruct_gui;
0044 else
0045
0046 figure(h);
0047 return;
0048 end
0049 end
0050
0051 data = create_gui(current_parm);
0052 figure_save_data(data.H.figure, data);
0053
0054
0055 waitfor(data.H.figure, 'Visible', 'off');
0056
0057
0058 data = figure_load_data(data.H.figure);
0059 cancelled = data.cancelled;
0060 current_parm = data.current_parm;
0061
0062 destruct_gui;
0063 return;
0064 case 'exit'
0065 destruct_gui;
0066 return;
0067 case 'set_parm'
0068 current_parm = varargin{2};
0069 set_parm_gui(data, current_parm);
0070 case 'get_parm'
0071 current_parm = get_parm_gui(data);
0072
0073
0074
0075
0076
0077
0078 case 'callback'
0079 hObj = varargin{2};
0080 data = callback(data, hObj);
0081 end
0082
0083 figure_save_data(data.H.figure, data);
0084
0085
0086 function [data] = create_gui(current_parm)
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 fig = openfig('current_gui_advanced');
0098 H = guihandles(fig);
0099 H.figure = fig;
0100 set(fig, 'Name', APPLICATION_NAME);
0101
0102
0103 data = struct;
0104 data.H = H;
0105 data.cancelled = false;
0106 data.current_parm = current_parm;
0107
0108
0109
0110 function destruct_gui
0111
0112
0113
0114
0115
0116
0117 h = get(0, 'CurrentFigure');
0118 if strcmp(get(h, 'Name'), APPLICATION_NAME)
0119 else
0120 h = findobj('Name', APPLICATION_NAME);
0121 end
0122 try
0123 delete(h);
0124 catch
0125 end
0126
0127
0128 function figure_save_data(fig, data)
0129
0130
0131
0132
0133 guidata(fig, data);
0134
0135
0136 function [data] = figure_load_data(fig)
0137
0138 data = [];
0139 if isempty(fig) || ~ishandle(fig)
0140 data.current_parm = [];
0141 data.cancelled = true;
0142 else
0143 data = guidata(fig);
0144 end
0145
0146
0147 function [data] = callback(data, hObj)
0148
0149
0150
0151
0152
0153
0154
0155 H = data.H;
0156 switch(hObj)
0157 case {H.overlapped_radiobutton, H.concatenate_radiobutton}
0158 radiobutton_group = [H.overlapped_radiobutton, ...
0159 H.concatenate_radiobutton];
0160 set(radiobutton_group, 'Value', 0);
0161 set(hObj, 'Value', 1);
0162 case H.cancel_push
0163 data.cancelled = true;
0164 set(H.figure, 'Visible', 'off');
0165 case H.ok_push
0166 data.current_parm = get_parm_gui(data);
0167 data.cancelled = false;
0168 set(H.figure, 'Visible', 'off');
0169 end
0170
0171 get(hObj, 'Tag')
0172
0173
0174 function current_parm = get_parm_gui(data)
0175 current_parm = [];
0176
0177 function v = APPLICATION_NAME
0178 v = 'current_parm';
0179