diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 97ddc6565..5da214392 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -54,16 +54,10 @@ namespace BlackMisc CVariant CAircraftSituation::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - if (ITimestampBased::canHandleIndex(index)) - { - return ITimestampBased::propertyByIndex(index); - } - if (ICoordinateGeodetic::canHandleIndex(index)) - { - return ICoordinateGeodetic::propertyByIndex(index); - } + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + if (ICoordinateGeodetic::canHandleIndex(index)) { return ICoordinateGeodetic::propertyByIndex(index); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexPosition: @@ -82,6 +76,8 @@ namespace BlackMisc return this->m_bank.propertyByIndex(index.copyFrontRemoved()); case IndexGroundSpeed: return this->m_groundSpeed.propertyByIndex(index.copyFrontRemoved()); + case IndexGroundElevation: + return this->m_groundElevation.propertyByIndex(index.copyFrontRemoved()); case IndexCallsign: return this->m_correspondingCallsign.propertyByIndex(index.copyFrontRemoved()); default: @@ -98,7 +94,7 @@ namespace BlackMisc return; } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexPosition: @@ -113,6 +109,9 @@ namespace BlackMisc case IndexGroundSpeed: this->m_groundSpeed.setPropertyByIndex(index.copyFrontRemoved(), variant); break; + case IndexGroundElevation: + this->m_groundElevation.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; case IndexCallsign: this->m_correspondingCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break; @@ -124,15 +123,9 @@ namespace BlackMisc int CAircraftSituation::comparePropertyByIndex(const CPropertyIndex &index, const CAircraftSituation &compareValue) const { - if (ITimestampBased::canHandleIndex(index)) - { - return ITimestampBased::comparePropertyByIndex(index, compareValue); - } - if (ICoordinateGeodetic::canHandleIndex(index)) - { - return ICoordinateGeodetic::comparePropertyByIndex(index, compareValue); - } - ColumnIndex i = index.frontCasted(); + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(index, compareValue); } + if (ICoordinateGeodetic::canHandleIndex(index)) { return ICoordinateGeodetic::comparePropertyByIndex(index, compareValue); } + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexPosition: @@ -150,6 +143,9 @@ namespace BlackMisc case IndexGroundSpeed: return this->m_groundSpeed.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getGroundSpeed()); break; + case IndexGroundElevation: + return this->m_groundElevation.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getGroundElevation()); + break; case IndexCallsign: return this->m_correspondingCallsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); break; @@ -161,19 +157,26 @@ namespace BlackMisc return 0; } - bool CAircraftSituation::isOnGroundGuessed() const + bool CAircraftSituation::isOnGroundGuessed(const CLength &cgAboveGround) const { const CLength heightAboveGround(this->getHeightAboveGround()); if (!heightAboveGround.isNull()) { - return heightAboveGround.value(CLengthUnit::m()) < 1.0; + if (cgAboveGround.isNull()) + { + return heightAboveGround.value(CLengthUnit::m()) < 1.0; + } + else + { + return heightAboveGround <= cgAboveGround; + } } - // we guess on pitch an bank + // we guess on pitch and bank if (qAbs(this->getPitch().value(CAngleUnit::deg())) > 10) { return false; } if (qAbs(this->getBank().value(CAngleUnit::deg())) > 10) { return false; } - if (this->getGroundSpeed().value(CSpeedUnit::km_h()) > 75) { return false; } + if (this->getGroundSpeed().value(CSpeedUnit::km_h()) > 50) { return false; } // not sure, but this is a guess return true; @@ -188,22 +191,30 @@ namespace BlackMisc { if (this->getAltitude().getReferenceDatum() == CAltitude::AboveGround) { - // we have a sure value + // we have a sure value explicitly set return this->getAltitude(); } - const CLength gh(getGroundElevation()); + const CLength gh(this->getGroundElevation()); if (!gh.isNull() && !getAltitude().isNull()) { - return getAltitude() - gh; + return this->getAltitude() - gh; } return { 0, nullptr }; } + CAltitude CAircraftSituation::getCorrectedAltitude(const CLength &cgAboveGround) const + { + if (!this->hasGroundElevation()) { return this->getAltitude(); } + const CAltitude groundElevation(cgAboveGround.isNull() ? + this->getGroundElevation() : + CAltitude(this->getGroundElevation() + cgAboveGround, CAltitude::MeanSeaLevel)); + return (groundElevation <= this->getAltitude()) ? this->getAltitude() : groundElevation; + } + void CAircraftSituation::setCallsign(const CCallsign &callsign) { this->m_correspondingCallsign = callsign; this->m_correspondingCallsign.setTypeHint(CCallsign::Aircraft); } - } // namespace } // namespace diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index f27f28c36..52dc2b384 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -54,6 +54,7 @@ namespace BlackMisc IndexBank, IndexPitch, IndexGroundSpeed, + IndexGroundElevation, IndexCallsign }; @@ -99,7 +100,7 @@ namespace BlackMisc virtual BlackMisc::Geo::CLongitude longitude() const override { return this->m_position.longitude(); } //! Guess if aircraft is "on ground" - bool isOnGroundGuessed() const; + bool isOnGroundGuessed(const BlackMisc::PhysicalQuantities::CLength &cgAboveGround = { 0, nullptr }) const; //! \copydoc Geo::ICoordinateGeodetic::geodeticHeight const BlackMisc::Aviation::CAltitude &geodeticHeight() const override { return this->m_position.geodeticHeight(); } @@ -128,9 +129,12 @@ namespace BlackMisc //! Set heading void setHeading(const BlackMisc::Aviation::CHeading &heading) { this->m_heading = heading; } - //! Get altitude (true) + //! Get altitude const BlackMisc::Aviation::CAltitude &getAltitude() const { return this->m_position.geodeticHeight(); } + //! Get altitude under consideration of ground elevation and CG (if available) + BlackMisc::Aviation::CAltitude getCorrectedAltitude(const PhysicalQuantities::CLength &cgAboveGround = { 0, nullptr }) const; + //! Set altitude void setAltitude(const BlackMisc::Aviation::CAltitude &altitude) { this->m_position.setGeodeticHeight(altitude); } diff --git a/src/blackmisc/aviation/callsignobjectlist.h b/src/blackmisc/aviation/callsignobjectlist.h index 3e9e83cb9..aaf91e590 100644 --- a/src/blackmisc/aviation/callsignobjectlist.h +++ b/src/blackmisc/aviation/callsignobjectlist.h @@ -19,7 +19,6 @@ namespace BlackMisc { - namespace Aviation { class CAircraftSituation; diff --git a/src/blackmisc/geo/coordinategeodetic.cpp b/src/blackmisc/geo/coordinategeodetic.cpp index d95aae2ef..ddb8a5119 100644 --- a/src/blackmisc/geo/coordinategeodetic.cpp +++ b/src/blackmisc/geo/coordinategeodetic.cpp @@ -160,7 +160,7 @@ namespace BlackMisc void CCoordinateGeodetic::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - ICoordinateGeodetic::ColumnIndex i = index.frontCasted(); + const ICoordinateGeodetic::ColumnIndex i = index.frontCasted(); switch (i) { case IndexGeodeticHeight: @@ -190,7 +190,7 @@ namespace BlackMisc } } - CCoordinateGeodetic::CCoordinateGeodetic(CLatitude latitude, CLongitude longitude, CAltitude geodeticHeight) : + CCoordinateGeodetic::CCoordinateGeodetic(const CLatitude &latitude, const CLongitude &longitude, const CAltitude &geodeticHeight) : m_x(latitude.cos() * longitude.cos()), m_y(latitude.cos() * longitude.sin()), m_z(latitude.sin()), diff --git a/src/blackmisc/geo/coordinategeodetic.h b/src/blackmisc/geo/coordinategeodetic.h index 2c9ff42e6..253abeead 100644 --- a/src/blackmisc/geo/coordinategeodetic.h +++ b/src/blackmisc/geo/coordinategeodetic.h @@ -9,8 +9,8 @@ //! \file -#ifndef BLACKMISC_COORDINATEGEODETIC_H -#define BLACKMISC_COORDINATEGEODETIC_H +#ifndef BLACKMISC_GEO_COORDINATEGEODETIC_H +#define BLACKMISC_GEO_COORDINATEGEODETIC_H #include "blackmisc/blackmiscexport.h" #include "blackmisc/aviation/altitude.h" @@ -188,7 +188,7 @@ namespace BlackMisc CCoordinateGeodetic(const QVector3D &normal) : m_x(normal.x()), m_y(normal.y()), m_z(normal.z()) {} //! Constructor by values - CCoordinateGeodetic(CLatitude latitude, CLongitude longitude, BlackMisc::Aviation::CAltitude geodeticHeight); + CCoordinateGeodetic(const CLatitude &latitude, const CLongitude &longitude, const BlackMisc::Aviation::CAltitude &geodeticHeight); //! Constructor by double values, but no geodetic height CCoordinateGeodetic(double latitudeDegrees, double longitudeDegrees); diff --git a/src/blackmisc/simulation/aircraftmodel.cpp b/src/blackmisc/simulation/aircraftmodel.cpp index 2aa9b6b31..a55c16c2a 100644 --- a/src/blackmisc/simulation/aircraftmodel.cpp +++ b/src/blackmisc/simulation/aircraftmodel.cpp @@ -167,6 +167,11 @@ namespace BlackMisc } } + bool CAircraftModel::isVtol() const + { + return this->getAircraftIcaoCode().isVtol(); + } + CVariant CAircraftModel::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } diff --git a/src/blackmisc/simulation/aircraftmodel.h b/src/blackmisc/simulation/aircraftmodel.h index 1a5a3eb0c..54f1e82c1 100644 --- a/src/blackmisc/simulation/aircraftmodel.h +++ b/src/blackmisc/simulation/aircraftmodel.h @@ -175,6 +175,9 @@ namespace BlackMisc //! Aircraft ICAO code designator const QString &getAircraftIcaoCodeDesignator() const { return this->m_aircraftIcao.getDesignator(); } + //! VTOL aircraft? + bool isVtol() const; + //! Airline ICAO code const BlackMisc::Aviation::CAirlineIcaoCode &getAirlineIcaoCode() const { return this->m_livery.getAirlineIcaoCode(); } diff --git a/src/blackmisc/simulation/simulatedaircraft.cpp b/src/blackmisc/simulation/simulatedaircraft.cpp index 84df9f42c..08e39ace1 100644 --- a/src/blackmisc/simulation/simulatedaircraft.cpp +++ b/src/blackmisc/simulation/simulatedaircraft.cpp @@ -243,7 +243,7 @@ namespace BlackMisc bool CSimulatedAircraft::isVtol() const { - return getAircraftIcaoCode().isVtol(); + return getModel().isVtol(); } QString CSimulatedAircraft::getCombinedIcaoLiveryString(bool networkModel) const diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index 8ac8c0465..7dbfbe84a 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -203,19 +203,19 @@ namespace BlackMisc //! \copydoc BlackMisc::Geo::ICoordinateGeodetic::normalVectorDouble virtual std::array normalVectorDouble() const override { return this->m_situation.normalVectorDouble(); } - //! Elevation + //! \copydoc BlackMisc::Aviation::CAircraftSituation::getGroundElevation const BlackMisc::Aviation::CAltitude &getGroundElevation() const { return this->m_situation.getGroundElevation(); } - //! Elevation - void setGroundElevation(const BlackMisc::Aviation::CAltitude &elevation) { return this->m_situation.setGroundElevation(elevation); } + //! \copydoc BlackMisc::Aviation::CAircraftSituation::setGroundElevation + void setGroundElevation(const BlackMisc::Aviation::CAltitude &elevation) { this->m_situation.setGroundElevation(elevation); } - //! Get heading + //! \copydoc BlackMisc::Aviation::CAircraftSituation::getHeading const BlackMisc::Aviation::CHeading &getHeading() const { return this->m_situation.getHeading(); } - //! Get pitch + //! \copydoc BlackMisc::Aviation::CAircraftSituation::getPitch const BlackMisc::PhysicalQuantities::CAngle &getPitch() const { return this->m_situation.getPitch(); } - //! Get bank + //! \copydoc BlackMisc::Aviation::CAircraftSituation::getBank const BlackMisc::PhysicalQuantities::CAngle &getBank() const { return this->m_situation.getBank(); } //! Get COM1 system diff --git a/src/blackmisc/simulation/simulatedaircraftlist.cpp b/src/blackmisc/simulation/simulatedaircraftlist.cpp index a4edd6fb0..220e6b47e 100644 --- a/src/blackmisc/simulation/simulatedaircraftlist.cpp +++ b/src/blackmisc/simulation/simulatedaircraftlist.cpp @@ -96,7 +96,7 @@ namespace BlackMisc } } - int CSimulatedAircraftList::setRendered(const CCallsign &callsign, bool rendered) + int CSimulatedAircraftList::setRendered(const CCallsign &callsign, bool rendered, bool onlyFirst) { int c = 0; for (CSimulatedAircraft &aircraft : (*this)) @@ -104,11 +104,12 @@ namespace BlackMisc if (aircraft.getCallsign() != callsign) { continue; } aircraft.setRendered(rendered); c++; + if (onlyFirst) break; } return c; } - int CSimulatedAircraftList::setAircraftModel(const CCallsign &callsign, const CAircraftModel &model) + int CSimulatedAircraftList::setAircraftModel(const CCallsign &callsign, const CAircraftModel &model, bool onlyFirst) { int c = 0; for (CSimulatedAircraft &aircraft : (*this)) @@ -116,11 +117,12 @@ namespace BlackMisc if (aircraft.getCallsign() != callsign) { continue; } aircraft.setModel(model); c++; + if (onlyFirst) break; } return c; } - int CSimulatedAircraftList::setAircraftParts(const CCallsign &callsign, const CAircraftParts &parts) + int CSimulatedAircraftList::setAircraftParts(const CCallsign &callsign, const CAircraftParts &parts, bool onlyFirst) { int c = 0; for (CSimulatedAircraft &aircraft : (*this)) @@ -129,6 +131,20 @@ namespace BlackMisc aircraft.setParts(parts); aircraft.setPartsSynchronized(true); c++; + if (onlyFirst) break; + } + return c; + } + + int CSimulatedAircraftList::setGroundElevation(const CCallsign &callsign, const CAltitude &elevation, bool onlyFirst) + { + int c = 0; + for (CSimulatedAircraft &aircraft : (*this)) + { + if (aircraft.getCallsign() != callsign) { continue; } + aircraft.setGroundElevation(elevation); + c++; + if (onlyFirst) break; } return c; } diff --git a/src/blackmisc/simulation/simulatedaircraftlist.h b/src/blackmisc/simulation/simulatedaircraftlist.h index 09f287f0d..88d7eeab2 100644 --- a/src/blackmisc/simulation/simulatedaircraftlist.h +++ b/src/blackmisc/simulation/simulatedaircraftlist.h @@ -78,13 +78,16 @@ namespace BlackMisc void markAllAsNotRendered(); //! Mark given callsign as rendered - int setRendered(const BlackMisc::Aviation::CCallsign &callsign, bool rendered); + int setRendered(const BlackMisc::Aviation::CCallsign &callsign, bool rendered, bool onlyFirst = true); //! Set model - int setAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftModel &model); + int setAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftModel &model, bool onlyFirst = true); //! Set aircraft parts - int setAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts); + int setAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool onlyFirst = true); + + //! Set ground elevation + int setGroundElevation(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAltitude &elevation, bool onlyFirst = true); //! Enabled? bool isEnabled(const BlackMisc::Aviation::CCallsign &callsign) const;