diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index a57c00d94..631411706 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -31,7 +31,6 @@ #include "blackcore/simulator.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/identifier.h" -#include "blackmisc/interpolationrenderingsetup.h" #include "blackmisc/pixmap.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/time.h" @@ -39,6 +38,7 @@ #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorplugininfolist.h" #include "blackmisc/simulation/simulatorinternals.h" +#include "blackmisc/simulation/interpolationrenderingsetup.h" #include "blackmisc/weather/weathergrid.h" #include @@ -165,10 +165,10 @@ namespace BlackCore virtual bool isTimeSynchronized() const = 0; //! Set interpolation and rendering - virtual BlackMisc::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const = 0; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const = 0; //! Set interpolation and rendering - virtual void setInterpolationAndRenderingSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup) = 0; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) = 0; //! Time synchronization offset virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index e7afb6f58..cf7d514e4 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -141,14 +141,14 @@ namespace BlackCore } //! \copydoc ISimulator::getInterpolationAndRenderingSetup - virtual BlackMisc::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override { logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CInterpolationAndRenderingSetup(); + return BlackMisc::Simulation::CInterpolationAndRenderingSetup(); } //! \copydoc ISimulator::setInterpolationAndRenderingSetup - virtual void setInterpolationAndRenderingSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup) override + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) override { Q_UNUSED(setup); logEmptyContextWarning(Q_FUNC_INFO); diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 952143d8c..f66a16c34 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -91,8 +91,8 @@ namespace BlackCore virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; virtual bool isTimeSynchronized() const override; - virtual BlackMisc::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; - virtual void setInterpolationAndRenderingSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup) override; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) override; virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 737803821..965595f02 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -68,8 +68,8 @@ namespace BlackCore virtual BlackMisc::Simulation::CSimulatorInternals getSimulatorInternals() const override; virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; virtual bool isTimeSynchronized() const override; - virtual BlackMisc::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; - virtual void setInterpolationAndRenderingSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup) override; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) override; virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index b0bea56b2..3be6aa204 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -18,12 +18,12 @@ #include "blackmisc/identifiable.h" #include "blackmisc/identifier.h" #include "blackmisc/pixmap.h" -#include "blackmisc/interpolationrenderingsetup.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/time.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatorplugininfo.h" +#include "blackmisc/simulation/interpolationrenderingsetup.h" #include "blackmisc/statusmessage.h" #include @@ -125,10 +125,10 @@ namespace BlackCore virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; //! Debugging messages etc. - virtual BlackMisc::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const = 0; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const = 0; //! Enable debugging messages etc. - virtual void setInterpolationAndRenderingSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup) = 0; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) = 0; //! Is the aircraft rendered (displayed in simulator)? //! This shall only return true if the aircraft is really visible in the simulator diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index a63e1447b..7a477685f 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -13,9 +13,9 @@ #include "blackcore/webdataservices.h" #include "blackmisc/aviation/aircraftsituation.h" #include "blackmisc/aviation/callsign.h" -#include "blackmisc/interpolator.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/airspaceaircraftsnapshot.h" +#include "blackmisc/simulation/interpolator.h" #include "blackmisc/simulation/interpolationhints.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/pq/physicalquantity.h" diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 033045dbb..f9fa8b6ef 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -19,7 +19,6 @@ #include "blackcore/aircraftmatcher.h" #include "blackcore/blackcoreexport.h" #include "blackcore/simulator.h" -#include "blackmisc/interpolationrenderingsetup.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/simulation/aircraftmodelsetloader.h" #include "blackmisc/simulation/ownaircraftprovider.h" @@ -28,6 +27,7 @@ #include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorinternals.h" +#include "blackmisc/simulation/interpolationrenderingsetup.h" #include "blackmisc/simulation/interpolationhints.h" #include "blackmisc/weather/weathergridprovider.h" #include "blackmisc/pq/length.h" @@ -37,8 +37,6 @@ namespace BlackMisc { - class IInterpolator; - namespace Aviation { class CAircraftParts; @@ -47,6 +45,7 @@ namespace BlackMisc } namespace Simulation { + class IInterpolator; class CAirspaceAircraftSnapshot; class CSimulatedAircraft; } @@ -73,8 +72,8 @@ namespace BlackCore //! \name ISimulator implementations //! @{ virtual BlackMisc::Simulation::CAircraftModel getDefaultModel() const override; - virtual void setInterpolationAndRenderingSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup) override; - virtual BlackMisc::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) override; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const override; virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const override; @@ -155,14 +154,14 @@ namespace BlackCore //! Set own model void reverseLookupAndUpdateOwnAircraftModel(const QString &modelString); - BlackMisc::IInterpolator *m_interpolator = nullptr; //!< interpolator instance - bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold) - BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< default model - qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time - qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time - int m_statsUpdateAircraftCountMs = 0; //!< statistics update time - BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object - BlackMisc::CInterpolationAndRenderingSetup m_interpolationRenderingSetup; //!< debug messages, rendering etc. + BlackMisc::Simulation::IInterpolator *m_interpolator = nullptr; //!< interpolator instance + bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold) + BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< default model + qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time + qint64 m_statsUpdateAircraftTimeAvgMs = 0; //!< statistics update time + int m_statsUpdateAircraftCountMs = 0; //!< statistics update time + BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object + BlackMisc::Simulation::CInterpolationAndRenderingSetup m_interpolationRenderingSetup; //!< debug messages, rendering etc. // some optional functionality which can be used by the sims as needed BlackMisc::Simulation::CSimulatedAircraftList m_aircraftToAddAgainWhenRemoved; //!< add this model again when removed, normally used to change model diff --git a/src/blackmisc/interpolationrenderingsetup.cpp b/src/blackmisc/interpolationrenderingsetup.cpp deleted file mode 100644 index 87dadb670..000000000 --- a/src/blackmisc/interpolationrenderingsetup.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* Copyright (C) 2016 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "interpolationrenderingsetup.h" -#include "stringutils.h" - -using namespace BlackMisc::PhysicalQuantities; - -namespace BlackMisc -{ - CInterpolationAndRenderingSetup::CInterpolationAndRenderingSetup() - { } - - int CInterpolationAndRenderingSetup::InfiniteAircraft() - { - return 100; - } - - bool CInterpolationAndRenderingSetup::isRenderingEnabled() const - { - if (m_maxRenderedAircraft < 1) { return false; } - if (!isMaxDistanceRestricted()) { return true; } - return m_maxRenderedDistance.isPositiveWithEpsilonConsidered(); - } - - bool CInterpolationAndRenderingSetup::isRenderingRestricted() const - { - return isRenderingEnabled() && (isMaxAircraftRestricted() || isMaxDistanceRestricted()); - } - - bool CInterpolationAndRenderingSetup::isAircraftPartsEnabled() const - { - return this->m_enabledAircraftParts; - } - - int CInterpolationAndRenderingSetup::getMaxRenderedAircraft() const - { - return (m_maxRenderedAircraft <= InfiniteAircraft()) ? m_maxRenderedAircraft : InfiniteAircraft(); - } - - bool CInterpolationAndRenderingSetup::setMaxRenderedAircraft(int maxRenderedAircraft) - { - if (maxRenderedAircraft == m_maxRenderedAircraft) { return false; } - if (maxRenderedAircraft < 1) - { - // disable, we set both values to 0 - this->disableRendering(); - } - else if (maxRenderedAircraft >= InfiniteAircraft()) - { - m_maxRenderedAircraft = InfiniteAircraft(); - } - else - { - m_maxRenderedAircraft = maxRenderedAircraft; - } - return true; - } - - bool CInterpolationAndRenderingSetup::setMaxRenderedDistance(const CLength &distance) - { - - if (distance == m_maxRenderedDistance) { return false; } - if (distance.isNull() || distance.isNegativeWithEpsilonConsidered()) - { - m_maxRenderedDistance = CLength(0.0, nullptr); - } - else if (distance.isZeroEpsilonConsidered()) - { - // zero means disabled, we disable max aircraft too - this->disableRendering(); - } - else - { - Q_ASSERT(!distance.isNegativeWithEpsilonConsidered()); - m_maxRenderedDistance = distance; - } - return true; - } - - bool CInterpolationAndRenderingSetup::setEnabledAircraftParts(bool enabled) - { - if (this->m_enabledAircraftParts == enabled) { return false; } - m_enabledAircraftParts = enabled; - return true; - } - - void CInterpolationAndRenderingSetup::clearMaxRenderedDistance() - { - this->setMaxRenderedDistance(CLength(0.0, nullptr)); - } - - bool CInterpolationAndRenderingSetup::isMaxAircraftRestricted() const - { - return m_maxRenderedAircraft < InfiniteAircraft(); - } - - void CInterpolationAndRenderingSetup::clearAllRenderingRestrictions() - { - this->m_maxRenderedDistance = CLength(0, nullptr); - this->m_maxRenderedAircraft = InfiniteAircraft(); - } - - void CInterpolationAndRenderingSetup::disableRendering() - { - this->m_maxRenderedAircraft = 0; - this->m_maxRenderedDistance = CLength(0, CLengthUnit::NM()); // zero distance - } - - bool CInterpolationAndRenderingSetup::isMaxDistanceRestricted() const - { - return !m_maxRenderedDistance.isNull(); - } - - QString CInterpolationAndRenderingSetup::getRenderRestrictionText() const - { - if (!this->isRenderingRestricted()) { return "none"; } - QString rt; - if (this->isMaxAircraftRestricted()) - { - rt.append(QString::number(this->getMaxRenderedAircraft())).append(" A/C"); - } - if (this->isMaxDistanceRestricted()) - { - if (!rt.isEmpty()) { rt.append(" ");} - rt.append(this->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0)); - } - return rt; - } - - QString CInterpolationAndRenderingSetup::convertToQString(bool i18n) const - { - Q_UNUSED(i18n); - QString s("Setup: debug sim: "); - s += boolToYesNo(this->m_simulatorDebugMessages); - s += " debug interpolator: "; - s += boolToYesNo(this->m_interpolatorDebugMessage); - s += " force full interpolation: "; - s += boolToYesNo(this->m_forceFullInterpolation); - s += " max.aircraft:"; - s += QString::number(m_maxRenderedAircraft); - s += " max.distance:"; - s += m_maxRenderedDistance.valueRoundedWithUnit(CLengthUnit::NM(), 2); - return s; - } - - CVariant CInterpolationAndRenderingSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const - { - if (index.isMyself()) { return CVariant::from(*this); } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexInterpolatorDebugMessages: - return CVariant::fromValue(m_interpolatorDebugMessage); - case IndexSimulatorDebugMessages: - return CVariant::fromValue(m_simulatorDebugMessages); - case IndexForceFullInterpolation: - return CVariant::fromValue(m_forceFullInterpolation); - case IndexMaxRenderedAircraft: - return CVariant::fromValue(m_maxRenderedAircraft); - case IndexMaxRenderedDistance: - return CVariant::fromValue(m_maxRenderedDistance); - case IndexEnabledAircraftParts: - return CVariant::fromValue(m_enabledAircraftParts); - default: - return CValueObject::propertyByIndex(index); - } - } - - void CInterpolationAndRenderingSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) - { - if (index.isMyself()) - { - *this = variant.value(); - return; - } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexInterpolatorDebugMessages: - this->m_interpolatorDebugMessage = variant.toBool(); - break; - case IndexSimulatorDebugMessages: - this->m_simulatorDebugMessages = variant.toBool(); - break; - case IndexForceFullInterpolation: - this->m_forceFullInterpolation = variant.toBool(); - break; - case IndexMaxRenderedAircraft: - this->m_maxRenderedAircraft = variant.toInt(); - break; - case IndexMaxRenderedDistance: - this->m_maxRenderedDistance = variant.value(); - break; - case IndexEnabledAircraftParts: - this->m_enabledAircraftParts = variant.toBool(); - break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; - } - } -} // ns diff --git a/src/blackmisc/interpolationrenderingsetup.h b/src/blackmisc/interpolationrenderingsetup.h deleted file mode 100644 index 4ba18fdac..000000000 --- a/src/blackmisc/interpolationrenderingsetup.h +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (C) 2016 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_INTERPOLATION_RENDERING_SETUP_H -#define BLACKMISC_INTERPOLATION_RENDERING_SETUP_H - -#include "blackmisc/pq/length.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/propertyindex.h" -#include "blackmisc/valueobject.h" -#include - -namespace BlackMisc -{ - /*! - * Value object for interpolator and rendering - */ - class BLACKMISC_EXPORT CInterpolationAndRenderingSetup : - public CValueObject - { - public: - //! Properties by index - enum ColumnIndex - { - IndexInterpolatorDebugMessages = BlackMisc::CPropertyIndex::GlobalIndexCInterpolatioRenderingSetup, - IndexSimulatorDebugMessages, - IndexForceFullInterpolation, - IndexMaxRenderedAircraft, - IndexMaxRenderedDistance, - IndexEnabledAircraftParts - }; - - //! Constructor. - CInterpolationAndRenderingSetup(); - - //! Considered as "all aircraft" - static int InfiniteAircraft(); - - //! Debugging messages - bool showInterpolatorDebugMessages() const { return m_interpolatorDebugMessage; } - - //! Debugging messages - void setInterpolatorDebuggingMessages(bool debug) { m_interpolatorDebugMessage = debug; } - - //! Debugging messages - bool showSimulatorDebugMessages() const { return m_simulatorDebugMessages; } - - //! Debugging messages - void setDriverDebuggingMessages(bool debug) { m_simulatorDebugMessages = debug; } - - //! Full interpolation - bool isForcingFullInterpolation() const { return m_forceFullInterpolation; } - - //! Force full interpolation - void setForceFullInterpolation(bool force) { m_forceFullInterpolation = force; } - - //! Max. number of aircraft rendered - int getMaxRenderedAircraft() const; - - //! Max. number of aircraft rendered - bool setMaxRenderedAircraft(int maxRenderedAircraft); - - //! Max. distance for rendering - bool setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance); - - //! Set enabled aircraft parts - bool setEnabledAircraftParts(bool enabled); - - //! Disable - void clearMaxRenderedDistance(); - - //! Rendering enabled (at all) - bool isRenderingEnabled() const; - - //! Rendering enabled, but restricted - bool isRenderingRestricted() const; - - //! Aircraft parts enabled - bool isAircraftPartsEnabled() const; - - //! Max.distance for rendering - BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const { return m_maxRenderedDistance; } - - //! Restricted by distance? - bool isMaxDistanceRestricted() const; - - //! Restricted by quantity? - bool isMaxAircraftRestricted() const; - - //! Remove all render restrictions - void clearAllRenderingRestrictions(); - - //! Entirely disable rendering - void disableRendering(); - - //! Text describing the restrictions - QString getRenderRestrictionText() const; - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - //! \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); - - private: - bool m_interpolatorDebugMessage = false; //! Debug messages in interpolator - bool m_simulatorDebugMessages = false; //! Debug messages of simulator (aka plugin) - bool m_forceFullInterpolation = false; //! always do a full interpolation, even if aircraft is not moving - bool m_enabledAircraftParts = true; //! Update aircraft parts - int m_maxRenderedAircraft = InfiniteAircraft(); //!< max.rendered aircraft - BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0, nullptr }; //!< max.distance for rendering - - BLACK_METACLASS( - CInterpolationAndRenderingSetup, - BLACK_METAMEMBER(interpolatorDebugMessage), - BLACK_METAMEMBER(simulatorDebugMessages), - BLACK_METAMEMBER(forceFullInterpolation), - BLACK_METAMEMBER(enabledAircraftParts), - BLACK_METAMEMBER(maxRenderedAircraft), - BLACK_METAMEMBER(maxRenderedDistance) - ); - }; -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::CInterpolationAndRenderingSetup) - -#endif // guard diff --git a/src/blackmisc/interpolator.cpp b/src/blackmisc/interpolator.cpp deleted file mode 100644 index 9442cac8b..000000000 --- a/src/blackmisc/interpolator.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (C) 2015 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "interpolator.h" -#include "blackmisc/aviation/callsign.h" -#include "blackmisc/simulation/interpolationhints.h" - -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Simulation; - -namespace BlackMisc -{ - IInterpolator::IInterpolator(IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent) : - QObject(parent), - CRemoteAircraftAware(provider) - { - Q_ASSERT_X(provider, Q_FUNC_INFO, "missing provider"); - this->setObjectName(objectName); - } - - BlackMisc::Aviation::CAircraftSituation IInterpolator::getInterpolatedSituation(const CCallsign &callsign, qint64 currentTimeSinceEpoc, - const CInterpolationHints &hints, InterpolationStatus &status) const - { - // has to be thread safe - - status.reset(); - Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign"); - - auto currentSituation = this->getInterpolatedSituation(this->remoteAircraftSituations(callsign), currentTimeSinceEpoc, hints, status); - currentSituation.setCallsign(callsign); // make sure callsign is correct - return currentSituation; - } - - CAircraftPartsList IInterpolator::getPartsBeforeTime(const CAircraftPartsList &parts, qint64 cutoffTime, IInterpolator::PartsStatus &partsStatus) const - { - partsStatus.reset(); - partsStatus.setSupportsParts(true); - - if (cutoffTime < 0) { return parts; } - return parts.findBefore(cutoffTime); - } - - CAircraftPartsList IInterpolator::getPartsBeforeTime(const CCallsign &callsign, qint64 cutoffTime, IInterpolator::PartsStatus &partsStatus) const - { - Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign"); - partsStatus.reset(); - - partsStatus.setSupportsParts(this->isRemoteAircraftSupportingParts(callsign)); - if (!partsStatus.isSupportingParts()) { return {}; } - return this->remoteAircraftParts(callsign, cutoffTime); - } - - void IInterpolator::setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup) - { - QWriteLocker l(&m_lock); - m_setup = setup; - } - - CInterpolationAndRenderingSetup IInterpolator::getInterpolatorSetup() const - { - QReadLocker l(&m_lock); - return m_setup; - } - - void IInterpolator::setGroundElevationFromHint(const CInterpolationHints &hints, CAircraftSituation &situation) - { - if (hints.getElevation().isNull()) return; - if (situation.hasGroundElevation()) return; - if (!hints.isWithinRange(situation)) return; - situation.setGroundElevation(hints.getElevation().geodeticHeight()); - } - - bool IInterpolator::InterpolationStatus::allTrue() const - { - return m_interpolationSucceeded && m_changedPosition; - } - - void IInterpolator::InterpolationStatus::reset() - { - m_changedPosition = false; - m_interpolationSucceeded = false; - } - - bool IInterpolator::PartsStatus::allTrue() const - { - return m_supportsParts; - } - - void IInterpolator::PartsStatus::reset() - { - m_supportsParts = false; - } -} // namespace diff --git a/src/blackmisc/interpolator.h b/src/blackmisc/interpolator.h deleted file mode 100644 index 4e2a24739..000000000 --- a/src/blackmisc/interpolator.h +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright (C) 2014 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_INTERPOLATOR_H -#define BLACKMISC_INTERPOLATOR_H - -#include "interpolationrenderingsetup.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/aviation/aircraftpartslist.h" -#include "blackmisc/aviation/aircraftsituation.h" -#include "blackmisc/simulation/remoteaircraftprovider.h" - -#include -#include -#include - -namespace BlackMisc -{ - namespace Aviation { class CCallsign; } - namespace Simulation { class CInterpolationHints; } - - //! Interpolator, calculation inbetween positions - class BLACKMISC_EXPORT IInterpolator : - public QObject, - public BlackMisc::Simulation::CRemoteAircraftAware - { - Q_OBJECT - - public: - //! Virtual destructor - virtual ~IInterpolator() {} - - //! Log category - static QString getLogCategory() { return "swift.interpolator"; } - - //! Status of interpolation - struct BLACKMISC_EXPORT InterpolationStatus // does not link without export/allTrue, reset - { - public: - //! Did interpolation succeed? - bool didInterpolationSucceed() const { return m_interpolationSucceeded; } - - //! Set succeeded - void setInterpolationSucceeded(bool succeeded) { m_interpolationSucceeded = succeeded; } - - //! Changed position? - bool hasChangedPosition() const { return m_changedPosition; } - - //! Set as changed - void setChangedPosition(bool changed) { m_changedPosition = changed; } - - //! all OK - bool allTrue() const; - - //! Reset to default values - void reset(); - - private: - bool m_changedPosition = false; //!< position was changed - bool m_interpolationSucceeded = false; //!< interpolation succeeded (means enough values, etc.) - }; - - //! Status regarding parts - struct BLACKMISC_EXPORT PartsStatus // does not link without export/allTrue, resetx - { - public: - //! all OK - bool allTrue() const; - - //! Supporting parts - bool isSupportingParts() const { return m_supportsParts; } - - //! Set support flag - void setSupportsParts(bool supports) { m_supportsParts = supports; } - - //! Reset to default values - void reset(); - - private: - bool m_supportsParts = false; //!< supports parts for given callsign - }; - - //! Current interpolated situation - //! \threadsafe - virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation( - const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc, - const CInterpolationHints &hints, InterpolationStatus &status) const; - - //! Current interpolated situation, to be implemented by subclass - //! \threadsafe - //! \remark public only for XP driver - virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation( - const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc, - const CInterpolationHints &hints, InterpolationStatus &status) const = 0; - - //! Parts before given offset time (aka pending parts) - //! \threadsafe - virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime( - const BlackMisc::Aviation::CAircraftPartsList &parts, qint64 cutoffTime, - PartsStatus &partsStatus) const; - - //! Parts before given offset time (aka pending parts) - //! \threadsafe - virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime( - const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime, - PartsStatus &partsStatus) const; - - //! Enable debug messages etc. - //! \threadsafe - void setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup); - - protected: - //! Constructor - IInterpolator(BlackMisc::Simulation::IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent); - - //! Enable debug messages etc. - //! \threadsafe - CInterpolationAndRenderingSetup getInterpolatorSetup() const; - - //! Set the ground elevation from hints, if possible and not already set - static void setGroundElevationFromHint(const CInterpolationHints &hints, BlackMisc::Aviation::CAircraftSituation &situation); - - CInterpolationAndRenderingSetup m_setup; //!< allows to disable debug messages - mutable QReadWriteLock m_lock; //!< lock interpolator - }; -} // namespace -#endif // guard diff --git a/src/blackmisc/interpolatorlinear.cpp b/src/blackmisc/interpolatorlinear.cpp deleted file mode 100644 index aacfab033..000000000 --- a/src/blackmisc/interpolatorlinear.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* Copyright (C) 2014 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "interpolatorlinear.h" -#include "blackmisc/aviation/aircraftsituation.h" -#include "blackmisc/aviation/aircraftsituationlist.h" -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/aviation/callsign.h" -#include "blackmisc/aviation/heading.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/pq/angle.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/pq/physicalquantity.h" -#include "blackmisc/pq/speed.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/simulation/interpolationhints.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/compare.h" -#include "blackmisc/range.h" -#include "blackmisc/sequence.h" -#include "blackmisc/statusmessage.h" - -#include -#include -#include - -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Math; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Simulation; - -namespace BlackMisc -{ - CAircraftSituation CInterpolatorLinear::getInterpolatedSituation(const CAircraftSituationList &situations, qint64 currentTimeMsSinceEpoc, const CInterpolationHints &hints, InterpolationStatus &status) const - { - // has to be thread safe - const CInterpolationAndRenderingSetup setup = this->getInterpolatorSetup(); - status.reset(); - - // any data at all? - if (situations.isEmpty()) { return {}; } - - // data, split situations by time - if (currentTimeMsSinceEpoc < 0) { currentTimeMsSinceEpoc = QDateTime::currentMSecsSinceEpoch(); } - - // find the first situation not in the correct order, keep only the situations before that one - auto end = std::is_sorted_until(situations.begin(), situations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); - auto validSituations = makeRange(situations.begin(), end); - - // find the first situation earlier than the current time - auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; }); - auto situationsNewer = makeRange(validSituations.begin(), pivot); - auto situationsOlder = makeRange(pivot, validSituations.end()); - - // interpolation situations - CAircraftSituation oldSituation; - CAircraftSituation newSituation; - status.setInterpolationSucceeded(true); - status.setChangedPosition(true); //! \todo efficiently determine whether the position has changed - - // latest first, now 00:20 split time - // time pos - // 00:25 10 newer - // 00:20 11 newer - // <----- split - // 00:15 12 older - // 00:10 13 older - // 00:05 14 older - - // The first condition covers a situation, when there are no before / after situations. - // We just place at he last position until we get before / after situations - if (situationsOlder.isEmpty() || situationsNewer.isEmpty()) - { - // no before situations - if (situationsOlder.isEmpty()) { return *(situationsNewer.end() - 1); } // oldest newest - - // only one before situation - if (situationsOlder.size() < 2) { return situationsOlder.front(); } // latest older - - // extrapolate from two before situations - oldSituation = *(situationsOlder.begin() + 1); // before newest - newSituation = situationsOlder.front(); // newest - } - else - { - oldSituation = situationsOlder.front(); // first oldest (aka newest oldest) - newSituation = *(situationsNewer.end() - 1); // latest newest (aka oldest of newer block) - Q_ASSERT(oldSituation.getAdjustedMSecsSinceEpoch() < newSituation.getAdjustedMSecsSinceEpoch()); - } - - // take hint into account to calculate elevation and above ground level - if (!hints.getElevation().isNull()) - { - setGroundElevationFromHint(hints, oldSituation); - setGroundElevationFromHint(hints, newSituation); - } - - CAircraftSituation currentSituation(oldSituation); - CCoordinateGeodetic currentPosition; - - // Time between start and end packet - double deltaTime = std::abs(oldSituation.getAdjustedMSecsSinceEpoch() - newSituation.getAdjustedMSecsSinceEpoch()); - - // Fraction of the deltaTime, ideally [0.0 - 1.0] - // < 0 should not happen due to the split, > 1 can happen if new values are delayed beyond split time - // 1) values > 1 mean extrapolation - // 2) values > 2 mean no new situations coming in - const double distanceToSplitTime = newSituation.getAdjustedMSecsSinceEpoch() - currentTimeMsSinceEpoc; - const double simulationTimeFraction = 1.0 - (distanceToSplitTime / deltaTime); - if (simulationTimeFraction > 2.0) - { - if (setup.showInterpolatorDebugMessages()) - { - CLogMessage(this).warning("Extrapolation, fraction > 1: %1 for callsign: %2") << simulationTimeFraction << oldSituation.getCallsign(); - } - } - - const std::array oldVec(oldSituation.getPosition().normalVectorDouble()); - const std::array newVec(newSituation.getPosition().normalVectorDouble()); - - // Interpolate position: pos = (posB - posA) * t + posA - currentPosition.setNormalVector((newVec[0] - oldVec[0]) * simulationTimeFraction + oldVec[0], - (newVec[1] - oldVec[1]) * simulationTimeFraction + oldVec[1], - (newVec[2] - oldVec[2]) * simulationTimeFraction + oldVec[2]); - - currentSituation.setPosition(currentPosition); - - // Interpolate altitude: Alt = (AltB - AltA) * t + AltA - const CAltitude oldAlt(oldSituation.getCorrectedAltitude(hints.getCGAboveGround())); - const CAltitude newAlt(newSituation.getCorrectedAltitude(hints.getCGAboveGround())); - Q_ASSERT_X(oldAlt.getReferenceDatum() == newAlt.getReferenceDatum(), Q_FUNC_INFO, "mismatch in reference"); // otherwise no calculation is possible - currentSituation.setAltitude(CAltitude((newAlt - oldAlt) - * simulationTimeFraction - + oldAlt, - oldAlt.getReferenceDatum())); - - if (!setup.isForcingFullInterpolation() && !hints.isVtolAircraft() && newVec == oldVec && oldAlt == newAlt) - { - // stop interpolation here, does not work for VTOL aircraft. We need a flag for VTOL aircraft - return currentSituation; - } - - // Interpolate heading: HDG = (HdgB - HdgA) * t + HdgA - const CHeading headingBegin = oldSituation.getHeading(); - CHeading headingEnd = newSituation.getHeading(); - - if ((headingEnd - headingBegin).value(CAngleUnit::deg()) < -180) - { - headingEnd += CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); - } - - if ((headingEnd - headingBegin).value(CAngleUnit::deg()) > 180) - { - headingEnd -= CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); - } - - currentSituation.setHeading(CHeading((headingEnd - headingBegin) - * simulationTimeFraction - + headingBegin, - headingBegin.getReferenceNorth())); - - // Interpolate Pitch: Pitch = (PitchB - PitchA) * t + PitchA - const CAngle pitchBegin = oldSituation.getPitch(); - const CAngle pitchEnd = newSituation.getPitch(); - const CAngle pitch = (pitchEnd - pitchBegin) * simulationTimeFraction + pitchBegin; - currentSituation.setPitch(pitch); - - // Interpolate bank: Bank = (BankB - BankA) * t + BankA - const CAngle bankBegin = oldSituation.getBank(); - const CAngle bankEnd = newSituation.getBank(); - const CAngle bank = (bankEnd - bankBegin) * simulationTimeFraction + bankBegin; - currentSituation.setBank(bank); - - currentSituation.setGroundSpeed((newSituation.getGroundSpeed() - oldSituation.getGroundSpeed()) - * simulationTimeFraction - + oldSituation.getGroundSpeed()); - return currentSituation; - } -} // namespace diff --git a/src/blackmisc/interpolatorlinear.h b/src/blackmisc/interpolatorlinear.h deleted file mode 100644 index 741650360..000000000 --- a/src/blackmisc/interpolatorlinear.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2014 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_INTERPOLATOR_LINEAR_H -#define BLACKMISC_INTERPOLATOR_LINEAR_H - -#include "interpolator.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/aviation/aircraftsituation.h" -#include -#include - -class QObject; - -namespace BlackMisc -{ - namespace Aviation { class CCallsign; } - namespace Simulation { class IRemoteAircraftProvider; } - - //! Linear interpolator, calculation inbetween positions - class BLACKMISC_EXPORT CInterpolatorLinear : public IInterpolator - { - public: - //! Constructor - CInterpolatorLinear(BlackMisc::Simulation::IRemoteAircraftProvider *provider, QObject *parent = nullptr) : - IInterpolator(provider, "CInterpolatorLinear", parent) - {} - - // public base class signature - using IInterpolator::getInterpolatedSituation; - - //! \copydoc IInterpolator::getInterpolatedSituation - virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc, const BlackMisc::Simulation::CInterpolationHints &hints, InterpolationStatus &status) const override; - - //! Log category - static QString getLogCategory() { return "swift.interpolatorlinear"; } - }; -} // ns - -#endif // guard diff --git a/src/blackmisc/simulation/interpolationrenderingsetup.cpp b/src/blackmisc/simulation/interpolationrenderingsetup.cpp new file mode 100644 index 000000000..b0cabfa4e --- /dev/null +++ b/src/blackmisc/simulation/interpolationrenderingsetup.cpp @@ -0,0 +1,212 @@ +/* Copyright (C) 2016 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "interpolationrenderingsetup.h" +#include "stringutils.h" + +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackMisc +{ + namespace Simulation + { + CInterpolationAndRenderingSetup::CInterpolationAndRenderingSetup() + { } + + int CInterpolationAndRenderingSetup::InfiniteAircraft() + { + return 100; + } + + bool CInterpolationAndRenderingSetup::isRenderingEnabled() const + { + if (m_maxRenderedAircraft < 1) { return false; } + if (!isMaxDistanceRestricted()) { return true; } + return m_maxRenderedDistance.isPositiveWithEpsilonConsidered(); + } + + bool CInterpolationAndRenderingSetup::isRenderingRestricted() const + { + return isRenderingEnabled() && (isMaxAircraftRestricted() || isMaxDistanceRestricted()); + } + + bool CInterpolationAndRenderingSetup::isAircraftPartsEnabled() const + { + return this->m_enabledAircraftParts; + } + + int CInterpolationAndRenderingSetup::getMaxRenderedAircraft() const + { + return (m_maxRenderedAircraft <= InfiniteAircraft()) ? m_maxRenderedAircraft : InfiniteAircraft(); + } + + bool CInterpolationAndRenderingSetup::setMaxRenderedAircraft(int maxRenderedAircraft) + { + if (maxRenderedAircraft == m_maxRenderedAircraft) { return false; } + if (maxRenderedAircraft < 1) + { + // disable, we set both values to 0 + this->disableRendering(); + } + else if (maxRenderedAircraft >= InfiniteAircraft()) + { + m_maxRenderedAircraft = InfiniteAircraft(); + } + else + { + m_maxRenderedAircraft = maxRenderedAircraft; + } + return true; + } + + bool CInterpolationAndRenderingSetup::setMaxRenderedDistance(const CLength &distance) + { + + if (distance == m_maxRenderedDistance) { return false; } + if (distance.isNull() || distance.isNegativeWithEpsilonConsidered()) + { + m_maxRenderedDistance = CLength(0.0, nullptr); + } + else if (distance.isZeroEpsilonConsidered()) + { + // zero means disabled, we disable max aircraft too + this->disableRendering(); + } + else + { + Q_ASSERT(!distance.isNegativeWithEpsilonConsidered()); + m_maxRenderedDistance = distance; + } + return true; + } + + bool CInterpolationAndRenderingSetup::setEnabledAircraftParts(bool enabled) + { + if (this->m_enabledAircraftParts == enabled) { return false; } + m_enabledAircraftParts = enabled; + return true; + } + + void CInterpolationAndRenderingSetup::clearMaxRenderedDistance() + { + this->setMaxRenderedDistance(CLength(0.0, nullptr)); + } + + bool CInterpolationAndRenderingSetup::isMaxAircraftRestricted() const + { + return m_maxRenderedAircraft < InfiniteAircraft(); + } + + void CInterpolationAndRenderingSetup::clearAllRenderingRestrictions() + { + this->m_maxRenderedDistance = CLength(0, nullptr); + this->m_maxRenderedAircraft = InfiniteAircraft(); + } + + void CInterpolationAndRenderingSetup::disableRendering() + { + this->m_maxRenderedAircraft = 0; + this->m_maxRenderedDistance = CLength(0, CLengthUnit::NM()); // zero distance + } + + bool CInterpolationAndRenderingSetup::isMaxDistanceRestricted() const + { + return !m_maxRenderedDistance.isNull(); + } + + QString CInterpolationAndRenderingSetup::getRenderRestrictionText() const + { + if (!this->isRenderingRestricted()) { return "none"; } + QString rt; + if (this->isMaxAircraftRestricted()) + { + rt.append(QString::number(this->getMaxRenderedAircraft())).append(" A/C"); + } + if (this->isMaxDistanceRestricted()) + { + if (!rt.isEmpty()) { rt.append(" ");} + rt.append(this->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0)); + } + return rt; + } + + QString CInterpolationAndRenderingSetup::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + QString s("Setup: debug sim: "); + s += boolToYesNo(this->m_simulatorDebugMessages); + s += " debug interpolator: "; + s += boolToYesNo(this->m_interpolatorDebugMessage); + s += " force full interpolation: "; + s += boolToYesNo(this->m_forceFullInterpolation); + s += " max.aircraft:"; + s += QString::number(m_maxRenderedAircraft); + s += " max.distance:"; + s += m_maxRenderedDistance.valueRoundedWithUnit(CLengthUnit::NM(), 2); + return s; + } + + CVariant CInterpolationAndRenderingSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexInterpolatorDebugMessages: + return CVariant::fromValue(m_interpolatorDebugMessage); + case IndexSimulatorDebugMessages: + return CVariant::fromValue(m_simulatorDebugMessages); + case IndexForceFullInterpolation: + return CVariant::fromValue(m_forceFullInterpolation); + case IndexMaxRenderedAircraft: + return CVariant::fromValue(m_maxRenderedAircraft); + case IndexMaxRenderedDistance: + return CVariant::fromValue(m_maxRenderedDistance); + case IndexEnabledAircraftParts: + return CVariant::fromValue(m_enabledAircraftParts); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CInterpolationAndRenderingSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) + { + *this = variant.value(); + return; + } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexInterpolatorDebugMessages: + this->m_interpolatorDebugMessage = variant.toBool(); + break; + case IndexSimulatorDebugMessages: + this->m_simulatorDebugMessages = variant.toBool(); + break; + case IndexForceFullInterpolation: + this->m_forceFullInterpolation = variant.toBool(); + break; + case IndexMaxRenderedAircraft: + this->m_maxRenderedAircraft = variant.toInt(); + break; + case IndexMaxRenderedDistance: + this->m_maxRenderedDistance = variant.value(); + break; + case IndexEnabledAircraftParts: + this->m_enabledAircraftParts = variant.toBool(); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + } // ns +} // ns diff --git a/src/blackmisc/simulation/interpolationrenderingsetup.h b/src/blackmisc/simulation/interpolationrenderingsetup.h new file mode 100644 index 000000000..87ed93612 --- /dev/null +++ b/src/blackmisc/simulation/interpolationrenderingsetup.h @@ -0,0 +1,141 @@ +/* Copyright (C) 2016 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_INTERPOLATIONRENDERINGSETUP_H +#define BLACKMISC_SIMULATION_INTERPOLATIONRENDERINGSETUP_H + +#include "blackmisc/pq/length.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/valueobject.h" +#include + +namespace BlackMisc +{ + namespace Simulation + { + /*! + * Value object for interpolator and rendering + */ + class BLACKMISC_EXPORT CInterpolationAndRenderingSetup : + public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexInterpolatorDebugMessages = BlackMisc::CPropertyIndex::GlobalIndexCInterpolatioRenderingSetup, + IndexSimulatorDebugMessages, + IndexForceFullInterpolation, + IndexMaxRenderedAircraft, + IndexMaxRenderedDistance, + IndexEnabledAircraftParts + }; + + //! Constructor. + CInterpolationAndRenderingSetup(); + + //! Considered as "all aircraft" + static int InfiniteAircraft(); + + //! Debugging messages + bool showInterpolatorDebugMessages() const { return m_interpolatorDebugMessage; } + + //! Debugging messages + void setInterpolatorDebuggingMessages(bool debug) { m_interpolatorDebugMessage = debug; } + + //! Debugging messages + bool showSimulatorDebugMessages() const { return m_simulatorDebugMessages; } + + //! Debugging messages + void setDriverDebuggingMessages(bool debug) { m_simulatorDebugMessages = debug; } + + //! Full interpolation + bool isForcingFullInterpolation() const { return m_forceFullInterpolation; } + + //! Force full interpolation + void setForceFullInterpolation(bool force) { m_forceFullInterpolation = force; } + + //! Max. number of aircraft rendered + int getMaxRenderedAircraft() const; + + //! Max. number of aircraft rendered + bool setMaxRenderedAircraft(int maxRenderedAircraft); + + //! Max. distance for rendering + bool setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance); + + //! Set enabled aircraft parts + bool setEnabledAircraftParts(bool enabled); + + //! Disable + void clearMaxRenderedDistance(); + + //! Rendering enabled (at all) + bool isRenderingEnabled() const; + + //! Rendering enabled, but restricted + bool isRenderingRestricted() const; + + //! Aircraft parts enabled + bool isAircraftPartsEnabled() const; + + //! Max.distance for rendering + BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const { return m_maxRenderedDistance; } + + //! Restricted by distance? + bool isMaxDistanceRestricted() const; + + //! Restricted by quantity? + bool isMaxAircraftRestricted() const; + + //! Remove all render restrictions + void clearAllRenderingRestrictions(); + + //! Entirely disable rendering + void disableRendering(); + + //! Text describing the restrictions + QString getRenderRestrictionText() const; + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \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); + + private: + bool m_interpolatorDebugMessage = false; //! Debug messages in interpolator + bool m_simulatorDebugMessages = false; //! Debug messages of simulator (aka plugin) + bool m_forceFullInterpolation = false; //! always do a full interpolation, even if aircraft is not moving + bool m_enabledAircraftParts = true; //! Update aircraft parts + int m_maxRenderedAircraft = InfiniteAircraft(); //!< max.rendered aircraft + BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0, nullptr }; //!< max.distance for rendering + + BLACK_METACLASS( + CInterpolationAndRenderingSetup, + BLACK_METAMEMBER(interpolatorDebugMessage), + BLACK_METAMEMBER(simulatorDebugMessages), + BLACK_METAMEMBER(forceFullInterpolation), + BLACK_METAMEMBER(enabledAircraftParts), + BLACK_METAMEMBER(maxRenderedAircraft), + BLACK_METAMEMBER(maxRenderedDistance) + ); + }; + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Simulation::CInterpolationAndRenderingSetup) + +#endif // guard diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp new file mode 100644 index 000000000..2efed3e4b --- /dev/null +++ b/src/blackmisc/simulation/interpolator.cpp @@ -0,0 +1,102 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "interpolator.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/simulation/interpolationhints.h" + +using namespace BlackMisc::Aviation; + +namespace BlackMisc +{ + namespace Simulation + { + IInterpolator::IInterpolator(IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent) : + QObject(parent), + CRemoteAircraftAware(provider) + { + Q_ASSERT_X(provider, Q_FUNC_INFO, "missing provider"); + this->setObjectName(objectName); + } + + BlackMisc::Aviation::CAircraftSituation IInterpolator::getInterpolatedSituation( + const CCallsign &callsign, qint64 currentTimeSinceEpoc, + const CInterpolationHints &hints, InterpolationStatus &status) const + { + // has to be thread safe + + status.reset(); + Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign"); + + auto currentSituation = this->getInterpolatedSituation(this->remoteAircraftSituations(callsign), currentTimeSinceEpoc, hints, status); + currentSituation.setCallsign(callsign); // make sure callsign is correct + return currentSituation; + } + + CAircraftPartsList IInterpolator::getPartsBeforeTime(const CAircraftPartsList &parts, qint64 cutoffTime, IInterpolator::PartsStatus &partsStatus) const + { + partsStatus.reset(); + partsStatus.setSupportsParts(true); + + if (cutoffTime < 0) { return parts; } + return parts.findBefore(cutoffTime); + } + + CAircraftPartsList IInterpolator::getPartsBeforeTime(const CCallsign &callsign, qint64 cutoffTime, IInterpolator::PartsStatus &partsStatus) const + { + Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign"); + partsStatus.reset(); + + partsStatus.setSupportsParts(this->isRemoteAircraftSupportingParts(callsign)); + if (!partsStatus.isSupportingParts()) { return {}; } + return this->remoteAircraftParts(callsign, cutoffTime); + } + + void IInterpolator::setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup) + { + QWriteLocker l(&m_lock); + m_setup = setup; + } + + CInterpolationAndRenderingSetup IInterpolator::getInterpolatorSetup() const + { + QReadLocker l(&m_lock); + return m_setup; + } + + void IInterpolator::setGroundElevationFromHint(const CInterpolationHints &hints, CAircraftSituation &situation) + { + if (hints.getElevation().isNull()) return; + if (situation.hasGroundElevation()) return; + if (!hints.isWithinRange(situation)) return; + situation.setGroundElevation(hints.getElevation().geodeticHeight()); + } + + bool IInterpolator::InterpolationStatus::allTrue() const + { + return m_interpolationSucceeded && m_changedPosition; + } + + void IInterpolator::InterpolationStatus::reset() + { + m_changedPosition = false; + m_interpolationSucceeded = false; + } + + bool IInterpolator::PartsStatus::allTrue() const + { + return m_supportsParts; + } + + void IInterpolator::PartsStatus::reset() + { + m_supportsParts = false; + } + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h new file mode 100644 index 000000000..a643d96dc --- /dev/null +++ b/src/blackmisc/simulation/interpolator.h @@ -0,0 +1,138 @@ +/* Copyright (C) 2014 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_INTERPOLATOR_H +#define BLACKMISC_SIMULATION_INTERPOLATOR_H + +#include "interpolationrenderingsetup.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/aviation/aircraftpartslist.h" +#include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/simulation/remoteaircraftprovider.h" + +#include +#include +#include + +namespace BlackMisc +{ + namespace Aviation { class CCallsign; } + namespace Simulation + { + class CInterpolationHints; + + //! Interpolator, calculation inbetween positions + class BLACKMISC_EXPORT IInterpolator : + public QObject, + public BlackMisc::Simulation::CRemoteAircraftAware + { + Q_OBJECT + + public: + //! Virtual destructor + virtual ~IInterpolator() {} + + //! Log category + static QString getLogCategory() { return "swift.interpolator"; } + + //! Status of interpolation + struct BLACKMISC_EXPORT InterpolationStatus // does not link without export/allTrue, reset + { + public: + //! Did interpolation succeed? + bool didInterpolationSucceed() const { return m_interpolationSucceeded; } + + //! Set succeeded + void setInterpolationSucceeded(bool succeeded) { m_interpolationSucceeded = succeeded; } + + //! Changed position? + bool hasChangedPosition() const { return m_changedPosition; } + + //! Set as changed + void setChangedPosition(bool changed) { m_changedPosition = changed; } + + //! all OK + bool allTrue() const; + + //! Reset to default values + void reset(); + + private: + bool m_changedPosition = false; //!< position was changed + bool m_interpolationSucceeded = false; //!< interpolation succeeded (means enough values, etc.) + }; + + //! Status regarding parts + struct BLACKMISC_EXPORT PartsStatus // does not link without export/allTrue, resetx + { + public: + //! all OK + bool allTrue() const; + + //! Supporting parts + bool isSupportingParts() const { return m_supportsParts; } + + //! Set support flag + void setSupportsParts(bool supports) { m_supportsParts = supports; } + + //! Reset to default values + void reset(); + + private: + bool m_supportsParts = false; //!< supports parts for given callsign + }; + + //! Current interpolated situation + //! \threadsafe + virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation( + const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc, + const CInterpolationHints &hints, InterpolationStatus &status) const; + + //! Current interpolated situation, to be implemented by subclass + //! \threadsafe + //! \remark public only for XP driver + virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation( + const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc, + const CInterpolationHints &hints, InterpolationStatus &status) const = 0; + + //! Parts before given offset time (aka pending parts) + //! \threadsafe + virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime( + const BlackMisc::Aviation::CAircraftPartsList &parts, qint64 cutoffTime, + PartsStatus &partsStatus) const; + + //! Parts before given offset time (aka pending parts) + //! \threadsafe + virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime( + const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime, + PartsStatus &partsStatus) const; + + //! Enable debug messages etc. + //! \threadsafe + void setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup); + + protected: + //! Constructor + IInterpolator(BlackMisc::Simulation::IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent); + + //! Enable debug messages etc. + //! \threadsafe + CInterpolationAndRenderingSetup getInterpolatorSetup() const; + + //! Set the ground elevation from hints, if possible and not already set + static void setGroundElevationFromHint(const CInterpolationHints &hints, BlackMisc::Aviation::CAircraftSituation &situation); + + CInterpolationAndRenderingSetup m_setup; //!< allows to disable debug messages + mutable QReadWriteLock m_lock; //!< lock interpolator + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackmisc/simulation/interpolatorlinear.cpp b/src/blackmisc/simulation/interpolatorlinear.cpp new file mode 100644 index 000000000..610eaa22f --- /dev/null +++ b/src/blackmisc/simulation/interpolatorlinear.cpp @@ -0,0 +1,189 @@ +/* Copyright (C) 2014 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "interpolatorlinear.h" +#include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/aviation/aircraftsituationlist.h" +#include "blackmisc/aviation/altitude.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/aviation/heading.h" +#include "blackmisc/geo/coordinategeodetic.h" +#include "blackmisc/pq/angle.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/pq/physicalquantity.h" +#include "blackmisc/pq/speed.h" +#include "blackmisc/pq/units.h" +#include "blackmisc/simulation/interpolationhints.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/compare.h" +#include "blackmisc/range.h" +#include "blackmisc/sequence.h" +#include "blackmisc/statusmessage.h" + +#include +#include +#include + +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Math; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Simulation; + +namespace BlackMisc +{ + namespace Simulation + { + CAircraftSituation CInterpolatorLinear::getInterpolatedSituation(const CAircraftSituationList &situations, qint64 currentTimeMsSinceEpoc, const CInterpolationHints &hints, InterpolationStatus &status) const + { + // has to be thread safe + const CInterpolationAndRenderingSetup setup = this->getInterpolatorSetup(); + status.reset(); + + // any data at all? + if (situations.isEmpty()) { return {}; } + + // data, split situations by time + if (currentTimeMsSinceEpoc < 0) { currentTimeMsSinceEpoc = QDateTime::currentMSecsSinceEpoch(); } + + // find the first situation not in the correct order, keep only the situations before that one + auto end = std::is_sorted_until(situations.begin(), situations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); + auto validSituations = makeRange(situations.begin(), end); + + // find the first situation earlier than the current time + auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; }); + auto situationsNewer = makeRange(validSituations.begin(), pivot); + auto situationsOlder = makeRange(pivot, validSituations.end()); + + // interpolation situations + CAircraftSituation oldSituation; + CAircraftSituation newSituation; + status.setInterpolationSucceeded(true); + status.setChangedPosition(true); //! \todo efficiently determine whether the position has changed + + // latest first, now 00:20 split time + // time pos + // 00:25 10 newer + // 00:20 11 newer + // <----- split + // 00:15 12 older + // 00:10 13 older + // 00:05 14 older + + // The first condition covers a situation, when there are no before / after situations. + // We just place at he last position until we get before / after situations + if (situationsOlder.isEmpty() || situationsNewer.isEmpty()) + { + // no before situations + if (situationsOlder.isEmpty()) { return *(situationsNewer.end() - 1); } // oldest newest + + // only one before situation + if (situationsOlder.size() < 2) { return situationsOlder.front(); } // latest older + + // extrapolate from two before situations + oldSituation = *(situationsOlder.begin() + 1); // before newest + newSituation = situationsOlder.front(); // newest + } + else + { + oldSituation = situationsOlder.front(); // first oldest (aka newest oldest) + newSituation = *(situationsNewer.end() - 1); // latest newest (aka oldest of newer block) + Q_ASSERT(oldSituation.getAdjustedMSecsSinceEpoch() < newSituation.getAdjustedMSecsSinceEpoch()); + } + + // take hint into account to calculate elevation and above ground level + if (!hints.getElevation().isNull()) + { + setGroundElevationFromHint(hints, oldSituation); + setGroundElevationFromHint(hints, newSituation); + } + + CAircraftSituation currentSituation(oldSituation); + CCoordinateGeodetic currentPosition; + + // Time between start and end packet + double deltaTime = std::abs(oldSituation.getAdjustedMSecsSinceEpoch() - newSituation.getAdjustedMSecsSinceEpoch()); + + // Fraction of the deltaTime, ideally [0.0 - 1.0] + // < 0 should not happen due to the split, > 1 can happen if new values are delayed beyond split time + // 1) values > 1 mean extrapolation + // 2) values > 2 mean no new situations coming in + const double distanceToSplitTime = newSituation.getAdjustedMSecsSinceEpoch() - currentTimeMsSinceEpoc; + const double simulationTimeFraction = 1.0 - (distanceToSplitTime / deltaTime); + if (simulationTimeFraction > 2.0) + { + if (setup.showInterpolatorDebugMessages()) + { + CLogMessage(this).warning("Extrapolation, fraction > 1: %1 for callsign: %2") << simulationTimeFraction << oldSituation.getCallsign(); + } + } + + const std::array oldVec(oldSituation.getPosition().normalVectorDouble()); + const std::array newVec(newSituation.getPosition().normalVectorDouble()); + + // Interpolate position: pos = (posB - posA) * t + posA + currentPosition.setNormalVector((newVec[0] - oldVec[0]) * simulationTimeFraction + oldVec[0], + (newVec[1] - oldVec[1]) * simulationTimeFraction + oldVec[1], + (newVec[2] - oldVec[2]) * simulationTimeFraction + oldVec[2]); + + currentSituation.setPosition(currentPosition); + + // Interpolate altitude: Alt = (AltB - AltA) * t + AltA + const CAltitude oldAlt(oldSituation.getCorrectedAltitude(hints.getCGAboveGround())); + const CAltitude newAlt(newSituation.getCorrectedAltitude(hints.getCGAboveGround())); + Q_ASSERT_X(oldAlt.getReferenceDatum() == newAlt.getReferenceDatum(), Q_FUNC_INFO, "mismatch in reference"); // otherwise no calculation is possible + currentSituation.setAltitude(CAltitude((newAlt - oldAlt) + * simulationTimeFraction + + oldAlt, + oldAlt.getReferenceDatum())); + + if (!setup.isForcingFullInterpolation() && !hints.isVtolAircraft() && newVec == oldVec && oldAlt == newAlt) + { + // stop interpolation here, does not work for VTOL aircraft. We need a flag for VTOL aircraft + return currentSituation; + } + + // Interpolate heading: HDG = (HdgB - HdgA) * t + HdgA + const CHeading headingBegin = oldSituation.getHeading(); + CHeading headingEnd = newSituation.getHeading(); + + if ((headingEnd - headingBegin).value(CAngleUnit::deg()) < -180) + { + headingEnd += CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); + } + + if ((headingEnd - headingBegin).value(CAngleUnit::deg()) > 180) + { + headingEnd -= CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); + } + + currentSituation.setHeading(CHeading((headingEnd - headingBegin) + * simulationTimeFraction + + headingBegin, + headingBegin.getReferenceNorth())); + + // Interpolate Pitch: Pitch = (PitchB - PitchA) * t + PitchA + const CAngle pitchBegin = oldSituation.getPitch(); + const CAngle pitchEnd = newSituation.getPitch(); + const CAngle pitch = (pitchEnd - pitchBegin) * simulationTimeFraction + pitchBegin; + currentSituation.setPitch(pitch); + + // Interpolate bank: Bank = (BankB - BankA) * t + BankA + const CAngle bankBegin = oldSituation.getBank(); + const CAngle bankEnd = newSituation.getBank(); + const CAngle bank = (bankEnd - bankBegin) * simulationTimeFraction + bankBegin; + currentSituation.setBank(bank); + + currentSituation.setGroundSpeed((newSituation.getGroundSpeed() - oldSituation.getGroundSpeed()) + * simulationTimeFraction + + oldSituation.getGroundSpeed()); + return currentSituation; + } + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/interpolatorlinear.h b/src/blackmisc/simulation/interpolatorlinear.h new file mode 100644 index 000000000..c4d78c96e --- /dev/null +++ b/src/blackmisc/simulation/interpolatorlinear.h @@ -0,0 +1,51 @@ +/* Copyright (C) 2014 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_INTERPOLATORLINEAR_H +#define BLACKMISC_SIMULATION_INTERPOLATORLINEAR_H + +#include "interpolator.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/aviation/aircraftsituation.h" +#include +#include + +class QObject; + +namespace BlackMisc +{ + namespace Aviation { class CCallsign; } + namespace Simulation + { + class IRemoteAircraftProvider; + + //! Linear interpolator, calculation inbetween positions + class BLACKMISC_EXPORT CInterpolatorLinear : public IInterpolator + { + public: + //! Constructor + CInterpolatorLinear(BlackMisc::Simulation::IRemoteAircraftProvider *provider, QObject *parent = nullptr) : + IInterpolator(provider, "CInterpolatorLinear", parent) + {} + + // public base class signature + using IInterpolator::getInterpolatedSituation; + + //! \copydoc IInterpolator::getInterpolatedSituation + virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc, const BlackMisc::Simulation::CInterpolationHints &hints, InterpolationStatus &status) const override; + + //! Log category + static QString getLogCategory() { return "swift.interpolatorlinear"; } + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackmisc/simulation/simulation.h b/src/blackmisc/simulation/simulation.h index c73da71eb..198bf4470 100644 --- a/src/blackmisc/simulation/simulation.h +++ b/src/blackmisc/simulation/simulation.h @@ -20,6 +20,7 @@ #include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/distributorlistpreferences.h" #include "blackmisc/simulation/interpolationhints.h" +#include "blackmisc/simulation/interpolationrenderingsetup.h" #include "blackmisc/simulation/modelsettings.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatedaircraftlist.h" diff --git a/src/plugins/simulator/fs9/fs9client.cpp b/src/plugins/simulator/fs9/fs9client.cpp index f8fbb04f4..48624a451 100644 --- a/src/plugins/simulator/fs9/fs9client.cpp +++ b/src/plugins/simulator/fs9/fs9client.cpp @@ -119,7 +119,7 @@ namespace BlackSimPlugin } CFs9Client::CFs9Client(const CCallsign &callsign, const QString &modelName, - BlackMisc::IInterpolator *interpolator, const CTime &updateInterval, QObject *owner) : + BlackMisc::Simulation::IInterpolator *interpolator, const CTime &updateInterval, QObject *owner) : CDirectPlayPeer(owner, callsign), m_updateInterval(updateInterval), m_interpolator(interpolator), m_modelName(modelName) { diff --git a/src/plugins/simulator/fs9/fs9client.h b/src/plugins/simulator/fs9/fs9client.h index 31bc34fb5..150267ce5 100644 --- a/src/plugins/simulator/fs9/fs9client.h +++ b/src/plugins/simulator/fs9/fs9client.h @@ -11,7 +11,7 @@ #define DIRECTPLAY_CLIENT_H #include "directplaypeer.h" -#include "blackmisc/interpolator.h" +#include "blackmisc/simulation/interpolator.h" #include "blackmisc/aviation/aircraftsituation.h" #include "blackmisc/pq/time.h" #include "blackmisc/aviation/callsign.h" @@ -40,7 +40,7 @@ namespace BlackSimPlugin //! Constructor CFs9Client(const BlackMisc::Aviation::CCallsign &callsign, const QString &modelName, - BlackMisc::IInterpolator *interpolator, const BlackMisc::PhysicalQuantities::CTime &updateInterval, + BlackMisc::Simulation::IInterpolator *interpolator, const BlackMisc::PhysicalQuantities::CTime &updateInterval, QObject *owner); //! Destructor @@ -91,7 +91,7 @@ namespace BlackSimPlugin void sendMultiplayerChangePlayerPlane(); BlackMisc::PhysicalQuantities::CTime m_updateInterval; - BlackMisc::IInterpolator *m_interpolator = nullptr; + BlackMisc::Simulation::IInterpolator *m_interpolator = nullptr; QString m_modelName; int m_timerId = 0; diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index f46a8c890..63f26aa9d 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -14,7 +14,7 @@ #include "multiplayerpackets.h" #include "multiplayerpacketparser.h" #include "registermetadata.h" -#include "blackmisc/interpolatorlinear.h" +#include "blackmisc/simulation/interpolatorlinear.h" #include "blackmisc/network/textmessage.h" #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/logmessage.h" diff --git a/src/plugins/simulator/fs9/simulatorfs9.h b/src/plugins/simulator/fs9/simulatorfs9.h index 55a7d8ad4..2247d7ce2 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.h +++ b/src/plugins/simulator/fs9/simulatorfs9.h @@ -18,7 +18,7 @@ #include "../fscommon/simulatorfscommon.h" #include "blackmisc/simulation/simulatorsettings.h" #include "blackcore/simulator.h" -#include "blackmisc/interpolator.h" +#include "blackmisc/simulation/interpolator.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/pixmap.h" diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.h b/src/plugins/simulator/fscommon/simulatorfscommon.h index 5c3e9f84b..8ddfd5a45 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.h +++ b/src/plugins/simulator/fscommon/simulatorfscommon.h @@ -13,7 +13,7 @@ #define BLACKSIMPLUGIN_SIMULATOR_COMMON_H #include "blackcore/simulatorcommon.h" -#include "blackmisc/interpolator.h" +#include "blackmisc/simulation/interpolator.h" #include "blackmisc/simulation/fscommon/aircraftcfgparser.h" #include "fsuipc.h" diff --git a/src/xbus/traffic.cpp b/src/xbus/traffic.cpp index 72c685885..2e2861d73 100644 --- a/src/xbus/traffic.cpp +++ b/src/xbus/traffic.cpp @@ -14,9 +14,9 @@ #endif #include "traffic.h" #include "utils.h" -#include "blackmisc/interpolator.h" -#include "blackmisc/interpolatorlinear.h" +#include "blackmisc/simulation/interpolator.h" #include "blackmisc/simulation/interpolationhints.h" +#include "blackmisc/simulation/interpolatorlinear.h" #include "blackmisc/simulation/remoteaircraftproviderdummy.h" #include "XPMPMultiplayer.h" #include @@ -44,7 +44,7 @@ namespace XBus CTraffic::CTraffic(QObject *parent) : QObject(parent), - m_interpolator(new BlackMisc::CInterpolatorLinear(new BlackMisc::Simulation::CRemoteAircraftProviderDummy(this), this)) + m_interpolator(new BlackMisc::Simulation::CInterpolatorLinear(new BlackMisc::Simulation::CRemoteAircraftProviderDummy(this), this)) { } @@ -305,7 +305,7 @@ namespace XBus { case xpmpDataType_Position: { - BlackMisc::IInterpolator::InterpolationStatus status; + BlackMisc::Simulation::IInterpolator::InterpolationStatus status; const BlackMisc::Simulation::CInterpolationHints hints; auto situation = m_interpolator->getInterpolatedSituation(plane->situations, -1, hints, status); if (! status.didInterpolationSucceed()) { return xpmpData_Unavailable; } diff --git a/src/xbus/traffic.h b/src/xbus/traffic.h index 1bea1f933..b775e8ddf 100644 --- a/src/xbus/traffic.h +++ b/src/xbus/traffic.h @@ -25,11 +25,9 @@ #define XBUS_TRAFFIC_OBJECTPATH "/xbus/traffic" //! \endcond -namespace BlackMisc { class IInterpolator; } - +namespace BlackMisc { namespace Simulation { class IInterpolator; } } namespace XBus { - /*! * XBus service object for traffic aircraft which is accessible through DBus */ @@ -144,9 +142,8 @@ namespace XBus return static_cast(self)->getPlaneData(id, dataType, io_data); } - BlackMisc::IInterpolator *m_interpolator = nullptr; + BlackMisc::Simulation::IInterpolator *m_interpolator = nullptr; }; - } #endif // guard diff --git a/tests/blackmisc/testinterpolator.cpp b/tests/blackmisc/testinterpolator.cpp index 17bbbaa92..ccb1b34f4 100644 --- a/tests/blackmisc/testinterpolator.cpp +++ b/tests/blackmisc/testinterpolator.cpp @@ -27,8 +27,8 @@ #include "blackmisc/geo/coordinategeodetic.h" #include "blackmisc/geo/latitude.h" #include "blackmisc/geo/longitude.h" -#include "blackmisc/interpolator.h" -#include "blackmisc/interpolatorlinear.h" +#include "blackmisc/simulation/interpolator.h" +#include "blackmisc/simulation/interpolatorlinear.h" #include "blackmisc/pq/angle.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/physicalquantity.h"