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

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

View File

@@ -16,37 +16,3 @@
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.
*/
#include <osg/UserDataContainer>
#include <osgPresentation/Group>
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()
{
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;
}