QGIS API Documentation 3.43.0-Master (a93bf8b6462)
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 "qgs3dmapcanvas.h"
21
23#include <Qt3DCore/QEntity>
24#include <Qt3DExtras/QText2DEntity>
25#include <Qt3DRender/QCamera>
26#include <Qt3DRender/QRenderSettings>
27#include <Qt3DRender/QScreenRayCaster>
28#include <QVector3D>
29
30#include <QtWidgets/QMenu>
31#include "qgs3daxissettings.h"
32
33#define SIP_NO_FILE
34
36class Qgs3DMapScene;
38
51class _3D_EXPORT Qgs3DAxis : public QObject
52{
53 Q_OBJECT
54 public:
64 Qgs3DAxis( Qgs3DMapCanvas *canvas, Qt3DCore::QEntity *parent3DScene, Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
65 ~Qgs3DAxis() override;
66
76 QVector3D from3DTo2DLabelPosition( const QVector3D &sourcePos, Qt3DRender::QCamera *sourceCamera, Qt3DRender::QCamera *destCamera );
77
82 void onViewportScaleFactorChanged( double scaleFactor );
83
90 bool handleEvent( QEvent *event );
91
92 public slots:
93
95 void onAxisSettingsChanged();
96
97 private slots:
98
99 void onCameraUpdate();
100 void onAxisViewportSizeUpdate();
101
102 // axis picking and menu
103 void onTouchedByRay( const Qt3DRender::QAbstractRayCaster::Hits &hits );
104 void onAxisModeChanged( Qgs3DAxisSettings::Mode mode );
105
106 private:
107 void createAxisScene();
108 void createAxis( Qt::Axis axis );
109 void createCube();
110 void setEnableCube( bool show );
111 void setEnableAxis( bool show );
112 void updateAxisLabelPosition();
113 void updateAxisLabelText( Qt3DExtras::QText2DEntity *textEntity, const QString &text );
114 QFont createFont( int pointSize );
115
116 void constructAxisScene( Qt3DCore::QEntity *parent3DScene );
117 void constructLabelsScene( Qt3DCore::QEntity *parent3DScene );
118
119 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &font, const QMatrix4x4 &rotation, const QVector3D &translation );
120
121 // axis picking and menu
122 void init3DObjectPicking();
123 void createMenu();
124 void hideMenu();
125 void displayMenuAt( const QPoint &position );
126
127 Qgs3DMapSettings *mMapSettings = nullptr;
128 Qgs3DMapCanvas *mCanvas = nullptr;
129 Qgs3DMapScene *mMapScene = nullptr;
130 QgsCameraController *mCameraController = nullptr;
131
132 float mCylinderLength = 40.0f;
133 int mFontSize = 12;
134
135 Qgs3DAxisRenderView *mRenderView = nullptr;
136 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
137 Qt3DRender::QCamera *mAxisCamera = nullptr;
138
139 Qt3DCore::QEntity *mAxisRoot = nullptr;
140 Qt3DCore::QEntity *mCubeRoot = nullptr;
141 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
142
143 Qt3DExtras::QText2DEntity *mTextX = nullptr;
144 Qt3DExtras::QText2DEntity *mTextY = nullptr;
145 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
146 QVector3D mTextCoordX;
147 QVector3D mTextCoordY;
148 QVector3D mTextCoordZ;
149 Qt3DCore::QTransform *mTextTransformX = nullptr;
150 Qt3DCore::QTransform *mTextTransformY = nullptr;
151 Qt3DCore::QTransform *mTextTransformZ = nullptr;
153 QVector3D mPreviousVector;
154 double mAxisScaleFactor = 1.0;
155
156 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
157 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
158
159 // axis picking and menu
160 Qt3DRender::QScreenRayCaster *mScreenRayCaster = nullptr;
161 bool mIsDragging = false;
162 bool mHasClicked = false;
163 QPoint mLastClickedPos;
164 Qt::MouseButton mLastClickedButton;
165 QCursor mPreviousCursor = Qt::ArrowCursor;
166 Qt3DRender::QPickingSettings::PickMethod mDefaultPickingMethod;
167 QMenu *mMenu = nullptr;
168};
169
170#endif // QGS3DAXIS_H
3D axis render view.
Mode
Axis representation enum.
Display 3D ortho axis in the main 3D view.
Definition qgs3daxis.h: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).