Mercurial > hg > octave-avbm
comparison src/graphics.cc @ 10717:9d4a198614ab
Add functionality set(handle)
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 21 Jun 2010 23:46:51 +0200 |
parents | fbd7843974fa |
children | 755fcb5baad3 |
comparison
equal
deleted
inserted
replaced
10716:f7f26094021b | 10717:9d4a198614ab |
---|---|
814 | 814 |
815 possible_vals.insert (t); | 815 possible_vals.insert (t); |
816 | 816 |
817 beg = end + 1; | 817 beg = end + 1; |
818 } | 818 } |
819 } | |
820 | |
821 std::string | |
822 radio_values::values_as_string (void) const | |
823 { | |
824 std::string retval; | |
825 for (std::set<caseless_str>::const_iterator it = possible_vals.begin (); | |
826 it != possible_vals.end (); it++) | |
827 { | |
828 if (retval == "") | |
829 { | |
830 if (*it == default_value ()) | |
831 retval = "{" + *it + "}"; | |
832 else | |
833 retval = *it; | |
834 } | |
835 else | |
836 { | |
837 if (*it == default_value ()) | |
838 retval += " | {" + *it + "}"; | |
839 else | |
840 retval += " | " + *it; | |
841 } | |
842 } | |
843 if (retval != "") | |
844 retval = "[ " + retval + " ]"; | |
845 return retval; | |
846 } | |
847 | |
848 Cell | |
849 radio_values::values_as_cell (void) const | |
850 { | |
851 octave_idx_type i = 0; | |
852 Cell retval (nelem (), 1); | |
853 for (std::set<caseless_str>::const_iterator it = possible_vals.begin (); | |
854 it != possible_vals.end (); it++) | |
855 retval(i++) = std::string (*it); | |
856 return retval; | |
819 } | 857 } |
820 | 858 |
821 bool | 859 bool |
822 color_values::str2rgb (std::string str) | 860 color_values::str2rgb (std::string str) |
823 { | 861 { |
1515 graphics_object::set (const octave_value_list& args) | 1553 graphics_object::set (const octave_value_list& args) |
1516 { | 1554 { |
1517 int nargin = args.length (); | 1555 int nargin = args.length (); |
1518 | 1556 |
1519 if (nargin == 0) | 1557 if (nargin == 0) |
1520 rep->defaults (); | 1558 error ("graphics_object::set: Nothing to set"); |
1521 else if (nargin % 2 == 0) | 1559 else if (nargin % 2 == 0) |
1522 { | 1560 { |
1523 for (int i = 0; i < nargin; i += 2) | 1561 for (int i = 0; i < nargin; i += 2) |
1524 { | 1562 { |
1525 caseless_str name = args(i).string_value (); | 1563 caseless_str name = args(i).string_value (); |
2412 property p = get_properties ().get_property (pa->first); | 2450 property p = get_properties ().get_property (pa->first); |
2413 | 2451 |
2414 if (! error_state && p.ok ()) | 2452 if (! error_state && p.ok ()) |
2415 p.delete_listener (); | 2453 p.delete_listener (); |
2416 } | 2454 } |
2455 } | |
2456 | |
2457 std::string | |
2458 base_graphics_object::values_as_string (void) | |
2459 { | |
2460 std::string retval; | |
2461 | |
2462 if (valid_object ()) | |
2463 { | |
2464 Octave_map m = get ().map_value (); | |
2465 | |
2466 for (Octave_map::const_iterator pa = m.begin (); pa != m.end (); pa++) | |
2467 { | |
2468 if (pa->first != "children") | |
2469 { | |
2470 property p = get_properties ().get_property (pa->first); | |
2471 | |
2472 if (p.ok () && ! p.is_hidden ()) | |
2473 { | |
2474 retval += "\n\t" + std::string (pa->first) + ": "; | |
2475 if (p.is_radio ()) | |
2476 retval += p.values_as_string (); | |
2477 } | |
2478 } | |
2479 } | |
2480 if (retval != "") | |
2481 retval += "\n"; | |
2482 } | |
2483 else | |
2484 error ("base_graphics_object::values_as_string: invalid graphics object"); | |
2485 | |
2486 return retval; | |
2487 } | |
2488 | |
2489 Octave_map | |
2490 base_graphics_object::values_as_struct (void) | |
2491 { | |
2492 Octave_map retval; | |
2493 | |
2494 if (valid_object ()) | |
2495 { | |
2496 Octave_map m = get ().map_value (); | |
2497 | |
2498 for (Octave_map::const_iterator pa = m.begin (); pa != m.end (); pa++) | |
2499 { | |
2500 if (pa->first != "children") | |
2501 { | |
2502 property p = get_properties ().get_property (pa->first); | |
2503 | |
2504 if (p.ok () && ! p.is_hidden ()) | |
2505 { | |
2506 if (p.is_radio ()) | |
2507 retval.assign (p.get_name (), | |
2508 octave_value (p.values_as_cell ())); | |
2509 else | |
2510 retval.assign (p.get_name (), octave_value (Cell ())); | |
2511 } | |
2512 } | |
2513 } | |
2514 } | |
2515 else | |
2516 error ("base_graphics_object::values_as_struct: invalid graphics object"); | |
2517 | |
2518 return retval; | |
2417 } | 2519 } |
2418 | 2520 |
2419 // --------------------------------------------------------------------- | 2521 // --------------------------------------------------------------------- |
2420 | 2522 |
2421 #include "graphics-props.cc" | 2523 #include "graphics-props.cc" |
4928 print_usage (); | 5030 print_usage (); |
4929 | 5031 |
4930 return retval; | 5032 return retval; |
4931 } | 5033 } |
4932 | 5034 |
4933 DEFUN (set, args, , | 5035 DEFUN (set, args, nargout, |
4934 "-*- texinfo -*-\n\ | 5036 "-*- texinfo -*-\n\ |
4935 @deftypefn {Built-in Function} {} set (@var{h}, @var{property}, @var{value}, @dots{})\n\ | 5037 @deftypefn {Built-in Function} {} set (@var{h}, @var{property}, @var{value}, @dots{})\n\ |
4936 @deftypefnx {Built-in Function} {} set (@var{h}, @var{properties}, @var{values})\n\ | 5038 @deftypefnx {Built-in Function} {} set (@var{h}, @var{properties}, @var{values})\n\ |
4937 @deftypefnx {Built-in Function} {} set (@var{h}, @var{pv})\n\ | 5039 @deftypefnx {Built-in Function} {} set (@var{h}, @var{pv})\n\ |
4938 Set named property values for the graphics handle (or vector of graphics\n\ | 5040 Set named property values for the graphics handle (or vector of graphics\n\ |
5007 } | 5109 } |
5008 } | 5110 } |
5009 else if (nargin == 2 && args(1).is_map ()) | 5111 else if (nargin == 2 && args(1).is_map ()) |
5010 { | 5112 { |
5011 obj.set (args(1).map_value ()); | 5113 obj.set (args(1).map_value ()); |
5114 } | |
5115 else if (nargin == 1) | |
5116 { | |
5117 if (nargout != 0) | |
5118 retval = obj.values_as_struct (); | |
5119 else | |
5120 { | |
5121 std::string s = obj.values_as_string (); | |
5122 if (! error_state) | |
5123 octave_stdout << s; | |
5124 } | |
5012 } | 5125 } |
5013 else | 5126 else |
5014 { | 5127 { |
5015 obj.set (args.splice (0, 1)); | 5128 obj.set (args.splice (0, 1)); |
5016 request_drawnow = true; | 5129 request_drawnow = true; |