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