QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgsrange.h"
22#include "qgsraycastresult.h"
23
24#include <QtGui/QWindow>
25
26#ifndef SIP_RUN
27namespace Qt3DCore
28{
29 class QAspectEngine;
30 class QAbstractAspect;
31 class QEntity;
32} // namespace Qt3DCore
33
34namespace Qt3DRender
35{
36 class QCamera;
37 class QFrameGraphNode;
38 class QRenderAspect;
39 class QRenderSettings;
40} // namespace Qt3DRender
41
42namespace Qt3DExtras
43{
44 class QForwardRenderer;
45}
46
47namespace Qt3DInput
48{
49 class QInputAspect;
50 class QInputSettings;
51} // namespace Qt3DInput
52
53namespace Qt3DLogic
54{
55 class QLogicAspect;
56}
57#endif
58
59class QgsRectangle;
61class Qgs3DMapTool;
62class QgsPointXY;
65class Qgs3DMapScene;
67class QgsFeature;
68class QgsMapLayer;
69class QgsRubberBand3D;
71
72
83class _3D_EXPORT Qgs3DMapCanvas : public QWindow
84{
85 Q_OBJECT
86 public:
88 ~Qgs3DMapCanvas() override;
89
91 Qgs3DMapSettings *mapSettings() { return mMapSettings; }
92
94 Qgs3DMapScene *scene() { return mScene; }
95
97 QgsCameraController *cameraController();
98
104 void setMapTool( Qgs3DMapTool *tool );
105
111 Qgs3DMapTool *mapTool() const { return mMapTool; }
112
119 QgsRayCastResult castRay( const QPoint &screenPoint, QgsRayCastContext context );
120
133 void enableCrossSection( const QgsPointXY &startPoint, const QgsPointXY &endPoint, double tolerance, bool setSideView = true );
134
140 void disableCrossSection();
141
148 bool crossSectionEnabled() const;
149
150#ifndef SIP_RUN
151
155 void setRootEntity( Qt3DCore::QEntity *root );
156
160 void setActiveFrameGraph( Qt3DRender::QFrameGraphNode *activeFrameGraph );
161
165 Qt3DRender::QFrameGraphNode *activeFrameGraph() const;
166
170 Qt3DRender::QCamera *camera() const;
171
175 Qt3DRender::QRenderSettings *renderSettings() const;
176
178 void setMapSettings( Qgs3DMapSettings *mapSettings );
179
181 void resetView();
182
184 void setViewFromTop( const QgsPointXY &center, float distance, float rotation = 0 );
185
187 void saveAsImage( const QString &fileName, const QString &fileFormat );
188
192 QgsWindow3DEngine *engine() const { return mEngine; }
193
197 void setTemporalController( QgsTemporalController *temporalController );
198
202 void setViewFrom2DExtent( const QgsRectangle &extent );
203
207 QVector<QgsPointXY> viewFrustum2DExtent();
208
213 void highlightFeature( const QgsFeature &feature, QgsMapLayer *layer );
214
218 void clearHighlights();
219
220 signals:
222 void savedAsImage( const QString &fileName );
223
226
228 void fpsCountChanged( float fpsCount );
229
231 void fpsCounterEnabledChanged( bool enabled );
232
234 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
235
237 void cameraNavigationSpeedChanged( double speed );
238
239#endif
245 void crossSectionEnabledChanged( bool enabled );
246
247 private slots:
248 void captureDepthBuffer();
249 void updateTemporalRange( const QgsDateTimeRange &timeRange );
250 void onNavigationModeChanged( Qgis::NavigationMode mode );
251 void updateHighlightSizes();
252
253 protected:
254
258 void showEvent( QShowEvent *e ) override;
259
263 void resizeEvent( QResizeEvent * ) override;
264
265 bool eventFilter( QObject *watched, QEvent *event ) override;
266
267 private:
268 Qt3DCore::QAspectEngine *m_aspectEngine;
269
270 // Aspects
271 Qt3DRender::QRenderAspect *m_renderAspect;
272 Qt3DInput::QInputAspect *m_inputAspect;
273 Qt3DLogic::QLogicAspect *m_logicAspect;
274
275 // Renderer configuration
276 Qt3DRender::QRenderSettings *m_renderSettings;
277 Qt3DRender::QCamera *m_defaultCamera;
278
279 // Input configuration
280 Qt3DInput::QInputSettings *m_inputSettings;
281
282 // Scene
283 Qt3DCore::QEntity *m_root;
284 Qt3DCore::QEntity *m_userRoot;
285
286 bool m_initialized;
287
288 QgsWindow3DEngine *mEngine = nullptr;
289
291 Qgs3DMapSettings *mMapSettings = nullptr;
293 Qgs3DMapScene *mScene = nullptr;
294
296 Qgs3DMapTool *mMapTool = nullptr;
297
298 QString mCaptureFileName;
299 QString mCaptureFileFormat;
300
301 QgsTemporalController *mTemporalController = nullptr;
302
304 QMap<QgsMapLayer *, QgsRubberBand3D *> mHighlights;
305};
306
307#endif //QGS3DMAPCANVAS_H
NavigationMode
The navigation mode used by 3D cameras.
Definition qgis.h:4155
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.
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.
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