WPickHandler.h 3.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WPICKHANDLER_H
#define WPICKHANDLER_H

#include <sstream>
#include <string>

31 32
#include <boost/signals2/signal.hpp>

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>

#include <osg/Material>
#include <osg/Geode>
#include <osg/BlendFunc>
#include <osg/Depth>
#include <osg/Projection>
#include <osg/MatrixTransform>
#include <osg/Camera>
#include <osg/io_utils>
#include <osg/ShapeDrawable>
#include <osgText/Text>

49 50
#include "../math/WPosition.h"

51 52 53 54 55 56
/**
 * class to handle events with a pick
 */
class WPickHandler: public osgGA::GUIEventHandler
{
public:
57 58 59
    /**
     * Deals with the events found by the osg.
     */
60 61
    bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );

62 63 64
    /**
     * Send a pick signal with the pick information as string
     */
65
    virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea );
66 67 68 69

    /**
     * Send a pick signal with the string "unpick"
     */
70
    virtual void unpick();
71

72 73 74
    /**
     * Gives information about the picked object.
     */
schurade's avatar
schurade committed
75
    std::string getHitResult();
76

77 78 79 80 81
    /**
     * Returns the position where the first object was picked.
     */
    wmath::WPosition getHitPosition();

82 83 84 85 86
    /**
     * returns the m_pickSignal to for registering to it.
     */
    boost::signals2::signal1< void, std::string >* getPickSignal();

87
protected:
88 89 90 91 92 93 94 95 96 97 98
    /**
     * Virtual destructor needed because of virtual function.
     *
     * This desctructor is protected to avoid accidentally deleting
     * a instance of WPickHandler.
     * This follows the philosophy of OSG to avoid problems in multithreaded
     * environments, since these pointers are used deep in the OSG where
     * an deletion could cause a segfault.
     */
    virtual ~WPickHandler();

99
    std::string m_hitResult; //!< Textual representation of the result of a pick.
100
    wmath::WPosition m_hitPosGlobal; //!< Global coordinates of the first hit of the pick.
101 102 103

private:
    boost::signals2::signal1<void, std::string > m_pickSignal; //!< One can register to this signal to receive pick events.
104 105 106
};

#endif  // WPICKHANDLER_H