23 #include <QDomDocument> 24 #include <QDomElement> 31 , mOrigin( other.mOrigin )
33 , mBackgroundColor( other.mBackgroundColor )
34 , mTerrainVerticalScale( other.mTerrainVerticalScale )
35 , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
36 , mMapTileResolution( other.mMapTileResolution )
37 , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
38 , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
39 , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
40 , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
41 , mLayers( other.mLayers )
42 , mSkyboxEnabled( other.mSkyboxEnabled )
43 , mSkyboxFileBase( other.mSkyboxFileBase )
44 , mSkyboxFileExtension( other.mSkyboxFileExtension )
48 mRenderers << renderer->
clone();
54 qDeleteAll( mRenderers );
59 QDomElement elemOrigin = elem.firstChildElement(
"origin" );
61 elemOrigin.attribute(
"x" ).toDouble(),
62 elemOrigin.attribute(
"y" ).toDouble(),
63 elemOrigin.attribute(
"z" ).toDouble() );
65 QDomElement elemCrs = elem.firstChildElement(
"crs" );
68 QDomElement elemTerrain = elem.firstChildElement(
"terrain" );
69 mTerrainVerticalScale = elemTerrain.attribute(
"exaggeration",
"1" ).toFloat();
70 mMapTileResolution = elemTerrain.attribute(
"texture-size",
"512" ).toInt();
71 mMaxTerrainScreenError = elemTerrain.attribute(
"max-terrain-error",
"3" ).toFloat();
72 mMaxTerrainGroundError = elemTerrain.attribute(
"max-ground-error",
"1" ).toFloat();
73 mShowLabels = elemTerrain.attribute(
"show-labels",
"0" ).toInt();
74 QDomElement elemMapLayers = elemTerrain.firstChildElement(
"layers" );
75 QDomElement elemMapLayer = elemMapLayers.firstChildElement(
"layer" );
76 QList<QgsMapLayerRef> mapLayers;
77 while ( !elemMapLayer.isNull() )
80 elemMapLayer = elemMapLayer.nextSiblingElement(
"layer" );
83 QDomElement elemTerrainGenerator = elemTerrain.firstChildElement(
"generator" );
84 QString terrainGenType = elemTerrainGenerator.attribute(
"type" );
85 if ( terrainGenType ==
"dem" )
88 demTerrainGenerator->
setCrs( mCrs, mTransformContext );
89 mTerrainGenerator.reset( demTerrainGenerator );
91 else if ( terrainGenType ==
"quantized-mesh" )
102 mTerrainGenerator.reset( flatGen );
104 mTerrainGenerator->readXml( elemTerrainGenerator );
106 qDeleteAll( mRenderers );
109 QDomElement elemRenderers = elem.firstChildElement(
"renderers" );
110 QDomElement elemRenderer = elemRenderers.firstChildElement(
"renderer" );
111 while ( !elemRenderer.isNull() )
114 QString type = elemRenderer.attribute(
"type" );
115 if ( type ==
"vector" )
122 renderer->
readXml( elemRenderer, context );
123 mRenderers.append( renderer );
125 elemRenderer = elemRenderer.nextSiblingElement(
"renderer" );
128 QDomElement elemSkybox = elem.firstChildElement(
"skybox" );
129 mSkyboxEnabled = elemSkybox.attribute(
"enabled",
"0" ).toInt();
130 mSkyboxFileBase = elemSkybox.attribute(
"file-base" );
131 mSkyboxFileExtension = elemSkybox.attribute(
"file-ext" );
133 QDomElement elemDebug = elem.firstChildElement(
"debug" );
134 mShowTerrainBoundingBoxes = elemDebug.attribute(
"bounding-boxes",
"0" ).toInt();
135 mShowTerrainTileInfo = elemDebug.attribute(
"terrain-tile-info",
"0" ).toInt();
140 QDomElement elem = doc.createElement(
"qgis3d" );
142 QDomElement elemOrigin = doc.createElement(
"origin" );
143 elemOrigin.setAttribute(
"x", QString::number( mOrigin.
x() ) );
144 elemOrigin.setAttribute(
"y", QString::number( mOrigin.
y() ) );
145 elemOrigin.setAttribute(
"z", QString::number( mOrigin.
z() ) );
146 elem.appendChild( elemOrigin );
148 QDomElement elemCrs = doc.createElement(
"crs" );
150 elem.appendChild( elemCrs );
152 QDomElement elemTerrain = doc.createElement(
"terrain" );
153 elemTerrain.setAttribute(
"exaggeration", QString::number( mTerrainVerticalScale ) );
154 elemTerrain.setAttribute(
"texture-size", mMapTileResolution );
155 elemTerrain.setAttribute(
"max-terrain-error", QString::number( mMaxTerrainScreenError ) );
156 elemTerrain.setAttribute(
"max-ground-error", QString::number( mMaxTerrainGroundError ) );
157 elemTerrain.setAttribute(
"show-labels", mShowLabels ? 1 : 0 );
158 QDomElement elemMapLayers = doc.createElement(
"layers" );
161 QDomElement elemMapLayer = doc.createElement(
"layer" );
162 elemMapLayer.setAttribute(
"id", layerRef.
layerId );
163 elemMapLayers.appendChild( elemMapLayer );
165 elemTerrain.appendChild( elemMapLayers );
166 QDomElement elemTerrainGenerator = doc.createElement(
"generator" );
168 mTerrainGenerator->writeXml( elemTerrainGenerator );
169 elemTerrain.appendChild( elemTerrainGenerator );
170 elem.appendChild( elemTerrain );
172 QDomElement elemRenderers = doc.createElement(
"renderers" );
175 QDomElement elemRenderer = doc.createElement(
"renderer" );
176 elemRenderer.setAttribute(
"type", renderer->
type() );
177 renderer->
writeXml( elemRenderer, context );
178 elemRenderers.appendChild( elemRenderer );
180 elem.appendChild( elemRenderers );
182 QDomElement elemSkybox = doc.createElement(
"skybox" );
183 elemSkybox.setAttribute(
"enabled", mSkyboxEnabled ? 1 : 0 );
185 elemSkybox.setAttribute(
"file-base", mSkyboxFileBase );
186 elemSkybox.setAttribute(
"file-ext", mSkyboxFileExtension );
187 elem.appendChild( elemSkybox );
189 QDomElement elemDebug = doc.createElement(
"debug" );
190 elemDebug.setAttribute(
"bounding-boxes", mShowTerrainBoundingBoxes ? 1 : 0 );
191 elemDebug.setAttribute(
"terrain-tile-info", mShowTerrainTileInfo ? 1 : 0 );
192 elem.appendChild( elemDebug );
199 for (
int i = 0; i < mLayers.count(); ++i )
205 mTerrainGenerator->resolveReferences( project );
207 for (
int i = 0; i < mRenderers.count(); ++i )
231 return mTransformContext;
236 mTransformContext = context;
241 if ( color == mBackgroundColor )
244 mBackgroundColor = color;
250 return mBackgroundColor;
255 if ( color == mSelectionColor )
258 mSelectionColor = color;
264 return mSelectionColor;
269 if ( zScale == mTerrainVerticalScale )
272 mTerrainVerticalScale = zScale;
278 return mTerrainVerticalScale;
283 QList<QgsMapLayerRef> lst;
284 lst.reserve( layers.count() );
290 if ( mLayers == lst )
299 QList<QgsMapLayer *> lst;
300 lst.reserve( mLayers.count() );
303 if ( layerRef.
layer )
304 lst.append( layerRef.
layer );
311 if ( mMapTileResolution == res )
314 mMapTileResolution = res;
320 return mMapTileResolution;
325 if ( mMaxTerrainScreenError == error )
328 mMaxTerrainScreenError = error;
334 return mMaxTerrainScreenError;
339 if ( mMaxTerrainGroundError == error )
342 mMaxTerrainGroundError = error;
348 return mMaxTerrainGroundError;
353 mTerrainGenerator.reset( gen );
364 if ( mShowTerrainBoundingBoxes == enabled )
367 mShowTerrainBoundingBoxes = enabled;
373 if ( mShowTerrainTileInfo == enabled )
376 mShowTerrainTileInfo = enabled;
382 if ( mShowLabels == enabled )
385 mShowLabels = enabled;
float maxTerrainScreenError() const
Returns maximum allowed screen error of terrain tiles in pixels.
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...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
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.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
void setTerrainGenerator(QgsTerrainGenerator *gen)
Sets terrain generator.
QColor selectionColor() const
Returns color used for selected features.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Base class for all renderers that may to participate in 3D view.
void layersChanged()
Emitted when the list of map layers for terrain texture has changed.
void setShowTerrainTilesInfo(bool enabled)
Sets whether to display extra tile info on top of terrain tiles (for debugging)
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x...
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
double y() const
Returns Y coordinate.
3 Definition of the world
3 Terrain generator using downloaded terrain tiles using quantized mesh specification ...
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
double z() const
Returns Z coordinate.
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...
QString layerId
Original layer ID.
void setRenderers(const QList< QgsAbstract3DRenderer *> &renderers)
Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
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...
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
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.
QColor backgroundColor() const
Returns background color of the 3D map view.
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) ...
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x...
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.
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
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.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
void setBackgroundColor(const QColor &color)
Sets background color of the 3D map view.
3 Implementation of terrain generator that uses a raster layer with DEM to build terrain.
This class represents a coordinate reference system (CRS).
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets CRS of the terrain.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
~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 setLayers(const QList< QgsMapLayer *> &layers)
Sets the list of map layers to be rendered as a texture of the terrain.
void setMaxTerrainScreenError(float error)
Sets maximum allowed screen error of terrain tiles in pixels.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
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 x() const
Returns X coordinate.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...