Ref T270, log display can trigger display in sim and further improvements

* log display can trigger displayed log in simulator
* check prerequisites for log and display overlay
* made component identifiable
* pre-load parts
This commit is contained in:
Klaus Basan
2018-06-02 02:03:33 +02:00
parent c750ad1dfc
commit 84428b1284
4 changed files with 82 additions and 27 deletions

View File

@@ -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, "<br>"));
@@ -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<CInterpolationLogDisplay> 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; }

View File

@@ -16,6 +16,7 @@
#include "blackgui/blackguiexport.h"
#include "blackcore/simulatorcommon.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/identifiable.h"
#include <QFrame>
#include <QTimer>
#include <QScopedPointer>
@@ -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::CInterpolationLogDisplay> ui;
QTimer m_updateTimer;
QPointer<BlackCore::CSimulatorCommon> m_simulatorCommon; //!< related simulator

View File

@@ -31,7 +31,7 @@
<property name="title">
<string>Log. callsign</string>
</property>
<layout class="QHBoxLayout" name="hl_LogCallsign" stretch="2,1,4,0,1">
<layout class="QHBoxLayout" name="hl_LogCallsign" stretch="2,1,4,0,0,1">
<property name="leftMargin">
<number>3</number>
</property>
@@ -84,10 +84,17 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_ShowInSimulator">
<property name="text">
<string>show in sim.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_StartStop">
<property name="text">
<string>Start</string>
<string>start</string>
</property>
</widget>
</item>