comparison src/graphics.cc @ 13801:195ff3561152

allow figure handles to be non-integers * graphics.h.in, graphics.cc (gh_manager::get_handle, make_graphics_object, gh_manager::make_graphics_handle, gh_manager::do_make_graphics_handle): New arg to determine whether to generate integer-valued figure handle. Change all callers. * graphics.h.in (gh_manager::handle_list, gh_manager::do_handle_list, gh_manager::figure_handle_list, gh_manager::do_figure_handle_list): New arg to determine whether to show hidden handles. Change all callers. * graphics.cc (F__go_figure__): If specified handle is Inf, use non-integer handle. Call gh_manager::push_figure here. (F__go_handles__): New arg to control display of hidden handles. Pass flag to gh_manager::handle_list. (F__go_figure_handles__): Likewise, pass flag to gh_manager::figure_handle_list.
author John W. Eaton <jwe@octave.org>
date Thu, 03 Nov 2011 05:01:52 -0400
parents 760e4e88dba3
children 4f112bebd474
comparison
equal deleted inserted replaced
13800:5acb5c25e4ae 13801:195ff3561152
2106 2106
2107 return (rand () + 1.0) / maxrand; 2107 return (rand () + 1.0) / maxrand;
2108 } 2108 }
2109 2109
2110 graphics_handle 2110 graphics_handle
2111 gh_manager::get_handle (const std::string& go_name) 2111 gh_manager::get_handle (bool integer_figure_handle)
2112 { 2112 {
2113 graphics_handle retval; 2113 graphics_handle retval;
2114 2114
2115 if (go_name == "figure") 2115 if (integer_figure_handle)
2116 { 2116 {
2117 // Figure handles are positive integers corresponding to the 2117 // Figure handles are positive integers corresponding to the
2118 // figure number. 2118 // figure number.
2119 2119
2120 // We always want the lowest unused figure number. 2120 // We always want the lowest unused figure number.
3847 { 3847 {
3848 graphics_handle val; 3848 graphics_handle val;
3849 3849
3850 if (v.is_string ()) 3850 if (v.is_string ())
3851 { 3851 {
3852 val = gh_manager::make_graphics_handle ("text", __myhandle__, false); 3852 val = gh_manager::make_graphics_handle ("text", __myhandle__,
3853 false, false);
3853 3854
3854 xset (val, "string", v); 3855 xset (val, "string", v);
3855 } 3856 }
3856 else 3857 else
3857 { 3858 {
4047 activepositionproperty = "outerposition"; 4048 activepositionproperty = "outerposition";
4048 } 4049 }
4049 4050
4050 delete_children (true); 4051 delete_children (true);
4051 4052
4052 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__, false); 4053 xlabel = gh_manager::make_graphics_handle ("text", __myhandle__,
4053 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__, false); 4054 false, false);
4054 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__, false); 4055
4055 title = gh_manager::make_graphics_handle ("text", __myhandle__, false); 4056 ylabel = gh_manager::make_graphics_handle ("text", __myhandle__,
4057 false, false);
4058
4059 zlabel = gh_manager::make_graphics_handle ("text", __myhandle__,
4060 false, false);
4061
4062 title = gh_manager::make_graphics_handle ("text", __myhandle__,
4063 false, false);
4056 4064
4057 xset (xlabel.handle_value (), "handlevisibility", "off"); 4065 xset (xlabel.handle_value (), "handlevisibility", "off");
4058 xset (ylabel.handle_value (), "handlevisibility", "off"); 4066 xset (ylabel.handle_value (), "handlevisibility", "off");
4059 xset (zlabel.handle_value (), "handlevisibility", "off"); 4067 xset (zlabel.handle_value (), "handlevisibility", "off");
4060 xset (title.handle_value (), "handlevisibility", "off"); 4068 xset (title.handle_value (), "handlevisibility", "off");
4120 // individual child object is delete and not when the parent axes 4128 // individual child object is delete and not when the parent axes
4121 // object is deleted. 4129 // object is deleted.
4122 4130
4123 if (! is_beingdeleted ()) 4131 if (! is_beingdeleted ())
4124 { 4132 {
4125 hp = gh_manager::make_graphics_handle ("text", __myhandle__, false); 4133 hp = gh_manager::make_graphics_handle ("text", __myhandle__,
4134 false, false);
4126 4135
4127 xset (hp.handle_value (), "handlevisibility", "off"); 4136 xset (hp.handle_value (), "handlevisibility", "off");
4128 4137
4129 adopt (hp.handle_value ()); 4138 adopt (hp.handle_value ());
4130 } 4139 }
7279 graphics_toolkit::default_toolkit (); 7288 graphics_toolkit::default_toolkit ();
7280 } 7289 }
7281 7290
7282 graphics_handle 7291 graphics_handle
7283 gh_manager::do_make_graphics_handle (const std::string& go_name, 7292 gh_manager::do_make_graphics_handle (const std::string& go_name,
7284 const graphics_handle& p, bool do_createfcn, 7293 const graphics_handle& p,
7294 bool integer_figure_handle,
7295 bool do_createfcn,
7285 bool do_notify_toolkit) 7296 bool do_notify_toolkit)
7286 { 7297 {
7287 graphics_handle h = get_handle (go_name); 7298 graphics_handle h = get_handle (integer_figure_handle);
7288 7299
7289 base_graphics_object *go = 0; 7300 base_graphics_object *go = 0;
7290 7301
7291 go = make_graphics_object_from_type (go_name, h, p); 7302 go = make_graphics_object_from_type (go_name, h, p);
7292 7303
8204 return retval; 8215 return retval;
8205 } 8216 }
8206 8217
8207 static octave_value 8218 static octave_value
8208 make_graphics_object (const std::string& go_name, 8219 make_graphics_object (const std::string& go_name,
8220 bool integer_figure_handle,
8209 const octave_value_list& args) 8221 const octave_value_list& args)
8210 { 8222 {
8211 octave_value retval; 8223 octave_value retval;
8212 8224
8213 double val = octave_NaN; 8225 double val = octave_NaN;
8243 graphics_handle parent = gh_manager::lookup (val); 8255 graphics_handle parent = gh_manager::lookup (val);
8244 8256
8245 if (parent.ok ()) 8257 if (parent.ok ())
8246 { 8258 {
8247 graphics_handle h 8259 graphics_handle h
8248 = gh_manager::make_graphics_handle (go_name, parent, false, false); 8260 = gh_manager::make_graphics_handle (go_name, parent,
8261 integer_figure_handle,
8262 false, false);
8249 8263
8250 if (! error_state) 8264 if (! error_state)
8251 { 8265 {
8252 adopt (parent, h); 8266 adopt (parent, h);
8253 8267
8299 } 8313 }
8300 else 8314 else
8301 { 8315 {
8302 graphics_handle h = octave_NaN; 8316 graphics_handle h = octave_NaN;
8303 8317
8304 if (xisnan (val)) 8318 if (xisnan (val) || xisinf (val))
8305 h = gh_manager::make_graphics_handle ("figure", 0, false, 8319 h = gh_manager::make_graphics_handle ("figure", 0,
8306 false); 8320 xisnan (val),
8321 false, false);
8307 else if (val > 0 && D_NINT (val) == val) 8322 else if (val > 0 && D_NINT (val) == val)
8308 h = gh_manager::make_figure_handle (val, false); 8323 h = gh_manager::make_figure_handle (val, false);
8309 else
8310 error ("__go_figure__: invalid figure number");
8311 8324
8312 if (! error_state && h.ok ()) 8325 if (! error_state && h.ok ())
8313 { 8326 {
8314 adopt (0, h); 8327 adopt (0, h);
8328
8329 gh_manager::push_figure (h);
8315 8330
8316 xset (h, args.splice (0, 1)); 8331 xset (h, args.splice (0, 1));
8317 xcreatefcn (h); 8332 xcreatefcn (h);
8318 xinitialize (h); 8333 xinitialize (h);
8319 8334
8336 gh_manager::auto_lock guard; \ 8351 gh_manager::auto_lock guard; \
8337 \ 8352 \
8338 octave_value retval; \ 8353 octave_value retval; \
8339 \ 8354 \
8340 if (args.length () > 0) \ 8355 if (args.length () > 0) \
8341 retval = make_graphics_object (#TYPE, args); \ 8356 retval = make_graphics_object (#TYPE, false, args); \
8342 else \ 8357 else \
8343 print_usage (); \ 8358 print_usage (); \
8344 \ 8359 \
8345 return retval 8360 return retval
8346 8361
8661 print_usage (); 8676 print_usage ();
8662 8677
8663 return retval; 8678 return retval;
8664 } 8679 }
8665 8680
8666 DEFUN (__go_handles__, , , 8681 DEFUN (__go_handles__, args, ,
8667 "-*- texinfo -*-\n\ 8682 "-*- texinfo -*-\n\
8668 @deftypefn {Built-in Function} {} __go_handles__ ()\n\ 8683 @deftypefn {Built-in Function} {} __go_handles__ (@var{show_hidden})\n\
8669 Undocumented internal function.\n\ 8684 Undocumented internal function.\n\
8670 @end deftypefn") 8685 @end deftypefn")
8671 { 8686 {
8672 gh_manager::auto_lock guard; 8687 gh_manager::auto_lock guard;
8673 8688
8674 return octave_value (gh_manager::handle_list ()); 8689 bool show_hidden = false;
8675 } 8690
8676 8691 if (args.length () > 0)
8677 DEFUN (__go_figure_handles__, , , 8692 show_hidden = args(0).bool_value ();
8693
8694 return octave_value (gh_manager::handle_list (show_hidden));
8695 }
8696
8697 DEFUN (__go_figure_handles__, args, ,
8678 "-*- texinfo -*-\n\ 8698 "-*- texinfo -*-\n\
8679 @deftypefn {Built-in Function} {} __go_figure_handles__ ()\n\ 8699 @deftypefn {Built-in Function} {} __go_figure_handles__ (@var{show_hidden})\n\
8680 Undocumented internal function.\n\ 8700 Undocumented internal function.\n\
8681 @end deftypefn") 8701 @end deftypefn")
8682 { 8702 {
8683 gh_manager::auto_lock guard; 8703 gh_manager::auto_lock guard;
8684 8704
8685 return octave_value (gh_manager::figure_handle_list ()); 8705 bool show_hidden = false;
8706
8707 if (args.length () > 0)
8708 show_hidden = args(0).bool_value ();
8709
8710 return octave_value (gh_manager::figure_handle_list (show_hidden));
8686 } 8711 }
8687 8712
8688 DEFUN (__go_execute_callback__, args, , 8713 DEFUN (__go_execute_callback__, args, ,
8689 "-*- texinfo -*-\n\ 8714 "-*- texinfo -*-\n\
8690 @deftypefn {Built-in Function} {} __go_execute_callback__ (@var{h}, @var{name})\n\ 8715 @deftypefn {Built-in Function} {} __go_execute_callback__ (@var{h}, @var{name})\n\
8815 __go_close_all_registered__ = true; 8840 __go_close_all_registered__ = true;
8816 } 8841 }
8817 8842
8818 if (args.length () == 0 || args.length () == 1) 8843 if (args.length () == 0 || args.length () == 1)
8819 { 8844 {
8820 Matrix hlist = gh_manager::figure_handle_list (); 8845 Matrix hlist = gh_manager::figure_handle_list (true);
8821 8846
8822 for (int i = 0; ! error_state && i < hlist.length (); i++) 8847 for (int i = 0; ! error_state && i < hlist.length (); i++)
8823 { 8848 {
8824 graphics_handle h = gh_manager::lookup (hlist(i)); 8849 graphics_handle h = gh_manager::lookup (hlist(i));
8825 8850