mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +08:00
refs #396 move Blackmisc Aviation classes into subfolder
This commit is contained in:
119
src/blackmisc/aviation/selcal.cpp
Normal file
119
src/blackmisc/aviation/selcal.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/* 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/selcal.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
QList<CFrequency> CSelcal::frequencyEquivalents = QList<CFrequency>();
|
||||
QStringList CSelcal::allCodePairs = QStringList();
|
||||
|
||||
QString CSelcal::convertToQString(bool /** i18n **/) const
|
||||
{
|
||||
return this->m_code;
|
||||
}
|
||||
|
||||
bool CSelcal::equalsString(const QString &code) const
|
||||
{
|
||||
if (code.isEmpty()) return false;
|
||||
return (this->m_code.compare(code, Qt::CaseInsensitive) == 0);
|
||||
}
|
||||
|
||||
QList<CFrequency> CSelcal::getFrequencies() const
|
||||
{
|
||||
QList<CFrequency> f;
|
||||
if (!CSelcal::isValidCode(this->m_code)) return f;
|
||||
for (int pos = 0; pos < this->m_code.length(); pos++)
|
||||
{
|
||||
f.append(CSelcal::audioFrequencyEquivalent(this->m_code.at(pos)));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
const QString &CSelcal::validCharacters()
|
||||
{
|
||||
static const QString valid = "ABCDEFGHJKLMPQRS";
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool CSelcal::isValidCharacter(QChar c)
|
||||
{
|
||||
return CSelcal::validCharacters().contains(c.toUpper());
|
||||
}
|
||||
|
||||
bool CSelcal::isValidCode(const QString &code)
|
||||
{
|
||||
if (code.length() != 4) return false;
|
||||
int p1, p2, p3, p4;
|
||||
QString codeUpper = code.toUpper();
|
||||
if ((p1 = CSelcal::validCharacters().indexOf(codeUpper.at(0))) < 0) return false;
|
||||
if ((p2 = CSelcal::validCharacters().indexOf(codeUpper.at(1))) < 0) return false;
|
||||
if ((p3 = CSelcal::validCharacters().indexOf(codeUpper.at(2))) < 0) return false;
|
||||
if ((p4 = CSelcal::validCharacters().indexOf(codeUpper.at(3))) < 0) return false;
|
||||
if (p1 >= p2 || p3 >= p4) return false; // pair in alphabetical order
|
||||
if (p1 == p3 || p2 == p3 || p2 == p4 || p3 == p4) return false; // given letter can be used only once in a SELCAL code
|
||||
return true;
|
||||
}
|
||||
|
||||
const PhysicalQuantities::CFrequency &CSelcal::audioFrequencyEquivalent(QChar c)
|
||||
{
|
||||
if (CSelcal::frequencyEquivalents.isEmpty())
|
||||
{
|
||||
QList<CFrequency> frequencies;
|
||||
frequencies
|
||||
<< CFrequency(312.7, CFrequencyUnit::Hz())
|
||||
<< CFrequency(346.7, CFrequencyUnit::Hz())
|
||||
<< CFrequency(384.6, CFrequencyUnit::Hz())
|
||||
<< CFrequency(426.6, CFrequencyUnit::Hz())
|
||||
<< CFrequency(473.2, CFrequencyUnit::Hz())
|
||||
<< CFrequency(524.8, CFrequencyUnit::Hz())
|
||||
<< CFrequency(582.1, CFrequencyUnit::Hz())
|
||||
<< CFrequency(645.7, CFrequencyUnit::Hz())
|
||||
<< CFrequency(716.1, CFrequencyUnit::Hz())
|
||||
<< CFrequency(794.3, CFrequencyUnit::Hz())
|
||||
<< CFrequency(881.0, CFrequencyUnit::Hz())
|
||||
<< CFrequency(977.2, CFrequencyUnit::Hz())
|
||||
<< CFrequency(1083.9, CFrequencyUnit::Hz())
|
||||
<< CFrequency(1202.3, CFrequencyUnit::Hz())
|
||||
<< CFrequency(1333.5, CFrequencyUnit::Hz())
|
||||
<< CFrequency(1479.1, CFrequencyUnit::Hz());
|
||||
CSelcal::frequencyEquivalents = frequencies;
|
||||
}
|
||||
int pos = CSelcal::validCharacters().indexOf(c);
|
||||
Q_ASSERT(pos >= 0);
|
||||
Q_ASSERT(CSelcal::frequencyEquivalents.size() > pos);
|
||||
return CSelcal::frequencyEquivalents.at(pos);
|
||||
}
|
||||
|
||||
const QStringList &CSelcal::codePairs()
|
||||
{
|
||||
if (CSelcal::allCodePairs.isEmpty())
|
||||
{
|
||||
QStringList pairs;
|
||||
for (int p1 = 0; p1 < (CSelcal::validCharacters().length() - 1); p1++)
|
||||
{
|
||||
for (int p2 = p1 + 1; p2 < CSelcal::validCharacters().length(); p2++)
|
||||
{
|
||||
QString pair;
|
||||
pair.append(CSelcal::validCharacters().at(p1)).append(CSelcal::validCharacters().at(p2));
|
||||
pairs.append(pair);
|
||||
}
|
||||
}
|
||||
CSelcal::allCodePairs = pairs;
|
||||
}
|
||||
return CSelcal::allCodePairs;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user