From 273427d3d92a7d7c14ffedff59fce9a07bc35b6e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 1 Feb 2017 02:52:27 +0100 Subject: [PATCH] refs #873, updated internals component * can trigger request of parts * opening logs * update parts in UI from aircraft --- .../components/internalscomponent.cpp | 83 ++++- src/blackgui/components/internalscomponent.h | 10 +- src/blackgui/components/internalscomponent.ui | 294 +++++++++++++----- src/blackmisc/simulation/interpolator.cpp | 20 ++ src/blackmisc/simulation/interpolator.h | 16 +- 5 files changed, 321 insertions(+), 102 deletions(-) diff --git a/src/blackgui/components/internalscomponent.cpp b/src/blackgui/components/internalscomponent.cpp index 98b658f1e..77352da13 100644 --- a/src/blackgui/components/internalscomponent.cpp +++ b/src/blackgui/components/internalscomponent.cpp @@ -16,11 +16,12 @@ #include "blackgui/components/remoteaircraftselector.h" #include "blackgui/guiapplication.h" #include "blackgui/uppercasevalidator.h" +#include "blackmisc/simulation/interpolationlogger.h" +#include "blackmisc/simulation/interpolationrenderingsetup.h" #include "blackmisc/aviation/aircraftenginelist.h" #include "blackmisc/aviation/aircraftlights.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/network/textmessage.h" - #include "blackmisc/logmessage.h" #include "blackmisc/statusmessage.h" #include "ui_internalscomponent.h" @@ -34,6 +35,7 @@ #include #include #include +#include using namespace BlackMisc; using namespace BlackMisc::Aviation; @@ -52,6 +54,7 @@ namespace BlackGui { ui->setupUi(this); ui->tw_Internals->setCurrentIndex(0); + ui->comp_RemoteAircraftSelector->indicatePartsEnabled(true); ui->le_TxtMsgFrom->setValidator(new CUpperCaseValidator(ui->le_TxtMsgFrom)); ui->le_TxtMsgTo->setValidator(new CUpperCaseValidator(ui->le_TxtMsgFrom)); @@ -63,6 +66,7 @@ namespace BlackGui connect(ui->pb_AircraftPartsEnginesOn, &QPushButton::pressed, this, &CInternalsComponent::ps_setAllEngines); connect(ui->pb_AircraftPartsEnginesOff, &QPushButton::pressed, this, &CInternalsComponent::ps_setAllEngines); connect(ui->pb_AircraftPartsUiToJson, &QPushButton::pressed, this, &CInternalsComponent::ps_guiToJson); + connect(ui->pb_CurrentParts, &QPushButton::pressed, this, &CInternalsComponent::ps_setCurrentParts); connect(ui->cb_DebugContextAudio, &QCheckBox::stateChanged, this, &CInternalsComponent::ps_enableDebug); connect(ui->cb_DebugContextApplication, &QCheckBox::stateChanged, this, &CInternalsComponent::ps_enableDebug); @@ -78,6 +82,10 @@ namespace BlackGui connect(ui->tb_LogStatusMessage, &QPushButton::pressed, this, &CInternalsComponent::ps_logStatusMessage); connect(ui->le_StatusMessage, &QLineEdit::returnPressed, this, &CInternalsComponent::ps_logStatusMessage); + connect(ui->pb_LatestInterpolationLog, &QPushButton::pressed, this, &CInternalsComponent::ps_showLogFiles); + connect(ui->pb_LatestPartsLog, &QPushButton::pressed, this, &CInternalsComponent::ps_showLogFiles); + connect(ui->pb_RequestFromNetwork, &QPushButton::pressed, this, &CInternalsComponent::ps_requestPartsFromNetwork); + contextFlagsToGui(); } @@ -98,7 +106,7 @@ namespace BlackGui CLogMessage(this).validationError("Cannot send aircraft parts, network not connected"); return; } - CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); if (callsign.isEmpty()) { CLogMessage(this).validationError("No valid callsign selected"); @@ -106,7 +114,7 @@ namespace BlackGui } CAircraftParts parts; - bool json = (QObject::sender() == ui->pb_SendAircraftPartsJson); + const bool json = (QObject::sender() == ui->pb_SendAircraftPartsJson); if (json) { @@ -141,6 +149,7 @@ namespace BlackGui this->ps_guiToJson(); } + ui->tb_History->setToolTip(""); sGui->getIContextNetwork()->testAddAircraftParts(callsign, parts, ui->cb_AircraftPartsIncremental->isChecked()); CLogMessage(this).info("Added parts for %1") << callsign.toQString(); } @@ -169,11 +178,30 @@ namespace BlackGui void CInternalsComponent::ps_guiToJson() { - QJsonDocument json(guiToAircraftParts().toJson()); + const QJsonDocument json(guiToAircraftParts().toJson()); QString j(json.toJson(QJsonDocument::Indented)); ui->te_AircraftPartsJson->setText(j); } + void CInternalsComponent::ps_setCurrentParts() + { + if (!sGui->getIContextNetwork()->isConnected()) { return; } + const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + if (callsign.isEmpty()) { return; } + + const CAircraftPartsList partsList = sGui->getIContextNetwork()->getRemoteAircraftParts(callsign, -1); + if (partsList.isEmpty()) + { + CStatusMessage(this).info("No parts for '%1'") << callsign.asString(); + return; + } + const CAircraftParts parts = partsList.latestObject(); + const CStatusMessageList history = sGui->getIContextNetwork()->getAircraftPartsHistory(callsign); + partsToGui(parts); + ui->te_AircraftPartsJson->setText(parts.toJsonString()); + ui->tb_History->setToolTip(history.toHtml()); + } + void CInternalsComponent::ps_enableDebug(int state) { Q_ASSERT(sGui->getIContextApplication()); @@ -182,9 +210,9 @@ namespace BlackGui Q_ASSERT(sGui->getIContextOwnAircraft()); Q_ASSERT(sGui->getIContextSimulator()); - Qt::CheckState checkState = static_cast(state); - bool debug = (checkState == Qt::Checked); - QObject *sender = QObject::sender(); + const Qt::CheckState checkState = static_cast(state); + const bool debug = (checkState == Qt::Checked); + const QObject *sender = QObject::sender(); if (sender == ui->cb_DebugContextApplication) { sGui->getIContextApplication()->setDebugEnabled(debug); } else if (sender == ui->cb_DebugContextAudio) { sGui->getIContextAudio()->setDebugEnabled(debug); } @@ -247,9 +275,46 @@ namespace BlackGui CLogMessage::preformatted(sm); } + void CInternalsComponent::ps_showLogFiles() + { + QString file; + const QObject *sender = QObject::sender(); + if (sender == ui->pb_LatestInterpolationLog) + { + file = CInterpolationLogger::getLatestLogFiles().first(); + } + else if (sender == ui->pb_LatestPartsLog) + { + file = CInterpolationLogger::getLatestLogFiles().last(); + } + + if (file.isEmpty()) { return; } + QDesktopServices::openUrl(QUrl::fromLocalFile(file)); + } + + void CInternalsComponent::ps_requestPartsFromNetwork() + { + const CCallsign callsign(ui->comp_RemoteAircraftSelector->getSelectedCallsign()); + if (callsign.isEmpty()) + { + CLogMessage(this).validationError("No valid callsign selected"); + return; + } + ui->pb_RequestFromNetwork->setEnabled(false); + sGui->getIContextNetwork()->testRequestAircraftConfig(callsign); + CLogMessage(this).info("Request aircraft config for '%1'") << callsign.asString(); + + // simple approach to update UI when parts are received + QTimer::singleShot(3000, this, [this] + { + ui->pb_CurrentParts->click(); + ui->pb_RequestFromNetwork->setEnabled(true); + }); + } + CAircraftParts CInternalsComponent::guiToAircraftParts() const { - CAircraftLights lights( + const CAircraftLights lights( ui->cb_AircraftPartsLightsStrobe->isChecked(), ui->cb_AircraftPartsLightsLanding->isChecked(), ui->cb_AircraftPartsLightsTaxi->isChecked(), @@ -257,7 +322,7 @@ namespace BlackGui ui->cb_AircraftPartsLightsNav->isChecked(), ui->cb_AircraftPartsLightsLogo->isChecked() ); - CAircraftEngineList engines( + const CAircraftEngineList engines( { ui->cb_AircraftPartsEngine1->isChecked(), ui->cb_AircraftPartsEngine2->isChecked(), diff --git a/src/blackgui/components/internalscomponent.h b/src/blackgui/components/internalscomponent.h index 52c2e7940..9a35b6096 100644 --- a/src/blackgui/components/internalscomponent.h +++ b/src/blackgui/components/internalscomponent.h @@ -57,6 +57,9 @@ namespace BlackGui //! GUI to JSON void ps_guiToJson(); + //! Current parts in UI + void ps_setCurrentParts(); + //! Enable / disable debugging void ps_enableDebug(int state); @@ -66,6 +69,12 @@ namespace BlackGui //! Send a dummy status message void ps_logStatusMessage(); + //! Show log files + void ps_showLogFiles(); + + //! Request parts (aka aircraft config) from network + void ps_requestPartsFromNetwork(); + private: QScopedPointer ui; @@ -78,7 +87,6 @@ namespace BlackGui //! Set the context flags void contextFlagsToGui(); }; - } // namespace } // namespace diff --git a/src/blackgui/components/internalscomponent.ui b/src/blackgui/components/internalscomponent.ui index 2e5105913..ec425f66c 100644 --- a/src/blackgui/components/internalscomponent.ui +++ b/src/blackgui/components/internalscomponent.ui @@ -6,8 +6,8 @@ 0 0 - 289 - 450 + 314 + 590 @@ -57,6 +57,18 @@ Contexts + + 4 + + + 4 + + + 4 + + + 4 + @@ -74,7 +86,7 @@ - Own aircraftt + Own aircraft @@ -101,6 +113,18 @@ Driver plugin and interpolator + + 4 + + + 4 + + + 4 + + + 4 + @@ -129,10 +153,22 @@ - + + + Status message + - 3 + 4 + + + 4 + + + 4 + + + 4 @@ -180,15 +216,38 @@ - + + + Text message + - 3 + 4 - 9 + 4 - + + 4 + + + 4 + + + + + send + + + + + + + from + + + + MHz @@ -210,35 +269,14 @@ - - - - send - - - - - - - Text messages: - - - - - - - from - - - - + to - + Text message @@ -265,21 +303,42 @@ - Statistics + Statistics / Logs - - - - 80 - 60 - 267 - 13 - - - - WORK IN PROGRESS! - - + + + + + + + Latest interpolation log + + + + + + + show + + + + + + + Latest parts log + + + + + + + show + + + + + + @@ -301,6 +360,12 @@ + + 4 + + + 4 + 2 @@ -330,6 +395,52 @@ + + + + Network + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Request from network + + + request (network) + + + + + + + + + + + :/diagona/icons/diagona/icons/table-sheet.png:/diagona/icons/diagona/icons/table-sheet.png + + + + + + @@ -391,7 +502,7 @@ - 6 + 4 @@ -400,6 +511,13 @@ + + + + Beacon + + + @@ -421,13 +539,6 @@ - - - - Beacon - - - @@ -435,13 +546,6 @@ - - - - Spoilers - - - @@ -449,6 +553,13 @@ + + + + Spoilers + + + @@ -463,6 +574,20 @@ + + + + all on + + + + + + + all off + + + @@ -480,15 +605,8 @@ - - - - all on - - - - - + + all off @@ -501,20 +619,6 @@ - - - - on ground - - - - - - - all off - - - @@ -522,6 +626,13 @@ + + + + on ground + + + @@ -630,8 +741,21 @@ + + incremental + - Incremental + Incr. + + + + + + + set current parts values + + + current diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index c774df76e..1c03c07a9 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -151,6 +151,26 @@ namespace BlackMisc return worker; } + QStringList IInterpolator::getLatestLogFiles() + { + QStringList files({ "", ""}); + const QString logDir = CDirectoryUtils::getLogDirectory(); + QDir logs(logDir); + if (!logs.exists()) { return files; } + logs.setNameFilters(QStringList() << "*interpolation.html" << "*parts.html"); + const QStringList interpolations = logs.entryList(QStringList({"*interpolation.html"}), QDir::NoFilter, QDir::Time); + if (!interpolations.isEmpty()) + { + files[0] = CFileUtils::appendFilePaths(logDir, interpolations.first()); + } + const QStringList parts = logs.entryList(QStringList({"*parts.html"}), QDir::NoFilter, QDir::Time); + if (!parts.isEmpty()) + { + files[1] = CFileUtils::appendFilePaths(logDir, parts.first()); + } + return files; + } + CStatusMessageList IInterpolator::writeLogFile(const QList &interpolation, const QList &parts) { if (parts.isEmpty() && interpolation.isEmpty()) { return CStatusMessage(static_cast(nullptr)).warning("No data for log"); } diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h index b51056f70..51b3570ed 100644 --- a/src/blackmisc/simulation/interpolator.h +++ b/src/blackmisc/simulation/interpolator.h @@ -124,6 +124,7 @@ namespace BlackMisc void setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup); //! Write a log in background + //! \threadsafe BlackMisc::CWorker *writeLogInBackground(); //! Clear log file @@ -134,18 +135,19 @@ namespace BlackMisc //! \remark public for FS9 to get setup in Fs9Client CInterpolationAndRenderingSetup getInterpolatorSetup() const; - /*! - * Takes input between 0 and 1 and returns output between 0 and 1 smoothed with an S-shaped curve. - * - * Useful for making interpolation seem smoother, efficiently as it just uses simple arithmetic. - * \see https://en.wikipedia.org/wiki/Smoothstep - * \see http://sol.gfxile.net/interpolation/ - */ + //! Takes input between 0 and 1 and returns output between 0 and 1 smoothed with an S-shaped curve. + //! + //! Useful for making interpolation seem smoother, efficiently as it just uses simple arithmetic. + //! \see https://en.wikipedia.org/wiki/Smoothstep + //! \see http://sol.gfxile.net/interpolation/ static double smootherStep(double x) { return x * x * x * (x * (x * 6.0 - 15.0) + 10.0); } + //! Latest log files: 0 Interpolation 1 Parts + static QStringList getLatestLogFiles(); + protected: //! Log for interpolation struct InterpolationLog