QGIS API Documentation 3.27.0-Master (9c08adf5ef)
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
22#include <Qt3DCore/QEntity>
23#include <Qt3DExtras/Qt3DWindow>
24#include <Qt3DExtras/QText2DEntity>
25#include <Qt3DRender/QCamera>
26#include <Qt3DRender/QViewport>
27#include <Qt3DRender/QPickEvent>
28#include <Qt3DRender/QScreenRayCaster>
29#include <QVector3D>
30#include <QVector2D>
31
32#include <Qt3DRender/QLayer>
33#include <Qt3DRender/QBuffer>
34#include <Qt3DRender/QGeometryRenderer>
35
36#include <QtWidgets/QMenu>
37#include "qgs3dmapsettings.h"
38
39#define SIP_NO_FILE
40
42class Qgs3DMapScene;
43
56class _3D_EXPORT Qgs3DAxis : public QObject
57{
58 Q_OBJECT
59 public:
60
69 Qgs3DAxis( Qt3DExtras::Qt3DWindow *parentWindow, Qt3DCore::QEntity *parent3DScene,
70 Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
71 ~Qgs3DAxis() override;
72
84 QVector3D from3DTo2DLabelPosition( const QVector3D &sourcePos,
85 Qt3DRender::QCamera *sourceCamera, Qt3DRender::QViewport *sourceViewport,
86 Qt3DRender::QCamera *destCamera, Qt3DRender::QViewport *destViewport,
87 const QSize &destSize );
88
89 public slots:
90
92 void onAxisSettingsChanged( );
93
94 private slots:
95
96 void onCameraUpdate( );
97 void onAxisViewportSizeUpdate( int val = 0 );
98
99 // axis picking and menu
100 void onTouchedByRay( const Qt3DRender::QAbstractRayCaster::Hits &hits );
101
102 void onAxisModeChanged( Qgs3DAxisSettings::Mode mode );
103 void onAxisHorizPositionChanged( Qt::AnchorPoint pos );
104 void onAxisVertPositionChanged( Qt::AnchorPoint pos );
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 void onTextXChanged( const QString &text );
116 void onTextYChanged( const QString &text );
117 void onTextZChanged( const QString &text );
118
119 private:
120
121 void createAxisScene();
122 void createAxis( Qt::Axis axis );
123 void createCube( );
124 void setEnableCube( bool show );
125 void setEnableAxis( bool show );
126 void updateAxisLabelPosition();
127
128 Qt3DRender::QViewport *constructAxisViewport( Qt3DCore::QEntity *parent3DScene );
129 Qt3DRender::QViewport *constructLabelViewport( Qt3DCore::QEntity *parent3DScene, const QRectF &parentViewportSize );
130
131 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &f, const QMatrix4x4 &rotation, const QVector3D &translation );
132
133 // axis picking and menu
134 void init3DObjectPicking( );
135 bool eventFilter( QObject *watched, QEvent *event ) override;
136 void createKeyboardShortCut();
137 void createMenu();
138 void hideMenu();
139 void displayMenuAt( const QPoint &position );
140
141 Qgs3DMapSettings *mMapSettings = nullptr;
142 Qt3DExtras::Qt3DWindow *mParentWindow = nullptr;
143 Qgs3DMapScene *mMapScene = nullptr;
144 QgsCameraController *mCameraController = nullptr;
145
146 float mCylinderLength = 40.0f;
147 int mFontSize = 10;
148
149 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
150 Qt3DRender::QLayer *mAxisSceneLayer = nullptr;
151 Qt3DRender::QCamera *mAxisCamera = nullptr;
152 Qt3DRender::QViewport *mAxisViewport = nullptr;
153
154 Qt3DCore::QEntity *mAxisRoot = nullptr;
155 Qt3DCore::QEntity *mCubeRoot = nullptr;
156 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
157
158 Qt3DExtras::QText2DEntity *mTextX = nullptr;
159 Qt3DExtras::QText2DEntity *mTextY = nullptr;
160 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
161 QVector3D mTextCoordX;
162 QVector3D mTextCoordY;
163 QVector3D mTextCoordZ;
164 Qt3DCore::QTransform *mTextTransformX = nullptr;
165 Qt3DCore::QTransform *mTextTransformY = nullptr;
166 Qt3DCore::QTransform *mTextTransformZ = nullptr;
168 QVector3D mPreviousVector;
169 double mAxisScaleFactor = 1.0;
170
171 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
172 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
173 Qt3DRender::QViewport *mTwoDLabelViewport = 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 QMenu *mMenu = nullptr;
183
184};
185
192class Qgs3DWiredMesh : public Qt3DRender::QGeometryRenderer
193{
194 Q_OBJECT
195
196 public:
197
201 Qgs3DWiredMesh( Qt3DCore::QNode *parent = nullptr );
202 ~Qgs3DWiredMesh() override;
203
207 void setVertices( const QList<QVector3D> &vertices );
208
209 private:
210 Qt3DRender::QGeometry *mGeom = nullptr;
211 Qt3DRender::QAttribute *mPositionAttribute = nullptr;
212 Qt3DRender::QBuffer *mVertexBuffer = nullptr;
213};
214
215#endif // QGS3DAXIS_H
Mode
Axis representation enum.
~Qgs3DWiredMesh() override
Qgs3DWiredMesh(Qt3DCore::QNode *parent=nullptr)
Defaul Qgs3DWiredMesh constructor.
Definition: qgs3daxis.cpp:1197
void setVertices(const QList< QVector3D > &vertices)
add or replace mesh vertices coordinates
Definition: qgs3daxis.cpp:1220
This class represents a coordinate reference system (CRS).