[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New Plotting Functions: findall.m and allchild.m
From: |
Bill Denney |
Subject: |
Re: New Plotting Functions: findall.m and allchild.m |
Date: |
Tue, 04 Mar 2008 23:16:02 -0500 |
User-agent: |
Thunderbird 2.0.0.12 (Windows/20080213) |
John W. Eaton wrote:
| Also, I was trying to write hgsave and hgload, but I could not find a
| way to create a handle without using the plotting functions. Is there a
| way to generate handle objects without going through the plotting functions?
Not that I know of, so at least part of hgload may need to be in C++.
If you could create graphics handles without generating a graph, how
would you want to do that? What data do you have available when you
want to create the graphics object?
Attached is what I wrote for hgsave. I was thinking that hgload would
essentially do what hgsave does in reverse, but assigning new handle
numbers to everything. It's a little more complex because there are
child handles in places other than the children field (i.e. the title,
xlabel, ylabel, and zlabel), but that was the general idea I had for it.
The alternative to the approach that I have there is to make
hgsave/hgload generate what is essentially an .m file that would execute
to generate the figure. That struck me as likely less efficient, so I
started with this method.
Have a good day,
Bill
## Copyright (C) 2008 Bill Denney
##
## 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} {} hgsave ()
## Save a graphics object.
## @seealso{hgload}
## @end deftypefn
## Author: Bill Denney <address@hidden>
function hgsave (varargin)
if ((nargin < 1) || (nargin > 3))
print_usage ();
endif
h = [];
## process the input arguments
idx = 1;
if isfigure (varargin{idx})
h = varargin{idx};
idx += 1;
endif
if (numel (varargin) >= idx)
if (ischar (varargin{idx})) && (size (varargin{idx}, 1) == 1)
filename = varargin{idx};
idx += 1;
endif
endif
if length (varargin) >= idx
## FIXME
warning (["Additional arguments beyond handle and filename are not "
"yet supported."])
endif
if isempty (h)
h = gca ();
endif
if isempty (filename)
error ("Filename not given");
endif
handlist = h;
handdata{1} = get (h);
c = allchild (h);
while ~ isempty (c)
if ~ ismember (c(1), handlist)
## only save objects that we have not yet seen.
handlist(end+1) = c(1);
handdata{end+1} = get (c(1));
ctmp = allchild (c(1));
if ~ isempty (ctmp)
c(end+1:numel(ctmp)) = ctmp;
endif
endif
c(1) = [];
endwhile
save (filename, "handlist", "handdata");
endfunction