OpenWalnut  1.4.0
WGENodeMaskCallback.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGENODEMASKCALLBACK_H
26 #define WGENODEMASKCALLBACK_H
27 
28 #include <boost/signals2.hpp>
29 
30 #include <osg/Camera>
31 #include <osg/Node>
32 
33 #include "../../common/WFlag.h"
34 
35 /**
36  * This callback is useful to en-/disable nodes using the node mask based on properties. In contrast to WGEManagedGroupNode, this callback can be
37  * added to every kind of node.
38  * 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
39  * inactive too. To reactive the node again, the callback somehow needs to remember which node it has deactivated. This is done during the first
40  * deactivation in update traversal.
41  */
42 class WGENodeMaskCallback: public osg::NodeCallback
43 {
44 public:
45  /**
46  * Creates new instance.
47  *
48  * \param flag the bool property which controls activation.
49  */
50  explicit WGENodeMaskCallback( boost::shared_ptr< WBoolFlag > flag );
51 
52  /**
53  * Destructor.
54  */
55  virtual ~WGENodeMaskCallback();
56 
57  /**
58  * This operator gets called by OSG every update cycle.
59  *
60  * \param node the osg node
61  * \param nv the node visitor
62  */
63  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
64 
65 protected:
66 private:
67  /**
68  * The flag controlling the node mask
69  */
70  boost::shared_ptr< WBoolFlag > m_flag;
71 
72  /**
73  * The subscription to the change signal of m_flag.
74  */
75  boost::signals2::connection m_connection;
76 
77  /**
78  * This connection gets established during the deactivation in operator() to ensure re-activation.
79  */
80  boost::signals2::connection m_reactivateConnection;
81 
82  /**
83  * The type of signal used to reactivate the signal.
84  */
85  typedef boost::signals2::signal< void() > ReactivateSignal;
86 
87  /**
88  * The reactivation signal.
89  */
90  ReactivateSignal m_reactivateSignal;
91 
92  /**
93  * Gets called if m_flag changes. This handles activation of the node.
94  */
95  virtual void activate();
96 };
97 
98 #endif // WGENODEMASKCALLBACK_H
99 
boost::signals2::connection m_reactivateConnection
This connection gets established during the deactivation in operator() to ensure re-activation.
ReactivateSignal m_reactivateSignal
The reactivation signal.
WGENodeMaskCallback(boost::shared_ptr< WBoolFlag > flag)
Creates new instance.
virtual ~WGENodeMaskCallback()
Destructor.
boost::signals2::connection m_connection
The subscription to the change signal of m_flag.
virtual void activate()
Gets called if m_flag changes.
boost::signals2::signal< void() > ReactivateSignal
The type of signal used to reactivate the signal.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
This operator gets called by OSG every update cycle.
boost::shared_ptr< WBoolFlag > m_flag
The flag controlling the node mask.
This callback is useful to en-/disable nodes using the node mask based on properties.