OpenWalnut  1.5.0dev
WOnscreenSelection.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 WONSCREENSELECTION_H
26 #define WONSCREENSELECTION_H
27 
28 #include <vector>
29 
30 #include <boost/function.hpp>
31 #include <osg/Depth>
32 #include <osg/Geode>
33 #include <osg/Geometry>
34 #include <osg/LineWidth>
35 #include <osg/Projection>
36 
37 #include "core/graphicsEngine/postprocessing/WGEPostprocessingNode.h"
38 #include "core/graphicsEngine/shaders/WGEShader.h"
39 #include "core/kernel/WKernel.h"
40 #include "WOnscreenSelectionHandler.h"
41 
42 /**
43  * Forward declaration of the SelectionHandler.
44  */
46 
47 /**
48  * Manages different types of selection.
49  */
51 {
52 public:
53  /**
54  * The different types of selection.
55  */
56  enum class WSelectionType
57  {
58  BRUSH, LINELOOP, BOX
59  };
60 
61  /**
62  * A typedef for the type of the callbacks.
63  */
64  typedef boost::function< void ( enum WSelectionType, float, float ) > CallbackType;
65 
66  /**
67  * Not only creates the Object but also sets up the drawing context.
68  */
70 
71  /**
72  * Cleans up all the now unneeded drawing context stuff.
73  */
75 
76  /**
77  * Starts the selection.
78  *
79  * \param x The normalized x position of the mouse.
80  * \param y The normalized y position of the mouse.
81  */
82  void start( float x, float y );
83 
84  /**
85  * Ends the selection.
86  *
87  * \param x The normalized x position of the mouse.
88  * \param y The normalized y position of the mouse.
89  */
90  void end( float x, float y );
91 
92  /**
93  * Handles mouse move while selecting.
94  *
95  * \param x The normalized x position of the mouse.
96  * \param y The normalized y position of the mouse.
97  */
98  void move( float x, float y );
99 
100  /**
101  * Gets the current selection type.
102  *
103  * \return enum WSelectionType The current selection type.
104  */
106 
107  /**
108  * Clears the current selection.
109  */
110  void clear();
111 
112  /**
113  * Whether a point is selected or not.
114  * \param x The x position.
115  * \param y The y position.
116  * \param z The z position.
117  * \return true The point is selected.
118  * \return false The point is not selected.
119  */
120  bool isSelected( float x, float y, float z );
121 
122  /**
123  * Checks if the positions are selected and only returns those that are.
124  * \param positions The positions to check
125  * \return std::vector< WPosition > A vector of selected positions
126  */
127  std::vector< WPosition > isSelected( std::vector< WPosition> positions );
128 
129  /**
130  * Sets the current selection type.
131  * \param selectionType The selection type to set.
132  */
133  void setSelectionType( enum WSelectionType selectionType );
134 
135  /**
136  * Sets the callback for the onstart function.
137  * Use NULL to reset.
138  *
139  * \param onstart The Callback or NULL.
140  */
141  void setOnstart( CallbackType onstart );
142 
143  /**
144  * Sets the callback for the onend function.
145  * Use NULL to reset.
146  *
147  * \param onend The Callback or NULL.
148  */
149  void setOnend( CallbackType onend );
150 
151  /**
152  * Sets the callback for the onmove function.
153  * Use NULL to reset.
154  *
155  * \param onmove The Callback or NULL.
156  */
157  void setOnmove( CallbackType onmove );
158 
159  /**
160  * Returns whether this manager is currently creating a selection.
161  * \return true It is creating a selection.
162  * \return false It is not creating a selection.
163  */
164  bool isSelecting();
165 
166  /**
167  * Check for the box selection.
168  * \param x The x position of the point.
169  * \param y The y position of the point.
170  * \return true The point is inside of the box.
171  * \return false The point is not inside of the box
172  */
173  bool boxCheck( float x, float y );
174 
175  /**
176  * Check for the brush selection.
177  * \param x The x position of the point.
178  * \param y The y position of the point.
179  * \return true The point is on the brush.
180  * \return false The point is not on the brush
181  */
182  bool brushCheck( float x, float y );
183 
184  /**
185  * Check for the lineloop selection.
186  * \param x The x position of the point.
187  * \param y The y position of the point.
188  * \return true The point is inside of the lineloop.
189  * \return false The point is inside of the lineloop
190  */
191  bool lineloopCheck( float x, float y );
192 
193  /**
194  * Calculates the crossing number product.
195  * \param x The x position of the point.
196  * \param y The y position of the point.
197  * \param b The start of the line.
198  * \param c The end of the line.
199  * \return int Either -1, 0 or 1.
200  */
201  int crossingNumberProduct( float x, float y, WPosition b, WPosition c );
202 
203  /**
204  * Sets the click type.
205  * \param clickType true for left click, false for right click.
206  */
207  void setClickType( bool clickType );
208 
209  /**
210  * Gets the click type.
211  * \return true left click.
212  * \return false right click.
213  */
214  bool getClickType();
215 
216  /**
217  * \return true The mouse has been moved.
218  * \return false The mouse has not been moved.
219  */
220  bool hasMoved();
221 
222 private:
223  /**
224  * Updates the current rendered data.
225  */
226  void updateDisplay();
227 
228  osg::ref_ptr< osg::Projection > m_projection; //!< The Projection to draw on.
229 
230  enum WSelectionType m_selectionType; //!< The current selection type.
231 
232  osg::ref_ptr< WOnscreenSelectionHandler > m_selectionHandler; //!< The SelectionHandler for this object.
233 
234  std::vector< WPosition > m_line; //!< The points that are used for the selection.
235 
236  bool m_isSelecting; //!< Whether a selection has been started or not.
237 
238  osg::ref_ptr< WGEShader > m_shader; //!< The shader for the selection.
239 
240  float m_thickness; //!< The thickness of the brush.
241 
242  bool m_clickType; //!< Whether this is a left click or not.
243 
244  bool m_moved; //!< Whether the mouse has been moved.
245 
246  CallbackType m_onstart; //!< The Callback for the start function.
247 
248  CallbackType m_onend; //!< The Callback for the end function.
249 
250  CallbackType m_onmove; //!< The Callback for the move function.
251 };
252 
253 #endif // WONSCREENSELECTION_H
Handles the GUIEvents in context of the WOnscreenSelection.
Manages different types of selection.
std::vector< WPosition > m_line
The points that are used for the selection.
bool lineloopCheck(float x, float y)
Check for the lineloop selection.
osg::ref_ptr< osg::Projection > m_projection
The Projection to draw on.
void setSelectionType(enum WSelectionType selectionType)
Sets the current selection type.
void clear()
Clears the current selection.
void start(float x, float y)
Starts the selection.
CallbackType m_onend
The Callback for the end function.
bool brushCheck(float x, float y)
Check for the brush selection.
osg::ref_ptr< WGEShader > m_shader
The shader for the selection.
int crossingNumberProduct(float x, float y, WPosition b, WPosition c)
Calculates the crossing number product.
void setOnmove(CallbackType onmove)
Sets the callback for the onmove function.
void setOnend(CallbackType onend)
Sets the callback for the onend function.
float m_thickness
The thickness of the brush.
CallbackType m_onmove
The Callback for the move function.
bool getClickType()
Gets the click type.
CallbackType m_onstart
The Callback for the start function.
void setClickType(bool clickType)
Sets the click type.
~WOnscreenSelection()
Cleans up all the now unneeded drawing context stuff.
bool m_clickType
Whether this is a left click or not.
bool isSelected(float x, float y, float z)
Whether a point is selected or not.
void move(float x, float y)
Handles mouse move while selecting.
bool m_moved
Whether the mouse has been moved.
WOnscreenSelection()
Not only creates the Object but also sets up the drawing context.
bool m_isSelecting
Whether a selection has been started or not.
enum WSelectionType getSelectionType()
Gets the current selection type.
void setOnstart(CallbackType onstart)
Sets the callback for the onstart function.
bool boxCheck(float x, float y)
Check for the box selection.
void updateDisplay()
Updates the current rendered data.
WSelectionType
The different types of selection.
bool isSelecting()
Returns whether this manager is currently creating a selection.
void end(float x, float y)
Ends the selection.
osg::ref_ptr< WOnscreenSelectionHandler > m_selectionHandler
The SelectionHandler for this object.
boost::function< void(enum WSelectionType, float, float) > CallbackType
A typedef for the type of the callbacks.
enum WSelectionType m_selectionType
The current selection type.
This only is a 3d double vector.