OpenWalnut  1.4.0
WPickInfo.h
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 WPICKINFO_H
00026 #define WPICKINFO_H
00027 
00028 #include <stdint.h>
00029 
00030 #include <string>
00031 #include <utility>
00032 
00033 #include "../common/math/linearAlgebra/WVectorFixed.h"
00034 #include "../common/math/linearAlgebra/WPosition.h"
00035 #include "../common/WDefines.h"
00036 
00037 
00038 /**
00039  * Encapsulates info for pick action.
00040  */
00041 class WPickInfo
00042 {
00043 public:
00044     /**
00045      * Different types of modifier keys.
00046      */
00047     enum modifierKey
00048     {
00049         NONE,
00050         SHIFT,
00051         STRG,
00052         ALT,
00053         WIN
00054     };
00055 
00056     /**
00057      * Different types of mouse buttons.
00058      */
00059     typedef enum
00060     {
00061         NOMOUSE,
00062         MOUSE_LEFT,
00063         MOUSE_RIGHT,
00064         MOUSE_MIDDLE,
00065         MOUSE4,
00066         MOUSE5
00067     }
00068     WMouseButton;
00069 
00070     /**
00071      * Creates an object with the needed information.
00072      * \param name name of picked object
00073      * \param viewerName name of the viewer
00074      * \param pickPosition position where object was hit
00075      * \param pixelCoords pixel coordinates of the mouse
00076      * \param modKey relevant modifier key pressed during the pick
00077      * \param mButton mouse button that initiated the pick
00078      * \param pickNormal normal at position where object was hit. (0,0,0) means not set.
00079      * \param wheelValue the value of the scroll wheel
00080      */
00081     inline WPickInfo( std::string name,
00082                       std::string viewerName,
00083                       WPosition pickPosition,
00084                       std::pair< float, float > pixelCoords,
00085                       modifierKey modKey,
00086                       WMouseButton mButton = WPickInfo::MOUSE_LEFT,
00087                       WVector3d pickNormal = WVector3d(),
00088                       int32_t wheelValue = 0 );
00089 
00090     /**
00091      * Creates an object with the empty name, zero position and no modkey.
00092      */
00093     inline WPickInfo();
00094 
00095     /**
00096      * Get the modifier key associated with the pick
00097      *
00098      * \return the mod key
00099      */
00100     inline modifierKey getModifierKey() const;
00101 
00102     /**
00103      * Get the mouse button associated with the pick
00104      *
00105      * \return the mouse button
00106      */
00107     inline WMouseButton getMouseButton() const;
00108 
00109     /**
00110      * Set the modifier key associated with the pick
00111      * \param modKey new modifier key
00112      */
00113     inline void setModifierKey( const modifierKey& modKey );
00114 
00115     /**
00116      * Set the modifier key associated with the pick
00117      * \param mButton new mouse button
00118      */
00119     inline void setMouseButton( const WMouseButton& mButton );
00120 
00121 
00122     /**
00123      * Get name of picked object.
00124      *
00125      * \return object name
00126      */
00127     inline std::string getName() const;
00128 
00129     /**
00130      * Get name of the viewer.
00131      *
00132      * \return viewer name
00133      */
00134     inline std::string getViewerName() const;
00135 
00136     /**
00137      * Get position where object was hit.
00138      *
00139      * \return the pick position
00140      */
00141     inline WPosition getPickPosition() const;
00142 
00143     /**
00144      * Get normal at position where object was hit.
00145      *
00146      * \return pick normal
00147      */
00148     inline WVector3d getPickNormal() const;
00149 
00150     /**
00151      * Returns the picked pixel coordinates in screen-space.
00152      *
00153      * \return the coordinates
00154      */
00155     inline WVector2d getPickPixel() const;
00156 
00157     /**
00158      * Returns an integer denoting the wheel movement. If the value gets smaller, the wheel scrolled down.
00159      *
00160      * \return the value.
00161      */
00162     inline int32_t getScrollWheel() const;
00163 
00164     /**
00165      * Tests two pick infos for equality
00166      * \param rhs right hand side of comparison
00167      *
00168      * \return true if equal
00169      */
00170     inline bool operator==( WPickInfo rhs ) const;
00171 
00172     /**
00173      * Tests two pick infos for inequality
00174      *
00175      * \param rhs right hand side of comparison
00176      *
00177      * \return true if not equal
00178      */
00179     inline bool operator!=( WPickInfo rhs ) const;
00180 
00181 protected:
00182 private:
00183     std::string m_name; //!< name of picked object.
00184     std::string m_viewerName; //!< name of the viewer
00185     WPosition m_pickPosition; //!< position where object was hit.
00186     std::pair< float, float > m_pixelCoords; //!< Pixel coordinates of the mouse.
00187     modifierKey m_modKey; //!< modifier key associated with the pick
00188     WMouseButton m_mouseButton; //!< which mouse button was used for the pick
00189     WVector3d m_pickNormal; //!< normal at position where object was hit.
00190     int32_t m_scrollValue; //!< the scroll wheel value.
00191 };
00192 
00193 WPickInfo::WPickInfo( std::string name,
00194                       std::string viewerName,
00195                       WPosition pickPosition,
00196                       std::pair< float, float > pixelCoords,
00197                       modifierKey modKey,
00198                       WMouseButton mButton,
00199                       WVector3d pickNormal,
00200                       int32_t wheelValue ) :
00201     m_name( name ),
00202     m_viewerName( viewerName ),
00203     m_pickPosition( pickPosition ),
00204     m_pixelCoords( pixelCoords ),
00205     m_modKey( modKey ),
00206     m_mouseButton( mButton ),
00207     m_pickNormal( pickNormal ),
00208     m_scrollValue( wheelValue )
00209 {
00210 }
00211 
00212 WPickInfo::WPickInfo() :
00213     m_name( "" ),
00214     m_viewerName( "" ),
00215     m_pickPosition( WPosition() ),
00216     m_pixelCoords( std::make_pair( 0.0, 0.0 ) ),
00217     m_modKey( WPickInfo::NONE ),
00218     m_mouseButton( WPickInfo::MOUSE_LEFT ),
00219     m_scrollValue( 0 )
00220 {
00221 }
00222 
00223 WPickInfo::modifierKey WPickInfo::getModifierKey() const
00224 {
00225     return m_modKey;
00226 }
00227 
00228 void WPickInfo::setModifierKey( const modifierKey& modKey )
00229 {
00230     m_modKey = modKey;
00231 }
00232 
00233 WPickInfo::WMouseButton WPickInfo::getMouseButton() const
00234 {
00235     return m_mouseButton;
00236 }
00237 
00238 void WPickInfo::setMouseButton( const WMouseButton& mButton )
00239 {
00240     m_mouseButton = mButton;
00241 }
00242 
00243 std::string WPickInfo::getName() const
00244 {
00245     return m_name;
00246 }
00247 
00248 std::string WPickInfo::getViewerName() const
00249 {
00250     return m_viewerName;
00251 }
00252 
00253 WPosition WPickInfo::getPickPosition() const
00254 {
00255     return m_pickPosition;
00256 }
00257 
00258 WVector3d WPickInfo::getPickNormal() const
00259 {
00260     return m_pickNormal;
00261 }
00262 
00263 inline bool WPickInfo::operator==( WPickInfo rhs ) const
00264 {
00265     return ( this->m_name == rhs.m_name
00266              && this->m_pickPosition == rhs.m_pickPosition
00267              && this->m_modKey == rhs.m_modKey );
00268 }
00269 
00270 inline bool WPickInfo::operator!=( WPickInfo rhs ) const
00271 {
00272     return !( *this == rhs );
00273 }
00274 
00275 inline WVector2d WPickInfo::getPickPixel() const
00276 {
00277     WVector2d v;
00278     v[0] = m_pixelCoords.first;
00279     v[1] = m_pixelCoords.second;
00280     return v;
00281 }
00282 
00283 inline int32_t WPickInfo::getScrollWheel() const
00284 {
00285     return m_scrollValue;
00286 }
00287 
00288 #endif  // WPICKINFO_H