Marble

GeoDataGeometry.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org>
4// SPDX-FileCopyrightText: 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
5// SPDX-FileCopyrightText: 2008 Inge Wallin <inge@lysator.liu.se>
6//
7
8#include "GeoDataGeometry.h"
9#include "GeoDataGeometry_p.h"
10
11#include "GeoDataLineString.h"
12#include "GeoDataLinearRing.h"
13#include "GeoDataModel.h"
14#include "GeoDataMultiGeometry.h"
15#include "GeoDataMultiTrack.h"
16#include "GeoDataPoint.h"
17#include "GeoDataPolygon.h"
18#include "GeoDataTrack.h"
19#include "GeoDataTypes.h"
20
21#include "MarbleDebug.h"
22
23#include <QDataStream>
24
25namespace Marble
26{
27
28GeoDataGeometry::GeoDataGeometry(const GeoDataGeometry &other)
29 : GeoDataObject()
30 , d_ptr(other.d_ptr)
31{
32 d_ptr->ref.ref();
33}
34
35GeoDataGeometry::GeoDataGeometry(GeoDataGeometryPrivate *priv)
36 : GeoDataObject()
37 , d_ptr(priv)
38{
39 d_ptr->ref.ref();
40}
41
42GeoDataGeometry::~GeoDataGeometry()
43{
44 if (!d_ptr->ref.deref())
45 delete d_ptr;
46}
47
48void GeoDataGeometry::detach()
49{
50 if (d_ptr->ref.fetchAndAddRelaxed(0) == 1) {
51 return;
52 }
53
54 GeoDataGeometryPrivate *new_d = d_ptr->copy();
55
56 if (!d_ptr->ref.deref())
57 delete d_ptr;
58
59 d_ptr = new_d;
60 d_ptr->ref.ref();
61}
62
63GeoDataGeometry &GeoDataGeometry::operator=(const GeoDataGeometry &other)
64{
65 GeoDataObject::operator=(other);
66
67 if (!d_ptr->ref.deref())
68 delete d_ptr;
69
70 d_ptr = other.d_ptr;
71 d_ptr->ref.ref();
72
73 return *this;
74}
75
76bool GeoDataGeometry::operator==(const GeoDataGeometry &other) const
77{
78 if (nodeType() != other.nodeType()) {
79 return false;
80 }
81
82 if (nodeType() == GeoDataTypes::GeoDataPolygonType) {
83 const auto &thisPoly = static_cast<const GeoDataPolygon &>(*this);
84 const auto &otherPoly = static_cast<const GeoDataPolygon &>(other);
85
86 return thisPoly == otherPoly;
87 } else if (nodeType() == GeoDataTypes::GeoDataLinearRingType) {
88 const auto &thisRing = static_cast<const GeoDataLinearRing &>(*this);
89 const auto &otherRing = static_cast<const GeoDataLinearRing &>(other);
90
91 return thisRing == otherRing;
92 } else if (nodeType() == GeoDataTypes::GeoDataLineStringType) {
93 const auto &thisLine = static_cast<const GeoDataLineString &>(*this);
94 const auto &otherLine = static_cast<const GeoDataLineString &>(other);
95
96 return thisLine == otherLine;
97 } else if (nodeType() == GeoDataTypes::GeoDataModelType) {
98 const auto &thisModel = static_cast<const GeoDataModel &>(*this);
99 const auto &otherModel = static_cast<const GeoDataModel &>(other);
100
101 return thisModel == otherModel;
102 } else if (nodeType() == GeoDataTypes::GeoDataMultiGeometryType) {
103 const auto &thisMG = static_cast<const GeoDataMultiGeometry &>(*this);
104 const auto &otherMG = static_cast<const GeoDataMultiGeometry &>(other);
105
106 return thisMG == otherMG;
107 } else if (nodeType() == GeoDataTypes::GeoDataTrackType) {
108 const auto &thisTrack = static_cast<const GeoDataTrack &>(*this);
109 const auto &otherTrack = static_cast<const GeoDataTrack &>(other);
110
111 return thisTrack == otherTrack;
112 } else if (nodeType() == GeoDataTypes::GeoDataMultiTrackType) {
113 const auto &thisMT = static_cast<const GeoDataMultiTrack &>(*this);
114 const auto &otherMT = static_cast<const GeoDataMultiTrack &>(other);
115
116 return thisMT == otherMT;
117 } else if (nodeType() == GeoDataTypes::GeoDataPointType) {
118 const auto &thisPoint = static_cast<const GeoDataPoint &>(*this);
119 const auto &otherPoint = static_cast<const GeoDataPoint &>(other);
120
121 return thisPoint == otherPoint;
122 }
123
124 return false;
125}
126
127bool GeoDataGeometry::extrude() const
128{
129 return d_ptr->m_extrude;
130}
131
132void GeoDataGeometry::setExtrude(bool extrude)
133{
134 detach();
135 d_ptr->m_extrude = extrude;
136}
137
138AltitudeMode GeoDataGeometry::altitudeMode() const
139{
140 return d_ptr->m_altitudeMode;
141}
142
143void GeoDataGeometry::setAltitudeMode(const AltitudeMode altitudeMode)
144{
145 detach();
146 d_ptr->m_altitudeMode = altitudeMode;
147}
148
149const GeoDataLatLonAltBox &GeoDataGeometry::latLonAltBox() const
150{
151 return d_ptr->m_latLonAltBox;
152}
153
154void GeoDataGeometry::pack(QDataStream &stream) const
155{
156 GeoDataObject::pack(stream);
157
158 stream << d_ptr->m_extrude;
159 stream << d_ptr->m_altitudeMode;
160}
161
162void GeoDataGeometry::unpack(QDataStream &stream)
163{
164 detach();
165 GeoDataObject::unpack(stream);
166
167 int am;
168 stream >> d_ptr->m_extrude;
169 stream >> am;
170 d_ptr->m_altitudeMode = (AltitudeMode)am;
171}
172
173bool GeoDataGeometry::equals(const GeoDataGeometry &other) const
174{
175 return GeoDataObject::equals(other) && d_ptr->m_extrude == other.d_ptr->m_extrude && d_ptr->m_altitudeMode == other.d_ptr->m_altitudeMode;
176}
177
178}
A base class for all geodata features.
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.