Marble

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

KDE's Doxygen guidelines are available online.