diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 2ee2ddf66..0c64fbcb0 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -122,7 +122,7 @@ namespace BlackCore bool ISimulator::followAircraft(const CCallsign &callsign) { - Q_UNUSED(callsign); + Q_UNUSED(callsign) return false; } @@ -1160,7 +1160,7 @@ namespace BlackCore void ISimulator::onOwnModelChanged(const CAircraftModel &newModel) { - Q_UNUSED(newModel); + Q_UNUSED(newModel) // can be overridden } @@ -1190,7 +1190,7 @@ namespace BlackCore const CLength radius = settings.getRecordedGndRadius().isNull() ? CElevationPlane::singlePointRadius() : settings.getRecordedGndRadius(); const CElevationPlane ep(situation, radius); const bool remembered = this->rememberGroundElevation(cs, ep, radius); - Q_UNUSED(remembered); // false means it was already in that cache, or something else is wrong + Q_UNUSED(remembered) // false means it was already in that cache, or something else is wrong } } } diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 8eaee10df..37f934aa8 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -209,10 +209,10 @@ namespace BlackCore //! Simulator running? virtual bool isSimulating() const { return this->isConnected(); } - //! Set test mode + //! Set test mode (driver can skip code parts etc., driver dependent) void setTestMode(bool test) { m_test = test; } - //! Test mode? + //! Test mode? (driver can skip code parts etc., driver dependent) bool isTestMode() const { return m_test; } //! Average FPS (frames per second) @@ -230,6 +230,9 @@ namespace BlackCore //! Send situation/parts for testing virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) = 0; + //! Enable pseudo elevations (testing) + void setTestEnablePseudoElevation(bool enable) { m_enablePseudoElevation = enable; } + //! Debug function to check state after all aircraft have been removed //! \remarks only in local developer builds virtual BlackMisc::CStatusMessageList debugVerifyStateAfterAllAircraftRemoved() const; @@ -583,6 +586,7 @@ namespace BlackCore bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold) bool m_updateRemoteAircraftInProgress = false; //!< currently updating remote aircraft + bool m_enablePseudoElevation = false; //!< return faked elevations (testing) int m_timerId = -1; //!< dispatch timer id int m_statsUpdateAircraftRuns = 0; //!< statistics update count int m_statsUpdateAircraftLimited = 0; //!< skipped because of max.update limitations diff --git a/src/blackgui/components/interpolationlogdisplay.cpp b/src/blackgui/components/interpolationlogdisplay.cpp index db3634794..2488ea97b 100644 --- a/src/blackgui/components/interpolationlogdisplay.cpp +++ b/src/blackgui/components/interpolationlogdisplay.cpp @@ -16,6 +16,8 @@ #include "blackmisc/timestampobjectlist.h" #include "blackmisc/stringutils.h" +#include + using namespace BlackCore; using namespace BlackCore::Context; using namespace BlackGui::Views; @@ -44,7 +46,7 @@ namespace BlackGui ui->hs_UpdateTime->setValue(timeSecs); this->onSliderChanged(timeSecs); - CLedWidget::LedShape shape = CLedWidget::Rounded; + const CLedWidget::LedShape shape = CLedWidget::Rounded; ui->led_Parts->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Parts received", "", 14); ui->led_Situation->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Situation received", "", 14); ui->led_Elevation->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Elevation received", "", 14); @@ -54,6 +56,14 @@ namespace BlackGui m_callsign = ui->comp_CallsignCompleter->getCallsign(); ui->tvp_InboundAircraftSituations->setWithMenuRequestElevation(true); + m_elvHistoryModel = new QStringListModel(this); + ui->lv_ElevevationHistory->setModel(m_elvHistoryModel); + ui->lv_ElevevationHistory->setEditTriggers(QAbstractItemView::NoEditTriggers); + + const int elvHistoryCount = 100; + m_elvHistoryCount = elvHistoryCount; + ui->le_ElvHistoryCount->setText(QString::number(elvHistoryCount)); + connect(&m_updateTimer, &QTimer::timeout, this, &CInterpolationLogDisplay::updateLog); connect(ui->comp_CallsignCompleter, &CCallsignCompleter::editingFinishedDigest, this, &CInterpolationLogDisplay::onCallsignEntered); connect(ui->hs_UpdateTime, &QSlider::valueChanged, this, &CInterpolationLogDisplay::onSliderChanged); @@ -66,9 +76,12 @@ namespace BlackGui connect(ui->pb_RequestElevation2, &QPushButton::released, this, &CInterpolationLogDisplay::requestElevationClicked); connect(ui->pb_GetLastInterpolation, &QPushButton::released, this, &CInterpolationLogDisplay::getLogAmdDisplayLastInterpolation); connect(ui->pb_InjectElevation, &QPushButton::released, this, &CInterpolationLogDisplay::onInjectElevation); + connect(ui->pb_ElvClear, &QPushButton::released, this, &CInterpolationLogDisplay::clearElevationResults); connect(ui->tvp_InboundAircraftSituations, &CAircraftSituationView::requestElevation, this, &CInterpolationLogDisplay::requestElevation); - connect(ui->le_InjectElevation, &QLineEdit::returnPressed, this, &CInterpolationLogDisplay::onInjectElevation); + connect(ui->le_InjectElevation, &QLineEdit::returnPressed, this, &CInterpolationLogDisplay::onInjectElevation); + connect(ui->le_ElvHistoryCount, &QLineEdit::editingFinished, this, &CInterpolationLogDisplay::onElevationHistoryCountFinished); connect(ui->editor_ElevationCoordinate, &CCoordinateForm::changedCoordinate, this, &CInterpolationLogDisplay::requestElevationAtPosition); + connect(ui->cb_ElvAllowPseudo, &QCheckBox::toggled, this, &CInterpolationLogDisplay::onPseudoElevationToggled); connect(sGui, &CGuiApplication::aboutToShutdown, this, &CInterpolationLogDisplay::onAboutToShutdown, Qt::QueuedConnection); } @@ -228,6 +241,12 @@ namespace BlackGui } } + void CInterpolationLogDisplay::onPseudoElevationToggled(bool checked) + { + if (!m_simulator) { return; } + m_simulator->setTestEnablePseudoElevation(checked); + } + void CInterpolationLogDisplay::toggleStartStop() { const bool running = m_updateTimer.isActive(); @@ -240,7 +259,7 @@ namespace BlackGui if (m_callsign.isEmpty()) { return; } if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } - const QString cmd = QStringLiteral(".drv pos ") + m_callsign.asString(); + const QString cmd = QStringLiteral(".drv pos ") % m_callsign.asString(); sGui->getIContextSimulator()->parseCommandLine(cmd, this->identifier()); } @@ -294,7 +313,7 @@ namespace BlackGui void CInterpolationLogDisplay::onSimulatorStatusChanged(ISimulator::SimulatorStatus status) { - Q_UNUSED(status); + Q_UNUSED(status) m_updateTimer.stop(); this->resetStatistics(); } @@ -327,6 +346,23 @@ namespace BlackGui void CInterpolationLogDisplay::onElevationReceived(const CElevationPlane &elevationPlane, const CCallsign &callsign) { m_elvReceived++; + + if (m_elvHistoryCount > 0) + { + const QString history = callsign.asString() % + QStringLiteral(": ") % QTime::currentTime().toString("hh:mm:ss.zzz") % + QStringLiteral(" ") % elevationPlane.toQString(true); + m_elvHistoryModel->insertRow(0); + const QModelIndex index = m_elvHistoryModel->index(0, 0); + m_elvHistoryModel->setData(index, history); + + const int c = m_elvHistoryModel->rowCount(); + if (m_elvHistoryCount < c) + { + m_elvHistoryModel->removeRows(m_elvHistoryCount, c - m_elvHistoryCount); + } + } + if (callsign == CInterpolationLogDisplay::pseudoCallsignElevation()) { this->displayArbitraryElevation(elevationPlane); @@ -364,6 +400,19 @@ namespace BlackGui m_simulator->callbackReceivedRequestedElevation(ep, m_callsign); } + void CInterpolationLogDisplay::onElevationHistoryCountFinished() + { + const QString cs = ui->le_ElvHistoryCount->text().trimmed(); + int c = -1; + if (!cs.isEmpty()) + { + bool ok = false; + const int cc = cs.toInt(&ok); + if (ok) { c = cc; } + } + m_elvHistoryCount = c; + } + void CInterpolationLogDisplay::resetStatistics() { if (m_simulator) { m_simulator->resetAircraftStatistics(); } @@ -388,6 +437,17 @@ namespace BlackGui ui->le_Limited->clear(); m_elvReceived = m_elvRequested = 0; m_lastInterpolations.clear(); + + this->clearElevationResults(); + } + + void CInterpolationLogDisplay::clearElevationResults() + { + ui->pte_ElevationAtPosition->clear(); + if (m_elvHistoryModel) + { + m_elvHistoryModel->removeRows(0, m_elvHistoryModel->rowCount()); + } } bool CInterpolationLogDisplay::checkLogPrerequisites() diff --git a/src/blackgui/components/interpolationlogdisplay.h b/src/blackgui/components/interpolationlogdisplay.h index a7c92972c..bbd163a1b 100644 --- a/src/blackgui/components/interpolationlogdisplay.h +++ b/src/blackgui/components/interpolationlogdisplay.h @@ -18,6 +18,8 @@ #include "blackmisc/aviation/aircraftsituationlist.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/identifiable.h" + +#include #include #include #include @@ -84,6 +86,9 @@ namespace BlackGui //! Callsign has been changed void onCallsignEntered(); + //! Use pseudo elevation + void onPseudoElevationToggled(bool checked); + //! Toggle start/stop void toggleStartStop(); @@ -126,6 +131,9 @@ namespace BlackGui //! Call the callback of requested elevations as it would come from the simulator void onInjectElevation(); + //! Entering a count failed + void onElevationHistoryCountFinished(); + //! \copydoc BlackCore::ISimulator::resetAircraftStatistics void resetStatistics(); @@ -135,6 +143,10 @@ namespace BlackGui //! Clear void clear(); + //! Clear elevation results + void clearElevationResults(); + + //! Check if can do logging, otherwise stop and display message bool checkLogPrerequisites(); @@ -165,8 +177,10 @@ namespace BlackGui QPointer m_airspaceMonitor; //!< related airspace monitor BlackMisc::Aviation::CAircraftSituationList m_lastInterpolations; //!< list of last interpolations BlackMisc::Aviation::CCallsign m_callsign; //!< current callsign - int m_elvRequested = 0; //!< counted via signal - int m_elvReceived = 0; //!< counted via signal + int m_elvRequested = 0; //!< counted via signal + int m_elvReceived = 0; //!< counted via signal + int m_elvHistoryCount = -1; //!< how many in history + QStringListModel *m_elvHistoryModel = nullptr; static const QString &startText(); static const QString &stopText(); diff --git a/src/blackgui/components/interpolationlogdisplay.ui b/src/blackgui/components/interpolationlogdisplay.ui index c89ff38a5..acdfc9d40 100644 --- a/src/blackgui/components/interpolationlogdisplay.ui +++ b/src/blackgui/components/interpolationlogdisplay.ui @@ -860,14 +860,89 @@ Result - - + + true + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + clear + + + + + + + history + + + + + + + + 100 + 16777215 + + + + 0 + + + 6 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + fake elevation + + + + + + diff --git a/src/plugins/simulator/emulated/simulatoremulated.cpp b/src/plugins/simulator/emulated/simulatoremulated.cpp index e5bcfda08..5c33a5041 100644 --- a/src/plugins/simulator/emulated/simulatoremulated.cpp +++ b/src/plugins/simulator/emulated/simulatoremulated.cpp @@ -10,7 +10,11 @@ #include "blackgui/guiapplication.h" #include "blackcore/context/contextsimulator.h" #include "blackmisc/simulation/simulatorplugininfo.h" +#include "blackmisc/aviation/altitude.h" +#include "blackmisc/math/mathutils.h" +#include +#include #include using namespace BlackGui; @@ -19,6 +23,7 @@ using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; using namespace BlackMisc::Network; +using namespace BlackMisc::Math; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::Settings; using namespace BlackMisc::Weather; @@ -204,6 +209,30 @@ namespace BlackSimPlugin return true; } + bool CSimulatorEmulated::requestElevation(const ICoordinateGeodetic &reference, const CCallsign &callsign) + { + const bool hasRequested = CSimulatorPluginCommon::requestElevation(reference, callsign); + if (hasRequested || !m_enablePseudoElevation) { return hasRequested; } + + // For TESTING purposes ONLY + // we could not request elevation + // very crude 1st implementation + const double elvRnd = CMathUtils::randomDouble(1000); + const CAltitude alt(elvRnd, CLengthUnit::ft()); + CElevationPlane elv(reference, CElevationPlane::singlePointRadius()); + elv.setGeodeticHeight(alt); + + QPointer myself(this); + QTimer::singleShot(444, this, [ = ] + { + if (!myself) { return; } + emit myself->receivedRequestedElevation(elv, callsign); + }); + + emit this->requestedElevation(callsign); + return true; + } + void CSimulatorEmulated::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime) { if (canLog()) { m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, aircraftToHighlight.toQString(), boolToTrueFalse(enableHighlight), displayTime.toQString()); } @@ -348,8 +377,8 @@ namespace BlackSimPlugin // debugging/logging (just here for debugging purposes) const CAircraftModel networkModel = remoteAircraft.getNetworkModel(); const CAircraftModel currentModel = remoteAircraft.getModel(); - Q_UNUSED(networkModel); - Q_UNUSED(currentModel); + Q_UNUSED(networkModel) + Q_UNUSED(currentModel) return true; } @@ -513,8 +542,8 @@ namespace BlackSimPlugin const CAircraftParts p = result; m_countInterpolatedParts++; m_countInterpolatedSituations++; - Q_UNUSED(s); - Q_UNUSED(p); + Q_UNUSED(s) + Q_UNUSED(p) } this->finishUpdateRemoteAircraftAndSetStatistics(now); diff --git a/src/plugins/simulator/emulated/simulatoremulated.h b/src/plugins/simulator/emulated/simulatoremulated.h index 61fcf82df..5b29aeae5 100644 --- a/src/plugins/simulator/emulated/simulatoremulated.h +++ b/src/plugins/simulator/emulated/simulatoremulated.h @@ -70,6 +70,7 @@ namespace BlackSimPlugin virtual BlackMisc::Aviation::CCallsignSet physicallyRenderedAircraft() const override; virtual BlackMisc::CStatusMessageList getInterpolationMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) override; + virtual bool requestElevation(const BlackMisc::Geo::ICoordinateGeodetic &reference, const BlackMisc::Aviation::CCallsign &callsign) override; // ----- functions just logged ------- virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override;