QGIS API Documentation 3.99.0-Master (c22de0620c0)
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
23#include <QCursor>
24#include <QObject>
25#include <QVector3D>
26#include <Qt3DRender/QAbstractRayCaster>
27#include <Qt3DRender/QPickingSettings>
28
29#define SIP_NO_FILE
30
31namespace Qt3DCore
32{
33 class QEntity;
34 class QTransform;
35} //namespace Qt3DCore
36
37namespace Qt3DExtras
38{
39 class QText2DEntity;
40}
41
42namespace Qt3DRender
43{
44 class QCamera;
45 class QScreenRayCaster;
46} //namespace Qt3DRender
47
49class Qgs3DMapCanvas;
51class Qgs3DMapScene;
53class QMenu;
54
67class _3D_EXPORT Qgs3DAxis : public QObject
68{
69 Q_OBJECT
70 public:
80 Qgs3DAxis( Qgs3DMapCanvas *canvas, Qt3DCore::QEntity *parent3DScene, Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
81 ~Qgs3DAxis() override;
82
92 QVector3D from3DTo2DLabelPosition( const QVector3D &sourcePos, Qt3DRender::QCamera *sourceCamera, Qt3DRender::QCamera *destCamera );
93
98 void onViewportScaleFactorChanged( double scaleFactor );
99
106 bool handleEvent( QEvent *event );
107
108 public slots:
109
112
113 private slots:
114
115 void onCameraUpdate();
116 void onAxisViewportSizeUpdate();
117
118 // axis picking and menu
119 void onTouchedByRay( const Qt3DRender::QAbstractRayCaster::Hits &hits );
120 void onAxisModeChanged( Qgs3DAxisSettings::Mode mode );
121
122 private:
123 void createAxisScene();
124 void createAxis( Qt::Axis axis );
125 void createCube();
126 void setEnableCube( bool show );
127 void setEnableAxis( bool show );
128 void updateAxisLabelPosition();
129 void updateAxisLabelText( Qt3DExtras::QText2DEntity *textEntity, const QString &text );
130 QFont createFont( int pointSize );
131
132 void constructAxisScene( Qt3DCore::QEntity *parent3DScene );
133 void constructLabelsScene( Qt3DCore::QEntity *parent3DScene );
134
135 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &font, const QMatrix4x4 &rotation, const QVector3D &translation );
136
137 // axis picking and menu
138 void init3DObjectPicking();
139 void createMenu();
140 void hideMenu();
141 void displayMenuAt( const QPoint &position );
142
143 Qgs3DMapSettings *mMapSettings = nullptr;
144 Qgs3DMapCanvas *mCanvas = nullptr;
145 Qgs3DMapScene *mMapScene = nullptr;
146 QgsCameraController *mCameraController = nullptr;
147
148 float mCylinderLength = 40.0f;
149 int mFontSize = 12;
150
151 Qgs3DAxisRenderView *mRenderView = nullptr;
152 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
153 Qt3DRender::QCamera *mAxisCamera = nullptr;
154
155 Qt3DCore::QEntity *mAxisRoot = nullptr;
156 Qt3DCore::QEntity *mCubeRoot = nullptr;
157 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
158
159 Qt3DExtras::QText2DEntity *mTextX = nullptr;
160 Qt3DExtras::QText2DEntity *mTextY = nullptr;
161 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
162 QVector3D mTextCoordX;
163 QVector3D mTextCoordY;
164 QVector3D mTextCoordZ;
165 Qt3DCore::QTransform *mTextTransformX = nullptr;
166 Qt3DCore::QTransform *mTextTransformY = nullptr;
167 Qt3DCore::QTransform *mTextTransformZ = nullptr;
169 QVector3D mPreviousVector;
170 double mAxisScaleFactor = 1.0;
171
172 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
173 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
174
175 // axis picking and menu
176 Qt3DRender::QScreenRayCaster *mScreenRayCaster = nullptr;
177 bool mIsDragging = false;
178 bool mHasClicked = false;
179 QPoint mLastClickedPos;
180 Qt::MouseButton mLastClickedButton;
181 QCursor mPreviousCursor = Qt::ArrowCursor;
182 Qt3DRender::QPickingSettings::PickMethod mDefaultPickingMethod;
183 QMenu *mMenu = nullptr;
184};
185
186#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: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).