QGIS API Documentation 3.43.0-Master (a6cade80589)
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 void onCameraViewChange( float pitch, float yaw );
106
107 void onCameraViewChangeHome() { onCameraViewChange( 45.0f, 45.0f ); }
108 void onCameraViewChangeTop() { onCameraViewChange( 0.0f, 90.0f ); }
109 void onCameraViewChangeNorth() { onCameraViewChange( 90.0f, 180.0f ); }
110 void onCameraViewChangeEast() { onCameraViewChange( 90.0f, 90.0f ); }
111 void onCameraViewChangeSouth() { onCameraViewChange( 90.0f, 0.0f ); }
112 void onCameraViewChangeWest() { onCameraViewChange( 90.0f, -90.0f ); }
113 void onCameraViewChangeBottom() { onCameraViewChange( 180.0f, 0.0f ); }
114
115 private:
116 void createAxisScene();
117 void createAxis( Qt::Axis axis );
118 void createCube();
119 void setEnableCube( bool show );
120 void setEnableAxis( bool show );
121 void updateAxisLabelPosition();
122 void updateAxisLabelText( Qt3DExtras::QText2DEntity *textEntity, const QString &text );
123 QFont createFont( int pointSize );
124
125 void constructAxisScene( Qt3DCore::QEntity *parent3DScene );
126 void constructLabelsScene( Qt3DCore::QEntity *parent3DScene );
127
128 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &font, const QMatrix4x4 &rotation, const QVector3D &translation );
129
130 // axis picking and menu
131 void init3DObjectPicking();
132 bool handleKeyEvent( QKeyEvent *keyEvent );
133 void createMenu();
134 void hideMenu();
135 void displayMenuAt( const QPoint &position );
136
137 Qgs3DMapSettings *mMapSettings = nullptr;
138 Qgs3DMapCanvas *mCanvas = nullptr;
139 Qgs3DMapScene *mMapScene = nullptr;
140 QgsCameraController *mCameraController = nullptr;
141
142 float mCylinderLength = 40.0f;
143 int mFontSize = 12;
144
145 Qgs3DAxisRenderView *mRenderView = nullptr;
146 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
147 Qt3DRender::QCamera *mAxisCamera = nullptr;
148
149 Qt3DCore::QEntity *mAxisRoot = nullptr;
150 Qt3DCore::QEntity *mCubeRoot = nullptr;
151 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
152
153 Qt3DExtras::QText2DEntity *mTextX = nullptr;
154 Qt3DExtras::QText2DEntity *mTextY = nullptr;
155 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
156 QVector3D mTextCoordX;
157 QVector3D mTextCoordY;
158 QVector3D mTextCoordZ;
159 Qt3DCore::QTransform *mTextTransformX = nullptr;
160 Qt3DCore::QTransform *mTextTransformY = nullptr;
161 Qt3DCore::QTransform *mTextTransformZ = nullptr;
163 QVector3D mPreviousVector;
164 double mAxisScaleFactor = 1.0;
165
166 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
167 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
168
169 // axis picking and menu
170 Qt3DRender::QScreenRayCaster *mScreenRayCaster = nullptr;
171 bool mIsDragging = false;
172 bool mHasClicked = false;
173 QPoint mLastClickedPos;
174 Qt::MouseButton mLastClickedButton;
175 QCursor mPreviousCursor = Qt::ArrowCursor;
176 Qt3DRender::QPickingSettings::PickMethod mDefaultPickingMethod;
177 QMenu *mMenu = nullptr;
178};
179
180#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).