OpenWalnut  1.5.0dev
WFiberHandler.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 WFIBERHANDLER_H
26 #define WFIBERHANDLER_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <boost/lexical_cast.hpp>
33 #include <osg/Geode>
34 
35 #include "WMPointConnector.h"
36 #include "action/WActionHandler.h"
37 #include "core/common/WItemSelectionItem.h"
38 #include "core/common/WItemSelectionItemTyped.h"
39 #include "core/common/WItemSelector.h"
40 #include "core/common/WPropertyGroup.h"
41 #include "core/kernel/WModule.h"
42 
43 
44 /**
45  * Handles the fibers of the WMPointsConnector.
46  */
48 {
49 public:
50  /**
51  * A shared_ptr to this class.
52  */
53  typedef std::shared_ptr< WFiberHandler > SPtr;
54 
55  /**
56  * Type of selectable items.
57  */
59 
60  /**
61  * Vector of 3D vectors, representing points
62  */
63  typedef std::vector< osg::Vec3 > PCFiber;
64 
65  /**
66  * Vector, that could contain multiple fibers
67  */
68  typedef std::vector< PCFiber > PCFiberList;
69 
70  /**
71  * Shared pointer to fibers-vector
72  */
73  typedef std::shared_ptr< PCFiberList > PCFiberListSPtr;
74 
75  /**
76  * Creates the list of fibers.
77  * \param pointConnector The WMPointConnector this belongs to.
78  */
79  explicit WFiberHandler( WMPointConnector* pointConnector );
80 
81  /**
82  * Creates the properties for this handler.
83  * \param properties The PropertyGroup to add the properties to.
84  */
85  void createProperties( WPropertyGroup::SPtr properties );
86 
87  /**
88  * Adds a vertex to the currently selected fiber.
89  * \param vertex The vertex to add.
90  * \param fiberIdx The index of the fiber to add the vertex to.
91  * \param silent Whether or not this should add to the undo stack.
92  */
93  void addVertexToFiber( osg::Vec3 vertex, size_t fiberIdx, bool silent = false );
94 
95  /**
96  * Adds multiple vertices to the currently selected fiber.
97  * \param vertices The vertices to add.
98  * \param fiberIdx The index of the fiber to add the vertex to.
99  * \param silent Whether or not this should add to the undo stack.
100  */
101  void addVerticesToFiber( std::vector< osg::Vec3 > vertices, size_t fiberIdx, bool silent = false );
102 
103  /**
104  * Adds a vertex to the currently selected fiber.
105  * \param vertex The vertex to add.
106  * \param fiberIdx The index of the fiber to add the vertex to.
107  * \param position The position where to add the vertex.
108  * \param silent Whether or not this should add to the undo stack.
109  */
110  void addVertexToFiberAt( osg::Vec3 vertex, size_t fiberIdx, size_t position, bool silent = false );
111 
112  /**
113  * Removes a vertex from the currently selected fiber.
114  * \param vertex The vertex to remove.
115  * \param fiberIdx The index of the fiber to remove the vertex from.
116  * \param silent Whether or not this should add to the undo stack.
117  */
118  void removeVertexFromFiber( osg::Vec3 vertex, size_t fiberIdx, bool silent = false );
119 
120  /**
121  * Removes multiple vertices from the currently selected fiber.
122  * \param vertices The vertices to remove.
123  * \param fiberIdx The index of the fiber to remove the vertex from.
124  * \param silent Whether or not this should add to the undo stack.
125  */
126  void removeVerticesFromFiber( std::vector< osg::Vec3 > vertices, size_t fiberIdx, bool silent = false );
127 
128  /**
129  * Adds a new fiber.
130  * \param name The name of the fiber.
131  * \param silent Whether or not this should add to the undo stack.
132  * \param updateSelector Whether the UI selector should be updated
133  */
134  void addFiber( std::string name, bool silent = false, bool updateSelector = true );
135 
136  /**
137  * Adds a new or an old fiber at a specific position.
138  * \param name The name of the fiber.
139  * \param position The position of the fiber.
140  * \param hidden Whether the fiber is hidden or not.
141  * \param silent Whether or not this should add to the undo stack.
142  * \param fiber The fiber to add.
143  */
144  void addFiberAt( std::string name, size_t position, bool hidden, bool silent = false, PCFiber fiber = PCFiber() );
145 
146  /**
147  * Removes a fiber at an index in the fibers vector.
148  * \param idx The index of the fiber.
149  * \param silent Whether or not this should add to the undo stack.
150  * \param updateSelector Whether the UI selector should be updated
151  */
152  void removeFiber( size_t idx, bool silent = false, bool updateSelector = true );
153 
154  /**
155  * Toggles the visibility of a fiber.
156  * \param idx The index of the fiber.
157  * \param silent Whether or not this should add to the undo stack.
158  */
159  void toggleFiber( size_t idx, bool silent = false );
160 
161  /**
162  * Creates a new fiber.
163  */
164  void createNewFiber();
165 
166  /**
167  * Updates the UI selector.
168  *
169  * \param idx index of the selected fiber.
170  */
171  void selectorUpdate( size_t idx );
172 
173  /**
174  * Clears the data in this handler.
175  */
176  void clear();
177 
178  /**
179  * Selects a fiber by its index in the fibers vector.
180  * \param idx The index of the fiber.
181  */
182  void selectFiber( size_t idx );
183 
184  /**
185  * Selects the last point of the currently selected fiber.
186  */
187  void selectLastPoint();
188 
189  /**
190  * Sorts the vertices by their z value.
191  */
192  void sortVertices();
193 
194  /**
195  * Checks if a fiber is hidden.
196  * \param idx The index of the fiber to check.
197  * \return true The fiber is hidden.
198  * \return false The fiber is not hidden.
199  */
200  bool isHidden( size_t idx );
201 
202  /**
203  * Gets the index of the fiber of a point.
204  * \param vertex The point to check.
205  * \param idx The index of the fiber of the point. This is a pointer and the secondary output. If this is NULL it is ignored.
206  * \return true The point is in a fiber.
207  * \return false The point is not in a fiber.
208  */
209  bool getFiberOfPoint( osg::Vec3 vertex, size_t* idx = NULL );
210 
211  /**
212  * Checks whether a point is in a hidden fiber.
213  * \param vertex The point to check.
214  * \return true The point is hidden.
215  * \return false The point is not hidden.
216  */
217  bool isPointHidden( osg::Vec3 vertex );
218 
219  /**
220  * \return PCFiberListSPtr All the fibers in this handler.
221  */
223 
224  /**
225  * \return WMPointConnector* The WMPointConnector this belongs to
226  */
228 
229  /**
230  * \return size_t The currently selected fiber.
231  */
232  size_t getSelectedFiber();
233 
234  /**
235  * \return WActionHandler::SPtr The WActionHandler of this class.
236  */
238 
239  /**
240  * Sets the fiber count.
241  * \param fiberCount The new fiber count.
242  */
243  void setFiberCount( size_t fiberCount );
244 
245 private:
246  /**
247  * Update handler for the properties
248  * \param property updated property
249  */
250  void updateProperty( WPropertyBase::SPtr property );
251 
252  /**
253  * A reference to the WMPointConnector this belongs to.
254  */
256 
257  /**
258  * Handles the undo and redo action.
259  */
261 
262  /**
263  * Stores the amount of new created fibers.
264  */
265  int m_fiberCount = 0;
266 
267  /**
268  * Represents the index of the current active fiber.
269  */
270  size_t m_selectedFiber = 0;
271 
272  /**
273  * The list of possible fibers, which can be selected.
274  */
275  std::shared_ptr< WItemSelection > m_possibleFiberSelections;
276 
277  /**
278  * Represents the current active fiber selection property.
279  */
280  WPropSelection m_fiberSelection;
281 
282  /**
283  * The type of the selection.
284  */
285  WPropSelection m_selectionType;
286 
287  /**
288  * Property (button) to add a new fiber.
289  */
290  WPropTrigger m_addFiber;
291 
292  /**
293  * Property (button) to remove a fiber.
294  */
295  WPropTrigger m_removeFiber;
296 
297  /**
298  * Property (button) to toggle the visibility of a fiber.
299  */
300  WPropTrigger m_toggleFiber;
301 
302  /**
303  * Property (button) to undo the last action.
304  */
305  WPropTrigger m_undoTrigger;
306 
307  /**
308  * Property (button) to redo the last action.
309  */
310  WPropTrigger m_redoTrigger;
311 
312  /**
313  * A pointer to the list of fibers.
314  */
316 
317  /**
318  * Vector for the visibility of the fibers.
319  */
320  std::shared_ptr< std::vector< char > > m_hidden;
321 };
322 
323 #endif // WFIBERHANDLER_H
std::shared_ptr< WActionHandler > SPtr
A shared_ptr to this class.
Handles the fibers of the WMPointsConnector.
Definition: WFiberHandler.h:48
void addVertexToFiber(osg::Vec3 vertex, size_t fiberIdx, bool silent=false)
Adds a vertex to the currently selected fiber.
void removeVerticesFromFiber(std::vector< osg::Vec3 > vertices, size_t fiberIdx, bool silent=false)
Removes multiple vertices from the currently selected fiber.
void selectLastPoint()
Selects the last point of the currently selected fiber.
WPropTrigger m_undoTrigger
Property (button) to undo the last action.
WActionHandler::SPtr getActionHandler()
void setFiberCount(size_t fiberCount)
Sets the fiber count.
void updateProperty(WPropertyBase::SPtr property)
Update handler for the properties.
WItemSelectionItemTyped< std::string > ItemType
Type of selectable items.
Definition: WFiberHandler.h:58
WPropTrigger m_addFiber
Property (button) to add a new fiber.
void toggleFiber(size_t idx, bool silent=false)
Toggles the visibility of a fiber.
std::vector< osg::Vec3 > PCFiber
Vector of 3D vectors, representing points.
Definition: WFiberHandler.h:63
void addVertexToFiberAt(osg::Vec3 vertex, size_t fiberIdx, size_t position, bool silent=false)
Adds a vertex to the currently selected fiber.
PCFiberListSPtr getFibers()
void addFiber(std::string name, bool silent=false, bool updateSelector=true)
Adds a new fiber.
WActionHandler::SPtr m_actionHandler
Handles the undo and redo action.
void selectorUpdate(size_t idx)
Updates the UI selector.
bool isHidden(size_t idx)
Checks if a fiber is hidden.
WPropTrigger m_removeFiber
Property (button) to remove a fiber.
bool getFiberOfPoint(osg::Vec3 vertex, size_t *idx=NULL)
Gets the index of the fiber of a point.
void removeVertexFromFiber(osg::Vec3 vertex, size_t fiberIdx, bool silent=false)
Removes a vertex from the currently selected fiber.
size_t getSelectedFiber()
WPropTrigger m_redoTrigger
Property (button) to redo the last action.
void createNewFiber()
Creates a new fiber.
WMPointConnector * m_pointConnector
A reference to the WMPointConnector this belongs to.
std::vector< PCFiber > PCFiberList
Vector, that could contain multiple fibers.
Definition: WFiberHandler.h:68
void addVerticesToFiber(std::vector< osg::Vec3 > vertices, size_t fiberIdx, bool silent=false)
Adds multiple vertices to the currently selected fiber.
std::shared_ptr< PCFiberList > PCFiberListSPtr
Shared pointer to fibers-vector.
Definition: WFiberHandler.h:73
WPropSelection m_selectionType
The type of the selection.
std::shared_ptr< std::vector< char > > m_hidden
Vector for the visibility of the fibers.
void sortVertices()
Sorts the vertices by their z value.
bool isPointHidden(osg::Vec3 vertex)
Checks whether a point is in a hidden fiber.
int m_fiberCount
Stores the amount of new created fibers.
void selectFiber(size_t idx)
Selects a fiber by its index in the fibers vector.
void removeFiber(size_t idx, bool silent=false, bool updateSelector=true)
Removes a fiber at an index in the fibers vector.
WFiberHandler(WMPointConnector *pointConnector)
Creates the list of fibers.
size_t m_selectedFiber
Represents the index of the current active fiber.
PCFiberListSPtr m_fibers
A pointer to the list of fibers.
std::shared_ptr< WItemSelection > m_possibleFiberSelections
The list of possible fibers, which can be selected.
WPropSelection m_fiberSelection
Represents the current active fiber selection property.
WPropTrigger m_toggleFiber
Property (button) to toggle the visibility of a fiber.
std::shared_ptr< WFiberHandler > SPtr
A shared_ptr to this class.
Definition: WFiberHandler.h:53
void createProperties(WPropertyGroup::SPtr properties)
Creates the properties for this handler.
void addFiberAt(std::string name, size_t position, bool hidden, bool silent=false, PCFiber fiber=PCFiber())
Adds a new or an old fiber at a specific position.
void clear()
Clears the data in this handler.
WMPointConnector * getPointConnector()
A derivation of WItemSelection which can store a value of any type.
This module connects the points in a point dataset.
std::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyBase >
Definition: WPropertyBase.h:53
std::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type