Newer
Older
function error = headerForm(hTsgGUI)
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
%
% Output
% ------
% error .............. 1: OK ; -1 : an error occured
% $Id$
error = -1;
% Get the data from the application GUI
% -------------------------------------

jacques.grelet_ird.fr
committed
tsg = getappdata(hTsgGUI, 'tsg_data');
% load platform mat file
% ----------------------
%load platform.mat;
% Define uicontrol start position
% -------------------------------
left = .01;
bottom = .95;
inc_x = 0.5;
inc_y = 0.03;
% set default uicontrol size
% --------------------------
default_height = 0.018;
default_length = .1;

jacques.grelet_ird.fr
committed
% get actual date
% ---------------
date = datestr(now,30);
% Get global attributes list from class tsg_nc with file 'tsg_ncattr.csv'
% -----------------------------------------------------------------------
nca = tsg_nc('tsg_ncattr.csv');
nca_keys = keys(nca);
% Load platform_info object from tsg_platform_info.csv
% ---------------------------------------------------------
platform_info = tsg_nc('tsg_platform.csv');
% header Uicontrols in a new figure
% ---------------------------------
hHeaderFig = figure(...
'BackingStore','off',...
'Name', 'TSG GLOBAL ATTRIBUTES', ...
'NumberTitle', 'off', ...
'Resize', 'on', ...
'Menubar','none', ...
'Toolbar', 'none', ...
'Tag', 'GLOBAL_ATTRIBUTES', ...
'Visible','on',...
'Units', 'normalized',...
'Position',get(hTsgGUI,'Position'), ...

jacques.grelet_ird.fr
committed
'Color', get(0, 'DefaultUIControlBackgroundColor'));

jacques.grelet_ird.fr
committed
% bg = [0.92549 0.913725 0.847059] = get(0, 'DefaultUIControlBackgroundColor');
% Iterate from each element from object nca
% -------------------------------------

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% ------------------------

jacques.grelet_ird.fr
committed
% get all structure for the key

jacques.grelet_ird.fr
committed
% -----------------------------

jacques.grelet_ird.fr
committed
% set tsg.DATE_UPDATE
% -------------------
if strcmp(key, 'DATE_UPDATE')
tsg.(key) = [date(1:8) date(10:15)];
end
% check for empty field and replace them by default value
% -------------------------------------------------------
if isempty(s.length), s.length = default_length; end;
if isempty(s.height), s.height = default_height; end;

jacques.grelet_ird.fr
committed
% display dynamically uicontrol text
% use of char function to prevent error when field is empty [] => ''
% ------------------------------------------------------------------
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', char(s.comment), ...

jacques.grelet_ird.fr
committed
'String', char(s.name));
% display dynamically uicontrol
% -----------------------------
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', char(s.uicontrolType), ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', char(s.horizontalAlignment), ...
'Position', [left+.11, bottom, s.length, s.height], ...
'String', char(s.string), ...
'Value', s.value, ...
'Tag', key);

jacques.grelet_ird.fr
committed
% display conventions field if exist
% ----------------------------------
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'text', ...
'Fontsize', tsg.fontSize-2, ...

jacques.grelet_ird.fr
committed
'HorizontalAlignment', 'left', ...
'Position', [left+.22, bottom, .1, s.height], ...

jacques.grelet_ird.fr
committed
'String', char(s.conventions));

jacques.grelet_ird.fr
committed
% set dynamically uicontrol from tsg struct
% -----------------------------------------
switch s.uicontrolType
case 'popupmenu'
str = cellstr(get(ui,'String'));
ind = strfind(str,tsg.(key));
for k=1:numel(ind)
if ~isempty(ind{k})
set(ui, 'value', k);
end
end
case 'edit'
set(ui, 'string', tsg.(key));
case 'checkbox'
% not yet implemented !!!
end
% Check vertical position of last uicontrol and creation new colomn
% -----------------------------------------------------------------
bottom = bottom - inc_y;
if bottom < .15
bottom = 0.95;
left = left + inc_x;
end
end

jacques.grelet_ird.fr
committed
% additionnal variable here
% -------------------------
add_variables(bottom, left);
% set a callback to PLATFORM_NAME uicontrol
% -----------------------------------------

jacques.grelet_ird.fr
committed
set(findobj('Tag', 'PLATFORM_NAME'), 'Callback', @updateForm);
% CONTINUE PUSH BUTTON
% --------------------
% The Continue (valid) button
uicontrol( ...
'Parent', hHeaderFig, ...
'Style','pushbutton',...
'Units', 'normalized', ...
'Position',[.05, .1, .05, .02],...
'String','Continue',...
'Interruptible','off',...
'BusyAction','cancel',...
'Tag','PUSH_BUTTON',...
'Callback', @continueCallback);
% CANCEL PUSH BUTTON
% ------------------
% The cancel button
uicontrol( ...
'Parent', hHeaderFig, ...
'Style','pushbutton',...
'Units', 'normalized', ...
'Position',[.15, .1, .05, .02],...
'String','Cancel',...
'Interruptible','off',...
'BusyAction','cancel',...
'Tag','PUSH_BUTTON',...
'Callback', @cancelCallback);
% Build structure container for graphic handles with tag property defined.
% ------------------------------------------------------------------------
data = guihandles(hHeaderFig);
% record data struct in application data object
% ---------------------------------------------
% stop execution until push-button Continue was press
% ---------------------------------------------------
uiwait(hHeaderFig);
%% Nested callback
% -----------------------------------------------------------------------
% Continue action, get uicontrol fields and populate tsg structure
% -----------------------------------------------------------------------
function continueCallback(obj, event)
% get the PLATFORM_NAME value, use tag to retrieve
% ------------------------------------------------
value = get(findobj('Tag', 'PLATFORM_NAME'), 'string');
% get platform info structure from hashtable store in platform_info object
% ------------------------------------------------------------------------
p_i = get(platform_info, value);

jacques.grelet_ird.fr
committed
% get hashtable describing platform_info structure data type
% ----------------------------------------------------------
hdr = header(platform_info);
% Iterate from each element from object nca
% -------------------------------------

jacques.grelet_ird.fr
committed
for ii=1:numel(nca_keys)
% get key, use {} for cell
% ------------------------

jacques.grelet_ird.fr
committed
key = nca_keys{ii};
% get all structure for the key
% -----------------------------
s = get(nca, key);
% get the corresponding string from uicontrol using guihandles
% data (dynamic)
% ------------------------------------------------------------
tsg.(key) = get(data.(key), 'string');
% if uicontrol is a popupmenu, string is cell array with all choices
% ------------------------------------------------------------------
if strcmp(s.uicontrolType,'popupmenu')
% get the corresponding string from cell array using selected value
% ------------------------------------------------------------------
tsg.(key) = deblank(tsg.(key)(get(data.(key), 'value'),:));
% update p_i structure from tsg only with corresponding field
% -----------------------------------------------------------
if isfield(p_i, key)

jacques.grelet_ird.fr
committed
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
% get data type from platform_info structure
% ------------------------------------------
switch hdr.(key)
case 'char'
p_i.(key) = tsg.(key);
case 'byte'
p_i.(key) = int8(str2num(tsg.(key)));
case 'integer'
p_i.(key) = int16(str2num(tsg.(key)));
case 'float'
p_i.(key) = single(str2double(tsg.(key)));
case 'double'
p_i.(key) = str2double(tsg.(key));
otherwise
% by default, display a warning
% -----------------------------
warning('tsgqc:headerForm', ...
'unknow type ''%s'' for ''%s'' attribute.\nCheck your %s file', ...
hdr.(key), key, platform_info.file);
% and cast to char
% ----------------
p_i.(key) = tsg.(key);
end
% Save tsg structure

jacques.grelet_ird.fr
committed
setappdata(hTsgGUI, 'tsg_data', tsg);
% test if uicontrol not empty
% ---------------------------
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
if isempty(value)
warndlg({'PLATFORM NAME is empty';'';'Please, enter a valid PLATFORM name'},...
'Invalid PLATFORM name');
else
% Update plateform_info object with this PLATFORM_NAME value and
% platform info updated structure
% --------------------------------------------------------------
platform_info = set(platform_info, value, p_i);
% save object in csv file
% -----------------------
save(platform_info);
% close windows (replace call to uiresume(hHeaderFig))
% ----------------------------------------------------
close(hHeaderFig);
% 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(hHeaderFig);
% flushes the event queue and updates the figure window
% -----------------------------------------------------
drawnow;
% return error code (no change)
% -----------------------------
error = -1;
end
% -----------------------------------------------------------------------
% Callback when uicontrol PLATFORM_NAME is modified
% -----------------------------------------------------------------------
function updateForm(obj, event)
% get the new value, use tag to retrieve
% --------------------------------------

jacques.grelet_ird.fr
committed
value = get(findobj('Tag', 'PLATFORM_NAME'), 'string');
% get platform info structure from hashtable store in platform_info object
% ------------------------------------------------------------------------
p_i = get(platform_info, value);

jacques.grelet_ird.fr
committed
% get hashtable describing platform_info structure data type
% ----------------------------------------------------------
hdr = header(platform_info);
% if this platform exist, structure not empty
% -------------------------------------------
if ~isempty(p_i)

jacques.grelet_ird.fr
committed
% get members list of structure platform_name
% -------------------------------------------
nb = fieldnames(p_i);

jacques.grelet_ird.fr
committed
% iterate on all members
% ----------------------

jacques.grelet_ird.fr
committed
for ii=1:numel(nb)

jacques.grelet_ird.fr
committed
% key member name and use it as a key for tsg structure
% -----------------------------------------------------

jacques.grelet_ird.fr
committed
key = nb{ii};

jacques.grelet_ird.fr
committed
% update tsg with data from platform_info struct
% TODOS:
% may be add color test here
% ----------------------------------------------
tsg.(key) = p_i.(key);

jacques.grelet_ird.fr
committed
% get uicontrol style
% -------------------
type = get(data.(key), 'style');
% update headerform fields
% ------------------------
switch type
case 'edit'
set(data.(key), 'string', tsg.(key));
case 'popupmenu'
indice = strmatch(tsg.(key), get(data.(key), 'string'));
set(data.(key), 'value', indice);
end
% with different color
% --------------------

jacques.grelet_ird.fr
committed
set(findobj('Tag', key), 'foregroundColor', 'r');

jacques.grelet_ird.fr
committed
% if user enter a new PLATFORM_NAME, open a question dialog box for
% confirmation
% -----------------------------------------------------------------
questdlg(['PLATFORM NAME: ' value ' is new. Do you want to use and save it ?'],...
'Create new PLATFORM NAME ?',...
'Yes', 'No', 'No');

jacques.grelet_ird.fr
committed
% if yes, continue, create and save new hash for PLATFORM_NAME in csv file
% ------------------------------------------------------------------------
if strcmp(selection, 'Yes')
return;

jacques.grelet_ird.fr
committed
% if not, reset field
% -------------------
else
set(findobj('Tag','PLATFORM_NAME'),'string', '');
end
end

jacques.grelet_ird.fr
committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
end
% additionnal variable here
% -------------------------
function add_variables(bottom, left)
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', '', ...
'String', 'SSPS_DEPH');
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'edit', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left+.11, bottom, .1, .02], ...
'String', '', ...
'Tag', 'SSPS_DEPH');
bottom = bottom - inc_y;
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', '', ...
'String', 'SSPS_DEPH_MIN');
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'edit', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left+.11, bottom, .1, .02], ...
'String', '', ...
'Tag', 'SSPS_DEPH_MIN');
bottom = bottom - inc_y;
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', '', ...
'String', 'SSPS_DEPH_MAX');
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'edit', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left+.11, bottom, .1, .02], ...
'String', '', ...
'Tag', 'SSPS_DEPH_MAX');
bottom = bottom - inc_y;
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', '', ...
'String', 'SSTP_DEPH');
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'edit', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left+.11, bottom, .1, .02], ...
'String', '', ...
'Tag', 'SSTP_DEPH');
bottom = bottom - inc_y;
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', '', ...
'String', 'SSTP_DEPH_MIN');
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'edit', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left+.11, bottom, .1, .02], ...
'String', '', ...
'Tag', 'SSTP_DEPH_MIN');
bottom = bottom - inc_y;
uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .2, .017], ...
'TooltipString', '', ...
'String', 'SSTP_DEPH_MAX');
ui = uicontrol(...
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', 'edit', ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'right', ...
'Position', [left+.11, bottom, .1, .02], ...
'String', '', ...
'Tag', 'SSTP_DEPH_MAX');