OpenWalnut 1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPICKHANDLER_H 00026 #define WPICKHANDLER_H 00027 00028 #include <sstream> 00029 #include <string> 00030 00031 #include <boost/signals2/signal.hpp> 00032 00033 #include <osgUtil/Optimizer> 00034 #include <osgDB/ReadFile> 00035 #include <osgViewer/Viewer> 00036 #include <osgViewer/CompositeViewer> 00037 00038 #include <osg/Material> 00039 #include <osg/Geode> 00040 #include <osg/BlendFunc> 00041 #include <osg/Depth> 00042 #include <osg/Projection> 00043 #include <osg/MatrixTransform> 00044 #include <osg/Camera> 00045 #include <osg/io_utils> 00046 #include <osg/ShapeDrawable> 00047 #include <osgText/Text> 00048 00049 #include "WPickInfo.h" 00050 #include "WExportWGE.h" 00051 00052 /** 00053 * Class to handle events with a pick. 00054 * 00055 * The handler ignores any geometry whose name starts with an underscore ("_"). 00056 */ 00057 class WGE_EXPORT WPickHandler: public osgGA::GUIEventHandler 00058 { 00059 public: 00060 00061 /** 00062 * Constructor that initalizes members with sensible defaults. 00063 */ 00064 WPickHandler(); 00065 00066 /** 00067 * Constructor that initalizes members with sensible defaults and sets the name of the viewer 00068 * 00069 * \param viewerName name of the viewer 00070 */ 00071 explicit WPickHandler( std::string viewerName ); 00072 00073 /** 00074 * Deals with the events found by the osg. 00075 * \param ea Event class for storing Keyboard, mouse and window events. 00076 * \param aa Interface by which GUIEventHandlers may request actions of the GUI system 00077 * 00078 * \return true if the event was handled. 00079 */ 00080 bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); 00081 00082 /** 00083 * Send a pick signal with the pick information as string 00084 * \param view the view in which we pick. 00085 * \param ea Event class for storing Keyboard, mouse and window events. 00086 */ 00087 virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea ); 00088 00089 /** 00090 * Send a pick signal with the string "unpick" 00091 */ 00092 virtual void unpick(); 00093 00094 /** 00095 * Gives information about the picked object. 00096 * 00097 * \return info object for this hit 00098 */ 00099 WPickInfo getHitResult(); 00100 00101 /** 00102 * returns the m_pickSignal to for registering to it. 00103 */ 00104 boost::signals2::signal1< void, WPickInfo >* getPickSignal(); 00105 00106 /** 00107 * setter for paint mode 00108 * \param mode the paint mode 00109 */ 00110 void setPaintMode( int mode ); 00111 00112 protected: 00113 /** 00114 * Virtual destructor needed because of virtual function. 00115 * 00116 * This desctructor is protected to avoid accidentally deleting 00117 * a instance of WPickHandler. 00118 * This follows the philosophy of OSG to avoid problems in multithreaded 00119 * environments, since these pointers are used deep in the OSG where 00120 * a deletion could cause a segfault. 00121 */ 00122 virtual ~WPickHandler(); 00123 00124 WPickInfo m_hitResult; //!< Textual representation of the result of a pick. 00125 WPickInfo m_startPick; //!< indicates what was first picked. Should be "" after unpick. 00126 bool m_shift; //!< is shift pressed? 00127 bool m_ctrl; //!< is ctrl pressed? 00128 std::string m_viewerName; //!< which viewer sends the signal 00129 int m_paintMode; //!< the paint mode 00130 WPickInfo::WMouseButton m_mouseButton; //!< stores mouse button that initiated the pick 00131 00132 00133 private: 00134 /** 00135 * Sets the current modifiers to the provided pickInfo 00136 * 00137 * \param pickInfo This pickInfo will be updated. 00138 */ 00139 void updatePickInfoModifierKeys( WPickInfo* pickInfo ); 00140 00141 boost::signals2::signal1< void, WPickInfo > m_pickSignal; //!< One can register to this signal to receive pick events. 00142 }; 00143 00144 #endif // WPICKHANDLER_H