From 2810d9bba6279aa830f863b4f41ba73f3b400491 Mon Sep 17 00:00:00 2001 From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Mon, 5 Jul 2010 09:07:34 +0000 Subject: [PATCH] added scene.RemoveAll() method git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2510 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gfx/doc/scene.rst | 7 ++++++- modules/gfx/pymod/export_scene.cc | 1 + modules/gfx/src/gfx_node.cc | 12 ++++++++++++ modules/gfx/src/gfx_node.hh | 2 ++ modules/gfx/src/scene.cc | 6 ++++++ modules/gfx/src/scene.hh | 4 ++++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/gfx/doc/scene.rst b/modules/gfx/doc/scene.rst index a31836aba..d1eb368c3 100644 --- a/modules/gfx/doc/scene.rst +++ b/modules/gfx/doc/scene.rst @@ -214,7 +214,12 @@ It is interesting to note that the offset from center (`trans`) is given in rota :param obj: :type obj: :class:`GfxNode` - + + .. method:: RemoveAll() + + Remove all objects from the scene + + .. method:: RenderGL() Renders the scene. diff --git a/modules/gfx/pymod/export_scene.cc b/modules/gfx/pymod/export_scene.cc index e66235742..1f9b2c459 100644 --- a/modules/gfx/pymod/export_scene.cc +++ b/modules/gfx/pymod/export_scene.cc @@ -127,6 +127,7 @@ void export_Scene() .def("GetSelectionMode",&Scene::GetSelectionMode) .def("SetBlur",&Scene::SetBlur) .def("BlurSnapshot",&Scene::BlurSnapshot) + .def("RemoveAll", &Scene::RemoveAll) .def("SetShadow",&Scene::SetShadow) .def("SetShadowQuality",&Scene::SetShadowQuality) .def("AttachObserver",&Scene::AttachObserver) diff --git a/modules/gfx/src/gfx_node.cc b/modules/gfx/src/gfx_node.cc index f3a61c11e..93f900980 100644 --- a/modules/gfx/src/gfx_node.cc +++ b/modules/gfx/src/gfx_node.cc @@ -16,6 +16,7 @@ // along with this library; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ +#include <boost/bind.hpp> #include <ost/dyn_cast.hh> #include "gfx_node.hh" #include "gfx_object.hh" @@ -113,6 +114,17 @@ void GfxNode::Remove(GfxObjP obj) node_vector_.erase(it); } } +using boost::bind; +void GfxNode::RemoveAll() +{ + GfxNodeVector v=node_vector_; + node_vector_.clear(); + for (GfxNodeVector::iterator i=v.begin(), e=v.end(); i!=e; ++i) { + if (GfxObjP o=dyn_cast<GfxObj>(*i)) { + Scene::Instance().NotifyObservers(bind(&SceneObserver::NodeRemoved, _1, o)); + } + } +} void GfxNode::Add(GfxNodeP node) { diff --git a/modules/gfx/src/gfx_node.hh b/modules/gfx/src/gfx_node.hh index 0f7ecc2d0..c91df438b 100644 --- a/modules/gfx/src/gfx_node.hh +++ b/modules/gfx/src/gfx_node.hh @@ -68,6 +68,8 @@ class DLLEXPORT_OST_GFX GfxNode: public boost::enable_shared_from_this<GfxNode> // return name String GetName() const; + // remove all child nodes + void RemoveAll(); // change name void Rename(const String& name); diff --git a/modules/gfx/src/scene.cc b/modules/gfx/src/scene.cc index 46af47626..715d5ba21 100644 --- a/modules/gfx/src/scene.cc +++ b/modules/gfx/src/scene.cc @@ -607,6 +607,12 @@ void Scene::Remove(const GfxNodeP& go) this->RequestRedraw(); } +void Scene::RemoveAll() +{ + root_node_->RemoveAll(); + this->RequestRedraw(); +} + void Scene::Remove(const String& name) { FindNode fn(name); diff --git a/modules/gfx/src/scene.hh b/modules/gfx/src/scene.hh index d86e46a6a..f4763be55 100644 --- a/modules/gfx/src/scene.hh +++ b/modules/gfx/src/scene.hh @@ -281,6 +281,10 @@ class DLLEXPORT_OST_GFX Scene { void Remove(const GfxNodeP& go); /// remove graphical object from the scene void Remove(const String& name); + + /// \brief remove all objects from the scene + void RemoveAll(); + /// \brief rename an existing graphical object /// defunct for now bool Rename(const String& old_name, const String& new_name); -- GitLab