Mercurial > hg > octave-terminal
changeset 7523:f2000f1971ab
new row_vector_property class
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 25 Feb 2008 03:44:50 -0500 |
parents | 8a6965a01176 |
children | a653856aa3e1 |
files | src/ChangeLog src/genprops.awk src/graphics.cc src/graphics.h.in |
diffstat | 4 files changed, 87 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2008-02-25 John W. Eaton <jwe@octave.org> + + * graphics.h.in, graphics.cc (class row_vector_property): New class. + (axes::properties): xlim, ylim, zlim, clim, alim, xtick, ytick, + ztick properties are now row_vector_property objects instead of + array_property objects. + * genprops.awk: Special case row_vector_property in the same way + as array_property. + 2008-02-22 John W. Eaton <jwe@octave.org> * DLD-FUNCTIONS/ccolamd.cc, DLD-FUNCTIONS/colamd.cc,
--- a/src/genprops.awk +++ b/src/genprops.awk @@ -244,7 +244,9 @@ { if (emit_get[i]) { - if (type[i] == "array_property" || type[i] == "any_property") + if (type[i] == "array_property" \ + || type[i] == "row_vector_property" \ + || type[i] == "any_property") emit_get_accessor(i, "octave_value", "get"); else if (type[i] == "handle_property") emit_get_accessor(i, "graphics_handle", "handle_value");
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -491,6 +491,36 @@ return xok; } +bool +row_vector_property::validate (const octave_value& v) +{ + bool xok = false; + + // FIXME: should we always support []? + if (v.is_empty () && v.is_double_type ()) + return true; + + // check value type + if (type_constraints.size () > 0) + { + for (std::list<std::string>::const_iterator it = type_constraints.begin (); + ! xok && it != type_constraints.end (); ++it) + if ((*it) == v.type_name ()) + xok = true; + } + else + xok = v.is_double_type (); + + if (xok) + { + dim_vector vdims = v.dims (); + + xok = vdims.length () != 2 || (vdims(0) != 1 && vdims(1) != 1); + } + + return xok; +} + void handle_property::set (const octave_value& v) {
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -717,12 +717,48 @@ private: OCTINTERP_API bool validate (const octave_value& v); -private: +protected: octave_value data; std::list<std::string> type_constraints; std::list<dim_vector> size_constraints; }; +class row_vector_property : public array_property +{ +public: + row_vector_property (const std::string& nm, const graphics_handle& h, + const octave_value& m) + : array_property (nm, h, m) { } + + void set (const octave_value& v) + { + array_property::set (v); + + if (! error_state) + { + dim_vector dv = data.dims (); + + if (dv(0) > 1 && dv(1) == 1) + { + int tmp = dv(0); + dv(0) = dv(1); + dv(1) = tmp; + + data = data.reshape (dv); + } + } + } + + row_vector_property& operator = (const octave_value& val) + { + set (val); + return *this; + } + +private: + OCTINTERP_API bool validate (const octave_value& v); +}; + // --------------------------------------------------------------------- class data_property : public base_property @@ -2330,11 +2366,11 @@ array_property dataaspectratio m , Matrix (1, 3, 1.0) radio_property dataaspectratiomode , "{auto}|manual" radio_property layer , "{bottom}|top" - array_property xlim mu , default_lim () - array_property ylim mu , default_lim () - array_property zlim mu , default_lim () - array_property clim m , default_lim () - array_property alim m , default_lim () + row_vector_property xlim mu , default_lim () + row_vector_property ylim mu , default_lim () + row_vector_property zlim mu , default_lim () + row_vector_property clim m , default_lim () + row_vector_property alim m , default_lim () radio_property xlimmode al , "{auto}|manual" radio_property ylimmode al , "{auto}|manual" radio_property zlimmode al , "{auto}|manual" @@ -2349,9 +2385,9 @@ bool_property xminorgrid , "off" bool_property yminorgrid , "off" bool_property zminorgrid , "off" - array_property xtick m , Matrix () - array_property ytick m , Matrix () - array_property ztick m , Matrix () + row_vector_property xtick m , Matrix () + row_vector_property ytick m , Matrix () + row_vector_property ztick m , Matrix () radio_property xtickmode , "{auto}|manual" radio_property ytickmode , "{auto}|manual" radio_property ztickmode , "{auto}|manual" @@ -2429,11 +2465,6 @@ colororder.add_constraint (dim_vector (-1, 3)); dataaspectratio.add_constraint (dim_vector (1, 3)); plotboxaspectratio.add_constraint (dim_vector (1, 3)); - xlim.add_constraint (dim_vector (1, 2)); - ylim.add_constraint (dim_vector (1, 2)); - zlim.add_constraint (dim_vector (1, 2)); - clim.add_constraint (dim_vector (1, 2)); - alim.add_constraint (dim_vector (1, 2)); xtick.add_constraint (dim_vector (1, -1)); ytick.add_constraint (dim_vector (1, -1)); ztick.add_constraint (dim_vector (1, -1));