OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGENODEMASKCALLBACK_H 00026 #define WGENODEMASKCALLBACK_H 00027 00028 #include <boost/signals2.hpp> 00029 00030 #include <osg/Camera> 00031 #include <osg/Node> 00032 00033 #include "../../common/WFlag.h" 00034 00035 /** 00036 * This callback is useful to en-/disable nodes using the node mask based on properties. In contrast to WGEManagedGroupNode, this callback can be 00037 * added to every kind of node. 00038 * DO NOT use one instance of this class for multiple nodes. The problem is not very obvious. If a node gets deactivated, its node callback is 00039 * inactive too. To reactive the node again, the callback somehow needs to remember which node it has deactivated. This is done during the first 00040 * deactivation in update traversal. 00041 */ 00042 class WGENodeMaskCallback: public osg::NodeCallback 00043 { 00044 public: 00045 /** 00046 * Creates new instance. 00047 * 00048 * \param flag the bool property which controls activation. 00049 */ 00050 explicit WGENodeMaskCallback( boost::shared_ptr< WBoolFlag > flag ); 00051 00052 /** 00053 * Destructor. 00054 */ 00055 virtual ~WGENodeMaskCallback(); 00056 00057 /** 00058 * This operator gets called by OSG every update cycle. 00059 * 00060 * \param node the osg node 00061 * \param nv the node visitor 00062 */ 00063 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ); 00064 00065 protected: 00066 private: 00067 /** 00068 * The flag controlling the node mask 00069 */ 00070 boost::shared_ptr< WBoolFlag > m_flag; 00071 00072 /** 00073 * The subscription to the change signal of m_flag. 00074 */ 00075 boost::signals2::connection m_connection; 00076 00077 /** 00078 * This connection gets established during the deactivation in operator() to ensure re-activation. 00079 */ 00080 boost::signals2::connection m_reactivateConnection; 00081 00082 /** 00083 * The type of signal used to reactivate the signal. 00084 */ 00085 typedef boost::signals2::signal< void() > ReactivateSignal; 00086 00087 /** 00088 * The reactivation signal. 00089 */ 00090 ReactivateSignal m_reactivateSignal; 00091 00092 /** 00093 * Gets called if m_flag changes. This handles activation of the node. 00094 */ 00095 virtual void activate(); 00096 }; 00097 00098 #endif // WGENODEMASKCALLBACK_H 00099