diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 59e25f74e..6bdef72b7 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -57,6 +57,7 @@ namespace BlackCore class BLACKCORE_EXPORT CSimulatorCommon : public ISimulator { Q_OBJECT + Q_INTERFACES(BlackCore::ISimulator) public: //! Log categories diff --git a/src/plugins/simulator/fsxcommon/fsxsettingscomponent.cpp b/src/plugins/simulator/fsxcommon/fsxsettingscomponent.cpp new file mode 100644 index 000000000..ad3c7b605 --- /dev/null +++ b/src/plugins/simulator/fsxcommon/fsxsettingscomponent.cpp @@ -0,0 +1,56 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "fsxsettingscomponent.h" +#include "ui_fsxsettingscomponent.h" +#include "simulatorfsxcommon.h" +#include "blackgui/guiapplication.h" + +using namespace BlackCore; +using namespace BlackGui; + +namespace BlackSimPlugin +{ + namespace FsxCommon + { + CFsxSettingsComponent::CFsxSettingsComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CFsxSettingsComponent) + { + ui->setupUi(this); + ui->cb_TraceSimConnectCalls->setChecked(false); + connect(ui->cb_TraceSimConnectCalls, &QCheckBox::released, this, &CFsxSettingsComponent::onSimConnectTraceChanged); + const CSimulatorFsxCommon *fsx = this->getFsxSimulator(); + if (fsx) + { + ui->cb_TraceSimConnectCalls->setChecked(fsx->isTracingSendId()); + } + } + + CFsxSettingsComponent::~CFsxSettingsComponent() + { } + + void CFsxSettingsComponent::onSimConnectTraceChanged() + { + CSimulatorFsxCommon *fsx = this->getFsxSimulator(); + if (!fsx) { return; } + fsx->setTractingSendId(ui->cb_TraceSimConnectCalls->isChecked()); + } + + CSimulatorFsxCommon *CFsxSettingsComponent::getFsxSimulator() const + { + if (!sGui || !sGui->getISimulator()) { return nullptr; } + ISimulator *sim = sGui->getISimulator(); + if (!sim->getSimulatorInfo().isFsxP3DFamily()) { return nullptr; } + if (sim->getSimulatorInfo() != m_simulator) { return nullptr; } + CSimulatorFsxCommon *fsx = static_cast(sim); // wonder why qobject_cast does not work here + return fsx; + } + } // ns +} // ns diff --git a/src/plugins/simulator/fsxcommon/fsxsettingscomponent.h b/src/plugins/simulator/fsxcommon/fsxsettingscomponent.h new file mode 100644 index 000000000..94b85d405 --- /dev/null +++ b/src/plugins/simulator/fsxcommon/fsxsettingscomponent.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKSIMPLUGIN_FSXCOMMON_FSXSETTINGSCOMPONENT_H +#define BLACKSIMPLUGIN_FSXCOMMON_FSXSETTINGSCOMPONENT_H + +#include "blackmisc/simulation/simulatorinfo.h" +#include +#include + +namespace Ui { class CFsxSettingsComponent; } +namespace BlackSimPlugin +{ + namespace FsxCommon + { + class CSimulatorFsxCommon; + + //! FSX/P3D settings + class CFsxSettingsComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CFsxSettingsComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CFsxSettingsComponent(); + + //! Simulator, P3D/FSX + void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) { m_simulator = simulator; } + + private: + //! Checkbox change + void onSimConnectTraceChanged(); + + //! Access the concrete implementation + CSimulatorFsxCommon *getFsxSimulator () const; + + BlackMisc::Simulation::CSimulatorInfo m_simulator { "FSX" }; + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/plugins/simulator/fsxcommon/fsxsettingscomponent.ui b/src/plugins/simulator/fsxcommon/fsxsettingscomponent.ui new file mode 100644 index 000000000..f2aa2a652 --- /dev/null +++ b/src/plugins/simulator/fsxcommon/fsxsettingscomponent.ui @@ -0,0 +1,28 @@ + + + CFsxSettingsComponent + + + + 0 + 0 + 126 + 31 + + + + Frame + + + + + + Trace simConnect calls + + + + + + + + diff --git a/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.cpp b/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.cpp index 7bf0c0e4e..49a7c8582 100644 --- a/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.cpp @@ -213,13 +213,13 @@ namespace BlackSimPlugin { if (CBuildConfig::isCompiledWithP3DSupport() && CBuildConfig::buildWordSize() == 64) { - ui->lbl_SimConnectInfo->setText("Static linking P3Dv4 x64"); + ui->pte_SimConnectInfo->setPlainText("Static linking P3Dv4 x64"); m_simulator = CSimulatorInfo(CSimulatorInfo::P3D); } else { const CWinDllUtils::DLLInfo SimConnectInfo = CSimConnectUtilities::simConnectDllInfo(); - ui->lbl_SimConnectInfo->setText(SimConnectInfo.summary()); + ui->pte_SimConnectInfo->setPlainText(SimConnectInfo.summary()); m_simulator = CSimulatorInfo(CSimulatorInfo::FSX); } ui->le_UserCfgFile->setText(CSimConnectUtilities::hasUserSimConnectCfgFile() ? CSimConnectUtilities::getUserSimConnectCfgFilename() : ""); diff --git a/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.ui b/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.ui index 84cfe7b14..8cbccc203 100644 --- a/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.ui +++ b/src/plugins/simulator/fsxcommon/simconnectsettingscomponent.ui @@ -45,16 +45,6 @@ - - - - info about version, ... - - - true - - - @@ -112,264 +102,6 @@ console=1 - - - - swift SimConnect.cfg - - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Address - - - - - - - 127.0.0.1 - - - 128 - - - e.g. "127.0.0.1" or "192.128.3.1" - - - - - - - Port - - - - - - - 500 - - - normally "500" - - - - - - - is 'SimConnect.cfg' available? - - - .cfg file - - - - - - - - 4 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - true - - - local "SimConnect.cfg" file? - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - check - - - - - - - - - - 3 - - - - - - 0 - 0 - - - - - 50 - 0 - - - - open - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - del. - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - - 16777215 - 16777215 - - - - save - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - - 16777215 - 16777215 - - - - Test connection - - - test - - - - - - - - - User's .cfg file - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - true - - - User's "SimConnect.cfg" file - - - - - - - open - - - - - - - - - @@ -411,11 +143,301 @@ console=1 + + + + + 16777215 + 40 + + + + Version info + + + true + + + + + + + + + + swift SimConnect.cfg + + + + 4 + + + 4 + + + 4 + + + 4 + + + + + Address + + + + + + + 127.0.0.1 + + + 128 + + + e.g. "127.0.0.1" or "192.128.3.1" + + + + + + + Port + + + + + + + 500 + + + normally "500" + + + + + + + is 'SimConnect.cfg' available? + + + .cfg file + + + + + + + + 4 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + local "SimConnect.cfg" file? + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + check + + + + + + + + + + 3 + + + + + + 0 + 0 + + + + + 50 + 0 + + + + open + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + del. + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 16777215 + 16777215 + + + + save + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 16777215 + 16777215 + + + + Test connection + + + test + + + + + + + + + User's .cfg file + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + User's "SimConnect.cfg" file + + + + + + + open + + + + + + + + pte_SimConnectInfo + pte_SimConnectIniFiles + pte_SimConnectIni + pb_SaveAsSimConnectIni + le_UserCfgFile + pb_OpenUserCfgFile + le_Address + le_Port + le_ExistsSimConnectCfg + pb_ExistsSimConnectCfg + pb_OpenSwiftSimConnectCfg + pb_DeleteSwiftSimConnectCfg + pb_SaveSwiftSimConnectCfg + pb_TestConnection + diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 77d91e914..a210ce55e 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -279,13 +279,13 @@ namespace BlackSimPlugin if (m_simConnectProbes.isEmpty()) { return this->physicallyAddAITerrainProbe(pos); } if (m_simConnectProbes.countConfirmedAdded() < 1) { return false; } // pending probes - CSimConnectObject simObj = m_simConnectProbes.values().front(); + CSimConnectObject simObject = m_simConnectProbes.values().front(); SIMCONNECT_DATA_INITPOSITION position = this->coordinateToFsxPosition(pos); const HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftSetPosition, - simObj.getObjectId(), 0, 0, + simObject.getObjectId(), 0, 0, sizeof(SIMCONNECT_DATA_INITPOSITION), &position); - if (m_traceSendId) { this->traceSendId(simObj.getObjectId(), Q_FUNC_INFO); } + if (m_traceSendId) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO); } if (hr == S_OK) { @@ -393,7 +393,12 @@ namespace BlackSimPlugin this->safeKillTimer(); // if called from dispatch function, avoid that SimConnectProc disconnects itself while in SimConnectProc - QTimer::singleShot(0, this, &CSimulatorFsxCommon::disconnectFrom); + QPointer myself(this); + QTimer::singleShot(0, this, [ = ] + { + if (myself.isNull()) { return; } + myself->disconnectFrom(); + }); } SIMCONNECT_DATA_REQUEST_ID CSimulatorFsxCommon::obtainRequestIdForSimData() @@ -884,7 +889,7 @@ namespace BlackSimPlugin } else if (m_dispatchErrors > 5) { - // this normally happens during a FSX crash or shutdown + // this normally happens during a FSX crash or shutdown with simconnect CLogMessage(this).error("%1: Multiple dispatch errors, disconnecting") << this->getSimulatorPluginInfo().getIdentifier(); this->disconnectFrom(); } diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h index dcbbcee6f..30b652338 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h @@ -100,6 +100,7 @@ namespace BlackSimPlugin class CSimulatorFsxCommon : public BlackSimPlugin::FsCommon::CSimulatorFsCommon { Q_OBJECT + Q_INTERFACES(BlackCore::ISimulator) public: //! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create @@ -134,6 +135,12 @@ namespace BlackSimPlugin //! \copydoc BlackMisc::Simulation::ISimulationEnvironmentProvider::requestElevation virtual bool requestElevation(const BlackMisc::Geo::ICoordinateGeodetic &reference, const BlackMisc::Aviation::CCallsign &callsign) override; + //! Tracing? + bool isTracingSendId() const { return m_traceSendId; } + + //! Set tracing on/off + void setTractingSendId(bool trace) { m_traceSendId = trace; } + protected: //! SimConnect Callback static void CALLBACK SimConnectProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext); diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.cpp index 35c1f92b5..2c30cfec1 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.cpp @@ -22,13 +22,15 @@ namespace BlackSimPlugin ui(new Ui::CSimulatorFsxConfigWindow) { ui->setupUi(this); + ui->tw_Settings->setCurrentIndex(0); + ui->comp_Settings->setSimulator(m_simulator); connect(ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &QWidget::close); - this->setWindowTitle(m_simulator + " plugin configuration"); + this->setWindowTitle(m_simulator.toQString(true) + " plugin configuration"); } CSimulatorFsxConfigWindow::~CSimulatorFsxConfigWindow() { // void } - } -} + } // ns +} // ns diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.h b/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.h index e180bf1e0..8a25a63ca 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.h @@ -13,6 +13,7 @@ #define BLACKSIMPLUGIN_FSXCOMMON_SIMULATORFSXCONFIGWINDOW_H #include "blackgui/pluginconfigwindow.h" +#include "blackmisc/simulation/simulatorinfo.h" #include namespace Ui { class CSimulatorFsxConfigWindow; } @@ -34,11 +35,14 @@ namespace BlackSimPlugin //! Dtor. virtual ~CSimulatorFsxConfigWindow(); + //! Related simulator, i.e. "P3D" or "FSX" + const BlackMisc::Simulation::CSimulatorInfo &getSimulator() const { return m_simulator; } + private: - QString m_simulator { "FSX" }; + const BlackMisc::Simulation::CSimulatorInfo m_simulator { "FSX" }; QScopedPointer ui; }; - } -} + } // ns +} // ns #endif // guard diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.ui b/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.ui index e08fb5a6b..3585ec39f 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.ui +++ b/src/plugins/simulator/fsxcommon/simulatorfsxconfigwindow.ui @@ -14,14 +14,67 @@ FSX/P3D plugin settings + + 4 + + + 4 + + + 4 + + + 4 + - - - QFrame::StyledPanel - - - QFrame::Raised + + + 0 + + + SimConnect config + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + Settings + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + @@ -40,6 +93,12 @@
simconnectsettingscomponent.h
1 + + BlackSimPlugin::FsxCommon::CFsxSettingsComponent + QFrame +
fsxsettingscomponent.h
+ 1 +