diff --git a/functions/utilities/exportFigureGUI.m b/functions/utilities/exportFigureGUI.m index 473589c06f55d3a0f8afd874e2e5a8217b8b2664..20690890178e0ac50f96fb3f769970f2ac0427f5 100644 --- a/functions/utilities/exportFigureGUI.m +++ b/functions/utilities/exportFigureGUI.m @@ -6,8 +6,8 @@ function exportFigureGUI screenSize = get(0, 'ScreenSize'); % [left, bottom, width, height] % Set the uifigure size -figWidth = 600; -figHeight = 600; +figWidth = 1400; +figHeight = 700; % Calculate position to center the figure figX = (screenSize(3) - figWidth) / 2; @@ -26,45 +26,45 @@ titleLabel.Position = [0, fig.Position(4)-50, fig.Position(3), 30]; %% Input fields % Figure Name -uilabel(fig, 'Text', 'Figure Name:', 'Position', [50 500 100 30]); -figNameField = uitextarea(fig, 'Position', [150 500 200 30]); - -% Percentage of Text Width -uilabel(fig, 'Text', 'Percentage of Text Width:', 'Position', [50 460 200 30]); -percTextField = uieditfield(fig, 'numeric', 'Position', [250 460 100 30]); +uilabel(fig, 'Text', 'Figure Name:', 'Position', [50 550 100 30]); +figNameField = uitextarea(fig, 'Position', [150 550 200 30]); % WHratio Input -uilabel(fig, 'Text', 'Width/Height Ratio:', 'Position', [50 110 150 30]); -WHratioField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [180 110 100 30]); +uilabel(fig, 'Text', 'Width/Height Ratio:', 'Position', [50 170 150 30]); +WHratioField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [180 170 50 30]); % Forced Markers Input -uilabel(fig, 'Text', 'Forced Markers:', 'Position', [320 110 150 30]); -forcedMarkersField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [430 110 100 30]); +uilabel(fig, 'Text', 'Forced Markers:', 'Position', [270 170 150 30]); +forcedMarkersField = uieditfield(fig, 'numeric', 'Value', 0, 'Position', [390 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]); %% Checkboxes %%% Create a panel to group flags flagsPanel = uipanel(fig, ... 'Title', 'Flags', ... 'FontSize', 12, ... - 'Position', [40 340 520 100]); % Position: [x, y, width, height] + 'Position', [40 400 720 70]); % Position: [x, y, width, height] % Checkboxes for optional parameters addMarkersBox = uicheckbox(flagsPanel, 'Text', 'Add Markers', 'Value', true, ... - 'Position', [10 40 150 20]); + 'Position', [10 10 150 20]); changeColorsBox = uicheckbox(flagsPanel, 'Text', 'Change Colors', 'Value', true, ... - 'Position', [120 40 150 20]); + 'Position', [120 10 150 20]); changeLineStyleBox = uicheckbox(flagsPanel, 'Text', 'Change Line Style', 'Value', false, ... - 'Position', [240 40 150 20]); + 'Position', [240 10 150 20]); gridBox = uicheckbox(flagsPanel, 'Text', 'Show Grid', 'Value', true, ... - 'Position', [10 10 150 20]); + 'Position', [370 10 150 20]); satelliteMapColorsBox = uicheckbox(flagsPanel, 'Text', 'Satellite Map Colors', 'Value', false, ... - 'Position', [350 10 150 20]); + 'Position', [480 10 150 20]); %%% Create a panel to group export settings exportPanel = uipanel(fig, ... 'Title', 'Export setting', ... 'FontSize', 12, ... - 'Position', [40 250 520 70]); % Position: [x, y, width, height] + 'Position', [40 310 720 70]); % Position: [x, y, width, height] % Checkboxes for optional parameters exportPDFBox = uicheckbox(exportPanel, 'Text', 'Export PDF', 'Value', true, ... @@ -79,7 +79,7 @@ overwriteFigureBox = uicheckbox(exportPanel, 'Text', 'Overwrite', 'Value', false legendPanel = uipanel(fig, ... 'Title', 'Legend', ... 'FontSize', 12, ... - 'Position', [40 160 520 70]); % Position: [x, y, width, height] + 'Position', [40 220 720 70]); % Position: [x, y, width, height] % Dropdowns for Legend Location and Orientation uilabel(legendPanel, 'Text', 'Location:', 'Position', [10 10 60 20]); @@ -98,6 +98,113 @@ legendOrientationDropDown = uidropdown(legendPanel, 'Items', legendOrientations, 'Value', 'horizontal', ... 'Position', [330 10 150 22]); +%% Preview content +uiPanel = uipanel(fig, 'Title', 'Copied Figure', 'Position', [810, 100, 550, 500]); + +% Find all open figures (excluding this GUI) +figHandles = findFigures(fig); +figNames = getFigureNames(figHandles); + +% Dropdown menu to select figure +uilabel(fig, 'Text', 'Select Figure:', 'Position', [50, 500, 100, 30]); +figSelectionDropDown = uidropdown(fig, ... + 'Items', figNames, ... + 'Position', [150, 500, 200, 30], ... + 'ValueChangedFcn', @(src, event) updatePreview()); + +% Button to update the dropdown menu +updateButton = uibutton(fig, 'Text', 'Update Figures', ... + 'Position', [370, 500, 120, 30], ... + 'ButtonPushedFcn', @(src, event) updateDropdown()); + +% Automatically update preview if only one figure exists +if length(figHandles) == 1 + updatePreview(); +end + +% Function to update dropdown menu with new figures + function updateDropdown() + figHandles = findFigures(fig); + figNames = getFigureNames(figHandles); + + figSelectionDropDown.Items = figNames; + + % Automatically update preview if only one valid figure exists + if length(figHandles) == 1 + updatePreview(); + end + end + +% Function to update preview + function updatePreview() + figHandles = findFigures(fig); + + % Get selected figure from dropdown + selectedIdx = figSelectionDropDown.Value; + selectedFig = []; + + % Find the selected figure + for i = 1:length(figHandles) + if strcmp(figSelectionDropDown.Items{i}, selectedIdx) + selectedFig = figHandles(i); + break; + end + end + + if isempty(selectedFig) && length(figHandles) == 1 + selectedFig = figHandles(1); + end + + if isempty(selectedFig) || ~isvalid(selectedFig) + return; + end + + % Retrieve axes from selected figure + ax = findall(selectedFig, 'Type', 'axes'); + + % Ensure valid axes exist + % if isempty(ax) + % ax = axes(selectedFig); + % plot(ax, rand(1, 10), rand(1, 10), 'o-'); % Sample plot + % end + + % Delete any existing axes in the UI panel + delete(findall(uiPanel, 'Type', 'axes')); + + % Copy the axes into the UI Panel + newAx = copyobj(ax, uiPanel); + set(newAx, 'Position', [0.1, 0.1, 0.8, 0.8]); % Adjust position in panel + + % Apply user settings + % if addMarkersBox.Value + % hold(newAx, 'on'); + % plot(newAx, x, y, 'o', 'MarkerSize', 4); + % hold(newAx, 'off'); + % end + % if changeColorsBox.Value + % newAx.ColorOrder = lines(7); % Change color scheme + % end + % if gridBox.Value + % grid(newAx, 'on'); + % else + % grid(newAx, 'off'); + % end + % + % % Adjust aspect ratio if specified + % if WHratioField.Value > 0 + % daspect(previewAxes, [1 WHratioField.Value 1]); + % end + + 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(); + end + %% Further developments % File Path Input % uilabel(fig, 'Text', 'Figure Save Path:', 'Position', [50 70 150 30]); @@ -106,7 +213,7 @@ legendOrientationDropDown = uidropdown(legendPanel, 'Items', legendOrientations, %% Buttons % Submit Button submitButton = uibutton(fig, 'Text', 'Export Figure', ... - 'Position', [250 20 100 30], ... + 'Position', [350 100 100 30], ... 'ButtonPushedFcn', @(src, event) exportFigureCallback()); % Callback Function for Button @@ -127,17 +234,19 @@ submitButton = uibutton(fig, 'Text', 'Export Figure', ... % figurePath = pathField.Value; WHratio = WHratioField.Value; overwriteFigure = overwriteFigureBox.Value; - + % Check for required inputs if isempty(figName) || isempty(percTextwidth) uialert(fig, 'Please enter both Figure Name and Percentage Text Width.', 'Input Error'); return; end - + % Try to export figure try % Call the exportStandardizedFigure function - figToExp = gcf; + % figToExp = gcf; + selectedIdx = figSelectionDropDown.Value; + figToExp = figHandles(strcmp(figSelectionDropDown.Items, selectedIdx)); exportStandardizedFigure(figToExp, figName, percTextwidth, ... 'addMarkers', addMarkers, ... 'forcedMarkers', forcedMarkers, ... @@ -158,3 +267,16 @@ submitButton = uibutton(fig, 'Text', 'Export Figure', ... end end end + +function figHandles = findFigures(fig) + figHandles = findall(0, 'Type', 'figure'); + figHandles(figHandles == fig) = []; % Exclude GUI figure +end + +function figNames = getFigureNames(figHandles) + if isempty(figHandles) + figNames = {'No figures open'}; + else + figNames = arrayfun(@(f) sprintf('Figure %d', f.Number), figHandles, 'UniformOutput', false); + end +end \ No newline at end of file