Files
pilotclient/src/blackmisc/simulation/fscommon/vpilotmodelrule.cpp
2016-08-26 21:05:03 +01:00

125 lines
5.8 KiB
C++

/* Copyright (C) 2015
* 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/aircrafticaocode.h"
#include "blackmisc/aviation/airlineicaocode.h"
#include "blackmisc/aviation/livery.h"
#include "blackmisc/simulation/distributor.h"
#include "blackmisc/simulation/fscommon/vpilotmodelrule.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include <Qt>
using namespace BlackMisc::Network;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Simulation;
namespace BlackMisc
{
namespace Simulation
{
namespace FsCommon
{
CVPilotModelRule::CVPilotModelRule() { }
CVPilotModelRule::CVPilotModelRule(const QString &modelName, const QString &folder, const QString &typeCode, const QString &callsignPrefix, qint64 updated) :
ITimestampBased(updated),
m_modelName(modelName.trimmed().toUpper()), m_folder(folder.trimmed().toUpper()),
m_typeCode(typeCode.trimmed().toUpper()), m_callsignPrefix(callsignPrefix.trimmed().toUpper()), m_updatedMsSinceEpoch(updated)
{ }
const QString CVPilotModelRule::getDistributor() const
{
QString f(this->getFolder().toUpper().simplified());
f.replace(" ", "");
if (f.isEmpty()) return ("UNKNOWN");
if (f.startsWith("WOAI", Qt::CaseInsensitive)) { return "WOAI"; }
if (f.startsWith("WORLDOFAI", Qt::CaseInsensitive)) { return "WOAI"; }
if (f.startsWith("IVAO", Qt::CaseInsensitive)) { return "IVAO"; }
if (f.startsWith("P3D", Qt::CaseInsensitive)) { return "P3D"; }
if (f.startsWith("FSX", Qt::CaseInsensitive)) { return "FSX"; }
if (f.startsWith("MYTRAFFIC", Qt::CaseInsensitive)) { return "MYTRAFFIC"; }
if (f.startsWith("JUSTFLIGHT", Qt::CaseInsensitive)) { return "JUSTFLIGHT"; }
if (f.startsWith("ULTIMATETRAFFIC", Qt::CaseInsensitive)) { return "ULTIMATETRAFFIC"; }
if (f.startsWith("VIP", Qt::CaseInsensitive)) { return "VIP"; }
return "??? - " + f;
}
CVariant CVPilotModelRule::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexModelName: return CVariant::from(this->m_modelName);
case IndexFolder: return CVariant::from(this->m_folder);
case IndexTypeCode: return CVariant::from(this->m_typeCode);
case IndexCallsignPrefix: return CVariant::from(this->m_callsignPrefix);
default:
return CValueObject::propertyByIndex(index);
}
}
void CVPilotModelRule::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CVPilotModelRule>(); return; }
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexModelName: this->setModelName(variant.value<QString>()); break;
case IndexFolder: this->setFolder(variant.value<QString>()); break;
case IndexTypeCode: this->setTypeCode(variant.value<QString>()); break;
case IndexCallsignPrefix: this->setCallsignPrefix(variant.value<QString>()); break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
QString CVPilotModelRule::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
QString s(this->m_modelName);
return s;
}
CAircraftModel CVPilotModelRule::toAircraftModel() const
{
QString al(m_callsignPrefix);
if (al.length() > 3)
{
// some known hardcoded fixes
if (al.startsWith("USAF")) { al = "AIO"; }
}
const QString liveryPseudoCode(
al.length() != 3 ?
"" :
al + "." + CLivery::standardLiveryMarker());
const CAircraftIcaoCode aircraftIcao(m_typeCode);
const CAirlineIcaoCode airlineIcao(al);
const CLivery livery(liveryPseudoCode, airlineIcao, "vPilot rule based");
const CDistributor distributor(getDistributor(), "vPilot based", "", "");
CAircraftModel model(
this->m_modelName, CAircraftModel::TypeVPilotRuleBased,
CAircraftModel::autoGenerated(),
aircraftIcao, livery
);
const CSimulatorInfo sim(CSimulatorInfo::FSX_P3D);
model.setMSecsSinceEpoch(m_timestampMSecsSinceEpoch);
model.setDistributor(distributor);
model.setSimulator(sim);
return model;
}
} // namespace
} // namespace
} // namespace