xxsimSavePlotAsBitmap

PURPOSE ^

xxsimSavePlotAsBitmap - Save a plot or plot window as bitmap. Supported formats: png, bmp, jpg, gif.

SYNOPSIS ^

function result = xxsimSavePlotAsBitmap(fileName, window, varargin)

DESCRIPTION ^

 xxsimSavePlotAsBitmap - Save a plot or plot window as bitmap. Supported formats: png, bmp, jpg, gif.

 Syntax: 
   result = xxsimSavePlotAsBitmap(fileName, window, plot, width, height, dpi)

 Inputs:
   fileName   = Path to where the bitmap should be stored. Supported file extensions: .png, .bmp, .jpg, .gif.
   window     = The name or ID of the plot window to select. negative => make plots of all plot window separately.
   plot       = (Optional) The plot (either via name or ID) to save. negative => plot all plots in window (default).
   width      = (Optional) The preferred width of the plot in pixels. 0 or negative => use same size as the plot (default).
   height     = (Optional) The preferred height of the plot in pixels. 0 or negative => use same size as the plot (default).
   dpi        = (Optional) The dpi the bitmap should be stored in. 0 or negative => use the resolution of the screen (default).

 Outputs:
   result  = returns true when the plot was saved successfully.

 Examples:
    result = xxsimSavePlotAsBitmap('Demo.png','Plots');
        Save the plot window called "Plots" as a PNG plot in the current directory with name Demo.png.

    result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage');
        Save the plot "Voltage" in window "Plots" as a PNG plot in the current directory with name Demo.png.

    result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage',1200,900,300);
        Save the plot "Voltage" in window "Plots" as a PNG plot with width of 1200 pixels, height of 900 pixels, and dpi of 300 in the current directory with name Demo.png.

    result = xxsimSavePlotAsBitmap('Demo.png',-1);
        Save all plot windows in the active model as PNG plots with names Demoxx.png, in which xx indicates the plot window number in the tree in the simulator.

 Author: Controllab Products B.V.
 email: info@controllab.nl
 Website: http://www.controllab.nl
 November 2015

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function result = xxsimSavePlotAsBitmap(fileName, window, varargin)
0002 % xxsimSavePlotAsBitmap - Save a plot or plot window as bitmap. Supported formats: png, bmp, jpg, gif.
0003 %
0004 % Syntax:
0005 %   result = xxsimSavePlotAsBitmap(fileName, window, plot, width, height, dpi)
0006 %
0007 % Inputs:
0008 %   fileName   = Path to where the bitmap should be stored. Supported file extensions: .png, .bmp, .jpg, .gif.
0009 %   window     = The name or ID of the plot window to select. negative => make plots of all plot window separately.
0010 %   plot       = (Optional) The plot (either via name or ID) to save. negative => plot all plots in window (default).
0011 %   width      = (Optional) The preferred width of the plot in pixels. 0 or negative => use same size as the plot (default).
0012 %   height     = (Optional) The preferred height of the plot in pixels. 0 or negative => use same size as the plot (default).
0013 %   dpi        = (Optional) The dpi the bitmap should be stored in. 0 or negative => use the resolution of the screen (default).
0014 %
0015 % Outputs:
0016 %   result  = returns true when the plot was saved successfully.
0017 %
0018 % Examples:
0019 %    result = xxsimSavePlotAsBitmap('Demo.png','Plots');
0020 %        Save the plot window called "Plots" as a PNG plot in the current directory with name Demo.png.
0021 %
0022 %    result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage');
0023 %        Save the plot "Voltage" in window "Plots" as a PNG plot in the current directory with name Demo.png.
0024 %
0025 %    result = xxsimSavePlotAsBitmap('Demo.png','Plots','Voltage',1200,900,300);
0026 %        Save the plot "Voltage" in window "Plots" as a PNG plot with width of 1200 pixels, height of 900 pixels, and dpi of 300 in the current directory with name Demo.png.
0027 %
0028 %    result = xxsimSavePlotAsBitmap('Demo.png',-1);
0029 %        Save all plot windows in the active model as PNG plots with names Demoxx.png, in which xx indicates the plot window number in the tree in the simulator.
0030 %
0031 % Author: Controllab Products B.V.
0032 % email: info@controllab.nl
0033 % Website: http://www.controllab.nl
0034 % November 2015
0035 
0036 %------------- BEGIN CODE --------------
0037     global xxsim;
0038 
0039     windowID = -1;
0040     plotID = -1;
0041     height = -1;
0042     width = -1;
0043     dpi = -1;
0044     
0045     % There cannot be more than 4 variable input arguments.
0046     if length(varargin)> 4
0047         error('Too many input arguments.');
0048     end
0049 
0050     % At least two input arguments have to be specified.
0051     if nargin < 2
0052         error('Too little input arguments.');
0053     end
0054 
0055     % fileName: first argument should be a string
0056     if ~ischar(fileName)
0057         error('fileName should be a string');
0058     end
0059 
0060     % translate the filename into something that 20-sim can understand
0061     % check if the user provided a full name
0062     [directory, name, extension] = fileparts(fileName);
0063     if length(directory) ==0
0064         % use the current directory
0065         directory = pwd;
0066     else
0067         % make it an absolute path
0068         currentDir = pwd;
0069         cd(directory);
0070         directory = pwd;
0071         cd(currentDir);
0072     end
0073     useFileName = fullfile(directory, [name, extension]);  
0074 
0075     % window: second argument should be a string or number
0076     if (~ischar(window) && ~isnumeric(window))
0077         error('window should be a string or number');
0078     end
0079 
0080     % Acquire the window ID via the name of the window.
0081     windowID = xxsimGetPlotWindowIDFromName(window);
0082     
0083     if length(varargin) >= 1
0084         % plot: third argument should be a string or number, if defined at all.
0085         if (~ischar(varargin{1}) && ~isnumeric(varargin{1}))
0086             error('plot should be a string or number');
0087         end;
0088 
0089         % Acquire the plot ID via the name of the plot.
0090         plotID = xxsimGetPlotIDFromName(windowID,varargin{1});
0091 
0092     % Warn the user when only a height is specified.
0093     if length(varargin)== 2
0094         warning('No height is specified for the given width, automatic scaling will be used.');
0095     end;
0096 
0097     % Do the check for if a height and width is specified.
0098         if length(varargin) >= 3
0099 
0100         % Check if the height and width are numeric.
0101             if(~isnumeric(varargin{2}))
0102                 error('width should be a number');
0103             end; 
0104             if(~isnumeric(varargin{3}))
0105                 error('height should be a number');
0106             end;
0107 
0108             % Set height
0109             if varargin{2} > 0
0110                 width = varargin{2};
0111             end
0112             % Set width
0113             if varargin{3} > 0
0114                 height = varargin{3};
0115             end
0116             
0117             % Check if there is a dpi input
0118             if(length(varargin) >= 4)
0119                 % Check if the dpi input is a number.
0120                 if(~isnumeric(varargin{4}))
0121                     error('dpi should be a number');
0122                 end;
0123 
0124                 % Set dpi
0125                 if varargin{4} > 0
0126                     dpi = varargin{4}
0127                 end;
0128             end;
0129         end
0130     end
0131     
0132     % invoke 20-sim with the xmlrpc call
0133     inputs = struct('fileName', useFileName, 'windowID', int32(windowID), 'plotID', int32(plotID), 'width', int32(width), 'height', int32(height), 'dpi', int32(dpi));
0134     result = xrlinvoke('xxsim.plot.savePlotAsBitmap', inputs);
0135 end
0136 %------------- END CODE --------------

Generated on Sun 10-Dec-2017 19:24:51