2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 07:41:39 +08:00
|
|
|
#ifndef OSG_NODECALLBACK
|
|
|
|
#define OSG_NODECALLBACK 1
|
|
|
|
|
2003-01-03 04:10:04 +08:00
|
|
|
#include <osg/Object>
|
2002-06-14 03:34:27 +08:00
|
|
|
#include <osg/ref_ptr>
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
class Node;
|
|
|
|
class NodeVisitor;
|
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT NodeCallback : public virtual Object {
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
public :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 07:41:39 +08:00
|
|
|
|
2002-03-15 00:01:21 +08:00
|
|
|
NodeCallback(){}
|
2003-01-03 04:10:04 +08:00
|
|
|
|
2004-10-02 06:05:40 +08:00
|
|
|
NodeCallback(const NodeCallback& nc,const CopyOp&):
|
|
|
|
_nestedCallback(nc._nestedCallback) {}
|
2003-01-03 04:10:04 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-28 17:14:04 +08:00
|
|
|
META_Object(osg,NodeCallback);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Callback method called by the NodeVisitor when visiting a node.*/
|
2002-04-15 21:15:48 +08:00
|
|
|
virtual void operator()(Node* node, NodeVisitor* nv)
|
2012-03-22 01:36:20 +08:00
|
|
|
{
|
2004-09-03 03:10:33 +08:00
|
|
|
// note, callback is responsible for scenegraph traversal so
|
2006-12-20 01:16:14 +08:00
|
|
|
// they must call traverse(node,nv) to ensure that the
|
|
|
|
// scene graph subtree (and associated callbacks) are traversed.
|
2002-04-15 21:15:48 +08:00
|
|
|
traverse(node,nv);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-11-12 06:32:59 +08:00
|
|
|
/** Call any nested callbacks and then traverse the scene graph. */
|
|
|
|
void traverse(Node* node,NodeVisitor* nv);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-11-12 06:32:59 +08:00
|
|
|
void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; }
|
|
|
|
NodeCallback* getNestedCallback() { return _nestedCallback.get(); }
|
2004-12-17 09:06:33 +08:00
|
|
|
const NodeCallback* getNestedCallback() const { return _nestedCallback.get(); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-11-12 06:32:59 +08:00
|
|
|
inline void addNestedCallback(NodeCallback* nc)
|
|
|
|
{
|
|
|
|
if (nc)
|
|
|
|
{
|
|
|
|
if (_nestedCallback.valid())
|
|
|
|
{
|
2013-06-10 18:37:08 +08:00
|
|
|
_nestedCallback->addNestedCallback(nc);
|
2001-11-12 06:32:59 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_nestedCallback = nc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-11-12 06:32:59 +08:00
|
|
|
inline void removeNestedCallback(NodeCallback* nc)
|
|
|
|
{
|
|
|
|
if (nc)
|
|
|
|
{
|
|
|
|
if (_nestedCallback==nc)
|
|
|
|
{
|
2013-06-10 18:37:08 +08:00
|
|
|
ref_ptr<NodeCallback> new_nested_callback = _nestedCallback->getNestedCallback();
|
|
|
|
_nestedCallback->setNestedCallback(0);
|
|
|
|
_nestedCallback = new_nested_callback;
|
2001-11-12 06:32:59 +08:00
|
|
|
}
|
2002-07-28 20:49:01 +08:00
|
|
|
else if (_nestedCallback.valid())
|
2001-11-12 06:32:59 +08:00
|
|
|
{
|
|
|
|
_nestedCallback->removeNestedCallback(nc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-01-10 17:25:42 +08:00
|
|
|
public:
|
2001-09-20 07:41:39 +08:00
|
|
|
|
2001-11-12 06:32:59 +08:00
|
|
|
ref_ptr<NodeCallback> _nestedCallback;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-01-03 04:10:04 +08:00
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-01-03 04:10:04 +08:00
|
|
|
virtual ~NodeCallback() {}
|
2001-09-20 07:41:39 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
} // namespace
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|