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