Marble

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

KDE's Doxygen guidelines are available online.