From 10c43a30524dfb74233c5a0f62a9cf6a932fc326 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 15 Nov 2012 12:11:19 +0000 Subject: [PATCH] Moved PropertyManager related classes out from SlideEventHandler into their own dedicated header/source file. --- include/osgPresentation/PropertyManager | 90 ++++++++++++++++++++ src/osgPresentation/CMakeLists.txt | 2 + src/osgPresentation/PropertyManager.cpp | 56 ++++++++++++ src/osgPresentation/SlideEventHandler.cpp | 61 ++++--------- src/osgPresentation/SlideShowConstructor.cpp | 35 ++++++++ 5 files changed, 198 insertions(+), 46 deletions(-) create mode 100644 include/osgPresentation/PropertyManager create mode 100644 src/osgPresentation/PropertyManager.cpp diff --git a/include/osgPresentation/PropertyManager b/include/osgPresentation/PropertyManager new file mode 100644 index 000000000..93bcc5f27 --- /dev/null +++ b/include/osgPresentation/PropertyManager @@ -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 +#include +#include +#include + +#include + +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 and gets the value. + * To use this template method you need to include the osg/ValueObject header.*/ + template + bool getProperty(const std::string& name, T& value) const + { + OpenThreads::ScopedLock lock(_mutex); + return getUserValue(name, value); + } + + /** Convinience method that creates the osg::TemplateValueObject 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 + void setProperty(const std::string& name, const T& value) + { + OpenThreads::ScopedLock 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 _imageSequence; + osg::ref_ptr _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; +}; + +} + +#endif diff --git a/src/osgPresentation/CMakeLists.txt b/src/osgPresentation/CMakeLists.txt index 43bbcd4e9..cd677fb62 100644 --- a/src/osgPresentation/CMakeLists.txt +++ b/src/osgPresentation/CMakeLists.txt @@ -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 diff --git a/src/osgPresentation/PropertyManager.cpp b/src/osgPresentation/PropertyManager.cpp new file mode 100644 index 000000000..2e27be6fe --- /dev/null +++ b/src/osgPresentation/PropertyManager.cpp @@ -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 + +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<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; +} diff --git a/src/osgPresentation/SlideEventHandler.cpp b/src/osgPresentation/SlideEventHandler.cpp index 472659177..e75d47649 100644 --- a/src/osgPresentation/SlideEventHandler.cpp +++ b/src/osgPresentation/SlideEventHandler.cpp @@ -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<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(_callback.get()); osg::AnimationPathCallback* apc = dynamic_cast(_callback.get()); osgUtil::TransformCallback* tc = dynamic_cast(_callback.get()); AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); @@ -295,20 +254,26 @@ struct CallbackOperator : public ObjectOperator OSG_INFO<<"apc->setPause("<setPause(pause); } - if (tc) + else if (tc) { OSG_INFO<<"tc->setPause("<setPause(pause); } - if (amc) + else if (amc) { OSG_INFO<<"amc->setPause("<setPause(pause); } + else if (nc) + { + OSG_NOTICE<<"Need to pause callback : "<className()<(_callback.get()); osg::AnimationPathCallback* apc = dynamic_cast(_callback.get()); osgUtil::TransformCallback* tc = dynamic_cast(_callback.get()); AnimationMaterialCallback* amc = dynamic_cast(_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 : "<className()<(node); + osgVolume::Locator* locator = tile ? tile->getLocator() : 0; + if (tile) + { + OSG_NOTICE<<"VolumeTileCallback : Have locator matrix "<getTransform()<setUpdateCallback(new VolumeTileCallback()); ModelData modelData;