QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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"
27 #include "qgsmesh3dsymbol.h"
29 #include "qgspointlightsettings.h"
30 #include "qgsterraingenerator.h"
31 #include "qgsvector3d.h"
32 
33 class QgsMapLayer;
34 class QgsRasterLayer;
35 
37 
38 
40 class QgsProject;
41 
42 class QDomElement;
43 
44 
51 class _3D_EXPORT Qgs3DMapSettings : public QObject
52 {
53  Q_OBJECT
54  public:
55 
57  Qgs3DMapSettings() = default;
59  Qgs3DMapSettings( const Qgs3DMapSettings &other );
60  ~Qgs3DMapSettings() override;
61 
63  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
65  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
67  void resolveReferences( const QgsProject &project );
68 
80  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
82  QgsVector3D origin() const { return mOrigin; }
83 
85  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
87  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
88 
90  void setCrs( const QgsCoordinateReferenceSystem &crs );
92  QgsCoordinateReferenceSystem crs() const { return mCrs; }
93 
101  QgsCoordinateTransformContext transformContext() const;
102 
110  void setTransformContext( const QgsCoordinateTransformContext &context );
111 
119  const QgsPathResolver &pathResolver() const { return mPathResolver; }
120 
128  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
129 
136  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
137 
143  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
144 
146  void setBackgroundColor( const QColor &color );
148  QColor backgroundColor() const;
149 
151  void setSelectionColor( const QColor &color );
153  QColor selectionColor() const;
154 
155  //
156  // terrain related config
157  //
158 
163  void setTerrainVerticalScale( double zScale );
165  double terrainVerticalScale() const;
166 
171  void setLayers( const QList<QgsMapLayer *> &layers );
172 
177  QList<QgsMapLayer *> layers() const;
178 
183  void setMapTileResolution( int res );
184 
189  int mapTileResolution() const;
190 
195  void setMaxTerrainScreenError( float error );
196 
204  float maxTerrainScreenError() const;
205 
210  void setMaxTerrainGroundError( float error );
211 
218  float maxTerrainGroundError() const;
219 
224  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER );
226  QgsTerrainGenerator *terrainGenerator() const { return mTerrainGenerator.get(); }
227 
233  void setTerrainShadingEnabled( bool enabled );
234 
241  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
242 
248  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
249 
255  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
256 
262  void setTerrainMapTheme( const QString &theme );
263 
270  QString terrainMapTheme() const { return mTerrainMapTheme; }
271 
272  //
273  // misc configuration
274  //
275 
277  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
279  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
280 
287  void setSkybox( bool enabled, const QString &fileBase = QString(), const QString &fileExtension = QString() );
289  bool hasSkyboxEnabled() const { return mSkyboxEnabled; }
291  QString skyboxFileBase() const { return mSkyboxFileBase; }
293  QString skyboxFileExtension() const { return mSkyboxFileExtension; }
294 
296  void setShowTerrainBoundingBoxes( bool enabled );
298  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
300  void setShowTerrainTilesInfo( bool enabled );
302  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
303 
308  void setShowCameraViewCenter( bool enabled );
309 
314  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
316  void setShowLabels( bool enabled );
318  bool showLabels() const { return mShowLabels; }
319 
324  QList<QgsPointLightSettings> pointLights() const { return mPointLights; }
325 
330  void setPointLights( const QList<QgsPointLightSettings> &pointLights );
331 
336  float fieldOfView() const { return mFieldOfView; }
337 
342  void setFieldOfView( const float fieldOfView );
343 
349  void setOutputDpi( const double dpi ) {mDpi = dpi;}
350 
351 
357  double outputDpi() const { return mDpi; }
358 
359  signals:
361  void backgroundColorChanged();
363  void selectionColorChanged();
365  void layersChanged();
367  void terrainGeneratorChanged();
369  void terrainVerticalScaleChanged();
371  void mapTileResolutionChanged();
373  void maxTerrainScreenErrorChanged();
375  void maxTerrainGroundErrorChanged();
376 
381  void terrainShadingChanged();
382 
387  void terrainMapThemeChanged();
388 
393  void renderersChanged();
394 
396  void showTerrainBoundingBoxesChanged();
398  void showTerrainTilesInfoChanged();
399 
404  void showCameraViewCenterChanged();
406  void showLabelsChanged();
407 
412  void pointLightsChanged();
413 
418  void fieldOfViewChanged();
419 
420  private:
422  QgsVector3D mOrigin;
424  QColor mBackgroundColor = Qt::black;
425  QColor mSelectionColor;
426  double mTerrainVerticalScale = 1;
427  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
428  int mMapTileResolution = 512;
429  float mMaxTerrainScreenError = 3.f;
430  float mMaxTerrainGroundError = 1.f;
431  bool mTerrainShadingEnabled = false;
432  QgsPhongMaterialSettings mTerrainShadingMaterial;
433  QString mTerrainMapTheme;
434  bool mShowTerrainBoundingBoxes = false;
435  bool mShowTerrainTileInfo = false;
436  bool mShowCameraViewCenter = false;
437  bool mShowLabels = false;
438  QList<QgsPointLightSettings> mPointLights;
439  float mFieldOfView = 45.0f; //<! Camera lens field of view value
440  QList<QgsMapLayerRef> mLayers;
441  QList<QgsAbstract3DRenderer *> mRenderers;
442  bool mSkyboxEnabled = false;
443  QString mSkyboxFileBase;
444  QString mSkyboxFileExtension;
445  QgsCoordinateTransformContext mTransformContext;
447  QgsPathResolver mPathResolver;
448  QgsMapThemeCollection *mMapThemes = nullptr;
449  double mDpi = 96;
450 };
451 
452 
453 #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:79
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.
void setOutputDpi(const double dpi)
Sets DPI used for conversion between real world units (e.g.
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
bool showCameraViewCenter() const
Returns whether to show camera&#39;s view center as a sphere (for debugging)
Represents a raster layer.
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
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:91
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())
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
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...