OpenWalnut  1.5.0dev
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 <memory>
29 
30 #include <boost/signals2.hpp>
31 #include <osg/Camera>
32 #include <osg/Node>
33 
34 #include "core/common/WFlag.h"
35 #include "core/kernel/WKernel.h"
36 
37 /**
38  * This callback is useful to en-/disable nodes using the node mask based on properties. In contrast to WGEManagedGroupNode, this callback can be
39  * added to every kind of node.
40  * 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
41  * inactive too. To reactive the node again, the callback somehow needs to remember which node it has deactivated. This is done during the first
42  * deactivation in update traversal.
43  */
44 class WGENodeMaskCallback: public osg::NodeCallback
45 {
46 public:
47  /**
48  * Creates new instance.
49  *
50  * \param flag the bool property which controls activation.
51  */
52  explicit WGENodeMaskCallback( std::shared_ptr< WBoolFlag > flag );
53 
54  /**
55  * Destructor.
56  */
57  virtual ~WGENodeMaskCallback();
58 
59  /**
60  * This operator gets called by OSG every update cycle.
61  *
62  * \param node the osg node
63  * \param nv the node visitor
64  */
65  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
66 
67 protected:
68 private:
69  /**
70  * The flag controlling the node mask
71  */
72  std::shared_ptr< WBoolFlag > m_flag;
73 
74  /**
75  * The subscription to the change signal of m_flag.
76  */
77  boost::signals2::connection m_connection;
78 
79  /**
80  * This connection gets established during the deactivation in operator() to ensure re-activation.
81  */
82  boost::signals2::connection m_reactivateConnection;
83 
84  /**
85  * The type of signal used to reactivate the signal.
86  */
87  typedef boost::signals2::signal< void() > ReactivateSignal;
88 
89  /**
90  * The reactivation signal.
91  */
93 
94  /**
95  * Gets called if m_flag changes. This handles activation of the node.
96  */
97  virtual void activate();
98 };
99 
100 #endif // WGENODEMASKCALLBACK_H
101 
This callback is useful to en-/disable nodes using the node mask based on properties.
virtual ~WGENodeMaskCallback()
Destructor.
boost::signals2::connection m_connection
The subscription to the change signal of m_flag.
ReactivateSignal m_reactivateSignal
The reactivation signal.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
This operator gets called by OSG every update cycle.
WGENodeMaskCallback(std::shared_ptr< WBoolFlag > flag)
Creates new instance.
virtual void activate()
Gets called if m_flag changes.
boost::signals2::signal< void() > ReactivateSignal
The type of signal used to reactivate the signal.
std::shared_ptr< WBoolFlag > m_flag
The flag controlling the node mask.
boost::signals2::connection m_reactivateConnection
This connection gets established during the deactivation in operator() to ensure re-activation.