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