WGENodeMaskCallback.h

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 #include "../WExportWGE.h"
00036 
00037 /**
00038  * This callback is useful to en-/disable nodes using the node mask based on properties. In contrast to WGEManagedGroupNode, this callback can be
00039  * added to every kind of node.
00040  * 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
00041  * inactive too. To reactive the node again, the callback somehow needs to remember which node it has deactivated. This is done during the first
00042  * deactivation in update traversal.
00043  */
00044 class WGE_EXPORT WGENodeMaskCallback: public osg::NodeCallback
00045 {
00046 public:
00047     /**
00048      * Creates new instance.
00049      *
00050      * \param flag the bool property which controls activation.
00051      */
00052     explicit WGENodeMaskCallback( boost::shared_ptr< WBoolFlag > flag );
00053 
00054     /**
00055      * Destructor.
00056      */
00057     virtual ~WGENodeMaskCallback();
00058 
00059      /**
00060      * This operator gets called by OSG every update cycle.
00061      *
00062      * \param node the osg node
00063      * \param nv the node visitor
00064      */
00065     virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
00066 
00067 protected:
00068 private:
00069     /**
00070      * The flag controlling the node mask
00071      */
00072      boost::shared_ptr< WBoolFlag > m_flag;
00073 
00074     /**
00075      * The subscription to the change signal of m_flag.
00076      */
00077     boost::signals2::connection m_connection;
00078 
00079     /**
00080      * This connection gets established during the deactivation in operator() to ensure re-activation.
00081      */
00082     boost::signals2::connection m_reactivateConnection;
00083 
00084     /**
00085      * The type of signal used to reactivate the signal.
00086      */
00087     typedef boost::signals2::signal< void() >  ReactivateSignal;
00088 
00089     /**
00090      * The reactivation signal.
00091      */
00092     ReactivateSignal m_reactivateSignal;
00093 
00094     /**
00095      * Gets called if m_flag changes. This handles activation of the node.
00096      */
00097     virtual void activate();
00098 };
00099 
00100 #endif  // WGENODEMASKCALLBACK_H
00101 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends