Skip to content
Snippets Groups Projects
Commit d2a38530 authored by leprob001's avatar leprob001
Browse files

Added first version of the +gui and +controller packages.

parent 77f607f4
No related branches found
No related tags found
No related merge requests found
Showing
with 555 additions and 0 deletions
function [ ] = close()
%CLOSEREQ Cleans up all variables that are used by the editTemperature GUI.
% Changes to the data is not being modified.
global artoaGui;
%% Close the figure
delete(artoaGui.figures.editTemperature);
%% Clean up variables
artoaGui = rmfield(artoaGui, 'editTemperature');
artoaGui.figures = rmfield(artoaGui.figures, 'editTemperature');
end
function [] = deleteSelectedPoints()
%DELETESELECTEDPOINTS Summary of this function goes here
% Detailed explanation goes here
global artoaWorkspace;
%% Check if selection exists
if ~isfield(artoaWorkspace, 'selectedPolygon') || ~isvalid(artoaWorkspace.selectedPolygon)
return;
end
%% Get polygon data
selectedPolygonX = artoaWorkspace.selectedPolygon.XData;
selectedPolygonY = artoaWorkspace.selectedPolygon.YData;
if isempty(selectedPolygonX) || isempty(selectedPolygonY)
return;
end
%% Find indices of selected points in temperature array
selectedPoints = inpolygon( ...
artoaWorkspace.rafosDate, ...
artoaWorkspace.temperature, ...
selectedPolygonX, ...
selectedPolygonY ...
);
%% Mark data as deleted
artoaWorkspace.status(selectedPoints) = 2;
%% Update gui
artoa.controller.edit.temperature.plot();
end
function [] = open()
%OPENEDITTEMPERATURE Initializes the temperature editing gui.
% Detailed explanation goes here
global artoaGui;
%% Check if the gui is already opened
if isfield(artoaGui.figures, 'editTemperature')
figure(artoaGui.figures.editTemperature);
return
end
%% Open the gui
artoa.gui.edit.temperature();
end
function [] = pickPolygon()
%PICKPOLYGON Lets the user pick a polygon in the plot.
% During selection, a line is being plotted that shows the selected
% points by the user.
global artoaGui artoaWorkspace;
%% Save current state of window button down
windowButtonDownFunction = get( ...
artoaGui.figures.editTemperature, ...
'WindowButtonDownFcn' ...
);
%% Disable current window button down
set( ...
artoaGui.figures.editTemperature, ...
'WindowButtonDownFcn', ...
'' ...
);
%% Select polygon by mouse
x = [];
y = [];
% draw the line that will be extended on every click
artoaWorkspace.selectedPolygon = line( ...
NaN, NaN, 'Color', [1 1 1], 'LineStyle', '-' ...
);
[dx, dy, button] = ginput(1);
while button == 1
% get boundaries
bound = artoaGui.figures.editTemperature.CurrentAxes.XLim;
dx = artoa.data.adjustToBoundaries(dx, bound(1), bound(2));
bound = artoaGui.figures.editTemperature.CurrentAxes.YLim;
dy = artoa.data.adjustToBoundaries(dy, bound(1), bound(2));
% add values to array
x = [x; dx];
y = [y; dy];
if length(x) == 1
continue;
end
% update the line
set(artoaWorkspace.selectedPolygon, 'XData', x, 'YData', y);
[dx, dy, button] = ginput(1);
end
% close the poligon by adding the first value as the last one
if length(x) > 3 % a polygon can only be closed if there are more than two values
x = [x; x(1)];
y = [y; y(1)];
end
% update the line
set(artoaWorkspace.selectedPolygon, 'XData', x, 'YData', y);
%% Restore window button down
set( ...
artoaGui.figures.editTemperature, ...
'WindowButtonDownFcn', ...
windowButtonDownFunction ...
);
end
function [] = plot()
%PLOT Plots or updates the temperature points.
% If the plot already exists and is valid, the points only get updated.
% Otherwise the plot will be initialized
%
global artoaGui artoaWorkspace;
hold on
%% Get all required values
% create color vector
c = repmat([1 1 0], length(artoaWorkspace.rafosDate), 1);
c(artoaWorkspace.status == 1, :) = repmat([1 1 1], length(c(artoaWorkspace.status == 1, 1)), 1);
c(artoaWorkspace.status == 2, :) = repmat([1 0 0], length(c(artoaWorkspace.status == 2, 1)), 1);
if artoaWorkspace.showAllDataPoints
x = artoaWorkspace.rafosDate;
y = artoaWorkspace.temperature;
else
x = artoaWorkspace.rafosDate(artoaWorkspace.status ~= 2);
y = artoaWorkspace.temperature(artoaWorkspace.status ~= 2);
c = c(artoaWorkspace.status ~= 2, :);
end
%% If the plot exists, just update the values
if isfield(artoaGui.editTemperature, 'scatterTemperature') ...
&& isvalid(artoaGui.editTemperature.scatterTemperature)
artoaGui.editTemperature.scatterTemperature.XData = x;
artoaGui.editTemperature.scatterTemperature.YData = y;
artoaGui.editTemperature.scatterTemperature.CData = c;
return
end
% get all points that are not deleted
artoaGui.editTemperature.scatterTemperature = scatter( ...
x, ...
y, ...
[], ...
c, ... %'.', 'MarkerSize', 10 ...
'filled' ...
);
grid on;
% set background color
set(gca, 'Color', [.3 .3 .3], 'XColor', 'blue', 'YColor', 'blue');
% set plot title
titleVal = [ ...
'Project: ' artoaWorkspace.float.projectname ...
' FloatId: ' num2str(artoaWorkspace.float.floatname) ...
' Cycle: ' num2str(artoaWorkspace.float.cycle(1)) ...
' - Temperature' ...
];
titleHandle = title(titleVal, 'FontSize', 10);
set(titleHandle, 'Color', 'blue');
% set x and y label
xlabel('Message Date', 'FontSize', 10);
ylabel('Temperature [C]', 'FontSize', 10);
hold off
end
function [] = copyRfbToWorkspace()
%COPYRFBTOWORKSPACE Copies rfb input data to the workspace.
%
global artoaDataInput artoaWorkspace;
%% Generate workspace
% TOA
artoaWorkspace.toaData = struct();
artoaWorkspace.toaData.status = zeros( ...
size(artoaDataInput.rfb.DATA, 1) * length(artoaDataInput.rfb.VARIABLE_LIST.time_of_arrival), ...
1 ...
);
% TEMPERATURE
artoaWorkspace.temperature = artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.temperature);
% PRESSURE
artoaWorkspace.pressure = artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.pressure);
% STATUS
artoaWorkspace.status = zeros(size(artoaDataInput.rfb.DATA, 1), 1);
% EXCLUDE LINES CONTAINING 9999
temperatureToExclude = artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.temperature) == 9999;
pressureToExclude = artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.pressure) == 9999;
pointsToExclude = or(temperatureToExclude, pressureToExclude);
artoaWorkspace.status(pointsToExclude) = 2;
% RAFOS DATE
artoaWorkspace.rafosDate = artoa.convert.dmy2rd( ...
artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.start_listen_day), ...
artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.start_listen_mon), ...
artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.start_listen_yr) ...
) ...
+ ...
artoa.convert.hms2rd( ...
artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.start_listen_hr), ...
artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.start_listen_min), ...
artoaDataInput.rfb.DATA(:, artoaDataInput.rfb.VARIABLE_LIST.start_listen_sec) ...
);
% FLOAT DETAILS
artoaWorkspace.float = artoaDataInput.rfb.FLOAT;
end
function [] = initializeArtoa4()
%INITIALIZEARTOA4 Initializes variables required for artoa4 and creates the main window if required.
%
global artoaDataInput artoaDataOutput artoaWorkspace artoaGui;
%% When the gui exists, focus it
if isfield(artoaGui, 'figures') && isfield(artoaGui.figures, 'main')
figure(artoaGui.figures.main.Number);
return
end
%% Initalize required variables
artoaDataInput = struct();
artoaDataOutput = struct();
artoaWorkspace = struct();
artoaWorkspace.showAllDataPoints = false;
artoaGui = struct();
artoaGui.figures = struct();
artoaGui.main = struct();
%% Start artoa4
artoa.gui.main();
end
function [] = loadRfb()
%LOADRFB Creates a file selection dialog and reads the file into memory.
global artoaGui artoaDataInput;
%% Initialize variables
artoaDataInput.rfb = false;
%% Create file dialog and filename
[file, path] = uigetfile('*.rfb');
filepath = fullfile(path, file);
%% Check if file exists
if ~isfile(filepath)
error([mfilename ': Selected file ' filepath ' is not a file! Please try again!']);
end
%% Load file into memory
artoaDataInput.rfb = artoa.load.rfb(filepath);
%% Update workspace
artoa.controller.copyRfbToWorkspace();
%% Update menu buttons
if ~islogical(artoaDataInput.rfb)
artoaGui.main.menus.edit.Enable = 'on';
end
end
function [] = quit()
%QUIT Closes all windows, cleans up workspace and quits ARTOA4.
global artoaGui;
openedFigures = fieldnames(artoaGui.figures);
for i = 1:length(openedFigures)
current = openedFigures{i};
if strcmp(current, 'main')
continue;
end
delete(artoaGui.figures.(current).Number);
end
% Close main figure
delete(artoaGui.figures.main.Number);
clearvars -global artoaGui artoaDataInput artoaDataOutput artoaWorkspace;
end
function [] = switchViewShowAll()
%SWITCHVIEWSHOWALL Switches wether all data points are shown or not.
% Switches the menu checkbox and updates the workspace accordingly.
global artoaWorkspace artoaGui;
if strcmp(artoaGui.main.menus.viewShowAllPoints.Checked, 'off')
artoaGui.main.menus.viewShowAllPoints.Checked = 'on';
artoaWorkspace.showAllDataPoints = true;
else
artoaGui.main.menus.viewShowAllPoints.Checked = 'off';
artoaWorkspace.showAllDataPoints = false;
end
end
function [adjustedInput] = adjustToBoundaries(inputValue, lowerBoundary, upperBoundary)
%ADJUSTTOBOUNDARIES If input data exceeds boundaries, it will received boundary value.
% If the input value exceeds the upper or lower limit that is given, the
% input data will become the boundary.
%
% Parameters:
% inputValue (number) The value that will be checked.
% lowerBoundary (number) The lower boundary.
% upperBoundary (number) The upper boundary.
%% Initialize return variable
adjustedInput = inputValue;
%% Check for lower boundary
if inputValue < lowerBoundary
adjustedInput = lowerBoundary;
return;
end
%% Check for upper boundary
if inputValue > upperBoundary
adjustedInput = upperBoundary;
return;
end
end
function [] = temperature()
%TEMPERATURE Defines the ARTOA4 edit temperature window.
global artoaGui artoaWorkspace;
%% Initialize required variables
windowTitle = [ 'ARTOA4 - Float ' num2str(artoaWorkspace.float.floatname) ' - Temperature' ];
%% Initialize temperature gui
artoaGui.figures.editTemperature = figure( ...
'Name', windowTitle, ...
'NumberTitle', 'off' ...
);
artoaGui.editTemperature = struct();
set( ...
artoaGui.figures.editTemperature, ...
'CloseRequestFcn', ...
'artoa.controller.edit.temperature.close();' ...
);
%% Generate Plot
artoa.controller.edit.temperature.plot();
set(gca, 'Position', [0.13 0.11 0.706 0.815]);
%% Generate Controls
left = .85;
width = .14;
buttonHeight = .05;
buttonMarginLeftRight = .005;
artoaGui.editTemperature.frameControls = uicontrol( ...
'Style', 'Frame', ...
'Units', 'normalized', ...
'BackgroundColor', 'white', ...
'Position', [left .11 width .815] ...
);
artoaGui.editTemperature.frameHeadline = uicontrol( ...
'Style', 'Text', ...
'Units', 'normalized', ...
'FontSize', 8, ...
'BackgroundColor', 'white', ...
'Position', [(left+buttonMarginLeftRight) .85 (width-2*buttonMarginLeftRight) buttonHeight], ...
'String', 'Data' ...
);
artoaGui.editTemperature.buttonPick = uicontrol( ...
'String', 'Pick', ...
'Style', 'PushButton', ...
'FontSize', 8, ...
'Units', 'normalized', ...
'Position', [(left+buttonMarginLeftRight) .8 (width-2*buttonMarginLeftRight) buttonHeight], ...
'CallBack', 'artoa.controller.edit.temperature.pickPolygon();' ...
);
artoaGui.editTemperature.buttonDelete = uicontrol( ...
'String', 'Delete', ...
'Style', 'PushButton', ...
'FontSize', 8, ...
'Units', 'normalized', ...
'Position', [(left+buttonMarginLeftRight) .75 (width-2*buttonMarginLeftRight) buttonHeight], ...
'CallBack', 'artoa.controller.edit.temperature.deleteSelectedPoints();' ...
);
end
function [ ] = main()
%MAIN Contains the definition of main ARTOA4 gui.
global artoaGui;
%% Initialize main window
artoaGui.figures.main = figure( ...
'Name', 'ARTOA 4', ...
'NumberTitle', 'off', ...
'Color', 'white', ...
'MenuBar', 'none' ...
);
set(artoaGui.figures.main, 'CloseRequestFcn', 'artoa.controller.quit();');
%% Initialize file menu
artoaGui.main.menus = struct();
artoaGui.main.menus.file = uimenu(artoaGui.figures.main, 'Label', 'File');
% LOAD
loadHandle = uimenu(artoaGui.main.menus.file, 'Label', 'Load');
uimenu( ...
loadHandle, ...
'Label', 'ARGOS file', ...%'Callback', 'artoa.controller.loadArgos' ...
'Enable', 'off' ...
);
uimenu( ...
loadHandle, ...
'Label', 'RFB file', ...
'Callback', 'artoa.controller.loadRfb();' ...
);
uimenu( ...
loadHandle, ...
'Label', 'Interim file', ...%'Callback', 'artoa.controller.loadInterim' ...
'Enable', 'off' ...
);
% SAVE
saveHandle = uimenu(artoaGui.main.menus.file, 'Label', 'Save');
uimenu( ...
saveHandle, ...
'Label', 'RIC file', ...
'Callback', 'artoa.controller.saveRic();', ...
'Enable', 'off' ...
);
% QUIT
artoaGui.main.menus.fileQuit = uimenu( ...
artoaGui.main.menus.file, ...
'Label', 'Quit', ...
'Callback', 'artoa.controller.quit();' ...
);
%% Initialize edit menu
artoaGui.main.menus.edit = uimenu( ...
artoaGui.figures.main, ...
'Label', 'Edit', ...
'Enable', 'off' ...
);
% TOA
%toaHandle = uimenu(artoaGui.main.menus.edit, 'Label', 'Time of Arrivals', 'Enable', 'off');
% TEMPERATURE
artoaGui.main.menus.editTemperature = uimenu( ...
artoaGui.main.menus.edit, ...
'Label', 'Temperature', ...
'Callback', 'artoa.controller.edit.temperature.open();' ...
);
% PRESSURE
%pressureHandle = uimenu(file, 'Label', 'Pressure', 'Enable', 'off');
%% Initialize view menu
artoaGui.main.menus.view = uimenu( ...
artoaGui.figures.main, ...
'Label', 'View', ...
'Enable', 'on' ...
);
artoaGui.main.menus.viewShowAllPoints = uimenu( ...
artoaGui.main.menus.view, ...
'Label', 'Show all data points', ...
'Callback', 'artoa.controller.switchViewShowAll();' ...
);
end
%% Start artoa4
global artoaDataInput artoaDataOutput artoaWorkspace artoaGui;
artoa.controller.initializeArtoa4();
\ No newline at end of file
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