2013-09-04 18:33:11 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield
|
2013-08-22 03:54:03 +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
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGPRESENTATION_GROUP
|
|
|
|
#define OSGPRESENTATION_GROUP 1
|
|
|
|
|
|
|
|
#include <osg/MatrixTransform>
|
2013-09-04 18:33:11 +08:00
|
|
|
#include <osg/ValueObject>
|
|
|
|
#include <osgPresentation/Action>
|
2013-08-22 03:54:03 +08:00
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
#include <sstream>
|
2013-08-22 03:54:03 +08:00
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
namespace osgPresentation {
|
2013-09-03 18:17:06 +08:00
|
|
|
|
|
|
|
typedef std::pair< osg::ref_ptr<osg::Object>, std::string> ObjectDescription;
|
|
|
|
typedef std::list< ObjectDescription > PropertyList;
|
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
/** META_Presentation macro define the standard clone, isSameKindAs, className
|
|
|
|
* and accept methods. Use when subclassing from Node to make it
|
|
|
|
* more convenient to define the required pure virtual methods.*/
|
|
|
|
#define META_Presentation(name) \
|
|
|
|
virtual osg::Object* cloneType() const { return new name (); } \
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
|
|
|
virtual const char* className() const { return #name; } \
|
|
|
|
virtual const char* libraryName() const { return "osgPresentation"; } \
|
|
|
|
virtual void accept(osg::NodeVisitor& nv) \
|
|
|
|
{ \
|
|
|
|
if (nv.validNodeMask(*this)) \
|
|
|
|
{ \
|
|
|
|
nv.pushOntoNodePath(this); \
|
|
|
|
osgPresentation::Action* action = dynamic_cast<osgPresentation::Action*>(&nv); \
|
|
|
|
if (action) action->apply(*this); \
|
|
|
|
else nv.apply(*this); \
|
|
|
|
nv.popFromNodePath(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2013-08-22 03:54:03 +08:00
|
|
|
/** osgPresentation::Group
|
|
|
|
*/
|
|
|
|
class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
Group() {}
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
|
|
|
Group(const Group& group,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::MatrixTransform(group,copyop) {}
|
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
META_Presentation(Group);
|
2013-08-22 03:54:03 +08:00
|
|
|
|
|
|
|
/** Convinience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
|
|
|
|
* To use this template method you need to include the osg/ValueObject header.*/
|
|
|
|
template<typename T>
|
|
|
|
bool getProperty(const std::string& name, T& value) const
|
|
|
|
{
|
|
|
|
return getUserValue(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Convinience method that creates the osg::TemplateValueObject<T> to store the
|
|
|
|
* specified value and adds it as a named UserObject.
|
|
|
|
* To use this template method you need to include the osg/ValueObject header. */
|
|
|
|
template<typename T>
|
|
|
|
void setProperty(const std::string& name, const T& value)
|
|
|
|
{
|
2013-09-20 00:18:20 +08:00
|
|
|
setUserValue(name, value);
|
2013-08-22 03:54:03 +08:00
|
|
|
}
|
|
|
|
|
2013-09-04 18:33:11 +08:00
|
|
|
/** Check for named Property, if it doesn't exist on this object check parents recursively for instances.*/
|
|
|
|
osg::Object* getPropertyObject(const std::string& name, bool checkParents = true);
|
|
|
|
|
|
|
|
/** Check for name Property, and convert to desired template value where possible. */
|
|
|
|
template<typename T>
|
|
|
|
bool getPropertyValue(const std::string& name, T& value, bool checkParents = true)
|
|
|
|
{
|
|
|
|
osg::Object* object = getPropertyObject(name, checkParents);
|
|
|
|
if (!object) return false;
|
|
|
|
|
|
|
|
typedef osg::TemplateValueObject<T> UserValueObject;
|
|
|
|
const UserValueObject* uvo = dynamic_cast<const UserValueObject*>(object);
|
|
|
|
if (uvo)
|
|
|
|
{
|
|
|
|
value = uvo->getValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::StringValueObject* svo = dynamic_cast<osg::StringValueObject*>(object);
|
|
|
|
if (svo)
|
|
|
|
{
|
|
|
|
std::istringstream str(svo->getValue());
|
|
|
|
str >> value;
|
|
|
|
return !str.fail();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:17:06 +08:00
|
|
|
/** Get all types of Properties supported by Presentation Object type, return true if the Properties are supported, false otherwise.*/
|
|
|
|
virtual bool getSupportedProperties(PropertyList&) { return false; }
|
|
|
|
|
|
|
|
|
2013-08-22 03:54:03 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Group() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|