From eccfae1fd32aba18eeaaa6122b1805d66212e90f Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Mon, 3 Mar 2014 22:14:30 +0100 Subject: [PATCH] Add new page in sample_blackgui to display user aircraft data refs #143 --- samples/blackgui/mainwindow.cpp | 39 +++++- samples/blackgui/mainwindow.h | 11 +- samples/blackgui/mainwindow.ui | 193 ++++++++++++++++++++++++++- samples/blackgui/mainwindow_init.cpp | 12 ++ 4 files changed, 252 insertions(+), 3 deletions(-) diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index a12a0706e..0a7df0cef 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -3,6 +3,7 @@ #include "blackgui/atcstationlistmodel.h" #include "blackcore/dbus_server.h" #include "blackcore/context_network.h" +#include "blackmisc/avaircraft.h" #include using namespace BlackCore; @@ -33,10 +34,11 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : m_coreMode(GuiModes::CoreExternal), m_coreAvailable(false), m_contextNetworkAvailable(false), m_contextVoiceAvailable(false), m_contextApplication(nullptr), m_contextNetwork(nullptr), m_contextVoice(nullptr), m_contextSettings(nullptr), + m_contextSimulator(nullptr), // timers m_timerUpdateAtcStationsOnline(nullptr), m_timerUpdateAircraftsInRange(nullptr), m_timerUpdateUsers(nullptr), m_timerCollectedCockpitUpdates(nullptr), m_timerContextWatchdog(nullptr), - m_timerStatusBar(nullptr), m_timerAudioTests(nullptr), + m_timerStatusBar(nullptr), m_timerAudioTests(nullptr), m_timerSimulator(nullptr), // context menus m_contextMenuAudio(nullptr), m_contextMenuStatusMessageList(nullptr), // cockpit @@ -165,6 +167,8 @@ void MainWindow::setMainPage(bool start) this->ui->sw_MainMiddle->setCurrentIndex(MainPageFlightplan); else if (sender == this->ui->pb_MainSettings) this->ui->sw_MainMiddle->setCurrentIndex(MainPageSettings); + else if (sender == this->ui->pb_MainSimulator) + this->ui->sw_MainMiddle->setCurrentIndex(MainPageSimulator); } /* @@ -314,6 +318,11 @@ void MainWindow::connectionStatusChanged(uint /** from **/, uint to) } } +void MainWindow::simulatorAvailable() +{ + m_timerSimulator->start(500); +} + /* * Timer event */ @@ -343,6 +352,10 @@ void MainWindow::timerBasedUpdates() this->setContextAvailability(); this->updateGuiStatusInformation(); } + else if (sender == this->m_timerSimulator) + { + updateSimulatorData(); + } // own aircraft if (sender == this->m_timerUpdateAircraftsInRange || sender == this->m_timerUpdateAtcStationsOnline) @@ -489,3 +502,27 @@ void MainWindow::reloadAllUsers() this->ui->tv_AllUsers->resizeRowsToContents(); this->ui->tv_AllUsers->horizontalHeader()->setStretchLastSection(true); } + +void MainWindow::updateSimulatorData() +{ + if (m_contextSimulator->isConnected()) + ui->le_SimulatorStatus->setText("Connected"); + else + ui->le_SimulatorStatus->setText("Not connected"); + + CAircraft ownAircraft = m_contextSimulator->ownAircraft(); + ui->le_SimulatorLatitude->setText(ownAircraft.getSituation().latitude().toFormattedQString()); + ui->le_SimulatorLongitude->setText(ownAircraft.getSituation().longitude().toFormattedQString()); + ui->le_SimulatorAltitude->setText(ownAircraft.getSituation().getAltitude().toFormattedQString()); + ui->le_SimulatorPitch->setText(ownAircraft.getSituation().getPitch().toFormattedQString()); + ui->le_SimulatorBank->setText(ownAircraft.getSituation().getBank().toFormattedQString()); + ui->le_SimulatorHeading->setText(ownAircraft.getSituation().getHeading().toFormattedQString()); + ui->le_SimulatorGroundSpeed->setText(ownAircraft.getSituation().getGroundSpeed().toFormattedQString()); + + + ui->le_SimulatorCom1Active->setText(ownAircraft.getCom1System().getFrequencyActive().toFormattedQString()); + ui->le_SimulatorCom1Standby->setText(ownAircraft.getCom1System().getFrequencyStandby().toFormattedQString()); + ui->le_SimulatorCom2Active->setText(ownAircraft.getCom2System().getFrequencyActive().toFormattedQString()); + ui->le_SimulatorCom2Standby->setText(ownAircraft.getCom2System().getFrequencyStandby().toFormattedQString()); + ui->le_SimulatorTransponder->setText(ownAircraft.getTransponderCodeFormatted()); +} diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index a22975a9c..ddc3e00bc 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -16,6 +16,7 @@ #include "blackcore/context_network_interface.h" #include "blackcore/context_settings_interface.h" #include "blackcore/context_application_interface.h" +#include "blackcore/context_simulator.h" #include "blackcore/coreruntime.h" #include "blackgui/atcstationlistmodel.h" #include "blackgui/serverlistmodel.h" @@ -93,7 +94,8 @@ protected: MainPageCockpit = 4, MainPageTextMessages = 5, MainPageFlightplan = 6, - MainPageSettings = 7 + MainPageSettings = 7, + MainPageSimulator = 8 }; enum AudioTest @@ -133,6 +135,7 @@ private: BlackCore::IContextNetwork *m_contextNetwork; BlackCore::IContextVoice *m_contextVoice; BlackCore::IContextSettings *m_contextSettings; + BlackCore::IContextSimulator *m_contextSimulator; BlackMisc::Aviation::CAircraft m_ownAircraft; /*!< own aircraft's state */ QTimer *m_timerUpdateAtcStationsOnline; /*!< timer for update of stations */ QTimer *m_timerUpdateAircraftsInRange; /*!< timer for update of aircrafts */ @@ -141,6 +144,7 @@ private: QTimer *m_timerContextWatchdog; /*!< core available? */ QTimer *m_timerStatusBar; /*!< cleaning up status bar */ QTimer *m_timerAudioTests; /*!< cleaning up status bar */ + QTimer *m_timerSimulator; /*!< update simulator data */ // pixmaps QPixmap m_resPixmapConnectionConnected; @@ -313,6 +317,9 @@ private: * \brief Play notifcation sound */ void playNotifcationSound(BlackSound::CSoundGenerator::Notification notification) const; + + //! \brief Update simulator page with latest user aircraft data + void updateSimulatorData(); private slots: @@ -372,6 +379,8 @@ private slots: //! \brief Send cockpit updates void sendCockpitUpdates(); + void simulatorAvailable(); + // // GUI related slots // diff --git a/samples/blackgui/mainwindow.ui b/samples/blackgui/mainwindow.ui index 975783655..546d29ee2 100644 --- a/samples/blackgui/mainwindow.ui +++ b/samples/blackgui/mainwindow.ui @@ -554,7 +554,7 @@ QStatusBar QLabel { - 0 + 1 3 @@ -2485,6 +2485,190 @@ QStatusBar QLabel { + + + + + + Longitude + + + + + + + Status + + + + + + + Bank + + + + + + + Latitude + + + + + + + Ground Speed + + + + + + + Heading + + + + + + + On ground + + + + + + + Altitude + + + + + + + Pitch + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + COM1 Standby + + + + + + + COM1 Active + + + + + + + COM2 Active + + + + + + + COM2 Standby + + + + + + + + + + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + + + + Transponder + + + + + @@ -2813,6 +2997,13 @@ QStatusBar QLabel { + + + + Simulator + + + diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 5bb9a3687..ee1d24071 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -2,6 +2,8 @@ #include "ui_mainwindow.h" #include "blackcore/dbus_server.h" #include "blackcore/context_network.h" +#include "blackcore/context_simulator_impl.h" +#include "blackcore/context_simulator_proxy.h" #include "blackcore/coreruntime.h" #include "blackgui/atcstationlistmodel.h" #include "blackgui/keyboardkeylistmodel.h" @@ -156,6 +158,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) if (this->m_timerContextWatchdog == nullptr) this->m_timerContextWatchdog = new QTimer(this); if (this->m_timerCollectedCockpitUpdates == nullptr) this->m_timerCollectedCockpitUpdates = new QTimer(this); if (this->m_timerAudioTests == nullptr) this->m_timerAudioTests = new QTimer(this); + if (this->m_timerSimulator == nullptr) this->m_timerSimulator = new QTimer(this); // context if (this->m_coreMode != GuiModes::CoreInGuiProcess) @@ -165,6 +168,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) this->m_contextVoice = new BlackCore::IContextVoice(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextSettings = new BlackCore::IContextSettings(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); this->m_contextApplication = new BlackCore::IContextApplication(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); + this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this); } else { @@ -173,6 +177,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode) this->m_contextVoice = this->m_coreRuntime->getIContextVoice(); this->m_contextSettings = this->m_coreRuntime->getIContextSettings(); this->m_contextApplication = this->m_coreRuntime->getIContextApplication(); + this->m_contextSimulator = this->m_coreRuntime->getIContextSimulator(); } // wire GUI signals @@ -209,12 +214,14 @@ void MainWindow::init(GuiModes::CoreMode coreMode) this->connect(this->m_contextSettings, &IContextSettings::changedSettings, this, &MainWindow::changedSettings); connect = this->connect(this->m_contextNetwork, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)), this, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList))); Q_ASSERT(connect); + this->connect(this->m_contextSimulator, &IContextSimulator::connectionChanged, this, &MainWindow::simulatorAvailable); this->connect(this->m_timerUpdateAircraftsInRange, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); this->connect(this->m_timerUpdateAtcStationsOnline, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); this->connect(this->m_timerUpdateUsers, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); this->connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); this->connect(this->m_timerCollectedCockpitUpdates, &QTimer::timeout, this, &MainWindow::sendCockpitUpdates); this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &MainWindow::audioTestUpdate); + this->connect(this->m_timerSimulator, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); connect = this->connect(this->m_contextVoice, &IContextVoice::audioTestCompleted, this, &MainWindow::audioTestUpdate); // start timers, update timers will be started when network is connected @@ -239,6 +246,9 @@ void MainWindow::init(GuiModes::CoreMode coreMode) // do this as last statement, so it can be used as flag // whether init has been completed this->m_init = true; + + // TODO remove later + simulatorAvailable(); } // @@ -267,6 +277,8 @@ void MainWindow::initGuiSignals() Q_ASSERT(connected); connected = this->connect(this->ui->pb_MainSettings, SIGNAL(released()), this, SLOT(setMainPage())); Q_ASSERT(connected); + connected = this->connect(this->ui->pb_MainSimulator, SIGNAL(released()), this, SLOT(setMainPage())); + Q_ASSERT(connected); connected = this->connect(this->ui->pb_MainStatus, SIGNAL(released()), this, SLOT(setMainPage())); Q_ASSERT(connected); connected = this->connect(this->ui->pb_MainUsers, SIGNAL(released()), this, SLOT(setMainPage()));