QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgs3dmapsettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapsettings.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 QGS3DMAPSETTINGS_H
17 #define QGS3DMAPSETTINGS_H
18 
19 #include "qgis_3d.h"
20 
21 #include <memory>
22 #include <QColor>
23 #include <QMatrix4x4>
24 
26 #include "qgsmaplayerref.h"
28 #include "qgspointlightsettings.h"
29 #include "qgsterraingenerator.h"
30 #include "qgsvector3d.h"
31 
32 class QgsMapLayer;
33 class QgsRasterLayer;
34 
36 
37 
39 class QgsProject;
40 
41 class QDomElement;
42 
43 
50 class _3D_EXPORT Qgs3DMapSettings : public QObject
51 {
52  Q_OBJECT
53  public:
54 
56  Qgs3DMapSettings() = default;
58  Qgs3DMapSettings( const Qgs3DMapSettings &other );
59  ~Qgs3DMapSettings() override;
60 
62  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
64  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
66  void resolveReferences( const QgsProject &project );
67 
79  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
81  QgsVector3D origin() const { return mOrigin; }
82 
84  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
86  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
87 
89  void setCrs( const QgsCoordinateReferenceSystem &crs );
91  QgsCoordinateReferenceSystem crs() const { return mCrs; }
92 
100  QgsCoordinateTransformContext transformContext() const;
101 
109  void setTransformContext( const QgsCoordinateTransformContext &context );
110 
118  const QgsPathResolver &pathResolver() const { return mPathResolver; }
119 
127  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
128 
135  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
136 
142  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
143 
145  void setBackgroundColor( const QColor &color );
147  QColor backgroundColor() const;
148 
150  void setSelectionColor( const QColor &color );
152  QColor selectionColor() const;
153 
154  //
155  // terrain related config
156  //
157 
162  void setTerrainVerticalScale( double zScale );
164  double terrainVerticalScale() const;
165 
170  void setLayers( const QList<QgsMapLayer *> &layers );
171 
176  QList<QgsMapLayer *> layers() const;
177 
182  void setMapTileResolution( int res );
183 
188  int mapTileResolution() const;
189 
194  void setMaxTerrainScreenError( float error );
195 
203  float maxTerrainScreenError() const;
204 
209  void setMaxTerrainGroundError( float error );
210 
217  float maxTerrainGroundError() const;
218 
223  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER );
225  QgsTerrainGenerator *terrainGenerator() const { return mTerrainGenerator.get(); }
226 
232  void setTerrainShadingEnabled( bool enabled );
233 
240  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
241 
247  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
248 
254  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
255 
261  void setTerrainMapTheme( const QString &theme );
262 
269  QString terrainMapTheme() const { return mTerrainMapTheme; }
270 
271  //
272  // misc configuration
273  //
274 
276  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
278  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
279 
286  void setSkybox( bool enabled, const QString &fileBase = QString(), const QString &fileExtension = QString() );
288  bool hasSkyboxEnabled() const { return mSkyboxEnabled; }
290  QString skyboxFileBase() const { return mSkyboxFileBase; }
292  QString skyboxFileExtension() const { return mSkyboxFileExtension; }
293 
295  void setShowTerrainBoundingBoxes( bool enabled );
297  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
299  void setShowTerrainTilesInfo( bool enabled );
301  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
302 
307  void setShowCameraViewCenter( bool enabled );
308 
313  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
315  void setShowLabels( bool enabled );
317  bool showLabels() const { return mShowLabels; }
318 
323  QList<QgsPointLightSettings> pointLights() const { return mPointLights; }
324 
329  void setPointLights( const QList<QgsPointLightSettings> &pointLights );
330 
335  float fieldOfView() const { return mFieldOfView; }
336 
341  void setFieldOfView( const float fieldOfView );
342 
343  signals:
345  void backgroundColorChanged();
347  void selectionColorChanged();
349  void layersChanged();
351  void terrainGeneratorChanged();
353  void terrainVerticalScaleChanged();
355  void mapTileResolutionChanged();
357  void maxTerrainScreenErrorChanged();
359  void maxTerrainGroundErrorChanged();
360 
365  void terrainShadingChanged();
366 
371  void terrainMapThemeChanged();
373  void showTerrainBoundingBoxesChanged();
375  void showTerrainTilesInfoChanged();
376 
381  void showCameraViewCenterChanged();
383  void showLabelsChanged();
384 
389  void pointLightsChanged();
390 
395  void fieldOfViewChanged();
396 
397  private:
399  QgsVector3D mOrigin;
401  QColor mBackgroundColor = Qt::black;
402  QColor mSelectionColor;
403  double mTerrainVerticalScale = 1;
404  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
405  int mMapTileResolution = 512;
406  float mMaxTerrainScreenError = 3.f;
407  float mMaxTerrainGroundError = 1.f;
408  bool mTerrainShadingEnabled = false;
409  QgsPhongMaterialSettings mTerrainShadingMaterial;
410  QString mTerrainMapTheme;
411  bool mShowTerrainBoundingBoxes = false;
412  bool mShowTerrainTileInfo = false;
413  bool mShowCameraViewCenter = false;
414  bool mShowLabels = false;
415  QList<QgsPointLightSettings> mPointLights;
416  float mFieldOfView = 45.0f; //<! Camera lens field of view value
417  QList<QgsMapLayerRef> mLayers;
418  QList<QgsAbstract3DRenderer *> mRenderers;
419  bool mSkyboxEnabled = false;
420  QString mSkyboxFileBase;
421  QString mSkyboxFileExtension;
422  QgsCoordinateTransformContext mTransformContext;
424  QgsPathResolver mPathResolver;
425  QgsMapThemeCollection *mMapThemes = nullptr;
426 };
427 
428 
429 #endif // QGS3DMAPSETTINGS_H
The class is used as a container of context for various read/write operations on other objects...
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:31
Base class for all map layer types.
Definition: qgsmaplayer.h:78
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
bool isTerrainShadingEnabled() const
Returns whether terrain shading is enabled.
Base class for all renderers that may to participate in 3D view.
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
bool showCameraViewCenter() const
Returns whether to show camera&#39;s view center as a sphere (for debugging)
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QString skyboxFileBase() const
Returns base part of filenames of skybox (see setSkybox())
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
const QgsCoordinateReferenceSystem & crs
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
3 Definition of the world
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
QString terrainMapTheme() const
Returns name of the map theme (from the active project) that will be used for terrain&#39;s texture...
bool hasSkyboxEnabled() const
Returns whether skybox is enabled.
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging) ...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Reads and writes project states.
Definition: qgsproject.h:89
Contains information about the context in which a coordinate transform is executed.
void setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
void setMapThemeCollection(QgsMapThemeCollection *mapThemes)
Sets pointer to the collection of map themes.
bool showLabels() const
Returns whether to display labels on terrain tiles.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
3 Base class for generators of terrain.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
This class represents a coordinate reference system (CRS).
QString skyboxFileExtension() const
Returns extension part of filenames of skybox (see setSkybox())
float fieldOfView() const
Returns the camera lens&#39; field of view.
Container class that allows storage of map themes consisting of visible map layers and layer styles...
Resolves relative paths into absolute paths and vice versa.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...