diff --git a/src/lib/marble/geodata/CMakeLists.txt b/src/lib/marble/geodata/CMakeLists.txt --- a/src/lib/marble/geodata/CMakeLists.txt +++ b/src/lib/marble/geodata/CMakeLists.txt @@ -76,6 +76,7 @@ geodata/data/GeoDataDelete.cpp geodata/data/GeoDataSchemaData.cpp geodata/data/GeoDataSimpleData.cpp + geodata/data/GeoDataBuilding.cpp ) SET ( geodata_scene_SRCS diff --git a/src/lib/marble/geodata/data/GeoDataBuilding.h b/src/lib/marble/geodata/data/GeoDataBuilding.h new file mode 100644 --- /dev/null +++ b/src/lib/marble/geodata/data/GeoDataBuilding.h @@ -0,0 +1,116 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2017 Mohammed Nafees +// + +#ifndef MARBLE_GEODATABUILDING_H +#define MARBLE_GEODATABUILDING_H + +#include + +#include "GeoDataGeometry.h" + +#include "geodata_export.h" + +namespace Marble { +class GeoDataBuildingPrivate; + +/*! + \class GeoDataBuilding + \brief Contains important information about a building and its floors (levels) + + GeoDataBuilding holds information such as minimum floor, maximum floor, + floor data and their respective MultiGeometry and other possible metadata such + as the total height of the building, type etc. + */ + +class GEODATA_EXPORT GeoDataBuilding : public GeoDataGeometry +{ +public: + explicit GeoDataBuilding(); + explicit GeoDataBuilding(const GeoDataGeometry &other); + explicit GeoDataBuilding(const GeoDataBuilding &other); + + GeoDataBuilding& operator=(const GeoDataBuilding &other); + + const char *nodeType() const override; + + EnumGeometryId geometryId() const override; + + GeoDataGeometry *copy() const override; + + /*! + Destroys the GeoDataBuilding +*/ + ~GeoDataBuilding() override; + + +/*! + @return the height of the building +*/ + double height() const; + + +/*! + Sets the height of the building + @param height + */ + void setHeight(double height); + + +/*! + @return the minimum level + */ + int minLevel() const; + + +/*! + Sets the minimum level of the building + @param minLevel + */ + void setMinLevel(int minLevel); + + +/*! + @return the maximum level of the building + */ + int maxLevel() const; + + +/*! + Sets the maximum level of the building + @param maxLevel + */ + void setMaxLevel(int maxLevel); + + +/*! + @return the non existent levels in the building + */ + QVector nonExistentLevels() const; + + +/*! + Sets the non existent levels of the building + @param nonExistentLevels + */ + void setNonExistentLevels(const QVector& nonExistentLevels); + + +/*! + * @return the multigeometry associated with the building + */ + GeoDataMultiGeometry* multiGeometry() const; + +private: + GeoDataBuildingPrivate* const d; +}; + +} + +#endif diff --git a/src/lib/marble/geodata/data/GeoDataBuilding.cpp b/src/lib/marble/geodata/data/GeoDataBuilding.cpp new file mode 100644 --- /dev/null +++ b/src/lib/marble/geodata/data/GeoDataBuilding.cpp @@ -0,0 +1,107 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2017 Mohammed Nafees +// + +#include "GeoDataBuilding.h" +#include "GeoDataBuilding_p.h" +#include "GeoDataTypes.h" + +namespace Marble { + +GeoDataBuilding::GeoDataBuilding() + : GeoDataGeometry(new GeoDataBuildingPrivate), + d(new GeoDataBuildingPrivate) +{ +} + +GeoDataBuilding::GeoDataBuilding(const GeoDataGeometry &other) + : GeoDataGeometry(other), + d(new GeoDataBuildingPrivate) +{ +} + +GeoDataBuilding::GeoDataBuilding(const GeoDataBuilding &other) + : GeoDataGeometry(other), + d(new GeoDataBuildingPrivate(*other.d)) +{ +} + +GeoDataBuilding::~GeoDataBuilding() +{ + delete d; +} + +GeoDataBuilding& GeoDataBuilding::operator=(const GeoDataBuilding& other) +{ + GeoDataGeometry::operator=(other); + *d = *other.d; + return *this; +} + +const char *GeoDataBuilding::nodeType() const +{ + return GeoDataTypes::GeoDataBuildingType; +} + +EnumGeometryId GeoDataBuilding::geometryId() const +{ + return GeoDataBuildingId; +} + +GeoDataGeometry *GeoDataBuilding::copy() const +{ + return new GeoDataBuilding(*this); +} + +double GeoDataBuilding::height() const +{ + return d->m_height; +} + +void GeoDataBuilding::setHeight(double height) +{ + d->m_height = height; +} + +int GeoDataBuilding::minLevel() const +{ + return d->m_minLevel; +} + +void GeoDataBuilding::setMinLevel(int minLevel) +{ + d->m_minLevel = minLevel; +} + +int GeoDataBuilding::maxLevel() const +{ + return d->m_maxLevel; +} + +void GeoDataBuilding::setMaxLevel(int maxLevel) +{ + d->m_maxLevel = maxLevel; +} + +QVector GeoDataBuilding::nonExistentLevels() const +{ + return d->m_nonExistentLevels; +} + +void GeoDataBuilding::setNonExistentLevels(const QVector &nonExistentLevels) +{ + d->m_nonExistentLevels = nonExistentLevels; +} + +GeoDataMultiGeometry* GeoDataBuilding::multiGeometry() const +{ + return &d->m_multiGeometry; +} + +} diff --git a/src/lib/marble/geodata/data/GeoDataBuilding_p.h b/src/lib/marble/geodata/data/GeoDataBuilding_p.h new file mode 100644 --- /dev/null +++ b/src/lib/marble/geodata/data/GeoDataBuilding_p.h @@ -0,0 +1,45 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2017 Mohammed Nafees +// + +#ifndef MARBLE_GEODATABUILDING_P_H +#define MARBLE_GEODATABUILDING_P_H + +#include "GeoDataGeometry_p.h" +#include "GeoDataMultiGeometry.h" + +namespace Marble { + +class GeoDataBuildingPrivate : public GeoDataGeometryPrivate +{ +public: + GeoDataBuildingPrivate() + : m_height(0.0), + m_minLevel(0), + m_maxLevel(0) + { + } + + GeoDataGeometryPrivate *copy() const override + { + GeoDataBuildingPrivate* copy = new GeoDataBuildingPrivate; + *copy = *this; + return copy; + } + + double m_height; + int m_minLevel; + int m_maxLevel; + QVector m_nonExistentLevels; + GeoDataMultiGeometry m_multiGeometry; +}; + +} + +#endif diff --git a/src/lib/marble/geodata/data/Serializable.h b/src/lib/marble/geodata/data/Serializable.h --- a/src/lib/marble/geodata/data/Serializable.h +++ b/src/lib/marble/geodata/data/Serializable.h @@ -46,7 +46,8 @@ GeoDataMultiGeometryId, GeoDataMultiTrackId, GeoDataModelId, - GeoDataTrackId + GeoDataTrackId, + GeoDataBuildingId }; } diff --git a/src/lib/marble/geodata/parser/GeoDataTypes.h b/src/lib/marble/geodata/parser/GeoDataTypes.h --- a/src/lib/marble/geodata/parser/GeoDataTypes.h +++ b/src/lib/marble/geodata/parser/GeoDataTypes.h @@ -101,6 +101,7 @@ GEODATA_EXPORT extern const char GeoDataViewVolumeType[]; GEODATA_EXPORT extern const char GeoDataNetworkLinkControlType[]; GEODATA_EXPORT extern const char GeoDataUpdateType[]; +GEODATA_EXPORT extern const char GeoDataBuildingType[]; } } diff --git a/src/lib/marble/geodata/parser/GeoDataTypes.cpp b/src/lib/marble/geodata/parser/GeoDataTypes.cpp --- a/src/lib/marble/geodata/parser/GeoDataTypes.cpp +++ b/src/lib/marble/geodata/parser/GeoDataTypes.cpp @@ -92,6 +92,7 @@ const char GeoDataViewVolumeType[] = "GeoDataViewVolume"; const char GeoDataNetworkLinkControlType[] = "GeoDataNetworkLinkControl"; const char GeoDataUpdateType[] = "GeoDataUpdate"; +const char GeoDataBuildingType[] = "GeoDataBuilding"; } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -110,6 +110,7 @@ marble_add_test( TestFeatureDetach ) marble_add_test( TestGeometryDetach ) marble_add_test( TestTileProjection ) +marble_add_test( TestGeoDataBuilding ) qt_add_resources(TestGeoDataCopy_SRCS TestGeoDataCopy.qrc) # Check copy operations on CoW classes marble_add_test( TestGeoDataCopy ${TestGeoDataCopy_SRCS} ) diff --git a/tests/TestGeoDataBuilding.cpp b/tests/TestGeoDataBuilding.cpp new file mode 100644 --- /dev/null +++ b/tests/TestGeoDataBuilding.cpp @@ -0,0 +1,69 @@ +// +// This file is part of the Marble Virtual Globe. +// +// This program is free software licensed under the GNU LGPL. You can +// find a copy of this license in LICENSE.txt in the top directory of +// the source code. +// +// Copyright 2017 Mohammed Nafees +// + +#include +#include + +#include "GeoDataBuilding.h" +#include "GeoDataMultiGeometry.h" +#include "GeoDataLinearRing.h" + +namespace Marble { + +class TestGeoDataBuilding : public QObject { + Q_OBJECT + +private Q_SLOTS: + void defaultConstructor(); +}; + +void TestGeoDataBuilding::defaultConstructor() { + GeoDataBuilding building; + + QCOMPARE(building.height(), 0.0); + QCOMPARE(building.minLevel(), 0); + QCOMPARE(building.maxLevel(), 0); + + building.setHeight(24.5); + building.setMinLevel(-2); + building.setMaxLevel(10); + + QCOMPARE(building.height(), 24.5); + QCOMPARE(building.minLevel(), -2); + QCOMPARE(building.maxLevel(), 10); + + QVERIFY(building.nonExistentLevels().isEmpty()); + + QVector nonExistentLevels; + nonExistentLevels << 4 << 13; + building.setNonExistentLevels(nonExistentLevels); + + QVERIFY(!building.nonExistentLevels().isEmpty()); + + QVERIFY(building.multiGeometry()->size() == 0); + + building.multiGeometry()->append(new GeoDataLinearRing); + + QVERIFY(building.multiGeometry()->size() > 0); + + GeoDataBuilding building2(building); + + QCOMPARE(building2.height(), 24.5); + QCOMPARE(building2.minLevel(), -2); + QCOMPARE(building2.maxLevel(), 10); + QVERIFY(!building2.nonExistentLevels().isEmpty()); + QVERIFY(building2.multiGeometry()->size() > 0); +} + +} + +QTEST_MAIN(Marble::TestGeoDataBuilding) + +#include "TestGeoDataBuilding.moc"