QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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( "renderer-3d-enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
45  elemAdvancedSettings.setAttribute( QStringLiteral( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
46  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
47  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth );
48  elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsSymbolLayerUtils::encodeColor( mWireframeLineColor ) );
49  elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-scale" ), mVerticalScale );
50  elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-group-index" ), mVerticalDatasetGroupIndex );
51  elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-relative" ), mIsVerticalMagnitudeRelative ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
52  elemAdvancedSettings.setAttribute( QStringLiteral( "texture-type" ), mRenderingStyle );
53  elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc ) );
54  elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() );
55  elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() );
56  elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) );
57  elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-enabled" ), mArrowsEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
58  elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-spacing" ), mArrowsSpacing );
59  elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-fixed-size" ), mArrowsFixedSize ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
60  elem.appendChild( elemAdvancedSettings );
61 
62  QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
64  elem.appendChild( elemDDP );
65 }
66 
67 void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
68 {
69  Q_UNUSED( context )
70 
71  //Simple symbol
72  QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
73  mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
74  mHeight = elemDataProperties.attribute( QStringLiteral( "height" ) ).toFloat();
75  mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();
76 
77  QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
78  mMaterial.readXml( elemMaterial );
79 
80  //Advanced symbol
81  QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
82  mEnabled = elemAdvancedSettings.attribute( QStringLiteral( "renderer-3d-enabled" ) ).toInt();
83  mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt();
84  mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt();
85  mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble();
86  mWireframeLineColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) );
87  mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble();
88  mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
89  mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
90  mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( QStringLiteral( "texture-type" ) ).toInt() );
91  mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ) );
92  mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() );
93  mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
94  mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );
95  mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt();
96  if ( elemAdvancedSettings.hasAttribute( QStringLiteral( "arrows-spacing" ) ) )
97  mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble();
98  mArrowsFixedSize = elemAdvancedSettings.attribute( QStringLiteral( "arrows-fixed-size" ) ).toInt();
99  QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
100  if ( !elemDDP.isNull() )
102 }
103 
105 {
106  return mSmoothedTriangles;
107 }
108 
109 void QgsMesh3DSymbol::setSmoothedTriangles( bool smoothTriangles )
110 {
111  mSmoothedTriangles = smoothTriangles;
112 }
113 
115 {
116  return mWireframeEnabled;
117 }
118 
119 void QgsMesh3DSymbol::setWireframeEnabled( bool wireframeEnabled )
120 {
121  mWireframeEnabled = wireframeEnabled;
122 }
123 
125 {
126  return mWireframeLineWidth;
127 }
128 
129 void QgsMesh3DSymbol::setWireframeLineWidth( double wireframeLineWidth )
130 {
131  mWireframeLineWidth = wireframeLineWidth;
132 }
133 
135 {
136  return mWireframeLineColor;
137 }
138 
139 void QgsMesh3DSymbol::setWireframeLineColor( const QColor &wireframeLineColor )
140 {
141  mWireframeLineColor = wireframeLineColor;
142 }
143 
145 {
146  return mVerticalScale;
147 }
148 
149 void QgsMesh3DSymbol::setVerticalScale( double verticalScale )
150 {
151  mVerticalScale = verticalScale;
152 }
153 
155 {
156  return mColorRampShader;
157 }
158 
160 {
161  mColorRampShader = colorRampShader;
162 }
163 
165 {
166  return mSingleColor;
167 }
168 
169 void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
170 {
171  mSingleColor = color;
172 }
173 
175 {
176  return mRenderingStyle;
177 }
178 
180 {
181  mRenderingStyle = coloringType;
182 }
183 
185 {
186  return mVerticalDatasetGroupIndex;
187 }
188 
189 void QgsMesh3DSymbol::setVerticalDatasetGroupIndex( int verticalDatasetGroupIndex )
190 {
191  mVerticalDatasetGroupIndex = verticalDatasetGroupIndex;
192 }
193 
195 {
196  return mIsVerticalMagnitudeRelative;
197 }
198 
199 void QgsMesh3DSymbol::setIsVerticalMagnitudeRelative( bool isVerticalScaleIsRelative )
200 {
201  mIsVerticalMagnitudeRelative = isVerticalScaleIsRelative;
202 }
203 
205 {
206  return mArrowsEnabled;
207 }
208 
209 void QgsMesh3DSymbol::setArrowsEnabled( bool vectorEnabled )
210 {
211  mArrowsEnabled = vectorEnabled;
212 }
213 
215 {
216  return mArrowsSpacing;
217 }
218 
219 void QgsMesh3DSymbol::setArrowsSpacing( double arrowsSpacing )
220 {
221  mArrowsSpacing = arrowsSpacing;
222 }
223 
225 {
226  return mMaximumTextureSize;
227 }
228 
229 void QgsMesh3DSymbol::setMaximumTextureSize( int maximumTextureSize )
230 {
231  mMaximumTextureSize = maximumTextureSize;
232 }
233 
235 {
236  return mArrowsFixedSize;
237 }
238 
239 void QgsMesh3DSymbol::setArrowsFixedSize( bool arrowsFixeSize )
240 {
241  mArrowsFixedSize = arrowsFixeSize;
242 }
243 
245 {
246  return mEnabled;
247 }
248 
249 void QgsMesh3DSymbol::setEnabled( bool enabled )
250 {
251  mEnabled = enabled;
252 }
QgsMesh3DSymbol::setArrowsEnabled
void setArrowsEnabled(bool arrowsEnabled)
Sets if arrows are enabled for 3D rendering.
Definition: qgsmesh3dsymbol.cpp:209
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsMesh3DSymbol::smoothedTriangles
bool smoothedTriangles() const
Returns if mesh triangle are smoothed.
Definition: qgsmesh3dsymbol.cpp:104
QgsMesh3DSymbol::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.
Definition: qgsmesh3dsymbol.cpp:67
QgsMesh3DSymbol::setWireframeLineWidth
void setWireframeLineWidth(double wireframeLineWidth)
Sets wireframe line width.
Definition: qgsmesh3dsymbol.cpp:129
QgsMesh3DSymbol::verticalDatasetGroupIndex
int verticalDatasetGroupIndex() const
Returns the index of the dataset group that will be used to render the vertical component of the 3D m...
Definition: qgsmesh3dsymbol.cpp:184
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsColorRampShader::writeXml
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element.
Definition: qgscolorrampshader.cpp:498
qgsmesh3dsymbol.h
qgssymbollayerutils.h
QgsAbstractPropertyCollection::readXml
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Definition: qgspropertycollection.cpp:108
QgsMesh3DSymbol::setEnabled
void setEnabled(bool enabled)
Sets if the 3d rendering is enabled.
Definition: qgsmesh3dsymbol.cpp:249
QgsRasterShaderFunction::maximumValue
double maximumValue() const
Returns the minimum value for the raster shader.
Definition: qgsrastershaderfunction.h:119
QgsMesh3DSymbol::setVerticalDatasetGroupIndex
void setVerticalDatasetGroupIndex(int verticalDatasetGroupIndex)
Sets the index of the dataset group that will be used to render the vertical component of the 3D mesh...
Definition: qgsmesh3dsymbol.cpp:189
QgsMesh3DSymbol::setRenderingStyle
void setRenderingStyle(const QgsMesh3DSymbol::RenderingStyle &textureType)
Sets the rendering style.
Definition: qgsmesh3dsymbol.cpp:179
QgsMesh3DSymbol::arrowsFixedSize
bool arrowsFixedSize() const
Returns if the arrow size is fixed.
Definition: qgsmesh3dsymbol.cpp:234
QgsMesh3DSymbol::clone
QgsAbstract3DSymbol * clone() const override
Returns a new instance of the symbol with the same settings.
Definition: qgsmesh3dsymbol.cpp:20
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsColorRampShader
Definition: qgscolorrampshader.h:39
QgsMesh3DSymbol::isVerticalMagnitudeRelative
bool isVerticalMagnitudeRelative() const
Returns if the vertical component of the mesh is relative to the mesh vertices Z value.
Definition: qgsmesh3dsymbol.cpp:194
QgsMesh3DSymbol::setArrowsSpacing
void setArrowsSpacing(double arrowsSpacing)
Sets the arrow spacing.
Definition: qgsmesh3dsymbol.cpp:219
QgsMesh3DSymbol::setColorRampShader
void setColorRampShader(const QgsColorRampShader &colorRampShader)
Sets the color ramp shader used to render the color.
Definition: qgsmesh3dsymbol.cpp:159
QgsMesh3DSymbol::setSingleMeshColor
void setSingleMeshColor(const QColor &singleMeshColor)
Sets the single color.
Definition: qgsmesh3dsymbol.cpp:169
QgsAbstract3DSymbol
Definition: qgsabstract3dsymbol.h:41
QgsMesh3DSymbol::renderingStyle
QgsMesh3DSymbol::RenderingStyle renderingStyle() const
Returns the rendering style.
Definition: qgsmesh3dsymbol.cpp:174
QgsMesh3DSymbol::setWireframeLineColor
void setWireframeLineColor(const QColor &wireframeLineColor)
Sets wireframe line color.
Definition: qgsmesh3dsymbol.cpp:139
QgsMesh3DSymbol::QgsMesh3DSymbol
QgsMesh3DSymbol()=default
Constructor for QgsMesh3DSymbol.
QgsMesh3DSymbol::wireframeLineColor
QColor wireframeLineColor() const
Returns wireframe line color.
Definition: qgsmesh3dsymbol.cpp:134
QgsMesh3DSymbol::colorRampShader
QgsColorRampShader colorRampShader() const
Returns the color ramp shader used to render the color.
Definition: qgsmesh3dsymbol.cpp:154
qgs3dutils.h
QgsAbstract3DSymbol::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
Definition: qgsabstract3dsymbol.cpp:22
QgsMesh3DSymbol::setVerticalScale
void setVerticalScale(double verticalScale)
Sets mesh vertical scale.
Definition: qgsmesh3dsymbol.cpp:149
QgsRasterShaderFunction::setMaximumValue
virtual void setMaximumValue(double value)
Sets the maximum value for the raster shader.
Definition: qgsrastershaderfunction.cpp:30
QgsMesh3DSymbol::setIsVerticalMagnitudeRelative
void setIsVerticalMagnitudeRelative(bool isVerticalMagnitudeRelative)
Sets if the vertical component of the mesh is relative to the mesh vertices Z value.
Definition: qgsmesh3dsymbol.cpp:199
QgsAbstract3DSymbol::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgsabstract3dsymbol.h:76
QgsColorRampShader::readXml
void readXml(const QDomElement &elem)
Reads configuration from the given DOM element.
Definition: qgscolorrampshader.cpp:529
Qgs3DUtils::altClampingToString
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
QgsPhongMaterialSettings::readXml
void readXml(const QDomElement &elem)
Reads settings from a DOM element.
Definition: qgsphongmaterialsettings.cpp:21
QgsRasterShaderFunction::minimumValue
double minimumValue() const
Returns the maximum value for the raster shader.
Definition: qgsrastershaderfunction.h:112
Qgs3DUtils::altClampingFromString
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
QgsMesh3DSymbol::setArrowsFixedSize
void setArrowsFixedSize(bool arrowsFixedSize)
Sets if the arrow size is fixed.
Definition: qgsmesh3dsymbol.cpp:239
QgsMesh3DSymbol::arrowsEnabled
bool arrowsEnabled() const
Returns if arrows are enabled for 3D rendering.
Definition: qgsmesh3dsymbol.cpp:204
QgsMesh3DSymbol::RenderingStyle
RenderingStyle
How to render the color of the mesh.
Definition: qgsmesh3dsymbol.h:51
QgsMesh3DSymbol::setSmoothedTriangles
void setSmoothedTriangles(bool smoothTriangles)
Sets if the mesh triangles have to been smoothed.
Definition: qgsmesh3dsymbol.cpp:109
QgsMesh3DSymbol::setMaximumTextureSize
void setMaximumTextureSize(int maximumTextureSize)
Sets the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE value t...
Definition: qgsmesh3dsymbol.cpp:229
QgsMesh3DSymbol::wireframeEnabled
bool wireframeEnabled() const
Returns if the mesh wireframe.
Definition: qgsmesh3dsymbol.cpp:114
QgsMesh3DSymbol::verticalScale
double verticalScale() const
Returns mesh vertical scale.
Definition: qgsmesh3dsymbol.cpp:144
QgsMesh3DSymbol::arrowsSpacing
double arrowsSpacing() const
Returns the arrow spacing.
Definition: qgsmesh3dsymbol.cpp:214
QgsPhongMaterialSettings::writeXml
void writeXml(QDomElement &elem) const
Writes settings to a DOM element.
Definition: qgsphongmaterialsettings.cpp:29
QgsMesh3DSymbol::setWireframeEnabled
void setWireframeEnabled(bool wireframeEnabled)
Sets if the mesh wireframe.
Definition: qgsmesh3dsymbol.cpp:119
QgsMesh3DSymbol::isEnabled
bool isEnabled() const
Returns if the 3d rendering is enabled.
Definition: qgsmesh3dsymbol.cpp:244
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99
QgsRasterShaderFunction::setMinimumValue
virtual void setMinimumValue(double value)
Sets the minimum value for the raster shader.
Definition: qgsrastershaderfunction.cpp:38
QgsMesh3DSymbol::wireframeLineWidth
double wireframeLineWidth() const
Returns wireframe line width.
Definition: qgsmesh3dsymbol.cpp:124
QgsMesh3DSymbol::singleMeshColor
QColor singleMeshColor() const
Returns the single color.
Definition: qgsmesh3dsymbol.cpp:164
QgsMesh3DSymbol::maximumTextureSize
int maximumTextureSize() const
Returns the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE valu...
Definition: qgsmesh3dsymbol.cpp:224
QgsMesh3DSymbol::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
Definition: qgsmesh3dsymbol.cpp:25