File indexing completed on 2024-05-12 03:50:17

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Torsten Rahn <rahn@kde.org>
0004 //
0005 
0006 
0007 // Own
0008 #include "GeoDataRegion.h"
0009 
0010 // Private
0011 #include "GeoDataRegion_p.h"
0012 
0013 // GeoData
0014 #include "GeoDataFeature.h"
0015 #include "GeoDataPlacemark.h"
0016 #include "GeoDataGeometry.h"
0017 #include "GeoDataTypes.h"
0018 
0019 // std
0020 #include <algorithm>
0021 
0022 
0023 namespace Marble
0024 {
0025 GeoDataRegion::GeoDataRegion()
0026     : GeoDataObject(),
0027       d( new GeoDataRegionPrivate )
0028 {
0029 }
0030 
0031 GeoDataRegion::GeoDataRegion( const GeoDataRegion& other )
0032     : GeoDataObject( other ),
0033       d( new GeoDataRegionPrivate( *other.d ) )
0034 {
0035 }
0036 
0037 GeoDataRegion::GeoDataRegion( GeoDataFeature * feature )
0038     : GeoDataObject(),
0039       d( new GeoDataRegionPrivate( feature ) )
0040 {
0041 }
0042 
0043 
0044 GeoDataRegion::~GeoDataRegion()
0045 {
0046     delete d;
0047 }
0048 
0049 
0050 const char* GeoDataRegion::nodeType() const
0051 {
0052     return GeoDataTypes::GeoDataRegionType;
0053 }
0054 
0055 bool GeoDataRegion::operator==(const GeoDataRegion& other) const
0056 {
0057     return equals(other)
0058            && this->latLonAltBox() == other.latLonAltBox()
0059            && this->lod() == other.lod();
0060 }
0061 
0062 bool GeoDataRegion::operator!=(const GeoDataRegion& other) const
0063 {
0064     return !this->operator==(other);
0065 }
0066 
0067 const GeoDataLatLonAltBox& GeoDataRegion::latLonAltBox() const
0068 {
0069     // FIXME: This isn't exactly what a 'const' function should do, is it?
0070 
0071     // If the latLonAltBox hasn't been set try to determine it automatically
0072     if ( !d->m_latLonAltBox ) {
0073         // If there is a parent try to 
0074         if ( d->m_parent ) {
0075 
0076             if (const GeoDataPlacemark *placemark = geodata_cast<GeoDataPlacemark>(d->m_parent)) {
0077                 const GeoDataGeometry * geometry = placemark->geometry();
0078                 if ( geometry ) {
0079                     d->m_latLonAltBox = new GeoDataLatLonAltBox( placemark->geometry()->latLonAltBox() );
0080                 }
0081                 else {
0082                     d->m_latLonAltBox = new GeoDataLatLonAltBox();
0083                 }
0084             }
0085             else {
0086                 // If the parent is not a placemark then create a default LatLonAltBox
0087                 // FIXME: reference a shared object instead
0088                 d->m_latLonAltBox = new GeoDataLatLonAltBox();
0089             }
0090         }
0091         else {
0092             // If there is no parent then create a default LatLonAltBox
0093             // FIXME: reference a shared object instead
0094             d->m_latLonAltBox = new GeoDataLatLonAltBox();
0095         }
0096     }
0097     
0098     return *(d->m_latLonAltBox);
0099 }
0100 
0101 
0102 void GeoDataRegion::setLatLonAltBox( const GeoDataLatLonAltBox & latLonAltBox )
0103 {
0104     delete d->m_latLonAltBox;
0105     d->m_latLonAltBox = new GeoDataLatLonAltBox( latLonAltBox );
0106 }
0107 
0108 
0109 GeoDataLod& GeoDataRegion::lod() const
0110 {
0111     // If the lod hasn't been set then return a shared one
0112     if ( !d->m_lod ) {
0113         // FIXME: reference a shared object instead
0114         d->m_lod = new GeoDataLod();
0115     }
0116 
0117     return *(d->m_lod);
0118 }
0119 
0120 
0121 void GeoDataRegion::setLod( const GeoDataLod & lod )
0122 {
0123     delete d->m_lod;
0124     d->m_lod = new GeoDataLod( lod );
0125 }
0126 
0127 
0128 void GeoDataRegion::pack( QDataStream& stream ) const
0129 {
0130     GeoDataObject::pack( stream );
0131 
0132     d->m_lod->pack( stream );
0133     d->m_latLonAltBox->pack( stream );
0134 }
0135 
0136 
0137 void GeoDataRegion::unpack( QDataStream& stream )
0138 {
0139     GeoDataObject::unpack( stream );
0140 
0141     d->m_lod->unpack( stream );
0142     d->m_latLonAltBox->unpack( stream );
0143 }
0144 
0145 GeoDataRegion &GeoDataRegion::operator=( const GeoDataRegion& other )
0146 {
0147     // Self assignment
0148     if ( this == &other ) return *this;
0149 
0150     GeoDataRegion temp( other );
0151     swap( temp );
0152     return *this;
0153 }
0154 
0155 void GeoDataRegion::swap( GeoDataRegion & other )
0156 {
0157     std::swap( d, other.d );
0158 }
0159 
0160 }
0161