QGIS API Documentation 3.99.0-Master (1d785854362)
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
116 Qgs3DMapTool *mapTool() const { return mMapTool; }
117
124 QgsRayCastResult castRay( const QPoint &screenPoint, QgsRayCastContext context );
125
131 bool crossSectionEnabled() const;
132
141 void setCrossSection( const QgsCrossSection &crossSection );
142
147 QgsCrossSection crossSection() const { return mCrossSection; }
148
149#ifndef SIP_RUN
150
154 void setRootEntity( Qt3DCore::QEntity *root );
155
159 void setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph );
160
164 Qt3DRender::QFrameGraphNode *activeFrameGraph() const;
165
169 Qt3DRender::QCamera *camera() const;
170
174 Qt3DRender::QRenderSettings *renderSettings() const;
175
177 void setMapSettings( Qgs3DMapSettings *mapSettings );
178
180 void resetView();
181
183 void setViewFromTop( const QgsPointXY &center, float distance, float rotation = 0 );
184
186 void saveAsImage( const QString &fileName, const QString &fileFormat );
187
191 QgsWindow3DEngine *engine() const { return mEngine; }
192
196 void setTemporalController( QgsTemporalController *temporalController );
197
201 void setViewFrom2DExtent( const QgsRectangle &extent );
202
206 QVector<QgsPointXY> viewFrustum2DExtent();
207
208 signals:
210 void savedAsImage( const QString &fileName );
211
214
216 void fpsCountChanged( float fpsCount );
217
219 void fpsCounterEnabledChanged( bool enabled );
220
222 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
223
225 void cameraNavigationSpeedChanged( double speed );
226
227#endif
232 void crossSectionEnabledChanged( bool enabled );
233
234#ifndef SIP_RUN
235 public slots:
242 void highlightFeature( const QgsFeature &feature, QgsMapLayer *layer );
243
249 void clearHighlights();
250#endif
251
252 private slots:
253 void captureDepthBuffer();
254 void updateTemporalRange( const QgsDateTimeRange &timeRange );
255 void onNavigationModeChanged( Qgis::NavigationMode mode );
256
257 protected:
261 void showEvent( QShowEvent *e ) override;
262
266 void resizeEvent( QResizeEvent * ) override;
267
268 bool eventFilter( QObject *watched, QEvent *event ) override;
269
270 private:
271 Qt3DCore::QAspectEngine *m_aspectEngine;
272
273 // Aspects
274 Qt3DRender::QRenderAspect *m_renderAspect;
275 Qt3DInput::QInputAspect *m_inputAspect;
276 Qt3DLogic::QLogicAspect *m_logicAspect;
277
278 // Renderer configuration
279 Qt3DRender::QRenderSettings *m_renderSettings;
280 Qt3DRender::QCamera *m_defaultCamera;
281
282 // Input configuration
283 Qt3DInput::QInputSettings *m_inputSettings;
284
285 // Scene
286 Qt3DCore::QEntity *m_root;
287 Qt3DCore::QEntity *m_userRoot = nullptr;
288
289 bool m_initialized = false;
290
291 QgsWindow3DEngine *mEngine = nullptr;
292
294 Qgs3DMapSettings *mMapSettings = nullptr;
296 Qgs3DMapScene *mScene = nullptr;
297
299 Qgs3DMapTool *mMapTool = nullptr;
300
301 QString mCaptureFileName;
302 QString mCaptureFileFormat;
303
304 QgsTemporalController *mTemporalController = nullptr;
305
306 std::unique_ptr<Qgs3DHighlightFeatureHandler> mHighlightsHandler = nullptr;
307
308 QgsCrossSection mCrossSection;
309};
310
311#endif //QGS3DMAPCANVAS_H
NavigationMode
The navigation mode used by 3D cameras.
Definition qgis.h:4237
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 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 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:83
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