refs #364, Simulated aircraft

* Simulated aircraft, basically aircraft + model + client
* moved corresponding model classes to subdir simulation
This commit is contained in:
Klaus Basan
2015-01-18 20:33:39 +01:00
parent 1e480d52b9
commit 5505222461
14 changed files with 636 additions and 141 deletions

View File

@@ -0,0 +1,135 @@
/* 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 "aircraftmodel.h"
#include <QString>
namespace BlackMisc
{
namespace Simulation
{
CAircraftModel::CAircraftModel(const Aviation::CAircraft &aircraft) :
m_callsign(aircraft.getCallsign()), m_icao(aircraft.getIcaoInfo())
{ }
QString CAircraftModel::convertToQString(bool i18n) const
{
QString s = this->m_modelString;
if (!s.isEmpty()) { s += ' '; }
s += this->getModelTypeAsString();
s += ' ';
s += this->m_icao.toQString(i18n);
if (!this->m_fileName.isEmpty())
{
s += ' ';
s += m_fileName;
}
return s;
}
CVariant CAircraftModel::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return this->toCVariant(); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexModelString:
return CVariant(this->m_modelString);
case IndexHasQueriedModelString:
return CVariant::fromValue(this->hasQueriedModelString());
case IndexModelType:
return CVariant::fromValue(this->m_modelType);
case IndexModelTypeAsString:
return CVariant(this->getModelTypeAsString());
case IndexDescription:
return CVariant(this->m_description);
case IndexFileName:
return CVariant(this->m_fileName);
case IndexIcao:
return m_icao.propertyByIndex(index.copyFrontRemoved());
case IndexCallsign:
return m_callsign.propertyByIndex(index.copyFrontRemoved());
default:
return CValueObject::propertyByIndex(index);
}
}
void CAircraftModel::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself())
{
this->convertFromCVariant(variant);
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexModelString:
this->m_modelString = variant.toQString();
break;
case IndexIcao:
this->m_icao.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexDescription:
this->m_description = variant.toQString();
break;
case IndexCallsign:
this->m_callsign.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexFileName:
this->m_fileName = variant.toQString();
break;
case IndexModelType:
this->m_modelType = variant.toInt();
break;
default:
CValueObject::setPropertyByIndex(variant, index);
break;
}
}
void CAircraftModel::updateMissingParts(const CAircraftModel &model)
{
if (this->m_modelString.isEmpty()) { this->m_modelString = model.getModelString(); }
if (this->m_description.isEmpty()) { this->m_description = model.getDescription(); }
if (this->m_fileName.isEmpty()) { this->m_fileName = model.getFileName(); }
if (this->m_callsign.isEmpty()) { this->m_callsign = model.getCallsign(); }
if (this->m_modelType == static_cast<int>(TypeUnknown)) { this->m_modelType = model.getModelType(); }
this->m_icao.updateMissingParts(model.getIcao());
}
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{
if (sensitivity == Qt::CaseSensitive)
{
return modelString == this->m_modelString;
}
else
{
return this->m_modelString.length() == modelString.length() &&
this->m_modelString.indexOf(modelString) == 0;
}
}
QString CAircraftModel::modelTypeToString(CAircraftModel::ModelType type)
{
switch (type)
{
case TypeQueriedFromNetwork: return "queried";
case TypeModelMatching: return "matching";
case TypeModelMapping: return "mapping";
case TypeOwnSimulatorModel: return "own simulator";
case TypeManuallySet: return "set";
case TypeUnknown:
default: return "unknown";
}
}
} // namespace
} // namespace

View File

@@ -0,0 +1,161 @@
/* 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.
*/
//! \file
#ifndef BLACKMISC_AIRCRAFTMODEL_H
#define BLACKMISC_AIRCRAFTMODEL_H
#include "blackmisc/avaircraft.h"
#include "blackmisc/avaircrafticao.h"
#include "blackmisc/nwuser.h"
#include "blackmisc/propertyindex.h"
namespace BlackMisc
{
namespace Simulation
{
//! Aircraft model (other pilot, my models on disk)
//! \remarks Simulator independent class, supposed to be common denominator
class CAircraftModel : public CValueObjectStdTuple<CAircraftModel>
{
public:
//! Model type
enum ModelType
{
TypeUnknown,
TypeQueriedFromNetwork, //!< model was queried by network protocol
TypeModelMatching, //!< model is result of model matching
TypeModelMapping, //!< used along with mapping definition
TypeManuallySet, //!< manually set, e.g. from GUI
TypeOwnSimulatorModel //!< represents own simulator model
};
//! Indexes
enum ColumnIndex
{
IndexModelString = BlackMisc::CPropertyIndex::GlobalIndexCAircraftModel,
IndexCallsign,
IndexDescription,
IndexIcao,
IndexFileName,
IndexModelType,
IndexModelTypeAsString,
IndexHasQueriedModelString
};
//! Default constructor.
CAircraftModel() {}
//! Constructor.
CAircraftModel(const QString &model, ModelType type) : m_modelString(model), m_modelType(type) {}
//! Constructor
CAircraftModel(const BlackMisc::Aviation::CAircraft &aircraft);
//! \copydoc CValueObject::propertyByIndex
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
//! \copydoc CValueObject::setPropertyByIndex
virtual void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) override;
//! Corresponding callsign if applicable
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_callsign; }
//! Corresponding callsign if applicable
void setCallsign(const BlackMisc::Aviation::CCallsign &callsign) { this->m_callsign = callsign; }
//! Callsign empty
bool isCallsignEmpty() const { return this->m_callsign.isEmpty(); }
//! Queried model string
const QString &getModelString() const { return this->m_modelString; }
//! Model string
void setModelString(const QString &modelString) { this->m_modelString = modelString; }
//! Descriptive text
const QString &getDescription() const { return this->m_description; }
//! Descriptive text
void setDescription(const QString &description) { this->m_description = description; }
//! Set queried model string
void setQueriedModelString(const QString &model) { this->m_modelString = model; this->m_modelType = TypeQueriedFromNetwork; }
//! ICAO code
BlackMisc::Aviation::CAircraftIcao getIcao() const { return this->m_icao; }
//! Set ICAO info
void setIcao(const BlackMisc::Aviation::CAircraftIcao &icao) { this->m_icao = icao; }
//! \copydoc CAircraftIcao::hasAircraftAndAirlineDesignator
bool hasAircraftAndAirlineDesignator() const { return this->m_icao.hasAircraftAndAirlineDesignator(); }
//! \copydoc CAircraftIcao::hasAircraftDesignator
bool hasAircraftDesignator() const { return this->m_icao.hasAircraftDesignator(); }
//! Model type
ModelType getModelType() const { return static_cast<ModelType>(m_modelType); }
//! Model type
QString getModelTypeAsString() const { return modelTypeToString(getModelType()); }
//! Set type
void setModelType(ModelType type) { this->m_modelType = static_cast<int>(type); }
//! File name
QString getFileName() const { return m_fileName; }
//! File name
void setFileName(const QString &fileName) { m_fileName = fileName; }
//! Update missing parts from another model
void updateMissingParts(const CAircraftModel &model);
//! Queried model string?
bool hasQueriedModelString() const { return this->m_modelType == TypeQueriedFromNetwork && this->hasModelString(); }
//! Non empty model string
bool hasModelString() const { return !m_modelString.isEmpty(); }
//! Matches model string?
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
//! Model type
static QString modelTypeToString(ModelType type);
protected:
//! \copydoc CValueObject::convertToQString
virtual QString convertToQString(bool i18n = false) const override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CAircraftModel)
BlackMisc::Aviation::CCallsign m_callsign; //!< aircraft's callsign
BlackMisc::Aviation::CAircraftIcao m_icao; //!< ICAO data if available
QString m_modelString; //!< Simulator model string
QString m_description; //!< descriptive text
QString m_fileName; //!< file name
int m_modelType = static_cast<int>(TypeUnknown); //!< model string is queried from network?
};
} // namespace
} // namespace
BLACK_DECLARE_TUPLE_CONVERSION(
BlackMisc::Simulation::CAircraftModel, (
attr(o.m_callsign),
attr(o.m_icao),
attr(o.m_modelString, flags<CaseInsensitiveComparison>()),
attr(o.m_description, flags<DisabledForComparison>()),
attr(o.m_fileName, flags <DisabledForComparison> ()),
attr(o.m_modelType)
))
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModel)
#endif // guard

View File

@@ -0,0 +1,81 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/predicates.h"
using namespace BlackMisc::Network;
using namespace BlackMisc::Aviation;
namespace BlackMisc
{
namespace Simulation
{
CAircraftModelList::CAircraftModelList() { }
CAircraftModelList::CAircraftModelList(const CSequence<CAircraftModel> &other) :
CSequence<CAircraftModel>(other)
{ }
bool CAircraftModelList::containsModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{
for (const CAircraftModel &model : (*this))
{
if (model.matchesModelString(modelString, sensitivity)) { return true; }
}
return false;
}
CAircraftModelList CAircraftModelList::findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{
return this->findBy([ = ](const CAircraftModel & model)
{
return model.matchesModelString(modelString, sensitivity);
});
}
CAircraftModel CAircraftModelList::findFirstByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{
CAircraftModelList ml = findByModelString(modelString, sensitivity);
return ml.frontOrDefault();
}
CAircraftModelList CAircraftModelList::findModelsStartingWith(const QString &modelString, Qt::CaseSensitivity sensitivity) const
{
CAircraftModelList ml;
for (const CAircraftModel &model : (*this))
{
if (model.getModelString().startsWith(modelString, sensitivity))
{
ml.push_back(model);
}
}
return ml;
}
QStringList CAircraftModelList::getModelStrings() const
{
QStringList ms;
for (const CAircraftModel &model : (*this))
{
ms.append(model.getModelString());
}
ms.sort(Qt::CaseInsensitive);
return ms;
}
void CAircraftModelList::registerMetadata()
{
qRegisterMetaType<BlackMisc::CSequence<CAircraftModel>>();
qDBusRegisterMetaType<BlackMisc::CSequence<CAircraftModel>>();
qRegisterMetaType<BlackMisc::CCollection<CAircraftModel>>();
qDBusRegisterMetaType<BlackMisc::CCollection<CAircraftModel>>();
qRegisterMetaType<CAircraftModelList>();
qDBusRegisterMetaType<CAircraftModelList>();
registerMetaValueType<CAircraftModelList>();
}
} // namespace
} // namespace

View File

@@ -0,0 +1,68 @@
/* 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.
*/
//! \file
#ifndef BLACKMISC_AIRCRAFTMODELLIST_H
#define BLACKMISC_AIRCRAFTMODELLIST_H
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
namespace BlackMisc
{
namespace Simulation
{
/*!
* Value object encapsulating a list of aircraft models
*/
class CAircraftModelList : public CSequence<CAircraftModel>
{
public:
//! Empty constructor.
CAircraftModelList();
//! Construct from a base class object.
CAircraftModelList(const CSequence<CAircraftModel> &other);
//! QVariant, required for DBus QVariant lists
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
//! Contains model string
bool containsModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
//! Find by model string
CAircraftModelList findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
//! Find first by model string
CAircraftModel findFirstByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
//! Find models starting with
CAircraftModelList findModelsStartingWith(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
//! Model strings
QStringList getModelStrings() const;
//! \copydoc CValueObject::convertFromQVariant
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
//! Register metadata
static void registerMetadata();
};
} //namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModelList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CAircraftModel>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CAircraftModel>)
#endif //guard

View File

@@ -0,0 +1,143 @@
/* 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 "simulatedaircraft.h"
#include "blackmisc/propertyindex.h"
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Network;
namespace BlackMisc
{
namespace Simulation
{
CSimulatedAircraft::CSimulatedAircraft()
{
init();
}
CSimulatedAircraft::CSimulatedAircraft(const CAircraft &aircraft, const CAircraftModel &model, const CClient &client) :
CValueObjectStdTuple(aircraft), m_model(model), m_client(client)
{
init();
}
void CSimulatedAircraft::init()
{
// sync some values, order here is crucial
this->setCallsign(this->getCallsign());
this->setIcaoInfo(this->getIcaoInfo());
this->setModel(this->getModel());
this->setPilot(this->hasValidRealName() ? this->getPilot() : this->getClient().getUser());
}
CVariant CSimulatedAircraft::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return this->toCVariant(); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexModel:
return this->m_model.propertyByIndex(index.copyFrontRemoved());
case IndexClient:
return this->m_client.propertyByIndex(index.copyFrontRemoved());
case IndexEnabled:
return CVariant::fromValue(this->isEnabled());
default:
return CAircraft::propertyByIndex(index);
}
}
void CSimulatedAircraft::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself())
{
this->convertFromCVariant(variant);
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexModel:
this->m_model.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexClient:
this->m_client.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
case IndexEnabled:
this->m_enabled = variant.toBool();
break;
default:
CAircraft::setPropertyByIndex(variant, index);
break;
}
}
void CSimulatedAircraft::setModel(const CAircraftModel &model)
{
// sync the callsigns
this->m_model = model;
this->setCallsign(this->hasValidCallsign() ? this->getCallsign() : model.getCallsign());
this->setIcaoInfo(model.getIcao());
}
void CSimulatedAircraft::setCallsign(const CCallsign &callsign)
{
this->m_model.setCallsign(callsign);
this->m_client.setUserCallsign(callsign);
CAircraft::setCallsign(callsign);
}
void CSimulatedAircraft::setIcaoInfo(const CAircraftIcao &icao)
{
// snyc ICAO info
CAircraftIcao newIcao(icao);
newIcao.updateMissingParts(this->getIcaoInfo());
newIcao.updateMissingParts(this->getModel().getIcao());
// now we have a superset of ICAO data
this->m_model.setIcao(newIcao);
CAircraft::setIcaoInfo(newIcao);
}
void CSimulatedAircraft::setPilot(const CUser &user)
{
this->m_client.setUser(user);
CAircraft::setPilot(user);
}
void CSimulatedAircraft::setClient(const CClient &client)
{
Q_ASSERT(client.getCallsign() == this->getCallsign());
m_client = client;
}
//! \todo Smarter way to do this?
void CSimulatedAircraft::update(const CAircraft &aircraft)
{
// override
(*this) = CSimulatedAircraft(aircraft, this->getModel(), this->getClient());
}
QString CSimulatedAircraft::convertToQString(bool i18n) const
{
QString s = CAircraft::convertToQString(i18n);
s += " enabled: ";
s += this->isEnabled() ? "yes" : "no";
s += " ";
s += this->m_model.toQString(i18n);
s += " ";
s += this->m_client.toQString(i18n);
return s;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,102 @@
/* 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.
*/
//! \file
#ifndef BLACKMISC_SIMULATEDAIRCRAFT_H
#define BLACKMISC_SIMULATEDAIRCRAFT_H
#include "blackmisc/avaircraft.h"
#include "aircraftmodel.h"
#include "blackmisc/nwclient.h"
namespace BlackMisc
{
namespace Simulation
{
//! Comprehensive information of an aircraft
//! \sa CAircraft
class CSimulatedAircraft : public CValueObjectStdTuple<CSimulatedAircraft, BlackMisc::Aviation::CAircraft>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexModel = BlackMisc::CPropertyIndex::GlobalIndexCSimulatedAircraft,
IndexClient,
IndexEnabled
};
//! Default constructor.
CSimulatedAircraft();
//! Constructor.
CSimulatedAircraft(const BlackMisc::Aviation::CAircraft &aircraft,
const BlackMisc::Simulation::CAircraftModel &model = BlackMisc::Simulation::CAircraftModel(),
const BlackMisc::Network::CClient &client = BlackMisc::Network::CClient());
//! \copydoc CValueObject::propertyByIndex
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
//! \copydoc CValueObject::setPropertyByIndex
virtual void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) override;
//! Get model
const BlackMisc::Simulation::CAircraftModel &getModel() const { return m_model; }
//! Set model
void setModel(const BlackMisc::Simulation::CAircraftModel &model);
//! \copydoc CAircraft::setCallsign
virtual void setCallsign(const BlackMisc::Aviation::CCallsign &callsign) override;
//! \copydoc CAircraft::setIcaoInfo
virtual void setIcaoInfo(const BlackMisc::Aviation::CAircraftIcao &icao) override;
//! \copydoc CAircraft::setPilot
virtual void setPilot(const BlackMisc::Network::CUser &user);
//! Get client
const BlackMisc::Network::CClient &getClient() const { return m_client; }
//! Set client
void setClient(const BlackMisc::Network::CClient &client);
//! Enabled?
bool isEnabled() const { return m_enabled; }
//! Enabled
void setEnabled(bool enabled) { m_enabled = enabled; }
//! Update from aviation aircraft
void update(const BlackMisc::Aviation::CAircraft &aircraft);
protected:
//! \copydoc CValueObject::convertToQString()
virtual QString convertToQString(bool i18n = false) const override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CSimulatedAircraft)
BlackMisc::Simulation::CAircraftModel m_model;
BlackMisc::Network::CClient m_client;
bool m_enabled = true;
void init();
};
} // namespace
} // namespace
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Simulation::CSimulatedAircraft, (
attr(o.m_model),
attr(o.m_client),
attr(o.m_enabled)
))
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatedAircraft)
#endif // guard

View 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/simulation/simulatedaircraftlist.h"
#include "blackmisc/nwuser.h"
#include "blackmisc/predicates.h"
#include "blackmisc/propertyindexallclasses.h"
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Network;
namespace BlackMisc
{
namespace Simulation
{
/*
* Default constructor
*/
CSimulatedAircraftList::CSimulatedAircraftList() { }
/*
* Construct from base class object
*/
CSimulatedAircraftList::CSimulatedAircraftList(const CSequence<CSimulatedAircraft> &other) :
CSequence<CSimulatedAircraft>(other)
{ }
/*
* Register metadata
*/
void CSimulatedAircraftList::registerMetadata()
{
qRegisterMetaType<BlackMisc::CSequence<CSimulatedAircraft>>();
qDBusRegisterMetaType<BlackMisc::CSequence<CSimulatedAircraft>>();
qRegisterMetaType<BlackMisc::CCollection<CSimulatedAircraft>>();
qDBusRegisterMetaType<BlackMisc::CCollection<CSimulatedAircraft>>();
qRegisterMetaType<CSimulatedAircraftList>();
qDBusRegisterMetaType<CSimulatedAircraftList>();
registerMetaValueType<CSimulatedAircraftList>();
}
/*
* Find by callsign
*/
CSimulatedAircraftList CSimulatedAircraftList::findByCallsign(const CCallsign &callsign) const
{
return this->findBy(&CSimulatedAircraft::getCallsign, callsign);
}
/*
* Find by callsigns
*/
CSimulatedAircraftList CSimulatedAircraftList::findByCallsigns(const CCallsignList &callsigns) const
{
return this->findBy(Predicates::MemberIsAnyOf(&CSimulatedAircraft::getCallsign, callsigns));
}
/*
* Find by callsign
*/
CSimulatedAircraft CSimulatedAircraftList::findFirstByCallsign(const CCallsign &callsign, const CSimulatedAircraft &ifNotFound) const
{
return this->findByCallsign(callsign).frontOrDefault(ifNotFound);
}
/*
* Contains callsign?
*/
bool CSimulatedAircraftList::containsCallsign(const CCallsign &callsign) const
{
return this->contains(&CSimulatedAircraft::getCallsign, callsign);
}
int CSimulatedAircraftList::incrementalUpdateOrAdd(const CSimulatedAircraft &changedAircraft, const CPropertyIndexVariantMap &changedValues)
{
int c;
const CCallsign cs = changedAircraft.getCallsign();
if (this->containsCallsign(cs))
{
if (changedValues.isEmpty()) { return 0; }
c = this->applyIf(&CSimulatedAircraft::getCallsign, cs, changedValues);
}
else
{
c = 1;
this->push_back(changedAircraft);
}
return c;
}
/*
* All pilots
*/
CUserList CSimulatedAircraftList::getPilots() const
{
return this->findBy(Predicates::MemberValid(&CSimulatedAircraft::getPilot)).transform(Predicates::MemberTransform(&CSimulatedAircraft::getPilot));
}
/*
* Aircrafts within range
*/
CSimulatedAircraftList CSimulatedAircraftList::findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const
{
return this->findBy([&](const CSimulatedAircraft & aircraft)
{
return BlackMisc::Geo::greatCircleDistance(aircraft, coordinate) <= range;
});
}
} // namespace
} // namespace

View File

@@ -0,0 +1,81 @@
/* 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.
*/
//! \file
#ifndef BLACKMISC_SIMULATEDNAIRCRAFTLIST_H
#define BLACKMISC_SIMULATEDNAIRCRAFTLIST_H
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/avcallsignlist.h"
#include "blackmisc/nwuserlist.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
#include <QObject>
#include <QString>
#include <QList>
namespace BlackMisc
{
namespace Simulation
{
//! Value object encapsulating a list of aircraft.
class CSimulatedAircraftList : public CSequence<CSimulatedAircraft>
{
public:
//! Default constructor.
CSimulatedAircraftList();
//! Construct from a base class object.
CSimulatedAircraftList(const CSequence<CSimulatedAircraft> &other);
//! Find 0..n stations by callsign
CSimulatedAircraftList findByCallsign(const BlackMisc::Aviation::CCallsign &callsign) const;
//! Find 0..n aircraft matching any of a set of callsigns
CSimulatedAircraftList findByCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const;
//! Find the first aircraft by callsign, if none return given one
CSimulatedAircraft findFirstByCallsign(const BlackMisc::Aviation::CCallsign &callsign, const CSimulatedAircraft &ifNotFound = CSimulatedAircraft()) const;
//! Contains callsign?
bool containsCallsign(const BlackMisc::Aviation::CCallsign &callsign) const;
//! Incremental update or add aircraft
int incrementalUpdateOrAdd(const BlackMisc::Simulation::CSimulatedAircraft &changedAircraft, const BlackMisc::CPropertyIndexVariantMap &changedValues);
//! All pilots (with valid data)
BlackMisc::Network::CUserList getPilots() const;
/*!
* Find 0..n stations within range of given coordinate
* \param coordinate other position
* \param range within range of other position
* \return
*/
CSimulatedAircraftList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const;
//! \copydoc CValueObject::toQVariant
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
//! \copydoc CValueObject::convertFromQVariant
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
//! Register metadata
static void registerMetadata();
};
} //namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatedAircraftList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CSimulatedAircraft>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CSimulatedAircraft>)
#endif //guard

View File

@@ -0,0 +1,19 @@
/* 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.
*/
//! \file
#ifndef BLACKMISC_SIMULATIONALLCLASSES_H
#define BLACKMISC_SIMULATIONALLCLASSES_H
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#endif // guard