Mercurial > hg > octave-jordi
diff src/graphics.h.in @ 7862:8f3459a90bf3
Redesign axis limit computation handling (using hidden limit properties in child objects)
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sun, 23 Mar 2008 16:45:45 +0100 |
parents | 67edbcb19665 |
children | 56f781f38f0b |
line wrap: on
line diff
--- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -852,6 +852,17 @@ double max_val (void) const { return xmax; } double min_pos (void) const { return xminp; } + Matrix get_limits (void) const + { + Matrix m (1, 3); + + m(0) = min_val (); + m(1) = max_val (); + m(2) = min_pos (); + + return m; + } + array_property& operator = (const octave_value& val) { set (val); @@ -1671,54 +1682,19 @@ // genprops.awk script. // // EMIT_BASE_PROPERTIES_GET_FUNCTIONS - virtual array_property get_xdata_property (void) const - { - error ("get: invalid property \"xdata\""); - return array_property (); - } - - virtual array_property get_ydata_property (void) const - { - error ("get: invalid property \"ydata\""); - return array_property (); - } - - virtual array_property get_zdata_property (void) const - { - error ("get: invalid property \"zdata\""); - return array_property (); - } - - virtual array_property get_ldata_property (void) const - { - error ("get: invalid property \"ldata\""); - return array_property (); - } - - virtual array_property get_udata_property (void) const - { - error ("get: invalid property \"udata\""); - return array_property (); - } - - virtual array_property get_xldata_property (void) const - { - error ("get: invalid property \"xldata\""); - return array_property (); - } - - virtual array_property get_xudata_property (void) const - { - error ("get: invalid property \"xudata\""); - return array_property (); - } - - virtual array_property get_cdata_property (void) const - { - error ("get: invalid property \"cdata\""); - return array_property (); - } - + + virtual octave_value get_xlim (void) const { return octave_value (); } + virtual octave_value get_ylim (void) const { return octave_value (); } + virtual octave_value get_zlim (void) const { return octave_value (); } + virtual octave_value get_clim (void) const { return octave_value (); } + virtual octave_value get_alim (void) const { return octave_value (); } + + virtual bool is_xliminclude (void) const { return false; } + virtual bool is_yliminclude (void) const { return false; } + virtual bool is_zliminclude (void) const { return false; } + virtual bool is_climinclude (void) const { return false; } + virtual bool is_aliminclude (void) const { return false; } + protected: // properties common to all objects bool_property beingdeleted; @@ -1901,10 +1877,7 @@ return properties; } - virtual void update_axis_limits (const std::string&) - { - error ("base_graphics_object::update_axis_limits: invalid graphics object"); - } + virtual void update_axis_limits (const std::string& axis_type); virtual bool valid_object (void) const { return false; } @@ -2054,54 +2027,37 @@ // genprops.awk script. // // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS - array_property get_xdata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_xdata_property (); - } - - array_property get_ydata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_ydata_property (); - } - - array_property get_zdata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_zdata_property (); - } - - array_property get_ldata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_ldata_property (); - } - - array_property get_udata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_udata_property (); - } - - array_property get_xldata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_xldata_property (); - } - - array_property get_xudata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_xudata_property (); - } - - array_property get_cdata_property (void) const - { - const base_properties& props = get_properties (); - return props.get_cdata_property (); - } - + + octave_value get_xlim (void) const + { return get_properties ().get_xlim (); } + + octave_value get_ylim (void) const + { return get_properties ().get_ylim (); } + + octave_value get_zlim (void) const + { return get_properties ().get_zlim (); } + + octave_value get_clim (void) const + { return get_properties ().get_clim (); } + + octave_value get_alim (void) const + { return get_properties ().get_alim (); } + + bool is_xliminclude (void) const + { return get_properties ().is_xliminclude (); } + + bool is_yliminclude (void) const + { return get_properties ().is_yliminclude (); } + + bool is_zliminclude (void) const + { return get_properties ().is_zliminclude (); } + + bool is_climinclude (void) const + { return get_properties ().is_climinclude (); } + + bool is_aliminclude (void) const + { return get_properties ().is_aliminclude (); } + graphics_backend get_backend (void) const { return rep->get_backend (); } void add_property_listener (const std::string& nm, const octave_value& v, @@ -2866,13 +2822,13 @@ // ldata, udata, xldata, xudata, keylabel, interpreter BEGIN_PROPERTIES(line) - row_vector_property xdata l , default_data () - row_vector_property ydata l , default_data () - row_vector_property zdata l , Matrix () - row_vector_property ldata l , Matrix () - row_vector_property udata l , Matrix () - row_vector_property xldata l , Matrix () - row_vector_property xudata l , Matrix () + row_vector_property xdata u , default_data () + row_vector_property ydata u , default_data () + row_vector_property zdata u , Matrix () + row_vector_property ldata u , Matrix () + row_vector_property udata u , Matrix () + row_vector_property xldata u , Matrix () + row_vector_property xudata u , Matrix () color_property color , color_values (0, 0, 0) radio_property linestyle , "{-}|--|:|-.|none" double_property linewidth , 0.5 @@ -2884,7 +2840,32 @@ radio_property interpreter , "{tex}|none|latex" string_property displayname , "" radio_property erasemode , "{normal}|none|xor|background" + // hidden properties for limit computation + row_vector_property xlim hlr , Matrix () + row_vector_property ylim hlr , Matrix () + row_vector_property zlim hlr , Matrix () + bool_property xliminclude hl , "on" + bool_property yliminclude hl , "on" + bool_property zliminclude hl , "off" END_PROPERTIES + + private: + Matrix compute_xlim (void) const; + Matrix compute_ylim (void) const; + + void update_xdata (void) { set_xlim (compute_xlim ()); } + void update_xldata (void) { set_xlim (compute_xlim ()); } + void update_xudata (void) { set_xlim (compute_xlim ()); } + + void update_ydata (void) { set_ylim (compute_ylim ()); } + void update_ldata (void) { set_ylim (compute_ylim ()); } + void update_udata (void) { set_ylim (compute_ylim ()); } + + void update_zdata (void) + { + set_zlim (zdata.get_limits ()); + set_zliminclude (get_zdata ().numel () > 0); + } }; private: @@ -2920,7 +2901,7 @@ BEGIN_PROPERTIES(text) string_property string , "" radio_property units , "{data}|pixels|normalized|inches|centimeters|points" - array_property position , Matrix (1, 3, 0.0) + array_property position u , Matrix (1, 3, 0.0) double_property rotation , 0 radio_property horizontalalignment , "{left}|center|right" color_property color , color_values (0, 0, 0) @@ -2939,6 +2920,13 @@ double_property linewidth , 0.5 double_property margin , 1 radio_property verticalalignment , "top|cap|{middle}|baseline|bottom" + // hidden properties for limit computation + row_vector_property xlim hlr , Matrix () + row_vector_property ylim hlr , Matrix () + row_vector_property zlim hlr , Matrix () + bool_property xliminclude hl , "on" + bool_property yliminclude hl , "on" + bool_property zliminclude hl , "off" END_PROPERTIES protected: @@ -2946,6 +2934,31 @@ { position.add_constraint (dim_vector (1, 3)); } + + private: + void update_position (void) + { + Matrix pos = get_position ().matrix_value (); + Matrix lim; + + lim = Matrix (1, 3, pos(0)); + lim(2) = (lim(2) <= 0 ? octave_Inf : lim(2)); + set_xlim (lim); + + lim = Matrix (1, 3, pos(1)); + lim(2) = (lim(2) <= 0 ? octave_Inf : lim(2)); + set_ylim (lim); + + if (pos.numel () == 3) + { + lim = Matrix (1, 3, pos(2)); + lim(2) = (lim(2) <= 0 ? octave_Inf : lim(2)); + set_zliminclude ("on"); + set_zlim (lim); + } + else + set_zliminclude ("off"); + } }; private: @@ -2975,14 +2988,26 @@ class OCTINTERP_API properties : public base_properties { public: + bool is_climinclude (void) const + { return (climinclude.is_on () && cdatamapping.is ("scaled")); } + std::string get_climinclude (void) const + { return climinclude.current_value (); } + // See the genprops.awk script for an explanation of the // properties declarations. BEGIN_PROPERTIES(image) - row_vector_property xdata l , Matrix () - row_vector_property ydata l , Matrix () - array_property cdata l , Matrix () - radio_property cdatamapping a , "{scaled}|direct" + row_vector_property xdata u , Matrix () + row_vector_property ydata u , Matrix () + array_property cdata u , Matrix () + radio_property cdatamapping al , "{scaled}|direct" + // hidden properties for limit computation + row_vector_property xlim hlr , Matrix() + row_vector_property ylim hlr , Matrix() + row_vector_property clim hlr , Matrix() + bool_property xliminclude hl , "on" + bool_property yliminclude hl , "on" + bool_property climinclude hlg , "on" END_PROPERTIES protected: @@ -2995,6 +3020,23 @@ cdata.add_constraint (dim_vector (-1, -1)); cdata.add_constraint (dim_vector (-1, -1, 3)); } + + private: + // FIXME: limits should take pixel width into account + void update_xdata (void) + { set_xlim (xdata.get_limits ()); } + + // FIXME: idem + void update_ydata (void) + { set_ylim (ydata.get_limits ()); } + + void update_cdata (void) + { + if (cdatamapping_is ("scaled")) + set_clim (cdata.get_limits ()); + else + clim = cdata.get_limits (); + } }; private: @@ -3026,15 +3068,25 @@ public: octave_value get_color_data (void) const; + bool is_climinclude (void) const + { return (climinclude.is_on () && cdatamapping.is ("scaled")); } + std::string get_climinclude (void) const + { return climinclude.current_value (); } + + bool is_aliminclude (void) const + { return (aliminclude.is_on () && alphadatamapping.is ("scaled")); } + std::string get_aliminclude (void) const + { return aliminclude.current_value (); } + // See the genprops.awk script for an explanation of the // properties declarations. BEGIN_PROPERTIES(patch) - array_property xdata l , Matrix () - array_property ydata l , Matrix () - array_property zdata l , Matrix () - array_property cdata l , Matrix () - radio_property cdatamapping , "{scaled}|direct" + array_property xdata u , Matrix () + array_property ydata u , Matrix () + array_property zdata u , Matrix () + array_property cdata u , Matrix () + radio_property cdatamapping l , "{scaled}|direct" array_property faces , Matrix () array_property facevertexalphadata , Matrix () array_property facevertexcdata , Matrix () @@ -3062,6 +3114,18 @@ double_property markersize , 6 string_property keylabel , "" radio_property interpreter , "{tex}|none|latex" + radio_property alphadatamapping l , "none|{scaled}|direct" + // hidden properties for limit computation + row_vector_property xlim hlr , Matrix () + row_vector_property ylim hlr , Matrix () + row_vector_property zlim hlr , Matrix () + row_vector_property clim hlr , Matrix () + row_vector_property alim hlr , Matrix () + bool_property xliminclude hl , "on" + bool_property yliminclude hl , "on" + bool_property zliminclude hl , "on" + bool_property climinclude hlg , "on" + bool_property aliminclude hlg , "on" END_PROPERTIES protected: @@ -3078,6 +3142,19 @@ facevertexcdata.add_constraint (dim_vector (-1, 3)); facevertexalphadata.add_constraint (dim_vector (-1, 1)); } + + private: + void update_xdata (void) { set_xlim (xdata.get_limits ()); } + void update_ydata (void) { set_ylim (ydata.get_limits ()); } + void update_zdata (void) { set_zlim (zdata.get_limits ()); } + + void update_cdata (void) + { + if (cdatamapping_is ("scaled")) + set_clim (cdata.get_limits ()); + else + clim = cdata.get_limits (); + } }; private: @@ -3109,15 +3186,25 @@ public: octave_value get_color_data (void) const; + bool is_climinclude (void) const + { return (climinclude.is_on () && cdatamapping.is ("scaled")); } + std::string get_climinclude (void) const + { return climinclude.current_value (); } + + bool is_aliminclude (void) const + { return (aliminclude.is_on () && alphadatamapping.is ("scaled")); } + std::string get_aliminclude (void) const + { return aliminclude.current_value (); } + // See the genprops.awk script for an explanation of the // properties declarations. BEGIN_PROPERTIES(surface) - array_property xdata lu , Matrix () - array_property ydata lu , Matrix () - array_property zdata lu , Matrix () - array_property cdata l , Matrix () - radio_property cdatamapping a , "{scaled}|direct" + array_property xdata u , Matrix () + array_property ydata u , Matrix () + array_property zdata u , Matrix () + array_property cdata u , Matrix () + radio_property cdatamapping al , "{scaled}|direct" color_property facecolor , "{flat}|none|interp|texturemap" double_radio_property facealpha , double_radio_property (1.0, radio_values ("flat|interp")) color_property edgecolor , color_property (color_values (0, 0, 0), radio_values ("flat|none|interp")) @@ -3129,8 +3216,8 @@ double_property markersize , 6 string_property keylabel , "" radio_property interpreter , "{tex}|none|latex" - array_property alphadata , Matrix () - radio_property alphadatamapping , "none|direct|{scaled}" + array_property alphadata u , Matrix () + radio_property alphadatamapping l , "none|direct|{scaled}" double_property ambientstrength , 0.3 radio_property backfacelighting , "unlit|lit|{reverselit}" double_property diffusestrength , 0.6 @@ -3144,6 +3231,17 @@ double_property specularexponent , 10 double_property specularstrength , 0.9 array_property vertexnormals u , Matrix () + // hidden properties for limit computation + row_vector_property xlim hlr , Matrix () + row_vector_property ylim hlr , Matrix () + row_vector_property zlim hlr , Matrix () + row_vector_property clim hlr , Matrix () + row_vector_property alim hlr , Matrix () + bool_property xliminclude hl , "on" + bool_property yliminclude hl , "on" + bool_property zliminclude hl , "on" + bool_property climinclude hlg , "on" + bool_property aliminclude hlg , "on" END_PROPERTIES protected: @@ -3165,9 +3263,39 @@ private: void update_normals (void); - void update_xdata (void) { update_normals (); } - void update_ydata (void) { update_normals (); } - void update_zdata (void) { update_normals (); } + void update_xdata (void) + { + update_normals (); + set_xlim (xdata.get_limits ()); + } + + void update_ydata (void) + { + update_normals (); + set_ylim (ydata.get_limits ()); + } + + void update_zdata (void) + { + update_normals (); + set_zlim (zdata.get_limits ()); + } + + void update_cdata (void) + { + if (cdatamapping_is ("scaled")) + set_clim (cdata.get_limits ()); + else + clim = cdata.get_limits (); + } + + void update_alphadata (void) + { + if (alphadatamapping_is ("scaled")) + set_alim (alphadata.get_limits ()); + else + alim = alphadata.get_limits (); + } void update_normalmode (void) { update_normals (); }