mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
refs #840, class combining all hints for the interpolator
This commit is contained in:
committed by
Mathew Sutcliffe
parent
70aee605cb
commit
e1b472490f
91
src/blackmisc/simulation/interpolationhints.cpp
Normal file
91
src/blackmisc/simulation/interpolationhints.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/* 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 "interpolationhints.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CInterpolationHints::CInterpolationHints() { }
|
||||
|
||||
CInterpolationHints::CInterpolationHints(bool isVtolAircraft) : m_isVtol(isVtolAircraft)
|
||||
{ }
|
||||
|
||||
void CInterpolationHints::resetElevation()
|
||||
{
|
||||
m_elevation = CElevationPlane();
|
||||
}
|
||||
|
||||
bool CInterpolationHints::isWithinRange(const Geo::ICoordinateGeodetic &coordinate) const
|
||||
{
|
||||
if (m_elevation.isNull()) return false;
|
||||
return m_elevation.isWithinRange(coordinate);
|
||||
}
|
||||
|
||||
CVariant CInterpolationHints::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCenterOfGravity:
|
||||
return this->m_cgAboveGround.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexElevationPlane:
|
||||
return this->m_elevation.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIsVtolAircraft:
|
||||
return CVariant::fromValue(m_isVtol);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CInterpolationHints::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CInterpolationHints>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCenterOfGravity:
|
||||
this->m_cgAboveGround.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexElevationPlane:
|
||||
this->m_elevation.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexIsVtolAircraft:
|
||||
this->m_isVtol = variant.toBool();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CInterpolationHints::convertToQString(bool i18n) const
|
||||
{
|
||||
static const QString s("%1 %2");
|
||||
return s.arg(m_elevation.toQString(i18n), m_cgAboveGround.toQString(i18n));
|
||||
}
|
||||
|
||||
QString CInterpolationHints::debugInfo(const Geo::CElevationPlane &deltaElevation) const
|
||||
{
|
||||
static const QString s("Lat: %1 Lng: %2 Elv: %3");
|
||||
if (m_elevation.isNull() || deltaElevation.isNull()) return "null";
|
||||
return s.arg(
|
||||
(deltaElevation.latitude() - m_elevation.latitude()).valueRoundedWithUnit(CAngleUnit::deg(), 10),
|
||||
(deltaElevation.longitude() - m_elevation.longitude()).valueRoundedWithUnit(CAngleUnit::deg(), 10),
|
||||
(deltaElevation.geodeticHeight() - m_elevation.geodeticHeight()).valueRoundedWithUnit(CLengthUnit::ft(), 2)
|
||||
);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
95
src/blackmisc/simulation/interpolationhints.h
Normal file
95
src/blackmisc/simulation/interpolationhints.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/* 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_INTERPOLATIONHINTS_H
|
||||
#define BLACKMISC_SIMULATION_INTERPOLATIONHINTS_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/geo/elevationplane.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
//! Hints for interpolator such as ground elevation
|
||||
class BLACKMISC_EXPORT CInterpolationHints :
|
||||
public BlackMisc::CValueObject<CInterpolationHints>
|
||||
{
|
||||
public:
|
||||
//! Property indexes
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexElevationPlane = CPropertyIndex::GlobalIndexCInterpolationHints,
|
||||
IndexCenterOfGravity,
|
||||
IndexIsVtolAircraft
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CInterpolationHints();
|
||||
|
||||
//! Constructor
|
||||
CInterpolationHints(bool isVtolAircraft);
|
||||
|
||||
//! Get elevation
|
||||
const BlackMisc::Geo::CElevationPlane &getElevation() const { return m_elevation;}
|
||||
|
||||
//! Set elevation
|
||||
void setElevation(const BlackMisc::Geo::CElevationPlane &elevation) { m_elevation = elevation; }
|
||||
|
||||
//! Elevation set to null
|
||||
void resetElevation();
|
||||
|
||||
//! Check if elevation is within radius and can be used
|
||||
bool isWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const;
|
||||
|
||||
//! Get CG above ground
|
||||
const BlackMisc::PhysicalQuantities::CLength &getCGAboveGround() const { return m_cgAboveGround;}
|
||||
|
||||
//! Set CG above ground
|
||||
void setCGAboveGround(const BlackMisc::PhysicalQuantities::CLength &cgAboveGround) { m_cgAboveGround = cgAboveGround; }
|
||||
|
||||
//! VTOL aircraft?
|
||||
bool isVtolAircraft() const { return m_isVtol; }
|
||||
|
||||
//! VTOL aircraft
|
||||
void setVtolAircraft(bool vtol) { m_isVtol = vtol; }
|
||||
|
||||
//! \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);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! For debugging
|
||||
QString debugInfo(const BlackMisc::Geo::CElevationPlane &deltaElevation) const;
|
||||
|
||||
private:
|
||||
bool m_isVtol = false; //!< VTOL aircraft?
|
||||
BlackMisc::Geo::CElevationPlane m_elevation; //! aircraft's elevation if available
|
||||
BlackMisc::PhysicalQuantities::CLength m_cgAboveGround { 0, nullptr }; //!< center of gravity above ground
|
||||
|
||||
BLACK_METACLASS(
|
||||
CInterpolationHints,
|
||||
BLACK_METAMEMBER(isVtol),
|
||||
BLACK_METAMEMBER(elevation),
|
||||
BLACK_METAMEMBER(cgAboveGround)
|
||||
);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CInterpolationHints)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user