1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
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.
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.
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/>.
23
//---------------------------------------------------------------------------
25
#ifndef WPICKHANDLER_H
26
#define WPICKHANDLER_H
31
#include <boost/signals2/signal.hpp>
33
#include <osgUtil/Optimizer>
34
#include <osgDB/ReadFile>
35
#include <osgViewer/Viewer>
36
#include <osgViewer/CompositeViewer>
38
#include <osg/Material>
40
#include <osg/BlendFunc>
42
#include <osg/Projection>
43
#include <osg/MatrixTransform>
45
#include <osg/io_utils>
46
#include <osg/ShapeDrawable>
47
#include <osgText/Text>
49
#include "WPickInfo.h"
50
#include "WExportWGE.h"
53
* Class to handle events with a pick.
55
* The handler ignores any geometry whose name starts with an underscore ("_").
57
class WGE_EXPORT WPickHandler: public osgGA::GUIEventHandler
62
* Constructor that initalizes members with sensible defaults.
67
* Constructor that initalizes members with sensible defaults and sets the name of the viewer
69
* \param viewerName name of the viewer
71
explicit WPickHandler( std::string viewerName );
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
78
* \return true if the event was handled.
80
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
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.
87
virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea );
90
* Send a pick signal with the string "unpick"
92
virtual void unpick();
95
* Gives information about the picked object.
97
* \return info object for this hit
99
WPickInfo getHitResult();
102
* returns the m_pickSignal to for registering to it.
104
boost::signals2::signal1< void, WPickInfo >* getPickSignal();
107
* setter for paint mode
108
* \param mode the paint mode
110
void setPaintMode( int mode );
114
* Virtual destructor needed because of virtual function.
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.
122
virtual ~WPickHandler();
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
135
* Sets the current modifiers to the provided pickInfo
137
* \param pickInfo This pickInfo will be updated.
139
void updatePickInfoModifierKeys( WPickInfo* pickInfo );
141
boost::signals2::signal1< void, WPickInfo > m_pickSignal; //!< One can register to this signal to receive pick events.
144
#endif // WPICKHANDLER_H