Send distance if own aircraft has been moved

This commit is contained in:
Klaus Basan
2020-04-16 23:46:40 +02:00
committed by Mat Sutcliffe
parent 8278a7d5e6
commit 668659248e
7 changed files with 32 additions and 13 deletions

View File

@@ -104,7 +104,7 @@ namespace BlackCore
void changedPilot(const BlackMisc::Network::CUser &pilot); void changedPilot(const BlackMisc::Network::CUser &pilot);
//! Aircraft has been moved from one location to another (changed scenery) //! Aircraft has been moved from one location to another (changed scenery)
void movedAircraft(); void movedAircraft(const BlackMisc::PhysicalQuantities::CLength &distance);
//! Just airborne //! Just airborne
void isTakingOff(); void isTakingOff();

View File

@@ -193,16 +193,20 @@ namespace BlackCore
// using copy to minimize lock time // using copy to minimize lock time
// 500km/h => 1sec: 0.1388 km // 500km/h => 1sec: 0.1388 km
// we check if there are situation for own aircraft outside the max.distance
static const CLength maxDistance(25, CLengthUnit::km()); static const CLength maxDistance(25, CLengthUnit::km());
const CAircraftSituation latest = situations.front();
const bool jumpDetected = situations.containsObjectOutsideRange(situations.front(), maxDistance); const bool jumpDetected = situations.containsObjectOutsideRange(situations.front(), maxDistance);
if (jumpDetected) if (jumpDetected)
{ {
const CAircraftSituationList ownDistances = situations.findFarthest(1, latest);
const CLength distance = ownDistances.front().calculateGreatCircleDistance(latest);
{ {
QWriteLocker wl(&m_lockAircraft); QWriteLocker wl(&m_lockAircraft);
m_situationHistory.clear(); m_situationHistory.clear();
} }
emit this->movedAircraft(); emit this->movedAircraft(distance);
} }
else else
{ {

View File

@@ -51,7 +51,7 @@ namespace BlackCore
"changedPilot", this, SIGNAL(changedPilot(BlackMisc::Network::CUser))); "changedPilot", this, SIGNAL(changedPilot(BlackMisc::Network::CUser)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(),
"movedAircraft", this, SIGNAL(movedAircraft())); "movedAircraft", this, SIGNAL(movedAircraft(BlackMisc::PhysicalQuantities::CLength)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(),
"isTakingOff", this, SIGNAL(isTakingOff())); "isTakingOff", this, SIGNAL(isTakingOff()));
@@ -61,7 +61,7 @@ namespace BlackCore
Q_ASSERT(s); Q_ASSERT(s);
this->relayBaseClassSignals(serviceName, connection, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName()); this->relayBaseClassSignals(serviceName, connection, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName());
Q_UNUSED(s); Q_UNUSED(s)
} }
void CContextOwnAircraftProxy::unitTestRelaySignals() void CContextOwnAircraftProxy::unitTestRelaySignals()
@@ -69,7 +69,7 @@ namespace BlackCore
// connect signals, asserts when failures // connect signals, asserts when failures
QDBusConnection con = QDBusConnection::sessionBus(); QDBusConnection con = QDBusConnection::sessionBus();
CContextOwnAircraftProxy c(CDBusServer::coreServiceName(), con, CCoreFacadeConfig::Remote, nullptr); CContextOwnAircraftProxy c(CDBusServer::coreServiceName(), con, CCoreFacadeConfig::Remote, nullptr);
Q_UNUSED(c); Q_UNUSED(c)
} }
BlackMisc::Simulation::CSimulatedAircraft CContextOwnAircraftProxy::getOwnAircraft() const BlackMisc::Simulation::CSimulatedAircraft CContextOwnAircraftProxy::getOwnAircraft() const

View File

@@ -57,11 +57,11 @@ namespace BlackGui
ui->tvp_AircraftInRange->setAircraftMode(CSimulatedAircraftListModel::NetworkMode); ui->tvp_AircraftInRange->setAircraftMode(CSimulatedAircraftListModel::NetworkMode);
ui->tvp_AircraftInRange->configureMenu(true, true, false, true, true, true); ui->tvp_AircraftInRange->configureMenu(true, true, false, true, true, true);
connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::modelDataChangedDigest, this, &CAircraftComponent::onRowCountChanged); connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::modelDataChangedDigest, this, &CAircraftComponent::onRowCountChanged);
connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestTextMessageWidget, this, &CAircraftComponent::requestTextMessageWidget); connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestTextMessageWidget, this, &CAircraftComponent::requestTextMessageWidget);
connect(ui->tvp_AirportsInRange, &CSimulatedAircraftView::modelDataChangedDigest, this, &CAircraftComponent::onRowCountChanged); connect(ui->tvp_AirportsInRange, &CSimulatedAircraftView::modelDataChangedDigest, this, &CAircraftComponent::onRowCountChanged);
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::onConnectionStatusChanged, Qt::QueuedConnection); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::onConnectionStatusChanged, Qt::QueuedConnection);
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::movedAircraft, this, &CAircraftComponent::onOwnAircraftMoved, Qt::QueuedConnection); connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::movedAircraft, this, &CAircraftComponent::onOwnAircraftMoved, Qt::QueuedConnection);
connect(&m_updateTimer, &QTimer::timeout, this, &CAircraftComponent::update); connect(&m_updateTimer, &QTimer::timeout, this, &CAircraftComponent::update);
this->onSettingsChanged(); this->onSettingsChanged();
@@ -187,8 +187,9 @@ namespace BlackGui
m_updateTimer.setInterval(ms); m_updateTimer.setInterval(ms);
} }
void CAircraftComponent::onOwnAircraftMoved() void CAircraftComponent::onOwnAircraftMoved(const CLength &distance)
{ {
Q_UNUSED(distance)
this->updateViews(); this->updateViews();
} }
} // namespace } // namespace

View File

@@ -92,7 +92,7 @@ namespace BlackGui
void onSettingsChanged(); void onSettingsChanged();
//! Own aircraft has been moved //! Own aircraft has been moved
void onOwnAircraftMoved(); void onOwnAircraftMoved(const BlackMisc::PhysicalQuantities::CLength &distance);
QScopedPointer<Ui::CAircraftComponent> ui; QScopedPointer<Ui::CAircraftComponent> ui;
BlackMisc::CSettingReadOnly<BlackGui::Settings::TViewUpdateSettings> m_settings { this, &CAircraftComponent::onSettingsChanged }; //!< settings changed BlackMisc::CSettingReadOnly<BlackGui::Settings::TViewUpdateSettings> m_settings { this, &CAircraftComponent::onSettingsChanged }; //!< settings changed

View File

@@ -197,6 +197,17 @@ namespace BlackMisc
return closest; return closest;
} }
template<class OBJ, class CONTAINER>
CONTAINER IGeoObjectList<OBJ, CONTAINER>::findFarthest(int number, const ICoordinateGeodetic &coordinate) const
{
CONTAINER farthest = this->container().partiallySorted(number, [ & ](const OBJ & a, const OBJ & b)
{
return calculateEuclideanDistanceSquared(a, coordinate) > calculateEuclideanDistanceSquared(b, coordinate);
});
farthest.truncate(number);
return farthest;
}
template<class OBJ, class CONTAINER> template<class OBJ, class CONTAINER>
OBJ IGeoObjectList<OBJ, CONTAINER>::findClosestWithinRange(const ICoordinateGeodetic &coordinate, const CLength &range) const OBJ IGeoObjectList<OBJ, CONTAINER>::findClosestWithinRange(const ICoordinateGeodetic &coordinate, const CLength &range) const
{ {
@@ -225,7 +236,7 @@ namespace BlackMisc
} }
template<class OBJ, class CONTAINER> template<class OBJ, class CONTAINER>
CONTAINER IGeoObjectList<OBJ, CONTAINER>::sortedByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate) CONTAINER IGeoObjectList<OBJ, CONTAINER>::sortedByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate) const
{ {
CONTAINER copy(this->container()); CONTAINER copy(this->container());
copy.sortByEuclideanDistanceSquared(coordinate); copy.sortByEuclideanDistanceSquared(coordinate);

View File

@@ -103,6 +103,9 @@ namespace BlackMisc
//! Find 0..n objects closest to the given coordinate. //! Find 0..n objects closest to the given coordinate.
CONTAINER findClosest(int number, const ICoordinateGeodetic &coordinate) const; CONTAINER findClosest(int number, const ICoordinateGeodetic &coordinate) const;
//! Find 0..n objects farthest to the given coordinate.
CONTAINER findFarthest(int number, const ICoordinateGeodetic &coordinate) const;
//! Find closest within range to the given coordinate //! Find closest within range to the given coordinate
OBJ findClosestWithinRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const; OBJ findClosestWithinRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const;
@@ -110,7 +113,7 @@ namespace BlackMisc
void sortByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate); void sortByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate);
//! Sorted by distance //! Sorted by distance
CONTAINER sortedByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate); CONTAINER sortedByEuclideanDistanceSquared(const ICoordinateGeodetic &coordinate) const;
protected: protected:
//! Constructor //! Constructor