OpenWalnut  1.3.1
WPickHandler.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 WPICKHANDLER_H
26 #define WPICKHANDLER_H
27 
28 #include <string>
29 
30 #include <boost/signals2/signal.hpp>
31 
32 #include <osgViewer/View>
33 
34 
35 #include "WPickInfo.h"
36 
37 
38 /**
39  * Class to handle events with a pick.
40  *
41  * The handler ignores any geometry whose name starts with an underscore ("_").
42  */
43 class WPickHandler: public osgGA::GUIEventHandler
44 {
45 public:
46  /**
47  * Constructor that initalizes members with sensible defaults.
48  */
49  WPickHandler();
50 
51  /**
52  * Constructor that initalizes members with sensible defaults and sets the name of the viewer
53  *
54  * \param viewerName name of the viewer
55  */
56  explicit WPickHandler( std::string viewerName );
57 
58  /**
59  * Deals with the events found by the osg.
60  * \param ea Event class for storing Keyboard, mouse and window events.
61  * \param aa Interface by which GUIEventHandlers may request actions of the GUI system
62  *
63  * \return true if the event was handled.
64  */
65  bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
66 
67  /**
68  * Send a pick signal with the pick information as string
69  * \param view the view in which we pick.
70  * \param ea Event class for storing Keyboard, mouse and window events.
71  */
72  virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea );
73 
74  /**
75  * Send a pick signal with the string "unpick"
76  */
77  virtual void unpick();
78 
79  /**
80  * Gives information about the picked object.
81  *
82  * \return info object for this hit
83  */
85 
86  /**
87  * returns the m_pickSignal to for registering to it.
88  */
89  boost::signals2::signal1< void, WPickInfo >* getPickSignal();
90 
91  /**
92  * setter for paint mode
93  * \param mode the paint mode
94  */
95  void setPaintMode( int mode );
96 
97 protected:
98  /**
99  * Virtual destructor needed because of virtual function.
100  *
101  * This desctructor is protected to avoid accidentally deleting
102  * a instance of WPickHandler.
103  * This follows the philosophy of OSG to avoid problems in multithreaded
104  * environments, since these pointers are used deep in the OSG where
105  * a deletion could cause a segfault.
106  */
107  virtual ~WPickHandler();
108 
109  WPickInfo m_hitResult; //!< Textual representation of the result of a pick.
110  WPickInfo m_startPick; //!< indicates what was first picked. Should be "" after unpick.
111  bool m_shift; //!< is shift pressed?
112  bool m_ctrl; //!< is ctrl pressed?
113  std::string m_viewerName; //!< which viewer sends the signal
114  int m_paintMode; //!< the paint mode
115  WPickInfo::WMouseButton m_mouseButton; //!< stores mouse button that initiated the pick
116 
117  bool m_inPickMode; //!< if true, the pick handler currently is in pick mode.
118 
119  int32_t m_scrollWheel; //!< the virtual value of the scrollwheel
120 
121 private:
122  /**
123  * Sets the current modifiers to the provided pickInfo
124  *
125  * \param pickInfo This pickInfo will be updated.
126  */
127  void updatePickInfoModifierKeys( WPickInfo* pickInfo );
128 
129  boost::signals2::signal1< void, WPickInfo > m_pickSignal; //!< One can register to this signal to receive pick events.
130 };
131 
132 #endif // WPICKHANDLER_H