Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • skyward/matlab-dependencies/common
1 result
Show changes
Commits on Source (10)
*.DS_Store
*.exe
*.dat
*.asv
*.f
*.json
......@@ -6,15 +6,28 @@ function exportFigureGUI
screenSize = get(0, 'ScreenSize'); % [left, bottom, width, height]
% Set the uifigure size
figWidth = 1400;
figWidth = 800;
figHeight = 700;
% Calculate position to center the figure
figX = (screenSize(3) - figWidth) / 2;
figX = (screenSize(3) - figWidth) / 10;
figY = (screenSize(4) - figHeight) / 2;
% Get the screen size
screenSize = get(0, 'ScreenSize');
screenWidth = screenSize(3);
screenHeight = screenSize(4);
% Define an offset from the top of the screen
topOffset = figY;
leftOffset = figX;
% Calculate the position for the new figures
positionGui = [leftOffset, screenHeight-figHeight-topOffset, figWidth, figHeight];
%% Create main figure window
fig = uifigure('Name', 'Export Standardized Figure', 'Position', [figX, figY, figWidth, figHeight]);
fig = uifigure('Name', 'Export Standardized Figure', 'Position', positionGui);
% Add title
titleLabel = uilabel(fig);
......@@ -27,24 +40,36 @@ titleLabel.Position = [0, fig.Position(4)-50, fig.Position(3), 30];
%% Input fields
% Figure Name
uilabel(fig, 'Text', 'Figure Name:', 'Position', [50 550 100 30]);
figNameField = uitextarea(fig, 'Position', [150 550 200 30]);
figNameField = uieditfield(fig, 'text', 'Position', [150 550 200 30], ...
'ValueChangedFcn', @(src, event) emptyNameField(src,event));
%%% Dropdown menu for departement name
uilabel(fig, 'Text', 'IPT Name:', 'Position', [370 550 100 30]);
prefixIPTName = {'[]', '[MSA]', '[AER]', '[PRF]', '[RCS]', '[GNC]', '[ARP]', ...
'[SWD]', '[ELC]', '[STR]', '[RPS]', '[LPS]', '[AFD]', '[MMC]', '[ROV]'};
prefixIPTNameDropDown = uidropdown(fig, 'Items', prefixIPTName, ...
'Value', '[]', ...
'Position', [455 550 80 30], ...
'Tooltip', 'Choose your IPT');
% WHratio Input
uilabel(fig, 'Text', 'Width/Height Ratio:', 'Position', [50 170 150 30]);
WHratioField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [180 170 50 30]);
WHratioField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [160 170 50 30]);
% Forced Markers Input
uilabel(fig, 'Text', 'Forced Markers:', 'Position', [270 170 150 30]);
forcedMarkersField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [390 170 50 30]);
uilabel(fig, 'Text', 'Forced Markers:', 'Position', [250 170 150 30]);
forcedMarkersField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [350 170 50 30]);
% Percentage of Text Width
uilabel(fig, 'Text', 'Percentage of Text Width:', 'Position', [500 170 200 30]);
percTextField = uieditfield(fig, 'numeric', 'Position', [670 170 50 30]);
uilabel(fig, 'Text', 'Percentage of Text Width:', 'Position', [450 170 200 30]);
percTextField = uieditfield(fig, 'numeric', 'Value', 0.75, 'Position', [600 170 50 30], ...
'ValueChangedFcn', @(src, event) limitsCheck(src, event));
%% Checkboxes
%%% Create a panel to group flags
flagsPanel = uipanel(fig, ...
'Title', 'Flags', ...
'FontWeight', 'bold', ...
'FontSize', 12, ...
'Position', [40 400 720 70]); % Position: [x, y, width, height]
......@@ -63,6 +88,7 @@ satelliteMapColorsBox = uicheckbox(flagsPanel, 'Text', 'Satellite Map Colors', '
%%% Create a panel to group export settings
exportPanel = uipanel(fig, ...
'Title', 'Export setting', ...
'FontWeight', 'bold', ...
'FontSize', 12, ...
'Position', [40 310 720 70]); % Position: [x, y, width, height]
......@@ -78,6 +104,7 @@ overwriteFigureBox = uicheckbox(exportPanel, 'Text', 'Overwrite', 'Value', false
%%% Create a panel to group dropdown menus
legendPanel = uipanel(fig, ...
'Title', 'Legend', ...
'FontWeight', 'bold', ...
'FontSize', 12, ...
'Position', [40 220 720 70]); % Position: [x, y, width, height]
......@@ -99,8 +126,6 @@ legendOrientationDropDown = uidropdown(legendPanel, 'Items', legendOrientations,
'Position', [330 10 150 22]);
%% Preview content
uiPanel = uipanel(fig, 'Title', 'Export preview', 'Position', [810, 100, 550, 500]);
% Find all open figures (excluding this GUI)
figHandles = findFigures(fig);
figNames = getFigureNames(figHandles);
......@@ -110,6 +135,7 @@ uilabel(fig, 'Text', 'Select Figure:', 'Position', [50, 500, 100, 30]);
figSelectionDropDown = uidropdown(fig, ...
'Items', figNames, ...
'Position', [150, 500, 200, 30], ...
'Tooltip', 'Select the figure you want to export', ...
'ValueChangedFcn', @(src, event) updatePreview());
% Automatically update preview if only one figure exists
......@@ -121,20 +147,131 @@ end
% Button to update the dropdown menu
updateButton = uibutton(fig, 'Text', 'Update Figures', ...
'Position', [370, 500, 120, 30], ...
'BackgroundColor', '#9fc9eb', ...
'Tooltip', 'Update list of available figures', ...
'ButtonPushedFcn', @(src, event) updateDropdown());
% Submit Button
submitButton = uibutton(fig, 'Text', 'Export Figure', ...
'Position', [350 100 100 30], ...
'ButtonPushedFcn', @(src, event) exportFigureCallback());
% preview image to export button
previewButton = uibutton(fig, 'Text', 'Update preview', ...
'Position', [500, 500, 120, 30], ...
'Position', [640, 500, 120, 30], ...
'BackgroundColor', '#fdf3ae', ...
'Tooltip', 'Click to see a preview of your plot', ...
'ButtonPushedFcn', @(src, event) previewFigureCallback());
% return to default button only for last 3 fields
defaultButton = uibutton(fig, 'Text', 'Reset', ...
'Position', [710, 170, 50, 30], ...
'BackgroundColor', [.7 .7 .7], ...
'Tooltip', 'Return to default values', ...
'ButtonPushedFcn', @(src, event) resetToDefaultMini());
% automatically generate a name
autoNameButton = uibutton(fig, 'Text', 'Auto name', ...
'Position', [640, 550, 120, 30], ...
'BackgroundColor', [.7 .7 .7], ...
'Tooltip', 'Generate a automatic name: "plot"', ...
'ButtonPushedFcn', @(src, event) autoNameGenerator());
% -------------------- BOTTOM PART ---------------------
% Export Button
exportButton = uibutton(fig, 'Text', 'Export Figure', ...
'Position', [200 100 100 30], ...
'BackgroundColor', '#cbffbe', ...
'Tooltip', 'Click to export', ...
'ButtonPushedFcn', @(src, event) exportFigureCallback());
% Save settings Button
settingsSaveButton = uibutton(fig, 'Text', 'Save settings', ...
'Position', [350 100 100 30], ...
'BackgroundColor', '#cbffbe', ...
'Tooltip', 'Save your configuration', ...
'ButtonPushedFcn', @(src, event) saveSettings());
% Reset to default settings to start over
allDefaultButton = uibutton(fig, 'Text', 'Reset All', ...
'Position', [500 100 100 30], ...
'BackgroundColor', '#e17b4b', ...
'Tooltip', 'Reset all settings to default', ...
'ButtonPushedFcn', @(src, event) resetToDefaultAll());
%% Functions
% Function to update dropdown menu with new figures
function saveSettings()
% This function save all the settings in a json file
settings.addMarkers = addMarkersBox.Value;
settings.changeColors = changeColorsBox.Value;
settings.changeLineStyle = changeLineStyleBox.Value;
settings.gridOption = gridBox.Value;
settings.satelliteMapColors = satelliteMapColorsBox.Value;
settings.legendLocation = legendLocationDropDown.Value;
settings.legendOrientation = legendOrientationDropDown.Value;
settings.exportPDF = exportPDFBox.Value;
settings.exportFIG = exportFIGBox.Value;
settings.overwriteFigure = overwriteFigureBox.Value;
settings.percTextwidth = percTextField.Value;
settings.forcedMarkers = forcedMarkersField.Value;
settings.WHratio = WHratioField.Value;
encoded = jsonencode(settings,PrettyPrint=true);
nameFile = ['settings_' strrep(figSelectionDropDown.Value,' ','-') '.json'];
fid = fopen(nameFile,'w');
fprintf(fid,'%s',encoded);
fclose(fid);
end
function autoNameGenerator()
figNameField.Value = "plot";
end
function emptyNameField(src)
if isempty(src.Value)
src.Tooltip = 'Insert a valid name';
src.BackgroundColor = [1, 0.8, 0.8]; % Light red
else
src.Tooltip = '';
src.BackgroundColor = [1, 1, 1]; % White
end
end
function limitsCheck(src, event)
if event.Value > 1
src.Tooltip = 'Only values less than 1 are accepted';
src.BackgroundColor = [1, 0.8, 0.8]; % Light red
else
src.Tooltip = '';
src.BackgroundColor = [1, 1, 1]; % White
end
end
function resetToDefaultMini()
forcedMarkersField.Value = 0;
WHratioField.Value = 0;
percTextField.Value = 0.75;
end
function resetToDefaultAll()
forcedMarkersField.Value = 0;
WHratioField.Value = 0;
percTextField.Value = 0.75;
% Flags default settings
addMarkersBox.Value = true;
changeColorsBox.Value = true;
changeLineStyleBox.Value = false;
gridBox.Value = true;
satelliteMapColorsBox.Value = false;
% Legend default settings
legendLocationDropDown.Value = 'southoutside';
legendOrientationDropDown.Value = 'horizontal';
% Export default settings
overwriteFigureBox.Value = false;
exportPDFBox.Value = true;
exportFIGBox.Value= false;
end
function updateDropdown()
figHandles = findFigures(fig);
figNames = getFigureNames(figHandles);
......@@ -149,8 +286,8 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ...
% Function to update preview
function updatePreview()
% Delete any existing axes
delete(findall(uiPanel, 'Type', 'figure'));
checkboxes = findall(flagsPanel.Children, 'Type', 'uicheckbox');
set(checkboxes, 'Enable', 'on');
figHandles = findFigures(fig);
......@@ -158,6 +295,21 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ...
selectedIdx = figSelectionDropDown.Value;
selectedFig = [];
for i = 1:length(figHandles)
figSeries = figHandles(i);
% Set the default figure position
pos = get(figSeries, 'Position'); % gives x left, y bottom, width, height
width = pos(3);
height = pos(4);
leftOffsetNew = screenWidth/5;
topOffsetNew = screenHeight/3;
positionCurrentFig = [screenWidth-width-leftOffsetNew, ...
screenHeight-height-topOffsetNew, width, height];
set(figSeries, 'Position', positionCurrentFig);
end
% Find the selected figure
for i = 1:length(figHandles)
if strcmp(figSelectionDropDown.Items{i}, selectedIdx)
......@@ -165,25 +317,28 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ...
break;
end
end
% Move from background to foreground current figure
uistack(selectedFig,'top')
updateDropdown();
if isempty(selectedFig) && isscalar(figHandles), selectedFig = figHandles(1); end
if isempty(selectedFig) || ~isvalid(selectedFig), return; end
% Retrieve axes from selected figure
obj = findall(selectedFig, 'Type', 'figure');
% Delete any existing axes
delete(findall(uiPanel, 'Type', 'axes'));
% Copy the axes into the UI Panel
% Copy the axes informations
check = size(obj.Children);
if check(1) == 1
newAx = copyobj(obj.Children, uiPanel);
if satelliteMapColorsBox.Value, satelliteMapColorsBox.Value = false; end
newAx = obj.Children;
hold(newAx, 'on');
end
if check(1) == 2 % geoplots or 3d plots or tabfigures
if isa(obj.Children(1), 'matlab.ui.container.TabGroup')
if satelliteMapColorsBox.Value, satelliteMapColorsBox.Value = false; end
numTabs = numel(obj.Children(1).Children); % Get number of tabs
originalFigNum = obj.Number; % Get the original figure number
......@@ -196,60 +351,66 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ...
set(newAx, 'Position', get(gca, 'Position'));
hold(newAx, 'on');
end
delete(obj);
else
newAx = copyobj(obj.Children(2), uiPanel);
if strcmp(obj.Children(2).Type, 'geoaxes')
satelliteMapColorsBox.Value = true;
else
satelliteMapColorsBox.Value = false;
end
newAx = obj.Children(2);
hold(newAx, 'on');
end
end
if check(1) > 2
if isa(obj.Children(1), 'matlab.graphics.illustration.Legend')
newAx = copyobj(obj.Children(2:end), uiPanel);
if satelliteMapColorsBox.Value, satelliteMapColorsBox.Value = false; end
newAx = obj.Children(2:end);
hold(newAx(1:check(1)-1), 'on');
else
newAx = copyobj(obj.Children, uiPanel);
if satelliteMapColorsBox.Value, satelliteMapColorsBox.Value = false; end
newAx = obj.Children;
hold(newAx, 'on');
end
end
%set(newAx, 'Position', [0.1, 0.1, 0.8, 0.8]); % Adjust position in panel
%hold(newAx, 'on');
% Apply user settings
linesInPlot = findall(newAx, 'Type', 'line');
if addMarkersBox.Value
% if addMarkersBox.Value
% for line = linesInPlot'
% set(line, 'Marker', 'o', 'MarkerSize', 4);
% end
% end
if changeColorsBox.Value, set(newAx, 'ColorOrder', lines(7)); end
if changeLineStyleBox.Value, set(linesInPlot, 'LineStyle', '--'); end
if satelliteMapColorsBox.Value, colormap(newAx, 'parula'); end
if WHratioField.Value > 0, daspect(newAx, [1 WHratioField.Value 1]); end
if changeLineStyleBox.Value
for line = linesInPlot'
set(line, 'Marker', 'o', 'MarkerSize', 4);
set(line, 'LineStyle', '--');
end
end
if changeColorsBox.Value
set(newAx, 'ColorOrder', lines(7));
end
if gridBox.Value
grid(newAx, 'on');
else
grid(newAx, 'off');
end
if changeLineStyleBox.Value
for line = linesInPlot'
set(line, 'LineStyle', '--');
end
end
if satelliteMapColorsBox.Value
colormap(newAx, 'parula');
end
if WHratioField.Value > 0
daspect(newAx, [1 WHratioField.Value 1]);
end
% Ensure preview updates on checkbox change
addMarkersBox.ValueChangedFcn = @(src, event) updatePreview();
changeColorsBox.ValueChangedFcn = @(src, event) updatePreview();
gridBox.ValueChangedFcn = @(src, event) updatePreview();
WHratioField.ValueChangedFcn = @(src, event) updatePreview();
changeLineStyleBox.ValueChangedFcn = @(src, event) updatePreview();
satelliteMapColorsBox.ValueChangedFcn = @(src, event) updatePreview();
legendLocationDropDown.ValueChangedFcn = @(src, event) updatePreview();
legendOrientationDropDown.ValueChangedFcn = @(src, event) updatePreview();
% addMarkersBox.ValueChangedFcn = @(src, event) updatePreview();
% changeColorsBox.ValueChangedFcn = @(src, event) updatePreview();
% gridBox.ValueChangedFcn = @(src, event) updatePreview();
% WHratioField.ValueChangedFcn = @(src, event) updatePreview();
% changeLineStyleBox.ValueChangedFcn = @(src, event) updatePreview();
% satelliteMapColorsBox.ValueChangedFcn = @(src, event) updatePreview();
% legendLocationDropDown.ValueChangedFcn = @(src, event) updatePreview();
% legendOrientationDropDown.ValueChangedFcn = @(src, event) updatePreview();
hold(newAx, 'off');
end
......@@ -257,7 +418,7 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ...
% Callback Function for Button
function exportFigureCallback()
% Get values from the GUI components
figName = figNameField.Value;
figName = [prefixIPTNameDropDown.Value figNameField.Value];
percTextwidth = percTextField.Value;
addMarkers = addMarkersBox.Value;
forcedMarkers = forcedMarkersField.Value;
......@@ -336,6 +497,9 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ...
'satelliteMapColors', satelliteMapColors, ...
'WHratio', WHratio, ...
'overwriteFigure', overwriteFigure);
checkboxes = findall(flagsPanel.Children, 'Type', 'uicheckbox');
set(checkboxes, 'Enable', 'off');
end
end
......