• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • kde-4.x
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • data
GeoDataGeometry.cpp
Go to the documentation of this file.
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 
169 void GeoDataGeometry::unpack( QDataStream& stream )
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 }
Marble::GeoDataTypes::GeoDataPolygonType
const char GeoDataPolygonType[]
Definition: GeoDataTypes.cpp:66
Marble::GeoDataPoint
A Geometry object representing a 3d point.
Definition: GeoDataPoint.h:47
Marble::GeoDataObject::unpack
void unpack(QDataStream &steam) override
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:125
Marble::GeoDataTypes::GeoDataLineStringType
const char GeoDataLineStringType[]
Definition: GeoDataTypes.cpp:50
Marble::GeoDataMultiTrack
Definition: GeoDataMultiTrack.h:27
Marble::GeoDataTypes::GeoDataMultiGeometryType
const char GeoDataMultiGeometryType[]
Definition: GeoDataTypes.cpp:57
Marble::GeoDataTrack
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:55
Marble::GeoDataGeometryPrivate::m_extrude
bool m_extrude
Definition: GeoDataGeometry_p.h:55
Marble::GeoDataGeometry::~GeoDataGeometry
~GeoDataGeometry() override
Definition: GeoDataGeometry.cpp:49
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:67
Marble::GeoDataGeometryPrivate::ref
QAtomicInt ref
Definition: GeoDataGeometry_p.h:59
Marble::GeoDataTypes::GeoDataModelType
const char GeoDataModelType[]
Definition: GeoDataTypes.cpp:56
GeoDataPolygon.h
QDataStream
Marble::GeoDataGeometry::setExtrude
void setExtrude(bool extrude)
Definition: GeoDataGeometry.cpp:139
Marble::GeoDataObject
A base class for all geodata objects.
Definition: GeoDataObject.h:48
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:43
Marble::GeoDataObject::equals
virtual bool equals(const GeoDataObject &other) const
Compares the value of id and targetId of the two objects.
Definition: GeoDataObject.cpp:131
QAtomicInt::ref
bool ref()
GeoDataModel.h
Marble::GeoDataGeometry::detach
void detach()
Definition: GeoDataGeometry.cpp:55
Marble::GeoDataGeometry::pack
void pack(QDataStream &stream) const override
Serialize the contents of the feature to stream.
Definition: GeoDataGeometry.cpp:161
GeoDataGeometry_p.h
Marble::GeoDataModel
Definition: GeoDataModel.h:31
MarbleDebug.h
GeoDataTrack.h
Marble::GeoDataGeometryPrivate
Definition: GeoDataGeometry_p.h:23
Marble::GeoDataTypes::GeoDataLinearRingType
const char GeoDataLinearRingType[]
Definition: GeoDataTypes.cpp:49
Marble::GeoDataGeometry::extrude
bool extrude() const
Definition: GeoDataGeometry.cpp:134
Marble::GeoDataGeometry::operator==
bool operator==(const GeoDataGeometry &other) const
Definition: GeoDataGeometry.cpp:83
Marble::GeoNode::nodeType
virtual const char * nodeType() const =0
Provides type information for downcasting a GeoNode.
GeoDataMultiGeometry.h
Marble::GeoDataGeometry::altitudeMode
AltitudeMode altitudeMode() const
Definition: GeoDataGeometry.cpp:145
Marble::AltitudeMode
AltitudeMode
Definition: MarbleGlobal.h:135
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::GeoDataGeometryPrivate::m_altitudeMode
AltitudeMode m_altitudeMode
Definition: GeoDataGeometry_p.h:56
Marble::GeoDataGeometryPrivate::copy
virtual GeoDataGeometryPrivate * copy() const =0
GeoDataLineString.h
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:72
QAtomicInt::deref
bool deref()
GeoDataMultiTrack.h
GeoDataLinearRing.h
Marble::GeoDataGeometry::operator=
GeoDataGeometry & operator=(const GeoDataGeometry &other)
Definition: GeoDataGeometry.cpp:70
Marble::GeoDataGeometry::d_ptr
GeoDataGeometryPrivate * d_ptr
Definition: GeoDataGeometry.h:80
Marble::GeoDataObject::pack
void pack(QDataStream &stream) const override
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:119
Marble::GeoDataTypes::GeoDataMultiTrackType
const char GeoDataMultiTrackType[]
Definition: GeoDataTypes.cpp:58
Marble::GeoDataTypes::GeoDataTrackType
const char GeoDataTrackType[]
Definition: GeoDataTypes.cpp:85
GeoDataPoint.h
Marble::GeoDataTypes::GeoDataPointType
const char GeoDataPointType[]
Definition: GeoDataTypes.cpp:65
Marble::GeoDataObject::operator=
GeoDataObject & operator=(const GeoDataObject &)
Definition: GeoDataObject.cpp:54
Marble::GeoDataMultiGeometry
A class that can contain other GeoDataGeometry objects.
Definition: GeoDataMultiGeometry.h:33
Marble::GeoDataGeometry::setAltitudeMode
void setAltitudeMode(const AltitudeMode altitudeMode)
Definition: GeoDataGeometry.cpp:150
Marble::GeoDataGeometryPrivate::m_latLonAltBox
GeoDataLatLonAltBox m_latLonAltBox
Definition: GeoDataGeometry_p.h:57
GeoDataGeometry.h
Marble::GeoDataGeometry::GeoDataGeometry
GeoDataGeometry(GeoDataGeometryPrivate *priv)
Definition: GeoDataGeometry.cpp:42
Marble::GeoDataGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataGeometry.cpp:156
GeoDataTypes.h
Marble::GeoDataGeometry::equals
bool equals(const GeoDataGeometry &other) const
Definition: GeoDataGeometry.cpp:180
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:47
Marble::GeoDataGeometry::unpack
void unpack(QDataStream &stream) override
Unserialize the contents of the feature from stream.
Definition: GeoDataGeometry.cpp:169
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Sat Dec 7 2019 02:40:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  •   KmPlot
  • libkeduvocdocument
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   src
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal