/* -*-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 #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; }; class PropertyAnimation : public osg::NodeCallback { public: PropertyAnimation(): _firstTime(DBL_MAX), _latestTime(0.0), _pause(false), _pauseTime(0.0) {} void setPropertyManager(PropertyManager* pm) { _pm = pm; } PropertyManager* getPropertyManager() const { return _pm.get(); } typedef std::map > KeyFrameMap; KeyFrameMap& getKeyFrameMap() { return _keyFrameMap; } const KeyFrameMap& getKeyFrameMap() const { return _keyFrameMap; } void addKeyFrame(double time, osg::UserDataContainer* udc) { _keyFrameMap[time] = udc; } virtual void reset(); void setPause(bool pause); bool getPause() const { return _pause; } double getAnimationTime() const; virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); virtual void update(); protected: osg::ref_ptr _pm; KeyFrameMap _keyFrameMap; double _firstTime; double _latestTime; bool _pause; double _pauseTime; }; 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