Moved PropertyManager related classes out from SlideEventHandler into their own dedicated header/source file.
This commit is contained in:
90
include/osgPresentation/PropertyManager
Normal file
90
include/osgPresentation/PropertyManager
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#ifndef PROPERTYMANAGER
|
||||
#define PROPERTYMANAGER 1
|
||||
|
||||
#include <osg/ValueObject>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/ImageSequence>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
|
||||
#include <osgPresentation/Export>
|
||||
|
||||
namespace osgPresentation
|
||||
{
|
||||
|
||||
class PropertyManager : protected osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
PropertyManager() {}
|
||||
PropertyManager(const PropertyManager& pm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(pm,copyop) {}
|
||||
|
||||
META_Object(osgPresentation, PropertyManager)
|
||||
|
||||
/** 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
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
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)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
return setUserValue(name, value);
|
||||
}
|
||||
|
||||
int ref() const { return osg::Referenced::ref(); }
|
||||
int unref() const { return osg::Referenced::unref(); }
|
||||
|
||||
protected:
|
||||
|
||||
mutable OpenThreads::Mutex _mutex;
|
||||
|
||||
};
|
||||
|
||||
struct OSGPRESENTATION_EXPORT ImageSequenceUpdateCallback : public osg::NodeCallback
|
||||
{
|
||||
ImageSequenceUpdateCallback(osg::ImageSequence* is, PropertyManager* pm, const std::string& propertyName):
|
||||
_imageSequence(is),
|
||||
_propertyManager(pm),
|
||||
_propertyName(propertyName) {}
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
|
||||
osg::ref_ptr<osg::ImageSequence> _imageSequence;
|
||||
osg::ref_ptr<PropertyManager> _propertyManager;
|
||||
std::string _propertyName;
|
||||
};
|
||||
|
||||
struct OSGPRESENTATION_EXPORT PropertyEventCallback : public osgGA::GUIEventHandler
|
||||
{
|
||||
PropertyEventCallback(PropertyManager* pm):
|
||||
_propertyManager(pm) {}
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
|
||||
|
||||
osg::ref_ptr<PropertyManager> _propertyManager;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,6 +12,7 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/AnimationMaterial
|
||||
${HEADER_PATH}/CompileSlideCallback
|
||||
${HEADER_PATH}/PickEventHandler
|
||||
${HEADER_PATH}/PropertyManager
|
||||
${HEADER_PATH}/KeyEventHandler
|
||||
${HEADER_PATH}/SlideEventHandler
|
||||
${HEADER_PATH}/SlideShowConstructor
|
||||
@@ -22,6 +23,7 @@ SET(TARGET_SRC
|
||||
AnimationMaterial.cpp
|
||||
CompileSlideCallback.cpp
|
||||
PickEventHandler.cpp
|
||||
PropertyManager.cpp
|
||||
KeyEventHandler.cpp
|
||||
SlideEventHandler.cpp
|
||||
SlideShowConstructor.cpp
|
||||
|
||||
56
src/osgPresentation/PropertyManager.cpp
Normal file
56
src/osgPresentation/PropertyManager.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/PropertyManager>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
void ImageSequenceUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
float x;
|
||||
if (_propertyManager->getProperty(_propertyName,x))
|
||||
{
|
||||
double xMin = -1.0;
|
||||
double xMax = 1.0;
|
||||
double position = ((double)x-xMin)/(xMax-xMin)*_imageSequence->getLength();
|
||||
|
||||
_imageSequence->seek(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_INFO<<"ImageSequenceUpdateCallback::operator() Could not find property : "<<_propertyName<<std::endl;
|
||||
}
|
||||
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// they must call traverse(node,nv) to ensure that the
|
||||
// scene graph subtree (and associated callbacks) are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
|
||||
bool PropertyEventCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
|
||||
bool mouseEvent = (ea.getEventType()==osgGA::GUIEventAdapter::MOVE ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::DRAG ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::PUSH ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::RELEASE);
|
||||
if(mouseEvent)
|
||||
{
|
||||
_propertyManager->setProperty("mouse.x",ea.getX());
|
||||
_propertyManager->setProperty("mouse.x_normalized",ea.getXnormalized());
|
||||
_propertyManager->setProperty("mouse.y",ea.getX());
|
||||
_propertyManager->setProperty("mouse.y_normalized",ea.getYnormalized());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -128,48 +128,6 @@ void LayerAttributes::callLeaveCallbacks(osg::Node* node)
|
||||
}
|
||||
}
|
||||
|
||||
void ImageSequenceUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
float x;
|
||||
if (_propertyManager->getProperty(_propertyName,x))
|
||||
{
|
||||
double xMin = -1.0;
|
||||
double xMax = 1.0;
|
||||
double position = ((double)x-xMin)/(xMax-xMin)*_imageSequence->getLength();
|
||||
|
||||
_imageSequence->seek(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_INFO<<"ImageSequenceUpdateCallback::operator() Could not find property : "<<_propertyName<<std::endl;
|
||||
}
|
||||
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// they must call traverse(node,nv) to ensure that the
|
||||
// scene graph subtree (and associated callbacks) are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
|
||||
bool PropertyEventCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
|
||||
bool mouseEvent = (ea.getEventType()==osgGA::GUIEventAdapter::MOVE ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::DRAG ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::PUSH ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::RELEASE);
|
||||
if(mouseEvent)
|
||||
{
|
||||
_propertyManager->setProperty("mouse.x",ea.getX());
|
||||
_propertyManager->setProperty("mouse.x_normalized",ea.getXnormalized());
|
||||
_propertyManager->setProperty("mouse.y",ea.getX());
|
||||
_propertyManager->setProperty("mouse.y_normalized",ea.getYnormalized());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct InteractiveImageSequenceOperator : public ObjectOperator
|
||||
{
|
||||
@@ -287,6 +245,7 @@ struct CallbackOperator : public ObjectOperator
|
||||
|
||||
virtual void setPause(SlideEventHandler*, bool pause)
|
||||
{
|
||||
osg::NodeCallback* nc = dynamic_cast<osg::NodeCallback*>(_callback.get());
|
||||
osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(_callback.get());
|
||||
osgUtil::TransformCallback* tc = dynamic_cast<osgUtil::TransformCallback*>(_callback.get());
|
||||
AnimationMaterialCallback* amc = dynamic_cast<AnimationMaterialCallback*>(_callback.get());
|
||||
@@ -295,20 +254,26 @@ struct CallbackOperator : public ObjectOperator
|
||||
OSG_INFO<<"apc->setPause("<<pause<<")"<<std::endl;
|
||||
apc->setPause(pause);
|
||||
}
|
||||
if (tc)
|
||||
else if (tc)
|
||||
{
|
||||
OSG_INFO<<"tc->setPause("<<pause<<")"<<std::endl;
|
||||
tc->setPause(pause);
|
||||
}
|
||||
if (amc)
|
||||
else if (amc)
|
||||
{
|
||||
OSG_INFO<<"amc->setPause("<<pause<<")"<<std::endl;
|
||||
amc->setPause(pause);
|
||||
}
|
||||
else if (nc)
|
||||
{
|
||||
OSG_NOTICE<<"Need to pause callback : "<<nc->className()<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual void reset(SlideEventHandler*)
|
||||
{
|
||||
osg::NodeCallback* nc = dynamic_cast<osg::NodeCallback*>(_callback.get());
|
||||
osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(_callback.get());
|
||||
osgUtil::TransformCallback* tc = dynamic_cast<osgUtil::TransformCallback*>(_callback.get());
|
||||
AnimationMaterialCallback* amc = dynamic_cast<AnimationMaterialCallback*>(_callback.get());
|
||||
@@ -317,14 +282,18 @@ struct CallbackOperator : public ObjectOperator
|
||||
apc->reset();
|
||||
apc->update(*_node);
|
||||
}
|
||||
if (tc)
|
||||
else if (tc)
|
||||
{
|
||||
}
|
||||
if (amc)
|
||||
else if (amc)
|
||||
{
|
||||
amc->reset();
|
||||
amc->update(*_node);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"Need to reset callback : "<<nc->className()<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2020,6 +2020,40 @@ bool DraggerVolumeTileCallback::receive(const osgManipulator::MotionCommand& com
|
||||
}
|
||||
}
|
||||
|
||||
class VolumeTileCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
|
||||
VolumeTileCallback()
|
||||
{
|
||||
}
|
||||
|
||||
VolumeTileCallback(const VolumeTileCallback& vtc,const osg::CopyOp& copyop):
|
||||
osg::NodeCallback(vtc,copyop) {}
|
||||
|
||||
META_Object(osgPresentation, VolumeTileCallback);
|
||||
|
||||
void reset() {}
|
||||
void update(osg::Node* node) {}
|
||||
void setPause(bool pause) {}
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
osgVolume::VolumeTile* tile = dynamic_cast<osgVolume::VolumeTile*>(node);
|
||||
osgVolume::Locator* locator = tile ? tile->getLocator() : 0;
|
||||
if (tile)
|
||||
{
|
||||
OSG_NOTICE<<"VolumeTileCallback : Have locator matrix "<<locator->getTransform()<<std::endl;
|
||||
}
|
||||
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// they must call traverse(node,nv) to ensure that the
|
||||
// scene graph subtree (and associated callbacks) are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& in_positionData, const VolumeData& volumeData)
|
||||
{
|
||||
// osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC
|
||||
@@ -2300,6 +2334,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
|
||||
model = group.get();
|
||||
}
|
||||
|
||||
tile->setUpdateCallback(new VolumeTileCallback());
|
||||
|
||||
|
||||
ModelData modelData;
|
||||
|
||||
Reference in New Issue
Block a user