changeset 11253:093c9facf0f0

Add saveas function
author Kai Habel <kai.habel@gmx.de>
date Mon, 15 Nov 2010 19:41:14 +0100
parents d048ce3f7cef
children 31f8534eb055
files ChangeLog NEWS scripts/ChangeLog scripts/plot/__print_parse_opts__.m scripts/plot/module.mk scripts/plot/print.m scripts/plot/saveas.m
diffstat 7 files changed, 127 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Nov 14 22:01:45 2010 +0000
+++ b/ChangeLog	Mon Nov 15 19:41:14 2010 +0100
@@ -1,3 +1,7 @@
+2010-11-15  Kai Habel  <kai.habel@gmx.de>
+
+	* NEWS: Add saveas. Fix uimenu.
+
 2010-11-14  Michael Goffioul  <michael.goffioul@gmail.com>
 
 	* mkoctfile.cc.in: replace %OCTAVE_CONF_F77_INTEGER8_FLAG% with
--- a/NEWS	Sun Nov 14 22:01:45 2010 +0000
+++ b/NEWS	Mon Nov 15 19:41:14 2010 +0100
@@ -314,12 +314,12 @@
   ** The following functions are new in Octave 3.4:
 
        accumdim   erfcx        luupdate     ppder      rsf2csf
-       bitpack    fileread     merge        ppint      sizemax
-       bitunpack  fminbnd      nfields      ppjumps    strread
-       blkmm      fskipl       nth_element  pqpnonneg  textread
-       cbrt       ifelse       onCleanup    randi      whitebg
-       chop       ishermitian  pbaspect     repelems
-       daspect    isindex      powerset     reset
+       bitpack    fileread     merge        ppint      saveas
+       bitunpack  fminbnd      nfields      ppjumps    sizemax
+       blkmm      fskipl       nth_element  pqpnonneg  strread
+       cbrt       ifelse       onCleanup    randi      textread
+       chop       ishermitian  pbaspect     repelems   uimenu
+       daspect    isindex      powerset     reset      whitebg
 
   ** Using the image function to view images with external programs such
      as display, xv, and xloadimage is no longer supported.  The
@@ -439,8 +439,8 @@
       allchild            ezmesh      gtext        specular
       available_backends  ezmeshc     intwarning   surfl
       backend             ezplot      ishghandle   trisurf
-      cla                 ezplot3     isocolors    uimenu
-      clabel              ezpolar     isonormals   waitforbuttonpress
+      cla                 ezplot3     isocolors    waitforbuttonpress
+      clabel              ezpolar     isonormals
       comet               ezsurf      isosurface  
       dellistener         findall     linkprop   
       diffuse             gcbf        plotmatrix
--- a/scripts/ChangeLog	Sun Nov 14 22:01:45 2010 +0000
+++ b/scripts/ChangeLog	Mon Nov 15 19:41:14 2010 +0100
@@ -1,3 +1,11 @@
+2010-11-15  Kai Habel  <kai.habel@gmx.de>
+
+	* plot/saveas.m: New file.
+	* plot/module.mk: Add saveas.m
+	* plot/__print_parse_opts__.m: Parse arguments correctly when first
+	argument is a figure handle.
+	* plot/print.m: Add saveas to seealso entry.
+
 2010-11-14  Michael Goffioul  <michael.goffioul@gmail.com>
 
 	* plot/print.m: Use "del" instead of "delete" in DOS shell, and
--- a/scripts/plot/__print_parse_opts__.m	Sun Nov 14 22:01:45 2010 +0000
+++ b/scripts/plot/__print_parse_opts__.m	Mon Nov 15 19:41:14 2010 +0100
@@ -71,6 +71,11 @@
   endif
   arg_st.unlink = {};
   
+  if (isfigure (varargin{1}))
+    arg_st.figure = varargin{1};
+    varargin(1) = [];
+  endif
+
   for i = 1:nargin
     arg = strtrim (varargin{i});
     if (ischar (arg))
--- a/scripts/plot/module.mk	Sun Nov 14 22:01:45 2010 +0000
+++ b/scripts/plot/module.mk	Mon Nov 15 19:41:14 2010 +0100
@@ -138,6 +138,7 @@
   plot/replot.m \
   plot/ribbon.m \
   plot/rose.m \
+  plot/saveas.m \
   plot/scatter.m \
   plot/scatter3.m \
   plot/semilogx.m \
--- a/scripts/plot/print.m	Sun Nov 14 22:01:45 2010 +0000
+++ b/scripts/plot/print.m	Mon Nov 15 19:41:14 2010 +0100
@@ -248,7 +248,7 @@
 ## print -dcdj550
 ## @end example
 ##
-## @seealso{figure, orient}
+## @seealso{figure, orient, saveas}
 ## @end deftypefn
 
 function print (varargin)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/saveas.m	Mon Nov 15 19:41:14 2010 +0100
@@ -0,0 +1,100 @@
+## Copyright (C) 2010 Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn  {Function File} {} saveas (@var{h}, @var{file_name})
+## @deftypefnx  {Function File} {} saveas (@var{h}, @var{file_name}, @var{file_ext})
+## Save the graphic object @var{h} to file @var{file_name} in graphic
+## format @var{file_ext}. 
+## 
+## @var{file_ext} should be one of the following formats:
+##
+## @table @code
+##   @item ps
+##     Postscript
+##   @item eps
+##     Encapsulated Postscript
+##   @item jpg
+##     JPEG Image
+##   @item png
+##     PNG Image
+##   @item emf
+##     Enhanced Meta File
+##   @item pdf
+##     Portable Document Format
+## @end table
+##
+## All device formats specified in @code{print} can also be used. If @var{file_ext}
+## is omitted it is extracted from @var{file_name}. The default value is
+## pdf.
+##
+## @example
+## figure (1);
+## clf ();
+## surf (peaks);
+## saveas(1, "figure1.png");
+## @end example
+##
+## @seealso{print}
+## @end deftypefn
+
+## Author: Kai Habel
+
+function  saveas (h, fname, fext = "pdf")
+
+  if ((nargin != 2) && (nargin != 3))
+    print_usage ();
+  endif
+
+  if (ishandle (h))
+    if (isfigure (h))
+      fig = h;
+    else
+      fig = ancestor (h, "figure")
+    endif
+  else
+    error ("first argument must be a graphics handle");
+  endif
+  
+  if (!ischar(fname))
+    error ("file_name must be a string.");
+  endif
+
+  if (nargin == 2)
+    [~, ~, ext] = fileparts (fname);
+    if (!isempty (ext))
+      fext = ext(2:end);
+    endif
+  endif
+
+  if (nargin == 3)
+    if (!ischar (fname))
+      error ("fext must be a string.");
+    endif
+
+    [~, ~, ext] = fileparts (fname);
+
+    if (isempty (ext))
+      fname = strcat (fname, ".", fext);
+    endif
+  endif
+
+  prt_opt = strcat ("-d", tolower (fext));
+  
+  print (fname, prt_opt)
+endfunction