QGIS API Documentation 3.38.0-Grenoble (exported)
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
31#include <Qt3DRender/QLayer>
32
33#include <QtWidgets/QMenu>
34#include "qgs3dmapsettings.h"
35
36#define SIP_NO_FILE
37
39class Qgs3DMapScene;
40
53class _3D_EXPORT Qgs3DAxis : public QObject
54{
55 Q_OBJECT
56 public:
57
66 Qgs3DAxis( Qgs3DMapCanvas *canvas, Qt3DCore::QEntity *parent3DScene,
67 Qgs3DMapScene *mapScene, QgsCameraController *camera, Qgs3DMapSettings *map );
68 ~Qgs3DAxis() override;
69
81 QVector3D from3DTo2DLabelPosition( const QVector3D &sourcePos,
82 Qt3DRender::QCamera *sourceCamera, Qt3DRender::QViewport *sourceViewport,
83 Qt3DRender::QCamera *destCamera, Qt3DRender::QViewport *destViewport,
84 const QSize &destSize );
85
86 public slots:
87
89 void onAxisSettingsChanged( );
90
91 private slots:
92
93 void onCameraUpdate( );
94 void onAxisViewportSizeUpdate( int val = 0 );
95
96 // axis picking and menu
97 void onTouchedByRay( const Qt3DRender::QAbstractRayCaster::Hits &hits );
98
99 void onAxisModeChanged( Qgs3DAxisSettings::Mode mode );
100 void onAxisHorizPositionChanged( Qt::AnchorPoint pos );
101 void onAxisVertPositionChanged( Qt::AnchorPoint pos );
102 void onCameraViewChange( float pitch, float yaw );
103
104 void onCameraViewChangeHome() { onCameraViewChange( 45.0f, 45.0f ); }
105 void onCameraViewChangeTop() { onCameraViewChange( 0.0f, 90.0f ); }
106 void onCameraViewChangeNorth() { onCameraViewChange( 90.0f, 180.0f ); }
107 void onCameraViewChangeEast() { onCameraViewChange( 90.0f, 90.0f ); }
108 void onCameraViewChangeSouth() { onCameraViewChange( 90.0f, 0.0f ); }
109 void onCameraViewChangeWest() { onCameraViewChange( 90.0f, -90.0f ); }
110 void onCameraViewChangeBottom() { onCameraViewChange( 180.0f, 0.0f ); }
111
112 void onTextXChanged( const QString &text );
113 void onTextYChanged( const QString &text );
114 void onTextZChanged( const QString &text );
115
116 private:
117
118 void createAxisScene();
119 void createAxis( Qt::Axis axis );
120 void createCube( );
121 void setEnableCube( bool show );
122 void setEnableAxis( bool show );
123 void updateAxisLabelPosition();
124
125 Qt3DRender::QViewport *constructAxisViewport( Qt3DCore::QEntity *parent3DScene );
126 Qt3DRender::QViewport *constructLabelViewport( Qt3DCore::QEntity *parent3DScene, const QRectF &parentViewportSize );
127
128 Qt3DExtras::QText2DEntity *addCubeText( const QString &text, float textHeight, float textWidth, const QFont &f, const QMatrix4x4 &rotation, const QVector3D &translation );
129
130 // axis picking and menu
131 void init3DObjectPicking( );
132 bool eventFilter( QObject *watched, QEvent *event ) override;
133 void createKeyboardShortCut();
134 void createMenu();
135 void hideMenu();
136 void displayMenuAt( const QPoint &position );
137
138 Qgs3DMapSettings *mMapSettings = nullptr;
139 Qgs3DMapCanvas *mCanvas = nullptr;
140 Qgs3DMapScene *mMapScene = nullptr;
141 QgsCameraController *mCameraController = nullptr;
142
143 float mCylinderLength = 40.0f;
144 int mFontSize = 10;
145
146 Qt3DCore::QEntity *mAxisSceneEntity = nullptr;
147 Qt3DRender::QLayer *mAxisSceneLayer = nullptr;
148 Qt3DRender::QCamera *mAxisCamera = nullptr;
149 Qt3DRender::QViewport *mAxisViewport = nullptr;
150
151 Qt3DCore::QEntity *mAxisRoot = nullptr;
152 Qt3DCore::QEntity *mCubeRoot = nullptr;
153 QList<Qt3DExtras::QText2DEntity *> mCubeLabels;
154
155 Qt3DExtras::QText2DEntity *mTextX = nullptr;
156 Qt3DExtras::QText2DEntity *mTextY = nullptr;
157 Qt3DExtras::QText2DEntity *mTextZ = nullptr;
158 QVector3D mTextCoordX;
159 QVector3D mTextCoordY;
160 QVector3D mTextCoordZ;
161 Qt3DCore::QTransform *mTextTransformX = nullptr;
162 Qt3DCore::QTransform *mTextTransformY = nullptr;
163 Qt3DCore::QTransform *mTextTransformZ = nullptr;
165 QVector3D mPreviousVector;
166 double mAxisScaleFactor = 1.0;
167
168 Qt3DRender::QCamera *mTwoDLabelCamera = nullptr;
169 Qt3DCore::QEntity *mTwoDLabelSceneEntity = nullptr;
170 Qt3DRender::QViewport *mTwoDLabelViewport = nullptr;
171
172 // axis picking and menu
173 Qt3DRender::QScreenRayCaster *mScreenRayCaster = nullptr;
174 bool mIsDragging = false;
175 bool mHasClicked = false;
176 QPoint mLastClickedPos;
177 Qt::MouseButton mLastClickedButton;
178 QCursor mPreviousCursor = Qt::ArrowCursor;
179 QMenu *mMenu = nullptr;
180
181};
182
183#endif // QGS3DAXIS_H
Mode
Axis representation enum.
This class represents a coordinate reference system (CRS).