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