QGIS API Documentation  3.0.2-Girona (307d082)
qgspoint3dsymbol.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspoint3dsymbol.cpp
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk 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 "qgspoint3dsymbol.h"
17 
18 #include "qgsreadwritecontext.h"
19 #include "qgsxmlutils.h"
20 
22 {
23  return new QgsPoint3DSymbol( *this );
24 }
25 
26 void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
27 {
28  QDomDocument doc = elem.ownerDocument();
29 
30  QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
31  elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
32  elem.appendChild( elemDataProperties );
33 
34  QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
35  mMaterial.writeXml( elemMaterial );
36  elem.appendChild( elemMaterial );
37 
38  elem.setAttribute( QStringLiteral( "shape" ), shapeToString( mShape ) );
39 
40  QVariantMap shapePropertiesCopy( mShapeProperties );
41  shapePropertiesCopy["model"] = QVariant( context.pathResolver().writePath( shapePropertiesCopy["model"].toString() ) );
42 
43  QDomElement elemShapeProperties = doc.createElement( QStringLiteral( "shape-properties" ) );
44  elemShapeProperties.appendChild( QgsXmlUtils::writeVariant( shapePropertiesCopy, doc ) );
45  elem.appendChild( elemShapeProperties );
46 
47  QDomElement elemTransform = doc.createElement( QStringLiteral( "transform" ) );
48  elemTransform.setAttribute( QStringLiteral( "matrix" ), Qgs3DUtils::matrix4x4toString( mTransform ) );
49  elem.appendChild( elemTransform );
50 }
51 
52 void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
53 {
54  QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
55  mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
56 
57  QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
58  mMaterial.readXml( elemMaterial );
59 
60  mShape = shapeFromString( elem.attribute( QStringLiteral( "shape" ) ) );
61 
62  QDomElement elemShapeProperties = elem.firstChildElement( QStringLiteral( "shape-properties" ) );
63  mShapeProperties = QgsXmlUtils::readVariant( elemShapeProperties.firstChildElement() ).toMap();
64  mShapeProperties["model"] = QVariant( context.pathResolver().readPath( mShapeProperties["model"].toString() ) );
65 
66  QDomElement elemTransform = elem.firstChildElement( QStringLiteral( "transform" ) );
67  mTransform = Qgs3DUtils::stringToMatrix4x4( elemTransform.attribute( QStringLiteral( "matrix" ) ) );
68 }
69 
71 {
72  if ( shape == QStringLiteral( "sphere" ) )
73  return Sphere;
74  else if ( shape == QStringLiteral( "cone" ) )
75  return Cone;
76  else if ( shape == QStringLiteral( "cube" ) )
77  return Cube;
78  else if ( shape == QStringLiteral( "torus" ) )
79  return Torus;
80  else if ( shape == QStringLiteral( "plane" ) )
81  return Plane;
82  else if ( shape == QStringLiteral( "extruded-text" ) )
83  return ExtrudedText;
84  else if ( shape == QStringLiteral( "model" ) )
85  return Model;
86  else // "cylinder" (default)
87  return Cylinder;
88 }
89 
91 {
92  switch ( shape )
93  {
94  case Cylinder: return QStringLiteral( "cylinder" );
95  case Sphere: return QStringLiteral( "sphere" );
96  case Cone: return QStringLiteral( "cone" );
97  case Cube: return QStringLiteral( "cube" );
98  case Torus: return QStringLiteral( "torus" );
99  case Plane: return QStringLiteral( "plane" );
100  case ExtrudedText: return QStringLiteral( "extruded-text" );
101  case Model: return QStringLiteral( "model" );
102  default: Q_ASSERT( false ); return QString();
103  }
104 }
The class is used as a container of context for various read/write operations on other objects...
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Shape shape() const
Returns 3D shape for points.
Supported in Qt 5.9+.
QgsPoint3DSymbol()=default
Constructor for QgsPoint3DSymbol.
3 Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
void readXml(const QDomElement &elem)
Reads settings from a DOM element.
QgsAbstract3DSymbol * clone() const override
Returns a new instance of the symbol with the same settings.
Shape
3D shape types supported by the symbol
static Shape shapeFromString(const QString &shape)
Returns shape enum value from a string.
void writeXml(QDomElement &elem) const
Writes settings to a DOM element.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
static AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:55
static QMatrix4x4 stringToMatrix4x4(const QString &str)
Convert a string to a 4x4 transform matrix.
Definition: qgs3dutils.cpp:178
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
static QString shapeToString(Shape shape)
Returns string from a shape enum value.
static QString altClampingToString(AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:43
static QString matrix4x4toString(const QMatrix4x4 &m)
Converts a 4x4 transform matrix to a string.
Definition: qgs3dutils.cpp:169
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads symbol configuration from the given DOM element.