mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
refs #364, Simulated aircraft
* Simulated aircraft, basically aircraft + model + client * moved corresponding model classes to subdir simulation
This commit is contained in:
@@ -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))
|
||||
{ }
|
||||
|
||||
/*
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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<CAircraftModel> &other) :
|
||||
CSequence<CAircraftModel>(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<BlackMisc::CSequence<CAircraftModel>>();
|
||||
qDBusRegisterMetaType<BlackMisc::CSequence<CAircraftModel>>();
|
||||
qRegisterMetaType<BlackMisc::CCollection<CAircraftModel>>();
|
||||
qDBusRegisterMetaType<BlackMisc::CCollection<CAircraftModel>>();
|
||||
qRegisterMetaType<CAircraftModelList>();
|
||||
qDBusRegisterMetaType<CAircraftModelList>();
|
||||
registerMetaValueType<CAircraftModelList>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -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<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); }
|
||||
|
||||
//! 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<BlackMisc::Network::CAircraftModel>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Network::CAircraftModel>)
|
||||
|
||||
#endif //guard
|
||||
@@ -7,23 +7,17 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "nwaircraftmodel.h"
|
||||
#include "aircraftmodel.h"
|
||||
#include <QString>
|
||||
|
||||
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<int>(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";
|
||||
}
|
||||
@@ -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<CaseInsensitiveComparison>()),
|
||||
@@ -156,6 +156,6 @@ BLACK_DECLARE_TUPLE_CONVERSION(
|
||||
attr(o.m_fileName, flags <DisabledForComparison> ()),
|
||||
attr(o.m_modelType)
|
||||
))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CAircraftModel)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModel)
|
||||
|
||||
#endif // guard
|
||||
81
src/blackmisc/simulation/aircraftmodellist.cpp
Normal file
81
src/blackmisc/simulation/aircraftmodellist.cpp
Normal 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
|
||||
68
src/blackmisc/simulation/aircraftmodellist.h
Normal file
68
src/blackmisc/simulation/aircraftmodellist.h
Normal 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
|
||||
143
src/blackmisc/simulation/simulatedaircraft.cpp
Normal file
143
src/blackmisc/simulation/simulatedaircraft.cpp
Normal 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
|
||||
102
src/blackmisc/simulation/simulatedaircraft.h
Normal file
102
src/blackmisc/simulation/simulatedaircraft.h
Normal 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
|
||||
119
src/blackmisc/simulation/simulatedaircraftlist.cpp
Normal file
119
src/blackmisc/simulation/simulatedaircraftlist.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/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
|
||||
81
src/blackmisc/simulation/simulatedaircraftlist.h
Normal file
81
src/blackmisc/simulation/simulatedaircraftlist.h
Normal 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
|
||||
19
src/blackmisc/simulation/simulationallclasses.h
Normal file
19
src/blackmisc/simulation/simulationallclasses.h
Normal 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
|
||||
Reference in New Issue
Block a user