| 1 |
/* |
| 2 |
* Extends the QuarterWidget with all functions the SoQtViewer has |
| 3 |
* Copyright (c) 2014 Stefan Tröger <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef SIM_COIN3D_SOQTQUARTERADAPTOR_H |
| 22 |
#define SIM_COIN3D_SOQTQUARTERADAPTOR_H |
| 23 |
|
| 24 |
#include <Inventor/SoType.h> |
| 25 |
#include <Inventor/actions/SoGetMatrixAction.h> |
| 26 |
#include <Inventor/actions/SoSearchAction.h> |
| 27 |
#include <Inventor/lists/SoCallbackList.h> |
| 28 |
#include <Inventor/sensors/SoTimerSensor.h> |
| 29 |
|
| 30 |
#include <Base/Color.h> |
| 31 |
|
| 32 |
#include "QuarterWidget.h" |
| 33 |
|
| 34 |
class QOpenGLContext; |
| 35 |
class QOpenGLWidget; |
| 36 |
class QSurfaceFormat; |
| 37 |
|
| 38 |
class SbViewportRegion; |
| 39 |
class SoCamera; |
| 40 |
class SoOrthographicCamera; |
| 41 |
class SoPerspectiveCamera; |
| 42 |
|
| 43 |
namespace SIM { |
| 44 |
namespace Coin3D { |
| 45 |
namespace Quarter { |
| 46 |
|
| 47 |
class SoQTQuarterAdaptor; |
| 48 |
using SoQTQuarterAdaptorCB = void (void* data, SoQTQuarterAdaptor* viewer); |
| 49 |
|
| 50 |
class QUARTER_DLL_API SoQTQuarterAdaptor : public QuarterWidget { |
| 51 |
|
| 52 |
Q_OBJECT |
| 53 |
|
| 54 |
public: |
| 55 |
explicit SoQTQuarterAdaptor(QWidget* parent = nullptr, |
| 56 |
const QOpenGLWidget* sharewidget = nullptr, |
| 57 |
Qt::WindowFlags flags = Qt::WindowFlags()); |
| 58 |
explicit SoQTQuarterAdaptor(const QSurfaceFormat& format, |
| 59 |
QWidget* parent = nullptr, |
| 60 |
const QOpenGLWidget* shareWidget = nullptr, |
| 61 |
Qt::WindowFlags flags = Qt::WindowFlags()); |
| 62 |
explicit SoQTQuarterAdaptor(QOpenGLContext* context, |
| 63 |
QWidget* parent = nullptr, |
| 64 |
const QOpenGLWidget* sharewidget = nullptr, |
| 65 |
Qt::WindowFlags flags = Qt::WindowFlags()); |
| 66 |
~SoQTQuarterAdaptor() override; |
| 67 |
|
| 68 |
//the functions available in soqtviewer but missing in quarter |
| 69 |
QWidget* getWidget(); |
| 70 |
QWidget* getGLWidget(); |
| 71 |
QWidget* getWidget() const; |
| 72 |
QWidget* getGLWidget() const; |
| 73 |
|
| 74 |
virtual void setCameraType(SoType type); |
| 75 |
SoCamera * getCamera() const; |
| 76 |
|
| 77 |
const SbViewportRegion & getViewportRegion() const; |
| 78 |
|
| 79 |
virtual void setViewing(bool enable); |
| 80 |
bool isViewing() const; |
| 81 |
|
| 82 |
void interactiveCountInc(); |
| 83 |
void interactiveCountDec(); |
| 84 |
int getInteractiveCount() const; |
| 85 |
|
| 86 |
void addStartCallback(SoQTQuarterAdaptorCB* func, void* data = nullptr); |
| 87 |
void addFinishCallback(SoQTQuarterAdaptorCB* func, void* data = nullptr); |
| 88 |
void removeStartCallback(SoQTQuarterAdaptorCB* func, void* data = nullptr); |
| 89 |
void removeFinishCallback(SoQTQuarterAdaptorCB* func, void* data = nullptr); |
| 90 |
|
| 91 |
virtual void setSeekMode(bool enable); |
| 92 |
bool isSeekMode() const; |
| 93 |
bool seekToPoint(const SbVec2s& screenpos); |
| 94 |
void seekToPoint(const SbVec3f& scenepos); |
| 95 |
void setSeekTime(float seconds); |
| 96 |
float getSeekTime() const; |
| 97 |
void setSeekDistance(float distance); |
| 98 |
float getSeekDistance() const; |
| 99 |
void setSeekValueAsPercentage(bool on); |
| 100 |
bool isSeekValuePercentage() const; |
| 101 |
|
| 102 |
virtual float getPickRadius() const {return this->pickRadius;} |
| 103 |
virtual void setPickRadius(float pickRadius); |
| 104 |
|
| 105 |
virtual void saveHomePosition(); |
| 106 |
virtual void resetToHomePosition(); |
| 107 |
virtual bool hasHomePosition() const |
| 108 |
{ |
| 109 |
return m_storedcamera != nullptr; |
| 110 |
} |
| 111 |
|
| 112 |
void setSceneGraph(SoNode* root) override |
| 113 |
{ |
| 114 |
QuarterWidget::setSceneGraph(root); |
| 115 |
} |
| 116 |
|
| 117 |
bool processSoEvent(const SoEvent* event) override; |
| 118 |
void paintEvent(QPaintEvent* event) override; |
| 119 |
|
| 120 |
//this functions still need to be ported |
| 121 |
virtual void afterRealizeHook() {} //enables spacenav and joystick in soqt, dunno if this is needed |
| 122 |
|
| 123 |
private: |
| 124 |
void init(); |
| 125 |
static void convertPerspective2Ortho(const SoPerspectiveCamera* in, SoOrthographicCamera* out); |
| 126 |
static void convertOrtho2Perspective(const SoOrthographicCamera* in, SoPerspectiveCamera* out); |
| 127 |
void getCameraCoordinateSystem(SoCamera * camera, SoNode * root, SbMatrix & matrix, SbMatrix & inverse); |
| 128 |
static void seeksensorCB(void * data, SoSensor * sensor); |
| 129 |
void moveCameraScreen(const SbVec2f & screenpos); |
| 130 |
void resetFrameCounter(); |
| 131 |
SbVec2f addFrametime(double ft); |
| 132 |
|
| 133 |
bool m_viewingflag = false; |
| 134 |
int m_interactionnesting = 0; |
| 135 |
SoCallbackList m_interactionStartCallback; |
| 136 |
SoCallbackList m_interactionEndCallback; |
| 137 |
|
| 138 |
double frametime = 0.0; |
| 139 |
double drawtime = 0.0; |
| 140 |
double starttime = 0.0; |
| 141 |
int framecount = 0.0; |
| 142 |
|
| 143 |
// Seek functionality |
| 144 |
SoTimerSensor* m_seeksensor = nullptr; |
| 145 |
float m_seekperiod = 0.0F; |
| 146 |
bool m_inseekmode = false; |
| 147 |
SbVec3f m_camerastartposition, m_cameraendposition; |
| 148 |
SbRotation m_camerastartorient, m_cameraendorient; |
| 149 |
float m_seekdistance = 0.0F; |
| 150 |
bool m_seekdistanceabs = false; |
| 151 |
SoSearchAction searchaction; |
| 152 |
SoGetMatrixAction matrixaction; |
| 153 |
float pickRadius = 0.0F; |
| 154 |
// Home position storage. |
| 155 |
SoNode * m_storedcamera = nullptr; |
| 156 |
|
| 157 |
protected: |
| 158 |
static void draw2DString(const char * str, SbVec2s glsize, SbVec2f position, Base::Color color); |
| 159 |
static void printString(const char * str); |
| 160 |
SbVec2f framesPerSecond; // NOLINT |
| 161 |
}; |
| 162 |
|
| 163 |
} //Quarter |
| 164 |
} //Coin3D |
| 165 |
} // |
| 166 |
|
| 167 |
#endif // SIM_COIN3D_SOQTQUARTERADAPTOR_H |