From 9c33c5d9fc30bfa4fef45d1733028341f86e4897 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 12 May 2018 20:59:40 +0200 Subject: [PATCH] Ref T245, Ref T261, added functions for "follow plane", "setup changed" signal in context and simulator interface --- src/blackcore/context/contextsimulator.h | 9 +++++ src/blackcore/context/contextsimulatorempty.h | 16 +++++++++ .../context/contextsimulatorimpl.cpp | 35 ++++++++++++++++++- src/blackcore/context/contextsimulatorimpl.h | 2 ++ .../context/contextsimulatorproxy.cpp | 13 +++++++ src/blackcore/context/contextsimulatorproxy.h | 2 ++ src/blackcore/simulator.h | 6 ++++ src/blackcore/simulatorcommon.cpp | 13 ++++++- src/blackcore/simulatorcommon.h | 1 + .../simulator/emulated/simulatoremulated.cpp | 8 ++++- 10 files changed, 102 insertions(+), 3 deletions(-) diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index b17ba17c0..47c91ffcd 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -94,6 +94,9 @@ namespace BlackCore //! Render restrictions have been changed void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance); + //! Setup changed + void interpolationAndRenderingSetupChanged(); + //! Model set ready or changed void modelSetChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -189,6 +192,9 @@ namespace BlackCore //! \copydoc BlackMisc::Simulation::IInterpolationSetupProvider::getInterpolationSetupsPerCallsign virtual BlackMisc::Simulation::CInterpolationSetupList getInterpolationAndRenderingSetupsPerCallsign() const = 0; + //! \copydoc BlackMisc::Simulation::IInterpolationSetupProvider::getInterpolationSetupPerCallsignOrDefault + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationAndRenderingSetupPerCallsignOrDefault(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + //! \copydoc BlackMisc::Simulation::IInterpolationSetupProvider::setInterpolationSetupGlobal virtual void setInterpolationAndRenderingSetupGlobal(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) = 0; @@ -219,6 +225,9 @@ namespace BlackCore //! Highlight aircraft in simulator virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; + //! Follow aircraft im simulator view + virtual bool followAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0; + //! Reset model by matching it again virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index ef486acb3..aeba0af76 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -175,6 +175,14 @@ namespace BlackCore return BlackMisc::Simulation::CInterpolationSetupList(); } + //! \copydoc ISimulator::getInterpolationSetupPerCallsignOrDefault + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationAndRenderingSetupPerCallsignOrDefault(const BlackMisc::Aviation::CCallsign &callsign) const override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign(); + } + //! \copydoc ISimulator::setInterpolationAndRenderingSetup virtual void setInterpolationAndRenderingSetupGlobal(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) override { @@ -213,6 +221,14 @@ namespace BlackCore logEmptyContextWarning(Q_FUNC_INFO); } + //! \copydoc IContextSimulator::followAircraft + virtual bool followAircraft(const BlackMisc::Aviation::CCallsign &callsign) override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + //! \copydoc IContextSimulator::resetToModelMatchingAircraft virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override { diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index a1d5b7d54..4008ca1ff 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -32,6 +32,7 @@ #include "blackmisc/threadutils.h" #include "blackmisc/verify.h" #include "blackconfig/buildconfig.h" +#include "contextsimulatorimpl.h" #include #include @@ -295,6 +296,14 @@ namespace BlackCore return m_simulatorPlugin.second->getInterpolationSetupsPerCallsign(); } + CInterpolationAndRenderingSetupPerCallsign CContextSimulator::getInterpolationAndRenderingSetupPerCallsignOrDefault(const CCallsign &callsign) const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return CInterpolationAndRenderingSetupPerCallsign(); } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getInterpolationSetupPerCallsignOrDefault(callsign); + } + void CContextSimulator::setInterpolationAndRenderingSetupsPerCallsign(const CInterpolationSetupList &setups) { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } @@ -374,6 +383,8 @@ namespace BlackCore Q_ASSERT(c); c = connect(simulator, &ISimulator::renderRestrictionsChanged, this, &IContextSimulator::renderRestrictionsChanged); Q_ASSERT(c); + c = connect(simulator, &ISimulator::interpolationAndRenderingSetupChanged, this, &IContextSimulator::interpolationAndRenderingSetupChanged); + Q_ASSERT(c); c = connect(simulator, &ISimulator::airspaceSnapshotHandled, this, &IContextSimulator::airspaceSnapshotHandled); Q_ASSERT(c); c = connect(simulator, &ISimulator::driverMessages, this, &IContextSimulator::driverMessages); @@ -503,10 +514,25 @@ namespace BlackCore Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "Mismatching callsigns"); this->updateAircraftModel(callsign, aircraftModel, this->identifier()); const CSimulatedAircraft aircraftAfterModelApplied = this->getAircraftInRangeForCallsign(remoteAircraft.getCallsign()); + if (!aircraftAfterModelApplied.hasModelString()) + { + if (!aircraftAfterModelApplied.hasCallsign()) { return; } // removed + if (this->isAircraftInRange(aircraftAfterModelApplied.getCallsign())) { return; } // removed, but callsig, we did crosscheck + + // callsign but not string + CLogMessage(this).error("Matching error for '%1', no model string") << aircraftAfterModelApplied.getCallsign().asString(); + + CSimulatedAircraft brokenAircraft(aircraftAfterModelApplied); + brokenAircraft.setEnabled(false); + brokenAircraft.setRendered(false); + emit this->aircraftRenderingChanged(brokenAircraft); + CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Cannot add remote aircraft, no model string: %1").arg(brokenAircraft.toQString())); + return; + } m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied); CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Logically added remote aircraft: %1").arg(aircraftAfterModelApplied.toQString())); this->addMatchingMessages(callsign, matchingMessages); - emit this->modelMatchingCompleted(remoteAircraft); + emit this->modelMatchingCompleted(aircraftAfterModelApplied); } void CContextSimulator::xCtxRemovedRemoteAircraft(const CCallsign &callsign) @@ -775,6 +801,13 @@ namespace BlackCore m_simulatorPlugin.second->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime); } + bool CContextSimulator::followAircraft(const CCallsign &callsign) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->followAircraft(callsign); + } + bool CContextSimulator::resetToModelMatchingAircraft(const CCallsign &callsign) { CSimulatedAircraft aircraft = getAircraftInRangeForCallsign(callsign); diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index f16672d98..bbd8ac408 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -90,10 +90,12 @@ namespace BlackCore virtual bool isTimeSynchronized() const override; virtual BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal getInterpolationAndRenderingSetupGlobal() const override; virtual BlackMisc::Simulation::CInterpolationSetupList getInterpolationAndRenderingSetupsPerCallsign() const override; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationAndRenderingSetupPerCallsignOrDefault(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual void setInterpolationAndRenderingSetupsPerCallsign(const BlackMisc::Simulation::CInterpolationSetupList &setups) override; virtual void setInterpolationAndRenderingSetupGlobal(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) override; virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + virtual bool followAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; virtual void setWeatherActivated(bool activated) override; virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index b8c0625d1..5590e5899 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -62,6 +62,9 @@ namespace BlackCore s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "renderRestrictionsChanged", this, SIGNAL(renderRestrictionsChanged(bool, bool, int, BlackMisc::PhysicalQuantities::CLength))); Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "interpolationAndRenderingSetupChanged", this, SIGNAL(interpolationAndRenderingSetupChanged())); + Q_ASSERT(s); s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "simulatorPluginChanged", this, SIGNAL(simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo))); Q_ASSERT(s); @@ -176,6 +179,11 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1String("getInterpolationAndRenderingSetupsPerCallsign")); } + CInterpolationAndRenderingSetupPerCallsign CContextSimulatorProxy::getInterpolationAndRenderingSetupPerCallsignOrDefault(const CCallsign &callsign) const + { + return m_dBusInterface->callDBusRet(QLatin1String("getInterpolationAndRenderingSetupsPerCallsign"), callsign); + } + void CContextSimulatorProxy::setInterpolationAndRenderingSetupsPerCallsign(const CInterpolationSetupList &setups) { m_dBusInterface->callDBus(QLatin1String("setInterpolationAndRenderingSetupsPerCallsign"), setups); @@ -211,6 +219,11 @@ namespace BlackCore m_dBusInterface->callDBus(QLatin1String("highlightAircraft"), aircraftToHighlight, enableHighlight, displayTime); } + bool CContextSimulatorProxy::followAircraft(const CCallsign &callsign) + { + return m_dBusInterface->callDBusRet(QLatin1String("followAircraft"), callsign); + } + bool CContextSimulatorProxy::resetToModelMatchingAircraft(const CCallsign &callsign) { return m_dBusInterface->callDBusRet(QLatin1String("resetToModelMatchingAircraft"), callsign, callsign); diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 38ebf7c63..0183e8484 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -78,10 +78,12 @@ namespace BlackCore virtual BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal getInterpolationAndRenderingSetupGlobal() const override; virtual void setInterpolationAndRenderingSetupGlobal(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) override; virtual BlackMisc::Simulation::CInterpolationSetupList getInterpolationAndRenderingSetupsPerCallsign() const override; + virtual BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationAndRenderingSetupPerCallsignOrDefault(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual void setInterpolationAndRenderingSetupsPerCallsign(const BlackMisc::Simulation::CInterpolationSetupList &setups) override; virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + virtual bool followAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; virtual void setWeatherActivated(bool activated) override; virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 139ce59f1..e25627d9c 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -164,6 +164,9 @@ namespace BlackCore //! Highlight the aircraft for given time (or disable highlight) virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; + //! Follow aircraft + virtual bool followAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0; + //! Activates or deactivates simulator weather virtual void setWeatherActivated(bool activated) = 0; @@ -216,6 +219,9 @@ namespace BlackCore //! Render restrictions have been changed void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance); + //! Interpolation or rendering setup changed + void interpolationAndRenderingSetupChanged(); + //! Aircraft rendering changed void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index e6e0de4cc..2b96fd8f7 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -358,6 +358,7 @@ namespace BlackCore const bool r = setup.isRenderingRestricted(); const bool e = setup.isRenderingEnabled(); + emit this->interpolationAndRenderingSetupChanged(); emit this->renderRestrictionsChanged(r, e, setup.getMaxRenderedAircraft(), setup.getMaxRenderedDistance()); } @@ -373,6 +374,12 @@ namespace BlackCore } } + bool CSimulatorCommon::followAircraft(const CCallsign &callsign) + { + Q_UNUSED(callsign); + return false; + } + int CSimulatorCommon::physicallyRemoveMultipleRemoteAircraft(const CCallsignSet &callsigns) { if (callsigns.isEmpty()) { return 0; } @@ -482,7 +489,11 @@ namespace BlackCore const CCallsign cs(parser.part(2)); CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(cs); const bool changed = setup.setInterpolatorMode(part1); - if (changed) { this->setInterpolationSetupPerCallsign(setup, cs); } + if (changed) + { + this->setInterpolationSetupPerCallsign(setup, cs); + emit this->interpolationAndRenderingSetupChanged(); + } CLogMessage(this).info(changed ? "Changed interpolation mode for '%1'" : "Unchanged interpolation mode for '%1'") << cs.asString(); return true; } diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 1af6e4b96..8b7bfcd1a 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -69,6 +69,7 @@ namespace BlackCore // --------- ISimulator implementations ------------ virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + virtual bool followAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const override; virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; virtual void setWeatherActivated(bool activated) override; diff --git a/src/plugins/simulator/emulated/simulatoremulated.cpp b/src/plugins/simulator/emulated/simulatoremulated.cpp index c8928e328..183da1615 100644 --- a/src/plugins/simulator/emulated/simulatoremulated.cpp +++ b/src/plugins/simulator/emulated/simulatoremulated.cpp @@ -379,13 +379,19 @@ namespace BlackSimPlugin m_monitorWidget->appendSendingCall("ownAircraftModelChanged", model.toQString()); }, Qt::QueuedConnection)); - m_connectionGuard.append(connect(this, &ISimulator::renderRestrictionsChanged, this, [ = ](bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength & maxRenderedDistance) + m_connectionGuard.append(connect(this, &ISimulator::renderRestrictionsChanged, this, [ = ](bool restricted, bool enabled, int maxAircraft, const CLength & maxRenderedDistance) { if (!m_monitorWidget) return; static const QString params("restricted: %1 enabled: %2 max aircraft: %3"); m_monitorWidget->appendSendingCall("renderRestrictionsChanged", params.arg(boolToYesNo(restricted), boolToYesNo(enabled)).arg(maxAircraft), maxRenderedDistance.valueRoundedWithUnit(CLengthUnit::m(), 1)); }, Qt::QueuedConnection)); + m_connectionGuard.append(connect(this, &ISimulator::interpolationAndRenderingSetupChanged, this, [ = ]() + { + if (!m_monitorWidget) return; + m_monitorWidget->appendSendingCall("interpolationAndRenderingSetupChanged"); + }, Qt::QueuedConnection)); + m_connectionGuard.append(connect(this, &ISimulator::aircraftRenderingChanged, this, [ = ](const CSimulatedAircraft & aircraft) { if (!m_monitorWidget) return;