Mercurial > hg > octave-shane
changeset 10717:9d4a198614ab
Add functionality set(handle)
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 21 Jun 2010 23:46:51 +0200 |
parents | f7f26094021b |
children | b8d76f4be94a |
files | src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 3 files changed, 188 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,32 @@ +2010-06-21 David Bateman <dbateman@free.fr> + + * graphics.cc (std::string radio_values:values_as_string (void) + const, Cell radio_values:values_as_cell (void) const): New functions. + (void graphics_object::set (const octave_value_list&)): Throw error + with no arguments. + (std::string base_graphics_object::values_as_string (void), + Octave_map base_graphics_object::values_as_struct (void)): New + functions. + (Fset): Allow single handle as an argument and return the radio + values. + * graphics.h.in (virtual bool base_property::is_radio (void) const, + virtual std::string base_property::values_as_string (void) const, + virtual Cell base_property::values_as_cell (void) const): + New function. + (std::string radio_values::values_as_string (void) const, + Cell radio_values::values_as_cell (void) const): Declaration. + (octave_idx_type radio_values::nelem (void) const): New function. + (std::string radio_property::values_as_string (void) const, + Cell radio_property::values_as_cell (void) const, + bool radio_property::is_radio (void) const): New functions. + (bool property::is_radio (void) const, + std::string raproperty::values_as_string (void) const, + Cell property::values_as_cell (void) const): New functions. + (std::string base_graphics_object::values_as_string (void), + Octave_map base_graphics_object::values_as_struct (void)): Declaration. + (std::string graphics_object::values_as_string (void), + Octave_map graphics_object::values_as_struct (void)): New functions. + 2010-06-21 Jaroslav Hajek <highegg@gmail.com> * data.cc (single_type_concat): Assume matrix arguments start from
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -818,6 +818,44 @@ } } +std::string +radio_values::values_as_string (void) const +{ + std::string retval; + for (std::set<caseless_str>::const_iterator it = possible_vals.begin (); + it != possible_vals.end (); it++) + { + if (retval == "") + { + if (*it == default_value ()) + retval = "{" + *it + "}"; + else + retval = *it; + } + else + { + if (*it == default_value ()) + retval += " | {" + *it + "}"; + else + retval += " | " + *it; + } + } + if (retval != "") + retval = "[ " + retval + " ]"; + return retval; +} + +Cell +radio_values::values_as_cell (void) const +{ + octave_idx_type i = 0; + Cell retval (nelem (), 1); + for (std::set<caseless_str>::const_iterator it = possible_vals.begin (); + it != possible_vals.end (); it++) + retval(i++) = std::string (*it); + return retval; +} + bool color_values::str2rgb (std::string str) { @@ -1517,7 +1555,7 @@ int nargin = args.length (); if (nargin == 0) - rep->defaults (); + error ("graphics_object::set: Nothing to set"); else if (nargin % 2 == 0) { for (int i = 0; i < nargin; i += 2) @@ -2416,6 +2454,70 @@ } } +std::string +base_graphics_object::values_as_string (void) +{ + std::string retval; + + if (valid_object ()) + { + Octave_map m = get ().map_value (); + + for (Octave_map::const_iterator pa = m.begin (); pa != m.end (); pa++) + { + if (pa->first != "children") + { + property p = get_properties ().get_property (pa->first); + + if (p.ok () && ! p.is_hidden ()) + { + retval += "\n\t" + std::string (pa->first) + ": "; + if (p.is_radio ()) + retval += p.values_as_string (); + } + } + } + if (retval != "") + retval += "\n"; + } + else + error ("base_graphics_object::values_as_string: invalid graphics object"); + + return retval; +} + +Octave_map +base_graphics_object::values_as_struct (void) +{ + Octave_map retval; + + if (valid_object ()) + { + Octave_map m = get ().map_value (); + + for (Octave_map::const_iterator pa = m.begin (); pa != m.end (); pa++) + { + if (pa->first != "children") + { + property p = get_properties ().get_property (pa->first); + + if (p.ok () && ! p.is_hidden ()) + { + if (p.is_radio ()) + retval.assign (p.get_name (), + octave_value (p.values_as_cell ())); + else + retval.assign (p.get_name (), octave_value (Cell ())); + } + } + } + } + else + error ("base_graphics_object::values_as_struct: invalid graphics object"); + + return retval; +} + // --------------------------------------------------------------------- #include "graphics-props.cc" @@ -4930,7 +5032,7 @@ return retval; } -DEFUN (set, args, , +DEFUN (set, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} set (@var{h}, @var{property}, @var{value}, @dots{})\n\ @deftypefnx {Built-in Function} {} set (@var{h}, @var{properties}, @var{values})\n\ @@ -5010,6 +5112,17 @@ { obj.set (args(1).map_value ()); } + else if (nargin == 1) + { + if (nargout != 0) + retval = obj.values_as_struct (); + else + { + std::string s = obj.values_as_string (); + if (! error_state) + octave_stdout << s; + } + } else { obj.set (args.splice (0, 1));
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -381,6 +381,8 @@ void set_hidden (bool flag) { hidden = flag; } + virtual bool is_radio (void) const { return false; } + int get_id (void) const { return id; } void set_id (int d) { id = d; } @@ -395,6 +397,19 @@ return octave_value (); } + + virtual std::string values_as_string (void) const + { + error ("values_as_string: invalid property \"%s\"", name.c_str ()); + return std::string (); + } + + virtual Cell values_as_cell (void) const + { + error ("values_as_cell: invalid property \"%s\"", name.c_str ()); + return Cell (); + } + base_property& operator = (const octave_value& val) { set (val); @@ -722,6 +737,12 @@ return (possible_vals.find (val) != possible_vals.end ()); } + std::string values_as_string (void) const; + + Cell values_as_cell (void) const; + + octave_idx_type nelem (void) const { return possible_vals.size (); } + private: // Might also want to cache std::string default_val; @@ -753,9 +774,15 @@ const std::string& current_value (void) const { return current_val; } + std::string values_as_string (void) const { return vals.values_as_string (); } + + Cell values_as_cell (void) const { return vals.values_as_cell (); } + bool is (const caseless_str& v) const { return v.compare (current_val); } + bool is_radio (void) const { return true; } + radio_property& operator = (const octave_value& val) { set (val); @@ -1469,6 +1496,9 @@ void set_hidden (bool flag) { rep->set_hidden (flag); } + bool is_radio (void) const + { return rep->is_radio (); } + int get_id (void) const { return rep->get_id (); } @@ -1481,6 +1511,12 @@ bool set (const octave_value& val) { return rep->set (val); } + std::string values_as_string (void) const + { return rep->values_as_string (); } + + Cell values_as_cell (void) const + { return rep->values_as_cell (); } + property& operator = (const octave_value& val) { *rep = val; @@ -2068,6 +2104,10 @@ return octave_value (); } + virtual std::string values_as_string (void); + + virtual Octave_map values_as_struct (void); + virtual graphics_handle get_parent (void) const { if (valid_object ()) @@ -2285,6 +2325,10 @@ return rep->get_factory_defaults (); } + std::string values_as_string (void) { return rep->values_as_string (); } + + Octave_map values_as_struct (void) { return rep->values_as_struct (); } + graphics_handle get_parent (void) const { return rep->get_parent (); } graphics_handle get_handle (void) const { return rep->get_handle (); }