QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgsmesh3dsymbol.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmesh3dsymbol.cpp
3  -------------------
4  Date : January 2019
5  Copyright : (C) 2019 by Peter Petrik
6  Email : zilolv 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 "qgsmesh3dsymbol.h"
17 #include "qgssymbollayerutils.h"
18 #include "qgs3dutils.h"
19 
21 {
22  return new QgsMesh3DSymbol( *this );
23 }
24 
25 void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
26 {
27  Q_UNUSED( context )
28 
29  QDomDocument doc = elem.ownerDocument();
30 
31  //Simple symbol
32  QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
33  elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
34  elemDataProperties.setAttribute( QStringLiteral( "height" ), mHeight );
35  elemDataProperties.setAttribute( QStringLiteral( "add-back-faces" ), mAddBackFaces ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
36  elem.appendChild( elemDataProperties );
37 
38  QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
39  mMaterial.writeXml( elemMaterial );
40  elem.appendChild( elemMaterial );
41 
42  //Advanced symbol
43  QDomElement elemAdvancedSettings = doc.createElement( QStringLiteral( "advanced-settings" ) );
44  elemAdvancedSettings.setAttribute( QStringLiteral( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
45  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
46  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth );
47  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsSymbolLayerUtils::encodeColor( mWireframeLineColor ) );
48  elemAdvancedSettings.setAttribute( QStringLiteral( "verticale-scale" ), mVerticaleScale );
49  elemAdvancedSettings.setAttribute( QStringLiteral( "texture-type" ), mRenderingStyle );
50  elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc ) );
51  elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() );
52  elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() );
53  elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) );
54  elem.appendChild( elemAdvancedSettings );
55 
56  QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
58  elem.appendChild( elemDDP );
59 }
60 
61 void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
62 {
63  Q_UNUSED( context )
64 
65  //Simple symbol
66  QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
67  mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
68  mHeight = elemDataProperties.attribute( QStringLiteral( "height" ) ).toFloat();
69  mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();
70 
71  QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
72  mMaterial.readXml( elemMaterial );
73 
74  //Advanced symbol
75  QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
76  mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt();
77  mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt();
78  mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble();
79  mWireframeLineColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) );
80  mVerticaleScale = elemAdvancedSettings.attribute( "verticale-scale" ).toDouble();
81  mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( QStringLiteral( "texture-type" ) ).toInt() );
82  mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ) );
83  mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() );
84  mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
85  mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );
86 
87  QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
88  if ( !elemDDP.isNull() )
90 }
91 
93 {
94  return mSmoothedTriangles;
95 }
96 
97 void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
98 {
99  mSmoothedTriangles = smoothTriangles;
100 }
101 
103 {
104  return mWireframeEnabled;
105 }
106 
108 {
109  mWireframeEnabled = wireframeEnabled;
110 }
111 
113 {
114  return mWireframeLineWidth;
115 }
116 
118 {
119  mWireframeLineWidth = wireframeLineWidth;
120 }
121 
123 {
124  return mWireframeLineColor;
125 }
126 
128 {
129  mWireframeLineColor = wireframeLineColor;
130 }
131 
133 {
134  return mVerticaleScale;
135 }
136 
138 {
139  mVerticaleScale = verticaleScale;
140 }
141 
143 {
144  return mColorRampShader;
145 }
146 
148 {
149  mColorRampShader = colorRampShader;
150 }
151 
153 {
154  return mSingleColor;
155 }
156 
157 void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
158 {
159  mSingleColor = color;
160 }
161 
163 {
164  return mRenderingStyle;
165 }
166 
168 {
169  mRenderingStyle = coloringType;
170 }
The class is used as a container of context for various read/write operations on other objects...
virtual void setMinimumValue(double value)
Sets the minimum value for the raster shader.
void setRenderingStyle(const QgsMesh3DSymbol::RenderingStyle &textureType)
Sets the rendering style.
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
bool wireframeEnabled() const
Returns if the mesh wireframe.
QgsPropertyCollection mDataDefinedProperties
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
double verticaleScale() const
Returns mesh verticale scale.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
void setSingleMeshColor(const QColor &singleMeshColor)
Sets the single color.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
void setSmoothedTriangles(bool smoothTriangles)
Sets if the mesh triangles have to been smoothed.
QgsMesh3DSymbol()=default
Constructor for QgsMesh3DSymbol.
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
void setWireframeLineWidth(double wireframeLineWidth)
Sets wireframe line width.
double maximumValue() const
Returns the minimum value for the raster shader.
void setWireframeEnabled(bool wireframeEnabled)
Sets if the mesh wireframe.
3 Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
double wireframeLineWidth() const
Returns wireframe line width.
static QString encodeColor(const QColor &color)
virtual void setMaximumValue(double value)
Sets the maximum value for the raster shader.
void setVerticaleScale(double verticaleScale)
Sets mesh verticale scale.
QColor singleMeshColor() const
Returns the single color.
void readXml(const QDomElement &elem)
Reads settings from a DOM element.
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Sets the color ramp shader used to render the color.
double minimumValue() const
Returns the maximum value for the raster shader.
void setWireframeLineColor(const QColor &wireframeLineColor)
Sets wireframe line color.
QgsAbstract3DSymbol * clone() const override
Returns a new instance of the symbol with the same settings.
void writeXml(QDomElement &elem) const
Writes settings to a DOM element.
bool smoothedTriangles() const
Returns if mesh triangle are smoothed.
QColor wireframeLineColor() const
Returns wireframe line color.
QgsColorRampShader colorRampShader() const
Returns the color ramp shader used to render the color.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
RenderingStyle
How to render the color of the mesh with advanced symbology.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.
static QColor decodeColor(const QString &str)
QgsMesh3DSymbol::RenderingStyle renderingStyle() const
Returns the rendering style.