Newer
Older
function error = preferencesForm(hTsgGUI)
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
%
% Output
% ------
% error .............. 1: OK ; -1 : an error occured
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
error = -1;
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata(hTsgGUI, 'tsg_data');
% set default uicontrol size
% --------------------------
height = 0.03;
length = .15;
% Define uicontrol start position
% -------------------------------
left = .01;
bottom = .95;
inc_x = 3 * length;
inc_y = 0.01;
% preferences Uicontrols in a new figure
% ---------------------------------
hPreferencesFig = figure(...
'BackingStore','off',...
'Name', 'TSGQC PREFERENCES', ...
'NumberTitle', 'off', ...
'Resize', 'on', ...
'Menubar','none', ...
'Toolbar', 'none', ...
'Tag', 'TSG_PREFERENCES', ...
'Visible','on',...
'WindowStyle', 'modal', ...
'Units', 'normalized',...
'Position',get(hTsgGUI,'Position'), ...
'Color', get(0, 'DefaultUIControlBackgroundColor'));
% display climatology text
% -------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, length, height], ...
'TooltipString', 'select climatology origin', ...
'String', 'Climatology');
% display climatology uicontrol
% -----------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'popupmenu', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left + length, bottom, length, height], ...
'String', tsg.preference.levitus_version, ...
'Value', tsg.preference.levitus_value, ...
'Tag', 'PREFERENCES_LEVITUS_VALUE');
bottom = bottom - inc_y - height;
if bottom < .1
bottom = 0.95;
left = left + inc_x;
end
% display climatology depth text
% -------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, length, height], ...
'TooltipString', 'select climatology depth', ...
'String', 'Climatology depth');
% display climatology depth uicontrol
% ------------------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'popupmenu', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left + length, bottom, length, height], ...
'String', tsg.preference.levitus_depth_string, ...
'Value', tsg.preference.levitus_depth_value, ...
'Tag', 'PREFERENCES_LEVITUS_DEPTH');
bottom = bottom - inc_y - height;
if bottom < .1
bottom = 0.95;
left = left + inc_x;
end
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
% display ship speed test text
% ----------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, length, height], ...
'TooltipString', 'enable/disable ship speed test', ...
'String', 'Ship Speed Test');
% display ship speed test uicontrol
% ---------------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'popupmenu', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left + length, bottom, length, height], ...
'String', tsg.preference.ship_speed_test_string, ...
'Value', tsg.preference.ship_speed_test, ...
'Tag', 'PREFERENCES_SHIP_SPEED_TEST');
bottom = bottom - inc_y - height;
if bottom < .1
bottom = 0.95;
left = left + inc_x;
end
% display ship speed min text
% -----------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, length, height], ...
'TooltipString', 'select ship speed min (knots)', ...
'String', 'Ship Speed Min');
% display ship speed min uicontrol
% --------------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'popupmenu', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left + length, bottom, length, height], ...
'String', tsg.preference.ship_speed_min_string, ...
'Value', tsg.preference.ship_speed_min, ...
'Tag', 'PREFERENCES_SHIP_SPEED_MIN');
bottom = bottom - inc_y - height;
if bottom < .1
bottom = 0.95;
left = left + inc_x;
end
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
% display connected line text
% -------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, length, height], ...
'TooltipString', 'select plot with connected line', ...
'String', 'Plot with connectd line');
% display connected line uicontrol
% --------------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'popupmenu', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left + length, bottom, length, height], ...
'String', tsg.preference.plot_connected_string , ...
'Value', tsg.preference.plot_connected_value , ...
'Tag', 'PREFERENCES_PLOT_CONNECTED_LINE');
% display conventions field if exist
% ----------------------------------
% uicontrol(...
% 'Parent', hPreferencesFig, ...
% 'Units', 'normalized', ...
% 'Style', 'text', ...
% 'Fontsize', tsg.fontSize-2, ...
% 'HorizontalAlignment', 'left', ...
% 'Position', [left + 2*length, bottom, length, height], ...
% 'String', char(s.conventions));
bottom = bottom - inc_y - height;
if bottom < .1
bottom = 0.95;
left = left + inc_x;
end
% display coefficient type text
% -----------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, length, height], ...
'TooltipString', 'select coefficients type', ...
'String', 'Coefficients type');
% display coefficient type uicontrol
% ----------------------------------
uicontrol(...
'Parent', hPreferencesFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'popupmenu', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left + length, bottom, length, height], ...
'String', tsg.preference.coeff_type_string , ...
'Value', tsg.preference.coeff_type_value , ...
'Tag', 'PREFERENCES_COEFF_TYPE');
bottom = bottom - inc_y - height;
if bottom < .1
bottom = 0.95;
left = left + inc_x;
end
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
% CONTINUE PUSH BUTTON
% --------------------
% The Continue (valid) button
uicontrol( ...
'Parent', hPreferencesFig, ...
'Style','pushbutton',...
'Fontsize', tsg.fontSize,...
'Units', 'normalized', ...
'Position',[.01, .01, .1, .04],...
'String','Continue',...
'Interruptible','off',...
'BusyAction','cancel',...
'Tag','PREF_CONTINUE_BUTTON',...
'Callback', @continueCallback);
% CANCEL PUSH BUTTON
% ------------------
% The cancel button
uicontrol( ...
'Parent', hPreferencesFig, ...
'Style','pushbutton',...
'Fontsize', tsg.fontSize,...
'Units', 'normalized', ...
'Position',[.2, .01, .1, .04],...
'String','Cancel',...
'Interruptible','off',...
'BusyAction','cancel',...
'Tag','PREF_CANCEL_BUTTON',...
'Callback', @cancelCallback);
% Build structure container for graphic handles with tag property defined.
% ------------------------------------------------------------------------
prefs = guihandles(hPreferencesFig);
% record data struct in application data object
% ---------------------------------------------
% guidata(hHeaderFig, data);
% stop execution until push-button Continue was press
% ---------------------------------------------------
uiwait(hPreferencesFig);
%% Nested callback
% -----------------------------------------------------------------------
% Continue action, get uicontrol fields and populate tsg structure
% -----------------------------------------------------------------------
function continueCallback(obj, event)
% Save tsg structure
% ------------------
setappdata(hTsgGUI, 'tsg_data', tsg);
% get the corresponding string from uicontrol using guihandles
% and save value in tsg.preferences struct
% ------------------------------------------------------------
tsg.preference.levitus_value = ...
get(prefs.PREFERENCES_LEVITUS_VALUE, 'value');
get(prefs.PREFERENCES_LEVITUS_DEPTH, 'value');
tsg.preference.ship_speed_test = ...
get(prefs.PREFERENCES_SHIP_SPEED_TEST, 'value');
tsg.preference.ship_speed_min = ...
get(prefs.PREFERENCES_SHIP_SPEED_MIN, 'value');
get(prefs.PREFERENCES_PLOT_CONNECTED_LINE, 'value');
tsg.preference.coeff_type_value = ...
get(prefs.PREFERENCES_COEFF_TYPE, 'value');
% Save tsg structure
% ------------------
setappdata(hTsgGUI, 'tsg_data', tsg);
% fill tsg calibration variables
% ------------------------------
updateTsgStructWithCalCoeff(hTsgGUI);
% apply ship speed QC
% -------------------
minSpeedQC(hTsgGUI);
% close windows (replace call to uiresume(hHeaderFig))
% ----------------------------------------------------
close(hPreferencesFig);
% flushes the event queue and updates the figure window
% -----------------------------------------------------
drawnow;
% return with no error code (true)
% --------------------------------
error = 1;
return
end
% -----------------------------------------------------------------------
% Cancel button, no action
% -----------------------------------------------------------------------
function cancelCallback(obj, event)
% close windows
% -------------
close(hPreferencesFig);
% flushes the event queue and updates the figure window
% -----------------------------------------------------
drawnow;
% return error code (no change)
% -----------------------------
error = -1;
end % end of cancelCallback nested function
end