diff --git a/src/blackgui/editors/cockpitcomform.cpp b/src/blackgui/editors/cockpitcomform.cpp new file mode 100644 index 000000000..42bcfc6ed --- /dev/null +++ b/src/blackgui/editors/cockpitcomform.cpp @@ -0,0 +1,180 @@ +/* Copyright (C) 2017 + * 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 "cockpitcomform.h" +#include "ui_cockpitcomform.h" +#include "blackmisc/logmessage.h" +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Audio; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Simulation; +using namespace BlackGui::Components; + +namespace BlackGui +{ + namespace Editors + { + CCockpitComForm::CCockpitComForm(QWidget *parent) : + CForm(parent), + ui(new Ui::CCockpitComForm) + { + ui->setupUi(this); + + // SELCAL pairs in cockpit + ui->frp_ComPanelSelcalBottom->clear(); + connect(ui->tb_ComPanelSelcalTest, &QPushButton::clicked, this, &CCockpitComForm::testSelcal); + + // XPdr + connect(ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderModeChanged, this, &CCockpitComForm::transponderModeChanged); + connect(ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderStateIdentEnded, this, &CCockpitComForm::transponderStateIdentEnded); + + // COM GUI events + connect(ui->tb_ComPanelCom1Toggle, &QPushButton::clicked, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->tb_ComPanelCom2Toggle, &QPushButton::clicked, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->ds_ComPanelCom1Active, &QDoubleSpinBox::editingFinished, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->ds_ComPanelCom2Active, &QDoubleSpinBox::editingFinished, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->ds_ComPanelCom1Standby, &QDoubleSpinBox::editingFinished, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->ds_ComPanelCom2Standby, &QDoubleSpinBox::editingFinished, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->sbp_ComPanelTransponder, &QDoubleSpinBox::editingFinished, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderModeChanged, this, &CCockpitComForm::onGuiChangedCockpitValues); + connect(ui->frp_ComPanelSelcalBottom, &CSelcalCodeSelector::valueChanged, this, &CCockpitComForm::onGuiChangedCockpitValues); + } + + CCockpitComForm::~CCockpitComForm() + { } + + void CCockpitComForm::setReadOnly(bool readonly) + { + ui->ds_ComPanelCom1Active->setReadOnly(readonly); + ui->ds_ComPanelCom2Active->setReadOnly(readonly); + ui->ds_ComPanelCom1Standby->setReadOnly(readonly); + ui->ds_ComPanelCom2Standby->setReadOnly(readonly); + ui->cbp_ComPanelTransponderMode->setDisabled(!readonly); + ui->tb_ComPanelCom1Toggle->setEnabled(!readonly); + ui->tb_ComPanelCom2Toggle->setEnabled(!readonly); + } + + void CCockpitComForm::setSelectOnly() + { + this->setReadOnly(true); + } + + CStatusMessageList CCockpitComForm::validate(bool nested) const + { + Q_UNUSED(nested); + CStatusMessageList msgs; + return msgs; + } + + void CCockpitComForm::changeVoiceRoomStatus(const Audio::CVoiceRoomList &selectedVoiceRooms) + { + Q_ASSERT_X(selectedVoiceRooms.size() == 2, Q_FUNC_INFO, "Expect 2 voice rooms"); + const CVoiceRoom room1 = selectedVoiceRooms[0]; + const CVoiceRoom room2 = selectedVoiceRooms[1]; + ui->led_ComPanelCom1->setOn(room1.isConnected()); + ui->led_ComPanelCom2->setOn(room2.isConnected()); + } + + void CCockpitComForm::initLeds() + { + const CLedWidget::LedShape shape = CLedWidget::Rounded; + ui->led_ComPanelCom1->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "COM1 connected", "COM1 disconnected", 14); + ui->led_ComPanelCom2->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "COM2 connected", "COM2 disconnected", 14); + } + + CSimulatedAircraft CCockpitComForm::cockpitValuesToAircraftObject() + { + CSimulatedAircraft comAircraft; + CTransponder transponder = comAircraft.getTransponder(); + CComSystem com1 = comAircraft.getCom1System(); + CComSystem com2 = comAircraft.getCom2System(); + + // + // Transponder + // + const QString transponderCode = QString::number(ui->sbp_ComPanelTransponder->value()); + if (CTransponder::isValidTransponderCode(transponderCode)) + { + transponder.setTransponderCode(transponderCode); + } + else + { + CLogMessage(this).validationWarning("Wrong transponder code, reset"); + ui->sbp_ComPanelTransponder->setValue(transponder.getTransponderCode()); + } + transponder.setTransponderMode(ui->cbp_ComPanelTransponderMode->getSelectedTransponderMode()); + + // + // COM units + // + com1.setFrequencyActiveMHz(ui->ds_ComPanelCom1Active->value()); + com1.setFrequencyStandbyMHz(ui->ds_ComPanelCom1Standby->value()); + com2.setFrequencyActiveMHz(ui->ds_ComPanelCom2Active->value()); + com2.setFrequencyStandbyMHz(ui->ds_ComPanelCom2Standby->value()); + this->updateFrequencyDisplaysFromComSystems(com1, com2); // back annotation after rounding + + comAircraft.setCom1System(com1); + comAircraft.setCom2System(com2); + comAircraft.setTransponder(transponder); + return comAircraft; + } + + void CCockpitComForm::updateFrequencyDisplaysFromComSystems(const CComSystem &com1, const CComSystem &com2) + { + double freq = com1.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != ui->ds_ComPanelCom1Active->value()) + { + ui->ds_ComPanelCom1Active->setValue(freq); + } + + freq = com2.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != ui->ds_ComPanelCom2Active->value()) + { + ui->ds_ComPanelCom2Active->setValue(freq); + } + + freq = com1.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != ui->ds_ComPanelCom1Standby->value()) + { + ui->ds_ComPanelCom1Standby->setValue(freq); + } + + freq = com2.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3); + if (freq != ui->ds_ComPanelCom2Standby->value()) + { + ui->ds_ComPanelCom2Standby->setValue(freq); + } + } + + void CCockpitComForm::onGuiChangedCockpitValues() + { + const QObject *sender = QObject::sender(); + if (sender == ui->tb_ComPanelCom1Toggle) + { + if (ui->ds_ComPanelCom1Standby->value() == ui->ds_ComPanelCom1Active->value()) { return; } + const double f = ui->ds_ComPanelCom1Active->value(); + ui->ds_ComPanelCom1Active->setValue(ui->ds_ComPanelCom1Standby->value()); + ui->ds_ComPanelCom1Standby->setValue(f); + } + else if (sender == ui->tb_ComPanelCom2Toggle) + { + if (ui->ds_ComPanelCom2Standby->value() == ui->ds_ComPanelCom2Active->value()) { return; } + const double f = ui->ds_ComPanelCom2Active->value(); + ui->ds_ComPanelCom2Active->setValue(ui->ds_ComPanelCom2Standby->value()); + ui->ds_ComPanelCom2Standby->setValue(f); + } + + const CSimulatedAircraft aircraft = this->cockpitValuesToAircraftObject(); + emit this->guiChangedCockpitValues(aircraft); + } + } // ns +} // ns diff --git a/src/blackgui/editors/cockpitcomform.h b/src/blackgui/editors/cockpitcomform.h new file mode 100644 index 000000000..466639aa5 --- /dev/null +++ b/src/blackgui/editors/cockpitcomform.h @@ -0,0 +1,80 @@ +/* Copyright (C) 2017 + * 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 BLACKGUI_EDITORS_COCKPITCOMFORM_H +#define BLACKGUI_EDITORS_COCKPITCOMFORM_H + +#include "form.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/audio/voiceroomlist.h" +#include +#include + +namespace Ui { class CCockpitComForm; } +namespace BlackGui +{ + namespace Editors + { + /*! + * COM elements + */ + class CCockpitComForm : public CForm + { + Q_OBJECT + + public: + //! Constructor + explicit CCockpitComForm(QWidget *parent = nullptr); + + //! Destrutor + virtual ~CCockpitComForm(); + + //! Change the voice room status + void changeVoiceRoomStatus(const BlackMisc::Audio::CVoiceRoomList &selectedVoiceRooms); + + //! \name Form class implementations + //! @{ + virtual void setReadOnly(bool readonly) override; + virtual void setSelectOnly() override; + virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override; + //! @} + + signals: + //! \copydoc BlackGui::Components::CTransponderModeSelector::transponderModeChanged + void transponderModeChanged(BlackMisc::Aviation::CTransponder::TransponderMode newMode); + + //! \copydoc BlackGui::Components::CTransponderModeSelector::transponderStateIdentEnded + void transponderStateIdentEnded(); + + //! Request to test SELCAL + void testSelcal(); + + //! GUI values changed + void guiChangedCockpitValues(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + + private: + //! Init LEDs + void initLeds(); + + //! Cockpit values to aircraft + BlackMisc::Simulation::CSimulatedAircraft cockpitValuesToAircraftObject(); + + //! COM frequencies displayed + void updateFrequencyDisplaysFromComSystems(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2); + + //! GUI values have been changed, will trigger CCockpitComForm::guiChangedCockpitValues + void onGuiChangedCockpitValues(); + + QScopedPointer ui; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/editors/cockpitcomform.ui b/src/blackgui/editors/cockpitcomform.ui new file mode 100644 index 000000000..e591f5b66 --- /dev/null +++ b/src/blackgui/editors/cockpitcomform.ui @@ -0,0 +1,526 @@ + + + CCockpitComForm + + + + 0 + 0 + 292 + 95 + + + + Frame + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 2 + + + 2 + + + 2 + + + 2 + + + 4 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + COM2: + + + qw_ComPanelCom2Active + + + + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + standby: + + + + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + 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 + + + + COM1: + + + qw_ComPanelCom1Active + + + + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + standby: + + + + + + + 3 + + + 118.000000000000000 + + + 136.974999999999994 + + + 0.025000000000000 + + + 119.000000000000000 + + + + + + + Toggle COM 2 standby/active + + + + + + + :/diagona/icons/diagona/icons/arrow-circle-double-135.png:/diagona/icons/diagona/icons/arrow-circle-double-135.png + + + + + + + + + + + + + 0 + + + + 2 + + + 2 + + + 2 + + + 2 + + + 4 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + XPDR: + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 18 + + + + 7777 + + + 7000 + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + SELCAL: + + + + + + + + 0 + 0 + + + + test SELCAL + + + test SELCAL + + + + :/diagona/icons/diagona/icons/speaker-volume.png:/diagona/icons/diagona/icons/speaker-volume.png + + + + + + + + + + + + + + + + + BlackGui::Components::CSelcalCodeSelector + QFrame +
blackgui/components/selcalcodeselector.h
+ 1 +
+ + BlackGui::CLedWidget + QWidget +
blackgui/led.h
+ 1 +
+ + BlackGui::Components::CTransponderModeSelector + QComboBox +
blackgui/components/transpondermodeselector.h
+
+ + BlackGui::Components::CTransponderCodeSpinBox + QSpinBox +
blackgui/components/transpondercodespinbox.h
+
+ + BlackGui::Components::CCockpitTransponderModeLedsComponent + QFrame +
blackgui/components/cockpittranspondermodeledscomponent.h
+ 1 +
+
+ + + + +