From 55052224611156693abc1246533ed31ad4a63f35 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 18 Jan 2015 20:33:39 +0100 Subject: [PATCH] refs #364, Simulated aircraft * Simulated aircraft, basically aircraft + model + client * moved corresponding model classes to subdir simulation --- src/blackmisc/nwaircraftmapping.cpp | 6 +- src/blackmisc/nwaircraftmapping.h | 10 +- src/blackmisc/nwaircraftmappinglist.h | 2 +- src/blackmisc/nwaircraftmodellist.cpp | 51 ------- src/blackmisc/nwaircraftmodellist.h | 52 ------- .../aircraftmodel.cpp} | 27 +--- .../aircraftmodel.h} | 16 +- .../simulation/aircraftmodellist.cpp | 81 ++++++++++ src/blackmisc/simulation/aircraftmodellist.h | 68 +++++++++ .../simulation/simulatedaircraft.cpp | 143 ++++++++++++++++++ src/blackmisc/simulation/simulatedaircraft.h | 102 +++++++++++++ .../simulation/simulatedaircraftlist.cpp | 119 +++++++++++++++ .../simulation/simulatedaircraftlist.h | 81 ++++++++++ .../simulation/simulationallclasses.h | 19 +++ 14 files changed, 636 insertions(+), 141 deletions(-) delete mode 100644 src/blackmisc/nwaircraftmodellist.cpp delete mode 100644 src/blackmisc/nwaircraftmodellist.h rename src/blackmisc/{nwaircraftmodel.cpp => simulation/aircraftmodel.cpp} (91%) rename src/blackmisc/{nwaircraftmodel.h => simulation/aircraftmodel.h} (94%) create mode 100644 src/blackmisc/simulation/aircraftmodellist.cpp create mode 100644 src/blackmisc/simulation/aircraftmodellist.h create mode 100644 src/blackmisc/simulation/simulatedaircraft.cpp create mode 100644 src/blackmisc/simulation/simulatedaircraft.h create mode 100644 src/blackmisc/simulation/simulatedaircraftlist.cpp create mode 100644 src/blackmisc/simulation/simulatedaircraftlist.h create mode 100644 src/blackmisc/simulation/simulationallclasses.h diff --git a/src/blackmisc/nwaircraftmapping.cpp b/src/blackmisc/nwaircraftmapping.cpp index b83501af5..736a5b605 100644 --- a/src/blackmisc/nwaircraftmapping.cpp +++ b/src/blackmisc/nwaircraftmapping.cpp @@ -1,8 +1,8 @@ /* Copyright (C) 2013 - * swift Project Community / Contributors + * 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, + * 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. */ @@ -23,7 +23,7 @@ namespace BlackMisc * Constructor */ CAircraftMapping::CAircraftMapping(const QString &source, const QString &packageName, const QString &aircraftDesignator, const QString &airlineDesignator, const QString &model) : - m_source(source.trimmed()), m_packageName(packageName.trimmed()), m_icao(CAircraftIcao(aircraftDesignator, airlineDesignator)), m_model(CAircraftModel(model, CAircraftModel::TypeModelMapping)) + m_source(source.trimmed()), m_packageName(packageName.trimmed()), m_icao(CAircraftIcao(aircraftDesignator, airlineDesignator)), m_model(BlackMisc::Simulation::CAircraftModel(model, BlackMisc::Simulation::CAircraftModel::TypeModelMapping)) { } /* diff --git a/src/blackmisc/nwaircraftmapping.h b/src/blackmisc/nwaircraftmapping.h index 4f1bf3d0c..7a6892722 100644 --- a/src/blackmisc/nwaircraftmapping.h +++ b/src/blackmisc/nwaircraftmapping.h @@ -13,7 +13,7 @@ #define BLACKMISC_NETWORK_AIRCRAFTMAPPING_H #include "blackmisc/avaircrafticao.h" -#include "blackmisc/nwaircraftmodel.h" +#include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/valueobject.h" namespace BlackMisc @@ -32,7 +32,7 @@ namespace BlackMisc //! Properties enum ColumnIndex { - IndexModel, + IndexModel = BlackMisc::CPropertyIndex::GlobalIndexCAircraftMapping, IndexIcao, IndexPackageName, IndexSource @@ -57,10 +57,10 @@ namespace BlackMisc const BlackMisc::Aviation::CAircraftIcao &getIcao() const { return this->m_icao; } //! Model - void setModel(const BlackMisc::Network::CAircraftModel &model) { this->m_model = model; } + void setModel(const BlackMisc::Simulation::CAircraftModel &model) { this->m_model = model; } //! Model - const BlackMisc::Network::CAircraftModel &getModel() const { return this->m_model; } + const BlackMisc::Simulation::CAircraftModel &getModel() const { return this->m_model; } //! Matches model string? bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const; @@ -74,7 +74,7 @@ namespace BlackMisc QString m_source; //!< source, e.g. database, vPilot QString m_packageName; //!< something like WoA, .. BlackMisc::Aviation::CAircraftIcao m_icao; //!< ICAO code - BlackMisc::Network::CAircraftModel m_model; //!< aircraft model + BlackMisc::Simulation::CAircraftModel m_model; //!< aircraft model // BlackSim::CSimulatorInfo m_simulatorInfo; //!< Mapping is for simulator }; diff --git a/src/blackmisc/nwaircraftmappinglist.h b/src/blackmisc/nwaircraftmappinglist.h index e8df84f4b..f07c63fd5 100644 --- a/src/blackmisc/nwaircraftmappinglist.h +++ b/src/blackmisc/nwaircraftmappinglist.h @@ -49,7 +49,7 @@ namespace BlackMisc CAircraftMappingList findByIcaoCodeExact(const BlackMisc::Aviation::CAircraftIcao &searchIcao) const; //! Find by model string - CAircraftMappingList findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const; + CAircraftMappingList findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const; //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } diff --git a/src/blackmisc/nwaircraftmodellist.cpp b/src/blackmisc/nwaircraftmodellist.cpp deleted file mode 100644 index 297ba8381..000000000 --- a/src/blackmisc/nwaircraftmodellist.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* 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 "nwaircraftmodellist.h" -#include "predicates.h" - -using namespace BlackMisc::Network; -using namespace BlackMisc::Aviation; - -namespace BlackMisc -{ - namespace Network - { - /* - * Empty constructor - */ - CAircraftModelList::CAircraftModelList() { } - - /* - * Construct from base class object - */ - CAircraftModelList::CAircraftModelList(const CSequence &other) : - CSequence(other) - { } - - CAircraftModelList CAircraftModelList::findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const - { - return this->findBy([ = ](const CAircraftModel &model) - { - return model.matchesModelString(modelString, sensitivity); - }); - } - - /* - * Register metadata - */ - void CAircraftModelList::registerMetadata() - { - qRegisterMetaType>(); - qDBusRegisterMetaType>(); - qRegisterMetaType>(); - qDBusRegisterMetaType>(); - qRegisterMetaType(); - qDBusRegisterMetaType(); - registerMetaValueType(); - } - - } // namespace -} // namespace diff --git a/src/blackmisc/nwaircraftmodellist.h b/src/blackmisc/nwaircraftmodellist.h deleted file mode 100644 index b551c9233..000000000 --- a/src/blackmisc/nwaircraftmodellist.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (C) 2014 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/. */ - -//! \file - -#ifndef BLACKMISC_AIRCRAFTMODELLIST_H -#define BLACKMISC_AIRCRAFTMODELLIST_H - -#include "nwaircraftmodel.h" -#include "collection.h" -#include "sequence.h" - -namespace BlackMisc -{ - namespace Network - { - /*! - * Value object encapsulating a list of aircraft models - */ - class CAircraftModelList : public CSequence - { - public: - //! Empty constructor. - CAircraftModelList(); - - //! Construct from a base class object. - CAircraftModelList(const CSequence &other); - - //! QVariant, required for DBus QVariant lists - virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } - - //! Find by model string - CAircraftModelList findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) 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::Network::CAircraftModelList) -Q_DECLARE_METATYPE(BlackMisc::CCollection) -Q_DECLARE_METATYPE(BlackMisc::CSequence) - -#endif //guard diff --git a/src/blackmisc/nwaircraftmodel.cpp b/src/blackmisc/simulation/aircraftmodel.cpp similarity index 91% rename from src/blackmisc/nwaircraftmodel.cpp rename to src/blackmisc/simulation/aircraftmodel.cpp index 6eab49564..088617756 100644 --- a/src/blackmisc/nwaircraftmodel.cpp +++ b/src/blackmisc/simulation/aircraftmodel.cpp @@ -7,23 +7,17 @@ * contained in the LICENSE file. */ -#include "nwaircraftmodel.h" +#include "aircraftmodel.h" #include namespace BlackMisc { - namespace Network + namespace Simulation { - /* - * Constructor - */ CAircraftModel::CAircraftModel(const Aviation::CAircraft &aircraft) : m_callsign(aircraft.getCallsign()), m_icao(aircraft.getIcaoInfo()) { } - /* - * Convert to string - */ QString CAircraftModel::convertToQString(bool i18n) const { QString s = this->m_modelString; @@ -39,9 +33,6 @@ namespace BlackMisc return s; } - /* - * Property by index - */ CVariant CAircraftModel::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return this->toCVariant(); } @@ -69,9 +60,6 @@ namespace BlackMisc } } - /* - * Set property as index - */ void CAircraftModel::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) { if (index.isMyself()) @@ -106,21 +94,16 @@ namespace BlackMisc } } - /* - * Update missing parts - */ 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(TypeUnknown)) { this->m_modelType = model.getModelType(); } this->m_icao.updateMissingParts(model.getIcao()); } - /* - * Matches string? - */ bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const { if (sensitivity == Qt::CaseSensitive) @@ -129,7 +112,8 @@ namespace BlackMisc } else { - return this->m_modelString.indexOf(modelString) == 0; + return this->m_modelString.length() == modelString.length() && + this->m_modelString.indexOf(modelString) == 0; } } @@ -141,6 +125,7 @@ namespace BlackMisc case TypeModelMatching: return "matching"; case TypeModelMapping: return "mapping"; case TypeOwnSimulatorModel: return "own simulator"; + case TypeManuallySet: return "set"; case TypeUnknown: default: return "unknown"; } diff --git a/src/blackmisc/nwaircraftmodel.h b/src/blackmisc/simulation/aircraftmodel.h similarity index 94% rename from src/blackmisc/nwaircraftmodel.h rename to src/blackmisc/simulation/aircraftmodel.h index 7af63af01..d54c9a212 100644 --- a/src/blackmisc/nwaircraftmodel.h +++ b/src/blackmisc/simulation/aircraftmodel.h @@ -12,15 +12,14 @@ #ifndef BLACKMISC_AIRCRAFTMODEL_H #define BLACKMISC_AIRCRAFTMODEL_H -#include "avaircraft.h" -#include "avaircrafticao.h" -#include "nwuser.h" -#include "propertyindex.h" - +#include "blackmisc/avaircraft.h" +#include "blackmisc/avaircrafticao.h" +#include "blackmisc/nwuser.h" +#include "blackmisc/propertyindex.h" namespace BlackMisc { - namespace Network + namespace Simulation { //! Aircraft model (other pilot, my models on disk) //! \remarks Simulator independent class, supposed to be common denominator @@ -34,6 +33,7 @@ namespace BlackMisc 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 }; @@ -148,7 +148,7 @@ namespace BlackMisc } // namespace BLACK_DECLARE_TUPLE_CONVERSION( - BlackMisc::Network::CAircraftModel, ( + BlackMisc::Simulation::CAircraftModel, ( attr(o.m_callsign), attr(o.m_icao), attr(o.m_modelString, flags()), @@ -156,6 +156,6 @@ BLACK_DECLARE_TUPLE_CONVERSION( attr(o.m_fileName, flags ()), attr(o.m_modelType) )) -Q_DECLARE_METATYPE(BlackMisc::Network::CAircraftModel) +Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModel) #endif // guard diff --git a/src/blackmisc/simulation/aircraftmodellist.cpp b/src/blackmisc/simulation/aircraftmodellist.cpp new file mode 100644 index 000000000..d04cd6537 --- /dev/null +++ b/src/blackmisc/simulation/aircraftmodellist.cpp @@ -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 &other) : + CSequence(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>(); + qDBusRegisterMetaType>(); + qRegisterMetaType>(); + qDBusRegisterMetaType>(); + qRegisterMetaType(); + qDBusRegisterMetaType(); + registerMetaValueType(); + } + + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/aircraftmodellist.h b/src/blackmisc/simulation/aircraftmodellist.h new file mode 100644 index 000000000..18c115d37 --- /dev/null +++ b/src/blackmisc/simulation/aircraftmodellist.h @@ -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 + { + public: + //! Empty constructor. + CAircraftModelList(); + + //! Construct from a base class object. + CAircraftModelList(const CSequence &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) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/simulation/simulatedaircraft.cpp b/src/blackmisc/simulation/simulatedaircraft.cpp new file mode 100644 index 000000000..ea06dbc05 --- /dev/null +++ b/src/blackmisc/simulation/simulatedaircraft.cpp @@ -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(); + 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(); + 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 diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h new file mode 100644 index 000000000..c0b1f5e12 --- /dev/null +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -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 + { + 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 diff --git a/src/blackmisc/simulation/simulatedaircraftlist.cpp b/src/blackmisc/simulation/simulatedaircraftlist.cpp new file mode 100644 index 000000000..e52d4c022 --- /dev/null +++ b/src/blackmisc/simulation/simulatedaircraftlist.cpp @@ -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 &other) : + CSequence(other) + { } + + /* + * Register metadata + */ + void CSimulatedAircraftList::registerMetadata() + { + qRegisterMetaType>(); + qDBusRegisterMetaType>(); + qRegisterMetaType>(); + qDBusRegisterMetaType>(); + qRegisterMetaType(); + qDBusRegisterMetaType(); + registerMetaValueType(); + } + + /* + * 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 diff --git a/src/blackmisc/simulation/simulatedaircraftlist.h b/src/blackmisc/simulation/simulatedaircraftlist.h new file mode 100644 index 000000000..087eaacd0 --- /dev/null +++ b/src/blackmisc/simulation/simulatedaircraftlist.h @@ -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 +#include +#include + +namespace BlackMisc +{ + namespace Simulation + { + //! Value object encapsulating a list of aircraft. + class CSimulatedAircraftList : public CSequence + { + public: + //! Default constructor. + CSimulatedAircraftList(); + + //! Construct from a base class object. + CSimulatedAircraftList(const CSequence &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) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/simulation/simulationallclasses.h b/src/blackmisc/simulation/simulationallclasses.h new file mode 100644 index 000000000..d849cecb4 --- /dev/null +++ b/src/blackmisc/simulation/simulationallclasses.h @@ -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