QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsmeshterrainsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshterrainsettings.cpp
3 --------------------------------------
4 Date : August 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson 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
17#include "qgsmeshlayer.h"
18#include "qgsmeshterraingenerator.h"
19#include "qgs3drendercontext.h"
20
25
27 : mSymbol( std::make_unique<QgsMesh3DSymbol>() )
28{
29}
30
32
34{
35 std::unique_ptr<QgsMeshTerrainSettings> cloned = std::make_unique<QgsMeshTerrainSettings>();
36 cloned->mSymbol.reset( mSymbol->clone() );
37 cloned->mLayer = mLayer;
38 cloned->copyCommonProperties( this );
39 return cloned.release();
40}
41
43{
44 return QStringLiteral( "mesh" );
45}
46
47void QgsMeshTerrainSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
48{
49 if ( element.hasAttribute( QStringLiteral( "layer" ) ) )
50 {
51 mLayer = QgsMapLayerRef( element.attribute( QStringLiteral( "layer" ) ) );
52 mSymbol->readXml( element.firstChildElement( "symbol" ), context );
53 }
54 else
55 {
56 // restore old project
57 const QDomElement elemTerrainGenerator = element.firstChildElement( QStringLiteral( "generator" ) );
58 mLayer = QgsMapLayerRef( elemTerrainGenerator.attribute( QStringLiteral( "layer" ) ) );
59 mSymbol->readXml( elemTerrainGenerator.firstChildElement( "symbol" ), context );
60 }
61
62 readCommonProperties( element, context );
63}
64
65void QgsMeshTerrainSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
66{
67 element.setAttribute( QStringLiteral( "layer" ), mLayer.layerId );
68
69 {
70 QDomElement elemSymbol = element.ownerDocument().createElement( "symbol" );
71 mSymbol->writeXml( elemSymbol, context );
72 element.appendChild( elemSymbol );
73 }
74
75 writeCommonProperties( element, context );
76}
77
79{
80 mLayer.resolve( project );
81}
82
84{
85 const QgsMeshTerrainSettings *otherMeshTerrain = dynamic_cast<const QgsMeshTerrainSettings *>( other );
86 if ( !otherMeshTerrain )
87 return false;
88
89 if ( *mSymbol != *otherMeshTerrain->mSymbol )
90 return false;
91
92 if ( !equalsCommon( otherMeshTerrain ) )
93 return false;
94
95 return mLayer.layerId == otherMeshTerrain->mLayer.layerId;
96}
97
98std::unique_ptr<QgsTerrainGenerator> QgsMeshTerrainSettings::createTerrainGenerator( const Qgs3DRenderContext &context ) const
99{
100 std::unique_ptr<QgsMeshTerrainGenerator> generator = std::make_unique<QgsMeshTerrainGenerator>();
101 generator->setLayer( layer() );
102 std::unique_ptr<QgsMesh3DSymbol> symbol( mSymbol->clone() );
104 generator->setSymbol( symbol.release() );
105 generator->setCrs( context.crs(), context.transformContext() );
106 generator->setExtent( context.extent() );
107 return generator;
108}
109
111{
112 mLayer = QgsMapLayerRef( layer );
113}
114
116{
117 return qobject_cast<QgsMeshLayer *>( mLayer.layer.data() );
118}
119
121{
122 return mSymbol.get();
123}
124
126{
127 mSymbol.reset( symbol );
128}
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system used in the 3D scene.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void writeCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Writes common properties from the base class into an XML element.
bool equalsCommon(const QgsAbstractTerrainSettings *other) const
Returns true if common base class settings from other match this object.
double verticalScale() const
Returns the vertical scale (exaggeration) for terrain.
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from the base class from the given DOM element.
void setVerticalScale(double verticalScale)
Sets mesh vertical scale.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
bool equals(const QgsAbstractTerrainSettings *other) const final
Returns true if this settings is exactly equal to another other settings.
void resolveReferences(const QgsProject *project) final
After reading settings from XML, resolves references to any layers in a project that have been read a...
void setSymbol(QgsMesh3DSymbol *symbol)
Sets the symbol used to render the mesh as terrain.
QString type() const final
Returns the unique type name for the terrain generator.
void readXml(const QDomElement &element, const QgsReadWriteContext &context) final
Reads settings from a DOM element.
QgsMeshTerrainSettings * clone() const final
Returns a copy of the terrain settings.
QgsMeshLayer * layer() const
Returns the mesh layer with elevation model to be used for terrain generation.
QgsMesh3DSymbol * symbol() const
Returns the symbol used to render the mesh as terrain.
~QgsMeshTerrainSettings() override
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const final
Writes settings to a DOM element.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsMeshTerrainSettings object.
void setLayer(QgsMeshLayer *layer)
Sets the mesh layer with elevation model to be used for terrain generation.
std::unique_ptr< QgsTerrainGenerator > createTerrainGenerator(const Qgs3DRenderContext &context) const override
Creates a new instance of a terrain generator which matches the terrain settings.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
The class is used as a container of context for various read/write operations on other objects.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QPointer< TYPE > layer
Weak pointer to map layer.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
QString layerId
Original layer ID.