2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
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;
|
|
|
|
|
2003-01-03 04:10:04 +08:00
|
|
|
class SG_EXPORT NodeCallback : public virtual Object {
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
public :
|
|
|
|
|
|
|
|
|
2002-03-15 00:01:21 +08:00
|
|
|
NodeCallback(){}
|
2003-01-03 04:10:04 +08:00
|
|
|
|
|
|
|
NodeCallback(const NodeCallback&,const CopyOp&):
|
|
|
|
_nestedCallback(_nestedCallback) {}
|
|
|
|
|
|
|
|
|
|
|
|
META_Object(osg,NodeCallback)
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Callback method call by the NodeVisitor when visiting a node.*/
|
2002-04-15 21:15:48 +08:00
|
|
|
virtual void operator()(Node* node, NodeVisitor* nv)
|
|
|
|
{
|
|
|
|
// note, callback is repsonsible for scenegraph traversal so
|
|
|
|
// should always include call the traverse(node,nv) to ensure
|
|
|
|
// that the rest of cullbacks and the scene graph are traversed.
|
|
|
|
traverse(node,nv);
|
|
|
|
}
|
2001-09-20 07:41:39 +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);
|
|
|
|
|
|
|
|
void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; }
|
|
|
|
NodeCallback* getNestedCallback() { return _nestedCallback.get(); }
|
|
|
|
|
|
|
|
inline void addNestedCallback(NodeCallback* nc)
|
|
|
|
{
|
|
|
|
if (nc)
|
|
|
|
{
|
|
|
|
if (_nestedCallback.valid())
|
|
|
|
{
|
|
|
|
nc->addNestedCallback(_nestedCallback.get());
|
|
|
|
_nestedCallback = nc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_nestedCallback = nc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void removeNestedCallback(NodeCallback* nc)
|
|
|
|
{
|
|
|
|
if (nc)
|
|
|
|
{
|
|
|
|
if (_nestedCallback==nc)
|
|
|
|
{
|
2002-07-28 20:49:01 +08:00
|
|
|
_nestedCallback = _nestedCallback->getNestedCallback();
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2003-01-03 04:10:04 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
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
|
|
|
|
|