From b959972e0c1721b926513e0c20c43629f85a9b1e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 12 Jul 2016 03:01:50 +0200 Subject: [PATCH] refs #707, refactoring geo interfaces * added compare functions (also to ATC list) * renamed to relative position, e.g. station.setRelativeDistance * delegate set/get/compare to correct interface --- src/blackgui/models/airportlistmodel.cpp | 6 +- src/blackgui/models/atcstationlistmodel.cpp | 6 +- src/blackgui/models/atcstationlistmodel.h | 4 +- .../models/simulatedaircraftlistmodel.cpp | 8 +- src/blackmisc/aviation/airport.cpp | 33 +++-- src/blackmisc/aviation/airport.h | 10 +- src/blackmisc/aviation/atcstation.cpp | 86 ++++++++++--- src/blackmisc/aviation/atcstation.h | 9 +- src/blackmisc/comparefunctions.cpp | 4 + src/blackmisc/comparefunctions.h | 7 +- src/blackmisc/geo/coordinategeodetic.cpp | 118 ++++++++++++++++-- src/blackmisc/geo/coordinategeodetic.h | 65 ++++++---- src/blackmisc/geo/geoobjectlist.cpp | 17 +-- src/blackmisc/geo/geoobjectlist.h | 3 +- src/blackmisc/propertyindex.h | 4 +- .../simulation/airspaceaircraftsnapshot.cpp | 2 +- .../simulation/simulatedaircraft.cpp | 29 +++-- src/blackmisc/simulation/simulatedaircraft.h | 6 +- src/blackmisc/testing.cpp | 12 +- tests/blackmisc/testvariantandmap.cpp | 2 +- 20 files changed, 302 insertions(+), 129 deletions(-) diff --git a/src/blackgui/models/airportlistmodel.cpp b/src/blackgui/models/airportlistmodel.cpp index de21318d6..5efe73311 100644 --- a/src/blackgui/models/airportlistmodel.cpp +++ b/src/blackgui/models/airportlistmodel.cpp @@ -29,15 +29,15 @@ namespace BlackGui CListModelBase("AirportListModel", parent) { this->m_columns.addColumn(CColumn::standardValueObject("ICAO", CAirport::IndexIcao)); - this->m_columns.addColumn(CColumn("distance", CAirport::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter())); - this->m_columns.addColumn(CColumn("bearing", CAirport::IndexBearing, new CAngleDegreeFormatter())); + this->m_columns.addColumn(CColumn("distance", CAirport::IndexRelativeDistance, new CAirspaceDistanceFormatter())); + this->m_columns.addColumn(CColumn("bearing", CAirport::IndexRelativeBearing, new CAngleDegreeFormatter())); this->m_columns.addColumn(CColumn::standardString("name", CAirport::IndexDescriptiveName)); this->m_columns.addColumn(CColumn("elevation", CAirport::IndexElevation, new CPhysiqalQuantiyFormatter(CLengthUnit::ft(), 0))); this->m_columns.addColumn(CColumn("latitude", CAirport::IndexLatitude, new CLatLonFormatter())); this->m_columns.addColumn(CColumn("longitude", CAirport::IndexLatitude, new CLatLonFormatter())); // default sort order - this->setSortColumnByPropertyIndex(CAirport::IndexDistanceToOwnAircraft); + this->setSortColumnByPropertyIndex(CAirport::IndexRelativeDistance); this->m_sortOrder = Qt::AscendingOrder; // force strings for translation in resource files diff --git a/src/blackgui/models/atcstationlistmodel.cpp b/src/blackgui/models/atcstationlistmodel.cpp index 06d92de8e..fb5aeaa09 100644 --- a/src/blackgui/models/atcstationlistmodel.cpp +++ b/src/blackgui/models/atcstationlistmodel.cpp @@ -70,7 +70,7 @@ namespace BlackGui CColumn col = CColumn("type", CAtcStation::IndexIcon); col.setSortPropertyIndex({ CAtcStation::IndexCallsign, CCallsign::IndexSuffix }); this->m_columns.addColumn(col); - this->m_columns.addColumn(CColumn("distance", CAtcStation::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter())); + this->m_columns.addColumn(CColumn("distance", CAtcStation::IndexRelativeDistance, new CAirspaceDistanceFormatter())); this->m_columns.addColumn(CColumn("r.", "in range", CAtcStation::IndexIsInRange, new CBoolIconFormatter("in range", "outside range"))); this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, new CComFrequencyFormatter())); this->m_columns.addColumn(CColumn::standardString("controllername", { CAtcStation::IndexController, CUser::IndexRealName })); @@ -79,7 +79,7 @@ namespace BlackGui this->m_columns.addColumn(CColumn::standardString("voiceroomurl", { CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl })); // default sort order - this->setSortColumnByPropertyIndex(CAtcStation::IndexDistanceToOwnAircraft); + this->setSortColumnByPropertyIndex(CAtcStation::IndexRelativeDistance); this->m_sortOrder = Qt::AscendingOrder; } break; @@ -132,7 +132,7 @@ namespace BlackGui new QStandardItem(station.getCallsign().toQString()), new QStandardItem(station.getFrequency().valueRoundedWithUnit(CFrequencyUnit::MHz(), 2, true)), new QStandardItem(station.getControllerRealName()), - new QStandardItem(station.getDistanceToOwnAircraft().valueRoundedWithUnit(CLengthUnit::NM(), 1, true)) + new QStandardItem(station.getRelativeDistance().valueRoundedWithUnit(CLengthUnit::NM(), 1, true)) }; break; case StationsBooked: diff --git a/src/blackgui/models/atcstationlistmodel.h b/src/blackgui/models/atcstationlistmodel.h index abad7c31c..e756d8e15 100644 --- a/src/blackgui/models/atcstationlistmodel.h +++ b/src/blackgui/models/atcstationlistmodel.h @@ -26,7 +26,7 @@ namespace BlackGui namespace Models { //! ATC list model - class BLACKGUI_EXPORT CAtcStationListModel : public CListModelBase + class BLACKGUI_EXPORT CAtcStationListModel : public CListModelBase { public: //! What kind of stations @@ -60,5 +60,5 @@ namespace BlackGui AtcStationMode m_stationMode = NotSet; }; } -} +} // ns #endif // guard diff --git a/src/blackgui/models/simulatedaircraftlistmodel.cpp b/src/blackgui/models/simulatedaircraftlistmodel.cpp index 908ac5ec1..5102a4cad 100644 --- a/src/blackgui/models/simulatedaircraftlistmodel.cpp +++ b/src/blackgui/models/simulatedaircraftlistmodel.cpp @@ -61,7 +61,7 @@ namespace BlackGui case InfoMode: this->m_columns.addColumn(CColumn::standardValueObject("cs.", "callsign", CSimulatedAircraft::IndexCallsign, CCallsign::IndexCallsignString)); this->m_columns.addColumn(CColumn::standardString("realname", "pilot's real name", { CSimulatedAircraft::IndexPilot, CUser::IndexRealName })); - this->m_columns.addColumn(CColumn("dist.", "distance", CSimulatedAircraft::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter())); + this->m_columns.addColumn(CColumn("dist.", "distance", CSimulatedAircraft::IndexRelativeDistance, new CAirspaceDistanceFormatter())); this->m_columns.addColumn(CColumn("altitude", { CSimulatedAircraft::IndexSituation, CAircraftSituation::IndexAltitude }, new CAltitudeFormatter())); this->m_columns.addColumn(CColumn("gs.", { CSimulatedAircraft::IndexSituation, CAircraftSituation::IndexGroundspeed }, new CAircraftSpeedFormatter())); this->m_columns.addColumn(CColumn::standardString("icao", "icao and livery info",{ CSimulatedAircraft::IndexCombinedIcaoLiveryString})); @@ -71,7 +71,7 @@ namespace BlackGui this->m_columns.addColumn(CColumn("longitude", { CSimulatedAircraft::IndexSituation, CAircraftSituation::IndexLongitude }, new CLatLonFormatter())); // default sort order - this->setSortColumnByPropertyIndex(CSimulatedAircraft::IndexDistanceToOwnAircraft); + this->setSortColumnByPropertyIndex(CSimulatedAircraft::IndexRelativeDistance); this->m_sortOrder = Qt::AscendingOrder; break; @@ -79,7 +79,7 @@ namespace BlackGui this->m_columns.addColumn(CColumn("e.", "enabled", CSimulatedAircraft::IndexEnabled, new CBoolIconFormatter("enabled", "disabled"), true)); this->m_columns.addColumn(CColumn("r.", "rendered", CSimulatedAircraft::IndexRendered, new CBoolIconFormatter("rendered", "skipped"), true)); this->m_columns.addColumn(CColumn::standardValueObject("cs.", "callsign", { CSimulatedAircraft::IndexCallsign, CCallsign::IndexCallsignString })); - this->m_columns.addColumn(CColumn("dist.", "distance", CSimulatedAircraft::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter())); + this->m_columns.addColumn(CColumn("dist.", "distance", CSimulatedAircraft::IndexRelativeDistance, new CAirspaceDistanceFormatter())); this->m_columns.addColumn(CColumn("altitude", { CSimulatedAircraft::IndexSituation, CAircraftSituation::IndexAltitude }, new CAltitudeFormatter())); this->m_columns.addColumn(CColumn("gs.", { CSimulatedAircraft::IndexSituation, CAircraftSituation::IndexGroundspeed }, new CAircraftSpeedFormatter())); this->m_columns.addColumn(CColumn("p.", "parts", CSimulatedAircraft::IndexPartsSynchronized, new CBoolIconFormatter("parts", "no parts"), true)); @@ -91,7 +91,7 @@ namespace BlackGui this->m_columns.addColumn(CColumn::standardString("type", { CSimulatedAircraft::IndexModel, CAircraftModel::IndexModelTypeAsString})); // default sort order - this->setSortColumnByPropertyIndex(CSimulatedAircraft::IndexDistanceToOwnAircraft); + this->setSortColumnByPropertyIndex(CSimulatedAircraft::IndexRelativeDistance); this->m_sortOrder = Qt::AscendingOrder; break; diff --git a/src/blackmisc/aviation/airport.cpp b/src/blackmisc/aviation/airport.cpp index e6b7ab15e..128359828 100644 --- a/src/blackmisc/aviation/airport.cpp +++ b/src/blackmisc/aviation/airport.cpp @@ -66,13 +66,9 @@ namespace BlackMisc return this->m_position.propertyByIndex(index.copyFrontRemoved()); case IndexElevation: return this->getElevation().propertyByIndex(index.copyFrontRemoved()); - case IndexBearing: - return this->m_bearingToOwnAircraft.propertyByIndex(index.copyFrontRemoved()); - case IndexDistanceToOwnAircraft: - return this->m_distanceToOwnAircraft.propertyByIndex(index.copyFrontRemoved()); default: - return (ICoordinateGeodetic::canHandleIndex(index)) ? - ICoordinateGeodetic::propertyByIndex(index) : + return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? + ICoordinateWithRelativePosition::propertyByIndex(index) : CValueObject::propertyByIndex(index); } } @@ -92,14 +88,15 @@ namespace BlackMisc case IndexPosition: this->m_position.setPropertyByIndex(index.copyFrontRemoved(), variant); break; - case IndexBearing: - this->m_bearingToOwnAircraft.setPropertyByIndex(index.copyFrontRemoved(), variant); - break; - case IndexDistanceToOwnAircraft: - this->m_distanceToOwnAircraft.setPropertyByIndex(index.copyFrontRemoved(), variant); - break; default: - CValueObject::setPropertyByIndex(index, variant); + if (ICoordinateWithRelativePosition::canHandleIndex(index)) + { + ICoordinateWithRelativePosition::setPropertyByIndex(index, variant); + } + else + { + CValueObject::setPropertyByIndex(index, variant); + } break; } } @@ -114,17 +111,15 @@ namespace BlackMisc return this->m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao()); case IndexDescriptiveName: return this->m_descriptiveName.compare(compareValue.getDescriptiveName(), Qt::CaseInsensitive); - case IndexBearing: - return this->m_bearingToOwnAircraft.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getBearingToOwnAircraft()); - case IndexPosition: - case IndexDistanceToOwnAircraft: - return this->m_distanceToOwnAircraft.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getDistanceToOwnAircraft()); default: + if (ICoordinateWithRelativePosition::canHandleIndex(index)) + { + return ICoordinateWithRelativePosition::comparePropertyByIndex(index, compareValue); + } break; } Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed"); return 0; } - } // namespace } // namespace diff --git a/src/blackmisc/aviation/airport.h b/src/blackmisc/aviation/airport.h index afe18d798..43d8b2ddb 100644 --- a/src/blackmisc/aviation/airport.h +++ b/src/blackmisc/aviation/airport.h @@ -42,9 +42,7 @@ namespace BlackMisc IndexIcao = BlackMisc::CPropertyIndex::GlobalIndexCAirport, IndexDescriptiveName, IndexPosition, - IndexElevation, - IndexDistanceToOwnAircraft, - IndexBearing + IndexElevation }; //! Default constructor. @@ -119,7 +117,7 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); - //! Compare for index + //! Compare by index int comparePropertyByIndex(const CPropertyIndex &index, const CAirport &compareValue) const; //! \copydoc BlackMisc::Mixin::String::toQString @@ -135,8 +133,8 @@ namespace BlackMisc BLACK_METAMEMBER(icao), BLACK_METAMEMBER(descriptiveName), BLACK_METAMEMBER(position), - BLACK_METAMEMBER(distanceToOwnAircraft), - BLACK_METAMEMBER(bearingToOwnAircraft) + BLACK_METAMEMBER(relativeDistance), + BLACK_METAMEMBER(relativeBearing) ); }; } // namespace diff --git a/src/blackmisc/aviation/atcstation.cpp b/src/blackmisc/aviation/atcstation.cpp index b5eb9566a..77e3a6449 100644 --- a/src/blackmisc/aviation/atcstation.cpp +++ b/src/blackmisc/aviation/atcstation.cpp @@ -16,10 +16,12 @@ #include "blackmisc/pq/units.h" #include "blackmisc/propertyindex.h" #include "blackmisc/variant.h" +#include "blackmisc/comparefunctions.h" #include #include +using namespace BlackMisc; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; using namespace BlackMisc::Network; @@ -133,12 +135,12 @@ namespace BlackMisc s.append(this->m_range.toQString(i18n)); // distance to plane - if (this->m_distanceToOwnAircraft.isPositiveWithEpsilonConsidered()) + if (this->m_relativeDistance.isPositiveWithEpsilonConsidered()) { s.append(' '); i18n ? s.append(QCoreApplication::translate("Aviation", "distance")) : s.append("distance"); s.append(' '); - s.append(this->m_distanceToOwnAircraft.toQString(i18n)); + s.append(this->m_relativeDistance.toQString(i18n)); } // from / to @@ -260,22 +262,22 @@ namespace BlackMisc // both ways this->syncronizeControllerData(bookedStation); - if (this->hasValidDistance()) + if (this->hasValidRelativeDistance()) { - bookedStation.setDistanceToOwnAircraft(this->getDistanceToOwnAircraft()); - bookedStation.setBearingToOwnAircraft(this->getBearingToOwnAircraft()); + bookedStation.setRelativeDistance(this->getRelativeDistance()); + bookedStation.setRelativeBearing(this->getRelativeBearing()); } - else if (bookedStation.hasValidDistance()) + else if (bookedStation.hasValidRelativeDistance()) { - this->setDistanceToOwnAircraft(bookedStation.getDistanceToOwnAircraft()); - this->setBearingToOwnAircraft(bookedStation.getBearingToOwnAircraft()); + this->setRelativeDistance(bookedStation.getRelativeDistance()); + this->setRelativeBearing(bookedStation.getRelativeBearing()); } } bool CAtcStation::isInRange() const { - if (m_range.isNull() || !hasValidDistance()) { return false; } - return (this->getDistanceToOwnAircraft() <= m_range); + if (m_range.isNull() || !hasValidRelativeDistance()) { return false; } + return (this->getRelativeDistance() <= m_range); } bool CAtcStation::hasValidBookingTimes() const @@ -373,8 +375,6 @@ namespace BlackMisc return CVariant::from(this->m_isOnline); case IndexLatitude: return this->latitude().propertyByIndex(index.copyFrontRemoved()); - case IndexDistanceToOwnAircraft: - return this->m_distanceToOwnAircraft.propertyByIndex(index.copyFrontRemoved()); case IndexLongitude: return this->longitude().propertyByIndex(index.copyFrontRemoved()); case IndexPosition: @@ -390,8 +390,9 @@ namespace BlackMisc case IndexVoiceRoom: return this->m_voiceRoom.propertyByIndex(index.copyFrontRemoved()); default: - if (ICoordinateGeodetic::canHandleIndex(index)) { return ICoordinateGeodetic::propertyByIndex(index); } - return CValueObject::propertyByIndex(index); + return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? + ICoordinateWithRelativePosition::propertyByIndex(index) : + CValueObject::propertyByIndex(index); } } @@ -425,9 +426,6 @@ namespace BlackMisc case IndexRange: this->m_range.setPropertyByIndex(index.copyFrontRemoved(), variant); break; - case IndexDistanceToOwnAircraft: - this->m_distanceToOwnAircraft.setPropertyByIndex(index.copyFrontRemoved(), variant); - break; case IndexAtis: this->m_atis.setPropertyByIndex(index.copyFrontRemoved(), variant); break; @@ -438,9 +436,61 @@ namespace BlackMisc this->m_voiceRoom.setPropertyByIndex(index.copyFrontRemoved(), variant); break; default: - CValueObject::setPropertyByIndex(index, variant); + if (ICoordinateWithRelativePosition::canHandleIndex(index)) + { + ICoordinateWithRelativePosition::setPropertyByIndex(index, variant); + } + else + { + CValueObject::setPropertyByIndex(index, variant); + } break; } } + + int CAtcStation::comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const + { + if (index.isMyself()) { return this->getCallsign().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexBookedFrom: + return Compare::compare(this->getBookedFromUtc(), compareValue.getBookedFromUtc()); + case IndexBookedUntil: + return Compare::compare(this->getBookedUntilUtc(), compareValue.getBookedUntilUtc()); + case IndexCallsign: + return this->m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); + case IndexController: + return this->m_controller.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getController()); + case IndexFrequency: + return this->m_frequency.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getFrequency()); + case IndexIsOnline: + return Compare::compare(this->isOnline(), compareValue.isOnline()); + case IndexLatitude: + return this->latitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.latitude()); + case IndexLongitude: + return this->longitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.longitude()); + case IndexPosition: + return this->m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); + case IndexRange: + return this->m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange()); + case IndexIsInRange: + return Compare::compare(this->isInRange(), compareValue.isInRange()); + case IndexAtis: + return this->m_atis.getMessage().compare(compareValue.getAtis().getMessage()); + case IndexMetar: + return this->m_metar.getMessage().compare(compareValue.getMetar().getMessage()); + case IndexVoiceRoom: + return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl()); + default: + if (ICoordinateWithRelativePosition::canHandleIndex(index)) + { + return ICoordinateWithRelativePosition::comparePropertyByIndex(index, compareValue); + } + break; + } + Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed"); + return 0; + } } // namespace } // namespace diff --git a/src/blackmisc/aviation/atcstation.h b/src/blackmisc/aviation/atcstation.h index 442a92aab..b1b489c09 100644 --- a/src/blackmisc/aviation/atcstation.h +++ b/src/blackmisc/aviation/atcstation.h @@ -54,7 +54,6 @@ namespace BlackMisc IndexPosition, IndexRange, IndexIsInRange, - IndexDistanceToOwnAircraft, IndexIsOnline, IndexBookedFrom, IndexBookedUntil, @@ -148,7 +147,6 @@ namespace BlackMisc //! Updates two stations (normally a booked and online ATC station) with complementary data void syncronizeControllerData(CAtcStation &otherStation); - //! Syncronize station data //! Updates the two stations (a booked and online ATC station) with complementary data //! \pre this object is the online station, the passed station the booked station @@ -253,6 +251,9 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); + //! Compare by index + int comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const; + //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; @@ -282,8 +283,8 @@ namespace BlackMisc BLACK_METAMEMBER(bookedUntilUtc), BLACK_METAMEMBER(metar), BLACK_METAMEMBER(voiceRoom), - BLACK_METAMEMBER(distanceToOwnAircraft), - BLACK_METAMEMBER(bearingToOwnAircraft) + BLACK_METAMEMBER(relativeDistance), + BLACK_METAMEMBER(relativeBearing) ); }; } // namespace diff --git a/src/blackmisc/comparefunctions.cpp b/src/blackmisc/comparefunctions.cpp index 6ee020468..7e5e81179 100644 --- a/src/blackmisc/comparefunctions.cpp +++ b/src/blackmisc/comparefunctions.cpp @@ -38,5 +38,9 @@ namespace BlackMisc return a < b ? -10 : 10; } + int compare(const QDateTime &a, const QDateTime &b) + { + return Compare::compare(a.toMSecsSinceEpoch(), b.toMSecsSinceEpoch()); + } } // ns } // ns diff --git a/src/blackmisc/comparefunctions.h b/src/blackmisc/comparefunctions.h index e81ac85b8..5450334ce 100644 --- a/src/blackmisc/comparefunctions.h +++ b/src/blackmisc/comparefunctions.h @@ -13,7 +13,7 @@ #define BLACKMISC_COMPAREFUNCTIONS_H #include "blackmisc/blackmiscexport.h" - +#include #include namespace BlackMisc @@ -29,8 +29,11 @@ namespace BlackMisc //! Compare qint64 BLACKMISC_EXPORT int compare(qint64 a, qint64 b); - //! Compare qint64 + //! Compare double BLACKMISC_EXPORT int compare(double a, double b); + + //! Compare double + BLACKMISC_EXPORT int compare(const QDateTime &a, const QDateTime &b); } // ns } // ns diff --git a/src/blackmisc/geo/coordinategeodetic.cpp b/src/blackmisc/geo/coordinategeodetic.cpp index bd6624642..81df4a7c0 100644 --- a/src/blackmisc/geo/coordinategeodetic.cpp +++ b/src/blackmisc/geo/coordinategeodetic.cpp @@ -24,7 +24,6 @@ namespace BlackMisc { namespace Geo { - QString CCoordinateGeodetic::convertToQString(bool i18n) const { QString s = "Geodetic: {%1, %2, %3}"; @@ -74,7 +73,7 @@ namespace BlackMisc return Geo::calculateGreatCircleDistance((*this), otherCoordinate); } - CAngle ICoordinateGeodetic::bearing(const ICoordinateGeodetic &otherCoordinate) const + CAngle ICoordinateGeodetic::calculateBearing(const ICoordinateGeodetic &otherCoordinate) const { return Geo::calculateBearing((*this), otherCoordinate); } @@ -112,10 +111,39 @@ namespace BlackMisc } const QString m = QString("no property, index ").append(index.toQString()); - Q_ASSERT_X(false, "ICoordinateGeodetic", m.toLocal8Bit().constData()); + Q_ASSERT_X(false, Q_FUNC_INFO, m.toLocal8Bit().constData()); return CVariant::fromValue(m); } + int ICoordinateGeodetic::comparePropertyByIndex(const CPropertyIndex &index, const ICoordinateGeodetic &compareValue) const + { + if (!index.isMyself()) + { + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexLatitude: + return this->latitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.latitude()); + case IndexLongitude: + return this->longitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.longitude()); + case IndexLatitudeAsString: + return this->latitudeAsString().compare(compareValue.latitudeAsString()); + case IndexLongitudeAsString: + return this->longitudeAsString().compare(compareValue.longitudeAsString()); + case IndexGeodeticHeight: + return this->geodeticHeight().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.geodeticHeight()); + case IndexGeodeticHeightAsString: + return this->geodeticHeightAsString().compare(compareValue.geodeticHeightAsString()); + default: + break; + } + } + + const QString m = QString("no property, index ").append(index.toQString()); + Q_ASSERT_X(false, Q_FUNC_INFO, m.toLocal8Bit().constData()); + return 0; + } + CVariant CCoordinateGeodetic::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } @@ -217,23 +245,89 @@ namespace BlackMisc return *this; } - CLength ICoordinateWithRelativePosition::calculcateDistanceToOwnAircraft(const ICoordinateGeodetic &position, bool updateValues) + CLength ICoordinateWithRelativePosition::calculcateAndUpdateRelativeDistance(const ICoordinateGeodetic &position) { - if (!updateValues) { return Geo::calculateGreatCircleDistance(*this, position); } - this->m_distanceToOwnAircraft = Geo::calculateGreatCircleDistance(*this, position); - return this->m_distanceToOwnAircraft; + this->m_relativeDistance = Geo::calculateGreatCircleDistance(*this, position); + return this->m_relativeDistance; } - CLength ICoordinateWithRelativePosition::calculcateDistanceAndBearingToOwnAircraft(const ICoordinateGeodetic &position, bool updateValues) + CLength ICoordinateWithRelativePosition::calculcateAndUpdateRelativeDistanceAndBearing(const ICoordinateGeodetic &position) { - if (!updateValues) { return Geo::calculateGreatCircleDistance(*this, position); } - this->m_distanceToOwnAircraft = Geo::calculateGreatCircleDistance(*this, position); - this->m_bearingToOwnAircraft = Geo::calculateBearing(*this, position); - return this->m_distanceToOwnAircraft; + this->m_relativeDistance = Geo::calculateGreatCircleDistance(*this, position); + this->m_relativeBearing = Geo::calculateBearing(*this, position); + return this->m_relativeDistance; + } + + CVariant ICoordinateWithRelativePosition::propertyByIndex(const CPropertyIndex &index) const + { + if (ICoordinateGeodetic::canHandleIndex(index)) { return ICoordinateGeodetic::propertyByIndex(index); } + if (!index.isMyself()) + { + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexRelativeBearing: + return this->getRelativeBearing().propertyByIndex(index.copyFrontRemoved()); + case IndexRelativeDistance: + return this->getRelativeDistance().propertyByIndex(index.copyFrontRemoved()); + default: + break; + } + } + const QString m = QString("no property, index ").append(index.toQString()); + Q_ASSERT_X(false, "ICoordinateWithRelativePosition", m.toLocal8Bit().constData()); + return CVariant::fromValue(m); + } + + void ICoordinateWithRelativePosition::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (!index.isMyself()) + { + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexRelativeBearing: + this->m_relativeBearing.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; + case IndexRelativeDistance: + this->m_relativeDistance.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; + default: + const QString m = QString("no property, index ").append(index.toQString()); + Q_ASSERT_X(false, "ICoordinateWithRelativePosition", m.toLocal8Bit().constData()); + break; + } + } + } + + int ICoordinateWithRelativePosition::comparePropertyByIndex(const CPropertyIndex &index, const ICoordinateWithRelativePosition &compareValue) const + { + if (ICoordinateGeodetic::canHandleIndex(index)) { return ICoordinateGeodetic::comparePropertyByIndex(index, compareValue); } + if (!index.isMyself()) + { + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexRelativeBearing: + return this->m_relativeBearing.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRelativeBearing()); + case IndexRelativeDistance: + return this->m_relativeDistance.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRelativeDistance()); + default: + const QString m = QString("no property, index ").append(index.toQString()); + Q_ASSERT_X(false, Q_FUNC_INFO, m.toLocal8Bit().constData()); + break; + } + } + return 0; } ICoordinateWithRelativePosition::ICoordinateWithRelativePosition() { } + bool ICoordinateWithRelativePosition::canHandleIndex(const CPropertyIndex &index) + { + int i = index.frontCasted(); + return (i >= static_cast(IndexRelativeDistance)) && (i <= static_cast(IndexRelativeBearing)); + } } // namespace } // namespace diff --git a/src/blackmisc/geo/coordinategeodetic.h b/src/blackmisc/geo/coordinategeodetic.h index bdba1cd1e..dade2a58b 100644 --- a/src/blackmisc/geo/coordinategeodetic.h +++ b/src/blackmisc/geo/coordinategeodetic.h @@ -32,7 +32,6 @@ namespace BlackMisc { namespace Geo { - //! Geodetic coordinate //! \sa http://www.esri.com/news/arcuser/0703/geoid1of3.html //! \sa http://http://www.gmat.unsw.edu.au/snap/gps/clynch_pdfs/coordcvt.pdf (page 5) @@ -76,9 +75,6 @@ namespace BlackMisc //! Normal vector with double precision virtual std::array normalVectorDouble() const = 0; - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; - //! Latitude as string QString latitudeAsString() const { return this->latitude().toQString(true); } @@ -92,7 +88,13 @@ namespace BlackMisc BlackMisc::PhysicalQuantities::CLength calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const; //! Initial bearing - BlackMisc::PhysicalQuantities::CAngle bearing(const ICoordinateGeodetic &otherCoordinate) const; + BlackMisc::PhysicalQuantities::CAngle calculateBearing(const ICoordinateGeodetic &otherCoordinate) const; + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! Compare by index + int comparePropertyByIndex(const CPropertyIndex &index, const ICoordinateGeodetic &compareValue) const; protected: //! Can given index be handled? @@ -111,48 +113,64 @@ namespace BlackMisc //! Euclidean distance squared between normal vectors, use for more efficient sorting by distance BLACKMISC_EXPORT double calculateEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate1, const ICoordinateGeodetic &coordinate2); - //! Interface (actually more an abstract class) of coordinate and - //! relative position to own aircraft + //! Interface (actually more an abstract class) of coordinates and relative position to something (normally own aircraft) class BLACKMISC_EXPORT ICoordinateWithRelativePosition : public ICoordinateGeodetic { public: - //! Get the distance to own plane - const BlackMisc::PhysicalQuantities::CLength &getDistanceToOwnAircraft() const { return m_distanceToOwnAircraft; } + //! Properties by index + enum ColumnIndex + { + IndexRelativeDistance = BlackMisc::CPropertyIndex::GlobalIndexICoordinateWithRelativePosition, + IndexRelativeBearing + }; - //! Set distance to own plane - void setDistanceToOwnAircraft(const BlackMisc::PhysicalQuantities::CLength &distance) { this->m_distanceToOwnAircraft = distance; } + //! Get the distance + const BlackMisc::PhysicalQuantities::CLength &getRelativeDistance() const { return m_relativeDistance; } - //! Get the bearing to own plane - const BlackMisc::PhysicalQuantities::CAngle &getBearingToOwnAircraft() const { return m_bearingToOwnAircraft; } + //! Set relative distance + void setRelativeDistance(const BlackMisc::PhysicalQuantities::CLength &distance) { this->m_relativeDistance = distance; } + + //! Get the relative bearing + const BlackMisc::PhysicalQuantities::CAngle &getRelativeBearing() const { return m_relativeBearing; } //! Set bearing to own plane - void setBearingToOwnAircraft(const BlackMisc::PhysicalQuantities::CAngle &angle) { this->m_bearingToOwnAircraft = angle; } + void setRelativeBearing(const BlackMisc::PhysicalQuantities::CAngle &angle) { this->m_relativeBearing = angle; } //! Valid distance? - bool hasValidDistance() const { return !this->m_distanceToOwnAircraft.isNull();} + bool hasValidRelativeDistance() const { return !this->m_relativeDistance.isNull();} //! Valid bearing? - bool hasValidBearing() const { return !this->m_bearingToOwnAircraft.isNull();} + bool hasValidRelativeBearing() const { return !this->m_relativeBearing.isNull();} //! Calculcate distance, set it, and return distance - BlackMisc::PhysicalQuantities::CLength calculcateDistanceToOwnAircraft(const BlackMisc::Geo::ICoordinateGeodetic &position, bool updateValues = true); + BlackMisc::PhysicalQuantities::CLength calculcateAndUpdateRelativeDistance(const BlackMisc::Geo::ICoordinateGeodetic &position); //! Calculcate distance and bearing to plane, set it, and return distance - BlackMisc::PhysicalQuantities::CLength calculcateDistanceAndBearingToOwnAircraft(const BlackMisc::Geo::ICoordinateGeodetic &position, bool updateValues = true); + BlackMisc::PhysicalQuantities::CLength calculcateAndUpdateRelativeDistanceAndBearing(const BlackMisc::Geo::ICoordinateGeodetic &position); + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); + + //! Compare by index + int comparePropertyByIndex(const CPropertyIndex &index, const ICoordinateWithRelativePosition &compareValue) const; protected: //! Constructor ICoordinateWithRelativePosition(); - BlackMisc::PhysicalQuantities::CAngle m_bearingToOwnAircraft {0.0, BlackMisc::PhysicalQuantities::CAngleUnit::nullUnit()}; //!< temporary stored value - BlackMisc::PhysicalQuantities::CLength m_distanceToOwnAircraft {0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< temporary stored value - }; + //! Can given index be handled? + static bool canHandleIndex(const BlackMisc::CPropertyIndex &index); + BlackMisc::PhysicalQuantities::CAngle m_relativeBearing {0.0, BlackMisc::PhysicalQuantities::CAngleUnit::nullUnit()}; //!< temporary stored value + BlackMisc::PhysicalQuantities::CLength m_relativeDistance {0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< temporary stored value + }; //! Geodetic coordinate class BLACKMISC_EXPORT CCoordinateGeodetic : public CValueObject, public ICoordinateGeodetic { - public: //! Default constructor CCoordinateGeodetic() : @@ -166,7 +184,7 @@ namespace BlackMisc //! Constructor by values CCoordinateGeodetic(double latitudeDegrees, double longitudeDegrees, double heightMeters) : - CCoordinateGeodetic({ latitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg() }, { longitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg() }, { heightMeters, BlackMisc::PhysicalQuantities::CLengthUnit::m() }) {} + CCoordinateGeodetic( { latitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg() }, { longitudeDegrees, BlackMisc::PhysicalQuantities::CAngleUnit::deg() }, { heightMeters, BlackMisc::PhysicalQuantities::CLengthUnit::m() }) {} //! \copydoc ICoordinateGeodetic::latitude virtual CLatitude latitude() const override; @@ -230,7 +248,6 @@ namespace BlackMisc BLACK_METAMEMBER(geodeticHeight) ); }; - } // namespace } // namespace diff --git a/src/blackmisc/geo/geoobjectlist.cpp b/src/blackmisc/geo/geoobjectlist.cpp index c8751a0c4..2628d4dcd 100644 --- a/src/blackmisc/geo/geoobjectlist.cpp +++ b/src/blackmisc/geo/geoobjectlist.cpp @@ -63,11 +63,11 @@ namespace BlackMisc } template - void IGeoObjectWithRelativePositionList::calculcateDistanceAndBearingToPosition(const ICoordinateGeodetic &position) + void IGeoObjectWithRelativePositionList::calculcateAndUpdateRelativeDistanceAndBearing(const ICoordinateGeodetic &position) { for (OBJ &geoObj : this->container()) { - geoObj.calculcateDistanceAndBearingToOwnAircraft(position); + geoObj.calculcateAndUpdateRelativeDistanceAndBearing(position); } } @@ -76,7 +76,9 @@ namespace BlackMisc { this->container().removeIf([ & ](OBJ & geoObj) { - return geoObj.calculcateDistanceAndBearingToOwnAircraft(position, updateValues) > maxDistance; + return updateValues ? + geoObj.calculcateAndUpdateRelativeDistanceAndBearing(position) > maxDistance : + geoObj.calculateGreatCircleDistance(position) > maxDistance; }); } @@ -85,21 +87,21 @@ namespace BlackMisc { if (updateValues) { - this->calculcateDistanceAndBearingToPosition(position); + this->calculcateAndUpdateRelativeDistanceAndBearing(position); } - this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getDistanceToOwnAircraft() < b.getDistanceToOwnAircraft(); }); + this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getRelativeDistance() < b.getRelativeDistance(); }); } template void IGeoObjectWithRelativePositionList::sortByDistanceToOwnAircraft() { - this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getDistanceToOwnAircraft() < b.getDistanceToOwnAircraft(); }); + this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getRelativeDistance() < b.getRelativeDistance(); }); } template void IGeoObjectWithRelativePositionList::partiallySortByDistanceToOwnAircraft(int number) { - this->container().partiallySort(number, [ & ](const OBJ & a, const OBJ & b) { return a.getDistanceToOwnAircraft() < b.getDistanceToOwnAircraft(); }); + this->container().partiallySort(number, [ & ](const OBJ & a, const OBJ & b) { return a.getRelativeDistance() < b.getRelativeDistance(); }); } template @@ -126,4 +128,3 @@ namespace BlackMisc } // namespace } // namespace - diff --git a/src/blackmisc/geo/geoobjectlist.h b/src/blackmisc/geo/geoobjectlist.h index 117f06725..645c8ec10 100644 --- a/src/blackmisc/geo/geoobjectlist.h +++ b/src/blackmisc/geo/geoobjectlist.h @@ -50,7 +50,6 @@ namespace BlackMisc //! Find 0..n objects within range of given coordinate //! \param coordinate other position //! \param range within range of other position - //! \return CONTAINER findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const; //! Find 0..n objects closest to the given coordinate. @@ -95,7 +94,7 @@ namespace BlackMisc void removeIfOutsideRange(const BlackMisc::Geo::ICoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &maxDistance, bool updateValues); //! Calculate distances - void calculcateDistanceAndBearingToPosition(const BlackMisc::Geo::ICoordinateGeodetic &position); + void calculcateAndUpdateRelativeDistanceAndBearing(const BlackMisc::Geo::ICoordinateGeodetic &position); protected: //! Constructor diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 776912aaa..414d74102 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -107,8 +107,10 @@ namespace BlackMisc GlobalIndexCVisibilityLayer = 4600, GlobalIndexCWeatherScenario = 4700, GlobalIndexICoordinateGeodetic = 5000, - GlobalIndexCCoordinateGeodetic = 5100, + GlobalIndexICoordinateWithRelativePosition = 5100, + GlobalIndexCCoordinateGeodetic = 5200, GlobalIndexCClient = 6000, + GlobalIndexClientCapabilities = 6050, //!< used with map key GlobalIndexCUser = 6100, GlobalIndexCAuthenticatedUser = 6200, GlobalIndexCRole = 6300, diff --git a/src/blackmisc/simulation/airspaceaircraftsnapshot.cpp b/src/blackmisc/simulation/airspaceaircraftsnapshot.cpp index a7538cb9e..5275e4238 100644 --- a/src/blackmisc/simulation/airspaceaircraftsnapshot.cpp +++ b/src/blackmisc/simulation/airspaceaircraftsnapshot.cpp @@ -72,7 +72,7 @@ namespace BlackMisc CCallsign cs(currentAircraft.getCallsign()); if (currentAircraft.isEnabled()) { - CLength distance(currentAircraft.getDistanceToOwnAircraft()); + CLength distance(currentAircraft.getRelativeDistance()); if (count >= maxAircraft || (!maxRenderedDistance.isNull() && distance >= maxRenderedBoundary) || (!maxRenderedBoundary.isNull() && distance >= maxRenderedBoundary)) diff --git a/src/blackmisc/simulation/simulatedaircraft.cpp b/src/blackmisc/simulation/simulatedaircraft.cpp index 59a7ac959..17adf4a83 100644 --- a/src/blackmisc/simulation/simulatedaircraft.cpp +++ b/src/blackmisc/simulation/simulatedaircraft.cpp @@ -288,8 +288,8 @@ namespace BlackMisc return this->m_callsign.propertyByIndex(index.copyFrontRemoved()); case IndexPilot: return this->m_pilot.propertyByIndex(index.copyFrontRemoved()); - case IndexDistanceToOwnAircraft: - return this->m_distanceToOwnAircraft.propertyByIndex(index.copyFrontRemoved()); + case IndexRelativeDistance: + return this->m_relativeDistance.propertyByIndex(index.copyFrontRemoved()); case IndexCom1System: return this->m_com1system.propertyByIndex(index.copyFrontRemoved()); case IndexCom2System: @@ -309,8 +309,8 @@ namespace BlackMisc case IndexCombinedIcaoLiveryString: return CVariant::fromValue(this->getCombinedIcaoLiveryString()); default: - return (ICoordinateGeodetic::canHandleIndex(index)) ? - ICoordinateGeodetic::propertyByIndex(index) : + return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? + ICoordinateWithRelativePosition::propertyByIndex(index) : CValueObject::propertyByIndex(index); } } @@ -327,8 +327,8 @@ namespace BlackMisc case IndexPilot: this->m_pilot.setPropertyByIndex(index.copyFrontRemoved(), variant); break; - case IndexDistanceToOwnAircraft: - this->m_distanceToOwnAircraft.setPropertyByIndex(index.copyFrontRemoved(), variant); + case IndexRelativeDistance: + this->m_relativeDistance.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexCom1System: this->m_com1system.setPropertyByIndex(index.copyFrontRemoved(), variant); @@ -365,7 +365,14 @@ namespace BlackMisc Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported"); break; default: - CValueObject::setPropertyByIndex(index, variant); + if (ICoordinateWithRelativePosition::canHandleIndex(index)) + { + ICoordinateWithRelativePosition::setPropertyByIndex(index, variant); + } + else + { + CValueObject::setPropertyByIndex(index, variant); + } break; } } @@ -381,8 +388,8 @@ namespace BlackMisc case IndexPilot: return this->m_pilot.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPilot()); case IndexSituation: - case IndexDistanceToOwnAircraft: - return this->m_distanceToOwnAircraft.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getDistanceToOwnAircraft()); + case IndexRelativeDistance: + return this->m_relativeDistance.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRelativeDistance()); case IndexCom1System: return m_com1system.getFrequencyActive().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCom1System().getFrequencyActive()); case IndexCom2System: @@ -404,6 +411,10 @@ namespace BlackMisc case IndexFastPositionUpdates: return Compare::compare(this->m_fastPositionUpdates, compareValue.fastPositionUpdates()); default: + if (ICoordinateWithRelativePosition::canHandleIndex(index)) + { + return ICoordinateWithRelativePosition::comparePropertyByIndex(index, compareValue); + } break; } Q_ASSERT_X(false, Q_FUNC_INFO, "Comapre failed"); diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index f8c01ce3f..a29697f0f 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -69,7 +69,7 @@ namespace BlackMisc { IndexCallsign = BlackMisc::CPropertyIndex::GlobalIndexCSimulatedAircraft, IndexPilot, - IndexDistanceToOwnAircraft, + IndexRelativeDistance, IndexCom1System, IndexCom2System, IndexTransponder, @@ -411,8 +411,8 @@ namespace BlackMisc BLACK_METAMEMBER(com2system), BLACK_METAMEMBER(transponder), BLACK_METAMEMBER(parts), - BLACK_METAMEMBER(distanceToOwnAircraft), - BLACK_METAMEMBER(bearingToOwnAircraft), + BLACK_METAMEMBER(relativeDistance), + BLACK_METAMEMBER(relativeBearing), BLACK_METAMEMBER(model), BLACK_METAMEMBER(enabled), BLACK_METAMEMBER(rendered), diff --git a/src/blackmisc/testing.cpp b/src/blackmisc/testing.cpp index e698e0dec..1e162b5c5 100644 --- a/src/blackmisc/testing.cpp +++ b/src/blackmisc/testing.cpp @@ -35,7 +35,6 @@ namespace BlackMisc { namespace Aviation { - CAtcStationList CTesting::createAtcStations(int number, bool byPropertyIndex) { CAtcStationList atcs; @@ -71,14 +70,14 @@ namespace BlackMisc station.setPropertyByIndex(CAtcStation::IndexIsOnline, CVariant::from(false)); station.setPropertyByIndex(CAtcStation::IndexBookedFrom, CVariant::from(dtFrom)); station.setPropertyByIndex(CAtcStation::IndexBookedUntil, CVariant::from(dtUntil)); - station.setPropertyByIndex(CAtcStation::IndexDistanceToOwnAircraft, CVariant::from(CLength(index + 1, CLengthUnit::NM()))); + station.setPropertyByIndex(CAtcStation::IndexRelativeDistance, CVariant::from(CLength(index + 1, CLengthUnit::NM()))); } else { station = CAtcStation(CCallsign(cs), user, CFrequency(f, CFrequencyUnit::MHz()), geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil); - station.setDistanceToOwnAircraft(CLength(index + 1, CLengthUnit::NM())); + station.setRelativeDistance(CLength(index + 1, CLengthUnit::NM())); } station.setVoiceRoomUrl("vvl://foo.bar.baz/room" + QString::number(index)); @@ -102,7 +101,7 @@ namespace BlackMisc r.append(station.propertyByIndex({ CAtcStation::IndexController, CUser::IndexRealName}).toQString()); r.append(station.propertyByIndex({ CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLatitudeAsString}).toQString()); r.append(station.propertyByIndex({ CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLongitudeAsString}).toQString()); - r.append(station.propertyByIndex({ CAtcStation::IndexDistanceToOwnAircraft, CLength::IndexValueRounded2DigitsWithUnit}).toQString()); + r.append(station.propertyByIndex({ CAtcStation::IndexRelativeDistance, CLength::IndexValueRounded2DigitsWithUnit}).toQString()); r.append(station.propertyByIndex({ CAtcStation::IndexBookedFrom}).toDateTime().toString("YYYY-mm-dd hh:mm")); r.append(station.propertyByIndex({ CAtcStation::IndexBookedUntil}).toDateTime().toString("YYYY-mm-dd hh:mm")); } @@ -112,7 +111,7 @@ namespace BlackMisc r.append(station.getController().getRealName()); r.append(station.getPosition().latitudeAsString()); r.append(station.getPosition().longitudeAsString()); - r.append(station.getDistanceToOwnAircraft().toQString(true)); + r.append(station.getRelativeDistance().toQString(true)); r.append(station.getBookedFromUtc().toString("YYYY-mm-dd hh:mm")); r.append(station.getBookedUntilUtc().toString("YYYY-mm-dd hh:mm")); } @@ -138,7 +137,7 @@ namespace BlackMisc for (int i = 0; i < n; i++) { int p = i % s; - atc.calculcateDistanceToOwnAircraft(pos.at(p)); + atc.calculcateAndUpdateRelativeDistance(pos.at(p)); } } @@ -172,6 +171,5 @@ namespace BlackMisc c = CCoordinateGeodetic::fromWgs84(wgsLatLng.at(idx), wgsLatLng.at(idx + 1), h); } } - } // namespace } // namespace diff --git a/tests/blackmisc/testvariantandmap.cpp b/tests/blackmisc/testvariantandmap.cpp index 0d409d6bc..ab4433104 100644 --- a/tests/blackmisc/testvariantandmap.cpp +++ b/tests/blackmisc/testvariantandmap.cpp @@ -75,7 +75,7 @@ namespace BlackMiscTest QVERIFY2(station1 == station1, "Station should be equal"); QVERIFY(station1.getController() == station2.getController()); - QVERIFY(station1.getDistanceToOwnAircraft() == station2.getDistanceToOwnAircraft()); + QVERIFY(station1.getRelativeDistance() == station2.getRelativeDistance()); QVERIFY2(station1 == station2, "Station should be equal"); QVERIFY2(station1 != station3, "Station should not be equal");