Skip to content
Snippets Groups Projects
Commit 5f95da5f authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

load ( 'tsg_platform_info.mat' )

tsg structure is dynamically set
add lot of test between tsg_platform_info.mat and tsg structure
parent 594c3bc1
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,10 @@ error = -1;
% -------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
% load platform mat file
% ----------------------
%load platform.mat;
% Define uicontrol start position
% -------------------------------
left = .01;
......@@ -37,6 +41,11 @@ date = datestr(now,30);
nca = tsg_nc('tsg_ncattr.csv');
nca_keys = keys(nca);
% Load platform_info object from tsg_platform_info.mat file
% see: Use the form of load that returns a MATLAB structure.
% ---------------------------------------------------------
s = load( 'tsg_platform_info.mat' );
platform_info = s.platform_info;
% header Uicontrols in a new figure
% ---------------------------------
......@@ -55,8 +64,8 @@ hHeaderFig = figure(...
% bg = [0.92549 0.913725 0.847059] = get( 0, 'DefaultUIControlBackgroundColor' );
% Display fields from class
% -------------------------
% Iterate from each element from object nca
% -------------------------------------
for i=1:numel(nca_keys)
% get key, use {} for cell
......@@ -85,7 +94,7 @@ for i=1:numel(nca_keys)
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'Text', ...
'Fontsize', tsg.fontSize, ...
'Fontsize', tsg.fontSize-1, ...
'HorizontalAlignment', 'left', ...
'Position',[left, bottom, .13, .0135], ...
'TooltipString', char(s.comment), ...
......@@ -98,7 +107,7 @@ for i=1:numel(nca_keys)
'Units', 'normalized', ...
'BackgroundColor', 'w', ...
'Style', char(s.uicontrolType), ...
'Fontsize', tsg.fontSize-1, ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', char(s.horizontalAlignment), ...
'Position',[left+.11, bottom, s.length, s.height], ...
'String', char(s.string), ...
......@@ -111,11 +120,11 @@ for i=1:numel(nca_keys)
'Parent', hHeaderFig, ...
'Units', 'normalized', ...
'Style', 'text', ...
'Fontsize', tsg.fontSize-1, ...
'Fontsize', tsg.fontSize-2, ...
'HorizontalAlignment', 'left', ...
'Position',[left+.22, bottom, .1, s.height], ...
'String', char(s.conventions) );
% set dynamically uicontrol from tsg struct
% -----------------------------------------
switch s.uicontrolType
......@@ -142,6 +151,9 @@ for i=1:numel(nca_keys)
end
end
% set a callback to PLATFORM_NAME uicontrol
% -----------------------------------------
set(findobj('Tag','PLATFORM_NAME'),'Callback', @updateForm);
% CONTINUE PUSH BUTTON
% --------------------
......@@ -179,64 +191,74 @@ data = guihandles(hHeaderFig);
% record data struct in application data object
% ---------------------------------------------
%guidata(hHeaderFig, data);
% guidata(hHeaderFig, data);
% 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 uicontrol fields and populate tsg structure
% ------------------------------------------------
% for text only
% -------------
tsg.CYCLE_MESURE = get(data.CYCLE_MESURE, 'string');
tsg.PLATFORM_NAME = get(data.PLATFORM_NAME, 'string');
tsg.SHIP_CALL_SIGN = get(data.SHIP_CALL_SIGN, 'string');
tsg.SHIP_MMSI = get(data.SHIP_MMSI, 'string');
tsg.TSG_TYPE = get(data.TSG_TYPE, 'string');
tsg.TSG_NUMBER = get(data.TSG_NUMBER, 'string');
tsg.TINT_TYPE = get(data.TINT_TYPE, 'string');
tsg.TINT_NUMBER = get(data.TINT_NUMBER, 'string');
tsg.DATA_TYPE = get(data.DATA_TYPE, 'string');
tsg.DATA_MODE = get(data.DATA_MODE, 'string');
tsg.SAMPLING_PERIOD = get(data.SAMPLING_PERIOD, 'string');
tsg.DATE_START = get(data.DATE_START, 'string');
tsg.DATE_END = get(data.DATE_END, 'string');
tsg.SOUTH_LATX = get(data.SOUTH_LATX, 'string');
tsg.NORTH_LATX = get(data.NORTH_LATX, 'string');
tsg.WEST_LONX = get(data.WEST_LONX, 'string');
tsg.EAST_LONX = get(data.EAST_LONX, 'string');
tsg.FORMAT_VERSION = get(data.FORMAT_VERSION, 'string');
tsg.DATE_CREATION = get(data.DATE_CREATION, 'string');
tsg.DATE_UPDATE = get(data.DATE_UPDATE, 'string');
tsg.DATA_RESTRICTIONS = get(data.DATA_RESTRICTIONS, 'string');
tsg.COMMENT = get(data.COMMENT, 'string');
tsg.PROJECT_NAME = get(data.PROJECT_NAME, 'string');
tsg.PI_NAME = get(data.PI_NAME, 'string');
tsg.DATA_CENTRE = get(data.DATA_CENTRE, 'string');
tsg.DATA_ACQUISITION = get(data.DATA_ACQUISITION, 'string');
tsg.PROCESSING_CENTRE = get(data.PROCESSING_CENTRE, 'string');
tsg.PROCESSING_STATES = get(data.PROCESSING_STATES, 'string');
% for popupmenu only, deblank remove all trailling whitespace char
% ----------------------------------------------------------------
tsg.TSG_TYPE = deblank(tsg.TSG_TYPE(get(data.TSG_TYPE, 'value'),:));
tsg.TINT_TYPE = deblank(tsg.TINT_TYPE(get(data.TINT_TYPE, 'value'),:));
tsg.DATA_MODE = deblank(tsg.DATA_MODE(get(data.DATA_MODE, 'value'),:));
tsg.PI_NAME = deblank(tsg.PI_NAME(get(data.PI_NAME, 'value'),:));
tsg.DATA_ACQUISITION = deblank(tsg.DATA_ACQUISITION(get(data.DATA_ACQUISITION, 'value'),:));
tsg.PROCESSING_CENTRE = deblank(tsg.PROCESSING_CENTRE(get(data.PROCESSING_CENTRE, 'value'),:));
tsg.PROCESSING_STATES = deblank(tsg.PROCESSING_STATES(get(data.PROCESSING_STATES, 'value'),:));
% Iterate from each element from object nca
% -------------------------------------
for i=1:numel(nca_keys)
% get key, use {} for cell
% ------------------------
key = nca_keys{i};
% 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'),:));
end
% set and update pi (platform_info) structure from tsg only with
% corresponding field before save
% --------------------------------------------------------------
if isfield(platform_info, key)
pi.(key) = tsg.(key);
end
end
% Save tsg structure
% ------------------
setappdata( hTsgGUI, 'tsg_data', tsg);
% get the uicontrol PLATFORM_NAME value as key, use tag to retrieve
% -----------------------------------------------------------------
key = get(findobj('Tag','PLATFORM_NAME'),'string');
% Update plateform_info object with this key and platform_name
% updated structure
% --------------------------------------------------------------
platform_info = set(platform_info, key, pi);
% save object in mat file, use what to find tsg_nc path
% -----------------------------------------------------
w = what( 'tsg_nc');
save([w.path filesep 'tsg_platform_info.mat'], 'platform_info');
% close windows (replace call to uiresume(hHeaderFig))
% ----------------------------------------------------
close(hHeaderFig);
......@@ -248,8 +270,11 @@ uiwait(hHeaderFig);
% return no error code (true)
% ---------------------------
error = 1;
end
% -----------------------------------------------------------------------
% Cancel button, no action
% -----------------------------------------------------------------------
function cancelCallback(obj, event)
......@@ -264,6 +289,70 @@ uiwait(hHeaderFig);
% 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
% --------------------------------------
value = get(findobj('Tag','PLATFORM_NAME'),'string');
% get platform_name structure from platform_info object (mat file)
% ----------------------------------------------------------------
platform_name = get(platform_info, value);
% if this platform exist, structure not empty
% -------------------------------------------
if ~isempty(platform_name)
% get members list of structure platform_name
% -------------------------------------------
nb = fieldnames(platform_name);
% iterate on all members
% ----------------------
for i=1:numel(nb)
% key member name and use it as a key for tsg structure
% -----------------------------------------------------
key = nb{i};
tsg.(key) = platform_name.(key);
% update headerform fields with values from mat file
% --------------------------------------------------
set(findobj('Tag', key),'string',tsg.(key));
% with different color
% --------------------
set(findobj('Tag', key),'foregroundColor', 'r');
end
% if user enter a new PLATFORM_NAME, open a question dialog box for
% confirmation
% -----------------------------------------------------------------
else
selection = ...
questdlg('This PLATFORM NAME is new. Do you want to use and save it ?',...
'Create new PLATFORM NAME ?',...
'Yes', 'No', 'No');
% if yes, continue, create and save new PLATFORM_NAME in mat file
% ---------------------------------------------------------------
if strcmp(selection, 'Yes')
return;
% if not, reset field
% -------------------
else
set(findobj('Tag','PLATFORM_NAME'),'string', '');
end
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment