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