PluginFunctions.hh 14.5 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  Standard Functions
//
//=============================================================================

/**
 * \file PluginFunctions.hh
 * This file contains functions which can be used by plugins to access data in the framework.
 */

//
#ifndef PLUGINFUNCTIONS_HH
#define PLUGINFUNCTIONS_HH

#include <OpenFlipper/common/Types.hh>

Jan Möbius's avatar
   
Jan Möbius committed
52
#include <ACG/Scenegraph/SceneGraph.hh>
53
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
Jan Möbius's avatar
 
Jan Möbius committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

/** The Namespace PluginFunctions contains functions for all plugins. These functions should be used to get the
 *  objects to work on or to set modes in the examiner widget. */
namespace PluginFunctions {

//=======================================
// Get Source/Target objects
/** @name Active Objects
* @{ */
//=======================================

/** \brief Get the picked mesh
 * @param _node_idx Node index returned by examiner picking
 * @param _object returns the object which contains the mesh
 * @return true if mesh was found, false if picked object is not a mesh or not found
 */
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
71
bool getPickedObject(const unsigned int _node_idx , BaseObjectData*& _object);
Jan Möbius's avatar
 
Jan Möbius committed
72
73
74
75

/** \brief Delete the object with the given id
 *
 *  Deletes the given object ( you have to emit the right signals yourself)\n
Jan Möbius's avatar
Jan Möbius committed
76
 *  updateView , objectListUpdate ... )
Jan Möbius's avatar
 
Jan Möbius committed
77
78
79
 * @return successful?
 * */
DLLEXPORT
80
bool deleteObject( const int _id );
Jan Möbius's avatar
 
Jan Möbius committed
81
82
83
84
85
86
87

/** \brief Delete all objects
 *
 * */
DLLEXPORT
void deleteAll( );

88
89
90
/** \brief Create a copy of the object with the given id
 *
 * Creates a copy of an object. All scenegraph nodes will be created. The object will
Jan Möbius's avatar
Jan Möbius committed
91
92
93
 * be part of the object tree at the same location as the parent of the original mesh.
 * This has to be done by setParent of the object.
 *
94
95
96
 * @return Pointer to new object or 0 if failed;
 * */
DLLEXPORT
97
int copyObject( const int _id );
98
99


Jan Möbius's avatar
 
Jan Möbius committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115


/** @} */

//=======================================
// Get Objects by their identifier
    /** @name Identifier handling
    * @{ */
//=======================================

/** \brief Get the identifiers of all objects marked as a source object.
 *
 * @param _identifiers ( vector returning the source object identifiers )
 * @return false, if no object is selected as source
*/
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
116
bool getSourceIdentifiers( std::vector<int>& _identifiers  );
Jan Möbius's avatar
 
Jan Möbius committed
117
118
119
120
121
122
123

/** \brief Get the identifiers of all objects marked as a target object.
 *
 * @param _identifiers ( vector returning the target object identifiers )
 * @return false, if no object is selected as target
*/
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
124
bool getTargetIdentifiers( std::vector<int>& _identifiers  );
Jan Möbius's avatar
 
Jan Möbius committed
125
126
127
128
129
130
131

/** \brief Get identifiers of all meshes
 *
 * @param _identifiers ( vector returning the identifiers )
 * @return false, if no mesh is found
*/
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
132
bool getAllMeshes( std::vector<int>& _identifiers  );
Jan Möbius's avatar
 
Jan Möbius committed
133
134
135
136
137
138
139

/** \brief Get identifiers of all objects
 *
 * @param _identifiers ( vector returning the identifiers )
 * @return false, if no mesh is found
*/
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
140
bool getAllObjectIdentifiers( std::vector<int>& _identifiers  );
Jan Möbius's avatar
 
Jan Möbius committed
141
142
143
144
145
146
147
148
149
150
151
152
153


/** \brief Get the object which has the given identifier.
 *
 *  Every loaded object has a unique identifier which is stored in the id field of the object container.
 *  Use this function to get the object which has this id. This can be used for a consistent mapping
 *  even if the data objects change during plugin operations (e.g. selection and main algorithm).\n
 *  This function only returns visible objects.
 * @param _identifier Object id to search for
 * @param _object  returns the object
 * @return Object found?
 */
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
154
bool getObject(  const int _identifier , BaseObject*& _object );
Jan Möbius's avatar
 
Jan Möbius committed
155
156

/** This functions returns the object with the given id regardless of the type of object.
157
 * See get_object(  int _identifier , ject*& _object ) for more details.
Jan Möbius's avatar
 
Jan Möbius committed
158
159
 */
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
160
bool getObject(  const int _identifier , BaseObjectData*& _object );
Jan Möbius's avatar
 
Jan Möbius committed
161
162
163
164
165
166
167

/** \brief Check if an object with this identifier exists.
 *
 * Searches through the Data containers and checks if the object with the given identifier exists
 * @param _identifier  Object id to search for
 */
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
168
bool objectExists(  const int _identifier );
Jan Möbius's avatar
 
Jan Möbius committed
169
170
171

/// Get the number of available objects
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
172
int objectCount();
Jan Möbius's avatar
 
Jan Möbius committed
173
174
175

/// Get the number of target objects
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
176
int targetCount();
Jan Möbius's avatar
 
Jan Möbius committed
177
178
179

/// Get the number of source objects
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
180
int sourceCount();
Jan Möbius's avatar
 
Jan Möbius committed
181
182
183

/// Get the number of visible objects
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
184
int visibleCount();
Jan Möbius's avatar
 
Jan Möbius committed
185
186
187
188
189
190
191
192

/** @} */

//=======================================
// Get/set status of examiner
    /** @name Examiner handling
    * @{ */
//=======================================
Jan Möbius's avatar
Jan Möbius committed
193

194
195
196
197
198

/// Get the number of viewers
DLLEXPORT
int viewers( );

Jan Möbius's avatar
Jan Möbius committed
199
200
/// Set the active id of the examiner which got the last mouse events
DLLEXPORT
201
void setActiveExaminer( const unsigned int _id );
Jan Möbius's avatar
 
Jan Möbius committed
202

203
204
205
206
/// Get the id of the examiner which got the last mouse events
DLLEXPORT
unsigned int activeExaminer();

Jan Möbius's avatar
Jan Möbius committed
207
208
209
210
/** Execute picking operation on scenegraph
 * This picking function will pick in the last active examiner context which is automatically
 * Set by mouseevents from the core
 */
Jan Möbius's avatar
 
Jan Möbius committed
211
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
212
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr );
Jan Möbius's avatar
 
Jan Möbius committed
213

Jan Möbius's avatar
Jan Möbius committed
214
215
216
/** Execute picking operation on scenegraph
 * This picking function will pick in the specified examiner context
 */
Jan Möbius's avatar
Jan Möbius committed
217
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
218
bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr );
Jan Möbius's avatar
Jan Möbius committed
219

Jan Möbius's avatar
Jan Möbius committed
220
/** Execute Scenegraph traversal with action and use the last active examiner
Jan Möbius's avatar
Jan Möbius committed
221
222
 *  If you are reacting on a mouseEvent you should use this function as it will
 *  automatically set the right view
Jan Möbius's avatar
Jan Möbius committed
223
 */
Jan Möbius's avatar
 
Jan Möbius committed
224
225
226
DLLEXPORT
void traverse( ACG::SceneGraph::MouseEventAction  &_action );

Jan Möbius's avatar
Jan Möbius committed
227
/// Execute Scenegraph traversal with action and a specified examiner
228
void traverse(  const unsigned int _examiner, ACG::SceneGraph::MouseEventAction  &_action );
Jan Möbius's avatar
Jan Möbius committed
229

Jan Möbius's avatar
 
Jan Möbius committed
230
231
232
233
/// Get the current Picking mode
DLLEXPORT
const std::string & pickMode ();

Jan Möbius's avatar
Jan Möbius committed
234
/// Set the current Picking mode for all examiner widgets
Jan Möbius's avatar
 
Jan Möbius committed
235
236
237
DLLEXPORT
void pickMode ( std::string _mode);

Jan Möbius's avatar
Jan Möbius committed
238
239
/// Set pick mode for a specific examiner
DLLEXPORT
240
void pickMode ( const unsigned int _examiner, std::string _mode);
Jan Möbius's avatar
Jan Möbius committed
241

Jan Möbius's avatar
 
Jan Möbius committed
242
243
/// Returns a QImage of the current View
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
244
void getCurrentViewImage(QImage& _image);
Jan Möbius's avatar
 
Jan Möbius committed
245

Dirk Wilden's avatar
Dirk Wilden committed
246
247
248
249
/// Get the root node
DLLEXPORT
ACG::SceneGraph::BaseNode* getSceneGraphRootNode();

Jan Möbius's avatar
 
Jan Möbius committed
250
251
252
253
/// Get the root node
DLLEXPORT
ACG::SceneGraph::BaseNode* getRootNode();

Dirk Wilden's avatar
Dirk Wilden committed
254
255
256
257
258
259
260
261
/// Add a node under the root node
DLLEXPORT
void addNode(ACG::SceneGraph::BaseNode* _node);

/// Add a node between root node and its children
DLLEXPORT
void addGlobalNode(ACG::SceneGraph::BaseNode* _node);

Jan Möbius's avatar
 
Jan Möbius committed
262
263
/// Set the current Action Mode (PickMode,ExamineMode,...)
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
264
void actionMode ( Viewer::ActionMode _mode);
Jan Möbius's avatar
 
Jan Möbius committed
265
266
267

/// Get the current Action mode
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
268
269
Viewer::ActionMode actionMode();

Jan Möbius's avatar
 
Jan Möbius committed
270
271
272
273
274
275
276
277
278
279
280
/** Lock scene rotation via mouse
 *
 * @param _mode allow or disallow rotation
 */
DLLEXPORT
void allowRotation(bool _mode);

/** \brief Map coordinates of GL Widget to global coordinates
 *
 */
DLLEXPORT
281
QPoint mapToGlobal( const QPoint _point );
Jan Möbius's avatar
 
Jan Möbius committed
282
283
284
285
286

/** \brief Map global coordinates to GL Widget local coordinates
 *
 */
DLLEXPORT
287
QPoint mapToLocal( const QPoint _point );
Jan Möbius's avatar
 
Jan Möbius committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

/** @} */

//=======================================
// Iterators for object Access
    /** @name Iterators
    * @{ */
//=======================================

enum IteratorRestriction {
   ALL_OBJECTS,
   TARGET_OBJECTS,
   SOURCE_OBJECTS
};

/** \brief Core Data Iterator
 *
 * This is the core iterator for the whole framework. You should use this iterator to access your data.\n
Jan Möbius's avatar
Jan Möbius committed
306
 * You can choose if the iterator returns only Target, Source or all objects.\n
Jan Möbius's avatar
 
Jan Möbius committed
307
 * Additionally you can set the type of objects returned by the iterator.
Jan Möbius's avatar
Jan Möbius committed
308
 * The ObjectIterator will only return real Objects. Groups are not considered to be objects
Jan Möbius's avatar
 
Jan Möbius committed
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
 */
class DLLEXPORT ObjectIterator {

   public :

      /// type of the Objects the iterator works on
      typedef BaseObjectData  value_type;

      /// handle type (just an int)
      typedef BaseObjectData* value_handle;

      /// reference type
      typedef value_type&     reference;

      /// basic pointer type
      typedef value_type*     pointer;

   /** \brief Use this constructor for iterating through your data.
    *
    * @param _restriction Use this parameter to define which objects will be returned.\n
    *                     You can select between ALL_OBJECTS , TARGET_OBJECTS , SOURCE_OBJECTS.
    * @param _dataType Use this parameter to select the returned object types.
    *                  You can use DATA_ALL DATA_POLY_MESH DATA_TRIANGLE_MESH DATA_VOLUME
    */
   ObjectIterator(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );

   /// additional constructor starting at a given position
   ObjectIterator(BaseObjectData* pos, IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );

   /// return the current position of the iterator
   operator value_handle() { return pos_;  };

   /// compare iterators
   bool operator==( const ObjectIterator& _rhs);

   /// compare iterators
   bool operator!=( const ObjectIterator& _rhs);

   /// assign iterators
   ObjectIterator& operator=( const ObjectIterator& _rhs);

   /// dereference
   pointer operator->();

   /// next element
   ObjectIterator& operator++();

   /// last element
   ObjectIterator& operator--();

   /// dereference the iterator
   BaseObjectData* operator*();

   /// return current position of the iterator
   BaseObjectData* index() { return pos_; };

   private :
      /// current position of the iterator
      BaseObjectData* pos_;

      /// returned data types of the iterator
      DataType dataType_;

      /// Restriction of the iterator
      IteratorRestriction restriction_;

Jan Möbius's avatar
Jan Möbius committed
375
376
377
378
379
      /** Takes an object and goes through the object tree to the next BaseObjectData
        *  It stops at the root node.
        */
      inline void proceedToNextBaseObjectData(BaseObject*& _object);

Jan Möbius's avatar
 
Jan Möbius committed
380
381
};

Jan Möbius's avatar
Jan Möbius committed
382
383
/** \brief Core Data Iterator used to iterate over all objects (Including groups)
 *
Jan Möbius's avatar
Jan Möbius committed
384
385
386
 * This iterator is a more low level one not only returning really visible objects but also
 * Data containers ( e.g. groups... )
 * You can choose if the iterator returns only Target, Source or all objects.\n
Jan Möbius's avatar
Jan Möbius committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
 * Additionally you can set the type of objects returned by the iterator.
 */
class DLLEXPORT BaseObjectIterator {

   public :

      /// type of the Objects the iterator works on
      typedef BaseObject  value_type;

      /// handle type (just an int)
      typedef BaseObject* value_handle;

      /// reference type
      typedef value_type&     reference;

      /// basic pointer type
      typedef value_type*     pointer;

   /** \brief Use this constructor for iterating through your data.
    *
    * @param _restriction Use this parameter to define which objects will be returned.\n
    *                     You can select between ALL_OBJECTS , TARGET_OBJECTS , SOURCE_OBJECTS.
    * @param _dataType Use this parameter to select the returned object types.
    *                  You can use DATA_ALL DATA_POLY_MESH DATA_TRIANGLE_MESH DATA_VOLUME
    */
   BaseObjectIterator(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );

   /// additional constructor starting at a given position
   BaseObjectIterator(BaseObject* pos, IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );

   /// return the current position of the iterator
   operator value_handle() { return pos_;  };

   /// compare iterators
   bool operator==( const BaseObjectIterator& _rhs);

   /// compare iterators
   bool operator!=( const BaseObjectIterator& _rhs);

   /// assign iterators
   BaseObjectIterator& operator=( const BaseObjectIterator& _rhs);

   /// dereference
   pointer operator->();

   /// next element
   BaseObjectIterator& operator++();

   /// last element
   BaseObjectIterator& operator--();

   /// dereference the iterator
   BaseObject* operator*();

   /// return current position of the iterator
   BaseObject* index() { return pos_; };

   private :
      /// current position of the iterator
      BaseObject* pos_;

      /// returned data types of the iterator
      DataType dataType_;

      /// Restriction of the iterator
      IteratorRestriction restriction_;

};

Jan Möbius's avatar
 
Jan Möbius committed
456
457
458
459
460
// /// Return Iterator to Mesh End
// MeshIterator meshes_end();

/// Return Iterator to Object End
DLLEXPORT
Jan Möbius's avatar
   
Jan Möbius committed
461
ObjectIterator objectsEnd();
Jan Möbius's avatar
 
Jan Möbius committed
462

Jan Möbius's avatar
Jan Möbius committed
463
464
/// Return Iterator to Object End
DLLEXPORT
465
BaseObjectIterator baseObjectsEnd();
Jan Möbius's avatar
Jan Möbius committed
466

Jan Möbius's avatar
 
Jan Möbius committed
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/** @} */

//=======================================
// Dont Use functions below!!!
    /** @name Do never use!!
    * @{ */
//=======================================

/** Set the global DataContainer*/
DLLEXPORT
void setDataRoot( BaseObject* _root );

/** @} */

//=======================================
    /** @name Getting data from objects and casting between them
     * @{ */
//=======================================

/** \brief Cast an BaseObject to a BaseObjectData if possible
 *
 * @param _object The object should be of type BaseObject. If the content is a BaseObjectData, a
 *                a BaseObjectData is returned. Otherwise a NULL pointer is returned.
 */
DLLEXPORT
BaseObjectData* baseObjectData( BaseObject* _object );

/** @} */

/// Get the root of the object structure
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
498
BaseObject*& objectRoot();
Jan Möbius's avatar
 
Jan Möbius committed
499
500
501
502

}

#endif //PLUGINFUNCTIONS_HH