Developer Documentation
PluginFunctions.hh
Go to the documentation of this file.
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42//=============================================================================
43//
44// Standard Functions
45//
46//=============================================================================
47
53#pragma once
54
55
56#include <QPair>
57#include <QFileDialog>
58
60#include <OpenFlipper/common/OFGLWidget.hh>
61
63#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
64
65//== FORWARDDECLARATIONS ======================================================
67
70namespace PluginFunctions {
71
72//=======================================
73// Get Source/Target objects
76//=======================================
77
84bool getPickedObject(const size_t _node_idx , BaseObjectData*& _object);
85
88//=======================================
89// Get Objects by their identifier
92//=======================================
93
100bool getSourceIdentifiers( std::vector<int>& _identifiers );
101
108bool getTargetIdentifiers( std::vector<int>& _identifiers );
109
116bool getAllObjectIdentifiers( std::vector<int>& _identifiers );
117
124bool getAllMeshes( std::vector<int>& _identifiers );
125
137bool getObject( const int _identifier , BaseObject*& _object );
138
143bool getObject( const int _identifier , BaseObjectData*& _object );
144
148int getObjectId( const QString& _name );
149
156bool objectExists( const int _identifier );
157
160int objectCount();
161
164int targetCount();
165
168int sourceCount();
169
172int visibleCount();
173
176//=======================================
177// Get/set status of examiner
180//=======================================
181
182
185int viewers( );
186
196
204
207void setActiveExaminer( const unsigned int _id );
208
211unsigned int activeExaminer();
212
215QString getEncodedExaminerView();
216
219QString getEncodedExaminerView(int _viewerId);
220
223void setEncodedExaminerView(const QString &_view );
224
227void setEncodedExaminerView(int _viewerId , QString _view );
228
233void setSceneCenter(const ACG::Vec3d& _center, int _viewer );
234
241bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr );
242
248bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr );
249
257bool scenegraphPick( const unsigned int _examiner ,ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, BaseObjectData*& _object, size_t &_targetIdx, const bool _refine ,ACG::Vec3d *_hitPointPtr );
258
266bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, BaseObjectData*& _object, size_t &_targetIdx, const bool _refine, ACG::Vec3d *_hitPointPtr );
267
268
275 const QRegion& _region,
276 QList<QPair<size_t, size_t> >& _list,
277 QVector<float>* _depths = 0,
278 QVector<ACG::Vec3d>* _points = 0);
279
284bool scenegraphRegionPick( const unsigned int _examiner,
285 ACG::SceneGraph::PickTarget _pickTarget,
286 const QRegion& _region,
287 QList<QPair<size_t, size_t> >& _list,
288 QVector<float>* _depths = 0,
289 QVector<ACG::Vec3d>* _points = 0);
290
297
300const std::string pickMode ();
301
304void pickMode ( const std::string& _mode);
305
308void getCurrentViewImage(QImage& _image);
309
320
328
336
344
355
358void actionMode ( Viewer::ActionMode _mode);
359
363
366void shareGLWidget(OFGLWidget* _widget);
367
370OFGLWidget* shareGLWidget();
371
377void allowRotation(bool _mode);
378
383QPoint mapToGlobal( const QPoint _point );
384
389QPoint mapToLocal( const QPoint _point );
390
397
404
408QStringList collectObjectComments(bool visibleOnly, bool targetedOnly);
409
413QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly);
414
418
428QPoint adjustForDevicePixelRatio(QPoint const & point);
430QPointF adjustForDevicePixelRatio(QPointF const & point);
431
435//=======================================
436// Iterators for object Access
439//=======================================
440
441typedef QStringList IteratorRestriction;
442
443const QStringList ALL_OBJECTS;
444const QStringList TARGET_OBJECTS ("target");
445const QStringList SOURCE_OBJECTS ("source");
446
455
456 public :
457
460
463
466
469
477 ObjectIterator(const IteratorRestriction &_restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
478
480 ObjectIterator(BaseObjectData* pos, const IteratorRestriction &_restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
481
482 ObjectIterator(const ObjectIterator &) = default;
483
485 operator value_handle() { return pos_; };
486
488 bool operator==( const ObjectIterator& _rhs) const;
489
491 bool operator!=( const ObjectIterator& _rhs) const;
492
495
497 pointer operator->();
498
500 ObjectIterator& operator++();
501
503 ObjectIterator& operator--();
504
506 BaseObjectData* operator*();
507
509 BaseObjectData* index() { return pos_; };
510
511 private :
514
517
520
524 inline void proceedToNextBaseObjectData(BaseObject*& _object);
525};
526
527
533{
534public:
535 using iterator_category = std::forward_iterator_tag;
537 using difference_type = std::ptrdiff_t;
538 using pointer = BaseObjectData*;
539 using reference = BaseObjectData&;
540
541 explicit ObjectReferenceIterator(IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
542 it_(_restriction, _dataType)
543 {
544 }
545
546 explicit ObjectReferenceIterator(BaseObjectData* _pos, IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
547 it_(_pos, _restriction, _dataType)
548 {
549 }
550
552 it_(_rhs.it_)
553 {
554 }
555
557 {
558 if (this != &_rhs) {
559 it_ = _rhs.it_;
560 }
561 return *this;
562 }
563
564 ObjectReferenceIterator& operator++() {
565 ++it_;
566 return *this;
567 }
568
569 ObjectReferenceIterator operator++(int) {
570 ObjectReferenceIterator copy(*this);
571 operator++();
572 return copy;
573 }
574
575 bool operator==(const ObjectReferenceIterator& _rhs) const {
576 return it_ == _rhs.it_;
577 }
578
579 bool operator!=(const ObjectReferenceIterator& _rhs) const {
580 return it_ != _rhs.it_;
581 }
582
583 BaseObjectData& operator*() {
584 return **it_;
585 }
586
587 BaseObjectData* operator->() {
588 return *it_;
589 }
590
591private:
592 ObjectIterator it_;
593};
594
595
605public:
606 explicit ObjectRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
607 restriction_(_restriction),
608 dataType_(_dataType)
609 {
610 }
611
612 ObjectIterator begin() const {
613 return ObjectIterator(restriction_, dataType_);
614 }
615
616 ObjectIterator end() const {
617 return ObjectIterator(0);
618 }
619
620private:
621 IteratorRestriction restriction_;
622 DataType dataType_;
623};
624
625
635public:
636 explicit ObjectReferenceRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
637 restriction_(_restriction),
638 dataType_(_dataType)
639 {
640 }
641
642 ObjectReferenceIterator begin() const {
643 return ObjectReferenceIterator(restriction_, dataType_);
644 }
645
646 ObjectReferenceIterator end() const {
647 return ObjectReferenceIterator(0);
648 }
649
650private:
651 IteratorRestriction restriction_;
652 DataType dataType_;
653};
654
655
670
671
687
688
697
698 public :
699
702
705
708
711
719 BaseObjectIterator(const IteratorRestriction &_restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
720
722 BaseObjectIterator(BaseObject* pos, const IteratorRestriction &_restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL );
723
725 operator value_handle() { return pos_; };
726
728 bool operator==( const BaseObjectIterator& _rhs);
729
731 bool operator!=( const BaseObjectIterator& _rhs);
732
734 BaseObjectIterator& operator=( const BaseObjectIterator& _rhs);
735
737 pointer operator->();
738
740 BaseObjectIterator& operator++();
741
743 BaseObjectIterator& operator--();
744
746 BaseObject* operator*();
747
749 BaseObject* index() { return pos_; };
750
751 private :
754
757
760
761};
762
763// /// Return Iterator to Mesh End
764// MeshIterator meshes_end();
765
769
773
776//=======================================
777// Dont Use functions below!!!
780//=======================================
781
784void setDataRoot( BaseObject* _root );
785
788//=======================================
791//=======================================
792
800
810int viewerId();
811
815
836#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
837QString getOpenFileName(const QString &configProperty,
838 QWidget * parent = nullptr, const QString & caption = QString(),
839 const QString & defaultDir = QString(), const QString & filter = QString(),
840 QString * selectedFilter = nullptr, QFileDialog::Options options = 0);
841#else
842QString getOpenFileName(const QString &configProperty,
843 QWidget * parent = nullptr, const QString & caption = QString(),
844 const QString & defaultDir = QString(), const QString & filter = QString(),
845 QString * selectedFilter = nullptr, QFileDialog::Options options = QFileDialog::Options() );
846#endif
847
848
869#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
870QString getSaveFileName(const QString &configProperty,
871 QWidget * parent = nullptr, const QString & caption = QString(),
872 const QString & defaultDir = QString(), const QString & filter = QString(),
873 QString * selectedFilter = nullptr, QFileDialog::Options options = 0,
874 const QString & defaultSuffix = QString() );
875#else
876QString getSaveFileName(const QString &configProperty,
877 QWidget * parent = nullptr, const QString & caption = QString(),
878 const QString & defaultDir = QString(), const QString & filter = QString(),
879 QString * selectedFilter = nullptr, QFileDialog::Options options = QFileDialog::Options(),
880 const QString & defaultSuffix = QString() );
881#endif
882
883
884} /* namespace PluginFunctions */
885
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
#define DLLEXPORT
ActionMode
Enum listing action modes of the viewers.
Predefined datatypes.
Definition: DataTypes.hh:83
Core Data Iterator used to iterate over all objects (Including groups)
BaseObject * pos_
current position of the iterator
IteratorRestriction restriction_
Restriction of the iterator.
value_type * pointer
basic pointer type
BaseObject * index()
return current position of the iterator
value_type & reference
reference type
DataType dataType_
returned data types of the iterator
BaseObject * value_handle
handle type (just an int)
BaseObject value_type
type of the Objects the iterator works on
value_type & reference
reference type
BaseObjectData * index()
return current position of the iterator
BaseObjectData * value_handle
handle type (just an int)
BaseObjectData value_type
type of the Objects the iterator works on
BaseObjectData * pos_
current position of the iterator
value_type * pointer
basic pointer type
ObjectIterator & operator=(const ObjectIterator &)=default
assign iterators
DataType dataType_
returned data types of the iterator
IteratorRestriction restriction_
Restriction of the iterator.
Range adapter for ObjectIterator.
Helper class that wraps an ObjectIterator to return a reference instead of a pointer.
Range adapter for ObjectIterator.
PickTarget
What target to use for picking.
Definition: PickTarget.hh:74
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
void getCurrentViewImage(QImage &_image)
Returns a QImage of the current View.
int targetCount()
Get the number of target objects.
void addObjectRenderingNode(ACG::SceneGraph::BaseNode *_node)
Add scenegraph node modifing object rendering.
void addGlobalNode(ACG::SceneGraph::BaseNode *_node)
Add a global node.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
int viewerId()
Return unique viewer id.
void shareGLWidget(OFGLWidget *_widget)
Sets the main QGLWidget for gl data sharing.
int getObjectId(const QString &_name)
bool scenegraphRegionPick(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths, QVector< ACG::Vec3d > *_points)
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly)
QPoint adjustForDevicePixelRatio(const QPoint &point)
int sourceCount()
Get the number of source objects.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
QPoint mapToGlobal(const QPoint _point)
Map coordinates of GL Widget to global coordinates.
void setDataRoot(BaseObject *_root)
ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
int objectCount()
Get the number of available objects.
QString getOpenFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
const std::string pickMode()
Get the current Picking mode.
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly)
QPoint mapToLocal(const QPoint _point)
Map global coordinates to GL Widget local coordinates.
QString getEncodedExaminerView()
Get the encoded view for the active examiner.
void setSceneCenter(const ACG::Vec3d &_center, int _viewer)
int viewers()
Get the number of viewers.
bool getAllObjectIdentifiers(std::vector< int > &_identifiers)
Get identifiers of all objects.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
BaseObject *& objectRoot()
Get the root of the object structure.
ViewObjectMarker * defaultViewObjectMarker()
Get the default ViewObjectMarker.
bool objectExists(const int _identifier)
Check if an object with this identifier exists.
bool examinerLightHandling()
returns if internal light handling is active.
QString getSaveFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QString &defaultSuffix)
bool getSourceIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a source object.
void traverse(ACG::SceneGraph::MouseEventAction &_action)
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
QStringList IteratorRestriction
Iterable object range.
int visibleCount()
Get the number of visible objects.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Viewer::ActionMode actionMode()
Get the current Action mode.
void setEncodedExaminerView(const QString &_view)
Set the encoded view for the active examiner.
void allowRotation(bool _mode, int _viewer)
void setActiveExaminer(const unsigned int _id)
Set the active id of the examiner which got the last mouse events.
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.
void disableExaminerLightHandling()
Disable the core light handling.
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
void addGlobalStatusNode(ACG::SceneGraph::BaseNode *_node)
Adds a global status node.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
void setViewObjectMarker(ViewObjectMarker *_marker)
const QStringList ALL_OBJECTS
Iterable object range.
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.