/* Copyright (C) 2013 * 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 "blackmisc/aviation/modulator.h" #include "blackmisc/aviation/comsystem.h" #include "blackmisc/aviation/navsystem.h" #include "blackmisc/aviation/adfsystem.h" #include "blackmisc/math/mathutils.h" #include "blackmisc/pq/units.h" #include "blackmisc/propertyindex.h" #include "blackmisc/variant.h" #include "blackmisc/comparefunctions.h" #include #include using BlackMisc::PhysicalQuantities::CFrequency; using BlackMisc::PhysicalQuantities::CFrequencyUnit; namespace BlackMisc { namespace Aviation { template void CModulator::toggleActiveStandby() { const CFrequency a = this->m_frequencyActive; this->m_frequencyActive = this->m_frequencyStandby; this->m_frequencyStandby = a; } template BlackMisc::PhysicalQuantities::CFrequency CModulator::getFrequencyActive() const { return this->m_frequencyActive; } template BlackMisc::PhysicalQuantities::CFrequency CModulator::getFrequencyStandby() const { return this->m_frequencyStandby; } template void CModulator::setFrequencyActive(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { this->m_frequencyActive = frequency; } template void CModulator::setFrequencyStandby(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { this->m_frequencyStandby = frequency; } template int CModulator::getVolumeOutput() const { return this->m_volumeOutput; } template int CModulator::getVolumeInput() const { return this->m_volumeInput; } template void CModulator::setVolumeOutput(int volume) { this->m_volumeOutput = volume; } template void CModulator::setVolumeInput(int volume) { this->m_volumeInput = volume; } template bool CModulator::isEnabled() const { return this->m_enabled; } template void CModulator::setEnabled(bool enable) { this->m_enabled = enable; } template QString CModulator::getName() const { return this->m_name; } template CVariant CModulator::propertyByIndex(const CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*derived()); } const ColumnIndex i = index.frontCasted(); switch (i) { case IndexActiveFrequency: return this->getFrequencyActive().propertyByIndex(index.copyFrontRemoved()); case IndexStandbyFrequency: return this->getFrequencyStandby().propertyByIndex(index.copyFrontRemoved()); case IndexEnabled: return CVariant::from(this->isEnabled()); case IndexInputVolume: return CVariant::from(this->getVolumeInput()); case IndexOutputVolume: return CVariant::from(this->getVolumeOutput()); default: return CValueObject>::propertyByIndex(index); } } template void CModulator::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong index to base template"); return; } const ColumnIndex i = index.frontCasted(); switch (i) { case IndexActiveFrequency: this->m_frequencyActive.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexStandbyFrequency: this->m_frequencyStandby.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexEnabled: this->setEnabled(variant.toBool()); break; case IndexInputVolume: this->setVolumeInput(variant.toInt()); break; case IndexOutputVolume: this->setVolumeOutput(variant.toInt()); break; default: CValueObject>::setPropertyByIndex(index, variant); break; } } template int CModulator::comparePropertyByIndex(const CPropertyIndex &index, const AVIO &compareValue) const { if (index.isMyself()) { return this->m_frequencyActive.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_frequencyActive); } const ColumnIndex i = index.frontCasted(); switch (i) { case IndexActiveFrequency: return this->m_frequencyActive.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_frequencyActive); case IndexStandbyFrequency: return this->m_frequencyStandby.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.m_frequencyStandby); case IndexEnabled: return Compare::compare(this->isEnabled(), compareValue.isEnabled()); case IndexInputVolume: return Compare::compare(this->getVolumeInput(), compareValue.getVolumeInput()); case IndexOutputVolume: return Compare::compare(this->getVolumeOutput(), compareValue.getVolumeOutput()); default: break; } Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed"); return 0; } template CModulator::CModulator() : m_name("default") { static_assert(!std::is_polymorphic::value, "Must not use virtual functions for value classes"); } template CModulator::CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency) : m_name(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency) { static_assert(!std::is_polymorphic::value, "Must not use virtual functions for value classes"); } template QString CModulator::convertToQString(bool i18n) const { QString s(this->getName()); s.append(" Active: ").append(this->m_frequencyActive.valueRoundedWithUnit(3, i18n)); s.append(" Standby: ").append(this->m_frequencyStandby.valueRoundedWithUnit(3, i18n)); return s; } template void CModulator::setFrequencyActiveKHz(double frequencyKHz) { this->m_frequencyActive = BlackMisc::PhysicalQuantities::CFrequency(frequencyKHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz()); } template void CModulator::setFrequencyStandbyKHz(double frequencyKHz) { this->m_frequencyStandby = BlackMisc::PhysicalQuantities::CFrequency(frequencyKHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz()); } template const QString &CModulator::NameCom1() { static QString n("COM1"); return n; } template const QString &CModulator::NameCom2() { static QString n("COM2"); return n; } template const QString &CModulator::NameCom3() { static QString n("COM3"); return n; } template const QString &CModulator::NameNav1() { static QString n("NAV1"); return n; } template const QString &CModulator::NameNav2() { static QString n("NAV2"); return n; } template const QString &CModulator::NameNav3() { static QString n("NAV3"); return n; } template const QString &CModulator::NameAdf1() { static QString n("ADF1"); return n; } template const QString &CModulator::NameAdf2() { static QString n("ADF2"); return n; } // see here for the reason of the forward instantiations // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl //! \cond PRIVATE template class BLACKMISC_EXPORT_DEFINE_TEMPLATE CModulator; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE CModulator; template class BLACKMISC_EXPORT_DEFINE_TEMPLATE CModulator; //! \endcond } // namespace } // namespace