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