24 #include <QDomDocument> 25 #include <QDomElement> 32 , mOrigin( other.mOrigin )
34 , mBackgroundColor( other.mBackgroundColor )
35 , mTerrainVerticalScale( other.mTerrainVerticalScale )
36 , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
37 , mMapTileResolution( other.mMapTileResolution )
38 , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
39 , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
40 , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
41 , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
42 , mShowCameraViewCenter( other.mShowCameraViewCenter )
43 , mLayers( other.mLayers )
44 , mSkyboxEnabled( other.mSkyboxEnabled )
45 , mSkyboxFileBase( other.mSkyboxFileBase )
46 , mSkyboxFileExtension( other.mSkyboxFileExtension )
50 mRenderers << renderer->
clone();
56 qDeleteAll( mRenderers );
61 QDomElement elemOrigin = elem.firstChildElement( QStringLiteral(
"origin" ) );
63 elemOrigin.attribute( QStringLiteral(
"x" ) ).toDouble(),
64 elemOrigin.attribute( QStringLiteral(
"y" ) ).toDouble(),
65 elemOrigin.attribute( QStringLiteral(
"z" ) ).toDouble() );
67 QDomElement elemColor = elem.firstChildElement( QStringLiteral(
"color" ) );
68 if ( !elemColor.isNull() )
74 QDomElement elemCrs = elem.firstChildElement( QStringLiteral(
"crs" ) );
77 QDomElement elemTerrain = elem.firstChildElement( QStringLiteral(
"terrain" ) );
78 mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral(
"exaggeration" ), QStringLiteral(
"1" ) ).toFloat();
79 mMapTileResolution = elemTerrain.attribute( QStringLiteral(
"texture-size" ), QStringLiteral(
"512" ) ).toInt();
80 mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral(
"max-terrain-error" ), QStringLiteral(
"3" ) ).toFloat();
81 mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral(
"max-ground-error" ), QStringLiteral(
"1" ) ).toFloat();
82 mShowLabels = elemTerrain.attribute( QStringLiteral(
"show-labels" ), QStringLiteral(
"0" ) ).toInt();
83 QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral(
"layers" ) );
84 QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral(
"layer" ) );
85 QList<QgsMapLayerRef> mapLayers;
86 while ( !elemMapLayer.isNull() )
88 mapLayers <<
QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral(
"id" ) ) );
89 elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral(
"layer" ) );
92 QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral(
"generator" ) );
93 QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral(
"type" ) );
94 if ( terrainGenType == QLatin1String(
"dem" ) )
97 demTerrainGenerator->
setCrs( mCrs, mTransformContext );
98 mTerrainGenerator.reset( demTerrainGenerator );
100 else if ( terrainGenType == QLatin1String(
"quantized-mesh" ) )
111 mTerrainGenerator.reset( flatGen );
113 mTerrainGenerator->readXml( elemTerrainGenerator );
115 qDeleteAll( mRenderers );
118 QDomElement elemRenderers = elem.firstChildElement( QStringLiteral(
"renderers" ) );
119 QDomElement elemRenderer = elemRenderers.firstChildElement( QStringLiteral(
"renderer" ) );
120 while ( !elemRenderer.isNull() )
123 QString type = elemRenderer.attribute( QStringLiteral(
"type" ) );
124 if ( type == QLatin1String(
"vector" ) )
131 renderer->
readXml( elemRenderer, context );
132 mRenderers.append( renderer );
134 elemRenderer = elemRenderer.nextSiblingElement( QStringLiteral(
"renderer" ) );
137 QDomElement elemSkybox = elem.firstChildElement( QStringLiteral(
"skybox" ) );
138 mSkyboxEnabled = elemSkybox.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ).toInt();
139 mSkyboxFileBase = elemSkybox.attribute( QStringLiteral(
"file-base" ) );
140 mSkyboxFileExtension = elemSkybox.attribute( QStringLiteral(
"file-ext" ) );
142 QDomElement elemDebug = elem.firstChildElement( QStringLiteral(
"debug" ) );
143 mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral(
"bounding-boxes" ), QStringLiteral(
"0" ) ).toInt();
144 mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral(
"terrain-tile-info" ), QStringLiteral(
"0" ) ).toInt();
145 mShowCameraViewCenter = elemDebug.attribute( QStringLiteral(
"camera-view-center" ), QStringLiteral(
"0" ) ).toInt();
150 QDomElement elem = doc.createElement( QStringLiteral(
"qgis3d" ) );
152 QDomElement elemOrigin = doc.createElement( QStringLiteral(
"origin" ) );
153 elemOrigin.setAttribute( QStringLiteral(
"x" ), QString::number( mOrigin.
x() ) );
154 elemOrigin.setAttribute( QStringLiteral(
"y" ), QString::number( mOrigin.
y() ) );
155 elemOrigin.setAttribute( QStringLiteral(
"z" ), QString::number( mOrigin.
z() ) );
156 elem.appendChild( elemOrigin );
158 QDomElement elemColor = doc.createElement( QStringLiteral(
"color" ) );
161 elem.appendChild( elemColor );
163 QDomElement elemCrs = doc.createElement( QStringLiteral(
"crs" ) );
165 elem.appendChild( elemCrs );
167 QDomElement elemTerrain = doc.createElement( QStringLiteral(
"terrain" ) );
168 elemTerrain.setAttribute( QStringLiteral(
"exaggeration" ), QString::number( mTerrainVerticalScale ) );
169 elemTerrain.setAttribute( QStringLiteral(
"texture-size" ), mMapTileResolution );
170 elemTerrain.setAttribute( QStringLiteral(
"max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
171 elemTerrain.setAttribute( QStringLiteral(
"max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
172 elemTerrain.setAttribute( QStringLiteral(
"show-labels" ), mShowLabels ? 1 : 0 );
173 QDomElement elemMapLayers = doc.createElement( QStringLiteral(
"layers" ) );
176 QDomElement elemMapLayer = doc.createElement( QStringLiteral(
"layer" ) );
177 elemMapLayer.setAttribute( QStringLiteral(
"id" ), layerRef.
layerId );
178 elemMapLayers.appendChild( elemMapLayer );
180 elemTerrain.appendChild( elemMapLayers );
181 QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral(
"generator" ) );
183 mTerrainGenerator->writeXml( elemTerrainGenerator );
184 elemTerrain.appendChild( elemTerrainGenerator );
185 elem.appendChild( elemTerrain );
187 QDomElement elemRenderers = doc.createElement( QStringLiteral(
"renderers" ) );
190 QDomElement elemRenderer = doc.createElement( QStringLiteral(
"renderer" ) );
191 elemRenderer.setAttribute( QStringLiteral(
"type" ), renderer->
type() );
192 renderer->
writeXml( elemRenderer, context );
193 elemRenderers.appendChild( elemRenderer );
195 elem.appendChild( elemRenderers );
197 QDomElement elemSkybox = doc.createElement( QStringLiteral(
"skybox" ) );
198 elemSkybox.setAttribute( QStringLiteral(
"enabled" ), mSkyboxEnabled ? 1 : 0 );
200 elemSkybox.setAttribute( QStringLiteral(
"file-base" ), mSkyboxFileBase );
201 elemSkybox.setAttribute( QStringLiteral(
"file-ext" ), mSkyboxFileExtension );
202 elem.appendChild( elemSkybox );
204 QDomElement elemDebug = doc.createElement( QStringLiteral(
"debug" ) );
205 elemDebug.setAttribute( QStringLiteral(
"bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
206 elemDebug.setAttribute( QStringLiteral(
"terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
207 elemDebug.setAttribute( QStringLiteral(
"camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
208 elem.appendChild( elemDebug );
215 for (
int i = 0; i < mLayers.count(); ++i )
221 mTerrainGenerator->resolveReferences( project );
223 for (
int i = 0; i < mRenderers.count(); ++i )
247 return mTransformContext;
252 mTransformContext = context;
257 if ( color == mBackgroundColor )
260 mBackgroundColor = color;
266 return mBackgroundColor;
271 if ( color == mSelectionColor )
274 mSelectionColor = color;
280 return mSelectionColor;
285 if ( zScale == mTerrainVerticalScale )
288 mTerrainVerticalScale = zScale;
294 return mTerrainVerticalScale;
299 QList<QgsMapLayerRef> lst;
300 lst.reserve( layers.count() );
306 if ( mLayers == lst )
315 QList<QgsMapLayer *> lst;
316 lst.reserve( mLayers.count() );
319 if ( layerRef.
layer )
320 lst.append( layerRef.
layer );
327 if ( mMapTileResolution == res )
330 mMapTileResolution = res;
336 return mMapTileResolution;
341 if ( mMaxTerrainScreenError == error )
344 mMaxTerrainScreenError = error;
350 return mMaxTerrainScreenError;
355 if ( mMaxTerrainGroundError == error )
358 mMaxTerrainGroundError = error;
364 return mMaxTerrainGroundError;
369 mTerrainGenerator.reset( gen );
380 if ( mShowTerrainBoundingBoxes == enabled )
383 mShowTerrainBoundingBoxes = enabled;
389 if ( mShowTerrainTileInfo == enabled )
392 mShowTerrainTileInfo = enabled;
398 if ( mShowCameraViewCenter == enabled )
401 mShowCameraViewCenter = enabled;
407 if ( mShowLabels == enabled )
410 mShowLabels = enabled;
QList< QgsMapLayer * > layers() const
Returns the list of map layers to be rendered as a texture of the terrain.
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...
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets coordinate reference system used in the 3D scene.
3 Terrain generator that creates a simple square flat area.
Base class for all map layer types.
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
void setShowCameraViewCenter(bool enabled)
Sets whether to show camera's view center as a sphere (for debugging)
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x...
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
void setTerrainGenerator(QgsTerrainGenerator *gen)
Sets terrain generator.
_LayerRef< QgsMapLayer > QgsMapLayerRef
Base class for all renderers that may to participate in 3D view.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
void layersChanged()
Emitted when the list of map layers for terrain texture has changed.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void setShowTerrainTilesInfo(bool enabled)
Sets whether to display extra tile info on top of terrain tiles (for debugging)
double z() const
Returns Z coordinate.
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
3 Definition of the world
QColor selectionColor() const
Returns color used for selected features.
3 Terrain generator using downloaded terrain tiles using quantized mesh specification ...
static QString encodeColor(const QColor &color)
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
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...
QColor backgroundColor() const
Returns background color of the 3D map view.
QString layerId
Original layer ID.
double x() const
Returns X coordinate.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of map layers to be rendered as a texture of the terrain.
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
QPointer< TYPE > layer
Weak pointer to map layer.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x...
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
void selectionColorChanged()
Emitted when the selection color has changed.
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...
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
Reads and writes project states.
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
Contains information about the context in which a coordinate transform is executed.
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
void setMaxTerrainGroundError(float error)
Returns maximum ground error of terrain tiles in world units.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void setTerrainVerticalScale(double zScale)
Sets vertical scale (exaggeration) of terrain (1 = true scale, > 1 = hills get more pronounced) ...
double y() const
Returns Y coordinate.
3D renderer that renders all features of a vector layer with the same 3D symbol.
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.
void setMapTileResolution(int res)
Sets resolution (in pixels) of the texture of a terrain tile.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
Qgs3DMapSettings()=default
Constructor for Qgs3DMapSettings.
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
3 Base class for generators of terrain.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void setBackgroundColor(const QColor &color)
Sets background color of the 3D map view.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
3 Implementation of terrain generator that uses a raster layer with DEM to build terrain.
This class represents a coordinate reference system (CRS).
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets CRS of the terrain.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
~Qgs3DMapSettings() override
void setShowLabels(bool enabled)
Sets whether to display labels on terrain tiles.
virtual QgsAbstract3DRenderer * clone() const =0
Returns a cloned instance.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
void backgroundColorChanged()
Emitted when the background color has changed.
void setMaxTerrainScreenError(float error)
Sets maximum allowed screen error of terrain tiles in pixels.
void setRenderers(const QList< QgsAbstract3DRenderer * > &renderers)
Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
void resolveReferences(const QgsProject &project)
Resolves references to other objects (map layers) after the call to readXml()
void setShowTerrainBoundingBoxes(bool enabled)
Sets whether to display bounding boxes of terrain tiles (for debugging)
void setSelectionColor(const QColor &color)
Sets color used for selected features.
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
float maxTerrainScreenError() const
Returns maximum allowed screen error of terrain tiles in pixels.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...
static QColor decodeColor(const QString &str)