QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 "qgs3dutils.h"
19 #include "qgsreadwritecontext.h"
20 #include "qgsxmlutils.h"
21 
23 {
24  return new QgsPoint3DSymbol( *this );
25 }
26 
27 void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
28 {
29  QDomDocument doc = elem.ownerDocument();
30 
31  QDomElement elemDataProperties = doc.createElement( QStringLiteral( "data" ) );
32  elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
33  elem.appendChild( elemDataProperties );
34 
35  QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
36  mMaterial.writeXml( elemMaterial );
37  elem.appendChild( elemMaterial );
38 
39  elem.setAttribute( QStringLiteral( "shape" ), shapeToString( mShape ) );
40 
41  QVariantMap shapePropertiesCopy( mShapeProperties );
42  shapePropertiesCopy[QStringLiteral( "model" )] = QVariant( context.pathResolver().writePath( shapePropertiesCopy[QStringLiteral( "model" )].toString() ) );
43 
44  QDomElement elemShapeProperties = doc.createElement( QStringLiteral( "shape-properties" ) );
45  elemShapeProperties.appendChild( QgsXmlUtils::writeVariant( shapePropertiesCopy, doc ) );
46  elem.appendChild( elemShapeProperties );
47 
48  QDomElement elemTransform = doc.createElement( QStringLiteral( "transform" ) );
49  elemTransform.setAttribute( QStringLiteral( "matrix" ), Qgs3DUtils::matrix4x4toString( mTransform ) );
50  elem.appendChild( elemTransform );
51 }
52 
53 void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
54 {
55  QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
56  mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
57 
58  QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
59  mMaterial.readXml( elemMaterial );
60 
61  mShape = shapeFromString( elem.attribute( QStringLiteral( "shape" ) ) );
62 
63  QDomElement elemShapeProperties = elem.firstChildElement( QStringLiteral( "shape-properties" ) );
64  mShapeProperties = QgsXmlUtils::readVariant( elemShapeProperties.firstChildElement() ).toMap();
65  mShapeProperties[QStringLiteral( "model" )] = QVariant( context.pathResolver().readPath( mShapeProperties[QStringLiteral( "model" )].toString() ) );
66 
67  QDomElement elemTransform = elem.firstChildElement( QStringLiteral( "transform" ) );
68  mTransform = Qgs3DUtils::stringToMatrix4x4( elemTransform.attribute( QStringLiteral( "matrix" ) ) );
69 }
70 
72 {
73  if ( shape == QStringLiteral( "sphere" ) )
74  return Sphere;
75  else if ( shape == QStringLiteral( "cone" ) )
76  return Cone;
77  else if ( shape == QStringLiteral( "cube" ) )
78  return Cube;
79  else if ( shape == QStringLiteral( "torus" ) )
80  return Torus;
81  else if ( shape == QStringLiteral( "plane" ) )
82  return Plane;
83  else if ( shape == QStringLiteral( "extruded-text" ) )
84  return ExtrudedText;
85  else if ( shape == QStringLiteral( "model" ) )
86  return Model;
87  else // "cylinder" (default)
88  return Cylinder;
89 }
90 
92 {
93  switch ( shape )
94  {
95  case Cylinder: return QStringLiteral( "cylinder" );
96  case Sphere: return QStringLiteral( "sphere" );
97  case Cone: return QStringLiteral( "cone" );
98  case Cube: return QStringLiteral( "cube" );
99  case Torus: return QStringLiteral( "torus" );
100  case Plane: return QStringLiteral( "plane" );
101  case ExtrudedText: return QStringLiteral( "extruded-text" );
102  case Model: return QStringLiteral( "model" );
103  default: Q_ASSERT( false ); return QString();
104  }
105 }
The class is used as a container of context for various read/write operations on other objects...
static QString altClampingToString(Qgs3DTypes::AltitudeClamping altClamp)
Converts a value from AltitudeClamping enum to a string.
Definition: qgs3dutils.cpp:184
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.
static Qgs3DTypes::AltitudeClamping altClampingFromString(const QString &str)
Converts a string to a value from AltitudeClamping enum.
Definition: qgs3dutils.cpp:196
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.
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.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes symbol configuration to the given DOM element.
static QMatrix4x4 stringToMatrix4x4(const QString &str)
Convert a string to a 4x4 transform matrix.
Definition: qgs3dutils.cpp:336
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 matrix4x4toString(const QMatrix4x4 &m)
Converts a 4x4 transform matrix to a string.
Definition: qgs3dutils.cpp:326
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.