Ref T259, Ref T243 use elevation plane for altitude

general idea: by using the plane class, we can set a elevation and then find a better one

* use elevation plane in situation
* adjusted depending classes such as hints, lists
* using setGroundElevationChecked so elevation can be gradually improved
This commit is contained in:
Klaus Basan
2018-03-07 01:53:10 +01:00
parent 0c877e1575
commit 83b6578e69
16 changed files with 307 additions and 110 deletions

View File

@@ -30,10 +30,41 @@ namespace BlackMisc
m_isVtol(isVtolAircraft), m_hasParts(hasParts), m_logInterpolation(log)
{ }
const CElevationPlane &CInterpolationHints::getElevationPlane(ICoordinateGeodetic &reference, const CLength &radius, SituationLog *log) const
{
if (m_elevationPlane.isNull())
{
if (log)
{
static const QString lm("By provider (no valid plane)");
log->elevationInfo = lm;
}
return CElevationPlane::null();
}
const CLength d = reference.calculateGreatCircleDistance(m_elevationPlane);
if (d <= radius)
{
if (log)
{
static const QString lm("Using elevation plane, distance: %1");
log->elevationInfo = lm.arg(d.valueRoundedWithUnit(CLengthUnit::m(), 1));
}
return m_elevationPlane;
}
else
{
if (log)
{
static const QString lm("Invalid elevation plane, distance: %1");
log->elevationInfo = lm.arg(d.valueRoundedWithUnit(CLengthUnit::m(), 1));
}
return CElevationPlane::null();
}
}
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, bool useProvider, bool forceProvider, SituationLog *log) const
{
static const CLength null = CLength(0, CLengthUnit::nullUnit());
return this->getGroundElevation(situation, null, useProvider, forceProvider, log);
return this->getGroundElevation(situation, CLength::null(), useProvider, forceProvider, log);
}
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, const CLength &validRadius, bool useProvider, bool forceProvider, SituationLog *log) const
@@ -46,6 +77,7 @@ namespace BlackMisc
static const QString lm("By provider (forced)");
log->elevationInfo = lm;
}
Q_ASSERT_X(false, Q_FUNC_INFO, "Elevation provider must no longer be used");
return m_elevationProvider(situation);
}
@@ -80,6 +112,16 @@ namespace BlackMisc
return CAltitude::null();
}
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, const CLength &validRadius, SituationLog *log) const
{
return this->getGroundElevation(situation, validRadius, false, false, log);
}
CAltitude CInterpolationHints::getGroundElevation(const CAircraftSituation &situation, SituationLog *log) const
{
return this->getGroundElevation(situation, CLength::null(), log);
}
void CInterpolationHints::resetElevationPlane()
{
m_elevationPlane = CElevationPlane();
@@ -87,7 +129,7 @@ namespace BlackMisc
bool CInterpolationHints::isWithinRange(const Geo::ICoordinateGeodetic &coordinate) const
{
if (m_elevationPlane.isNull()) return false;
if (m_elevationPlane.isNull()) { return false; }
return m_elevationPlane.isWithinRange(coordinate);
}

View File

@@ -48,6 +48,9 @@ namespace BlackMisc
//! Get elevation plane
const Geo::CElevationPlane &getElevationPlane() const { return m_elevationPlane;}
//! Get elevation plane
const Geo::CElevationPlane &getElevationPlane(Geo::ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &radius, SituationLog *log = nullptr) const;
//! Set elevation
//! \remark used to store a ground elevation and use it as well for nearby situatons
void setElevationPlane(const Geo::CElevationPlane &elevation) { m_elevationPlane = elevation; }
@@ -55,6 +58,8 @@ namespace BlackMisc
//! Elevation plane set to null
void resetElevationPlane();
private:
//! \todo KB 2018-03 ground flag refactoring
//! Get elevation from CInterpolationHints::getElevationProvider or CInterpolationHints::getElevation
//! \remark avoid unnecessary calls on XPlane (calling elevation provider)
//! \param situation where to check
@@ -63,12 +68,23 @@ namespace BlackMisc
//! \param log optional chance to write info about elevation
//! \see setElevationProvider
//! \see setElevationPlane
//! \deprecated
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, bool useProvider, bool forceProvider = false, SituationLog *log = nullptr) const;
//! Get elevation from CInterpolationHints::getElevationProvider or CInterpolationHints::getElevation
//! \remark if validRadius is >= Geo::CElevationPlane::radius use validRadius
//! \deprecated
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, const PhysicalQuantities::CLength &validRadius, bool useProvider, bool forceProvider = false, SituationLog *log = nullptr) const;
//! Get ground elevation by using the elevation plane
//! \deprecated
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, const PhysicalQuantities::CLength &validRadius, SituationLog *log = nullptr) const;
//! Get ground elevation by using the elevation plane
//! \deprecated
Aviation::CAltitude getGroundElevation(const Aviation::CAircraftSituation &situation, SituationLog *log = nullptr) const;
public:
//! Check if elevation is within radius and can be used
bool isWithinRange(const Geo::ICoordinateGeodetic &coordinate) const;
@@ -110,12 +126,14 @@ namespace BlackMisc
using ElevationProvider = std::function<Aviation::CAltitude(const Aviation::CAircraftSituation &)>;
//! Has elevation provider?
//! \deprecated
bool hasElevationProvider() const;
//! Set function object that can obtain ground elevation
//! \remark either a provider can be used or an elevation plan can be set
//! \see setElevationPlane
//! \see getGroundElevation
//! \deprecated
void setElevationProvider(const ElevationProvider &ep) { m_elevationProvider = ep; }
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex

View File

@@ -74,12 +74,14 @@ namespace BlackMisc
currentSituation.setCallsign(m_callsign);
}
//! \todo KB 2018-03 ground flag refactoring
// Update current position by hints' elevation
// * for XP provided by hints.getElevationProvider at current position
// * for FSX/P3D provided as hints.getElevation which is set to current position of remote aircraft in simulator
// * As XP uses lazy init we will call getGroundElevation only when needed
// * default here via getElevationPlane
CAltitude currentGroundElevation(hints.getGroundElevation(currentSituation, currentSituation.getDistancePerTime(1000), true, false, logP));
// CAltitude currentGroundElevation(hints.getGroundElevation(currentSituation, currentSituation.getDistancePerTime(1000), true, false, logP));
const CElevationPlane currentGroundElevation = hints.getElevationPlane(currentSituation, currentSituation.getDistancePerTime(1000), logP);
currentSituation.setGroundElevation(currentGroundElevation); // set as default
// data, split situations by time
@@ -410,15 +412,6 @@ namespace BlackMisc
return IRemoteAircraftProvider::MaxSituationsPerCallsign;
}
template <typename Derived>
void CInterpolator<Derived>::setGroundElevationFromHint(const CInterpolationHints &hints, CAircraftSituation &situation, bool override)
{
if (!override && situation.hasGroundElevation()) { return; }
const CAltitude elevation = hints.getGroundElevation(situation, false);
if (elevation.isNull()) { return; }
situation.setGroundElevation(elevation);
}
template <typename Derived>
void CInterpolator<Derived>::setGroundFlagFromInterpolator(const CInterpolationHints &hints, double groundFactor, CAircraftSituation &situation)
{

View File

@@ -112,9 +112,6 @@ namespace BlackMisc
//! Constructor
CInterpolator(const QString &objectName, const Aviation::CCallsign &callsign, QObject *parent);
//! Set the ground elevation from hints
static void setGroundElevationFromHint(const CInterpolationHints &hints, Aviation::CAircraftSituation &situation, bool override = true);
//! Set on ground flag
static void setGroundFlagFromInterpolator(const CInterpolationHints &hints, double groundFactor, Aviation::CAircraftSituation &situation);

View File

@@ -120,8 +120,8 @@ namespace BlackMisc
// do not call for XP (lazy init)
if (!hints.hasElevationProvider())
{
CInterpolator::setGroundElevationFromHint(hints, oldSituation, false);
CInterpolator::setGroundElevationFromHint(hints, newSituation, false);
oldSituation.setGroundElevationChecked(hints.getElevationPlane());
newSituation.setGroundElevationChecked(hints.getElevationPlane());
}
CAircraftSituation currentSituation(oldSituation); // also sets ground elevation if available

View File

@@ -213,7 +213,10 @@ namespace BlackMisc
const BlackMisc::Aviation::CAltitude &getGroundElevation() const { return m_situation.getGroundElevation(); }
//! \copydoc BlackMisc::Aviation::CAircraftSituation::setGroundElevation
void setGroundElevation(const BlackMisc::Aviation::CAltitude &elevation) { m_situation.setGroundElevation(elevation); }
void setGroundElevation(const Geo::CElevationPlane &elevation) { m_situation.setGroundElevation(elevation); }
//! \copydoc BlackMisc::Aviation::CAircraftSituation::setGroundElevation
void setGroundElevationChecked(const Geo::CElevationPlane &elevation) { m_situation.setGroundElevationChecked(elevation); }
//! \copydoc BlackMisc::Aviation::CAircraftSituation::getHeading
const BlackMisc::Aviation::CHeading &getHeading() const { return m_situation.getHeading(); }

View File

@@ -20,8 +20,8 @@
#include <QString>
#include <tuple>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Network;
@@ -160,13 +160,13 @@ namespace BlackMisc
return c;
}
int CSimulatedAircraftList::setGroundElevation(const CCallsign &callsign, const CAltitude &elevation, bool onlyFirst)
int CSimulatedAircraftList::setGroundElevationChecked(const CCallsign &callsign, const CElevationPlane &elevation, bool onlyFirst)
{
int c = 0;
for (CSimulatedAircraft &aircraft : (*this))
{
if (aircraft.getCallsign() != callsign) { continue; }
aircraft.setGroundElevation(elevation);
aircraft.setGroundElevationChecked(elevation);
c++;
if (onlyFirst) break;
}
@@ -227,7 +227,7 @@ namespace BlackMisc
return c;
}
int CSimulatedAircraftList::countAircraftPartsSyncronized() const
int CSimulatedAircraftList::countAircraftPartsSynchronized() const
{
int c = 0;
for (const CSimulatedAircraft &aircraft : (*this))

View File

@@ -12,16 +12,15 @@
#ifndef BLACKMISC_SIMULATION_SIMULATEDNAIRCRAFTLIST_H
#define BLACKMISC_SIMULATION_SIMULATEDNAIRCRAFTLIST_H
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/aviation/callsignobjectlist.h"
#include "blackmisc/aviation/callsignset.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/collection.h"
#include "blackmisc/geo/geoobjectlist.h"
#include "blackmisc/network/userlist.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/variant.h"
#include <QMetaType>
namespace BlackMisc
@@ -92,7 +91,7 @@ namespace BlackMisc
int setAircraftSituation(const Aviation::CCallsign &callsign, const Aviation::CAircraftSituation &situation, bool onlyFirst = true);
//! Set ground elevation
int setGroundElevation(const Aviation::CCallsign &callsign, const Aviation::CAltitude &elevation, bool onlyFirst = true);
int setGroundElevationChecked(const Aviation::CCallsign &callsign, const Geo::CElevationPlane &elevation, bool onlyFirst = true);
//! Enabled?
bool isEnabled(const Aviation::CCallsign &callsign) const;
@@ -110,7 +109,7 @@ namespace BlackMisc
int countRendered() const;
//! Number of aircraft with parts
int countAircraftPartsSyncronized() const;
int countAircraftPartsSynchronized() const;
};
} //namespace
} // namespace