mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #291, improved airport class
* supports bearing (to own plane) * elevation * Fixed Property index
This commit is contained in:
@@ -135,9 +135,10 @@ namespace BlackMisc
|
||||
/*
|
||||
* Distance to planne
|
||||
*/
|
||||
const CLength &CAirport::calculcateDistanceToPlane(const CCoordinateGeodetic &position)
|
||||
const CLength &CAirport::calculcateDistanceAndBearingToPlane(const CCoordinateGeodetic &position)
|
||||
{
|
||||
this->m_distanceToPlane = Geo::greatCircleDistance(this->m_position, position);
|
||||
this->m_bearingToPlane = Geo::initialBearing(this->m_position, position);
|
||||
return this->m_distanceToPlane;
|
||||
}
|
||||
|
||||
@@ -146,6 +147,11 @@ namespace BlackMisc
|
||||
*/
|
||||
QVariant CAirport::propertyByIndex(int index) const
|
||||
{
|
||||
if (index > static_cast<int>(CAirport::IndexBearing))
|
||||
{
|
||||
return this->m_position.propertyByIndex(index);
|
||||
}
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case IndexIcao:
|
||||
@@ -155,8 +161,12 @@ namespace BlackMisc
|
||||
case IndexDescriptiveName:
|
||||
return QVariant(this->m_descriptiveName);
|
||||
case IndexPosition:
|
||||
return this->getPosition().toQVariant();
|
||||
case IndexDistanceToPlane:
|
||||
return this->m_position.toQVariant();
|
||||
case IndexElevation:
|
||||
return this->getElevation().toQVariant();
|
||||
case IndexBearing:
|
||||
return this->m_bearingToPlane.toQVariant();
|
||||
case IndexDistance:
|
||||
return this->m_distanceToPlane.toQVariant();
|
||||
default:
|
||||
break;
|
||||
@@ -172,6 +182,11 @@ namespace BlackMisc
|
||||
*/
|
||||
void CAirport::setPropertyByIndex(const QVariant &variant, int index)
|
||||
{
|
||||
if (index >= static_cast<int>(CAirport::IndexBearing))
|
||||
{
|
||||
this->m_position.setPropertyByIndex(variant, index);
|
||||
}
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case IndexIcao:
|
||||
@@ -186,6 +201,12 @@ namespace BlackMisc
|
||||
case IndexPosition:
|
||||
this->setPosition(variant.value<CCoordinateGeodetic>());
|
||||
break;
|
||||
case IndexBearing:
|
||||
this->setBearingToPlane(variant.value<CAngle>());
|
||||
break;
|
||||
case IndexDistance:
|
||||
this->setDistanceToPlane(variant.value<CLength>());
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT_X(false, "CAirport", "index unknown (setter)");
|
||||
break;
|
||||
|
||||
@@ -29,7 +29,9 @@ namespace BlackMisc
|
||||
IndexIcaoAsString,
|
||||
IndexDescriptiveName,
|
||||
IndexPosition,
|
||||
IndexDistanceToPlane
|
||||
IndexElevation,
|
||||
IndexDistance,
|
||||
IndexBearing
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
@@ -71,24 +73,36 @@ namespace BlackMisc
|
||||
//! Set position
|
||||
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
|
||||
|
||||
//! Elevation
|
||||
const BlackMisc::PhysicalQuantities::CLength getElevation() const { return this->getPosition().geodeticHeight(); }
|
||||
|
||||
//! Get the distance to own plane
|
||||
const BlackMisc::PhysicalQuantities::CLength &getDistanceToPlane() const { return m_distanceToPlane; }
|
||||
|
||||
//! Set distance to own plane
|
||||
void setDistanceToPlane(const BlackMisc::PhysicalQuantities::CLength &distance) { this->m_distanceToPlane = distance; }
|
||||
|
||||
//! Get the bearing to own plane
|
||||
const BlackMisc::PhysicalQuantities::CAngle &getBearingToPlane() const { return m_bearingToPlane; }
|
||||
|
||||
//! Set bearing to own plane
|
||||
void setBearingToPlane(const BlackMisc::PhysicalQuantities::CAngle &angle) { this->m_bearingToPlane = angle; }
|
||||
|
||||
//! Valid distance?
|
||||
bool hasValidDistance() const { return !this->m_distanceToPlane.isNull();}
|
||||
|
||||
//! Valid bearing?
|
||||
bool hasValidBearing() const { return !this->m_bearingToPlane.isNull();}
|
||||
|
||||
//! Valid ICAO code
|
||||
bool hasValidIcaoCode() const { return !this->getIcao().isEmpty(); }
|
||||
|
||||
/*!
|
||||
* Calculcate distance to plane, set it, and also return it
|
||||
* Calculcate distance and bearing to plane, set it, and return distance
|
||||
* \param position other position
|
||||
* \return
|
||||
*/
|
||||
const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||
const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceAndBearingToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||
|
||||
//! \copydoc ICoordinateGeodetic::latitude
|
||||
virtual const BlackMisc::Geo::CLatitude &latitude() const override
|
||||
@@ -147,6 +161,7 @@ namespace BlackMisc
|
||||
CAirportIcao m_icao;
|
||||
QString m_descriptiveName;
|
||||
BlackMisc::Geo::CCoordinateGeodetic m_position;
|
||||
BlackMisc::PhysicalQuantities::CAngle m_bearingToPlane;
|
||||
BlackMisc::PhysicalQuantities::CLength m_distanceToPlane; // make mutable ?
|
||||
};
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace BlackMisc
|
||||
|
||||
void CAirportList::replaceOrAddByIcao(const CAirport &addedOrReplacedAirport)
|
||||
{
|
||||
Q_ASSERT(addedOrReplacedAirport.hasValidIcaoCode());
|
||||
if (!addedOrReplacedAirport.hasValidIcaoCode()) return; // ignore invalid airport
|
||||
this->replaceOrAdd(&CAirport::getIcao, addedOrReplacedAirport.getIcao(), addedOrReplacedAirport);
|
||||
}
|
||||
|
||||
@@ -75,28 +75,28 @@ namespace BlackMisc
|
||||
/*
|
||||
* Distances to own plane
|
||||
*/
|
||||
void CAirportList::calculateDistancesToPlane(const Geo::CCoordinateGeodetic &position)
|
||||
void CAirportList::calculcateDistanceAndBearingToPlane(const Geo::CCoordinateGeodetic &position)
|
||||
{
|
||||
std::for_each(this->begin(), this->end(), [ & ](CAirport & airport)
|
||||
{
|
||||
airport.calculcateDistanceToPlane(position);
|
||||
airport.calculcateDistanceAndBearingToPlane(position);
|
||||
});
|
||||
}
|
||||
|
||||
void CAirportList::removeIfOutsideRange(const Geo::CCoordinateGeodetic &position, const CLength &distance, bool updateDistance)
|
||||
void CAirportList::removeIfOutsideRange(const Geo::CCoordinateGeodetic &position, const CLength &maxDistance, bool updateDistance)
|
||||
{
|
||||
CLength d;
|
||||
for (CAirportList::iterator i = begin(); i != end();)
|
||||
{
|
||||
if (updateDistance)
|
||||
{
|
||||
d = i->calculcateDistanceToPlane(position);
|
||||
d = i->calculcateDistanceAndBearingToPlane(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
d = i->greatCircleDistance(position);
|
||||
}
|
||||
if (distance > d)
|
||||
if (maxDistance < d)
|
||||
{
|
||||
i = this->erase(i);
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace BlackMisc
|
||||
CAirportList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const;
|
||||
|
||||
//! Update distances to coordinate, usually own aircraft's position
|
||||
void calculateDistancesToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||
void calculcateDistanceAndBearingToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||
|
||||
//! Remove if outside given radius
|
||||
void removeIfOutsideRange(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &distance, bool updateDistance);
|
||||
void removeIfOutsideRange(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &maxDistance, bool updateDistance);
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
Reference in New Issue
Block a user