QGIS API Documentation 4.3.0-Master (bf28115e945)
Loading...
Searching...
No Matches
qgs3daxis.h
Go to the documentation of this file.
1/***************************************************************************
2 qgs3daxis.h
3 --------------------------------------
4 Date : March 2022
5 Copyright : (C) 2022 by Jean Felder
6 Email : jean dot felder at oslandia dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGS3DAXIS_H
17#define QGS3DAXIS_H
18
19#include "qgis_3d.h"
20#include "qgs3daxissettings.h"
22#include "qobjectuniqueptr.h"
23
24#include <QCursor>
25#include <QObject>
26#include <QVector3D>
27#include <Qt3DRender/QAbstractRayCaster>
28#include <Qt3DRender/QPickingSettings>
29
30#define SIP_NO_FILE
31
32namespace Qt3DCore
33{
34 class QEntity;
35 class QTransform;
36} //namespace Qt3DCore
37
38namespace Qt3DExtras
39{
40 class QText2DEntity;
41}
42
43namespace Qt3DRender
44{
45 class QCamera;
46 class QScreenRayCaster;
47} //namespace Qt3DRender
48
50class Qgs3DMapCanvas;
52class Qgs3DMapScene;
54class QMenu;
55
68class _3D_EXPORT Qgs3DAxis : public QObject
69{
70 Q_OBJECT
71 public:
81 Qgs3DAxis( Qgs3DMapCanvas *canvas, Qt3DCore::QEntity *parent3DScene, Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
82 ~Qgs3DAxis() override;
83
93 QVector3D from3DTo2DLabelPosition( const QVector3D &sourcePos, Qt3DRender::QCamera *sourceCamera, Qt3DRender::QCamera *destCamera );
94
99 void onViewportScaleFactorChanged( double scaleFactor );
100
107 bool handleEvent( QEvent *event );
108
109 public slots:
110
113
114 private slots:
115
116 void onCameraUpdate();
117 void onAxisViewportSizeUpdate();
118
119 // axis picking and menu
120 void onTouchedByRay( const Qt3DRender::QAbstractRayCaster::Hits &hits );
121 void onAxisModeChanged( Qgs3DAxisSettings::Mode mode );
122
123 private:
124 void createAxisScene();
125 void createAxis( Qt::Axis axis );
126 void createCube();
127 void setEnableCube( bool show );
128 void setEnableAxis( bool show );
129 void updateAxisLabelPosition();
130 void updateAxisLabelText( Qt3DExtras::QText2DEntity *textEntity, const QString &text );
131 QFont createFont( int pointSize );
132
133 void constructAxisScene( Qt3DCore::QEntity *parent3DScene );
134 void constructLabelsScene( Qt3DCore::QEntity *parent3DScene );
135
136 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &font, const QMatrix4x4 &rotation, const QVector3D &translation );
137
138 // axis picking and menu
139 void init3DObjectPicking();
140 void createMenu();
141 void hideMenu();
142 void displayMenuAt( const QPoint &position );
143
144 Qgs3DMapSettings *mMapSettings = nullptr;
145 Qgs3DMapCanvas *mCanvas = nullptr;
146 Qgs3DMapScene *mMapScene = nullptr;
147 QgsCameraController *mCameraController = nullptr;
148
149 float mCylinderLength = 40.0f;
150 int mFontSize = 12;
151
152 Qgs3DAxisRenderView *mRenderView = nullptr;
153 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
154 Qt3DRender::QCamera *mAxisCamera = nullptr;
155
156 Qt3DCore::QEntity *mAxisRoot = nullptr;
157 Qt3DCore::QEntity *mCubeRoot = nullptr;
158 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
159
160 Qt3DExtras::QText2DEntity *mTextX = nullptr;
161 Qt3DExtras::QText2DEntity *mTextY = nullptr;
162 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
163 QVector3D mTextCoordX;
164 QVector3D mTextCoordY;
165 QVector3D mTextCoordZ;
166 Qt3DCore::QTransform *mTextTransformX = nullptr;
167 Qt3DCore::QTransform *mTextTransformY = nullptr;
168 Qt3DCore::QTransform *mTextTransformZ = nullptr;
170 QVector3D mPreviousVector;
171 double mAxisScaleFactor = 1.0;
172
173 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
174 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
175
176 // axis picking and menu
177 Qt3DRender::QScreenRayCaster *mScreenRayCaster = nullptr;
178 bool mIsDragging = false;
179 bool mHasClicked = false;
180 QPoint mLastClickedPos;
181 Qt::MouseButton mLastClickedButton;
182 QCursor mPreviousCursor = Qt::ArrowCursor;
183 Qt3DRender::QPickingSettings::PickMethod mDefaultPickingMethod;
185};
186
187#endif // QGS3DAXIS_H
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
3D axis render view.
Mode
Axis representation enum.
bool handleEvent(QEvent *event)
Returns if the 3D axis controller will handle the specified event.
void onAxisSettingsChanged()
Force update of the axis and the viewport when a setting has changed.
void onViewportScaleFactorChanged(double scaleFactor)
Used as callback from renderview when viewport scale factor changes.
QVector3D from3DTo2DLabelPosition(const QVector3D &sourcePos, Qt3DRender::QCamera *sourceCamera, Qt3DRender::QCamera *destCamera)
Project a 3D position from sourceCamera to a 2D position for destCamera.
Qgs3DAxis(Qgs3DMapCanvas *canvas, Qt3DCore::QEntity *parent3DScene, Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map)
Default Qgs3DAxis constructor.
Definition qgs3daxis.cpp:52
Convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS.
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition of the world.
Object that controls camera movement based on user input.
Represents a coordinate reference system (CRS).