# HG changeset patch # User John W. Eaton # Date 1313339474 14400 # Node ID 0c86ae6f7c34fcb1a179947a31db5c21627680a3 # Parent ae88a81e5d5ccae495b1f333d83172c8727485ba new text_label_property graphics property type * chMatrix.cc (charMatrix::charMatrix (const string_vector&)): Accept optional fill value. * chMatrix.h: Fix decl. * graphics.h.in (text_label_property): New property type. (text::properties::string): Use it. (text::properties::get_string): New custom get function for string property. * genprops.awk (emit_declarations): Handle text_label_property the same as string_array_property. diff -r ae88a81e5d5c -r 0c86ae6f7c34 liboctave/chMatrix.cc --- a/liboctave/chMatrix.cc Fri Aug 12 14:16:34 2011 -0400 +++ b/liboctave/chMatrix.cc Sun Aug 14 12:31:14 2011 -0400 @@ -74,8 +74,8 @@ elem (0, i) = s[i]; } -charMatrix::charMatrix (const string_vector& s) - : Array (dim_vector (s.length (), s.max_length ()), 0) +charMatrix::charMatrix (const string_vector& s, char fill_value) + : Array (dim_vector (s.length (), s.max_length ()), fill_value) { octave_idx_type nr = rows (); diff -r ae88a81e5d5c -r 0c86ae6f7c34 liboctave/chMatrix.h --- a/liboctave/chMatrix.h Fri Aug 12 14:16:34 2011 -0400 +++ b/liboctave/chMatrix.h Sun Aug 14 12:31:14 2011 -0400 @@ -62,7 +62,7 @@ charMatrix (const std::string& s); - charMatrix (const string_vector& s); + charMatrix (const string_vector& s, char fill_value = '\0'); charMatrix& operator = (const charMatrix& a) { diff -r ae88a81e5d5c -r 0c86ae6f7c34 src/genprops.awk --- a/src/genprops.awk Fri Aug 12 14:16:34 2011 -0400 +++ b/src/genprops.awk Sun Aug 14 12:31:14 2011 -0400 @@ -300,8 +300,9 @@ emit_get_accessor(i, "graphics_handle", "handle_value"); else if (type[i] == "string_property") emit_get_accessor(i, "std::string", "string_value"); - else if (type[i] == "string_array_property") - emit_get_accessor(i, "octave_value", "get"); + else if (type[i] == "string_array_property" \ + || type[i] == "text_label_property") + emit_get_accessor(i, "octave_value", "get"); else if (type[i] == "double_property") emit_get_accessor(i, "double", "double_value"); else if (type[i] == "double_radio_property") diff -r ae88a81e5d5c -r 0c86ae6f7c34 src/graphics.h.in --- a/src/graphics.h.in Fri Aug 12 14:16:34 2011 -0400 +++ b/src/graphics.h.in Sun Aug 14 12:31:14 2011 -0400 @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "caseless-str.h" @@ -692,6 +693,170 @@ // --------------------------------------------------------------------- +class text_label_property : public base_property +{ +public: + enum type { char_t, cellstr_t }; + + text_label_property (const std::string& s, const graphics_handle& h, + const std::string& val = "") + : base_property (s, h), value (val), stored_type (char_t) + { } + + text_label_property (const std::string& s, const graphics_handle& h, + const NDArray& nda) + : base_property (s, h), stored_type (char_t) + { + octave_idx_type nel = nda.numel (); + + value.resize (nel); + + for (octave_idx_type i = 0; i < nel; i++) + { + std::ostringstream buf; + buf << nda(i); + value[i] = buf.str (); + } + } + + text_label_property (const std::string& s, const graphics_handle& h, + const Cell& c) + : base_property (s, h), stored_type (cellstr_t) + { + octave_idx_type nel = c.numel (); + + value.resize (nel); + + for (octave_idx_type i = 0; i < nel; i++) + { + octave_value tmp = c(i); + + if (tmp.is_string ()) + value[i] = c(i).string_value (); + else + { + double d = c(i).double_value (); + + if (! error_state) + { + std::ostringstream buf; + buf << d; + value[i] = buf.str (); + } + else + break; + } + } + } + + text_label_property (const text_label_property& p) + : base_property (p), value (p.value), stored_type (p.stored_type) + { } + + octave_value get (void) const + { + if (stored_type == char_t) + return octave_value (char_value ()); + else + return octave_value (cell_value ()); + } + + std::string string_value (void) const + { + return value.empty () ? std::string () : value[0]; + } + + string_vector string_vector_value (void) const { return value; } + + charMatrix char_value (void) const { return charMatrix (value, ' '); } + + Cell cell_value (void) const {return Cell (value); } + + text_label_property& operator = (const octave_value& val) + { + set (val); + return *this; + } + + base_property* clone (void) const { return new text_label_property (*this); } + +protected: + + bool do_set (const octave_value& val) + { + if (val.is_string ()) + { + value = val.all_strings (); + + stored_type = char_t; + } + else if (val.is_cell ()) + { + Cell c = val.cell_value (); + + octave_idx_type nel = c.numel (); + + value.resize (nel); + + for (octave_idx_type i = 0; i < nel; i++) + { + octave_value tmp = c(i); + + if (tmp.is_string ()) + value[i] = c(i).string_value (); + else + { + double d = c(i).double_value (); + + if (! error_state) + { + std::ostringstream buf; + buf << d; + value[i] = buf.str (); + } + else + return false; + } + } + } + else + { + NDArray nda = val.array_value (); + + if (! error_state) + { + octave_idx_type nel = nda.numel (); + + value.resize (nel); + + for (octave_idx_type i = 0; i < nel; i++) + { + std::ostringstream buf; + buf << nda(i); + value[i] = buf.str (); + } + + stored_type = char_t; + } + else + { + error ("set: invalid string property value for \"%s\"", + get_name ().c_str ()); + + return false; + } + } + + return true; + } + +private: + string_vector value; + type stored_type; +}; + +// --------------------------------------------------------------------- + class radio_values { public: @@ -3686,7 +3851,7 @@ // properties declarations. BEGIN_PROPERTIES (text) - string_property string u , "" + text_label_property string gu , "" radio_property units u , "{data}|pixels|normalized|inches|centimeters|points" array_property position mu , Matrix (1, 3, 0.0) double_property rotation mu , 0 @@ -3723,6 +3888,8 @@ radio_property autopos_tag h , "{none}|xlabel|ylabel|zlabel|title" END_PROPERTIES + std::string get_string (void) const { return string.string_value (); } + Matrix get_data_position (void) const; Matrix get_extent_matrix (void) const; const uint8NDArray& get_pixels (void) const { return pixels; }