mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
Ref T111, using a simulated aircraft to represent emulated driver's own aircraft (this is the aircraft a user would fly in a real simulator)
* change functions for that aircraft * support for SELCAL * removed unused function * adjusted simulated aircraft monitor ** unified naming of functions ** support for text/status messages
This commit is contained in:
committed by
Mathew Sutcliffe
parent
71fa0fc7b8
commit
753bbc1847
@@ -31,15 +31,17 @@ namespace BlackSimPlugin
|
||||
namespace Emulated
|
||||
{
|
||||
CSimulatorEmulated::CSimulatorEmulated(const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IWeatherGridProvider *weatherGridProvider,
|
||||
QObject *parent) :
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IWeatherGridProvider *weatherGridProvider,
|
||||
QObject *parent) :
|
||||
CSimulatorCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, parent)
|
||||
{
|
||||
Q_ASSERT_X(sApp && sApp->getIContextSimulator(), Q_FUNC_INFO, "Need context");
|
||||
|
||||
CSimulatorEmulated::registerHelp();
|
||||
m_myAircraft = this->getOwnAircraft(); // sync with provider
|
||||
|
||||
m_monitorWidget.reset(new CSimulatorEmulatedMonitorDialog(this, sGui->mainApplicationWindow()));
|
||||
connect(qApp, &QApplication::aboutToQuit, this, &CSimulatorEmulated::closeMonitor);
|
||||
this->onSettingsChanged();
|
||||
@@ -110,17 +112,32 @@ namespace BlackSimPlugin
|
||||
bool CSimulatorEmulated::updateOwnSimulatorCockpit(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
|
||||
{
|
||||
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, aircraft.toQString(), originator.toQString());
|
||||
if (originator == identifier()) { return false; } // myself
|
||||
m_myAircraft.setCockpit(aircraft);
|
||||
emit this->internalAircraftChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::updateOwnSimulatorSelcal(const CSelcal &selcal, const CIdentifier &originator)
|
||||
{
|
||||
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, selcal.toQString(), originator.toQString());
|
||||
if (originator == identifier()) { return false; } // myself
|
||||
if (m_myAircraft.getSelcal() == selcal) { return false; }
|
||||
m_myAircraft.setSelcal(selcal);
|
||||
emit this->internalAircraftChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorEmulated::displayStatusMessage(const CStatusMessage &message) const
|
||||
{
|
||||
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, message.toQString());
|
||||
m_monitorWidget->displayStatusMessage(message);
|
||||
}
|
||||
|
||||
void CSimulatorEmulated::displayTextMessage(const CTextMessage &message) const
|
||||
{
|
||||
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, message.toQString());
|
||||
m_monitorWidget->displayTextMessage(message);
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::setTimeSynchronization(bool enable, const CTime &offset)
|
||||
@@ -177,6 +194,40 @@ namespace BlackSimPlugin
|
||||
this->emitSimulatorCombinedStatus();
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::changeInternalCom(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
bool changed = false;
|
||||
if (aircraft.getCom1System() != m_myAircraft.getCom1System()) { changed = true; }
|
||||
if (aircraft.getCom2System() != m_myAircraft.getCom2System()) { changed = true; }
|
||||
if (aircraft.getTransponder() != m_myAircraft.getTransponder()) { changed = true; }
|
||||
if (aircraft.getSelcal() != m_myAircraft.getSelcal()) { changed = true; }
|
||||
|
||||
if (!changed) { return false; }
|
||||
m_myAircraft.setCockpit(aircraft);
|
||||
return this->updateCockpit(aircraft, this->identifier());
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::changeInternalSelcal(const CSelcal &selcal)
|
||||
{
|
||||
if (m_myAircraft.getSelcal() == selcal) { return false; }
|
||||
m_myAircraft.setSelcal(selcal);
|
||||
return this->updateSelcal(selcal, identifier());
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::changeInternalSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
if (m_myAircraft.getSituation() == situation) { return false; }
|
||||
m_myAircraft.setSituation(situation);
|
||||
return this->updateOwnSituation(situation);
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::changeInternalParts(const CAircraftParts &parts)
|
||||
{
|
||||
if (m_myAircraft.getParts() == parts) { return false; }
|
||||
m_myAircraft.setParts(parts);
|
||||
return this->updateOwnParts(parts);
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::isConnected() const
|
||||
{
|
||||
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
|
||||
@@ -247,20 +298,6 @@ namespace BlackSimPlugin
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorEmulated::setOwnAircraftPosition(const QString &wgsLatitude, const QString &wgsLongitude, const CAltitude &altitude)
|
||||
{
|
||||
const CCoordinateGeodetic coordinate(
|
||||
CLatitude::fromWgs84(wgsLatitude),
|
||||
CLongitude::fromWgs84(wgsLongitude),
|
||||
CAltitude(0, CLengthUnit::m()));
|
||||
|
||||
CAircraftSituation s = this->getOwnAircraftSituation();
|
||||
s.setPosition(coordinate);
|
||||
s.setAltitude(altitude);
|
||||
|
||||
this->updateOwnSituation(s);
|
||||
}
|
||||
|
||||
void CSimulatorEmulated::onSettingsChanged()
|
||||
{
|
||||
const CSwiftPluginSettings settings(m_settings.get());
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace BlackSimPlugin
|
||||
virtual bool changeRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) override;
|
||||
virtual bool changeRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) override;
|
||||
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator) override;
|
||||
virtual bool updateOwnSimulatorSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override;
|
||||
virtual void displayStatusMessage(const BlackMisc::CStatusMessage &message) const override;
|
||||
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override;
|
||||
virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override;
|
||||
@@ -80,6 +81,30 @@ namespace BlackSimPlugin
|
||||
//! UI setter
|
||||
void setCombinedStatus(bool connected, bool simulating, bool paused);
|
||||
|
||||
//! Internal own aircraft
|
||||
//! \remark normally used by corresponding BlackSimPlugin::Emulated::CSimulatorEmulatedMonitorDialog
|
||||
const BlackMisc::Simulation::CSimulatedAircraft &getInternalOwnAircraft() const { return m_myAircraft; }
|
||||
|
||||
//! Simulator internal change of COM values
|
||||
//! \remark normally used by corresponding BlackSimPlugin::Emulated::CSimulatorEmulatedMonitorDialog
|
||||
bool changeInternalCom(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
|
||||
//! Simulator internal change of SELCAL
|
||||
//! \remark normally used by corresponding BlackSimPlugin::Emulated::CSimulatorEmulatedMonitorDialog
|
||||
bool changeInternalSelcal(const BlackMisc::Aviation::CSelcal &selcal);
|
||||
|
||||
//! Simulator internal change of situation
|
||||
//! \remark normally used by corresponding BlackSimPlugin::Emulated::CSimulatorEmulatedMonitorDialog
|
||||
bool changeInternalSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Simulator internal change of parts
|
||||
//! \remark normally used by corresponding BlackSimPlugin::Emulated::CSimulatorEmulatedMonitorDialog
|
||||
bool changeInternalParts(const BlackMisc::Aviation::CAircraftParts &parts);
|
||||
|
||||
signals:
|
||||
//! Internal aircraft changed
|
||||
void internalAircraftChanged();
|
||||
|
||||
protected:
|
||||
virtual bool isConnected() const override;
|
||||
virtual bool isPaused() const override;
|
||||
@@ -100,9 +125,6 @@ namespace BlackSimPlugin
|
||||
//! Close window
|
||||
void closeMonitor();
|
||||
|
||||
//! Set own aircraft position
|
||||
void setOwnAircraftPosition(const QString &wgsLatitude, const QString &wgsLongitude, const BlackMisc::Aviation::CAltitude &altitude);
|
||||
|
||||
//! Settings changed
|
||||
void onSettingsChanged();
|
||||
|
||||
@@ -115,7 +137,8 @@ namespace BlackSimPlugin
|
||||
bool m_simulating = true;
|
||||
bool m_timeSyncronized = false;
|
||||
BlackMisc::PhysicalQuantities::CTime m_offsetTime;
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_renderedAircraft;
|
||||
BlackMisc::Simulation::CSimulatedAircraft m_myAircraft; //!< represents own aircraft of simulator
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_renderedAircraft; //!< represents other aircraft of simulator
|
||||
|
||||
QScopedPointer<CSimulatorEmulatedMonitorDialog> m_monitorWidget; //!< parent will be main window, so we need to destroy widget when destroyed
|
||||
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSwiftPlugin> m_settings { this, &CSimulatorEmulated::onSettingsChanged };
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackGui::Editors;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
@@ -32,19 +33,24 @@ namespace BlackSimPlugin
|
||||
Q_ASSERT_X(simulator, Q_FUNC_INFO, "Need simulator");
|
||||
|
||||
m_simulator = simulator;
|
||||
connect(m_simulator, &CSimulatorEmulated::internalAircraftChanged, this, &CSimulatorEmulatedMonitorDialog::setInteralAircraftUiValues, Qt::QueuedConnection);
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->tw_SwiftMonitorDialog->setCurrentIndex(0);
|
||||
ui->comp_LogComponent->setMaxLogMessages(500);
|
||||
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
connect(ui->cb_Connected, &QCheckBox::released, this, &CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged);
|
||||
connect(ui->cb_Paused, &QCheckBox::released, this, &CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged);
|
||||
connect(ui->cb_Simulating, &QCheckBox::released, this, &CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged);
|
||||
|
||||
connect(ui->editor_Situation, &CSituationForm::changeAircraftSituation, this, &CSimulatorEmulatedMonitorDialog::changeSituation);
|
||||
connect(ui->editor_AircraftParts, &CAircraftPartsForm::changeAircraftParts, this, &CSimulatorEmulatedMonitorDialog::changeParts);
|
||||
connect(ui->editor_Situation, &CSituationForm::changeAircraftSituation, this, &CSimulatorEmulatedMonitorDialog::changeSituationFromUi);
|
||||
connect(ui->editor_AircraftParts, &CAircraftPartsForm::changeAircraftParts, this, &CSimulatorEmulatedMonitorDialog::changePartsFromUi);
|
||||
connect(ui->editor_Com, &CCockpitComForm::changedCockpitValues, this, &CSimulatorEmulatedMonitorDialog::changeComFromUi);
|
||||
connect(ui->editor_Com, &CCockpitComForm::changedSelcal, this, &CSimulatorEmulatedMonitorDialog::changeSelcalFromUi);
|
||||
|
||||
this->setSimulatorUiValues();
|
||||
ui->editor_Situation->setSituation(m_simulator->getOwnAircraftSituation());
|
||||
this->setInteralAircraftUiValues();
|
||||
}
|
||||
|
||||
CSimulatorEmulatedMonitorDialog::~CSimulatorEmulatedMonitorDialog()
|
||||
@@ -86,6 +92,16 @@ namespace BlackSimPlugin
|
||||
this->appendStatusMessageToList(msg);
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::displayStatusMessage(const CStatusMessage &message)
|
||||
{
|
||||
ui->pte_StatusMessages->setPlainText(message.toQString(true));
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::displayTextMessage(const Network::CTextMessage &message)
|
||||
{
|
||||
ui->pte_TextMessages->setPlainText(message.toQString(true));
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged()
|
||||
{
|
||||
m_simulator->setCombinedStatus(
|
||||
@@ -95,18 +111,30 @@ namespace BlackSimPlugin
|
||||
);
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::changeSituation()
|
||||
void CSimulatorEmulatedMonitorDialog::changeComFromUi(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
if (!m_simulator) { return; }
|
||||
m_simulator->changeInternalCom(aircraft);
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::changeSelcalFromUi(const CSelcal &selcal)
|
||||
{
|
||||
if (!m_simulator) { return; }
|
||||
m_simulator->changeInternalSelcal(selcal);
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::changeSituationFromUi()
|
||||
{
|
||||
if (!m_simulator) { return; }
|
||||
const CAircraftSituation s(ui->editor_Situation->getSituation());
|
||||
m_simulator->updateOwnSituation(s);
|
||||
m_simulator->changeInternalSituation(s);
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::changeParts()
|
||||
void CSimulatorEmulatedMonitorDialog::changePartsFromUi()
|
||||
{
|
||||
if (!m_simulator) { return; }
|
||||
const CAircraftParts p(ui->editor_AircraftParts->getAircraftPartsFromGui());
|
||||
m_simulator->updateOwnParts(p);
|
||||
m_simulator->changeInternalParts(p);
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::setSimulatorUiValues()
|
||||
@@ -118,5 +146,13 @@ namespace BlackSimPlugin
|
||||
ui->le_Simulator->setText(m_simulator->getSimulatorInfo().toQString(true));
|
||||
ui->le_SimulatorPlugin->setText(m_simulator->getSimulatorPluginInfo().toQString(true));
|
||||
}
|
||||
|
||||
void CSimulatorEmulatedMonitorDialog::setInteralAircraftUiValues()
|
||||
{
|
||||
const CSimulatedAircraft internal(m_simulator->getInternalOwnAircraft());
|
||||
ui->editor_Situation->setSituation(internal.getSituation());
|
||||
ui->editor_AircraftParts->setAircraftParts(internal.getParts());
|
||||
ui->editor_Com->setValue(internal);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QScopedPointer>
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
|
||||
@@ -50,19 +51,36 @@ namespace BlackSimPlugin
|
||||
//! Append a function call as status message
|
||||
void appendFunctionCall(const QString &function, const QString &p1 = {}, const QString &p2 = {}, const QString &p3 = {});
|
||||
|
||||
//! Display status message
|
||||
void displayStatusMessage(const BlackMisc::CStatusMessage &message);
|
||||
|
||||
//! Display text message
|
||||
void displayTextMessage(const BlackMisc::Network::CTextMessage &message);
|
||||
|
||||
private:
|
||||
static int constexpr MaxLogMessages = 500; //!< desired log message number
|
||||
|
||||
//! UI values changed
|
||||
void onSimulatorValuesChanged();
|
||||
|
||||
//! Cockpit COM values changed
|
||||
void changeComFromUi(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
|
||||
//! SELCAL values changed
|
||||
void changeSelcalFromUi(const BlackMisc::Aviation::CSelcal &selcal);
|
||||
|
||||
//! Update aircraft situation
|
||||
void changeSituation();
|
||||
void changeSituationFromUi();
|
||||
|
||||
//! Change the aircraft parts
|
||||
void changeParts();
|
||||
void changePartsFromUi();
|
||||
|
||||
//! UI values
|
||||
void setSimulatorUiValues();
|
||||
|
||||
//! Set values from internal aircraft
|
||||
void setInteralAircraftUiValues();
|
||||
|
||||
QScopedPointer<Ui::CSimulatorEmulatedMonitorDialog> ui;
|
||||
CSimulatorEmulated *m_simulator = nullptr;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,19 @@
|
||||
<attribute name="title">
|
||||
<string>Situation</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<layout class="QVBoxLayout" name="vl_Situation">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::Editors::CSituationForm" name="editor_Situation">
|
||||
<property name="minimumSize">
|
||||
@@ -36,12 +48,44 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_Parts">
|
||||
<widget class="QWidget" name="tb_ComParts">
|
||||
<attribute name="title">
|
||||
<string>Parts</string>
|
||||
<string>COM and Parts</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_Parts">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gl_ComParts">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="gb_Com">
|
||||
<property name="title">
|
||||
<string>COM</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="BlackGui::Editors::CCockpitComForm" name="editor_Com">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>75</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="vs_Com">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QGroupBox" name="gb_Parts">
|
||||
<property name="title">
|
||||
<string>Parts</string>
|
||||
@@ -66,7 +110,7 @@
|
||||
<attribute name="title">
|
||||
<string>Simulator</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="vl_Simulator">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_General">
|
||||
<property name="title">
|
||||
@@ -146,6 +190,49 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Messages">
|
||||
<property name="title">
|
||||
<string>Messages</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gl_Messages">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPlainTextEdit" name="pte_StatusMessages">
|
||||
<property name="documentTitle">
|
||||
<string>Received status messages</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPlainTextEdit" name="pte_TextMessages">
|
||||
<property name="documentTitle">
|
||||
<string>Received text messages</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_TextMessages">
|
||||
<property name="text">
|
||||
<string>Text messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="lbl_StatusMessages">
|
||||
<property name="text">
|
||||
<string>Status messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_LogMessages">
|
||||
@@ -238,6 +325,12 @@
|
||||
<header>blackgui/editors/aircraftpartsform.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Editors::CCockpitComForm</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/editors/cockpitcomform.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
||||
Reference in New Issue
Block a user