]> Creatis software - CreaPhase.git/blob - octave_packages/geometry-1.5.0/io/@svg/subsref.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / geometry-1.5.0 / io / @svg / subsref.m
1 ## Copyright (C) 2011 CarnĂ« Draug <carandraug+dev@gmail.com>
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 ## Improvement based on John W. Eaton's idea.
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {} function_name ()
20 ## @end deftypefn
21
22 function varargout = subsref (obj, idx)
23
24   persistent __method__ method4field typeNotImplemented
25   if isempty(__method__)
26
27     __method__ = struct();
28
29     __method__.plot = @(o,varargin) plot (o, varargin{:});
30     __method__.getpath = @(o,varargin) getpath (o, varargin{:});
31     __method__.pathid = @(o,varargin) pathid(o,varargin{:});
32     __method__.path2polygon = @(o,varargin) path2polygon (o, varargin{:});
33     __method__.normalize = @(o,varargin) normalize (o, varargin{:});
34     __method__.height = @(o,varargin) height(o, varargin{:});
35     __method__.width = @(o,varargin) width(o,varargin{:});
36
37     # Error strings
38     method4field = "Class %s has no field %s. Use %s() for the method.";
39     typeNotImplemented = "%s no implemented for class %s.";
40
41   end
42
43   if ( !strcmp (class (obj), 'svg') )
44     error ("Object must be of the svg class but '%s' was used", class (obj) );
45   elseif ( idx(1).type != '.' )
46     error ("Invalid index for class %s", class (obj) );
47   endif
48
49   method = idx(1).subs;
50   if ~isfield(__method__, method)
51     error('Unknown method %s.',method);
52   else
53     fhandle = __method__.(method);
54   end
55
56   if strcmp(method,'normalize')
57     warning("svg:Devel",["Not returning second output argument of %s" ...
58                          " use method(obj) API to get it"],method);
59   end
60
61   if numel (idx) == 1 % can't access properties, only methods
62
63     error (method4field, class (obj), method, method);
64
65   end
66
67   if strcmp (idx(2).type, '()')
68
69     args = idx(2).subs;
70     if isempty(args)
71      out = fhandle (obj);
72     else
73       out = fhandle (obj, args{:});
74     end
75
76     varargout{1} = out;
77
78   else
79
80     error (typeNotImplemented,[method idx(2).type], class (obj));
81
82   end
83
84 endfunction