mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
Ref T111, cockpit COM form to be used in cockpit component and dummy driver
This commit is contained in:
committed by
Mathew Sutcliffe
parent
9040665173
commit
4013154a20
180
src/blackgui/editors/cockpitcomform.cpp
Normal file
180
src/blackgui/editors/cockpitcomform.cpp
Normal file
@@ -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 <QPushButton>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user