mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +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
|
* 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_distanceToPlane = Geo::greatCircleDistance(this->m_position, position);
|
||||||
|
this->m_bearingToPlane = Geo::initialBearing(this->m_position, position);
|
||||||
return this->m_distanceToPlane;
|
return this->m_distanceToPlane;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +147,11 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
QVariant CAirport::propertyByIndex(int index) const
|
QVariant CAirport::propertyByIndex(int index) const
|
||||||
{
|
{
|
||||||
|
if (index > static_cast<int>(CAirport::IndexBearing))
|
||||||
|
{
|
||||||
|
return this->m_position.propertyByIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
switch (index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case IndexIcao:
|
case IndexIcao:
|
||||||
@@ -155,8 +161,12 @@ namespace BlackMisc
|
|||||||
case IndexDescriptiveName:
|
case IndexDescriptiveName:
|
||||||
return QVariant(this->m_descriptiveName);
|
return QVariant(this->m_descriptiveName);
|
||||||
case IndexPosition:
|
case IndexPosition:
|
||||||
return this->getPosition().toQVariant();
|
return this->m_position.toQVariant();
|
||||||
case IndexDistanceToPlane:
|
case IndexElevation:
|
||||||
|
return this->getElevation().toQVariant();
|
||||||
|
case IndexBearing:
|
||||||
|
return this->m_bearingToPlane.toQVariant();
|
||||||
|
case IndexDistance:
|
||||||
return this->m_distanceToPlane.toQVariant();
|
return this->m_distanceToPlane.toQVariant();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -172,6 +182,11 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CAirport::setPropertyByIndex(const QVariant &variant, int index)
|
void CAirport::setPropertyByIndex(const QVariant &variant, int index)
|
||||||
{
|
{
|
||||||
|
if (index >= static_cast<int>(CAirport::IndexBearing))
|
||||||
|
{
|
||||||
|
this->m_position.setPropertyByIndex(variant, index);
|
||||||
|
}
|
||||||
|
|
||||||
switch (index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case IndexIcao:
|
case IndexIcao:
|
||||||
@@ -186,6 +201,12 @@ namespace BlackMisc
|
|||||||
case IndexPosition:
|
case IndexPosition:
|
||||||
this->setPosition(variant.value<CCoordinateGeodetic>());
|
this->setPosition(variant.value<CCoordinateGeodetic>());
|
||||||
break;
|
break;
|
||||||
|
case IndexBearing:
|
||||||
|
this->setBearingToPlane(variant.value<CAngle>());
|
||||||
|
break;
|
||||||
|
case IndexDistance:
|
||||||
|
this->setDistanceToPlane(variant.value<CLength>());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Q_ASSERT_X(false, "CAirport", "index unknown (setter)");
|
Q_ASSERT_X(false, "CAirport", "index unknown (setter)");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ namespace BlackMisc
|
|||||||
IndexIcaoAsString,
|
IndexIcaoAsString,
|
||||||
IndexDescriptiveName,
|
IndexDescriptiveName,
|
||||||
IndexPosition,
|
IndexPosition,
|
||||||
IndexDistanceToPlane
|
IndexElevation,
|
||||||
|
IndexDistance,
|
||||||
|
IndexBearing
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Default constructor.
|
//! Default constructor.
|
||||||
@@ -71,24 +73,36 @@ namespace BlackMisc
|
|||||||
//! Set position
|
//! Set position
|
||||||
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = 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
|
//! Get the distance to own plane
|
||||||
const BlackMisc::PhysicalQuantities::CLength &getDistanceToPlane() const { return m_distanceToPlane; }
|
const BlackMisc::PhysicalQuantities::CLength &getDistanceToPlane() const { return m_distanceToPlane; }
|
||||||
|
|
||||||
//! Set distance to own plane
|
//! Set distance to own plane
|
||||||
void setDistanceToPlane(const BlackMisc::PhysicalQuantities::CLength &distance) { this->m_distanceToPlane = distance; }
|
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?
|
//! Valid distance?
|
||||||
bool hasValidDistance() const { return !this->m_distanceToPlane.isNull();}
|
bool hasValidDistance() const { return !this->m_distanceToPlane.isNull();}
|
||||||
|
|
||||||
|
//! Valid bearing?
|
||||||
|
bool hasValidBearing() const { return !this->m_bearingToPlane.isNull();}
|
||||||
|
|
||||||
//! Valid ICAO code
|
//! Valid ICAO code
|
||||||
bool hasValidIcaoCode() const { return !this->getIcao().isEmpty(); }
|
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
|
* \param position other position
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceAndBearingToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position);
|
||||||
|
|
||||||
//! \copydoc ICoordinateGeodetic::latitude
|
//! \copydoc ICoordinateGeodetic::latitude
|
||||||
virtual const BlackMisc::Geo::CLatitude &latitude() const override
|
virtual const BlackMisc::Geo::CLatitude &latitude() const override
|
||||||
@@ -147,6 +161,7 @@ namespace BlackMisc
|
|||||||
CAirportIcao m_icao;
|
CAirportIcao m_icao;
|
||||||
QString m_descriptiveName;
|
QString m_descriptiveName;
|
||||||
BlackMisc::Geo::CCoordinateGeodetic m_position;
|
BlackMisc::Geo::CCoordinateGeodetic m_position;
|
||||||
|
BlackMisc::PhysicalQuantities::CAngle m_bearingToPlane;
|
||||||
BlackMisc::PhysicalQuantities::CLength m_distanceToPlane; // make mutable ?
|
BlackMisc::PhysicalQuantities::CLength m_distanceToPlane; // make mutable ?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CAirportList::replaceOrAddByIcao(const CAirport &addedOrReplacedAirport)
|
void CAirportList::replaceOrAddByIcao(const CAirport &addedOrReplacedAirport)
|
||||||
{
|
{
|
||||||
Q_ASSERT(addedOrReplacedAirport.hasValidIcaoCode());
|
if (!addedOrReplacedAirport.hasValidIcaoCode()) return; // ignore invalid airport
|
||||||
this->replaceOrAdd(&CAirport::getIcao, addedOrReplacedAirport.getIcao(), addedOrReplacedAirport);
|
this->replaceOrAdd(&CAirport::getIcao, addedOrReplacedAirport.getIcao(), addedOrReplacedAirport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,28 +75,28 @@ namespace BlackMisc
|
|||||||
/*
|
/*
|
||||||
* Distances to own plane
|
* 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)
|
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;
|
CLength d;
|
||||||
for (CAirportList::iterator i = begin(); i != end();)
|
for (CAirportList::iterator i = begin(); i != end();)
|
||||||
{
|
{
|
||||||
if (updateDistance)
|
if (updateDistance)
|
||||||
{
|
{
|
||||||
d = i->calculcateDistanceToPlane(position);
|
d = i->calculcateDistanceAndBearingToPlane(position);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d = i->greatCircleDistance(position);
|
d = i->greatCircleDistance(position);
|
||||||
}
|
}
|
||||||
if (distance > d)
|
if (maxDistance < d)
|
||||||
{
|
{
|
||||||
i = this->erase(i);
|
i = this->erase(i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ namespace BlackMisc
|
|||||||
CAirportList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const;
|
CAirportList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const;
|
||||||
|
|
||||||
//! Update distances to coordinate, usually own aircraft's position
|
//! 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
|
//! 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
|
//! Register metadata
|
||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
|
|||||||
Reference in New Issue
Block a user