QGIS API Documentation 4.5.0-Master (c9e0ddc514d)
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"
22#include "qgscrosssection.h"
23#include "qgsrange.h"
24#include "qgsraycastresult.h"
25
26#include <QtGui/QWindow>
27
28#ifndef SIP_RUN
29namespace Qt3DCore
30{
31 class QAspectEngine;
32 class QAbstractAspect;
33 class QEntity;
34} // namespace Qt3DCore
35
36namespace Qt3DRender
37{
38 class QCamera;
39 class QFrameGraphNode;
40 class QRenderAspect;
41 class QRenderSettings;
42} // namespace Qt3DRender
43
44namespace Qt3DExtras
45{
46 class QForwardRenderer;
47}
48
49namespace Qt3DInput
50{
51 class QInputAspect;
52 class QInputSettings;
53} // namespace Qt3DInput
54
55namespace Qt3DLogic
56{
57 class QLogicAspect;
58}
59#endif
60
62class Qgs3DMapScene;
63class Qgs3DMapSceneEntity;
65class Qgs3DMapTool;
67class QgsFeature3DHandler;
68class QgsFeature;
69class QgsMapLayer;
70class QgsPointXY;
72class QgsRectangle;
73class QgsRubberBand3D;
76
77
88class _3D_EXPORT Qgs3DMapCanvas : public QWindow
89{
90 Q_OBJECT
91 public:
93 ~Qgs3DMapCanvas() override;
94
96 Qgs3DMapSettings *mapSettings() { return mMapSettings; }
97
99 Qgs3DMapScene *scene() { return mScene; }
100
102 QgsCameraController *cameraController();
103
109 void setMapTool( Qgs3DMapTool *tool );
110
120 void unsetMapTool( Qgs3DMapTool *tool );
121
127 Qgs3DMapTool *mapTool() const { return mMapTool; }
128
135 QgsRayCastResult castRay( const QPoint &screenPoint, QgsRayCastContext context );
136
142 bool crossSectionEnabled() const;
143
152 void setCrossSection( const QgsCrossSection &crossSection );
153
158 QgsCrossSection crossSection() const { return mCrossSection; }
159
160#ifndef SIP_RUN
161
165 void setRootEntity( Qt3DCore::QEntity *root );
166
170 void setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph );
171
175 Qt3DRender::QFrameGraphNode *activeFrameGraph() const;
176
180 Qt3DRender::QCamera *camera() const;
181
185 Qt3DRender::QRenderSettings *renderSettings() const;
186
188 void setMapSettings( Qgs3DMapSettings *mapSettings );
189
191 void resetView();
192
194 void setViewFromTop( const QgsPointXY &center, float distance, float rotation = 0 );
195
197 void saveAsImage( const QString &fileName, const QString &fileFormat );
198
202 QgsWindow3DEngine *engine() const { return mEngine; }
203
207 void setTemporalController( QgsTemporalController *temporalController );
208
212 void setViewFrom2DExtent( const QgsRectangle &extent );
213
217 QVector<QgsPointXY> viewFrustum2DExtent();
218
219 signals:
221 void savedAsImage( const QString &fileName );
222
225
227 void fpsCountChanged( float fpsCount );
228
230 void fpsCounterEnabledChanged( bool enabled );
231
233 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
234
236 void cameraNavigationSpeedChanged( double speed );
237
244 void mapToolSet( Qgs3DMapTool *newTool, Qgs3DMapTool *oldTool );
245
246#endif
251 void crossSectionEnabledChanged( bool enabled );
252
253#ifndef SIP_RUN
254 public slots:
261 void highlightFeature( const QgsFeature &feature, QgsMapLayer *layer );
262
268 void clearHighlights();
269#endif
270
271 private slots:
272 void captureDepthBuffer();
273 void updateTemporalRange( const QgsDateTimeRange &timeRange );
274 void onNavigationModeChanged( Qgis::NavigationMode mode );
275
276 protected:
280 void showEvent( QShowEvent *e ) override;
281
285 void resizeEvent( QResizeEvent * ) override;
286
287 bool eventFilter( QObject *watched, QEvent *event ) override;
288
289 private:
291 bool canvasEventFilter( QEvent *event );
292
294 bool containerEventFilter( QEvent *event );
295
296 private:
297 std::unique_ptr<Qt3DCore::QAspectEngine> m_aspectEngine;
298
299 // Aspects
300 Qt3DRender::QRenderAspect *m_renderAspect;
301 Qt3DInput::QInputAspect *m_inputAspect;
302 Qt3DLogic::QLogicAspect *m_logicAspect;
303
304 // Renderer configuration
305 Qt3DRender::QRenderSettings *m_renderSettings;
306 Qt3DRender::QCamera *m_defaultCamera;
307
308 // Input configuration
309 Qt3DInput::QInputSettings *m_inputSettings;
310
311 // Scene
312 Qt3DCore::QEntity *m_root;
313 Qt3DCore::QEntity *m_userRoot = nullptr;
314
315 bool m_initialized = false;
316
317 QgsWindow3DEngine *mEngine = nullptr;
318
320 Qgs3DMapSettings *mMapSettings = nullptr;
322 Qgs3DMapScene *mScene = nullptr;
323
325 Qgs3DMapTool *mMapTool = nullptr;
326
327 QString mCaptureFileName;
328 QString mCaptureFileFormat;
329
330 QgsTemporalController *mTemporalController = nullptr;
331
332 std::unique_ptr<Qgs3DHighlightFeatureHandler> mHighlightsHandler = nullptr;
333
334 QgsCrossSection mCrossSection;
335};
336
337#endif //QGS3DMAPCANVAS_H
NavigationMode
The navigation mode used by 3D cameras.
Definition qgis.h:4606
Handles the creation of 3D entities used for highlighting identified features.
QgsWindow3DEngine * engine() const
Returns the 3D engine.
Qgs3DMapSettings * mapSettings()
Returns access to the 3D scene configuration.
void mapSettingsChanged()
Emitted when 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 mapToolSet(Qgs3DMapTool *newTool, Qgs3DMapTool *oldTool)
Emitted when the map tool is changed from oldTool to newTool Any of those two may be nullptr if there...
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 highlightFeature(const QgsFeature &feature, QgsMapLayer *layer)
Add a highlight 3d entity for feature of layer.
void savedAsImage(const QString &fileName)
Emitted when the 3D map canvas was successfully saved as image.
void clearHighlights()
Removes all highlight entities.
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:60
Base class for all map layer types.
Definition qgsmaplayer.h:84
Represents a 2D point.
Definition qgspointxy.h:62
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:764