PluginFunctions.hh 27.4 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41
\*===========================================================================*/

42 43 44 45 46 47 48 49 50 51 52
//=============================================================================
//
//  Standard Functions
//
//=============================================================================

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

53
#pragma once
54

Matthias Möller's avatar
Matthias Möller committed
55

Jan Möbius's avatar
Jan Möbius committed
56
#include <QPair>
57
#include <QFileDialog>
Jan Möbius's avatar
Jan Möbius committed
58

59
#include <OpenFlipper/common/Types.hh>
60 61
#include <OpenFlipper/common/OFGLWidget.hh>

62
#include <ACG/Scenegraph/SceneGraph.hh>
63
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
64

65 66
//== FORWARDDECLARATIONS ======================================================
class ViewObjectMarker;
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
/** 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
84
bool getPickedObject(const size_t _node_idx , BaseObjectData*& _object);
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

/** @} */

//=======================================
// 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
100
bool getSourceIdentifiers( std::vector<int>& _identifiers  );
101 102 103 104 105 106 107

/** \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
108
bool getTargetIdentifiers( std::vector<int>& _identifiers  );
109

110
/** \brief Get identifiers of all objects
111 112
 *
 * @param _identifiers ( vector returning the identifiers )
113
 * @return false, if no object is found
114 115
*/
DLLEXPORT
116
bool getAllObjectIdentifiers( std::vector<int>& _identifiers  );
117

118
/** \brief Get identifiers of all meshes
119 120 121 122 123
 *
 * @param _identifiers ( vector returning the identifiers )
 * @return false, if no mesh is found
*/
DLLEXPORT
124
bool getAllMeshes( std::vector<int>& _identifiers  );
125 126 127 128 129 130 131 132 133 134 135 136

/** \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
137
bool getObject(  const int _identifier , BaseObject*& _object );
138 139

/** This functions returns the object with the given id regardless of the type of object.
140
 * See getObject(  const int _identifier , BaseObject*& _object ) for more details.
141 142
 */
DLLEXPORT
143
bool getObject(  const int _identifier , BaseObjectData*& _object );
144

145 146 147
/** This functions returns the object's id with the given name.
 */
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
148
int getObjectId( const QString& _name );
149

150 151 152 153 154 155
/** \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
156
bool objectExists(  const int _identifier );
157 158 159

/// Get the number of available objects
DLLEXPORT
160
int objectCount();
161 162 163

/// Get the number of target objects
DLLEXPORT
164
int targetCount();
165 166 167

/// Get the number of source objects
DLLEXPORT
168
int sourceCount();
169 170 171

/// Get the number of visible objects
DLLEXPORT
172
int visibleCount();
173 174 175 176 177 178 179 180

/** @} */

//=======================================
// Get/set status of examiner
    /** @name Examiner handling
    * @{ */
//=======================================
181

182 183 184

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

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
/** \brief Disable the core light handling
*
* Use this function to disable OpenFlippers Core light handling.
* Use this function only if the light is handled by your plugin
* Normally this function is called by the light plugin which
* fully takes control over the glLighting and adds its own light nodes.
*/
DLLEXPORT
void disableExaminerLightHandling();

/** \brief returns if internal light handling is active.
*
* Internal light handling could only be deactivated. From than on a plugin
* has to manage all light handling.
*/
DLLEXPORT
bool examinerLightHandling();

205 206
/// Set the active id of the examiner which got the last mouse events
DLLEXPORT
207
void setActiveExaminer( const unsigned int _id );
208

209 210 211 212
/// Get the id of the examiner which got the last mouse events
DLLEXPORT
unsigned int activeExaminer();

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
/// Get the encoded view for the active examiner
DLLEXPORT
QString getEncodedExaminerView();

/// Get the encoded view for the given
DLLEXPORT
QString getEncodedExaminerView(int _viewerId);

/// Set the encoded view for the active examiner
DLLEXPORT
void setEncodedExaminerView( QString _view );

/// Set the encoded view for the given
DLLEXPORT
void setEncodedExaminerView(int _viewerId , QString _view );

229 230 231 232 233 234
/**
 * Set center of scene
 */
DLLEXPORT
void setSceneCenter(const ACG::Vec3d& _center, int _viewer );

235 236
/** \brief Execute picking operation on scenegraph
 *
237
 * This picking function will pick in the last active examiner context which is automatically
238
 * set by the last mouse event from the core
239
 */
240
DLLEXPORT
241
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr );
242

243 244
/** \brief Execute picking operation on scenegraph
 *
Jan Möbius's avatar
Jan Möbius committed
245 246
 * This picking function will pick in the specified examiner context
 */
247
DLLEXPORT
248
bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr );
249

250 251 252 253 254 255 256
/** \brief Execute picking operation on scenegraph and return object
 *
 * This picking function will pick in the specified examiner context and
 * will return a pointer to the picked object. Furthermore, the refine picking of
 * the picked object will be called in order to achieve higher picking accuracy
 */
DLLEXPORT
257
bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, BaseObjectData*& _object, size_t &_targetIdx, const bool _refine ,ACG::Vec3d *_hitPointPtr );
258 259 260 261 262 263 264 265

/** \brief Execute picking operation on scenegraph and return object
 *
 * This picking function will pick in the examiner context of the last mouse event and
 * will return a pointer to the picked object. Furthermore, the refine picking of
 * the picked object will be called in order to achieve higher picking accuracy
 */
DLLEXPORT
266
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, BaseObjectData*& _object, size_t &_targetIdx, const bool _refine, ACG::Vec3d *_hitPointPtr );
267 268


Jan Möbius's avatar
Jan Möbius committed
269 270 271 272 273
/** 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
 */
DLLEXPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
274 275
bool scenegraphRegionPick( ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
276
                           QList<QPair<size_t, size_t> >&             _list,
277 278
                           QVector<float>*                            _depths = 0,
                           QVector<ACG::Vec3d>*                       _points = 0);
Henrik Zimmer's avatar
Henrik Zimmer committed
279 280 281 282 283 284 285 286

/** Execute picking operation on scenegraph
 * This picking function will pick in the specified examiner context
 */
DLLEXPORT
bool scenegraphRegionPick( const unsigned int                         _examiner,
                           ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
287
                           QList<QPair<size_t, size_t> >&             _list,
288 289
                           QVector<float>*                            _depths = 0,
                           QVector<ACG::Vec3d>*                       _points = 0);
Henrik Zimmer's avatar
Henrik Zimmer committed
290

Jan Möbius's avatar
Jan Möbius committed
291
/** Execute Scenegraph traversal with action and use the last active examiner
Jan Möbius's avatar
Jan Möbius committed
292 293
 *  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
294
 */
295 296 297 298 299
DLLEXPORT
void traverse( ACG::SceneGraph::MouseEventAction  &_action );

/// Get the current Picking mode
DLLEXPORT
300
const std::string pickMode ();
301

302
/// Set the current Picking mode for all examiner widgets
303
DLLEXPORT
Jan Möbius's avatar
Jan Möbius committed
304
void pickMode ( const std::string& _mode);
305 306 307

/// Returns a QImage of the current View
DLLEXPORT
308
void getCurrentViewImage(QImage& _image);
309

310 311 312 313
/** \brief get scenegraph root node
*
* Get the real root node of the scenegraph.This node is the topmost
* node of the scenegraph. Normally you do not need to use this node.
Jan Möbius's avatar
Jan Möbius committed
314
* Except you are writing a renderer plugin.
315 316 317
* All objects should be added below the data root node which you can get
* with getRootNode().
*/
318 319 320
DLLEXPORT
ACG::SceneGraph::BaseNode* getSceneGraphRootNode();

321 322 323 324 325
/** \brief Get the root node for data objects
*
* Get the root node for the objects. This node is a separator node.
* All nodes belonging to objects have to be placed below this node.
* Add a separatornode for each object below this node! */
326 327 328
DLLEXPORT
ACG::SceneGraph::BaseNode* getRootNode();

329 330 331 332 333
/** \brief Add a global node
*
* The node will be added as a global node. Only the global status nodes
* will be above this node.
*/
334
DLLEXPORT
335
void addGlobalNode(ACG::SceneGraph::BaseNode* _node);
336

337 338 339 340 341
/** \brief Adds a global status node.
*
* The node will be added at the top of the scenegraph, before all other nodes except
* The scenegraphs real node. It will therefore influence all nodes in the scenegraph.
*/
Jan Möbius's avatar
Jan Möbius committed
342
DLLEXPORT
343 344
void addGlobalStatusNode(ACG::SceneGraph::BaseNode* _node);

345 346 347 348 349 350 351 352
/** \brief Add scenegraph node modifing object rendering
*
* This function adds nodes in front of the object root node.
* Therefore all objects renderings will be modified by the
* state changes in the added node. This might be usefull for
* adding for example a slicing node, which adds clipping planes
* such that the objects will be sliced.
*/
353
DLLEXPORT
354
void addObjectRenderingNode(ACG::SceneGraph::BaseNode* _node);
355

356 357
/// Set the current Action Mode (PickMode,ExamineMode,...)
DLLEXPORT
358
void actionMode ( Viewer::ActionMode _mode);
359 360 361

/// Get the current Action mode
DLLEXPORT
362 363
Viewer::ActionMode actionMode();

364 365
/// Sets the main QGLWidget for gl data sharing.
DLLEXPORT
366
void shareGLWidget(OFGLWidget* _widget);
367 368 369

/// Returns the main QGLWidget for gl data sharing.
DLLEXPORT
370
OFGLWidget* shareGLWidget();
371

372 373 374 375 376 377 378 379 380 381 382
/** 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
383
QPoint mapToGlobal( const QPoint _point );
384 385 386 387 388

/** \brief Map global coordinates to GL Widget local coordinates
 *
 */
DLLEXPORT
389
QPoint mapToLocal( const QPoint _point );
390

391 392 393 394 395 396 397 398 399 400 401 402 403 404
/** Set current ViewObjectMarker (will be reseted to default on pick mode change)
 *
 * @param _marker Object marker
 */
DLLEXPORT
void setViewObjectMarker (ViewObjectMarker *_marker);

/** Set the default ViewObjectMarker
 *
 * @param _marker Object marker
 */
DLLEXPORT
void setDefaultViewObjectMarker (ViewObjectMarker *_marker);

405 406 407 408 409
/** Collect and return COMMENT properties of all meshes.
 */
DLLEXPORT
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly);

410 411 412 413 414
/** Collect and return serialized materials of all meshes.
 */
DLLEXPORT
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly);

415 416 417 418
/// Get the default ViewObjectMarker
DLLEXPORT
ViewObjectMarker* defaultViewObjectMarker ();

419 420
/** @} */

421

422 423 424 425 426 427
//=======================================
// Iterators for object Access
    /** @name Iterators
    * @{ */
//=======================================

Jan Möbius's avatar
Jan Möbius committed
428 429 430 431 432
typedef QStringList IteratorRestriction;

const QStringList ALL_OBJECTS;
const QStringList TARGET_OBJECTS ("target");
const QStringList SOURCE_OBJECTS ("source");
433 434 435 436

/** \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
437
 * You can choose if the iterator returns only Target, Source or all objects.\n
438
 * Additionally you can set the type of objects returned by the iterator.
Jan Möbius's avatar
Jan Möbius committed
439
 * The ObjectIterator will only return real Objects. Groups are not considered to be objects
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
 */
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
473
   bool operator==( const ObjectIterator& _rhs) const;
474 475

   /// compare iterators
476
   bool operator!=( const ObjectIterator& _rhs) const;
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

   /// 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_;

506 507 508 509
      /** Takes an object and goes through the object tree to the next BaseObjectData
        *  It stops at the root node.
        */
      inline void proceedToNextBaseObjectData(BaseObject*& _object);
510 511 512 513 514 515 516
};


/**
 * \brief Helper class that wraps an ObjectIterator to return a reference
 * instead of a pointer
 */
517
class DLLEXPORT ObjectReferenceIterator : public std::iterator<std::forward_iterator_tag, BaseObjectData>
518 519
{
public:
520
    explicit ObjectReferenceIterator(IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
521 522 523 524
        it_(_restriction, _dataType)
    {
    }

525
    explicit ObjectReferenceIterator(BaseObjectData* _pos, IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
        it_(_pos, _restriction, _dataType)
    {
    }

    ObjectReferenceIterator(const ObjectReferenceIterator& _rhs) :
        it_(_rhs.it_)
    {
    }

    ObjectReferenceIterator& operator=(const ObjectReferenceIterator& _rhs)
    {
        if (this != &_rhs) {
            it_ = _rhs.it_;
        }
        return *this;
    }

    ObjectReferenceIterator& operator++() {
        ++it_;
        return *this;
    }

    ObjectReferenceIterator operator++(int) {
        ObjectReferenceIterator copy(*this);
        operator++();
        return copy;
    }

    bool operator==(const ObjectReferenceIterator& _rhs) const {
        return it_ == _rhs.it_;
    }

    bool operator!=(const ObjectReferenceIterator& _rhs) const {
        return it_ != _rhs.it_;
    }

    BaseObjectData& operator*() {
        return **it_;
    }

    BaseObjectData* operator->() {
        return *it_;
    }
569

570 571
private:
    ObjectIterator it_;
572 573
};

574

575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
/** \brief Range adapter for ObjectIterator
 *
 * An iterator range suitable for iterating over objects using a C++11
 * range-based for loop.
 *
 * \note Use the PluginFunction::objects factory function as a shorthand for
 * creating object ranges.
 **/
class DLLEXPORT ObjectRange {
public:
    explicit ObjectRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
        restriction_(_restriction),
        dataType_(_dataType)
    {
    }

    ObjectIterator begin() const {
        return ObjectIterator(restriction_, dataType_);
    }

    ObjectIterator end() const {
        return ObjectIterator(0);
    }

private:
    IteratorRestriction restriction_;
    DataType dataType_;
};


605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
/** \brief Range adapter for ObjectIterator
 *
 * An iterator range suitable for iterating over objects using a C++11
 * range-based for loop.
 *
 * \note Use the PluginFunction::objectReferences factory function as a shorthand for
 * creating object ranges.
 **/
class DLLEXPORT ObjectReferenceRange {
public:
    explicit ObjectReferenceRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
        restriction_(_restriction),
        dataType_(_dataType)
    {
    }

    ObjectReferenceIterator begin() const {
        return ObjectReferenceIterator(restriction_, dataType_);
    }

    ObjectReferenceIterator end() const {
        return ObjectReferenceIterator(0);
    }

private:
    IteratorRestriction restriction_;
    DataType dataType_;
};


/** \brief Iterable object range
 *
 * Creates an iterator range suitable for iterating over objects using a C++11
 * range-based for loop.
 *
 * \note Usage:
 * \code
642
 * for (auto& object : PluginFunctions::objectReferences(..., ...)) {
643 644 645 646 647 648 649 650
 *     ...
 * }
 * \endcode
 **/
DLLEXPORT
ObjectReferenceRange objectReferences(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);


651 652 653 654 655 656 657 658
/** \brief Iterable object range
 *
 * Creates an iterator range suitable for iterating over objects using a C++11
 * range-based for loop.
 *
 * \note Iterated elements are *pointers* to objects, not object references.
 * Hence, the loop header should be declared as
 * \code
659
 * for (auto* object : PluginFunctions::objects(..., ...)) {
660 661 662 663 664 665 666 667
 *     ...
 * }
 * \endcode
 **/
DLLEXPORT
ObjectRange objects(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);


668 669
/** \brief Core Data Iterator used to iterate over all objects (Including groups)
 *
Jan Möbius's avatar
Jan Möbius committed
670 671 672
 * 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
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
 * 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_;

};

742 743 744 745 746
// /// Return Iterator to Mesh End
// MeshIterator meshes_end();

/// Return Iterator to Object End
DLLEXPORT
747
ObjectIterator objectsEnd();
748

749 750
/// Return Iterator to Object End
DLLEXPORT
751
BaseObjectIterator baseObjectsEnd();
752

753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
/** @} */

//=======================================
// 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 );

/** @} */

782 783 784 785 786 787 788 789 790

/** \brief Return unique viewer id
 *
 * This function returns a id which is unique to all running Openflippers on that machine.
 * This id changes when you restart the viewer!
 */
DLLEXPORT
int viewerId();

791 792
/// Get the root of the object structure
DLLEXPORT
793
BaseObject*& objectRoot();
794

795 796 797 798 799 800 801 802 803 804
/**
 * The same as QFileDialog::getOpenFileName, except the dialog remembers its
 * last location within the file systems and opens at the same location the
 * next time.
 *
 * @param configProperty The name of the property in which to store the
 *                       last location. Should be of the form "Plugin-Foo/OpenBarFile".
 *
 * @param defaultDir If the property doesn't exist yet, defaultDir is used
 *                   as the initial location.
805 806 807 808 809 810 811 812
 *
 * @param parent       Parent qt widget
 * @param caption      Caption of the dialog
 * @param defaultDir   Default directory when dialog is shown
 * @param filter       name filters
 * @param selectedFilter currently selected filter
 * @param options      filedialog options
 *
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
 */
DLLEXPORT
QString getOpenFileName(const QString &configProperty,
                        QWidget * parent = 0, const QString & caption = QString(),
                        const QString & defaultDir = QString(), const QString & filter = QString(),
                        QString * selectedFilter = 0, QFileDialog::Options options = 0);
/**
 * The same as QFileDialog::getSaveFileName, except the dialog remembers its
 * last location within the file systems and opens at the same location the
 * next time.
 *
 * @param configProperty The name of the property in which to store the
 *                       last location. Should be of the form "Plugin-Foo/SaveBarFile".
 *
 * @param defaultDir If the property doesn't exist yet, defaultDir is used
 *                   as the initial location.
829
 *
Jan Möbius's avatar
Jan Möbius committed
830 831 832 833
 * @param parent         Parent qt widget
 * @param caption        Caption of the dialog
 * @param defaultDir     Default directory when dialog is shown
 * @param filter         name filters
834
 * @param selectedFilter currently selected filter
Jan Möbius's avatar
Jan Möbius committed
835 836
 * @param options        file dialog options
 * @param defaultSuffix  Optional default suffix used in the dialog
837 838 839 840 841
 */
DLLEXPORT
QString getSaveFileName(const QString &configProperty,
                        QWidget * parent = 0, const QString & caption = QString(),
                        const QString & defaultDir = QString(), const QString & filter = QString(),
842 843
                        QString * selectedFilter = 0, QFileDialog::Options options = 0,
                        const QString & defaultSuffix = QString() );
844

845
} /* namespace PluginFunctions */
846