diff --git a/GUI/mainWindow.m b/GUI/mainWindow.m index 5e626d3ec..bc94a3575 100644 --- a/GUI/mainWindow.m +++ b/GUI/mainWindow.m @@ -155,22 +155,21 @@ function mainWindow(windowTitle, sample_data, states, startState, selectionCallb 'Parent', fig,... 'BorderType', 'none'); +% buttons panel +butPanel = uipanel(... + 'Parent', sidePanel,... + 'BorderType', 'none'); + % state buttons lenStates = length(states); stateButtons = nan(lenStates, 1); for k = 1:lenStates stateButtons(k) = uicontrol(... - 'Parent', sidePanel,... + 'Parent', butPanel,... 'Style', 'pushbutton',... 'String', states{k}); end -% button to save current graph as an image -graphButton = uicontrol(... - 'Parent', sidePanel, ... - 'Style', 'pushbutton',... - 'String', 'Save Graph'); - % variable selection panel - created in createVarPanel varPanel = uipanel(... 'Parent', sidePanel,... @@ -186,8 +185,8 @@ function mainWindow(windowTitle, sample_data, states, startState, selectionCallb set(fig, 'Units', 'normalized'); set(sidePanel, 'Units', 'normalized'); set(mainPanel, 'Units', 'normalized'); +set(butPanel, 'Units', 'normalized'); set(varPanel, 'Units', 'normalized'); -set(graphButton, 'Units', 'normalized'); set(sampleMenu, 'Units', 'normalized'); set(graphMenu, 'Units', 'normalized'); set(extraSampleCb, 'Units', 'normalized'); @@ -216,17 +215,16 @@ function mainWindow(windowTitle, sample_data, states, startState, selectionCallb set(extraSampleMenu, 'Position', posUi2(fig, 100, 100, 6:10, 1:75, 0)); set(extraSampleCb, 'Position', posUi2(fig, 100, 100, 6:10, 76:100, 0)); -% varPanel, graph and stateButtons are positioned relative to sidePanel +% varPanel and butPanel are positioned relative to sidePanel +set(butPanel, 'Position', posUi2(sidePanel, 10, 1, 1:5, 1, 0)); set(varPanel, 'Position', posUi2(sidePanel, 10, 1, 6:10, 1, 0)); +% set state buttons position relative to butPanel n = length(stateButtons); for k = 1:n - set(stateButtons(k), 'Position', posUi2(sidePanel, 2*(n+1)+1, 1, k, 1, 0)); + set(stateButtons(k), 'Position', posUi2(butPanel, n, 1, k, 1, 0)); end -% graph button is tacked on right below state buttons -set(graphButton, 'Position', posUi2(sidePanel, 2*(n+1)+1, 1, n+1, 1, 0)); - % set callbacks - variable panel widget % callbacks are set in createParamPanel set(sampleMenu, 'Callback', @sampleMenuCallback); @@ -234,7 +232,6 @@ function mainWindow(windowTitle, sample_data, states, startState, selectionCallb set(extraSampleCb, 'Callback', @sampleMenuCallback); set(extraSampleMenu, 'Callback', @sampleMenuCallback); set(stateButtons, 'Callback', @stateButtonCallback); -set(graphButton, 'Callback', @graphButtonCallback); set(fig, 'Visible', 'on'); createVarPanel(sample_data{1}, []); @@ -243,19 +240,24 @@ function mainWindow(windowTitle, sample_data, states, startState, selectionCallb tb = findall(fig, 'Type', 'uitoolbar'); buttons = findall(tb); -zoomoutb = findobj(buttons, 'TooltipString', 'Zoom Out'); +savefigb = findobj(buttons, 'TooltipString', 'Save Figure'); zoominb = findobj(buttons, 'TooltipString', 'Zoom In'); +zoomoutb = findobj(buttons, 'TooltipString', 'Zoom Out'); panb = findobj(buttons, 'TooltipString', 'Pan'); datacursorb = findobj(buttons, 'TooltipString', 'Data Cursor'); buttons(buttons == tb) = []; -buttons(buttons == zoomoutb) = []; +buttons(buttons == savefigb) = []; buttons(buttons == zoominb) = []; +buttons(buttons == zoomoutb) = []; buttons(buttons == panb) = []; buttons(buttons == datacursorb) = []; delete(buttons); +% reset save figure callback with the FileSaveAs one instead of FileSave +set(savefigb, 'ClickedCallback', 'filemenufcn(gcbf,''FileSaveAs'')'); + %set zoom/pan post-callback %zoom v6 off; % undocumented Matlab to make sure zoom function prior to R14 is not used. Seems to not be supported from R2015a. hZoom = zoom(fig); @@ -424,17 +426,6 @@ function stateButtonCallback(source, ev) createVarPanel(sam, vars); end - function graphButtonCallback(source, ev) - %GRAPHBUTTONCALLBACK Called when the user pushes the 'Save Graph' button. - % Prompts the user to save the current graph. - - % find all axes objects on the main panel - ax = findobj(mainPanel, 'Type', 'axes'); - - % save the axes - saveGraph(fig, ax); - end - function varPanelCallback(source, ev) %PARAMPANELCALLBACK Called when the variable or dimension selection % changes. Delegates to selectionChange. diff --git a/Util/saveGraph.m b/Util/saveGraph.m deleted file mode 100644 index f97a58391..000000000 --- a/Util/saveGraph.m +++ /dev/null @@ -1,183 +0,0 @@ -function return_types = saveGraph( fig, ax ) -%SAVEGRAPH Saves the given axis to an image file. Prompts the user to select -% the location and file name. -% -% Inputs: -% fig - The main figure handle. -% ax - The axis handle to save. -% -% Author: Paul McCarthy -% Contributor: Guillaume Galibert -% - -% -% Copyright (c) 2016, Australian Ocean Data Network (AODN) and Integrated -% Marine Observing System (IMOS). -% All rights reserved. -% -% Redistribution and use in source and binary forms, with or without -% modification, are permitted provided that the following conditions are met: -% -% * Redistributions of source code must retain the above copyright notice, -% this list of conditions and the following disclaimer. -% * Redistributions in binary form must reproduce the above copyright -% notice, this list of conditions and the following disclaimer in the -% documentation and/or other materials provided with the distribution. -% * Neither the name of the AODN/IMOS nor the names of its contributors -% may be used to endorse or promote products derived from this software -% without specific prior written permission. -% -% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -% POSSIBILITY OF SUCH DAMAGE. -% - -% supported export types and corresponding print function switches -fileTypes = {'*.png'; '*.jpg' ; '*.bmp' ; '*.pdf'}; -printSwitches = {'-dpng'; '-djpeg'; '-dbmp16m'; '-dpdf'}; - - -dateFmt = readProperty('toolbox.timeFormat'); - -try - noPrompt = eval(readProperty('saveGraph.noPrompt')); -catch e - noPrompt = false; -end - -try - exportDir = readProperty('saveGraph.exportDir'); - if ~exist(exportDir, 'dir'), error(''); end -catch e - exportDir = '.'; -end - -try - imgType = ['*.' readProperty('saveGraph.imgType')]; - if ~ismember(imgType, fileTypes), error(''); end - imgType = find(strcmp(imgType, fileTypes)); -catch e - imgType = 1; -end - -fileName = ['graph_' datestr(now, dateFmt) '.' fileTypes{imgType}(3:end)]; - -if ~noPrompt - - while true - - % prompt user to select file type, name, save location - [fileName exportDir imgType] = ... - uiputfile(fileTypes, 'Save Graph', exportDir); - - % user cancelled dialog - if fileName == 0, return; end - - [~, name, ext] = fileparts(fileName); - - % The uiputfile function automatically adds an 'All Files' - % option to the list of file types. What purpose could this possibly - % serve? It's a save dialog. Anyway, if the user - % selects this option, we need to figure out if the user has provided a - % file extension, and if it is a supported type. - if imgType > length(fileTypes) - - % if user hasn't provided an extension, just use the default - if isempty(ext), imgType = 1; - - % if user has provided an unknown type, show an error, reprompt - elseif ~ismember(['*' ext], fileTypes) - - e = errordlg(... - 'Please provide a file type', 'Unknown file type', 'modal'); - uiwait(e); - - continue; - - % otherwise extract the extension - else imgType = find(strcmp(['*' ext], fileTypes)); - end - end - - % if user hasn't provided the correct extension, add it - if isempty(ext), fileName = [name '.' fileTypes{imgType}(3:end)]; - - % if user has provided a different - % extension, append the correct extension - elseif ~strcmp(['*' ext], fileTypes{imgType}) - - fileName = [fileName '.' fileTypes{imgType}(3:end)]; - end - - % update toolbox properties for next time - writeProperty('saveGraph.exportDir', exportDir); - writeProperty('saveGraph.imgType', fileTypes{imgType}(3:end)); - - break; - end -end - -progress = waitbar(0, 'Saving graph', ... - 'Name', 'Saving',... - 'DefaultTextInterpreter','none'); - -% Matlab can't save individual axes - it is only able to save complete -% figures. What we are doing, then, is copying the provided axis over to a -% new, invisible figure, and saving that figure. -saveFig = figure('Visible', 'off'); - -% ensure the printed version is the same whatever the screen used. -set(saveFig, 'PaperPositionMode', 'manual'); -set(saveFig, 'PaperType', 'A4', 'PaperOrientation', 'landscape', 'PaperUnits', 'normalized', 'PaperPosition', [0, 0, 1, 1]); - -% preserve the color scheme -set(saveFig, 'InvertHardcopy', 'off'); - -new_ax = copyobj(ax, saveFig); - -% Note that figure properties like the colormap and axes properties are not -% copied automatically by copyobj. -col = get(fig, 'Colormap'); -set(saveFig, 'Colormap', col); - -% the default renderer under windows is opengl; for some reason, -% printing pcolor plots fails when using opengl as the renderer -set(saveFig, 'Renderer', 'zbuffer'); - -waitbar(1, progress); -msg = ''; -icon = ''; - -try - print(saveFig, printSwitches{imgType}, fullfile(exportDir, fileName)); - - % trick to save the image in landscape rather than portrait file - image = imread(fullfile(exportDir, fileName)); - r = image(:,:,1); - g = image(:,:,2); - b = image(:,:,3); - r = rot90(r, 3); - g = rot90(g, 3); - b = rot90(b, 3); - image = cat(3, r, g, b); - imwrite(image, fullfile(exportDir, fileName)); - - msg = [fileName ' saved successfully']; - icon = 'none'; - -catch e - msg = ['Could not save ' fileName ' (' e.message ')']; - icon = 'error'; -end - -delete(saveFig); -close(progress); -uiwait(msgbox(msg, 'Save graph', icon, 'non-modal'));