diff --git a/src/blackgui/components/interpolationlogdisplay.cpp b/src/blackgui/components/interpolationlogdisplay.cpp
index bfe4ef068..12935673c 100644
--- a/src/blackgui/components/interpolationlogdisplay.cpp
+++ b/src/blackgui/components/interpolationlogdisplay.cpp
@@ -11,6 +11,7 @@
#include "ui_interpolationlogdisplay.h"
#include "blackgui/guiapplication.h"
#include "blackcore/context/contextnetworkimpl.h"
+#include "blackcore/context/contextsimulator.h"
#include "blackcore/airspacemonitor.h"
#include "blackmisc/simulation/interpolationlogger.h"
#include "blackmisc/stringutils.h"
@@ -30,6 +31,7 @@ namespace BlackGui
{
CInterpolationLogDisplay::CInterpolationLogDisplay(QWidget *parent) :
COverlayMessagesFrame(parent),
+ CIdentifiable(this),
ui(new Ui::CInterpolationLogDisplay)
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui");
@@ -53,6 +55,7 @@ namespace BlackGui
connect(ui->hs_UpdateTime, &QSlider::valueChanged, this, &CInterpolationLogDisplay::onSliderChanged);
connect(ui->pb_StartStop, &QPushButton::released, this, &CInterpolationLogDisplay::toggleStartStop);
connect(ui->pb_ResetStats, &QPushButton::released, this, &CInterpolationLogDisplay::resetStatistics);
+ connect(ui->pb_ShowInSimulator, &QPushButton::released, this, &CInterpolationLogDisplay::showLogInSimulator);
connect(ui->pb_GetLastInterpolation, &QPushButton::released, this, &CInterpolationLogDisplay::displayLastInterpolation);
connect(sGui, &CGuiApplication::aboutToShutdown, this, &CInterpolationLogDisplay::onAboutToShutdown);
}
@@ -94,15 +97,7 @@ namespace BlackGui
void CInterpolationLogDisplay::updateLog()
{
- if (!sGui || sGui->isShuttingDown()) { return; }
- if (!this->isVisible()) { return; }
- const bool hasLogger = m_airspaceMonitor && m_simulatorCommon && m_simulatorCommon->isConnected() && !m_simulatorCommon->isShuttingDown();
- if (!hasLogger || m_callsign.isEmpty())
- {
- ui->te_TextLog->setText("No logger attached or no callsign");
- this->stop();
- this->clear();
- }
+ if (!this->checkLogPrerequisites()) { return; }
// only display visible tab
if (ui->tw_LogTabs->currentWidget() == ui->tb_TextLog)
@@ -130,19 +125,7 @@ namespace BlackGui
void CInterpolationLogDisplay::displayLastInterpolation()
{
- if (!sApp || sApp->isShuttingDown() || !m_airspaceMonitor || !m_simulatorCommon) { return; }
- if (m_callsign.isEmpty())
- {
- static const CStatusMessage m = CStatusMessage(this).validationError("No callsign");
- this->showOverlayMessage(m);
- return;
- }
- if (!m_simulatorCommon->getLogCallsigns().contains(m_callsign))
- {
- static const CStatusMessage m = CStatusMessage(this).validationError("No logger attached, start logging");
- this->showOverlayMessage(m);
- return;
- }
+ if (!this->checkLogPrerequisites()) { return; }
const SituationLog sLog = m_simulatorCommon->interpolationLogger().getLastSituationLog();
// ui->te_LastInterpolatedSituation->setText(sLog.toQString(false, true, true, false, "
"));
@@ -198,12 +181,31 @@ namespace BlackGui
else { this->start(); }
}
+ void CInterpolationLogDisplay::showLogInSimulator()
+ {
+ if (m_callsign.isEmpty()) { return; }
+ if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; }
+
+ const QString cmd = QStringLiteral(".drv pos ") + m_callsign.asString();
+ sGui->getIContextSimulator()->parseCommandLine(cmd, this->identifier());
+ }
+
void CInterpolationLogDisplay::start()
{
- const int interval = ui->hs_UpdateTime->value() * 1000;
+ if (m_updateTimer.isActive()) { return; }
+ const int interval = 1000 * ui->hs_UpdateTime->value();
m_updateTimer.start(interval);
ui->pb_StartStop->setText(stopText());
ui->led_Running->setOn(true);
+
+ // it can take a while until we receive parts, so we init
+ QPointer myself(this);
+ QTimer::singleShot(250, this, [ = ]
+ {
+ if (!myself) { return; }
+ if (m_callsign.isEmpty()) { return; }
+ myself->onPartsAdded(m_callsign, CAircraftParts());
+ });
}
void CInterpolationLogDisplay::stop()
@@ -296,6 +298,43 @@ namespace BlackGui
m_elvReceived = m_elvRequested = 0;
}
+ bool CInterpolationLogDisplay::checkLogPrerequisites()
+ {
+ CStatusMessage m;
+ do
+ {
+ if (!this->isVisible()) { return false; } // silently return
+ if (!sApp || sApp->isShuttingDown()) { break; } // stop and return
+ if (m_callsign.isEmpty())
+ {
+ static const CStatusMessage ms = CStatusMessage(this).validationError("No callsign");
+ m = ms;
+ break;
+ }
+
+ const bool canUpdateLog = m_airspaceMonitor && m_simulatorCommon && m_simulatorCommon->isConnected() && !m_simulatorCommon->isShuttingDown();
+ if (!canUpdateLog)
+ {
+ static const CStatusMessage ms = CStatusMessage(this).validationError("No airspace monitor or simulator or shutting down");
+ m = ms;
+ break;
+ }
+
+ if (!m_simulatorCommon->getLogCallsigns().contains(m_callsign))
+ {
+ static const CStatusMessage ms = CStatusMessage(this).validationError("No longer logging callsign");
+ m = ms;
+ break;
+ }
+ return true;
+ }
+ while (false);
+
+ this->stop();
+ if (!m.isEmpty()) { this->showOverlayMessage(m); }
+ return false;
+ }
+
void CInterpolationLogDisplay::linkWithAirspaceMonitor()
{
if (!sGui || sGui->isShuttingDown() || !sGui->supportsContexts()) { return; }
diff --git a/src/blackgui/components/interpolationlogdisplay.h b/src/blackgui/components/interpolationlogdisplay.h
index 101a8e0f0..c37c9fea1 100644
--- a/src/blackgui/components/interpolationlogdisplay.h
+++ b/src/blackgui/components/interpolationlogdisplay.h
@@ -16,6 +16,7 @@
#include "blackgui/blackguiexport.h"
#include "blackcore/simulatorcommon.h"
#include "blackmisc/aviation/callsign.h"
+#include "blackmisc/identifiable.h"
#include
#include
#include
@@ -30,7 +31,9 @@ namespace BlackGui
/**
* Display live data of interpolation
*/
- class BLACKGUI_EXPORT CInterpolationLogDisplay : public COverlayMessagesFrame
+ class BLACKGUI_EXPORT CInterpolationLogDisplay :
+ public COverlayMessagesFrame,
+ public BlackMisc::CIdentifiable
{
Q_OBJECT
@@ -74,6 +77,9 @@ namespace BlackGui
//! Toggle start/stop
void toggleStartStop();
+ //! Display log in simulator
+ void showLogInSimulator();
+
//! Start displaying
void start();
@@ -110,6 +116,9 @@ namespace BlackGui
//! Clear
void clear();
+ //! Check if can do logging, otherwise stop and display message
+ bool checkLogPrerequisites();
+
QScopedPointer ui;
QTimer m_updateTimer;
QPointer m_simulatorCommon; //!< related simulator
diff --git a/src/blackgui/components/interpolationlogdisplay.ui b/src/blackgui/components/interpolationlogdisplay.ui
index 328f82bd7..7d85ae5b3 100644
--- a/src/blackgui/components/interpolationlogdisplay.ui
+++ b/src/blackgui/components/interpolationlogdisplay.ui
@@ -31,7 +31,7 @@
Log. callsign
-
+
3
@@ -84,10 +84,17 @@
+ -
+
+
+ show in sim.
+
+
+
-
- Start
+ start
diff --git a/src/blackmisc/identifiable.h b/src/blackmisc/identifiable.h
index 1dc5eb5a1..f7567389b 100644
--- a/src/blackmisc/identifiable.h
+++ b/src/blackmisc/identifiable.h
@@ -45,7 +45,7 @@ namespace BlackMisc
//! Use literal based object name
CIdentifiable(const QString &objectName) : m_identifier(objectName) {}
- //! Connect with QObject providing then name
+ //! Connect with QObject providing the name
CIdentifiable(QObject *nameProvider);
//! Destructor