QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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, public QgsTemporalRangeObject
52 {
53  Q_OBJECT
54  public:
55 
57  Qgs3DMapSettings() = default;
59  Qgs3DMapSettings( const Qgs3DMapSettings &other );
60  ~Qgs3DMapSettings() override;
61 
62  Qgs3DMapSettings &operator=( Qgs3DMapSettings const & ) = delete;
63 
65  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
67  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
69  void resolveReferences( const QgsProject &project );
70 
82  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
84  QgsVector3D origin() const { return mOrigin; }
85 
87  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
89  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
90 
92  void setCrs( const QgsCoordinateReferenceSystem &crs );
94  QgsCoordinateReferenceSystem crs() const { return mCrs; }
95 
103  QgsCoordinateTransformContext transformContext() const;
104 
112  void setTransformContext( const QgsCoordinateTransformContext &context );
113 
121  const QgsPathResolver &pathResolver() const { return mPathResolver; }
122 
130  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
131 
138  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
139 
145  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
146 
148  void setBackgroundColor( const QColor &color );
150  QColor backgroundColor() const;
151 
153  void setSelectionColor( const QColor &color );
155  QColor selectionColor() const;
156 
157  //
158  // terrain related config
159  //
160 
165  void setTerrainVerticalScale( double zScale );
167  double terrainVerticalScale() const;
168 
173  void setLayers( const QList<QgsMapLayer *> &layers );
174 
179  QList<QgsMapLayer *> layers() const;
180 
185  void setMapTileResolution( int res );
186 
191  int mapTileResolution() const;
192 
197  void setMaxTerrainScreenError( float error );
198 
206  float maxTerrainScreenError() const;
207 
212  void setMaxTerrainGroundError( float error );
213 
220  float maxTerrainGroundError() const;
221 
226  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
228  QgsTerrainGenerator *terrainGenerator() const SIP_SKIP { return mTerrainGenerator.get(); }
229 
235  void setTerrainShadingEnabled( bool enabled );
236 
243  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
244 
250  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
251 
257  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
258 
264  void setTerrainMapTheme( const QString &theme );
265 
272  QString terrainMapTheme() const { return mTerrainMapTheme; }
273 
274  //
275  // misc configuration
276  //
277 
279  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
281  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
282 
289  void setSkybox( bool enabled, const QString &fileBase = QString(), const QString &fileExtension = QString() );
291  bool hasSkyboxEnabled() const { return mSkyboxEnabled; }
293  QString skyboxFileBase() const { return mSkyboxFileBase; }
295  QString skyboxFileExtension() const { return mSkyboxFileExtension; }
296 
298  void setShowTerrainBoundingBoxes( bool enabled );
300  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
302  void setShowTerrainTilesInfo( bool enabled );
304  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
305 
310  void setShowCameraViewCenter( bool enabled );
311 
316  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
318  void setShowLabels( bool enabled );
320  bool showLabels() const { return mShowLabels; }
321 
326  QList<QgsPointLightSettings> pointLights() const { return mPointLights; }
327 
332  void setPointLights( const QList<QgsPointLightSettings> &pointLights );
333 
338  float fieldOfView() const { return mFieldOfView; }
339 
344  void setFieldOfView( const float fieldOfView );
345 
351  void setOutputDpi( const double dpi ) {mDpi = dpi;}
352 
353 
359  double outputDpi() const { return mDpi; }
360 
361  signals:
363  void backgroundColorChanged();
365  void selectionColorChanged();
367  void layersChanged();
369  void terrainGeneratorChanged();
371  void terrainVerticalScaleChanged();
373  void mapTileResolutionChanged();
375  void maxTerrainScreenErrorChanged();
377  void maxTerrainGroundErrorChanged();
378 
383  void terrainShadingChanged();
384 
389  void terrainMapThemeChanged();
390 
395  void renderersChanged();
396 
398  void showTerrainBoundingBoxesChanged();
400  void showTerrainTilesInfoChanged();
401 
406  void showCameraViewCenterChanged();
408  void showLabelsChanged();
409 
414  void pointLightsChanged();
415 
420  void fieldOfViewChanged();
421 
422  private:
423 #ifdef SIP_RUN
424  Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
425 #endif
426 
427  private:
429  QgsVector3D mOrigin;
431  QColor mBackgroundColor = Qt::black;
432  QColor mSelectionColor;
433  double mTerrainVerticalScale = 1;
434  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
435  int mMapTileResolution = 512;
436  float mMaxTerrainScreenError = 3.f;
437  float mMaxTerrainGroundError = 1.f;
438  bool mTerrainShadingEnabled = false;
439  QgsPhongMaterialSettings mTerrainShadingMaterial;
440  QString mTerrainMapTheme;
441  bool mShowTerrainBoundingBoxes = false;
442  bool mShowTerrainTileInfo = false;
443  bool mShowCameraViewCenter = false;
444  bool mShowLabels = false;
445  QList<QgsPointLightSettings> mPointLights;
446  float mFieldOfView = 45.0f; //<! Camera lens field of view value
447  QList<QgsMapLayerRef> mLayers;
448  QList<QgsAbstract3DRenderer *> mRenderers;
449  bool mSkyboxEnabled = false;
450  QString mSkyboxFileBase;
451  QString mSkyboxFileExtension;
452  QgsCoordinateTransformContext mTransformContext;
454  QgsPathResolver mPathResolver;
455  QgsMapThemeCollection *mMapThemes = nullptr;
456  double mDpi = 96;
457 };
458 
459 
460 #endif // QGS3DMAPSETTINGS_H
Qgs3DMapSettings::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Definition: qgs3dmapsettings.h:94
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
Qgs3DMapSettings::terrainShadingMaterial
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
Definition: qgs3dmapsettings.h:257
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
Qgs3DMapSettings::outputDpi
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
Definition: qgs3dmapsettings.h:359
Qgs3DMapSettings::mapThemeCollection
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
Definition: qgs3dmapsettings.h:138
QgsAbstract3DRenderer
Definition: qgsabstract3drenderer.h:48
QgsVector3D
Definition: qgsvector3d.h:31
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
qgsmesh3dsymbol.h
Qgs3DMapSettings::terrainMapTheme
QString terrainMapTheme() const
Returns name of the map theme (from the active project) that will be used for terrain's texture.
Definition: qgs3dmapsettings.h:272
QgsProject
Definition: qgsproject.h:92
Qgs3DMapSettings::showLabels
bool showLabels() const
Returns whether to display labels on terrain tiles.
Definition: qgs3dmapsettings.h:320
qgspointlightsettings.h
QgsPhongMaterialSettings
Definition: qgsphongmaterialsettings.h:35
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
Qgs3DMapSettings::hasSkyboxEnabled
bool hasSkyboxEnabled() const
Returns whether skybox is enabled.
Definition: qgs3dmapsettings.h:291
QgsTerrainGenerator
Definition: qgsterraingenerator.h:47
Qgs3DMapSettings::pathResolver
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Definition: qgs3dmapsettings.h:121
Qgs3DMapSettings::setOutputDpi
void setOutputDpi(const double dpi)
Sets DPI used for conversion between real world units (e.g.
Definition: qgs3dmapsettings.h:351
qgsterraingenerator.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Qgs3DMapSettings::setOrigin
void setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
Definition: qgs3dmapsettings.h:82
Qgs3DMapSettings
Definition: qgs3dmapsettings.h:51
Qgs3DMapSettings::skyboxFileExtension
QString skyboxFileExtension() const
Returns extension part of filenames of skybox (see setSkybox())
Definition: qgs3dmapsettings.h:295
Qgs3DMapSettings::fieldOfView
float fieldOfView() const
Returns the camera lens' field of view.
Definition: qgs3dmapsettings.h:338
QgsRasterLayer
Definition: qgsrasterlayer.h:72
Qgs3DMapSettings::origin
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Definition: qgs3dmapsettings.h:84
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
Qgs3DMapSettings::terrainGenerator
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data.
Definition: qgs3dmapsettings.h:228
Qgs3DMapSettings::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Definition: qgs3dmapsettings.h:130
Qgs3DMapSettings::setMapThemeCollection
void setMapThemeCollection(QgsMapThemeCollection *mapThemes)
Sets pointer to the collection of map themes.
Definition: qgs3dmapsettings.h:145
qgsvector3d.h
QgsMapLayer
Definition: qgsmaplayer.h:81
Qgs3DMapSettings::renderers
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
Definition: qgs3dmapsettings.h:281
Qgs3DMapSettings::showTerrainBoundingBoxes
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
Definition: qgs3dmapsettings.h:300
qgsmaplayerref.h
Qgs3DMapSettings::showTerrainTilesInfo
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging)
Definition: qgs3dmapsettings.h:304
QgsMapThemeCollection
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Definition: qgsmapthemecollection.h:44
Qgs3DMapSettings::showCameraViewCenter
bool showCameraViewCenter() const
Returns whether to show camera's view center as a sphere (for debugging)
Definition: qgs3dmapsettings.h:316
qgsphongmaterialsettings.h
Qgs3DMapSettings::skyboxFileBase
QString skyboxFileBase() const
Returns base part of filenames of skybox (see setSkybox())
Definition: qgs3dmapsettings.h:293
qgscoordinatereferencesystem.h
QgsPathResolver
Definition: qgspathresolver.h:31
QgsTemporalRangeObject
Definition: qgstemporalrangeobject.h:33
Qgs3DMapSettings::pointLights
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
Definition: qgs3dmapsettings.h:326
Qgs3DMapSettings::isTerrainShadingEnabled
bool isTerrainShadingEnabled() const
Returns whether terrain shading is enabled.
Definition: qgs3dmapsettings.h:243