Newer
Older

jacques.grelet_ird.fr
committed
function tsg_preferences(hTsgGUI, app_name, DEFAULT_PATH_FILE)
% tsg_preferences(S1,S2) returns structure tsg saved in S1.mat file
% and with S2 internal version number.
% If S1.mat dosn't exist, call tsg_initialisation to create it in
% prefdir directory
%
% Input
% -----
% hTsgGUI ............ Handle to the main user interface
% app_name ............ application name
%
% Output
% ------
% none
%
% $Id$
%
% global variable VERSION, update revision number when tsg structure change
% -------------------------------------------------------------------------
global VERSION
% Construct config file path
% --------------------------
config_file = [prefdir, filesep, app_name, '.mat'];
% Open config file
% ----------------
% desactive la gestion des preferences, car la classe tsg.qc.hash (tsg_nc)
% est transformee en structure lors de l'ecriture, a verifier
% -----------------------------------------------------------

jacques.grelet_ird.fr
committed
fid = fopen( config_file, 'r' );
%fid = -2;
% test fopen return value
% -----------------------
switch fid
% preference file is missing
% --------------------------
case -1
% create new tsg structure and save it to appdata
% -----------------------------------------------
new_config;
% disactive the preference mode (for test or bug)
% -----------------------------------------------
case -2

jacques.grelet_ird.fr
committed
% init root structure to default values
% -------------------------------------
root.preference.autoload = 'off';
root.version = VERSION;
% call default tsg_initialisation
% -------------------------------
tsg_initialisation(hTsgGUI);
% save root in root object for next use
% -------------------------------------
set(0, 'userdata', root);
return;

jacques.grelet_ird.fr
committed
% file exist and is open, fid > 2
% -------------------------------
otherwise

jacques.grelet_ird.fr
committed
% Pointer set to watch during loading preference file
% ---------------------------------------------------
set( hTsgGUI, 'Pointer', 'watch' );

jacques.grelet_ird.fr
committed
% Initialize loading preference file waitbar
% ------------------------------------------
wb = waitbar(0, 'Loading préference file. Please wait...');

jacques.grelet_ird.fr
committed
% display waitbar

jacques.grelet_ird.fr
committed
% ---------------
waitbar( 1/10, wb, 'loading structure root' );

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% if file exist, load in workspace
% --------------------------------
load( config_file, 'root', 'tsg' );

jacques.grelet_ird.fr
committed
% transforme filename saved in tsg.qc.hash to tsg_nc object
% ---------------------------------------------------------
tsg.qc.hash = tsg_nc(tsg.qc.hash);

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% display warning
% ---------------
warning('tsgqc_GUI:tsg_preferences', ...
'Can''t load preference file ''%s''', config_file);
% quit program
% ------------
quitProgram(hTsgGUI, DEFAULT_PATH_FILE);

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% display waitbar
% ---------------
waitbar( 1/2, wb, 'loading structure tsg' );

jacques.grelet_ird.fr
committed
% Close waitbar
% -------------
close(wb)

jacques.grelet_ird.fr
committed
% cursor back to normal
% ---------------------
set(hTsgGUI,'Pointer','arrow');
% set current preference autoload in submenu option/preference
% ------------------------------------------------------------
set(findobj('tag', 'TAG_UIMENU_OPTION_PREFERENCES', ...
'checked', root.preference.autoload));
catch
warning('tsgqc_GUI:tsg_preferences', ...
['Preference file ''%s''\nis malformed\n' ...
'delete it.'], config_file);
quitProgram(hTsgGUI, DEFAULT_PATH_FILE);
end
% If there no field version or wrong version, initialize
% -------------------------------------------------------
if ~isfield( root, 'version') || ~strcmp(root.version, VERSION)
% call new config private function
% --------------------------------
new_config;
end
% Save structure tsg
% ------------------
setappdata( hTsgGUI, 'tsg_data', tsg);

jacques.grelet_ird.fr
committed
% save root in userdata property
% ------------------------------

jacques.grelet_ird.fr
committed
set(0, 'userdata', root);

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

jacques.grelet_ird.fr
committed
% nested function new_config
% ----------------------------------------------------------------------
function new_config

jacques.grelet_ird.fr
committed
% call default tsg_initialisation
% -------------------------------

jacques.grelet_ird.fr
committed
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
% init root structure to default values
% -------------------------------------
root.preference.autoload = 'off';
root.version = VERSION;

jacques.grelet_ird.fr
committed
% save root and tsg to 'prefdir.mat' file
% ---------------------------------------