QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgs3dmapsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapsettings.cpp
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 #include "qgs3dmapsettings.h"
17 
18 #include "qgs3dutils.h"
20 #include "qgsdemterraingenerator.h"
21 #include "qgsmeshterraingenerator.h"
24 #include "qgsmeshlayer3drenderer.h"
25 
26 #include <QDomDocument>
27 #include <QDomElement>
28 
29 #include "qgssymbollayerutils.h"
30 #include "qgsrasterlayer.h"
31 
33  : QObject( nullptr )
34  , QgsTemporalRangeObject( other )
35  , mOrigin( other.mOrigin )
36  , mCrs( other.mCrs )
37  , mBackgroundColor( other.mBackgroundColor )
38  , mSelectionColor( other.mSelectionColor )
39  , mTerrainVerticalScale( other.mTerrainVerticalScale )
40  , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
41  , mMapTileResolution( other.mMapTileResolution )
42  , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
43  , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
44  , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
45  , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
46  , mTerrainMapTheme( other.mTerrainMapTheme )
47  , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
48  , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
49  , mShowCameraViewCenter( other.mShowCameraViewCenter )
50  , mShowLightSources( other.mShowLightSources )
51  , mShowLabels( other.mShowLabels )
52  , mPointLights( other.mPointLights )
53  , mDirectionalLights( other.mDirectionalLights )
54  , mFieldOfView( other.mFieldOfView )
55  , mLayers( other.mLayers )
56  , mTerrainLayers( other.mTerrainLayers )
57  , mRenderers() // initialized in body
58  , mTransformContext( other.mTransformContext )
59  , mPathResolver( other.mPathResolver )
60  , mMapThemes( other.mMapThemes )
61  , mIsSkyboxEnabled( other.mIsSkyboxEnabled )
62  , mSkyboxSettings()
63  , mShadowSettings()
64 {
65  Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.mRenderers )
66  {
67  mRenderers << renderer->clone();
68  }
69 }
70 
72 {
73  qDeleteAll( mRenderers );
74 }
75 
76 void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
77 {
78  QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
79  mOrigin = QgsVector3D(
80  elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
81  elemOrigin.attribute( QStringLiteral( "y" ) ).toDouble(),
82  elemOrigin.attribute( QStringLiteral( "z" ) ).toDouble() );
83 
84  QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
85  if ( !elemCamera.isNull() )
86  {
87  mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
88  }
89 
90  QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
91  if ( !elemColor.isNull() )
92  {
93  mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "background" ) ) );
94  mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "selection" ) ) );
95  }
96 
97  QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
98  mCrs.readXml( elemCrs );
99 
100  QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
101  mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
102  mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
103  mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
104  mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
105  mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
106  QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
107  if ( !elemTerrainShadingMaterial.isNull() )
108  mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial, context );
109  mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
110  mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
111 
112  mPointLights.clear();
113  QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
114  if ( !elemPointLights.isNull() )
115  {
116  QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
117  while ( !elemPointLight.isNull() )
118  {
119  QgsPointLightSettings pointLight;
120  pointLight.readXml( elemPointLight );
121  mPointLights << pointLight;
122  elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
123  }
124  }
125  else
126  {
127  // QGIS <= 3.4 did not have light configuration
128  QgsPointLightSettings defaultLight;
129  defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
130  mPointLights << defaultLight;
131  }
132 
133  mDirectionalLights.clear();
134  QDomElement elemDirectionalLights = elem.firstChildElement( QStringLiteral( "directional-lights" ) );
135  if ( !elemDirectionalLights.isNull() )
136  {
137  QDomElement elemDirectionalLight = elemDirectionalLights.firstChildElement( QStringLiteral( "directional-light" ) );
138  while ( !elemDirectionalLight.isNull() )
139  {
140  QgsDirectionalLightSettings directionalLight;
141  directionalLight.readXml( elemDirectionalLight );
142  mDirectionalLights << directionalLight;
143  elemDirectionalLight = elemDirectionalLight.nextSiblingElement( QStringLiteral( "directional-light" ) );
144  }
145  }
146 
147  QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
148  QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
149  QList<QgsMapLayerRef> mapLayers;
150  while ( !elemMapLayer.isNull() )
151  {
152  mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
153  elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
154  }
155  mLayers = mapLayers; // needs to resolve refs afterwards
156 
157  QDomElement elemTerrainLayers = elemTerrain.firstChildElement( QStringLiteral( "terrainLayers" ) );
158  if ( elemTerrainLayers.isNull() )
159  {
160  mTerrainLayers = mLayers;
161  }
162  else
163  {
164  QDomElement elemTerrainMapLayer = elemTerrainLayers.firstChildElement( QStringLiteral( "layer" ) );
165  QList<QgsMapLayerRef> terrainMapLayers;
166  while ( !elemTerrainMapLayer.isNull() )
167  {
168  terrainMapLayers << QgsMapLayerRef( elemTerrainMapLayer.attribute( QStringLiteral( "id" ) ) );
169  elemTerrainMapLayer = elemTerrainMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
170  }
171  mTerrainLayers = mapLayers; // needs to resolve refs afterwards
172  }
173 
174  QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
175  QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
176  if ( terrainGenType == QLatin1String( "dem" ) )
177  {
178  QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
179  demTerrainGenerator->setCrs( mCrs, mTransformContext );
180  mTerrainGenerator.reset( demTerrainGenerator );
181  }
182  else if ( terrainGenType == QLatin1String( "online" ) )
183  {
184  QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
185  onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
186  mTerrainGenerator.reset( onlineTerrainGenerator );
187  }
188  else if ( terrainGenType == QLatin1String( "mesh" ) )
189  {
190  QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
191  meshTerrainGenerator->setCrs( mCrs, mTransformContext );
192  mTerrainGenerator.reset( meshTerrainGenerator );
193  }
194  else // "flat"
195  {
197  flatGen->setCrs( mCrs );
198  mTerrainGenerator.reset( flatGen );
199  }
200  mTerrainGenerator->readXml( elemTerrainGenerator );
201 
202  qDeleteAll( mRenderers );
203  mRenderers.clear();
204 
205  QDomElement elemRenderers = elem.firstChildElement( QStringLiteral( "renderers" ) );
206  QDomElement elemRenderer = elemRenderers.firstChildElement( QStringLiteral( "renderer" ) );
207  while ( !elemRenderer.isNull() )
208  {
209  QgsAbstract3DRenderer *renderer = nullptr;
210  QString type = elemRenderer.attribute( QStringLiteral( "type" ) );
211  if ( type == QLatin1String( "vector" ) )
212  {
213  renderer = new QgsVectorLayer3DRenderer;
214  }
215  else if ( type == QLatin1String( "mesh" ) )
216  {
217  renderer = new QgsMeshLayer3DRenderer;
218  }
219 
220  if ( renderer )
221  {
222  renderer->readXml( elemRenderer, context );
223  mRenderers.append( renderer );
224  }
225  elemRenderer = elemRenderer.nextSiblingElement( QStringLiteral( "renderer" ) );
226  }
227 
228  QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
229  mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
230  mSkyboxSettings.readXml( elemSkybox, context );
231 
232  QDomElement elemShadows = elem.firstChildElement( QStringLiteral( "shadow-rendering" ) );
233  mShadowSettings.readXml( elemShadows, context );
234 
235  QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
236  mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
237  mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
238  mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
239  mShowLightSources = elemDebug.attribute( QStringLiteral( "show-light-sources" ), QStringLiteral( "0" ) ).toInt();
240 
241  QDomElement elemTemporalRange = elem.firstChildElement( QStringLiteral( "temporal-range" ) );
242  QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
243  QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
244  setTemporalRange( QgsDateTimeRange( start, end ) );
245 }
246 
247 QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
248 {
249  QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
250 
251  QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
252  elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
253  elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
254  elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
255  elem.appendChild( elemOrigin );
256 
257  QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
258  elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
259  elem.appendChild( elemCamera );
260 
261  QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
262  elemColor.setAttribute( QStringLiteral( "background" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
263  elemColor.setAttribute( QStringLiteral( "selection" ), QgsSymbolLayerUtils::encodeColor( mSelectionColor ) );
264  elem.appendChild( elemColor );
265 
266  QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
267  mCrs.writeXml( elemCrs, doc );
268  elem.appendChild( elemCrs );
269 
270  QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
271  elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
272  elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
273  elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
274  elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
275  elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
276  QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
277  mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial, context );
278  elemTerrain.appendChild( elemTerrainShadingMaterial );
279  elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
280  elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
281 
282  QDomElement elemPointLights = doc.createElement( QStringLiteral( "point-lights" ) );
283  for ( const QgsPointLightSettings &pointLight : qgis::as_const( mPointLights ) )
284  {
285  QDomElement elemPointLight = pointLight.writeXml( doc );
286  elemPointLights.appendChild( elemPointLight );
287  }
288  elem.appendChild( elemPointLights );
289 
290  QDomElement elemDirectionalLights = doc.createElement( QStringLiteral( "directional-lights" ) );
291  for ( const QgsDirectionalLightSettings &directionalLight : qgis::as_const( mDirectionalLights ) )
292  {
293  QDomElement elemDirectionalLight = directionalLight.writeXml( doc );
294  elemDirectionalLights.appendChild( elemDirectionalLight );
295  }
296  elem.appendChild( elemDirectionalLights );
297 
298  QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
299  Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
300  {
301  QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
302  elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
303  elemMapLayers.appendChild( elemMapLayer );
304  }
305  elemTerrain.appendChild( elemMapLayers );
306 
307  QDomElement elemTerrainMapLayers = doc.createElement( QStringLiteral( "terrainLayers" ) );
308  Q_FOREACH ( const QgsMapLayerRef &layerRef, mTerrainLayers )
309  {
310  QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
311  elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
312  elemTerrainMapLayers.appendChild( elemMapLayer );
313  }
314  elemTerrain.appendChild( elemTerrainMapLayers );
315 
316  QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
317  elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
318  mTerrainGenerator->writeXml( elemTerrainGenerator );
319  elemTerrain.appendChild( elemTerrainGenerator );
320  elem.appendChild( elemTerrain );
321 
322  QDomElement elemRenderers = doc.createElement( QStringLiteral( "renderers" ) );
323  Q_FOREACH ( const QgsAbstract3DRenderer *renderer, mRenderers )
324  {
325  QDomElement elemRenderer = doc.createElement( QStringLiteral( "renderer" ) );
326  elemRenderer.setAttribute( QStringLiteral( "type" ), renderer->type() );
327  renderer->writeXml( elemRenderer, context );
328  elemRenderers.appendChild( elemRenderer );
329  }
330  elem.appendChild( elemRenderers );
331 
332  QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
333  elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
334  mSkyboxSettings.writeXml( elemSkybox, context );
335  elem.appendChild( elemSkybox );
336 
337  QDomElement elemShadows = doc.createElement( QStringLiteral( "shadow-rendering" ) );
338  mShadowSettings.writeXml( elemShadows, context );
339  elem.appendChild( elemShadows );
340 
341  QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
342  elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
343  elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
344  elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
345  elemDebug.setAttribute( QStringLiteral( "show-light-sources" ), mShowLightSources ? 1 : 0 );
346  elem.appendChild( elemDebug );
347 
348  QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
349  elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
350  elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
351 
352  return elem;
353 }
354 
356 {
357  for ( int i = 0; i < mLayers.count(); ++i )
358  {
359  QgsMapLayerRef &layerRef = mLayers[i];
360  layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
361  }
362  for ( int i = 0; i < mTerrainLayers.count(); ++i )
363  {
364  QgsMapLayerRef &layerRef = mTerrainLayers[i];
365  layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
366  }
367 
368  mTerrainGenerator->resolveReferences( project );
369 
370  for ( int i = 0; i < mRenderers.count(); ++i )
371  {
372  QgsAbstract3DRenderer *renderer = mRenderers[i];
373  renderer->resolveReferences( project );
374  }
375 }
376 
378 {
379  return Qgs3DUtils::mapToWorldCoordinates( mapCoords, mOrigin );
380 }
381 
383 {
384  return Qgs3DUtils::worldToMapCoordinates( worldCoords, mOrigin );
385 }
386 
388 {
389  mCrs = crs;
390 }
391 
393 {
394  return mTransformContext;
395 }
396 
398 {
399  mTransformContext = context;
400 }
401 
402 void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
403 {
404  if ( color == mBackgroundColor )
405  return;
406 
407  mBackgroundColor = color;
408  emit backgroundColorChanged();
409 }
410 
412 {
413  return mBackgroundColor;
414 }
415 
416 void Qgs3DMapSettings::setSelectionColor( const QColor &color )
417 {
418  if ( color == mSelectionColor )
419  return;
420 
421  mSelectionColor = color;
422  emit selectionColorChanged();
423 }
424 
426 {
427  return mSelectionColor;
428 }
429 
431 {
432  if ( zScale == mTerrainVerticalScale )
433  return;
434 
435  mTerrainVerticalScale = zScale;
437 }
438 
440 {
441  return mTerrainVerticalScale;
442 }
443 
444 void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
445 {
446  QList<QgsMapLayerRef> lst;
447  lst.reserve( layers.count() );
448  Q_FOREACH ( QgsMapLayer *layer, layers )
449  {
450  lst.append( layer );
451  }
452 
453  if ( mLayers == lst )
454  return;
455 
456  mLayers = lst;
457  emit layersChanged();
458 }
459 
460 QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
461 {
462  QList<QgsMapLayer *> lst;
463  lst.reserve( mLayers.count() );
464  Q_FOREACH ( const QgsMapLayerRef &layerRef, mLayers )
465  {
466  if ( layerRef.layer )
467  lst.append( layerRef.layer );
468  }
469  return lst;
470 }
471 
472 void Qgs3DMapSettings::setTerrainLayers( const QList<QgsMapLayer *> &layers )
473 {
474  QList<QgsMapLayerRef> lst;
475  lst.reserve( layers.count() );
476  Q_FOREACH ( QgsMapLayer *layer, layers )
477  {
478  lst.append( layer );
479  }
480 
481  if ( mTerrainLayers == lst )
482  return;
483 
484  mTerrainLayers = lst;
485  emit terrainLayersChanged();
486 }
487 
488 QList<QgsMapLayer *> Qgs3DMapSettings::terrainLayers() const
489 {
490  QList<QgsMapLayer *> lst;
491  lst.reserve( mTerrainLayers.count() );
492  Q_FOREACH ( const QgsMapLayerRef &layerRef, mTerrainLayers )
493  {
494  if ( layerRef.layer )
495  lst.append( layerRef.layer );
496  }
497  return lst;
498 }
499 
501 {
502  if ( mMapTileResolution == res )
503  return;
504 
505  mMapTileResolution = res;
507 }
508 
510 {
511  return mMapTileResolution;
512 }
513 
515 {
516  if ( mMaxTerrainScreenError == error )
517  return;
518 
519  mMaxTerrainScreenError = error;
521 }
522 
524 {
525  return mMaxTerrainScreenError;
526 }
527 
529 {
530  if ( mMaxTerrainGroundError == error )
531  return;
532 
533  mMaxTerrainGroundError = error;
535 }
536 
538 {
539  return mMaxTerrainGroundError;
540 }
541 
543 {
544  mTerrainGenerator.reset( gen );
546 }
547 
549 {
550  if ( mTerrainShadingEnabled == enabled )
551  return;
552 
553  mTerrainShadingEnabled = enabled;
554  emit terrainShadingChanged();
555 }
556 
558 {
559  if ( mTerrainShadingMaterial == material )
560  return;
561 
562  mTerrainShadingMaterial = material;
563  emit terrainShadingChanged();
564 }
565 
566 void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
567 {
568  if ( mTerrainMapTheme == theme )
569  return;
570 
571  mTerrainMapTheme = theme;
572  emit terrainMapThemeChanged();
573 }
574 
575 void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
576 {
577  qDeleteAll( mRenderers );
578 
579  mRenderers = renderers;
580 
581  emit renderersChanged();
582 }
583 
585 {
586  if ( mShowTerrainBoundingBoxes == enabled )
587  return;
588 
589  mShowTerrainBoundingBoxes = enabled;
591 }
592 
594 {
595  if ( mShowTerrainTileInfo == enabled )
596  return;
597 
598  mShowTerrainTileInfo = enabled;
600 }
601 
603 {
604  if ( mShowCameraViewCenter == enabled )
605  return;
606 
607  mShowCameraViewCenter = enabled;
609 }
610 
612 {
613  if ( mShowLightSources == enabled )
614  return;
615 
616  mShowLightSources = enabled;
618 }
619 
621 {
622  if ( mShowLabels == enabled )
623  return;
624 
625  mShowLabels = enabled;
626  emit showLabelsChanged();
627 }
628 
629 void Qgs3DMapSettings::setPointLights( const QList<QgsPointLightSettings> &pointLights )
630 {
631  if ( mPointLights == pointLights )
632  return;
633 
634  mPointLights = pointLights;
635  emit pointLightsChanged();
636 }
637 
638 void Qgs3DMapSettings::setDirectionalLights( const QList<QgsDirectionalLightSettings> &directionalLights )
639 {
640  if ( mDirectionalLights == directionalLights )
641  return;
642 
643  mDirectionalLights = directionalLights;
645 }
646 
647 void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
648 {
649  if ( mFieldOfView == fieldOfView )
650  return;
651 
652  mFieldOfView = fieldOfView;
653  emit fieldOfViewChanged();
654 }
655 
657 {
658  mSkyboxSettings = skyboxSettings;
659  emit skyboxSettingsChanged();
660 }
661 
663 {
664  mShadowSettings = shadowSettings;
665  emit shadowSettingsChanged();
666 }
Qgs3DMapSettings::backgroundColorChanged
void backgroundColorChanged()
Emitted when the background color has changed.
Qgs3DMapSettings::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Definition: qgs3dmapsettings.h:96
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
qgsrasterlayer.h
Qgs3DMapSettings::setLayers
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of 3D map layers to be rendered in the scene.
Definition: qgs3dmapsettings.cpp:444
QgsVectorLayer3DRenderer
3D renderer that renders all features of a vector layer with the same 3D symbol.
Definition: qgsvectorlayer3drenderer.h:61
Qgs3DMapSettings::directionalLightsChanged
void directionalLightsChanged()
Emitted when the list of directional lights changes.
Qgs3DUtils::mapToWorldCoordinates
static QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords, const QgsVector3D &origin)
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dutils.cpp:430
QgsPhongMaterialSettings::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
Definition: qgsphongmaterialsettings.cpp:67
Qgs3DMapSettings::setTerrainShadingMaterial
void setTerrainShadingMaterial(const QgsPhongMaterialSettings &material)
Sets terrain shading material.
Definition: qgs3dmapsettings.cpp:557
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
Qgs3DMapSettings::worldToMapCoordinates
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dmapsettings.cpp:382
Qgs3DMapSettings::selectionColor
QColor selectionColor() const
Returns color used for selected features.
Definition: qgs3dmapsettings.cpp:425
Qgs3DMapSettings::setTerrainGenerator
void setTerrainGenerator(QgsTerrainGenerator *gen)
Sets terrain generator.
Definition: qgs3dmapsettings.cpp:542
Qgs3DMapSettings::maxTerrainGroundError
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
Definition: qgs3dmapsettings.cpp:537
QgsAbstract3DRenderer::type
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
QgsVector3D::y
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:49
QgsVector3D
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:32
Qgs3DMapSettings::showLightSourceOriginsChanged
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
QgsPointLightSettings::setPosition
void setPosition(const QgsVector3D &pos)
Sets position of the light (in 3D world coordinates)
Definition: qgspointlightsettings.h:47
Qgs3DMapSettings::mapTileResolution
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
Definition: qgs3dmapsettings.cpp:509
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
Qgs3DMapSettings::showCameraViewCenterChanged
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
qgssymbollayerutils.h
Qgs3DMapSettings::setTerrainLayers
void setTerrainLayers(const QList< QgsMapLayer * > &layers)
Sets the list of 2d map layers to be rendered in the terrain.
Definition: qgs3dmapsettings.cpp:472
QgsTemporalRangeObject::temporalRange
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
Definition: qgstemporalrangeobject.cpp:43
QgsSkyboxSettings
class containing the configuration of a skybox entity 3
Definition: qgsskyboxsettings.h:36
Qgs3DMapSettings::mapTileResolutionChanged
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
qgsdemterraingenerator.h
QgsMapLayerRef
_LayerRef< QgsMapLayer > QgsMapLayerRef
Definition: qgsmaplayerref.h:294
Qgs3DMapSettings::resolveReferences
void resolveReferences(const QgsProject &project)
Resolves references to other objects (map layers) after the call to readXml()
Definition: qgs3dmapsettings.cpp:355
Qgs3DMapSettings::terrainGeneratorChanged
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
QgsProject::mapLayer
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Definition: qgsproject.cpp:3208
Qgs3DMapSettings::setSelectionColor
void setSelectionColor(const QColor &color)
Sets color used for selected features.
Definition: qgs3dmapsettings.cpp:416
QgsCoordinateReferenceSystem::readXml
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Definition: qgscoordinatereferencesystem.cpp:2018
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
Qgs3DMapSettings::skyboxSettingsChanged
void skyboxSettingsChanged()
Emitted when skybox settings are changed.
_LayerRef::layer
QPointer< TYPE > layer
Weak pointer to map layer.
Definition: qgsmaplayerref.h:113
Qgs3DMapSettings::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Definition: qgs3dmapsettings.cpp:392
Qgs3DMapSettings::renderersChanged
void renderersChanged()
Emitted when the list of map's extra renderers have been modified.
Qgs3DMapSettings::setTerrainVerticalScale
void setTerrainVerticalScale(double zScale)
Sets vertical scale (exaggeration) of terrain (1 = true scale, > 1 = hills get more pronounced)
Definition: qgs3dmapsettings.cpp:430
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsSkyboxSettings::writeXml
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
Definition: qgsskyboxsettings.cpp:41
QgsPhongMaterialSettings
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
Definition: qgsphongmaterialsettings.h:37
Qgs3DMapSettings::maxTerrainScreenErrorChanged
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
Qgs3DMapSettings::maxTerrainScreenError
float maxTerrainScreenError() const
Returns maximum allowed screen error of terrain tiles in pixels.
Definition: qgs3dmapsettings.cpp:523
QgsAbstract3DRenderer::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
_LayerRef::layerId
QString layerId
Original layer ID.
Definition: qgsmaplayerref.h:116
QgsAbstract3DRenderer::resolveReferences
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
Definition: qgsabstract3drenderer.cpp:19
Qgs3DMapSettings::setCrs
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets coordinate reference system used in the 3D scene.
Definition: qgs3dmapsettings.cpp:387
qgsonlineterraingenerator.h
qgsmeshlayer3drenderer.h
QgsTerrainGenerator
3 Base class for generators of terrain.
Definition: qgsterraingenerator.h:48
Qgs3DMapSettings::setPointLights
void setPointLights(const QList< QgsPointLightSettings > &pointLights)
Sets list of point lights defined in the scene.
Definition: qgs3dmapsettings.cpp:629
_LayerRef::setLayer
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
Definition: qgsmaplayerref.h:77
Qgs3DMapSettings::setMaxTerrainGroundError
void setMaxTerrainGroundError(float error)
Returns maximum ground error of terrain tiles in world units.
Definition: qgs3dmapsettings.cpp:528
QgsCoordinateReferenceSystem::writeXml
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Definition: qgscoordinatereferencesystem.cpp:2123
QgsSkyboxSettings::readXml
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Definition: qgsskyboxsettings.cpp:23
QgsPointLightSettings::readXml
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()
Definition: qgspointlightsettings.cpp:37
QgsVector3D::z
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
qgs3dutils.h
Qgs3DMapSettings::setTerrainShadingEnabled
void setTerrainShadingEnabled(bool enabled)
Sets whether terrain shading is enabled.
Definition: qgs3dmapsettings.cpp:548
QgsDirectionalLightSettings::readXml
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()
Definition: qgsdirectionallightsettings.cpp:34
Qgs3DMapSettings::terrainLayersChanged
void terrainLayersChanged()
Emitted when the list of map layers for terrain texture has changed.
QgsAbstract3DRenderer::writeXml
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
QgsPointLightSettings
3 Definition of a point light in a 3D map scene
Definition: qgspointlightsettings.h:39
Qgs3DMapSettings::backgroundColor
QColor backgroundColor() const
Returns background color of the 3D map view.
Definition: qgs3dmapsettings.cpp:411
QgsTerrainGenerator::typeToString
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
Definition: qgsterraingenerator.cpp:59
Qgs3DMapSettings::terrainVerticalScaleChanged
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
Qgs3DMapSettings::setMapTileResolution
void setMapTileResolution(int res)
Sets resolution (in pixels) of the texture of a terrain tile.
Definition: qgs3dmapsettings.cpp:500
QgsOnlineTerrainGenerator::setCrs
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
Definition: qgsonlineterraingenerator.cpp:92
QgsPhongMaterialSettings::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
Definition: qgsphongmaterialsettings.cpp:59
QgsMeshLayer3DRenderer
3D renderer that renders all mesh triangles of a mesh layer.
Definition: qgsmeshlayer3drenderer.h:60
Qgs3DMapSettings
3 Definition of the world
Definition: qgs3dmapsettings.h:54
Qgs3DMapSettings::setDirectionalLights
void setDirectionalLights(const QList< QgsDirectionalLightSettings > &directionalLights)
Sets list of directional lights defined in the scene.
Definition: qgs3dmapsettings.cpp:638
Qgs3DMapSettings::setTransformContext
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
Definition: qgs3dmapsettings.cpp:397
Qgs3DMapSettings::fieldOfView
float fieldOfView() const
Returns the camera lens' field of view.
Definition: qgs3dmapsettings.h:393
Qgs3DMapSettings::fieldOfViewChanged
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
QgsFlatTerrainGenerator
3 Terrain generator that creates a simple square flat area.
Definition: qgsflatterraingenerator.h:54
Qgs3DMapSettings::pointLightsChanged
void pointLightsChanged()
Emitted when the list of point lights changes.
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsShadowSettings::readXml
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Definition: qgsshadowsettings.cpp:23
Qgs3DMapSettings::shadowSettingsChanged
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
QgsDemTerrainGenerator
3 Implementation of terrain generator that uses a raster layer with DEM to build terrain.
Definition: qgsdemterraingenerator.h:42
Qgs3DMapSettings::setFieldOfView
void setFieldOfView(const float fieldOfView)
Sets the camera lens' field of view.
Definition: qgs3dmapsettings.cpp:647
Qgs3DMapSettings::terrainShadingChanged
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
Qgs3DMapSettings::Qgs3DMapSettings
Qgs3DMapSettings()=default
Constructor for Qgs3DMapSettings.
qgs3dmapsettings.h
Qgs3DMapSettings::showTerrainBoundingBoxesChanged
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
QgsDemTerrainGenerator::setCrs
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
Definition: qgsdemterraingenerator.cpp:38
Qgs3DMapSettings::shadowSettings
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
Definition: qgs3dmapsettings.h:426
Qgs3DMapSettings::directionalLights
QList< QgsDirectionalLightSettings > directionalLights() const
Returns list of directional lights defined in the scene.
Definition: qgs3dmapsettings.h:375
Qgs3DMapSettings::~Qgs3DMapSettings
~Qgs3DMapSettings() override
Definition: qgs3dmapsettings.cpp:71
QgsShadowSettings::writeXml
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
Definition: qgsshadowsettings.cpp:33
Qgs3DMapSettings::setShowCameraViewCenter
void setShowCameraViewCenter(bool enabled)
Sets whether to show camera's view center as a sphere (for debugging)
Definition: qgs3dmapsettings.cpp:602
Qgs3DMapSettings::setShowLabels
void setShowLabels(bool enabled)
Sets whether to display labels on terrain tiles.
Definition: qgs3dmapsettings.cpp:620
QgsAbstract3DRenderer::clone
virtual QgsAbstract3DRenderer * clone() const =0
Returns a cloned instance.
QgsFlatTerrainGenerator::setCrs
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets CRS of the terrain.
Definition: qgsflatterraingenerator.cpp:136
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
Qgs3DMapSettings::layers
QList< QgsMapLayer * > layers() const
Returns the list of 3D map layers to be rendered in the scene.
Definition: qgs3dmapsettings.cpp:460
QgsOnlineTerrainGenerator
3 Implementation of terrain generator that uses online resources to download heightmaps.
Definition: qgsonlineterraingenerator.h:38
Qgs3DMapSettings::setRenderers
void setRenderers(const QList< QgsAbstract3DRenderer * > &renderers)
Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
Definition: qgs3dmapsettings.cpp:575
Qgs3DMapSettings::renderers
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
Definition: qgs3dmapsettings.h:325
Qgs3DMapSettings::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
Definition: qgs3dmapsettings.cpp:247
Qgs3DMapSettings::selectionColorChanged
void selectionColorChanged()
Emitted when the selection color has changed.
QgsShadowSettings
class containing the configuration of shadows rendering 3
Definition: qgsshadowsettings.h:35
Qgs3DMapSettings::terrainLayers
QList< QgsMapLayer * > terrainLayers() const
Returns the list of map layers to be rendered as a texture of the terrain.
Definition: qgs3dmapsettings.cpp:488
qgsvectorlayer3drenderer.h
Qgs3DMapSettings::setShowTerrainTilesInfo
void setShowTerrainTilesInfo(bool enabled)
Sets whether to display extra tile info on top of terrain tiles (for debugging)
Definition: qgs3dmapsettings.cpp:593
QgsTemporalRangeObject::setTemporalRange
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
Definition: qgstemporalrangeobject.cpp:35
Qgs3DMapSettings::terrainMapThemeChanged
void terrainMapThemeChanged()
Emitted when terrain's map theme has changed.
Qgs3DMapSettings::mapToWorldCoordinates
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dmapsettings.cpp:377
Qgs3DUtils::worldToMapCoordinates
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dutils.cpp:438
_LayerRef< QgsMapLayer >
Qgs3DMapSettings::setShadowSettings
void setShadowSettings(const QgsShadowSettings &shadowSettings)
Sets the current configuration of shadow rendering.
Definition: qgs3dmapsettings.cpp:662
Qgs3DMapSettings::skyboxSettings
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
Definition: qgs3dmapsettings.h:420
Qgs3DMapSettings::setTerrainMapTheme
void setTerrainMapTheme(const QString &theme)
Sets name of the map theme.
Definition: qgs3dmapsettings.cpp:566
Qgs3DMapSettings::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
Definition: qgs3dmapsettings.cpp:76
Qgs3DMapSettings::setMaxTerrainScreenError
void setMaxTerrainScreenError(float error)
Sets maximum allowed screen error of terrain tiles in pixels.
Definition: qgs3dmapsettings.cpp:514
QgsVector3D::x
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
qgsflatterraingenerator.h
Qgs3DMapSettings::maxTerrainGroundErrorChanged
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
Qgs3DMapSettings::setShowTerrainBoundingBoxes
void setShowTerrainBoundingBoxes(bool enabled)
Sets whether to display bounding boxes of terrain tiles (for debugging)
Definition: qgs3dmapsettings.cpp:584
QgsTemporalRangeObject
Base class for objects with an associated (optional) temporal range.
Definition: qgstemporalrangeobject.h:34
Qgs3DMapSettings::pointLights
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
Definition: qgs3dmapsettings.h:369
Qgs3DMapSettings::showLabelsChanged
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
Qgs3DMapSettings::setSkyboxSettings
void setSkyboxSettings(const QgsSkyboxSettings &skyboxSettings)
Sets the current configuration of the skybox.
Definition: qgs3dmapsettings.cpp:656
Qgs3DMapSettings::terrainVerticalScale
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
Definition: qgs3dmapsettings.cpp:439
Qgs3DMapSettings::setShowLightSourceOrigins
void setShowLightSourceOrigins(bool enabled)
Sets whether to show light source origins as a sphere (for debugging)
Definition: qgs3dmapsettings.cpp:611
Qgs3DMapSettings::layersChanged
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
Qgs3DMapSettings::showTerrainTilesInfoChanged
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.
QgsDirectionalLightSettings
3 Definition of a directional light in a 3D map scene
Definition: qgsdirectionallightsettings.h:33
Qgs3DMapSettings::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets background color of the 3D map view.
Definition: qgs3dmapsettings.cpp:402