QGIS API Documentation 3.99.0-Master (a8882ad4560)
Loading...
Searching...
No Matches
qgs3dmapcanvas.h
Go to the documentation of this file.
1/***************************************************************************
2 qgs3dmapcanvas.h
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk at gmail 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 QGS3DMAPCANVAS_H
17#define QGS3DMAPCANVAS_H
18
19#include "qgis.h"
20#include "qgis_3d.h"
21#include "qgscrosssection.h"
22#include "qgsrange.h"
23#include "qgsraycastresult.h"
24
25#include <QtGui/QWindow>
26
27#ifndef SIP_RUN
28namespace Qt3DCore
29{
30 class QAspectEngine;
31 class QAbstractAspect;
32 class QEntity;
33} // namespace Qt3DCore
34
35namespace Qt3DRender
36{
37 class QCamera;
38 class QFrameGraphNode;
39 class QRenderAspect;
40 class QRenderSettings;
41} // namespace Qt3DRender
42
43namespace Qt3DExtras
44{
45 class QForwardRenderer;
46}
47
48namespace Qt3DInput
49{
50 class QInputAspect;
51 class QInputSettings;
52} // namespace Qt3DInput
53
54namespace Qt3DLogic
55{
56 class QLogicAspect;
57}
58#endif
59
60class QgsRectangle;
62class Qgs3DMapTool;
63class QgsPointXY;
66class Qgs3DMapScene;
68class QgsFeature;
69class QgsMapLayer;
70class QgsRubberBand3D;
72
73
84class _3D_EXPORT Qgs3DMapCanvas : public QWindow
85{
86 Q_OBJECT
87 public:
89 ~Qgs3DMapCanvas() override;
90
92 Qgs3DMapSettings *mapSettings() { return mMapSettings; }
93
95 Qgs3DMapScene *scene() { return mScene; }
96
98 QgsCameraController *cameraController();
99
105 void setMapTool( Qgs3DMapTool *tool );
106
112 Qgs3DMapTool *mapTool() const { return mMapTool; }
113
120 QgsRayCastResult castRay( const QPoint &screenPoint, QgsRayCastContext context );
121
127 bool crossSectionEnabled() const;
128
137 void setCrossSection( const QgsCrossSection &crossSection );
138
143 QgsCrossSection crossSection() const { return mCrossSection; }
144
145#ifndef SIP_RUN
146
150 void setRootEntity( Qt3DCore::QEntity *root );
151
155 void setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph );
156
160 Qt3DRender::QFrameGraphNode *activeFrameGraph() const;
161
165 Qt3DRender::QCamera *camera() const;
166
170 Qt3DRender::QRenderSettings *renderSettings() const;
171
173 void setMapSettings( Qgs3DMapSettings *mapSettings );
174
176 void resetView();
177
179 void setViewFromTop( const QgsPointXY &center, float distance, float rotation = 0 );
180
182 void saveAsImage( const QString &fileName, const QString &fileFormat );
183
187 QgsWindow3DEngine *engine() const { return mEngine; }
188
192 void setTemporalController( QgsTemporalController *temporalController );
193
197 void setViewFrom2DExtent( const QgsRectangle &extent );
198
202 QVector<QgsPointXY> viewFrustum2DExtent();
203
208 void highlightFeature( const QgsFeature &feature, QgsMapLayer *layer );
209
213 void clearHighlights();
214
215 signals:
217 void savedAsImage( const QString &fileName );
218
221
223 void fpsCountChanged( float fpsCount );
224
226 void fpsCounterEnabledChanged( bool enabled );
227
229 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
230
232 void cameraNavigationSpeedChanged( double speed );
233
234#endif
239 void crossSectionEnabledChanged( bool enabled );
240
241 private slots:
242 void captureDepthBuffer();
243 void updateTemporalRange( const QgsDateTimeRange &timeRange );
244 void onNavigationModeChanged( Qgis::NavigationMode mode );
245 void updateHighlightSizes();
246
247 protected:
251 void showEvent( QShowEvent *e ) override;
252
256 void resizeEvent( QResizeEvent * ) override;
257
258 bool eventFilter( QObject *watched, QEvent *event ) override;
259
260 private:
261 Qt3DCore::QAspectEngine *m_aspectEngine;
262
263 // Aspects
264 Qt3DRender::QRenderAspect *m_renderAspect;
265 Qt3DInput::QInputAspect *m_inputAspect;
266 Qt3DLogic::QLogicAspect *m_logicAspect;
267
268 // Renderer configuration
269 Qt3DRender::QRenderSettings *m_renderSettings;
270 Qt3DRender::QCamera *m_defaultCamera;
271
272 // Input configuration
273 Qt3DInput::QInputSettings *m_inputSettings;
274
275 // Scene
276 Qt3DCore::QEntity *m_root;
277 Qt3DCore::QEntity *m_userRoot = nullptr;
278
279 bool m_initialized = false;
280
281 QgsWindow3DEngine *mEngine = nullptr;
282
284 Qgs3DMapSettings *mMapSettings = nullptr;
286 Qgs3DMapScene *mScene = nullptr;
287
289 Qgs3DMapTool *mMapTool = nullptr;
290
291 QString mCaptureFileName;
292 QString mCaptureFileFormat;
293
294 QgsTemporalController *mTemporalController = nullptr;
295
297 QMap<QgsMapLayer *, QgsRubberBand3D *> mHighlights;
298
299 QgsCrossSection mCrossSection;
300};
301
302#endif //QGS3DMAPCANVAS_H
NavigationMode
The navigation mode used by 3D cameras.
Definition qgis.h:4202
QgsWindow3DEngine * engine() const
Returns the 3D engine.
Qgs3DMapSettings * mapSettings()
Returns access to the 3D scene configuration.
void mapSettingsChanged()
Emitted when the the map setting is changed.
void crossSectionEnabledChanged(bool enabled)
Emitted when the cross section mode is enabled or disabled.
void viewed2DExtentFrom3DChanged(QVector< QgsPointXY > extent)
Emitted when the viewed 2D extent seen by the 3D camera has changed.
Qgs3DMapTool * mapTool() const
Returns the active map tool that will receive events from the 3D canvas.
void fpsCountChanged(float fpsCount)
Emitted when the FPS count changes (at most every frame).
void showEvent(QShowEvent *e) override
Manages the display events specified in e.
QgsCrossSection crossSection() const
Returns the current cross section definition for the 3D map canvas.
void cameraNavigationSpeedChanged(double speed)
Emitted when the camera navigation speed is changed.
Qgs3DMapScene * scene()
Returns access to the 3D scene (root 3D entity).
void resizeEvent(QResizeEvent *) override
Resets the aspect ratio of the 3D window.
void savedAsImage(const QString &fileName)
Emitted when the 3D map canvas was successfully saved as image.
void fpsCounterEnabledChanged(bool enabled)
Emitted when the FPS counter is enabled or disabeld.
bool eventFilter(QObject *watched, QEvent *event) override
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition of the world.
Base class for map tools operating on 3D map canvas.
Object that controls camera movement based on user input.
Encapsulates the definition of a cross section in 3D map coordinates.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for all map layer types.
Definition qgsmaplayer.h:80
Represents a 2D point.
Definition qgspointxy.h:60
Responsible for defining parameters of the ray casting operations in 3D map canvases.
Contains the results of ray casting operations in a 3D map canvas.
A rectangle specified with double values.
A controller base class for temporal objects, contains a signal for notifying updates of the objects ...
On-screen 3D engine: it creates an OpenGL window (QWindow) and displays rendered 3D scenes there.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:761