From fa60703a1d67bb3bfa22b02ddb8d2b5e811555a9 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 22 Oct 2014 15:00:17 +0200 Subject: [PATCH] refs #335, added functionality for com components * set COM unit values * set values in context --- .../components/cockpitcomcomponent.cpp | 230 +++++ src/blackgui/components/cockpitcomcomponent.h | 39 +- .../components/cockpitcomcomponent.ui | 852 ++++++++++-------- 3 files changed, 729 insertions(+), 392 deletions(-) diff --git a/src/blackgui/components/cockpitcomcomponent.cpp b/src/blackgui/components/cockpitcomcomponent.cpp index 8815ef8aa..c74fd7468 100644 --- a/src/blackgui/components/cockpitcomcomponent.cpp +++ b/src/blackgui/components/cockpitcomcomponent.cpp @@ -10,8 +10,17 @@ #include "cockpitcomcomponent.h" #include "ui_cockpitcomcomponent.h" #include "../stylesheetutility.h" +#include "blackcore/context_network.h" +#include "blackmisc/avaircraft.h" +#include "blackmisc/logmessage.h" + +#include +#include using namespace BlackGui; +using namespace BlackCore; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; namespace BlackGui { @@ -23,6 +32,7 @@ namespace BlackGui ui(new Ui::CCockpitMainComponent) { ui->setupUi(this); + this->initLeds(); } CCockpitComComponent::~CCockpitComComponent() @@ -34,5 +44,225 @@ namespace BlackGui CStyleSheetUtility::useStyleSheetInDerivedWidget(this); } + void CCockpitComComponent::runtimeHasBeenSet() + { + + // SELCAL pairs in cockpit + this->ui->cb_ComPanelSelcalSelector1->clear(); + this->ui->cb_ComPanelSelcalSelector2->clear(); + this->ui->cb_ComPanelSelcalSelector1->addItems(BlackMisc::Aviation::CSelcal::codePairs()); + this->ui->cb_ComPanelSelcalSelector2->addItems(BlackMisc::Aviation::CSelcal::codePairs()); + connect(this->ui->pb_ComPanelSelcalTest, &QPushButton::clicked, this, &CCockpitComComponent::ps_testSelcal); + + // COM GUI events + connect(this->ui->pb_ComPanelCom1Toggle, &QPushButton::clicked, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + connect(this->ui->pb_ComPanelCom2Toggle, &QPushButton::clicked, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + + connect(this->ui->ds_ComPanelCom1Active, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + connect(this->ui->ds_ComPanelCom2Active, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + connect(this->ui->ds_ComPanelCom1Standby, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + connect(this->ui->ds_ComPanelCom2Standby, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + connect(this->ui->ds_ComPanelTransponder, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + connect(this->ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::valueChanged, this, &CCockpitComComponent::ps_guiChangedCockpitValues); + + // hook up with changes from own aircraft context + Q_ASSERT(this->getIContextOwnAircraft()); + this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitComComponent::ps_updateCockpitFromContext); + } + + void CCockpitComComponent::ps_guiChangedCockpitValues() + { + QObject *sender = QObject::sender(); + if (sender == this->ui->pb_ComPanelCom1Toggle) + { + if (this->ui->ds_ComPanelCom1Standby->value() == this->ui->ds_ComPanelCom1Active->value()) return; + double f = this->ui->ds_ComPanelCom1Active->value(); + this->ui->ds_ComPanelCom1Active->setValue(this->ui->ds_ComPanelCom1Standby->value()); + this->ui->ds_ComPanelCom1Standby->setValue(f); + } + else if (sender == this->ui->pb_ComPanelCom2Toggle) + { + if (this->ui->ds_ComPanelCom2Standby->value() == this->ui->ds_ComPanelCom2Active->value()) return; + double f = this->ui->ds_ComPanelCom2Active->value(); + this->ui->ds_ComPanelCom2Active->setValue(this->ui->ds_ComPanelCom2Standby->value()); + this->ui->ds_ComPanelCom2Standby->setValue(f); + } + else if (sender == this->ui->cbp_ComPanelTransponderMode) + { + // toggle the external button + if (this->ui->cbp_ComPanelTransponderMode->isIdentSelected()) + { + // todo + } + } + + const CAircraft ownAircraft = this->cockpitValuesToAircraftObject(); + this->updateOwnCockpitInContext(ownAircraft); + } + + void CCockpitComComponent::ps_updateCockpitFromContext(const CAircraft &ownAircraft, const QString &originator) + { + if (originator == CCockpitComComponent::cockpitOriginator()) return; // comes from myself + + // update GUI elements + // avoid unnecessary change events as far as possible + const CComSystem com1 = ownAircraft.getCom1System(); // aircraft just updated or set from context + const CComSystem com2 = ownAircraft.getCom2System(); + const CTransponder transponder = ownAircraft.getTransponder(); + + // update the frequencies + this->updateComFrequencyDisplaysFromComSystems(com1, com2); + + // update transponder + qint32 tc = transponder.getTransponderCode(); + if (tc != static_cast(this->ui->ds_ComPanelTransponder->value())) + this->ui->ds_ComPanelTransponder->setValue(tc); + + this->ui->cbp_ComPanelTransponderMode->setSelectedTransponderMode(transponder.getTransponderMode()); + + if (this->getIContextNetwork()) + { + CAtcStationList selectedStations = this->getIContextNetwork()->getSelectedAtcStations(); + CAtcStation com1Station = selectedStations[0]; + CAtcStation com2Station = selectedStations[1]; + if (com1Station.getCallsign().isEmpty()) + { + this->ui->lbl_ComPanelCom1Active->setToolTip(""); + this->ui->led_ComPanelCom1->setOn(false); + } + else + { + this->ui->lbl_ComPanelCom1Active->setToolTip(com1Station.getCallsign().getStringAsSet()); + this->ui->led_ComPanelCom1->setOn(true); + + } + if (com2Station.getCallsign().isEmpty()) + { + this->ui->lbl_ComPanelCom2Active->setToolTip(""); + this->ui->led_ComPanelCom2->setOn(false); + } + else + { + this->ui->lbl_ComPanelCom2Active->setToolTip(com2Station.getCallsign().getStringAsSet()); + this->ui->led_ComPanelCom2->setOn(true); + } + } + } + + void CCockpitComComponent::ps_testSelcal() + { + QString selcalCode = this->getSelcalCode(); + if (!CSelcal::isValidCode(selcalCode)) + { + CLogMessage().validationWarning("Invalid SELCAL codde"); + } + else if (this->getIContextAudio()) + { + CSelcal selcal(selcalCode); + this->getIContextAudio()->playSelcalTone(selcal); + } + else + { + CLogMessage().validationWarning("No audio available"); + } + } + + QString CCockpitComComponent::getSelcalCode() const + { + QString selcal = this->ui->cb_ComPanelSelcalSelector1->currentText().append(this->ui->cb_ComPanelSelcalSelector2->currentText()); + return selcal; + } + + void CCockpitComComponent::initLeds() + { + CLedWidget::LedShape shape = CLedWidget::Rounded; + this->ui->led_ComPanelCom1->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "COM1 connected", "COM1 disconnected", 14); + this->ui->led_ComPanelCom2->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "COM2 connected", "COM2 disconnected", 14); + } + + CAircraft CCockpitComComponent::cockpitValuesToAircraftObject() + { + CAircraft ownAircraft = this->getOwnAircraft(); + CTransponder transponder = ownAircraft.getTransponder(); + CComSystem com1 = ownAircraft.getCom1System(); + CComSystem com2 = ownAircraft.getCom2System(); + + // + // Transponder + // + QString transponderCode = QString::number(qRound(this->ui->ds_ComPanelTransponder->value())); + if (CTransponder::isValidTransponderCode(transponderCode)) + { + transponder.setTransponderCode(transponderCode); + } + else + { + CLogMessage().validationWarning("Wrong transponder code, reset"); + this->ui->ds_ComPanelTransponder->setValue(transponder.getTransponderCode()); + } + transponder.setTransponderMode(this->ui->cbp_ComPanelTransponderMode->getSelectedTransponderMode()); + + // + // COM units + // + com1.setFrequencyActiveMHz(this->ui->ds_ComPanelCom1Active->value()); + com1.setFrequencyStandbyMHz(this->ui->ds_ComPanelCom1Standby->value()); + com2.setFrequencyActiveMHz(this->ui->ds_ComPanelCom2Active->value()); + com2.setFrequencyStandbyMHz(this->ui->ds_ComPanelCom2Standby->value()); + this->updateComFrequencyDisplaysFromComSystems(com1, com2); // back annotation after rounding + + ownAircraft.setCom1System(com1); + ownAircraft.setCom2System(com2); + ownAircraft.setTransponder(transponder); + return ownAircraft; + } + + CAircraft CCockpitComComponent::getOwnAircraft() const + { + Q_ASSERT(this->getIContextOwnAircraft()); + if (!this->getIContextOwnAircraft()) return CAircraft(); + return this->getIContextOwnAircraft()->getOwnAircraft(); + } + + bool CCockpitComComponent::updateOwnCockpitInContext(const CAircraft &ownAircraft) + { + return this->getIContextOwnAircraft()->updateOwnCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), ownAircraft.getTransponder(), CCockpitComComponent::cockpitOriginator()); + } + + void CCockpitComComponent::updateComFrequencyDisplaysFromComSystems(const CComSystem &com1, const CComSystem &com2) + { + double freq = com1.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != this->ui->ds_ComPanelCom1Active->value()) + { + this->ui->ds_ComPanelCom1Active->setValue(freq); + } + + freq = com2.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != this->ui->ds_ComPanelCom2Active->value()) + { + this->ui->ds_ComPanelCom2Active->setValue(freq); + } + + freq = com1.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != this->ui->ds_ComPanelCom1Standby->value()) + { + this->ui->ds_ComPanelCom1Standby->setValue(freq); + } + + freq = com2.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != this->ui->ds_ComPanelCom2Standby->value()) + { + this->ui->ds_ComPanelCom2Standby->setValue(freq); + } + } + + const QString CCockpitComComponent::cockpitOriginator() + { + // string is generated once, the timestamp allows to use multiple + // components (as long as they are not generated in the same ms) + static const QString o = QString("COCKPITCOMCOMPONENT:").append(QString::number(QDateTime::currentMSecsSinceEpoch())); + return o; + } + } // namespace } // namespace diff --git a/src/blackgui/components/cockpitcomcomponent.h b/src/blackgui/components/cockpitcomcomponent.h index 4f432f730..897ef5b94 100644 --- a/src/blackgui/components/cockpitcomcomponent.h +++ b/src/blackgui/components/cockpitcomcomponent.h @@ -11,6 +11,7 @@ #define BLACKGUI_COCKPITCOMCOMPONENT_H #include "enablefordockwidgetinfoarea.h" +#include "enableforruntime.h" #include #include @@ -23,7 +24,8 @@ namespace BlackGui //! The main cockpit area class CCockpitComComponent : public QFrame, - public CEnableForDockWidgetInfoArea + public CEnableForDockWidgetInfoArea, + public CEnableForRuntime { Q_OBJECT @@ -38,7 +40,42 @@ namespace BlackGui //! \copydoc QWidget::paintEvent virtual void paintEvent(QPaintEvent *event) override; + //! \copydoc CEnableForRuntime::runtimeHasBeenSet + virtual void runtimeHasBeenSet() override; + + private slots: + //! Cockpit values have been changed in GUI + void ps_guiChangedCockpitValues(); + + //! Update cockpit from context + void ps_updateCockpitFromContext(const BlackMisc::Aviation::CAircraft &ownAircraft, const QString &originator); + + //! Cockpit values have been changed in GUI + void ps_testSelcal(); + private: + //! Init LEDs + void initLeds(); + + //! Cockpit values to aircraft + BlackMisc::Aviation::CAircraft cockpitValuesToAircraftObject(); + + //! Get own aircraft + BlackMisc::Aviation::CAircraft getOwnAircraft() const; + + //! Current SELCAL code + QString getSelcalCode() const; + + //! Cockpit updates + bool updateOwnCockpitInContext(const BlackMisc::Aviation::CAircraft &ownAircraft); + + //! COM frequencies displayed + void updateComFrequencyDisplaysFromComSystems(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2); + + //! Identifies sender of cockpit updates + // TODO: Check if to be migrated to COriginator + static const QString cockpitOriginator(); + QScopedPointer ui; }; diff --git a/src/blackgui/components/cockpitcomcomponent.ui b/src/blackgui/components/cockpitcomcomponent.ui index 6da775a5b..ed2d422cc 100644 --- a/src/blackgui/components/cockpitcomcomponent.ui +++ b/src/blackgui/components/cockpitcomcomponent.ui @@ -6,8 +6,8 @@ 0 0 - 363 - 81 + 297 + 89 @@ -52,393 +52,7 @@ 2 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - COM2: - - - qw_ComPanelCom2Active - - - - - - - - 0 - 0 - - - - DDD.990 - - - 128.800 - - - 7 - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - COM1: - - - qw_ComPanelCom1Active - - - - - - - - 0 - 0 - - - - DDD.990 - - - 123.750 - - - 7 - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - standby: - - - - - - - - 0 - 0 - - - - DDD.990 - - - 123.750 - - - 7 - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Toggle COM 1 standby/active - - - - - - - :/diagona/icons/diagona/icons/arrow-circle-double-135.png:/diagona/icons/diagona/icons/arrow-circle-double-135.png - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - standby: - - - - - - - - 0 - 0 - - - - DDD.990 - - - 123.750 - - - 7 - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Toggle COM 2 standby/active - - - - - - - :/diagona/icons/diagona/icons/arrow-circle-double-135.png:/diagona/icons/diagona/icons/arrow-circle-double-135.png - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::NoFrame - - - XPDR: - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 2 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - 9999 - - - 7000 - - - 4 - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - - - - - - - + @@ -535,15 +149,21 @@ + + + 0 + 0 + + SELCAL: - + - + 0 0 @@ -566,6 +186,450 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + COM2: + + + qw_ComPanelCom2Active + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + standby: + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Toggle COM 1 standby/active + + + + + + + :/diagona/icons/diagona/icons/arrow-circle-double-135.png:/diagona/icons/diagona/icons/arrow-circle-double-135.png + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + standby: + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Toggle COM 2 standby/active + + + + + + + :/diagona/icons/diagona/icons/arrow-circle-double-135.png:/diagona/icons/diagona/icons/arrow-circle-double-135.png + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + XPDR: + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 18 + + + + 0 + + + 7777.000000000000000 + + + 7000.000000000000000 + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + + 0 + 0 + + + + COM1: + + + qw_ComPanelCom1Active + + + + + + + + + @@ -576,6 +640,12 @@ QComboBox
blackgui/transpondermodeselector.h
+ + BlackGui::CLedWidget + QWidget +
blackgui/led.h
+ 1 +