Added Action class NodeVisitor that supports osgPresentation nodes.
This commit is contained in:
88
include/osgPresentation/Action
Normal file
88
include/osgPresentation/Action
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGPRESENTATION_ACTION
|
||||
#define OSGPRESENTATION_ACTION 1
|
||||
|
||||
#include <osgPresentation/Export>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
namespace osgPresentation
|
||||
{
|
||||
|
||||
// forward declare osgPresention nodes
|
||||
class Group;
|
||||
|
||||
class Element;
|
||||
class Text;
|
||||
class Volume;
|
||||
class Model;
|
||||
class Image;
|
||||
class Movie;
|
||||
|
||||
class Section;
|
||||
class Layer;
|
||||
class Slide;
|
||||
class Presentation;
|
||||
|
||||
/** Action base class that is a NodeVistor that addes osgPresentation node support.*/
|
||||
class OSGPRESENTATION_EXPORT Action : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
Action(osg::NodeVisitor::TraversalMode traversalMode=osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN):
|
||||
osg::NodeVisitor(traversalMode) {}
|
||||
|
||||
virtual void apply(osgPresentation::Group& group);
|
||||
|
||||
virtual void apply(osgPresentation::Element& element);
|
||||
virtual void apply(osgPresentation::Text& text);
|
||||
virtual void apply(osgPresentation::Volume& volume);
|
||||
virtual void apply(osgPresentation::Model& model);
|
||||
virtual void apply(osgPresentation::Image& image);
|
||||
virtual void apply(osgPresentation::Movie& movie);
|
||||
|
||||
virtual void apply(osgPresentation::Section& section);
|
||||
virtual void apply(osgPresentation::Layer& layer);
|
||||
virtual void apply(osgPresentation::Slide& slide);
|
||||
virtual void apply(osgPresentation::Presentation& presentation);
|
||||
};
|
||||
|
||||
|
||||
struct OSGPRESENTATION_EXPORT LoadAction : public Action
|
||||
{
|
||||
void apply(osgPresentation::Element& element);
|
||||
};
|
||||
|
||||
struct OSGPRESENTATION_EXPORT UnloadAction : public Action
|
||||
{
|
||||
void apply(osgPresentation::Element& element);
|
||||
};
|
||||
|
||||
struct OSGPRESENTATION_EXPORT ResetAction : public Action
|
||||
{
|
||||
void apply(osgPresentation::Element& element);
|
||||
};
|
||||
|
||||
struct OSGPRESENTATION_EXPORT PauseAction : public Action
|
||||
{
|
||||
void apply(osgPresentation::Element& element);
|
||||
};
|
||||
|
||||
struct OSGPRESENTATION_EXPORT PlayAction : public Action
|
||||
{
|
||||
void apply(osgPresentation::Element& element);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Audio : public osgPresentation::Element
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Audio(const Audio& audio,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(audio,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Audio);
|
||||
META_Presentation(Audio);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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
|
||||
@@ -31,9 +31,7 @@ class OSGPRESENTATION_EXPORT Element : public osgPresentation::Group
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Element(const Element& element,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(element,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Element);
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
META_Presentation(Element);
|
||||
|
||||
/** Load the subgraph implementation of the element.*/
|
||||
virtual bool load() { return false; }
|
||||
@@ -45,12 +43,6 @@ class OSGPRESENTATION_EXPORT Element : public osgPresentation::Group
|
||||
virtual bool loaded() const { return getNumChildren()!=0; }
|
||||
|
||||
|
||||
/** Do updates as part of the update traversal.*/
|
||||
virtual void updateTraversal(osgUtil::UpdateVisitor& uv);
|
||||
|
||||
/** Do updates as part of the event traversal.*/
|
||||
virtual void eventTraversal(osgGA::EventVisitor& ev);
|
||||
|
||||
/** Enter the element for the first time, starting any animations, movies, audio etc..*/
|
||||
virtual void enter() {}
|
||||
|
||||
@@ -58,6 +50,15 @@ class OSGPRESENTATION_EXPORT Element : public osgPresentation::Group
|
||||
virtual void leave() {}
|
||||
|
||||
|
||||
/** Pause any animatios, videos, audio etc.*/
|
||||
virtual void pause() {}
|
||||
|
||||
/** Play any animatios, videos, audio etc.*/
|
||||
virtual void play() {}
|
||||
|
||||
/** Reset any animations, vidoes, audio etc. back to the begininng.*/
|
||||
virtual void reset() {}
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~Element() {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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
|
||||
@@ -15,14 +15,37 @@
|
||||
#define OSGPRESENTATION_GROUP 1
|
||||
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osgPresentation/Export>
|
||||
#include <osg/ValueObject>
|
||||
#include <osgPresentation/Action>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace osgPresentation {
|
||||
|
||||
|
||||
typedef std::pair< osg::ref_ptr<osg::Object>, std::string> ObjectDescription;
|
||||
typedef std::list< ObjectDescription > PropertyList;
|
||||
|
||||
/** 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(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/** osgPresentation::Group
|
||||
*/
|
||||
class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform
|
||||
@@ -34,7 +57,7 @@ class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform
|
||||
/** 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) {}
|
||||
|
||||
META_Node(osgPresentation, Group);
|
||||
META_Presentation(Group);
|
||||
|
||||
/** 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.*/
|
||||
@@ -53,6 +76,34 @@ class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform
|
||||
return setUserValue(name, value);
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
/** 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; }
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Image : public osgPresentation::Element
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Image(const Image& image,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(image,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Image);
|
||||
META_Presentation(Image);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Layer : public osgPresentation::Group
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Layer(const Layer& layer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(layer,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Layer);
|
||||
META_Presentation(Layer);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Model : public osgPresentation::Element
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Model(const Model& model,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(model,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Model);
|
||||
META_Presentation(Model);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Movie : public osgPresentation::Element
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Movie(const Movie& movie,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(movie,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Movie);
|
||||
META_Presentation(Movie);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Presentation : public osgPresentation::Group
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Presentation(const Presentation& presentation,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(presentation,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Presentation);
|
||||
META_Presentation(Presentation);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Section : public osgPresentation::Group
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Section(const Section& section,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(section,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Section);
|
||||
META_Presentation(Section);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Slide : public osgPresentation::Group
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Slide(const Slide& slide,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(slide,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Slide);
|
||||
META_Presentation(Slide);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Text : public osgPresentation::Element
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Text(const Text& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(text,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Text);
|
||||
META_Presentation(Text);
|
||||
|
||||
/** load the text subgraph.*/
|
||||
virtual bool load();
|
||||
|
||||
@@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Volume : public osgPresentation::Element
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Volume(const Volume& volume,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(volume,copyop) {}
|
||||
|
||||
META_Node(osgPresentation, Volume);
|
||||
META_Presentation(Volume);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
Reference in New Issue
Block a user