2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2004-09-03 03:10:33 +08:00
|
|
|
// note, callback is responsible for scenegraph traversal so
|
|
|
|
// should always include call traverse(node,nv) to ensure
|
2002-04-15 21:15:48 +08:00
|
|
|
// 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
|
|
|
|
|