mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #335, added functionality for com components
* set COM unit values * set values in context
This commit is contained in:
committed by
Roland Winklmeier
parent
48741c218f
commit
fa60703a1d
@@ -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 <QDoubleSpinBox>
|
||||
#include <QPushButton>
|
||||
|
||||
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<qint32>(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
|
||||
|
||||
Reference in New Issue
Block a user