Mercurial > hg > octave-nkf
changeset 6841:9cee629fe20c
[project @ 2007-08-29 17:31:45 by jwe]
author | jwe |
---|---|
date | Wed, 29 Aug 2007 17:31:45 +0000 |
parents | 2f17d5556756 |
children | 8d3426c59a88 |
files | src/ChangeLog src/base-list.h src/graphics.cc src/graphics.h |
diffstat | 4 files changed, 185 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,24 @@ +2007-08-29 John W. Eaton <jwe@octave.org> + + * base-list.h (octave_base_list::remove): Implement our own + remove_if function here. + +2007-08-28 John W. Eaton <jwe@octave.org> + + * graphics.h (OCTAVE_GRAPHICS_PROPERTY_INTERNAL): Also define + set_X functions for properties. + (base_properties): Move class definition before definition of + base_graphics_object class. Provide forward declaration of + base_graphics_object prior to definition of base_properties. + (base_graphics_object::get_properties): New virtual function. + (graphics_object::get_properties, root_figure::get_properties, + figure::get_properties, axes::get_properties, + line::get_properties, text::get_properties, image::get_properties, + patch::get_properties, surface::get_properties): New functions. + (root_figure::properties, figure::properties, axes::properties, + line::properties, text::properties, image::properties, + patch::properties, surface::properties): Data member now private. + 2007-08-27 John W. Eaton <jwe@octave.org> * load-path.cc (load_path::do_find_file): Also files with non
--- a/src/base-list.h +++ b/src/base-list.h @@ -42,7 +42,27 @@ iterator erase (iterator pos) { return lst.erase (pos); } template <class P> - void remove_if (P pred) { lst.remove_if (pred); } + void remove_if (P pred) + { + // We would like to simply call + // + // lst.remove_if (pred); + // + // but the Sun Studio compiler chokes on that. + // + // FIXME -- this kluge should be removed at some point. + + iterator b = lst.begin (); + iterator e = lst.end (); + while (b != e) + { + iterator n = b; + n++; + if (pred (*b)) + erase (b); + b = n; + } + } void clear (void) { lst.clear (); }
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -2878,6 +2878,60 @@ return ret; } +DEFUN (doit, args, , "") +{ + octave_value retval; + + if (args.length () == 1) + { + graphics_handle h = octave_NaN; + + double val = args(0).double_value (); + + if (! error_state) + { + h = gh_manager::lookup (val); + + if (! xisnan (h)) + { + graphics_object obj = gh_manager::get_object (h); + + if (obj.isa ("line")) + { + line::line_properties& lp + = dynamic_cast<line::line_properties&> (obj.get_properties ()); + retval = lp.get_xdata (); + Matrix m (1, 5); + m(0) = 0; + m(1) = 1; + m(2) = 2; + m(3) = 3; + m(4) = 4; + lp.set_xdata (m); + m(0) = 0; + m(1) = 1; + m(2) = 0.2; + m(3) = 0.8; + m(4) = 0.4; + lp.set_ydata (m); + + feval ("__request_drawnow__"); + } + else + error ("doit: looking for line"); + } + else + error ("doit: invalid graphics object (= %g)", val); + } + else + error ("doit: invalid graphics object"); + } + else + print_usage (); + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/graphics.h +++ b/src/graphics.h @@ -40,8 +40,11 @@ #include "ov.h" #define OCTAVE_GRAPHICS_PROPERTY_INTERNAL(TAG, TYPE, NAME) \ - private: TAG TYPE NAME; \ - public: const TYPE& get_ ## NAME () const { return NAME; } \ + private: \ + TAG TYPE NAME; \ + public: \ + const TYPE& get_ ## NAME () const { return NAME; } \ + void set_ ## NAME (const TYPE& val) { NAME = val; mark_modified (); } \ private: #define OCTAVE_GRAPHICS_PROPERTY(TYPE, NAME) \ @@ -421,6 +424,57 @@ // --------------------------------------------------------------------- +class base_graphics_object; + +class base_properties +{ +public: + base_properties (const std::string& t = "unknown", + const graphics_handle& mh = octave_NaN, + const graphics_handle& p = octave_NaN) + : type (t), __modified__ (true), __myhandle__ (mh), parent (p), + children () { } + + virtual ~base_properties (void) { } + + virtual std::string graphics_object_name (void) const { return "unknonwn"; } + + void mark_modified (void); + + void override_defaults (base_graphics_object& obj); + + // Look through DEFAULTS for properties with given CLASS_NAME, and + // apply them to the current object with set (virtual method). + + void set_from_list (base_graphics_object& obj, property_list& defaults); + + virtual void set (const property_name&, const octave_value&) { } + + graphics_handle get_parent (void) const { return parent; } + + void remove_child (const graphics_handle& h); + + void adopt (const graphics_handle& h) + { + octave_idx_type n = children.numel (); + children.resize (1, n+1); + children(n) = h; + } + + void set_parent (const octave_value& val); + + void reparent (const graphics_handle& new_parent) { parent = new_parent; } + + virtual void delete_children (void); + +protected: + std::string type; + bool __modified__; + graphics_handle __myhandle__; + graphics_handle parent; + Matrix children; +}; + class base_graphics_object { public: @@ -511,6 +565,13 @@ error ("base_graphics_object::default: invalid graphics object"); } + virtual base_properties& get_properties (void) + { + static base_properties properties; + error ("base_graphics_object::get_properties: invalid graphics object"); + return properties; + } + virtual bool valid_object (void) const { return false; } virtual std::string type (void) const { return "unknown"; } @@ -625,6 +686,8 @@ bool isa (const std::string& go_name) const { return rep->isa (go_name); } + base_properties& get_properties (void) { return rep->get_properties (); } + bool valid_object (void) const { return rep->valid_object (); } operator bool (void) const { return rep->valid_object (); } @@ -633,55 +696,6 @@ base_graphics_object *rep; }; -class base_properties -{ -public: - base_properties (const std::string& t = "unknown", - const graphics_handle& mh = octave_NaN, - const graphics_handle& p = octave_NaN) - : type (t), __modified__ (true), __myhandle__ (mh), parent (p), - children () { } - - virtual ~base_properties (void) { } - - virtual std::string graphics_object_name (void) const = 0; - - void mark_modified (void); - - void override_defaults (base_graphics_object& obj); - - // Look through DEFAULTS for properties with given CLASS_NAME, and - // apply them to the current object with set (virtual method). - - void set_from_list (base_graphics_object& obj, property_list& defaults); - - virtual void set (const property_name& name, const octave_value& val) = 0; - - graphics_handle get_parent (void) const { return parent; } - - void remove_child (const graphics_handle& h); - - void adopt (const graphics_handle& h) - { - octave_idx_type n = children.numel (); - children.resize (1, n+1); - children(n) = h; - } - - void set_parent (const octave_value& val); - - void reparent (const graphics_handle& new_parent) { parent = new_parent; } - - virtual void delete_children (void); - -protected: - std::string type; - bool __modified__; - graphics_handle __myhandle__; - graphics_handle parent; - Matrix children; -}; - // --------------------------------------------------------------------- class root_figure : public base_graphics_object @@ -713,6 +727,7 @@ static std::string go_name; }; +private: root_figure_properties properties; public: @@ -808,6 +823,8 @@ void reparent (const graphics_handle& np) { properties.reparent (np); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } private: @@ -854,6 +871,7 @@ static std::string go_name; }; +private: figure_properties properties; public: @@ -935,6 +953,8 @@ void reparent (const graphics_handle& np) { properties.reparent (np); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } private: @@ -1023,6 +1043,7 @@ static std::string go_name; }; +private: axes_properties properties; public: @@ -1106,6 +1127,8 @@ void reparent (const graphics_handle& np) { properties.reparent (np); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } private: @@ -1154,6 +1177,7 @@ static std::string go_name; }; +private: line_properties properties; public: @@ -1204,6 +1228,8 @@ void reparent (const graphics_handle& h) { properties.reparent (h); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } }; @@ -1240,6 +1266,7 @@ static std::string go_name; }; +private: text_properties properties; public: @@ -1290,6 +1317,8 @@ void reparent (const graphics_handle& h) { properties.reparent (h); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } }; @@ -1323,6 +1352,7 @@ static std::string go_name; }; +private: image_properties properties; public: @@ -1373,6 +1403,8 @@ void reparent (const graphics_handle& h) { properties.reparent (h); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } }; @@ -1416,6 +1448,7 @@ static std::string go_name; }; +private: patch_properties properties; public: @@ -1466,6 +1499,8 @@ void reparent (const graphics_handle& h) { properties.reparent (h); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } }; @@ -1500,6 +1535,7 @@ static std::string go_name; }; +private: surface_properties properties; public: @@ -1550,6 +1586,8 @@ void reparent (const graphics_handle& h) { properties.reparent (h); } + base_properties& get_properties (void) { return properties; } + bool valid_object (void) const { return true; } };