OpenWalnut  1.3.1
WPickInfo.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 WPICKINFO_H
26 #define WPICKINFO_H
27 
28 #include <stdint.h>
29 
30 #include <string>
31 #include <utility>
32 
33 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
34 #include "../common/WDefines.h"
35 
36 
37 /**
38  * Encapsulates info for pick action.
39  */
40 class WPickInfo
41 {
42 public:
43  /**
44  * Different types of modifier keys.
45  */
47  {
48  NONE,
49  SHIFT,
50  STRG,
51  ALT,
52  WIN
53  };
54 
55  /**
56  * Different types of mouse buttons.
57  */
58  typedef enum
59  {
60  NOMOUSE,
61  MOUSE_LEFT,
62  MOUSE_RIGHT,
63  MOUSE_MIDDLE,
64  MOUSE4,
65  MOUSE5
66  }
68 
69  /**
70  * Creates an object with the needed information.
71  * \param name name of picked object
72  * \param viewerName name of the viewer
73  * \param pickPosition position where object was hit
74  * \param pixelCoords pixel coordinates of the mouse
75  * \param modKey relevant modifier key pressed during the pick
76  * \param mButton mouse button that initiated the pick
77  * \param pickNormal normal at position where object was hit. (0,0,0) means not set.
78  * \param wheelValue the value of the scroll wheel
79  */
80  inline WPickInfo( std::string name,
81  std::string viewerName,
82  WPosition pickPosition,
83  std::pair< float, float > pixelCoords,
84  modifierKey modKey,
85  WMouseButton mButton = WPickInfo::MOUSE_LEFT,
86  WVector3d pickNormal = WVector3d(),
87  int32_t wheelValue = 0 );
88 
89  /**
90  * Creates an object with the empty name, zero position and no modkey.
91  */
92  inline WPickInfo();
93 
94  /**
95  * Get the modifier key associated with the pick
96  *
97  * \return the mod key
98  */
99  inline modifierKey getModifierKey() const;
100 
101  /**
102  * Get the mouse button associated with the pick
103  *
104  * \return the mouse button
105  */
106  inline WMouseButton getMouseButton() const;
107 
108  /**
109  * Set the modifier key associated with the pick
110  * \param modKey new modifier key
111  */
112  inline void setModifierKey( const modifierKey& modKey );
113 
114  /**
115  * Set the modifier key associated with the pick
116  * \param mButton new mouse button
117  */
118  inline void setMouseButton( const WMouseButton& mButton );
119 
120 
121  /**
122  * Get name of picked object.
123  *
124  * \return object name
125  */
126  inline std::string getName() const;
127 
128  /**
129  * Get name of the viewer.
130  *
131  * \return viewer name
132  */
133  inline std::string getViewerName() const;
134 
135  /**
136  * Get position where object was hit.
137  *
138  * \return the pick position
139  */
140  inline WPosition getPickPosition() const;
141 
142  /**
143  * Get normal at position where object was hit.
144  *
145  * \return pick normal
146  */
147  inline WVector3d getPickNormal() const;
148 
149  /**
150  * Returns the picked pixel coordinates in screen-space.
151  *
152  * \return the coordinates
153  */
154  inline WVector2d getPickPixel() const;
155 
156  /**
157  * Returns an integer denoting the wheel movement. If the value gets smaller, the wheel scrolled down.
158  *
159  * \return the value.
160  */
161  inline int32_t getScrollWheel() const;
162 
163  /**
164  * Tests two pick infos for equality
165  * \param rhs right hand side of comparison
166  *
167  * \return true if equal
168  */
169  inline bool operator==( WPickInfo rhs ) const;
170 
171  /**
172  * Tests two pick infos for inequality
173  *
174  * \param rhs right hand side of comparison
175  *
176  * \return true if not equal
177  */
178  inline bool operator!=( WPickInfo rhs ) const;
179 
180 protected:
181 private:
182  std::string m_name; //!< name of picked object.
183  std::string m_viewerName; //!< name of the viewer
184  WPosition m_pickPosition; //!< position where object was hit.
185  std::pair< float, float > m_pixelCoords; //!< Pixel coordinates of the mouse.
186  modifierKey m_modKey; //!< modifier key associated with the pick
187  WMouseButton m_mouseButton; //!< which mouse button was used for the pick
188  WVector3d m_pickNormal; //!< normal at position where object was hit.
189  int32_t m_scrollValue; //!< the scroll wheel value.
190 };
191 
192 WPickInfo::WPickInfo( std::string name,
193  std::string viewerName,
194  WPosition pickPosition,
195  std::pair< float, float > pixelCoords,
196  modifierKey modKey,
197  WMouseButton mButton,
198  WVector3d pickNormal,
199  int32_t wheelValue ) :
200  m_name( name ),
201  m_viewerName( viewerName ),
202  m_pickPosition( pickPosition ),
203  m_pixelCoords( pixelCoords ),
204  m_modKey( modKey ),
205  m_mouseButton( mButton ),
206  m_pickNormal( pickNormal ),
207  m_scrollValue( wheelValue )
208 {
209 }
210 
212  m_name( "" ),
213  m_viewerName( "" ),
214  m_pickPosition( WPosition() ),
215  m_pixelCoords( std::make_pair( 0.0, 0.0 ) ),
216  m_modKey( WPickInfo::NONE ),
217  m_mouseButton( WPickInfo::MOUSE_LEFT ),
218  m_scrollValue( 0 )
219 {
220 }
221 
223 {
224  return m_modKey;
225 }
226 
228 {
229  m_modKey = modKey;
230 }
231 
233 {
234  return m_mouseButton;
235 }
236 
238 {
239  m_mouseButton = mButton;
240 }
241 
242 std::string WPickInfo::getName() const
243 {
244  return m_name;
245 }
246 
247 std::string WPickInfo::getViewerName() const
248 {
249  return m_viewerName;
250 }
251 
253 {
254  return m_pickPosition;
255 }
256 
258 {
259  return m_pickNormal;
260 }
261 
262 inline bool WPickInfo::operator==( WPickInfo rhs ) const
263 {
264  return ( this->m_name == rhs.m_name
265  && this->m_pickPosition == rhs.m_pickPosition
266  && this->m_modKey == rhs.m_modKey );
267 }
268 
269 inline bool WPickInfo::operator!=( WPickInfo rhs ) const
270 {
271  return !( *this == rhs );
272 }
273 
275 {
276  WVector2d v;
277  v[0] = m_pixelCoords.first;
278  v[1] = m_pixelCoords.second;
279  return v;
280 }
281 
282 inline int32_t WPickInfo::getScrollWheel() const
283 {
284  return m_scrollValue;
285 }
286 
287 #endif // WPICKINFO_H