QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
18#include "qgs3drendercontext.h"
19#include "qgsmeshlayer.h"
20#include "qgsmeshterraingenerator.h"
21
26
28 : mSymbol( std::make_unique<QgsMesh3DSymbol>() )
29{
30}
31
33
35{
36 auto cloned = std::make_unique<QgsMeshTerrainSettings>();
37 cloned->mSymbol.reset( mSymbol->clone() );
38 cloned->mLayer = mLayer;
39 cloned->copyCommonProperties( this );
40 return cloned.release();
41}
42
44{
45 return QStringLiteral( "mesh" );
46}
47
48void QgsMeshTerrainSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
49{
50 if ( element.hasAttribute( QStringLiteral( "layer" ) ) )
51 {
52 mLayer = QgsMapLayerRef( element.attribute( QStringLiteral( "layer" ) ) );
53 mSymbol->readXml( element.firstChildElement( "symbol" ), context );
54 }
55 else
56 {
57 // restore old project
58 const QDomElement elemTerrainGenerator = element.firstChildElement( QStringLiteral( "generator" ) );
59 mLayer = QgsMapLayerRef( elemTerrainGenerator.attribute( QStringLiteral( "layer" ) ) );
60 mSymbol->readXml( elemTerrainGenerator.firstChildElement( "symbol" ), context );
61 }
62
63 readCommonProperties( element, context );
64}
65
66void QgsMeshTerrainSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
67{
68 element.setAttribute( QStringLiteral( "layer" ), mLayer.layerId );
69
70 {
71 QDomElement elemSymbol = element.ownerDocument().createElement( "symbol" );
72 mSymbol->writeXml( elemSymbol, context );
73 element.appendChild( elemSymbol );
74 }
75
76 writeCommonProperties( element, context );
77}
78
80{
81 mLayer.resolve( project );
82}
83
85{
86 const QgsMeshTerrainSettings *otherMeshTerrain = dynamic_cast<const QgsMeshTerrainSettings *>( other );
87 if ( !otherMeshTerrain )
88 return false;
89
90 if ( *mSymbol != *otherMeshTerrain->mSymbol )
91 return false;
92
93 if ( !equalsCommon( otherMeshTerrain ) )
94 return false;
95
96 return mLayer.layerId == otherMeshTerrain->mLayer.layerId;
97}
98
99std::unique_ptr<QgsTerrainGenerator> QgsMeshTerrainSettings::createTerrainGenerator( const Qgs3DRenderContext &context ) const
100{
101 auto generator = std::make_unique<QgsMeshTerrainGenerator>();
102 generator->setLayer( layer() );
103 std::unique_ptr<QgsMesh3DSymbol> symbol( mSymbol->clone() );
104 symbol->setVerticalScale( verticalScale() );
105 generator->setSymbol( symbol.release() );
106 generator->setCrs( context.crs(), context.transformContext() );
107 generator->setExtent( context.extent() );
108 return generator;
109}
110
115
117{
118 return qobject_cast<QgsMeshLayer *>( mLayer.layer.data() );
119}
120
122{
123 return mSymbol.get();
124}
125
127{
128 mSymbol.reset( symbol );
129}
Rendering context for preparation of 3D entities.
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...
Base class for all terrain settings classes.
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.
3D symbol that draws mesh geometry as planar triangles.
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:109
A container for the context for various read/write operations on objects.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QString layerId
Original layer ID.