OpenWalnut  1.5.0dev
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 unpickString
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  * \return the m_pickSignal to for registering to it.
88  */
89  boost::signals2::signal< void( WPickInfo ) >* getPickSignal();
90 
91  /**
92  * setter for paint mode
93  * \deprecated use variant taking bool instead.
94  * \param mode the paint mode
95  */
96  OW_API_DEPRECATED void setPaintMode( int mode );
97 
98  /**
99  * Set in paint mode
100  * \param paintMode Should we switch to paint mode?
101  */
102  void setPaintMode( bool paintMode );
103 
104  static const std::string unpickString; //!< The string indicating picking has stopped.
105 
106 protected:
107  /**
108  * Virtual destructor needed because of virtual function.
109  *
110  * This desctructor is protected to avoid accidentally deleting
111  * an instance of WPickHandler.
112  * This follows the philosophy of OSG to avoid problems in multithreaded
113  * environments, since these pointers are used deep in the OSG where
114  * a deletion could cause a segfault.
115  */
116  virtual ~WPickHandler();
117 
118 private:
119  /**
120  * Sets the current modifiers to the provided pickInfo
121  *
122  * \param pickInfo This pickInfo will be updated.
123  */
124  void updatePickInfoModifierKeys( WPickInfo* pickInfo );
125 
126  boost::signals2::signal< void( WPickInfo ) > m_pickSignal; //!< One can register to this signal to receive pick events.
127 
128  WPickInfo m_hitResult; //!< Textual representation of the result of a pick.
129  WPickInfo m_startPick; //!< indicates what was first picked. Should be "" after unpick.
130  bool m_shift; //!< is shift pressed?
131  bool m_ctrl; //!< is ctrl pressed?
132  std::string m_viewerName; //!< which viewer sends the signal
133  bool m_paintMode; //!< the paint mode
134  WPickInfo::WMouseButton m_mouseButton; //!< stores mouse button that initiated the pick
135 
136  bool m_inPickMode; //!< if true, the pick handler currently is in pick mode.
137 
138  int32_t m_scrollWheel; //!< the virtual value of the scrollwheel
139 };
140 
141 #endif // WPICKHANDLER_H
Class to handle events with a pick.
Definition: WPickHandler.h:44
virtual void unpick()
Send a pick signal with the unpickString.
WPickInfo m_hitResult
Textual representation of the result of a pick.
Definition: WPickHandler.h:128
WPickHandler()
Constructor that initalizes members with sensible defaults.
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Deals with the events found by the osg.
bool m_shift
is shift pressed?
Definition: WPickHandler.h:130
WPickInfo m_startPick
indicates what was first picked. Should be "" after unpick.
Definition: WPickHandler.h:129
boost::signals2::signal< void(WPickInfo) > m_pickSignal
One can register to this signal to receive pick events.
Definition: WPickHandler.h:126
std::string m_viewerName
which viewer sends the signal
Definition: WPickHandler.h:132
void updatePickInfoModifierKeys(WPickInfo *pickInfo)
Sets the current modifiers to the provided pickInfo.
bool m_ctrl
is ctrl pressed?
Definition: WPickHandler.h:131
boost::signals2::signal< void(WPickInfo) > * getPickSignal()
virtual void pick(osgViewer::View *view, const osgGA::GUIEventAdapter &ea)
Send a pick signal with the pick information as string.
WPickInfo::WMouseButton m_mouseButton
stores mouse button that initiated the pick
Definition: WPickHandler.h:134
bool m_inPickMode
if true, the pick handler currently is in pick mode.
Definition: WPickHandler.h:136
WPickInfo getHitResult()
Gives information about the picked object.
int32_t m_scrollWheel
the virtual value of the scrollwheel
Definition: WPickHandler.h:138
virtual ~WPickHandler()
Virtual destructor needed because of virtual function.
bool m_paintMode
the paint mode
Definition: WPickHandler.h:133
OW_API_DEPRECATED void setPaintMode(int mode)
setter for paint mode
static const std::string unpickString
The string indicating picking has stopped.
Definition: WPickHandler.h:104
Encapsulates info for pick action.
Definition: WPickInfo.h:42
WMouseButton
Different types of mouse buttons.
Definition: WPickInfo.h:60
#define OW_API_DEPRECATED
In order to mark functions for the compiler as deprecated we need to put this before each deprecated ...
Definition: WDefines.h:44