From 2b51094b02e1e43eb3c9bcadc385688b8915d64e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 29 Oct 2018 02:43:31 +0100 Subject: [PATCH] Ref T412, Ref T227, lists/parts improvements * Ctor with timestamp * detect/improved state detection (e.g. "takeoff") * objects outside range --- src/blackmisc/aviation/aircraftparts.cpp | 7 +++ src/blackmisc/aviation/aircraftparts.h | 6 ++- .../aviation/aircraftsituationlist.cpp | 51 ++++++++++++++----- .../aviation/aircraftsituationlist.h | 12 +++-- src/blackmisc/geo/geoobjectlist.cpp | 10 ++++ src/blackmisc/geo/geoobjectlist.h | 3 ++ 6 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/blackmisc/aviation/aircraftparts.cpp b/src/blackmisc/aviation/aircraftparts.cpp index e24f4d5d8..37799cbbd 100644 --- a/src/blackmisc/aviation/aircraftparts.cpp +++ b/src/blackmisc/aviation/aircraftparts.cpp @@ -35,6 +35,13 @@ namespace BlackMisc m_spoilersOut(spoilersOut), m_isOnGround(onGround) {} + CAircraftParts::CAircraftParts(const CAircraftLights &lights, bool gearDown, int flapsPercent, bool spoilersOut, const CAircraftEngineList &engines, bool onGround, qint64 timestamp) + : m_lights(lights), m_engines(engines), m_flapsPercentage(flapsPercent), m_gearDown(gearDown), + m_spoilersOut(spoilersOut), m_isOnGround(onGround) + { + this->setMSecsSinceEpoch(timestamp); + } + QString CAircraftParts::convertToQString(bool i18n) const { return QStringLiteral("ts: ") % this->getFormattedTimestampAndOffset(true) % diff --git a/src/blackmisc/aviation/aircraftparts.h b/src/blackmisc/aviation/aircraftparts.h index 9b035ac6c..081fe2c53 100644 --- a/src/blackmisc/aviation/aircraftparts.h +++ b/src/blackmisc/aviation/aircraftparts.h @@ -68,13 +68,17 @@ namespace BlackMisc CAircraftParts(const CAircraftLights &lights, bool gearDown, int flapsPercent, bool spoilersOut, const CAircraftEngineList &engines, bool onGround); + //! Constructor + CAircraftParts(const CAircraftLights &lights, bool gearDown, int flapsPercent, bool spoilersOut, + const CAircraftEngineList &engines, bool onGround, qint64 timestamp); + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex CVariant propertyByIndex(const CPropertyIndex &index) const; //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); - //! Compare for index + //! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex int comparePropertyByIndex(const CPropertyIndex &index, const CAircraftParts &compareValue) const; //! Get aircraft lights diff --git a/src/blackmisc/aviation/aircraftsituationlist.cpp b/src/blackmisc/aviation/aircraftsituationlist.cpp index cb42aa5d7..c37a0c62d 100644 --- a/src/blackmisc/aviation/aircraftsituationlist.cpp +++ b/src/blackmisc/aviation/aircraftsituationlist.cpp @@ -278,35 +278,60 @@ namespace BlackMisc return true; } - bool CAircraftSituationList::isGndFlagChanging(bool alreadySortedLatestFirst) const + QPair CAircraftSituationList::isGndFlagStableChanging(bool alreadySortedLatestFirst) const { - if (this->size() < 2) { return false; } + if (this->size() < 2) { return QPair(false, CAircraftSituation::OnGroundSituationUnknown); } - const CAircraftSituationList sorted(this->getLatestAdjustedTwoObjects(alreadySortedLatestFirst)); - const CAircraftSituation s1 = sorted.front(); - const CAircraftSituation s2 = sorted.back(); - return (s1.getOnGround() == CAircraftSituation::OnGround && s2.getOnGround() == CAircraftSituation::NotOnGround) || - (s2.getOnGround() == CAircraftSituation::OnGround && s1.getOnGround() == CAircraftSituation::NotOnGround); + const CAircraftSituationList sorted(alreadySortedLatestFirst ? (*this) : this->getSortedAdjustedLatestFirst()); + const CAircraftSituation::IsOnGround f = sorted.front().getOnGround(); + const CAircraftSituation::IsOnGround t = sorted.back().getOnGround(); + QPair ret(false, f); // changing to front (latest) + if (f == t) { return ret; } + + bool changed = false; + + for (const CAircraftSituation &s : sorted) + { + if (!changed && s.getOnGround() == f) { continue; } // find 1st changing + if (!changed) { changed = true; continue; } // just changed + if (s.getOnGround() != t) { return ret; } // jitter, something like gnd, no gnd, gnd + } + ret.first = changed; + return ret; } bool CAircraftSituationList::isJustTakingOff(bool alreadySortedLatestFirst) const { if (this->size() < 2) { return false; } - const CAircraftSituationList sorted(this->getLatestAdjustedTwoObjects(alreadySortedLatestFirst)); + const CAircraftSituationList sorted(alreadySortedLatestFirst ? (*this) : this->getSortedAdjustedLatestFirst()); const CAircraftSituation latest = sorted.front(); - const CAircraftSituation oldest = sorted.back(); - return (latest.getOnGround() == CAircraftSituation::NotOnGround && oldest.getOnGround() == CAircraftSituation::OnGround); + if (latest.getOnGround() != CAircraftSituation::NotOnGround) { return false; } + const int c = this->countOnGround(CAircraftSituation::OnGround); + return this->size() - 1 == c; // all others on ground } bool CAircraftSituationList::isJustTouchingDown(bool alreadySortedLatestFirst) const { if (this->size() < 2) { return false; } - const CAircraftSituationList sorted(this->getLatestAdjustedTwoObjects(alreadySortedLatestFirst)); + const CAircraftSituationList sorted(alreadySortedLatestFirst ? (*this) : this->getSortedAdjustedLatestFirst()); const CAircraftSituation latest = sorted.front(); - const CAircraftSituation oldest = sorted.back(); - return (latest.getOnGround() == CAircraftSituation::OnGround && oldest.getOnGround() == CAircraftSituation::NotOnGround); + if (latest.getOnGround() != CAircraftSituation::OnGround) { return false; } + const int c = this->countOnGround(CAircraftSituation::NotOnGround); + return this->size() - 1 == c; // all others not on ground + } + + bool CAircraftSituationList::isTakingOff(bool alreadySortedLatestFirst) const + { + const QPair r = this->isGndFlagStableChanging(alreadySortedLatestFirst); + return r.first && r.second == CAircraftSituation::NotOnGround; + } + + bool CAircraftSituationList::isTouchingDown(bool alreadySortedLatestFirst) const + { + const QPair r = this->isGndFlagStableChanging(alreadySortedLatestFirst); + return r.first && r.second == CAircraftSituation::OnGround; } bool CAircraftSituationList::isRotatingUp(bool alreadySortedLatestFirst) const diff --git a/src/blackmisc/aviation/aircraftsituationlist.h b/src/blackmisc/aviation/aircraftsituationlist.h index c7d829f6c..1a5b86ae8 100644 --- a/src/blackmisc/aviation/aircraftsituationlist.h +++ b/src/blackmisc/aviation/aircraftsituationlist.h @@ -123,15 +123,21 @@ namespace BlackMisc //! Constantly decelarating? bool isConstDecelarating(bool alreadySortedLatestFirst = false) const; - //! Is the ground flag changing for the recent situations - bool isGndFlagChanging(bool alreadySortedLatestFirst = false) const; + //! Is the ground flag changing for the situations + QPair isGndFlagStableChanging(bool alreadySortedLatestFirst = false) const; //! Is just taking off? bool isJustTakingOff(bool alreadySortedLatestFirst = false) const; - //! Is just touch down? + //! Is just touching down? bool isJustTouchingDown(bool alreadySortedLatestFirst = false) const; + //! Is taking off? + bool isTakingOff(bool alreadySortedLatestFirst = false) const; + + //! Is touching down? + bool isTouchingDown(bool alreadySortedLatestFirst = false) const; + //! Is rotating up? bool isRotatingUp(bool alreadySortedLatestFirst = false) const; diff --git a/src/blackmisc/geo/geoobjectlist.cpp b/src/blackmisc/geo/geoobjectlist.cpp index c3662c800..0172e1fca 100644 --- a/src/blackmisc/geo/geoobjectlist.cpp +++ b/src/blackmisc/geo/geoobjectlist.cpp @@ -78,6 +78,16 @@ namespace BlackMisc }); } + template + bool IGeoObjectList::containsObjectOutsideRange(const ICoordinateGeodetic &coordinate, const CLength &range) const + { + return this->container().containsBy([&](const OBJ & geoObj) + { + const CLength d = coordinate.calculateGreatCircleDistance(geoObj); + return d > range; + }); + } + template bool IGeoObjectList::containsNullPosition() const { diff --git a/src/blackmisc/geo/geoobjectlist.h b/src/blackmisc/geo/geoobjectlist.h index 7d17a3d39..7e7033857 100644 --- a/src/blackmisc/geo/geoobjectlist.h +++ b/src/blackmisc/geo/geoobjectlist.h @@ -72,6 +72,9 @@ namespace BlackMisc //! Any object in range? bool containsObjectInRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const; + //! Any object in range? + bool containsObjectOutsideRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const; + //! Any NULL position? bool containsNullPosition() const;