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