Added Action class NodeVisitor that supports osgPresentation nodes.

This commit is contained in:
Robert Osfield 2013-09-04 10:33:11 +00:00
parent 3c106e4dd7
commit 9f5e131203
19 changed files with 354 additions and 79 deletions

View File

@ -29,32 +29,28 @@
#include <osg/NodeVisitor> #include <osg/NodeVisitor>
class PrintSupportedProperties : public osg::NodeVisitor class PrintSupportedProperties : public osgPresentation::Action
{ {
public: public:
PrintSupportedProperties() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} PrintSupportedProperties() :
osgPresentation::Action(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
void apply(osg::Node& node) void apply(osgPresentation::Group& group)
{ {
osgPresentation::Group* pres_group = dynamic_cast<osgPresentation::Group*>(&node); OSG_NOTICE<<"osgPresentation object : "<<group.className()<<std::endl;
if (pres_group) osgPresentation::PropertyList properties;
if (group.getSupportedProperties(properties))
{ {
OSG_NOTICE<<"osgPresentation object : "<<pres_group->className()<<std::endl; for(osgPresentation::PropertyList::iterator itr = properties.begin();
osgPresentation::PropertyList properties; itr != properties.end();
if (pres_group->getSupportedProperties(properties)) ++itr)
{ {
for(osgPresentation::PropertyList::iterator itr = properties.begin(); osgPresentation::ObjectDescription& od = *itr;
itr != properties.end(); OSG_NOTICE<<" "<<od.first->className()<<" : "<<od.first->getName()<<", description = "<<od.second<<std::endl;
++itr)
{
osgPresentation::ObjectDescription& od = *itr;
OSG_NOTICE<<" "<<od.first->className()<<" : "<<od.first->getName()<<", description = "<<od.second<<std::endl;
}
} }
} }
traverse(node); traverse(group);
} }
}; };
@ -141,6 +137,7 @@ int main(int argc, char** argv)
osg::ref_ptr<osgPresentation::Layer> layer = new osgPresentation::Layer; osg::ref_ptr<osgPresentation::Layer> layer = new osgPresentation::Layer;
osg::ref_ptr<osgPresentation::Group> group = new osgPresentation::Group; osg::ref_ptr<osgPresentation::Group> group = new osgPresentation::Group;
osg::ref_ptr<osgPresentation::Element> element = new osgPresentation::Element; osg::ref_ptr<osgPresentation::Element> element = new osgPresentation::Element;
osg::ref_ptr<osgPresentation::Element> text = new osgPresentation::Text;
presentation->addChild(slide.get()); presentation->addChild(slide.get());
slide->addChild(layer.get()); slide->addChild(layer.get());
//layer->addChild(element.get()); //layer->addChild(element.get());
@ -148,15 +145,24 @@ int main(int argc, char** argv)
group->addChild(element.get()); group->addChild(element.get());
element->addChild(model.get()); element->addChild(model.get());
group->addChild(new osgPresentation::Model); group->addChild(new osgPresentation::Model);
group->addChild(new osgPresentation::Text); group->addChild(text.get());
group->addChild(new osgPresentation::Audio); group->addChild(new osgPresentation::Audio);
group->addChild(new osgPresentation::Movie); group->addChild(new osgPresentation::Movie);
group->addChild(new osgPresentation::Volume); group->addChild(new osgPresentation::Volume);
text->setProperty("string",std::string("This is a first test"));
text->setProperty("font",std::string("times.ttf"));
text->setProperty("character_size",2.2);
text->setProperty("width",std::string("103.2"));
PrintSupportedProperties psp; PrintSupportedProperties psp;
presentation->accept(psp); presentation->accept(psp);
osgPresentation::LoadAction load;
presentation->accept( load );
viewer.setSceneData( presentation.get() ); viewer.setSceneData( presentation.get() );

View 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

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Audio : public osgPresentation::Element
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Audio(const Audio& audio,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(audio,copyop) {}
META_Node(osgPresentation, Audio); META_Presentation(Audio);
protected : protected :

View File

@ -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 * 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 * 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. */ /** 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) {} Element(const Element& element,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(element,copyop) {}
META_Node(osgPresentation, Element); META_Presentation(Element);
virtual void traverse(osg::NodeVisitor& nv);
/** Load the subgraph implementation of the element.*/ /** Load the subgraph implementation of the element.*/
virtual bool load() { return false; } virtual bool load() { return false; }
@ -45,12 +43,6 @@ class OSGPRESENTATION_EXPORT Element : public osgPresentation::Group
virtual bool loaded() const { return getNumChildren()!=0; } 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..*/ /** Enter the element for the first time, starting any animations, movies, audio etc..*/
virtual void enter() {} virtual void enter() {}
@ -58,6 +50,15 @@ class OSGPRESENTATION_EXPORT Element : public osgPresentation::Group
virtual void leave() {} 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 : protected :
virtual ~Element() {} virtual ~Element() {}

View File

@ -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 * 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 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
@ -15,14 +15,37 @@
#define OSGPRESENTATION_GROUP 1 #define OSGPRESENTATION_GROUP 1
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
#include <osgPresentation/Export> #include <osg/ValueObject>
#include <osgPresentation/Action>
#include <sstream>
namespace osgPresentation { namespace osgPresentation {
typedef std::pair< osg::ref_ptr<osg::Object>, std::string> ObjectDescription; typedef std::pair< osg::ref_ptr<osg::Object>, std::string> ObjectDescription;
typedef std::list< ObjectDescription > PropertyList; 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 /** osgPresentation::Group
*/ */
class OSGPRESENTATION_EXPORT Group : public osg::MatrixTransform 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. */ /** 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) {} 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. /** 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.*/ * 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); 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.*/ /** 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; } virtual bool getSupportedProperties(PropertyList&) { return false; }

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Image : public osgPresentation::Element
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Image(const Image& image,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(image,copyop) {}
META_Node(osgPresentation, Image); META_Presentation(Image);
protected : protected :

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Layer : public osgPresentation::Group
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Layer(const Layer& layer,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(layer,copyop) {}
META_Node(osgPresentation, Layer); META_Presentation(Layer);
protected : protected :

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Model : public osgPresentation::Element
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Model(const Model& model,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(model,copyop) {}
META_Node(osgPresentation, Model); META_Presentation(Model);
protected : protected :

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Movie : public osgPresentation::Element
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Movie(const Movie& movie,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(movie,copyop) {}
META_Node(osgPresentation, Movie); META_Presentation(Movie);
protected : protected :

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Presentation : public osgPresentation::Group
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Presentation(const Presentation& presentation,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(presentation,copyop) {}
META_Node(osgPresentation, Presentation); META_Presentation(Presentation);
protected : protected :

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Section : public osgPresentation::Group
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Section(const Section& section,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(section,copyop) {}
META_Node(osgPresentation, Section); META_Presentation(Section);
protected : protected :

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Slide : public osgPresentation::Group
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Slide(const Slide& slide,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Group(slide,copyop) {}
META_Node(osgPresentation, Slide); META_Presentation(Slide);
protected : protected :

View File

@ -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 * 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 * 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. */ /** 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) {} 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.*/ /** load the text subgraph.*/
virtual bool load(); virtual bool load();

View File

@ -29,7 +29,7 @@ class OSGPRESENTATION_EXPORT Volume : public osgPresentation::Element
/** Copy constructor using CopyOp to manage deep vs shallow copy. */ /** 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) {} Volume(const Volume& volume,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osgPresentation::Element(volume,copyop) {}
META_Node(osgPresentation, Volume); META_Presentation(Volume);
protected : protected :

View File

@ -0,0 +1,120 @@
/* -*-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.
*/
#include <osgPresentation/Action>
#include <osgPresentation/Group>
#include <osgPresentation/Element>
#include <osgPresentation/Text>
#include <osgPresentation/Model>
#include <osgPresentation/Volume>
#include <osgPresentation/Movie>
#include <osgPresentation/Image>
#include <osgPresentation/Section>
#include <osgPresentation/Layer>
#include <osgPresentation/Slide>
#include <osgPresentation/Presentation>
using namespace osgPresentation;
//////////////////////////////////////////////////////////////////////////////////
//
// Action base class
//
void Action::apply(osgPresentation::Group& group)
{
OSG_NOTICE<<"LoadAction::apply()"<<std::endl;
osg::NodeVisitor::apply(group);
}
void Action::apply(osgPresentation::Element& element)
{
apply(static_cast<osgPresentation::Group&>(element));
}
void Action::apply(osgPresentation::Text& text)
{
apply(static_cast<osgPresentation::Element&>(text));
}
void Action::apply(osgPresentation::Volume& volume)
{
apply(static_cast<osgPresentation::Element&>(volume));
}
void Action::apply(osgPresentation::Model& model)
{
apply(static_cast<osgPresentation::Element&>(model));
}
void Action::apply(osgPresentation::Image& image)
{
apply(static_cast<osgPresentation::Element&>(image));
}
void Action::apply(osgPresentation::Movie& movie)
{
apply(static_cast<osgPresentation::Element&>(movie));
}
void Action::apply(osgPresentation::Section& section)
{
apply(static_cast<osgPresentation::Group&>(section));
}
void Action::apply(osgPresentation::Layer& layer)
{
apply(static_cast<osgPresentation::Group&>(layer));
}
void Action::apply(osgPresentation::Slide& slide)
{
apply(static_cast<osgPresentation::Group&>(slide));
}
void Action::apply(osgPresentation::Presentation& presentation)
{
apply(static_cast<osgPresentation::Group&>(presentation));
}
/////////////////////////////////////////////////////////////////////////
//
// Specific Action implementations
//
void LoadAction::apply(osgPresentation::Element& element)
{
OSG_NOTICE<<"LoadAction::apply()"<<std::endl;
element.load();
}
void UnloadAction::apply(osgPresentation::Element& element)
{
element.unload();
}
void ResetAction::apply(osgPresentation::Element& element)
{
element.reset();
}
void PauseAction::apply(osgPresentation::Element& element)
{
element.pause();
}
void PlayAction::apply(osgPresentation::Element& element)
{
element.play();
}

View File

@ -8,6 +8,7 @@ ENDIF()
SET(LIB_NAME osgPresentation) SET(LIB_NAME osgPresentation)
SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
SET(TARGET_H SET(TARGET_H
${HEADER_PATH}/Action
${HEADER_PATH}/Export ${HEADER_PATH}/Export
${HEADER_PATH}/Cursor ${HEADER_PATH}/Cursor
${HEADER_PATH}/Group ${HEADER_PATH}/Group
@ -37,6 +38,7 @@ SET(TARGET_H
# FIXME: For OS X, need flag for Framework or dylib # FIXME: For OS X, need flag for Framework or dylib
SET(TARGET_SRC SET(TARGET_SRC
Action.cpp
Cursor.cpp Cursor.cpp
Group.cpp Group.cpp
Element.cpp Element.cpp

View File

@ -16,37 +16,3 @@
using namespace osgPresentation; using namespace osgPresentation;
void Element::traverse(osg::NodeVisitor& nv)
{
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
{
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv);
if (uv)
{
updateTraversal(*uv);
return;
}
}
else if (nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
if (ev)
{
eventTraversal(*ev);
return;
}
}
osgPresentation::Group::traverse(nv);
}
void Element::updateTraversal(osgUtil::UpdateVisitor& uv)
{
OSG_NOTICE<<"Element::updateTraversal()"<<std::endl;
osgPresentation::Group::traverse(uv);
}
void Element::eventTraversal(osgGA::EventVisitor& ev)
{
OSG_NOTICE<<"Element::eventTraversal()"<<std::endl;
osgPresentation::Group::traverse(ev);
}

View File

@ -11,8 +11,31 @@
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
#include <osg/UserDataContainer>
#include <osgPresentation/Group> #include <osgPresentation/Group>
using namespace osgPresentation; using namespace osgPresentation;
/** Nothing to implement yet...*/ class PropertyVisitor : public osg::NodeVisitor
{
public:
PropertyVisitor(const std::string& name) : _name(name), _object(0) {}
void apply(osg::Node& node)
{
osg::UserDataContainer* udc = node.getUserDataContainer();
_object = udc ? udc->getUserObject(_name) : 0;
if (!_object) traverse(node);
};
std::string _name;
osg::Object* _object;
};
osg::Object* Group::getPropertyObject(const std::string& name, bool checkParents)
{
PropertyVisitor pv(name);
if (checkParents) pv.setTraversalMode(osg::NodeVisitor::TRAVERSE_PARENTS);
accept(pv);
return pv._object;
}

View File

@ -20,7 +20,25 @@ using namespace osgPresentation;
bool Text::load() bool Text::load()
{ {
OSG_NOTICE<<"Not implemented yet"<<std::endl; OSG_NOTICE<<"Text::load() Not implemented yet"<<std::endl;
std::string value;
getPropertyValue("string", value);
std::string font("arial.ttf");
getPropertyValue("font", font);
double width = 1.0;
getPropertyValue("width", width);
double character_size = 0.06;
getPropertyValue("character_size", character_size);
OSG_NOTICE<<"Text : string = "<<value<<std::endl;
OSG_NOTICE<<" font = "<<font<<std::endl;
OSG_NOTICE<<" width = "<<width<<std::endl;
OSG_NOTICE<<" character_size = "<<character_size<<std::endl;
return false; return false;
} }