changeset 18999:137d01e7c2d4

New scripts pan.m and rotate3d.m, update __add_default_menu__.m * pan.m: New script to control panning mode for GUI * rotate3d.m: New script to control panning mode for GUI * __add_default_menu__.m: Update uimenus and callbacks. The menubar items now sets properties on all axes except legends. It's now possible to set, for example, the grid for all plots in a subplot. * findall.m: Update test to reflect change of __add_default_menu__.m * __unimplemented__.m: remove added pan and rotate3d scripts
author Andreas Weber <andy.weber.aw@gmail.com>
date Mon, 28 Jul 2014 22:40:12 +0200
parents a0c514c243f6
children b2db129c664d
files scripts/help/__unimplemented__.m scripts/plot/util/findall.m scripts/plot/util/pan.m scripts/plot/util/private/__add_default_menu__.m scripts/plot/util/rotate3d.m
diffstat 5 files changed, 185 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/help/__unimplemented__.m	Mon Jul 28 08:36:39 2014 -0700
+++ b/scripts/help/__unimplemented__.m	Mon Jul 28 22:40:12 2014 +0200
@@ -730,7 +730,6 @@
   "ordqz",
   "ordschur",
   "padecoef",
-  "pan",
   "parseSoapResponse",
   "pathtool",
   "pcode",
@@ -755,7 +754,6 @@
   "readasync",
   "rng",
   "rotate",
-  "rotate3d",
   "scatteredInterpolant",
   "selectmoveresize",
   "sendmail",
--- a/scripts/plot/util/findall.m	Mon Jul 28 08:36:39 2014 -0700
+++ b/scripts/plot/util/findall.m	Mon Jul 28 22:40:12 2014 +0200
@@ -56,7 +56,7 @@
 %! unwind_protect
 %!   h = findall (hf);
 %!   all_handles(1) = {"figure"};
-%!   all_handles(2:15,1) = {"uimenu"};
+%!   all_handles(2:18,1) = {"uimenu"};
 %!   assert (get (h, "type"), all_handles);
 %! unwind_protect_cleanup
 %!   close (hf);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/util/pan.m	Mon Jul 28 22:40:12 2014 +0200
@@ -0,0 +1,77 @@
+## Copyright (C) 2014 Andreas Weber
+##
+## 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  {Command} {} pan
+## @deftypefnx {Command} {} pan on
+## @deftypefnx {Command} {} pan xon
+## @deftypefnx {Command} {} pan yon
+## @deftypefnx {Command} {} pan off
+## @deftypefnx {Function File} {} pan (@var{hax}, @dots{})
+## Control panning mode of interactive graph in GUI.
+##
+## The function state input may be either @qcode{"on"}, @qcode{"xon"},
+## @qcode{"yon"} or @qcode{"off"}.
+##
+## If it is omitted the current state is toggled (@qcode{"xon"} and
+## @qcode{"yon"} are treated as @qcode{"on"}).
+##
+## @qcode{"xon"} limits panning to the x-axis, @qcode{"yon"} to the
+## y-axis.
+##
+## If the first argument @var{hax} is an axes handle, then operate on
+## this axis rather than the current axes returned by @code{gca}.
+##
+## To query the current mode use the @code{get}
+## function.  For example:
+## @example
+## mode = get (gca, "pan");
+## @end example
+## @seealso{rotate3d}
+## @end deftypefn
+
+function pan (varargin)
+
+  if (numel (varargin) > 0 && isaxes (varargin{1}))
+    hax = varargin{1};
+    varargin(1) = [];
+  else
+    hax = gca ();
+  endif
+
+  toolkit = get (ancestor (hax, "figure"), "__graphics_toolkit__");
+  if (! strcmp (toolkit, "fltk"))
+    warning ("pan: Only implemented for graphics_toolkit FLTK");
+  endif
+
+  if (numel (varargin) > 1)
+    print_usage ();
+  elseif (numel (varargin) == 0)
+    # toggle
+    m = get (hax, "pan");
+    if (findstr (m, "on") > 0)
+      set (hax, "pan", "off");
+    else
+      set (hax, "pan", "on");
+    endif
+  elseif (numel (varargin) == 1)
+    set (hax, "pan", varargin{1});
+  endif
+
+endfunction
+
--- a/scripts/plot/util/private/__add_default_menu__.m	Mon Jul 28 08:36:39 2014 -0700
+++ b/scripts/plot/util/private/__add_default_menu__.m	Mon Jul 28 22:40:12 2014 +0200
@@ -41,12 +41,15 @@
 
     __e = uimenu (fig, "label", "&Edit", "handlevisibility", "off",
                        "tag", "__default_menu__");
-      uimenu (__e, "label", "&Grid", "callback", @grid_cb);
-      uimenu (__e, "label", "Auto&scale", "callback", @autoscale_cb);
-      gm = uimenu (__e, "label", "GUI &Mode");
+      uimenu (__e, "label", "Toggle &grid on all axes", "tag", "toggle", "callback", @grid_cb);
+      uimenu (__e, "label", "Show grid on all axes", "tag", "on", "callback", @grid_cb);
+      uimenu (__e, "label", "Hide grid on all axes", "tag", "off", "callback", @grid_cb);
+      uimenu (__e, "label", "Auto&scale all axes", "callback", @autoscale_cb);
+      gm = uimenu (__e, "label", "GUI &Mode (on all axes)");
         uimenu (gm, "label", "Pan x and y", "tag", "pan_on", "callback", @guimode_cb);
         uimenu (gm, "label", "Pan x only", "tag", "pan_xon", "callback", @guimode_cb);
         uimenu (gm, "label", "Pan y only", "tag", "pan_yon", "callback", @guimode_cb);
+        uimenu (gm, "label", "Disable pan and rotate", "tag", "no_pan_rotate", "callback", @guimode_cb);
         uimenu (gm, "label", "Rotate on", "tag", "rotate3d", "callback", @guimode_cb);
         uimenu (gm, "label", "Enable mousezoom", "tag", "zoom_on", "callback", @guimode_cb);
         uimenu (gm, "label", "Disable mousezoom", "tag", "zoom_off", "callback", @guimode_cb);
@@ -84,31 +87,49 @@
   endif
 endfunction
 
+
+function hax = __get_axes__ (h)
+  ## Get parent figure
+  fig = ancestor (h, "figure");
+
+  ## Find all axes which aren't legends
+  hax = findobj ("type", "axes", "-not", "tag", "legend");
+endfunction
+
 function grid_cb (h, e)
-  grid;
+  hax = __get_axes__ (h);
+  id = get (h, "tag");
+  switch (id)
+    case "toggle"
+      arrayfun (@grid, hax);
+    otherwise
+      arrayfun (@(h) grid(h, id), hax);
+  endswitch
 endfunction
 
 function autoscale_cb (h, e)
-  axis ("auto");
+  hax = __get_axes__ (h);
+  arrayfun (@(h) axis (h, "auto"), hax)
 endfunction
 
 function guimode_cb (h, e)
+  hax = __get_axes__ (h);
   id = get (h, "tag");
   switch (id)
     case "pan_on"
-      set (gco, "pan", "on");
+      arrayfun (@(h) pan (h, "on"), hax)
     case "pan_xon"
-      set (gco, "pan", "xon");
+      arrayfun (@(h) pan (h, "xon"), hax)
     case "pan_yon"
-      set (gco, "pan", "yon");
+      arrayfun (@(h) pan (h, "yon"), hax)
     case "rotate3d"
-      set (gco, "rotate3d", "on");
+      arrayfun (@(h) rotate3d (h, "on"), hax)
     case "no_pan_rotate"
-      set (gco, "pan", "off");
-      set (gco, "rotate3d", "off");
+      arrayfun (@(h) pan (h, "off"), hax)
+      arrayfun (@(h) rotate3d (h, "off"), hax)
     case "zoom_on"
-      set (gco, "mouse_wheel_zoom", 0.05);
+      arrayfun (@(h) set (h, "mouse_wheel_zoom", 0.05), hax);
     case "zoom_off"
-      set (gco, "mouse_wheel_zoom", 0.0);
+      arrayfun (@(h) set (h, "mouse_wheel_zoom", 0.0), hax);
   endswitch
 endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/util/rotate3d.m	Mon Jul 28 22:40:12 2014 +0200
@@ -0,0 +1,73 @@
+## Copyright (C) 2014 Andreas Weber
+##
+## 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  {Command} {} rotate3d
+## @deftypefnx {Command} {} rotate3d on
+## @deftypefnx {Command} {} rotate3d off
+## @deftypefnx {Function File} {} rotate3d (@var{hax}, @dots{})
+## Control 3D rotation mode of interactive graph in GUI.
+##
+## The function state input may be either @qcode{"on"} or @qcode{"off"}
+## and can only be set for 3D plots.
+##
+## If the first argument @var{hax} is an axes handle, then operate on
+## this axis rather than the current axes returned by @code{gca}.
+##
+## To query the current mode use the @code{get} function.  For example:
+## @example
+## mode = get (gca, "rotate3d");
+## @end example
+## @seealso{pan}
+## @end deftypefn
+
+function rotate3d (varargin)
+
+  if (numel (varargin) > 0 && isaxes (varargin{1}))
+    hax = varargin{1};
+    varargin(1) = [];
+  else
+    hax = gca ();
+  endif
+
+  toolkit = get (ancestor (hax, "figure"), "__graphics_toolkit__");
+  if (! strcmp (toolkit, "fltk"))
+    warning ("rotate3d: Only implemented for graphics_toolkit FLTK");
+  endif
+
+  ndims = __calc_dimensions__ (hax);
+  if (ndims == 2)
+    warning ("rotate3d: Only available for 3D plots");
+  else
+    if (numel (varargin) > 1)
+      print_usage ();
+    elseif (numel (varargin) == 0)
+      # toggle
+      m = get (hax, "pan");
+      if (strcmp (get (hax, "rotate3d"), "on"))
+        set (hax, "rotate3d", "off");
+      else
+        set (hax, "rotate3d", "on");
+      endif
+    elseif (numel (varargin) == 1)
+      set (hax, "rotate3d", varargin{1});
+    endif
+  endif
+
+endfunction
+