# HG changeset patch # User John W. Eaton # Date 1203929090 18000 # Node ID f2000f1971ab6499e94ba0af41782e2563fb2fd0 # Parent 8a6965a011764c14a5d33e15d498453c3613fe3b new row_vector_property class diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2008-02-25 John W. Eaton + + * 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 * DLD-FUNCTIONS/ccolamd.cc, DLD-FUNCTIONS/colamd.cc, diff --git a/src/genprops.awk b/src/genprops.awk --- 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"); diff --git a/src/graphics.cc b/src/graphics.cc --- 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::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) { diff --git a/src/graphics.h.in b/src/graphics.h.in --- 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 type_constraints; std::list 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));