Ref T301, cockpit double value frequency comparison (double comparison unsafe)

This commit is contained in:
Klaus Basan
2018-08-12 02:59:24 +02:00
parent 38e2a3ee3d
commit a47da54d8c
2 changed files with 18 additions and 6 deletions

View File

@@ -10,12 +10,15 @@
#include "cockpitcomform.h" #include "cockpitcomform.h"
#include "ui_cockpitcomform.h" #include "ui_cockpitcomform.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/math/mathutils.h"
#include <QPushButton> #include <QPushButton>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Math;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
using namespace BlackGui::Components; using namespace BlackGui::Components;
@@ -185,25 +188,25 @@ namespace BlackGui
void CCockpitComForm::setFrequencies(const CComSystem &com1, const CComSystem &com2) void CCockpitComForm::setFrequencies(const CComSystem &com1, const CComSystem &com2)
{ {
double freq = com1.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3); double freq = com1.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3);
if (freq != ui->ds_ComPanelCom1Active->value()) if (!isFrequenceEqual(freq, ui->ds_ComPanelCom1Active->value()))
{ {
ui->ds_ComPanelCom1Active->setValue(freq); ui->ds_ComPanelCom1Active->setValue(freq);
} }
freq = com2.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3); freq = com2.getFrequencyActive().valueRounded(CFrequencyUnit::MHz(), 3);
if (freq != ui->ds_ComPanelCom2Active->value()) if (!isFrequenceEqual(freq, ui->ds_ComPanelCom2Active->value()))
{ {
ui->ds_ComPanelCom2Active->setValue(freq); ui->ds_ComPanelCom2Active->setValue(freq);
} }
freq = com1.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3); freq = com1.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3);
if (freq != ui->ds_ComPanelCom1Standby->value()) if (!isFrequenceEqual(freq, ui->ds_ComPanelCom1Standby->value()))
{ {
ui->ds_ComPanelCom1Standby->setValue(freq); ui->ds_ComPanelCom1Standby->setValue(freq);
} }
freq = com2.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3); freq = com2.getFrequencyStandby().valueRounded(CFrequencyUnit::MHz(), 3);
if (freq != ui->ds_ComPanelCom2Standby->value()) if (!isFrequenceEqual(freq, ui->ds_ComPanelCom2Standby->value()))
{ {
ui->ds_ComPanelCom2Standby->setValue(freq); ui->ds_ComPanelCom2Standby->setValue(freq);
} }
@@ -220,6 +223,7 @@ namespace BlackGui
if (transponder.getTransponderMode() != ui->cbp_ComPanelTransponderMode->getSelectedTransponderMode()) if (transponder.getTransponderMode() != ui->cbp_ComPanelTransponderMode->getSelectedTransponderMode())
{ {
ui->cbp_ComPanelTransponderMode->setSelectedTransponderMode(transponder.getTransponderMode()); ui->cbp_ComPanelTransponderMode->setSelectedTransponderMode(transponder.getTransponderMode());
ui->comp_TransponderLeds->setMode(transponder.getTransponderMode());
} }
} }
@@ -228,14 +232,14 @@ namespace BlackGui
const QObject *sender = QObject::sender(); const QObject *sender = QObject::sender();
if (sender == ui->tb_ComPanelCom1Toggle) if (sender == ui->tb_ComPanelCom1Toggle)
{ {
if (ui->ds_ComPanelCom1Standby->value() == ui->ds_ComPanelCom1Active->value()) { return; } if (isFrequenceEqual(ui->ds_ComPanelCom1Standby->value(), ui->ds_ComPanelCom1Active->value())) { return; }
const double f = ui->ds_ComPanelCom1Active->value(); const double f = ui->ds_ComPanelCom1Active->value();
ui->ds_ComPanelCom1Active->setValue(ui->ds_ComPanelCom1Standby->value()); ui->ds_ComPanelCom1Active->setValue(ui->ds_ComPanelCom1Standby->value());
ui->ds_ComPanelCom1Standby->setValue(f); ui->ds_ComPanelCom1Standby->setValue(f);
} }
else if (sender == ui->tb_ComPanelCom2Toggle) else if (sender == ui->tb_ComPanelCom2Toggle)
{ {
if (ui->ds_ComPanelCom2Standby->value() == ui->ds_ComPanelCom2Active->value()) { return; } if (isFrequenceEqual(ui->ds_ComPanelCom2Standby->value(), ui->ds_ComPanelCom2Active->value())) { return; }
const double f = ui->ds_ComPanelCom2Active->value(); const double f = ui->ds_ComPanelCom2Active->value();
ui->ds_ComPanelCom2Active->setValue(ui->ds_ComPanelCom2Standby->value()); ui->ds_ComPanelCom2Active->setValue(ui->ds_ComPanelCom2Standby->value());
ui->ds_ComPanelCom2Standby->setValue(f); ui->ds_ComPanelCom2Standby->setValue(f);
@@ -250,5 +254,10 @@ namespace BlackGui
const CSelcal selcal = ui->frp_ComPanelSelcalSelector->getSelcal(); const CSelcal selcal = ui->frp_ComPanelSelcalSelector->getSelcal();
emit this->changedSelcal(selcal); emit this->changedSelcal(selcal);
} }
bool CCockpitComForm::isFrequenceEqual(double f1, double f2)
{
return CMathUtils::epsilonEqual(f1, f2);
}
} // ns } // ns
} // ns } // ns

View File

@@ -99,6 +99,9 @@ namespace BlackGui
//! SELCAL value changed (in selector) //! SELCAL value changed (in selector)
void onSelcalChanged(); void onSelcalChanged();
//! Compare 2 frequencies (consider epsilon)
static bool isFrequenceEqual(double f1, double f2);
QScopedPointer<Ui::CCockpitComForm> ui; QScopedPointer<Ui::CCockpitComForm> ui;
}; };
} // ns } // ns