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