comparison src/graphics.cc @ 13210:d0f9d7353ee5

return get(h) as a struct array when h is a vector of handles * graphics.cc (get_graphics_object_type): New function. (Fget): Use it. Return struct array instead of cell array of scalar structures when argument is a vector of graphics handles.
author John W. Eaton <jwe@octave.org>
date Sat, 24 Sep 2011 17:27:53 -0400
parents e81ddf9cacd5
children 78744376463a
comparison
equal deleted inserted replaced
13209:9eff72139c05 13210:d0f9d7353ee5
43 #include "display.h" 43 #include "display.h"
44 #include "error.h" 44 #include "error.h"
45 #include "graphics.h" 45 #include "graphics.h"
46 #include "input.h" 46 #include "input.h"
47 #include "ov.h" 47 #include "ov.h"
48 #include "oct-locbuf.h"
48 #include "oct-obj.h" 49 #include "oct-obj.h"
49 #include "oct-map.h" 50 #include "oct-map.h"
50 #include "ov-fcn-handle.h" 51 #include "ov-fcn-handle.h"
51 #include "parse.h" 52 #include "parse.h"
52 #include "toplev.h" 53 #include "toplev.h"
7119 print_usage (); 7120 print_usage ();
7120 7121
7121 return retval; 7122 return retval;
7122 } 7123 }
7123 7124
7125 static std::string
7126 get_graphics_object_type (const double val)
7127 {
7128 std::string retval;
7129
7130 graphics_object obj = gh_manager::get_object (val);
7131
7132 if (obj)
7133 retval = obj.type ();
7134 else
7135 error ("get: invalid handle (= %g)", val);
7136
7137 return retval;
7138 }
7139
7124 DEFUN (get, args, , 7140 DEFUN (get, args, ,
7125 "-*- texinfo -*-\n\ 7141 "-*- texinfo -*-\n\
7126 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\ 7142 @deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\
7127 Return the named property @var{p} from the graphics handle @var{h}.\n\ 7143 Return the named property @var{p} from the graphics handle @var{h}.\n\
7128 If @var{p} is omitted, return the complete property list for @var{h}.\n\ 7144 If @var{p} is omitted, return the complete property list for @var{h}.\n\
7152 { 7168 {
7153 octave_idx_type len = hcv.length (); 7169 octave_idx_type len = hcv.length ();
7154 7170
7155 vals.resize (dim_vector (len, 1)); 7171 vals.resize (dim_vector (len, 1));
7156 7172
7157 for (octave_idx_type n = 0; n < len; n++) 7173 if (nargin == 1 && len > 1)
7158 { 7174 {
7159 graphics_object obj = gh_manager::get_object (hcv(n)); 7175 std::string t0 = get_graphics_object_type (hcv(0));
7160 7176
7161 if (obj) 7177 if (! error_state)
7162 { 7178 {
7163 if (nargin == 1) 7179 for (octave_idx_type n = 1; n < len; n++)
7164 vals(n) = obj.get ();
7165 else
7166 { 7180 {
7167 caseless_str property = args(1).string_value (); 7181 std::string t = get_graphics_object_type (hcv(n));
7168 7182
7169 if (! error_state) 7183 if (error_state)
7170 vals(n) = obj.get (property); 7184 break;
7171 else 7185
7186 if (t != t0)
7172 { 7187 {
7173 error ("get: expecting property name as second argument"); 7188 error ("get: vector of handles must all have same type");
7174 break; 7189 break;
7175 } 7190 }
7176 } 7191 }
7192
7177 } 7193 }
7178 else 7194 }
7195
7196 if (! error_state)
7197 {
7198 for (octave_idx_type n = 0; n < len; n++)
7179 { 7199 {
7180 error ("get: invalid handle (= %g)", hcv(n)); 7200 graphics_object obj = gh_manager::get_object (hcv(n));
7181 break; 7201
7202 if (obj)
7203 {
7204 if (nargin == 1)
7205 vals(n) = obj.get ();
7206 else
7207 {
7208 caseless_str property = args(1).string_value ();
7209
7210 if (! error_state)
7211 vals(n) = obj.get (property);
7212 else
7213 {
7214 error ("get: expecting property name as second argument");
7215 break;
7216 }
7217 }
7218 }
7219 else
7220 {
7221 error ("get: invalid handle (= %g)", hcv(n));
7222 break;
7223 }
7182 } 7224 }
7183 } 7225 }
7184 } 7226 }
7185 else 7227 else
7186 error ("get: expecting graphics handle as first argument"); 7228 error ("get: expecting graphics handle as first argument");
7194 7236
7195 if (len == 0) 7237 if (len == 0)
7196 retval = Matrix (); 7238 retval = Matrix ();
7197 else if (len == 1) 7239 else if (len == 1)
7198 retval = vals(0); 7240 retval = vals(0);
7241 else if (len > 1 && nargin == 1)
7242 {
7243 OCTAVE_LOCAL_BUFFER (octave_scalar_map, tmp, len);
7244
7245 for (octave_idx_type n = 0; n < len; n++)
7246 tmp[n] = vals(n).scalar_map_value ();
7247
7248 retval = octave_map::cat (0, len, tmp);
7249 }
7199 else 7250 else
7200 retval = vals; 7251 retval = vals;
7201 } 7252 }
7202 7253
7203 return retval; 7254 return retval;