diff --git a/src/blackcore/context_simulator.cpp b/src/blackcore/context_simulator.cpp index 5841dd523..5bf00b6cb 100644 --- a/src/blackcore/context_simulator.cpp +++ b/src/blackcore/context_simulator.cpp @@ -47,4 +47,5 @@ namespace BlackCore return nullptr; // simulator not mandatory } } + } // namespace diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 551bdb5ee..66d970ccc 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -74,6 +74,9 @@ namespace BlackCore //! Simulator combined status void simulatorStatusChanged(bool connected, bool running, bool paused); + //! Only a limited number of aircraft displayed + void restrictedRenderingChanged(bool restricted); + //! Installed aircraft models ready or changed void installedAircraftModelsChanged(); @@ -138,8 +141,26 @@ namespace BlackCore //! Max. number of remote aircraft rendered virtual int getMaxRenderedAircraft() const = 0; - //! Max. number of remote aircraft rendered and provide optional selection which aircraft this are - virtual void setMaxRenderedAircraft(int number, const BlackMisc::Aviation::CCallsignList &renderedAircraft) = 0; + //! Max. rendered distance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const = 0; + + //! Technical range until aircraft are visible + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const = 0; + + //! Text describing the rendering restrictions + virtual QString getRenderRestrictionText() const = 0; + + //! Max. number of remote aircraft rendered and provide optional selection which aircraft those are + virtual void setMaxRenderedAircraft(int number) = 0; + + //! Max. distance until we render an aircraft + virtual void setMaxRenderedDistance(BlackMisc::PhysicalQuantities::CLength &distance) = 0; + + //! Delete all restrictions (if any) -> unlimited number of aircraft + virtual void deleteAllRenderingRestrictions() = 0; + + //! Is number of aircraft restricted + virtual bool isRenderingRestricted() const = 0; //! Time synchronization offset virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index f5f4fc0b1..c89d31249 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -171,20 +171,71 @@ namespace BlackCore int CContextSimulator::getMaxRenderedAircraft() const { - CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; + if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (!m_simulator) return 0; return m_simulator->getMaxRenderedAircraft(); } - void CContextSimulator::setMaxRenderedAircraft(int number, const CCallsignList &renderedAircraft) + void CContextSimulator::setMaxRenderedAircraft(int number) { - CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; - if (m_simulator) { this->m_simulator->setMaxRenderedAircraft(number, renderedAircraft); } + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; } + if (m_simulator) { this->m_simulator->setMaxRenderedAircraft(number); } + } + + void CContextSimulator::setMaxRenderedDistance(CLength &distance) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << distance; } + if (m_simulator) { this->m_simulator->setMaxRenderedDistance(distance); } + } + + QString CContextSimulator::getRenderRestrictionText() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (!m_simulator) { return ""; } + if (!m_simulator->isRenderingRestricted()) { return "none"; } + QString rt; + if (m_simulator->isMaxAircraftRestricted()) + { + rt.append(QString::number(m_simulator->getMaxRenderedAircraft())).append(" A/C"); + } + if (m_simulator->isMaxDistanceRestricted()) + { + if (!rt.isEmpty()) { rt.append(" ");} + rt.append(m_simulator->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0)); + } + return rt; + } + + CLength CContextSimulator::getMaxRenderedDistance() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulator) { return this->m_simulator->getMaxRenderedDistance(); } + return CLength(0, CLengthUnit::nullUnit()); + } + + CLength CContextSimulator::getRenderedDistanceBoundary() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulator) { return this->m_simulator->getRenderedDistanceBoundary(); } + return CLength(20.0, CLengthUnit::NM()); + } + + void CContextSimulator::deleteAllRenderingRestrictions() + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulator) { this->m_simulator->deleteAllRenderingRestrictions(); } + } + + bool CContextSimulator::isRenderingRestricted() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulator) { return this->m_simulator->isRenderingRestricted(); } + return false; } CTime CContextSimulator::getTimeSynchronizationOffset() const { - CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (!m_simulator) return CTime(0, CTimeUnit::hrmin()); return this->m_simulator->getTimeSynchronizationOffset(); } @@ -237,6 +288,7 @@ namespace BlackCore connect(m_simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); connect(m_simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted); connect(m_simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged); + connect(m_simulator, &ISimulator::restrictedRenderingChanged, this, &IContextSimulator::restrictedRenderingChanged); // log from context to simulator connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, m_simulator, &ISimulator::displayStatusMessage); diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index f9295b4a5..514552513 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -96,7 +96,25 @@ namespace BlackCore virtual int getMaxRenderedAircraft() const override; //! \copydoc IContextSimulator::setMaxRenderedAircraft - virtual void setMaxRenderedAircraft(int number, const BlackMisc::Aviation::CCallsignList &renderedAircraft) override; + virtual void setMaxRenderedAircraft(int number) override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void setMaxRenderedDistance(BlackMisc::PhysicalQuantities::CLength &distance) override; + + //! \copydoc IContextSimulator::getRenderRestrictionText + virtual QString getRenderRestrictionText() const override; + + //! \copydoc IContextSimulator::getMaxRenderedDistance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; + + //! \copydoc IContextSimulator::getRenderedDistanceBoundary + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void deleteAllRenderingRestrictions() override; + + //! \copydoc IContextSimulator::isRenderingRestricted + virtual bool isRenderingRestricted() const override; //! \copydoc IContextSimulator::getTimeSynchronizationOffset virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; diff --git a/src/blackcore/context_simulator_proxy.cpp b/src/blackcore/context_simulator_proxy.cpp index 4ad29508a..d69265be6 100644 --- a/src/blackcore/context_simulator_proxy.cpp +++ b/src/blackcore/context_simulator_proxy.cpp @@ -51,6 +51,9 @@ namespace BlackCore s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft))); Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "restrictedRenderingChanged", this, SIGNAL(restrictedRenderingChanged(bool))); + Q_ASSERT(s); Q_UNUSED(s); } @@ -129,9 +132,39 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1Literal("isTimeSynchronized")); } - void CContextSimulatorProxy::setMaxRenderedAircraft(int number, const CCallsignList &renderedAircraft) + void CContextSimulatorProxy::setMaxRenderedAircraft(int number) { - m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedRemoteAircraft"), number, renderedAircraft); + m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedAircraft"), number); + } + + void CContextSimulatorProxy::setMaxRenderedDistance(CLength &distance) + { + m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedDistance"), distance); + } + + void CContextSimulatorProxy::deleteAllRenderingRestrictions() + { + m_dBusInterface->callDBus(QLatin1Literal("deleteAllRenderingRestrictions")); + } + + bool CContextSimulatorProxy::isRenderingRestricted() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("isRenderingRestricted")); + } + + CLength CContextSimulatorProxy::getMaxRenderedDistance() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getMaxRenderedDistance")); + } + + CLength CContextSimulatorProxy::getRenderedDistanceBoundary() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getRenderedDistanceBoundary")); + } + + QString CContextSimulatorProxy::getRenderRestrictionText() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getRenderRestrictionText")); } int CContextSimulatorProxy::getMaxRenderedAircraft() const diff --git a/src/blackcore/context_simulator_proxy.h b/src/blackcore/context_simulator_proxy.h index 2cd83bdfe..10d13fc10 100644 --- a/src/blackcore/context_simulator_proxy.h +++ b/src/blackcore/context_simulator_proxy.h @@ -99,7 +99,25 @@ namespace BlackCore virtual int getMaxRenderedAircraft() const override; //! \copydoc IContextSimulator::setMaxRenderedRemoteAircraft - virtual void setMaxRenderedAircraft(int number, const BlackMisc::Aviation::CCallsignList &renderedAircraft) override; + virtual void setMaxRenderedAircraft(int number) override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void setMaxRenderedDistance(BlackMisc::PhysicalQuantities::CLength &distance); + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void deleteAllRenderingRestrictions() override; + + //! \copydoc IContextSimulator::isRenderingRestricted + virtual bool isRenderingRestricted() const override; + + //! \copydoc IContextSimulator::getMaxRenderedDistance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; + + //! \copydoc IContextSimulator::getRenderedDistanceBoundary + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; + + //! \copydoc IContextSimulator::getRenderRestrictionText + virtual QString getRenderRestrictionText() const override; //! \copydoc IContextSimulator::getTimeSynchronizationOffset virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index f1a76ae55..879aefe0e 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -9,7 +9,9 @@ #include "simulator.h" #include "interpolator.h" +#include "blackmisc/collection.h" +using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackMisc::PhysicalQuantities; @@ -23,7 +25,9 @@ namespace BlackCore } CSimulatorCommon::CSimulatorCommon(const BlackSim::CSimulatorInfo &simInfo, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent) - : ISimulator(parent), COwnAircraftProviderSupport(ownAircraftProvider), CRemoteAircraftProviderSupport(remoteAircraftProvider), m_simulatorInfo(simInfo) + : ISimulator(parent), + COwnAircraftProviderSupport(ownAircraftProvider), + CRemoteAircraftProviderSupport(remoteAircraftProvider), m_simulatorInfo(simInfo) { m_oneSecondTimer = new QTimer(this); connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer); @@ -65,6 +69,27 @@ namespace BlackCore } } + void CSimulatorCommon::recalculateRestrictedAircraft() + { + if (!isMaxAircraftRestricted()) { return; } + if (!isRenderingEnabled()) { return; } + + //! \todo Simulator, why is there no difference on CSequence? + CSimulatedAircraftList newAircraftInRange(remoteAircraft().getClosestObjects(getMaxRenderedAircraft())); + CCallsignList newAircraftCallsigns(newAircraftInRange.getCallsigns()); + CCallsignList toBeRemovedCallsigns(m_callsignsToBeRendered.difference(newAircraftCallsigns)); + CCallsignList toBeAddedCallsigns(newAircraftCallsigns.difference(m_callsignsToBeRendered)); + for (const CCallsign &cs : toBeRemovedCallsigns) + { + removeRemoteAircraft(cs); + } + for (const CCallsign &cs : toBeAddedCallsigns) + { + addRemoteAircraft(newAircraftInRange.findFirstByCallsign(cs)); + } + this->m_callsignsToBeRendered = newAircraftCallsigns; + } + void CSimulatorCommon::resetAircraftFromBacked(const CCallsign &callsign) { CSimulatedAircraft aircraft(this->remoteAircraft().findFirstByCallsign(callsign)); @@ -101,13 +126,65 @@ namespace BlackCore int CSimulatorCommon::getMaxRenderedAircraft() const { - return m_maxRenderedAircraft; + return (m_maxRenderedAircraft <= MaxAircraftInfinite) ? m_maxRenderedAircraft : MaxAircraftInfinite; } - void CSimulatorCommon::setMaxRenderedAircraft(int maxRenderedAircraft, const BlackMisc::Aviation::CCallsignList &callsigns) + void CSimulatorCommon::setMaxRenderedAircraft(int maxRenderedAircraft) { - m_maxRenderedAircraft = maxRenderedAircraft; - m_callsignsToBeRendered = callsigns; + if (maxRenderedAircraft == m_maxRenderedAircraft) { return; } + if (maxRenderedAircraft < 1) + { + m_maxRenderedAircraft = 0; + } + else if (maxRenderedAircraft >= MaxAircraftInfinite) + { + m_maxRenderedAircraft = MaxAircraftInfinite; + } + else + { + m_maxRenderedAircraft = maxRenderedAircraft; + } + + bool r = isRenderingRestricted(); + emit restrictedRenderingChanged(r); + } + + void CSimulatorCommon::setMaxRenderedDistance(CLength &distance) + { + if (distance == m_maxRenderedDistance) { return; } + if (distance.isNull() || distance >= getRenderedDistanceBoundary()) + { + m_maxRenderedDistance = CLength(0.0, CLengthUnit::nullUnit()); + } + else + { + Q_ASSERT(distance.isPositiveWithEpsilonConsidered()); + m_maxRenderedDistance = distance; + } + + bool r = isRenderingRestricted(); + emit restrictedRenderingChanged(r); + } + + CLength CSimulatorCommon::getMaxRenderedDistance() const + { + if (m_maxRenderedDistance.isNull()) { return getRenderedDistanceBoundary(); } + return m_maxRenderedDistance; + } + + CLength CSimulatorCommon::getRenderedDistanceBoundary() const + { + return CLength(20.0, CLengthUnit::NM()); + } + + bool CSimulatorCommon::isMaxAircraftRestricted() const + { + return m_maxRenderedAircraft < MaxAircraftInfinite && isRenderingEnabled(); + } + + bool CSimulatorCommon::isMaxDistanceRestricted() const + { + return !m_maxRenderedDistance.isNull(); } CSimulatorInfo CSimulatorCommon::getSimulatorInfo() const @@ -140,12 +217,35 @@ namespace BlackCore bool CSimulatorCommon::isRenderingEnabled() const { - return m_maxRenderedAircraft < 1; + if (m_maxRenderedAircraft < 1) { return false; } + if (!isMaxDistanceRestricted()) { return true; } + + return m_maxRenderedDistance.valueRounded(CLengthUnit::NM(), 2) > 0.1; + } + + bool CSimulatorCommon::isRenderingRestricted() const + { + return this->isMaxDistanceRestricted() || this->isMaxAircraftRestricted(); + } + + void CSimulatorCommon::deleteAllRenderingRestrictions() + { + if (!isRenderingEnabled()) { return; } + this->m_maxRenderedDistance = CLength(0, CLengthUnit::nullUnit()); + this->m_maxRenderedAircraft = MaxAircraftInfinite; + emit restrictedRenderingChanged(false); } void CSimulatorCommon::ps_oneSecondTimer() { + m_timerCounter++; blinkHighlightedAircraft(); + + // any seconds + if (m_timerCounter % 10 == 0) + { + recalculateRestrictedAircraft(); + } } } // namespace diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index cc168fcb7..5b641e9be 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -43,6 +43,9 @@ namespace BlackCore ConnectionFailed }; + //! Render all aircraft + const int MaxAircraftInfinite = 100; + //! Destructor virtual ~ISimulator() {} @@ -70,7 +73,7 @@ namespace BlackCore return o; } - public slots: + public: //! Connect to simulator virtual bool connectTo() = 0; @@ -138,7 +141,28 @@ namespace BlackCore virtual int getMaxRenderedAircraft() const = 0; //! Max. rendered aircraft - virtual void setMaxRenderedAircraft(int maxRenderedAircraft, const BlackMisc::Aviation::CCallsignList &callsigns) = 0; + virtual void setMaxRenderedAircraft(int maxRenderedAircraft) = 0; + + //! Max. distance for rendered aircraft + virtual void setMaxRenderedDistance(BlackMisc::PhysicalQuantities::CLength &distance) = 0; + + //! Max. distance for rendered aircraft + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const = 0; + + //! Technical range until aircraft are visible + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const = 0; + + //! Restricted number of aircraft + virtual bool isMaxAircraftRestricted() const = 0; + + //! Restriced distance + virtual bool isMaxDistanceRestricted() const = 0; + + //! Is there a restriction? No rendering -> limited number of aircraft -> unlimited number of aircraft + virtual bool isRenderingRestricted() const = 0; + + //! Delete all restrictions (if any) -> unlimited number of aircraft + virtual void deleteAllRenderingRestrictions() = 0; //! Enable debugging messages virtual void enableDebugMessages(bool driver, bool interpolator) = 0; @@ -162,6 +186,9 @@ namespace BlackCore //! Simulator combined status void simulatorStatusChanged(bool connected, bool running, bool paused); + //! Only a limited number of aircraft displayed + void restrictedRenderingChanged(bool restricted); + //! Simulator started void simulatorStarted(); @@ -217,13 +244,27 @@ namespace BlackCore Q_OBJECT - public slots: - + public: //! \copydoc ISimulator::getMaxRenderedAircraft virtual int getMaxRenderedAircraft() const override; //! \copydoc ISimulator::setMaxRenderedAircraft - virtual void setMaxRenderedAircraft(int maxRenderedAircraft, const BlackMisc::Aviation::CCallsignList &callsigns) override; + virtual void setMaxRenderedAircraft(int maxRenderedAircraft) override; + + //! \copydoc ISimulator::setMaxRenderedDistance + virtual void setMaxRenderedDistance(BlackMisc::PhysicalQuantities::CLength &distance) override; + + //! \copydoc ISimulator::getMaxRenderedDistance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; + + //! \copydoc ISimulator::getRenderedDistanceBoundary + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; + + //! \copydoc ISimulator::isMaxAircraftRestricted + virtual bool isMaxAircraftRestricted() const override; + + //! \copydoc ISimulator::isMaxDistanceRestricted + virtual bool isMaxDistanceRestricted() const override; //! \copydoc ISimulator::getSimulatorInfo virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override; @@ -240,6 +281,12 @@ namespace BlackCore //! \copydoc IContextSimulator::isRenderingEnabled virtual bool isRenderingEnabled() const override; + //! \copydoc IContextSimulator::isRenderingRestricted + virtual bool isRenderingRestricted() const override; + + //! \copydoc IContextSimulator::deleteAllRenderingRestrictions + virtual void deleteAllRenderingRestrictions(); + protected slots: //! Slow timer used to highlight aircraft, can be used for other things too virtual void ps_oneSecondTimer(); @@ -256,6 +303,9 @@ namespace BlackCore //! Blink the highlighted aircraft void blinkHighlightedAircraft(); + //! Recalculate the restricted aircraft + void recalculateRestrictedAircraft(); + //! Restore aircraft from backedn data void resetAircraftFromBacked(const BlackMisc::Aviation::CCallsign &callsign); @@ -263,15 +313,16 @@ namespace BlackCore void setInitialAircraftSituationAndParts(BlackMisc::Simulation::CSimulatedAircraft &aircraft) const; BlackSim::CSimulatorInfo m_simulatorInfo; //!< about the simulator - int m_maxRenderedAircraft = 90; //!< max. rendered aircraft bool m_debugMessages = false; //!< Display debug messages bool m_blinkCycle = false; //!< use for highlighting IInterpolator *m_interpolator = nullptr; //!< interpolator instance qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting + int m_timerCounter = 0; //!< allows to calculate n seconds + QTimer *m_oneSecondTimer = nullptr; //!< timer BlackMisc::Simulation::CSimulatedAircraftList m_highlightedAircraft; //!< all other aircraft are to be ignored BlackMisc::Aviation::CCallsignList m_callsignsToBeRendered; //!< callsigns which will be rendered - QTimer *m_oneSecondTimer = nullptr; //!< timer - + int m_maxRenderedAircraft = MaxAircraftInfinite; //!< max.rendered aircraft + BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< max.distance for rendering }; } // namespace diff --git a/src/blackgui/components/settingssimulatorcomponent.cpp b/src/blackgui/components/settingssimulatorcomponent.cpp index 8917d5ecc..ffe1f84e0 100644 --- a/src/blackgui/components/settingssimulatorcomponent.cpp +++ b/src/blackgui/components/settingssimulatorcomponent.cpp @@ -32,12 +32,12 @@ namespace BlackGui ui(new Ui::CSettingsSimulatorComponent) { ui->setupUi(this); + CLedWidget::LedShape shape = CLedWidget::Circle; + this->ui->led_RestrictedRendering->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Limited", "Unlimited", 14); } CSettingsSimulatorComponent::~CSettingsSimulatorComponent() - { - delete ui; - } + { } void CSettingsSimulatorComponent::runtimeHasBeenSet() { @@ -51,8 +51,7 @@ namespace BlackGui this->setCurrentPlugin(currentPlugin); // disable / enable driver specific GUI parts - bool fsxDriver = - this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX()); + bool fsxDriver = this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX()); this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver); // time sync @@ -61,13 +60,15 @@ namespace BlackGui CTime timeOffset = this->getIContextSimulator()->getTimeSynchronizationOffset(); this->ui->le_TimeSyncOffset->setText(timeOffset.formattedHrsMin()); - // max.aircraft - this->ui->sb_MaxAircraft->setValue(getIContextSimulator()->getMaxRenderedAircraft()); - // only with simulator context set GUI values - bool connected = this->connect(this->ui->cb_Plugins, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_pluginHasChanged(int))); + bool connected = this->connect(this->ui->cb_Plugins, static_cast (&QComboBox::currentIndexChanged), this, &CSettingsSimulatorComponent::ps_pluginHasChanged); + Q_ASSERT(connected); + connected = this->connect(getIContextSimulator(), &IContextSimulator::restrictedRenderingChanged, this, &CSettingsSimulatorComponent::ps_onRenderingRestricted); Q_ASSERT(connected); Q_UNUSED(connected); + + // set values + this->setRestrictedValues(); } if (this->getIContextSettings()) @@ -75,8 +76,10 @@ namespace BlackGui connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsSimulatorComponent::ps_settingsHaveChanged); } - connect(this->ui->pb_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyNewMaxRemoteAircraft); + connect(this->ui->pb_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft); connect(this->ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyTimeSync); + connect(this->ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance); + connect(this->ui->pb_ClearRestrictedRendering, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_clearRestricedRendering); } void CSettingsSimulatorComponent::setCurrentPlugin(const CSimulatorInfo &plugin) @@ -95,6 +98,20 @@ namespace BlackGui } } + void CSettingsSimulatorComponent::setRestrictedValues() + { + Q_ASSERT(getIContextSimulator()); + this->ui->led_RestrictedRendering->setOn(getIContextSimulator()->isRenderingRestricted()); + this->ui->lbl_RestrictionText->setText(getIContextSimulator()->getRenderRestrictionText()); + + int distanceBoundaryNM = getIContextSimulator()->getRenderedDistanceBoundary().valueInteger(CLengthUnit::NM()); + this->ui->sb_MaxDistance->setMaximum(distanceBoundaryNM); + this->ui->sb_MaxAircraft->setValue(getIContextSimulator()->getMaxRenderedAircraft()); + + int distanceNM = getIContextSimulator()->getMaxRenderedDistance().valueInteger(CLengthUnit::NM()); + this->ui->sb_MaxDistance->setValue(distanceNM); + } + void CSettingsSimulatorComponent::ps_pluginHasChanged(int index) { Q_ASSERT(this->getIContextSimulator()); @@ -131,18 +148,13 @@ namespace BlackGui this->ui->cb_TimeSync->setChecked(simSettings.isTimeSyncEnabled()); } - void CSettingsSimulatorComponent::ps_onApplyNewMaxRemoteAircraft() + void CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft() { Q_ASSERT(getIContextSimulator()); - Q_ASSERT(getIContextNetwork()); // get initial aircraft to render int noRequested = this->ui->sb_MaxAircraft->value(); - CSimulatedAircraftList inRange(this->getIContextNetwork()->getAircraftInRange()); - inRange.truncate(noRequested); - inRange.sortByDistanceToOwnAircraft(); - CCallsignList initialCallsigns(inRange.getCallsigns()); - this->getIContextSimulator()->setMaxRenderedAircraft(noRequested, initialCallsigns); + this->getIContextSimulator()->setMaxRenderedAircraft(noRequested); // real value int noRendered = this->getIContextSimulator()->getMaxRenderedAircraft(); @@ -157,6 +169,18 @@ namespace BlackGui } } + void CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance() + { + Q_ASSERT(getIContextSimulator()); + + // get initial aircraft to render + int maxDistanceNM = this->ui->sb_MaxDistance->value(); + CLength distance(maxDistanceNM, CLengthUnit::NM()); + this->getIContextSimulator()->setMaxRenderedDistance(distance); + + CLogMessage(this).info("Max.distance requested: %1") << distance.valueRoundedWithUnit(2, true); + } + void CSettingsSimulatorComponent::ps_onApplyTimeSync() { bool timeSync = this->ui->cb_TimeSync->isChecked(); @@ -175,6 +199,18 @@ namespace BlackGui getIContextSimulator()->setTimeSynchronization(timeSync, ost); } } + + void CSettingsSimulatorComponent::ps_onRenderingRestricted(bool restricted) + { + Q_UNUSED(restricted); + setRestrictedValues(); + } + + void CSettingsSimulatorComponent::ps_clearRestricedRendering() + { + Q_ASSERT(getIContextSimulator()); + this->getIContextSimulator()->deleteAllRenderingRestrictions(); + } } } // namespace diff --git a/src/blackgui/components/settingssimulatorcomponent.h b/src/blackgui/components/settingssimulatorcomponent.h index 1936bdb02..b580baf06 100644 --- a/src/blackgui/components/settingssimulatorcomponent.h +++ b/src/blackgui/components/settingssimulatorcomponent.h @@ -46,18 +46,30 @@ namespace BlackGui //! Settings have been changed void ps_settingsHaveChanged(uint settingsType); - //! Apply max aircraft - void ps_onApplyNewMaxRemoteAircraft(); + //! Apply max.aircraft + void ps_onApplyMaxRenderedAircraft(); + + //! Apply max.distance + void ps_onApplyMaxRenderedDistance(); //! Apply time sync void ps_onApplyTimeSync(); + //! Restricted number of rendered aircraft + void ps_onRenderingRestricted(bool restricted); + + //! Clear restricted rendering + void ps_clearRestricedRendering(); + private: - Ui::CSettingsSimulatorComponent *ui; //!< UI + QScopedPointer ui; //!< UI //! Smarter way to set current driver, avoids unnecessary signals and less formatting dependend void setCurrentPlugin(const BlackSim::CSimulatorInfo &plugin); + //! Set the GUI values + void setRestrictedValues(); + }; } } // namespace diff --git a/src/blackgui/components/settingssimulatorcomponent.ui b/src/blackgui/components/settingssimulatorcomponent.ui index 87d65f238..28731bf34 100644 --- a/src/blackgui/components/settingssimulatorcomponent.ui +++ b/src/blackgui/components/settingssimulatorcomponent.ui @@ -161,21 +161,129 @@ + + + Current rendering restrictions (if any) + + + Restrictions + + + + + + + 4 + + + + + + + + rest.text goes here + + + + + + + + 0 + 0 + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + clear + + + + + + Max.aircraft - + + + 4 + - + + + 100 + + - + + 0 + 0 + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + apply + + + + + + + + + Max.distance (NM) + + + + + + + 4 + + + + + 100 + + + 100 + + + + + + + 0 0 @@ -226,6 +334,12 @@
blackgui/components/settingsfsxcomponent.h
1 + + BlackGui::CLedWidget + QWidget +
blackgui/led.h
+ 1 +
diff --git a/src/blackmisc/audiodeviceinfo.cpp b/src/blackmisc/audiodeviceinfo.cpp index 50a607858..9de0febd6 100644 --- a/src/blackmisc/audiodeviceinfo.cpp +++ b/src/blackmisc/audiodeviceinfo.cpp @@ -28,7 +28,7 @@ namespace BlackMisc /* * Constructor */ - CAudioDeviceInfo::CAudioDeviceInfo(DeviceType type, const qint16 index, const QString &name) : + CAudioDeviceInfo::CAudioDeviceInfo(DeviceType type, const int index, const QString &name) : m_type(type), m_deviceIndex(index), m_deviceName(name), m_hostName(BlackMisc::localHostName()) { @@ -38,8 +38,9 @@ namespace BlackMisc /* * As String */ - QString CAudioDeviceInfo::convertToQString(bool /* i18n */) const + QString CAudioDeviceInfo::convertToQString(bool i18n) const { + Q_UNUSED(i18n); if (this->m_hostName.isEmpty()) return m_deviceName; QString s(this->m_deviceName); s.append(" ["); diff --git a/src/blackmisc/audiodeviceinfo.h b/src/blackmisc/audiodeviceinfo.h index 168a0c73b..a364ebb94 100644 --- a/src/blackmisc/audiodeviceinfo.h +++ b/src/blackmisc/audiodeviceinfo.h @@ -29,7 +29,7 @@ namespace BlackMisc { public: //! Type - enum DeviceType : uint + enum DeviceType { InputDevice, OutputDevice, @@ -44,10 +44,10 @@ namespace BlackMisc CAudioDeviceInfo(); //! Constructor. - CAudioDeviceInfo(DeviceType type, const qint16 index, const QString &getName); + CAudioDeviceInfo(DeviceType type, const int index, const QString &getName); //! Get the device index - qint16 getIndex() const { return m_deviceIndex; } + int getIndex() const { return m_deviceIndex; } //! Get the device name const QString &getName() const { return m_deviceName; } @@ -62,10 +62,10 @@ namespace BlackMisc bool isValid() const { return m_deviceIndex >= -1 && !m_deviceName.isEmpty(); } //! Device index for default device - static qint16 defaultDeviceIndex() {return -1;} + static int defaultDeviceIndex() {return -1;} //! Invalid device index - static qint16 invalidDeviceIndex() {return -2;} + static int invalidDeviceIndex() {return -2;} //! Default output device static CAudioDeviceInfo getDefaultOutputDevice() @@ -91,7 +91,7 @@ namespace BlackMisc * deviceIndex is the number is the reference for the VVL. The device is selected by this index. * The managing class needs to take care, that indexes are valid. */ - qint16 m_deviceIndex; + int m_deviceIndex; //! Device name QString m_deviceName; //! We use a DBus based system. Hence an audio device can reside on a differen computers, this here is its name diff --git a/src/blackmisc/avatcstationlist.h b/src/blackmisc/avatcstationlist.h index c02007fc9..52f98891d 100644 --- a/src/blackmisc/avatcstationlist.h +++ b/src/blackmisc/avatcstationlist.h @@ -12,6 +12,7 @@ #ifndef BLACKMISC_ATCSTATIONLIST_H #define BLACKMISC_ATCSTATIONLIST_H +#include "geoobjectlist.h" #include "nwuserlist.h" #include "avatcstation.h" #include "avcallsignobjectlist.h" @@ -30,7 +31,8 @@ namespace BlackMisc */ class CAtcStationList : public CSequence, - public ICallsignObjectList + public BlackMisc::Aviation::ICallsignObjectList, + public BlackMisc::Geo::IGeoObjectWithRelativePositionList { public: //! Default constructor. diff --git a/src/blackmisc/avcallsignlist.cpp b/src/blackmisc/avcallsignlist.cpp index 194c77443..781a47e91 100644 --- a/src/blackmisc/avcallsignlist.cpp +++ b/src/blackmisc/avcallsignlist.cpp @@ -14,21 +14,12 @@ namespace BlackMisc { namespace Aviation { - /* - * Empty constructor - */ CCallsignList::CCallsignList() { } - /* - * Construct from base class object - */ - CCallsignList::CCallsignList(const CSequence &other) : - CSequence(other) + CCallsignList::CCallsignList(const CCollection &other) : + CCollection(other) { } - /* - * Register metadata - */ void CCallsignList::registerMetadata() { qRegisterMetaType>(); diff --git a/src/blackmisc/avcallsignlist.h b/src/blackmisc/avcallsignlist.h index b5f3d1c4d..da037c181 100644 --- a/src/blackmisc/avcallsignlist.h +++ b/src/blackmisc/avcallsignlist.h @@ -22,14 +22,14 @@ namespace BlackMisc namespace Aviation { //! Value object for a list of callsigns. - class CCallsignList : public CSequence + class CCallsignList : public CCollection { public: //! Default constructor. CCallsignList(); //! Construct from a base class object. - CCallsignList(const CSequence &other); + CCallsignList(const CCollection &other); //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } diff --git a/src/blackmisc/collection.h b/src/blackmisc/collection.h index 3c34800d9..55b9fd290 100644 --- a/src/blackmisc/collection.h +++ b/src/blackmisc/collection.h @@ -44,6 +44,9 @@ namespace BlackMisc //! Initializer list constructor. QOrderedSet(std::initializer_list il) { for (const auto &v : il) { insert(v); } } + + //! Constructor from QList + QOrderedSet(const QList &list) { for (const auto &v : list) { insert(v); }} }; /*! @@ -85,6 +88,11 @@ namespace BlackMisc */ CCollection(const CCollection &other) : m_pimpl(other.pimpl() ? other.pimpl()->clone() : nullptr) {} + /*! + * \brief Constructor from QList. + */ + CCollection(const QList &list) : m_pimpl(new Pimpl>(QOrderedSet(list))) {} + /*! * \brief Move constructor. */ diff --git a/src/blackmisc/geoobjectlist.cpp b/src/blackmisc/geoobjectlist.cpp index ba4b0baa1..564e882a9 100644 --- a/src/blackmisc/geoobjectlist.cpp +++ b/src/blackmisc/geoobjectlist.cpp @@ -71,6 +71,17 @@ namespace BlackMisc this->container().sort([ & ](const OBJ & a, const OBJ & b) { return a.getDistanceToOwnAircraft() < b.getDistanceToOwnAircraft(); }); } + template + CONTAINER IGeoObjectWithRelativePositionList::getClosestObjects(int number) const + { + if (number < 1) { return CONTAINER(); } + if (this->container().size() >= number) { return (this->container()); } + CONTAINER closest(this->container()); + closest.sortByDistanceToOwnAircraft(); + closest.truncate(number); + return closest; + } + // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class IGeoObjectList; diff --git a/src/blackmisc/geoobjectlist.h b/src/blackmisc/geoobjectlist.h index e21d6f2e5..618e1a43b 100644 --- a/src/blackmisc/geoobjectlist.h +++ b/src/blackmisc/geoobjectlist.h @@ -56,6 +56,9 @@ namespace BlackMisc //! If distance is already set, just sort void sortByDistanceToOwnAircraft(); + //! Get n closest objects + CONTAINER getClosestObjects(int number) const; + //! Calculate distances, remove if outside range void removeIfOutsideRange(const BlackMisc::Geo::ICoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &maxDistance, bool updateValues); diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index 341728b7b..5a7b0652a 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -234,6 +234,20 @@ namespace BlackMisc return unit.roundValue(this->value(unit), digits); } + /* + * Value rounded as integer + */ + template int CPhysicalQuantity::valueInteger(const MU &unit) const + { + double v = unit.roundValue(this->value(unit), 0); + return static_cast(v); + } + + template double CPhysicalQuantity::valueRounded(int digits) const + { + return this->valueRounded(this->m_unit, digits); + } + /* * Value in unit */ diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 280380038..5d469502f 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -115,11 +115,11 @@ namespace BlackMisc //! Rounded value in given unit double valueRounded(const MU &unit, int digits = -1) const; + //! As integer value + int valueInteger(const MU &unit) const; + //! Rounded value in current unit - double valueRounded(int digits = -1) const - { - return this->valueRounded(this->m_unit, digits); - } + double valueRounded(int digits = -1) const; //! Value to QString with the given unit, e.g. "5.00m" QString valueRoundedWithUnit(const MU &unit, int digits = -1, bool i18n = false) const; diff --git a/src/plugins/simulator/fs9/simulator_fs9.h b/src/plugins/simulator/fs9/simulator_fs9.h index c8de192aa..20a71f10f 100644 --- a/src/plugins/simulator/fs9/simulator_fs9.h +++ b/src/plugins/simulator/fs9/simulator_fs9.h @@ -74,8 +74,6 @@ namespace BlackSimPlugin //! \copydoc ISimulator::isSimulating virtual bool isSimulating() const override { return isConnected(); } - public slots: - //! \copydoc ISimulator::connectTo() virtual bool connectTo() override; diff --git a/src/plugins/simulator/fscommon/fsuipc.cpp b/src/plugins/simulator/fscommon/fsuipc.cpp index faaaf9ba7..055a33218 100644 --- a/src/plugins/simulator/fscommon/fsuipc.cpp +++ b/src/plugins/simulator/fscommon/fsuipc.cpp @@ -91,31 +91,18 @@ namespace BlackSimPlugin DWORD dwResult; char localFsTimeRaw[3]; char modelNameRaw[256]; - qint16 com1ActiveRaw; - qint16 com2ActiveRaw; - qint16 com1StandbyRaw; - qint16 com2StandbyRaw; - qint16 transponderCodeRaw; - qint8 xpdrModeSb3Raw; - qint8 xpdrIdentSb3Raw; - qint32 groundspeedRaw; - qint32 pitchRaw; - qint32 bankRaw; - qint32 headingRaw; - qint64 altitudeRaw; - qint32 groundAltitudeRaw; - qint64 latitudeRaw; - qint64 longitudeRaw; - qint16 lightsRaw; - qint16 onGroundRaw; - qint32 flapsControlRaw; - qint32 gearControlRaw; - qint32 spoilersControlRaw; - qint16 numberOfEngines; - qint16 engine1CombustionFlag; - qint16 engine2CombustionFlag; - qint16 engine3CombustionFlag; - qint16 engine4CombustionFlag; + qint16 com1ActiveRaw = 0, com2ActiveRaw = 0, com1StandbyRaw = 0, com2StandbyRaw = 0; + qint16 transponderCodeRaw = 0; + qint8 xpdrModeSb3Raw = 0, xpdrIdentSb3Raw = 0; + qint32 groundspeedRaw = 0, pitchRaw = 0, bankRaw = 0, headingRaw = 0; + qint64 altitudeRaw = 0; + qint32 groundAltitudeRaw = 0; + qint64 latitudeRaw = 0, longitudeRaw = 0; + qint16 lightsRaw = 0; + qint16 onGroundRaw = 0; + qint32 flapsControlRaw = 0, gearControlRaw = 0, spoilersControlRaw = 0; + qint16 numberOfEngines = 0; + qint16 engine1CombustionFlag = 0, engine2CombustionFlag = 0, engine3CombustionFlag = 0, engine4CombustionFlag = 0; // http://www.projectmagenta.com/all-fsuipc-offsets/ @@ -198,7 +185,7 @@ namespace BlackSimPlugin com1.setFrequencyStandbyMHz(com1StandbyRaw / 100.0); com2.setFrequencyStandbyMHz(com2StandbyRaw / 100.0); - transponderCodeRaw = CBcdConversions::bcd2Dec(transponderCodeRaw); + transponderCodeRaw = static_cast(CBcdConversions::bcd2Dec(transponderCodeRaw)); xpdr.setTransponderCode(transponderCodeRaw); // Mode by SB3 if (xpdrIdentSb3Raw != 0) diff --git a/src/plugins/simulator/fscommon/simulator_fscommon.h b/src/plugins/simulator/fscommon/simulator_fscommon.h index 90d4f618c..ff64e1877 100644 --- a/src/plugins/simulator/fscommon/simulator_fscommon.h +++ b/src/plugins/simulator/fscommon/simulator_fscommon.h @@ -42,8 +42,6 @@ namespace BlackSimPlugin //! SimObjects directory static QString simObjectsDir(); - public slots: - //! \copydoc ISimulator::isPaused virtual bool isPaused() const override { return m_simPaused; } diff --git a/src/plugins/simulator/fsx/simulator_fsx.h b/src/plugins/simulator/fsx/simulator_fsx.h index 7f06b1ad2..e0d3ddad1 100644 --- a/src/plugins/simulator/fsx/simulator_fsx.h +++ b/src/plugins/simulator/fsx/simulator_fsx.h @@ -93,8 +93,6 @@ namespace BlackSimPlugin //! SimConnect Callback static void CALLBACK SimConnectProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext); - public slots: - //! \copydoc ISimulator::connectTo() virtual bool connectTo() override; diff --git a/src/plugins/simulator/xplane/simulator_xplane.h b/src/plugins/simulator/xplane/simulator_xplane.h index da98d97ce..a94353b9c 100644 --- a/src/plugins/simulator/xplane/simulator_xplane.h +++ b/src/plugins/simulator/xplane/simulator_xplane.h @@ -58,7 +58,6 @@ namespace BlackSimPlugin //! \copydoc BlackCore::ISimulator::getIcaoForModelString virtual BlackMisc::Aviation::CAircraftIcao getIcaoForModelString(const QString &modelString) const override; - public slots: //! \copydoc BlackCore::ISimulator::connectTo virtual bool connectTo() override;