mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
MS & KB workshop: ICAO class renamings.
This commit is contained in:
186
src/blackmisc/aviation/aircrafticaodata.cpp
Normal file
186
src/blackmisc/aviation/aircrafticaodata.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/* 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/aircrafticaodata.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CAircraftIcaoData::CAircraftIcaoData(const QString &icao, const QString &airline)
|
||||
: m_aircraftDesignator(icao.trimmed().toUpper()), m_airlineDesignator(airline.trimmed().toUpper())
|
||||
{}
|
||||
|
||||
QString CAircraftIcaoData::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s(this->m_aircraftDesignator);
|
||||
if (this->hasAircraftCombinedType()) s.append(" ").append(this->m_aircraftCombinedType);
|
||||
if (this->hasAirlineDesignator()) s.append(" ").append(this->m_airlineDesignator);
|
||||
if (this->hasLivery()) s.append(" ").append(this->m_livery);
|
||||
if (this->hasAircraftColor()) s.append(" ").append(this->m_aircraftColor);
|
||||
return s;
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::hasAircraftDesignator() const
|
||||
{
|
||||
return !this->m_aircraftDesignator.isEmpty();
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::hasKnownAircraftDesignator() const
|
||||
{
|
||||
return (this->hasAircraftDesignator() && this->getAircraftDesignator() != "ZZZZ");
|
||||
}
|
||||
|
||||
QString CAircraftIcaoData::getEngineType() const
|
||||
{
|
||||
if (this->m_aircraftCombinedType.length() != 3) return "";
|
||||
return this->m_aircraftCombinedType.right(1);
|
||||
}
|
||||
|
||||
QString CAircraftIcaoData::asString() const
|
||||
{
|
||||
if (this->m_aircraftDesignator.isEmpty()) { return ""; }
|
||||
QString s(this->m_aircraftDesignator);
|
||||
if (!this->m_airlineDesignator.isEmpty())
|
||||
{
|
||||
s.append(" (").append(this->m_airlineDesignator).append(")");
|
||||
return s;
|
||||
}
|
||||
if (!this->m_aircraftColor.isEmpty())
|
||||
{
|
||||
s.append(" (").append(this->m_aircraftColor).append(")");
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void CAircraftIcaoData::updateMissingParts(const CAircraftIcaoData &icao)
|
||||
{
|
||||
if (this->m_aircraftDesignator.isEmpty()) { this->setAircraftDesignator(icao.getAircraftDesignator()); }
|
||||
if (this->m_airlineDesignator.isEmpty()) { this->setAirlineDesignator(icao.getAirlineDesignator()); }
|
||||
if (this->m_aircraftCombinedType.isEmpty()) { this->setAircraftCombinedType(icao.getAircraftCombinedType()); }
|
||||
if (this->m_aircraftColor.isEmpty()) { this->setAircraftColor(icao.getAircraftColor()); }
|
||||
if (this->m_livery.isEmpty()) { this->setLivery(icao.getLivery()); }
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::matchesWildcardIcao(const CAircraftIcaoData &otherIcao) const
|
||||
{
|
||||
if ((*this) == otherIcao) return true;
|
||||
if (otherIcao.hasAircraftDesignator() && otherIcao.getAircraftDesignator() != this->getAircraftDesignator()) { return false; }
|
||||
if (otherIcao.hasAirlineDesignator() && otherIcao.getAirlineDesignator() != this->getAirlineDesignator()) { return false; }
|
||||
if (otherIcao.hasAircraftCombinedType() && otherIcao.getAircraftCombinedType() != this->getAircraftCombinedType()) { return false; }
|
||||
if (otherIcao.hasLivery() && otherIcao.getLivery() != this->getLivery()) { return false; }
|
||||
if (otherIcao.hasAircraftColor() && otherIcao.getAircraftColor() != this->getAircraftColor()) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::isVtol() const
|
||||
{
|
||||
// special designators
|
||||
if (
|
||||
this->m_aircraftDesignator == "BALL" ||
|
||||
this->m_aircraftDesignator == "SHIP" ||
|
||||
this->m_aircraftDesignator == "GYRO" ||
|
||||
this->m_aircraftDesignator == "UHEL"
|
||||
) { return true; }
|
||||
|
||||
if (!m_aircraftCombinedType.isEmpty())
|
||||
{
|
||||
if (
|
||||
this->m_aircraftCombinedType.startsWith('G') || // gyrocopter
|
||||
this->m_aircraftCombinedType.startsWith('H') || // helicopter
|
||||
this->m_aircraftCombinedType.startsWith('T') // tilt wing
|
||||
) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CVariant CAircraftIcaoData::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toCVariant(); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraftDesignator:
|
||||
return CVariant::fromValue(this->m_aircraftDesignator);
|
||||
case IndexAirlineDesignator:
|
||||
return CVariant::fromValue(this->m_airlineDesignator);
|
||||
case IndexCombinedAircraftType:
|
||||
return CVariant::fromValue(this->m_aircraftCombinedType);
|
||||
case IndexAircraftColor:
|
||||
return CVariant::fromValue(this->m_aircraftColor);
|
||||
case IndexAsString:
|
||||
return CVariant::fromValue(this->asString());
|
||||
case IndexIsVtol:
|
||||
return CVariant::fromValue(this->isVtol());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftIcaoData::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself())
|
||||
{
|
||||
this->convertFromCVariant(variant);
|
||||
return;
|
||||
}
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraftDesignator:
|
||||
this->setAircraftDesignator(variant.value<QString>());
|
||||
break;
|
||||
case IndexAirlineDesignator:
|
||||
this->setAirlineDesignator(variant.value<QString>());
|
||||
break;
|
||||
case IndexCombinedAircraftType:
|
||||
this->setAircraftCombinedType(variant.value<QString>());
|
||||
break;
|
||||
case IndexAircraftColor:
|
||||
this->setAircraftColor(variant.value<QString>());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::isValidDesignator(const QString &designator)
|
||||
{
|
||||
static QRegularExpression regexp("^[A-Z]+[A-Z0-9]*$");
|
||||
if (designator.length() < 2 || designator.length() > 5) { return false; }
|
||||
return (regexp.match(designator).hasMatch());
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::isValidCombinedType(const QString &combinedType)
|
||||
{
|
||||
static QRegularExpression regexp("^[A-Z][0-9][A-Z]$");
|
||||
if (combinedType.length() != 3) return false;
|
||||
return (regexp.match(combinedType).hasMatch());
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::isValidAirlineDesignator(const QString &airline)
|
||||
{
|
||||
static QRegularExpression regexp("^[A-Z]+[A-Z0-9]*$");
|
||||
if (airline.length() < 2 || airline.length() > 5) return false;
|
||||
return (regexp.match(airline).hasMatch());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user