QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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 "qgs3dmapcanvas.h"
21
23#include <Qt3DCore/QEntity>
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#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
34#include <Qt3DRender/QBuffer>
35#else
36#include <Qt3DCore/QBuffer>
37#endif
38#include <Qt3DRender/QGeometryRenderer>
39
40#include <QtWidgets/QMenu>
41#include "qgs3dmapsettings.h"
42
43#define SIP_NO_FILE
44
46class Qgs3DMapScene;
47
60class _3D_EXPORT Qgs3DAxis : public QObject
61{
62 Q_OBJECT
63 public:
64
73 Qgs3DAxis( Qgs3DMapCanvas *canvas, Qt3DCore::QEntity *parent3DScene,
74 Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
75 ~Qgs3DAxis() override;
76
88 QVector3D from3DTo2DLabelPosition( const QVector3D &sourcePos,
89 Qt3DRender::QCamera *sourceCamera, Qt3DRender::QViewport *sourceViewport,
90 Qt3DRender::QCamera *destCamera, Qt3DRender::QViewport *destViewport,
91 const QSize &destSize );
92
93 public slots:
94
96 void onAxisSettingsChanged( );
97
98 private slots:
99
100 void onCameraUpdate( );
101 void onAxisViewportSizeUpdate( int val = 0 );
102
103 // axis picking and menu
104 void onTouchedByRay( const Qt3DRender::QAbstractRayCaster::Hits &hits );
105
106 void onAxisModeChanged( Qgs3DAxisSettings::Mode mode );
107 void onAxisHorizPositionChanged( Qt::AnchorPoint pos );
108 void onAxisVertPositionChanged( Qt::AnchorPoint pos );
109 void onCameraViewChange( float pitch, float yaw );
110
111 void onCameraViewChangeHome() { onCameraViewChange( 45.0f, 45.0f ); }
112 void onCameraViewChangeTop() { onCameraViewChange( 0.0f, 90.0f ); }
113 void onCameraViewChangeNorth() { onCameraViewChange( 90.0f, 180.0f ); }
114 void onCameraViewChangeEast() { onCameraViewChange( 90.0f, 90.0f ); }
115 void onCameraViewChangeSouth() { onCameraViewChange( 90.0f, 0.0f ); }
116 void onCameraViewChangeWest() { onCameraViewChange( 90.0f, -90.0f ); }
117 void onCameraViewChangeBottom() { onCameraViewChange( 180.0f, 0.0f ); }
118
119 void onTextXChanged( const QString &text );
120 void onTextYChanged( const QString &text );
121 void onTextZChanged( const QString &text );
122
123 private:
124
125 void createAxisScene();
126 void createAxis( Qt::Axis axis );
127 void createCube( );
128 void setEnableCube( bool show );
129 void setEnableAxis( bool show );
130 void updateAxisLabelPosition();
131
132 Qt3DRender::QViewport *constructAxisViewport( Qt3DCore::QEntity *parent3DScene );
133 Qt3DRender::QViewport *constructLabelViewport( Qt3DCore::QEntity *parent3DScene, const QRectF &parentViewportSize );
134
135 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &f, const QMatrix4x4 &rotation, const QVector3D &translation );
136
137 // axis picking and menu
138 void init3DObjectPicking( );
139 bool eventFilter( QObject *watched, QEvent *event ) override;
140 void createKeyboardShortCut();
141 void createMenu();
142 void hideMenu();
143 void displayMenuAt( const QPoint &position );
144
145 Qgs3DMapSettings *mMapSettings = nullptr;
146 Qgs3DMapCanvas *mCanvas = nullptr;
147 Qgs3DMapScene *mMapScene = nullptr;
148 QgsCameraController *mCameraController = nullptr;
149
150 float mCylinderLength = 40.0f;
151 int mFontSize = 10;
152
153 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
154 Qt3DRender::QLayer *mAxisSceneLayer = nullptr;
155 Qt3DRender::QCamera *mAxisCamera = nullptr;
156 Qt3DRender::QViewport *mAxisViewport = nullptr;
157
158 Qt3DCore::QEntity *mAxisRoot = nullptr;
159 Qt3DCore::QEntity *mCubeRoot = nullptr;
160 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
161
162 Qt3DExtras::QText2DEntity *mTextX = nullptr;
163 Qt3DExtras::QText2DEntity *mTextY = nullptr;
164 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
165 QVector3D mTextCoordX;
166 QVector3D mTextCoordY;
167 QVector3D mTextCoordZ;
168 Qt3DCore::QTransform *mTextTransformX = nullptr;
169 Qt3DCore::QTransform *mTextTransformY = nullptr;
170 Qt3DCore::QTransform *mTextTransformZ = nullptr;
172 QVector3D mPreviousVector;
173 double mAxisScaleFactor = 1.0;
174
175 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
176 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
177 Qt3DRender::QViewport *mTwoDLabelViewport = nullptr;
178
179 // axis picking and menu
180 Qt3DRender::QScreenRayCaster *mScreenRayCaster = nullptr;
181 bool mIsDragging = false;
182 bool mHasClicked = false;
183 QPoint mLastClickedPos;
184 Qt::MouseButton mLastClickedButton;
185 QCursor mPreviousCursor = Qt::ArrowCursor;
186 QMenu *mMenu = nullptr;
187
188};
189
196class Qgs3DWiredMesh : public Qt3DRender::QGeometryRenderer
197{
198 Q_OBJECT
199
200 public:
201
205 Qgs3DWiredMesh( Qt3DCore::QNode *parent = nullptr );
206 ~Qgs3DWiredMesh() override;
207
211 void setVertices( const QList<QVector3D> &vertices );
212
213 private:
214#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
215 Qt3DRender::QGeometry *mGeom = nullptr;
216 Qt3DRender::QAttribute *mPositionAttribute = nullptr;
217 Qt3DRender::QBuffer *mVertexBuffer = nullptr;
218#else
219 Qt3DCore::QGeometry *mGeom = nullptr;
220 Qt3DCore::QAttribute *mPositionAttribute = nullptr;
221 Qt3DCore::QBuffer *mVertexBuffer = nullptr;
222#endif
223};
224
225#endif // QGS3DAXIS_H
Mode
Axis representation enum.
~Qgs3DWiredMesh() override
void setVertices(const QList< QVector3D > &vertices)
add or replace mesh vertices coordinates
This class represents a coordinate reference system (CRS).