/
qgspoint3dsymbol.cpp
87 lines (71 loc) · 3.16 KB
/
qgspoint3dsymbol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "qgspoint3dsymbol.h"
#include "qgsreadwritecontext.h"
#include "qgsxmlutils.h"
QgsPoint3DSymbol::QgsPoint3DSymbol()
{
}
QgsAbstract3DSymbol *QgsPoint3DSymbol::clone() const
{
return new QgsPoint3DSymbol( *this );
}
void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
{
QDomDocument doc = elem.ownerDocument();
QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
mMaterial.writeXml( elemMaterial );
elem.appendChild( elemMaterial );
elem.setAttribute( QStringLiteral( "shape" ), shapeToString( mShape ) );
QVariantMap shapePropertiesCopy( mShapeProperties );
shapePropertiesCopy["model"] = QVariant( context.pathResolver().writePath( shapePropertiesCopy["model"].toString() ) );
QDomElement elemShapeProperties = doc.createElement( QStringLiteral( "shape-properties" ) );
elemShapeProperties.appendChild( QgsXmlUtils::writeVariant( shapePropertiesCopy, doc ) );
elem.appendChild( elemShapeProperties );
QDomElement elemTransform = doc.createElement( QStringLiteral( "transform" ) );
elemTransform.setAttribute( QStringLiteral( "matrix" ), Qgs3DUtils::matrix4x4toString( mTransform ) );
elem.appendChild( elemTransform );
}
void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
mMaterial.readXml( elemMaterial );
mShape = shapeFromString( elem.attribute( QStringLiteral( "shape" ) ) );
QDomElement elemShapeProperties = elem.firstChildElement( QStringLiteral( "shape-properties" ) );
mShapeProperties = QgsXmlUtils::readVariant( elemShapeProperties.firstChildElement() ).toMap();
mShapeProperties["model"] = QVariant( context.pathResolver().readPath( mShapeProperties["model"].toString() ) );
QDomElement elemTransform = elem.firstChildElement( QStringLiteral( "transform" ) );
mTransform = Qgs3DUtils::stringToMatrix4x4( elemTransform.attribute( QStringLiteral( "matrix" ) ) );
}
QgsPoint3DSymbol::Shape QgsPoint3DSymbol::shapeFromString( const QString &shape )
{
if ( shape == QStringLiteral( "sphere" ) )
return Sphere;
else if ( shape == QStringLiteral( "cone" ) )
return Cone;
else if ( shape == QStringLiteral( "cube" ) )
return Cube;
else if ( shape == QStringLiteral( "torus" ) )
return Torus;
else if ( shape == QStringLiteral( "plane" ) )
return Plane;
else if ( shape == QStringLiteral( "extruded-text" ) )
return ExtrudedText;
else if ( shape == QStringLiteral( "model" ) )
return Model;
else // "cylinder" (default)
return Cylinder;
}
QString QgsPoint3DSymbol::shapeToString( QgsPoint3DSymbol::Shape shape )
{
switch ( shape )
{
case Cylinder: return QStringLiteral( "cylinder" );
case Sphere: return QStringLiteral( "sphere" );
case Cone: return QStringLiteral( "cone" );
case Cube: return QStringLiteral( "cube" );
case Torus: return QStringLiteral( "torus" );
case Plane: return QStringLiteral( "plane" );
case ExtrudedText: return QStringLiteral( "extruded-text" );
case Model: return QStringLiteral( "model" );
default: Q_ASSERT( false ); return QString();
}
}