mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-19 20:25:29 +08:00
refs #614, changed matcher and applied changes
* new function in model list * removed all models in matcher, only provider data will be used
This commit is contained in:
@@ -22,6 +22,11 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
namespace Simulation
|
namespace Simulation
|
||||||
{
|
{
|
||||||
|
const CLogCategoryList &CAircraftMatcher::getLogCategories()
|
||||||
|
{
|
||||||
|
static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::matching() };
|
||||||
|
return cats;
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftMatcher::CAircraftMatcher(MatchingMode matchingMode, QObject *parent) :
|
CAircraftMatcher::CAircraftMatcher(MatchingMode matchingMode, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
@@ -29,100 +34,74 @@ namespace BlackMisc
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
CAircraftMatcher::~CAircraftMatcher()
|
CAircraftMatcher::~CAircraftMatcher()
|
||||||
{
|
{ }
|
||||||
cancelInit();
|
|
||||||
if (this->m_initWorker) { this->m_initWorker->waitForFinished(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftMatcher::init()
|
|
||||||
{
|
|
||||||
if (m_initState != NotInitialized) { return; }
|
|
||||||
m_initWorker = BlackMisc::CWorker::fromTask(this, "CAircraftMatcher::initImpl", [this]()
|
|
||||||
{
|
|
||||||
this->initImpl();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CAircraftMatcher::isInitialized() const
|
|
||||||
{
|
|
||||||
return m_initState == InitFinished;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftMatcher::setModelMappingProvider(std::unique_ptr<IModelMappingsProvider> mappings)
|
void CAircraftMatcher::setModelMappingProvider(std::unique_ptr<IModelMappingsProvider> mappings)
|
||||||
{
|
{
|
||||||
m_mappingsProvider = std::move(mappings);
|
this->m_mappingsProvider = std::move(mappings);
|
||||||
if (m_matchingMode.testFlag(ModelMapping)) { initMappings(); }
|
CAircraftModelList models = this->m_mappingsProvider->getMatchingModels();
|
||||||
|
int d = models.removeIfExcluded();
|
||||||
|
this->m_models.uniqueWrite() = models; // local copy
|
||||||
|
CLogMessage(this).info("Added %1 models for model matching, %2 removed") << models.size() << d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAircraftMatcher::setMatchingModes(MatchingMode matchingModes)
|
void CAircraftMatcher::setLogDetails(bool log)
|
||||||
{
|
{
|
||||||
m_matchingMode = matchingModes;
|
this->m_logDetails = log;
|
||||||
if (m_matchingMode.testFlag(ModelMapping) && m_modelsFromDatastoreInstalled.isEmpty())
|
|
||||||
{
|
|
||||||
initMappings();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModel CAircraftMatcher::getClosestMatch(const CSimulatedAircraft &remoteAircraft)
|
void CAircraftMatcher::reload()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftModel CAircraftMatcher::getClosestMatch(const CSimulatedAircraft &remoteAircraft) const
|
||||||
{
|
{
|
||||||
CAircraftModel aircraftModel(remoteAircraft.getModel()); // set defaults
|
CAircraftModel aircraftModel(remoteAircraft.getModel()); // set defaults
|
||||||
|
|
||||||
// Manually set string?
|
// Manually set string?
|
||||||
if (remoteAircraft.getModel().hasManuallySetString())
|
if (remoteAircraft.getModel().hasManuallySetString())
|
||||||
{
|
{
|
||||||
// manual set model, maybe update missing parts
|
// the user did a manual mapping "by hand", so he really should know what he is doing
|
||||||
aircraftModel.updateMissingParts(remoteAircraft.getModel());
|
// no matching
|
||||||
aircraftModel.setCallsign(remoteAircraft.getCallsign());
|
this->logDetails(remoteAircraft, "Manually set model " + remoteAircraft.getModelString());
|
||||||
return aircraftModel;
|
return remoteAircraft.getModel();
|
||||||
}
|
|
||||||
|
|
||||||
// mapper ready?
|
|
||||||
if (!isInitialized())
|
|
||||||
{
|
|
||||||
// will be removed later, just for experimental version
|
|
||||||
aircraftModel = getDefaultModel();
|
|
||||||
aircraftModel.setCallsign(remoteAircraft.getCallsign());
|
|
||||||
CLogMessage(static_cast<CAircraftMatcher *>(nullptr)).warning("Matcher not initialized, set to default model");
|
|
||||||
return aircraftModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString log;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
//! \todo this code here is partially nuts and needs to be adjusted
|
|
||||||
//! as soon as we have real DB data
|
|
||||||
//! things to change:
|
|
||||||
//! 1) instead of keeping two lists (DB data + own models) just
|
|
||||||
//! update / enhance the list of installed models with the DB metadata
|
|
||||||
//! then there is only one search required
|
|
||||||
//! 2) Keep a cache of installed models enriched by the DB metadata (that will eliminate all
|
|
||||||
//! sync processes and can be done offline
|
|
||||||
//! 3) drivers which can assign reliable ICAO codes should do this as much as possible
|
|
||||||
//! the sync process with DB will improve those information (by livery details, but in case
|
|
||||||
//! of now metadata from DB we have the best matching data we can get
|
|
||||||
//! Also such data can be used in the mapping tool as default values (Less values to type in)
|
|
||||||
|
|
||||||
// try to find in installed models by model string
|
// try to find in installed models by model string
|
||||||
aircraftModel = matchByExactModelName(remoteAircraft);
|
aircraftModel = matchByExactModelString(remoteAircraft);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (aircraftModel.hasModelString())
|
||||||
|
{
|
||||||
|
if (this->m_logDetails) { log = "Matched by exact model string " + aircraftModel.getModelString(); }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------ start parts depending on swift DB data -------------------
|
// ------------ start parts depending on swift DB data -------------------
|
||||||
|
|
||||||
// by DB ICAO data
|
// by DB ICAO data
|
||||||
aircraftModel = matchInstalledModelsByIcaoData(remoteAircraft);
|
aircraftModel = matchModelsByIcaoData(remoteAircraft, log);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (aircraftModel.hasModelString())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------ end parts depending on swift DB data -------------------
|
// ------------ end parts depending on swift DB data -------------------
|
||||||
|
|
||||||
aircraftModel = matchByAlgorithm(remoteAircraft);
|
aircraftModel = matchByFamily(remoteAircraft, log);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (aircraftModel.hasModelString()) { break; }
|
||||||
|
|
||||||
aircraftModel = getDefaultModel();
|
aircraftModel = getDefaultModel();
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
// copy over callsign
|
// copy over callsign and other data
|
||||||
aircraftModel.setCallsign(remoteAircraft.getCallsign());
|
aircraftModel.setCallsign(remoteAircraft.getCallsign());
|
||||||
|
|
||||||
|
this->logDetails(aircraftModel, log);
|
||||||
|
|
||||||
Q_ASSERT_X(!aircraftModel.getCallsign().isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
Q_ASSERT_X(!aircraftModel.getCallsign().isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
||||||
Q_ASSERT_X(aircraftModel.hasModelString(), Q_FUNC_INFO, "Missing model string");
|
Q_ASSERT_X(aircraftModel.hasModelString(), Q_FUNC_INFO, "Missing model string");
|
||||||
Q_ASSERT_X(aircraftModel.getModelType() != CAircraftModel::TypeUnknown, Q_FUNC_INFO, "Missing model type");
|
Q_ASSERT_X(aircraftModel.getModelType() != CAircraftModel::TypeUnknown, Q_FUNC_INFO, "Missing model type");
|
||||||
@@ -130,18 +109,7 @@ namespace BlackMisc
|
|||||||
return aircraftModel;
|
return aircraftModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAircraftMatcher::synchronize()
|
const CAircraftModel &CAircraftMatcher::getDefaultModel() const
|
||||||
{
|
|
||||||
return synchronizeWithExistingModels(m_installedModels.getModelStrings());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftMatcher::cancelInit()
|
|
||||||
{
|
|
||||||
// when running, force re-init
|
|
||||||
this->m_initState = NotInitialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CAircraftModel &CAircraftMatcher::getDefaultModel()
|
|
||||||
{
|
{
|
||||||
return m_defaultModel;
|
return m_defaultModel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
#include "blackmisc/simulation/modelmappingsprovider.h"
|
#include "blackmisc/simulation/modelmappingsprovider.h"
|
||||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||||
#include "blackmisc/worker.h"
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -48,29 +47,14 @@ namespace BlackMisc
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag)
|
Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag)
|
||||||
|
|
||||||
|
//! Log categories
|
||||||
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CAircraftMatcher(MatchingMode matchingMode = ModelMatching, QObject *parent = nullptr);
|
CAircraftMatcher(MatchingMode matchingMode = ModelMatching, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~CAircraftMatcher();
|
virtual ~CAircraftMatcher();
|
||||||
|
|
||||||
//! Initialize
|
|
||||||
void init();
|
|
||||||
|
|
||||||
//! Init completed?
|
|
||||||
bool isInitialized() const;
|
|
||||||
|
|
||||||
//! Get all models
|
|
||||||
const CAircraftModelList &getInstalledModelsList() const { return m_installedModels; }
|
|
||||||
|
|
||||||
//! Set the list of installed models
|
|
||||||
void setInstalledModels(const CAircraftModelList &models) { m_installedModels = models; }
|
|
||||||
|
|
||||||
//! Number of models
|
|
||||||
int countInstalledModels() const { return m_installedModels.size(); }
|
|
||||||
|
|
||||||
//! Set the model mapping provider. The CAircraftMatcher will move the object and take over ownership
|
|
||||||
void setModelMappingProvider(std::unique_ptr<IModelMappingsProvider> mappings);
|
|
||||||
|
|
||||||
//! Set the enabled matching modes
|
//! Set the enabled matching modes
|
||||||
void setMatchingModes(MatchingMode matchingModes);
|
void setMatchingModes(MatchingMode matchingModes);
|
||||||
@@ -78,35 +62,27 @@ namespace BlackMisc
|
|||||||
//! Get the closest matching aircraft model.
|
//! Get the closest matching aircraft model.
|
||||||
//! Result depends on enabled modes.
|
//! Result depends on enabled modes.
|
||||||
//! \sa MatchingModeFlag
|
//! \sa MatchingModeFlag
|
||||||
CAircraftModel getClosestMatch(const CSimulatedAircraft &remoteAircraft);
|
//! \threadsafe
|
||||||
|
CAircraftModel getClosestMatch(const CSimulatedAircraft &remoteAircraft) const;
|
||||||
|
|
||||||
//! Get all mappings
|
//! Get all mappings
|
||||||
BlackMisc::Simulation::CAircraftModelList getMappingModels() const { return m_mappingsProvider->getMappingModels(); }
|
BlackMisc::Simulation::CAircraftModelList getMatchingModels() const { return m_mappingsProvider->getMatchingModels(); }
|
||||||
|
|
||||||
//! Number of mapping definitions
|
//! Set the model mapping provider. The CAircraftMatcher will move the object and take over ownership
|
||||||
int countMappingRules() const { return m_modelsFromDatastoreInstalled.size(); }
|
void setModelMappingProvider(std::unique_ptr<IModelMappingsProvider> mappings);
|
||||||
|
|
||||||
//! Synchronize models and mappings
|
//! Log.details?
|
||||||
//! \remarks after this step, we only have mappings for which we have models
|
void setLogDetails(bool log);
|
||||||
int synchronize();
|
|
||||||
|
|
||||||
//! Shutdown
|
//! Reload
|
||||||
void cancelInit();
|
void reload();
|
||||||
|
|
||||||
//! default model
|
//! Default model
|
||||||
const BlackMisc::Simulation::CAircraftModel &getDefaultModel();
|
const BlackMisc::Simulation::CAircraftModel &getDefaultModel() const;
|
||||||
|
|
||||||
//! Set default model
|
//! Set default model
|
||||||
void setDefaultModel(const BlackMisc::Simulation::CAircraftModel &defaultModel);
|
void setDefaultModel(const BlackMisc::Simulation::CAircraftModel &defaultModel);
|
||||||
|
|
||||||
signals:
|
|
||||||
//! Full init completed
|
|
||||||
void initializationFinished();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
//! Set the datatstore models
|
|
||||||
void ps_setDatastoreModels(const CAircraftModelList &mappings);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Init state
|
//! Init state
|
||||||
enum InitState
|
enum InitState
|
||||||
@@ -116,27 +92,26 @@ namespace BlackMisc
|
|||||||
InitFinished
|
InitFinished
|
||||||
};
|
};
|
||||||
|
|
||||||
void initImpl();
|
//! Search in models by key (aka model string)
|
||||||
void initMappings();
|
//! \threadsafe
|
||||||
|
CAircraftModel matchByExactModelString(const CSimulatedAircraft &remoteAircraft) const;
|
||||||
|
|
||||||
//! Search in installed models by key (aka model string)
|
//! Installed models by ICAO data
|
||||||
CAircraftModel matchByExactModelName(const CSimulatedAircraft &remoteAircraft);
|
//! \threadsafe
|
||||||
|
CAircraftModel matchModelsByIcaoData(const CSimulatedAircraft &remoteAircraft, QString &log) const;
|
||||||
|
|
||||||
//! Installed models by database ICAO data (requires DB entries)
|
//! Find model by aircraft family
|
||||||
CAircraftModel matchInstalledModelsByIcaoData(const CSimulatedAircraft &remoteAircraft);
|
CAircraftModel matchByFamily(const CSimulatedAircraft &remoteAircraft, QString &log) const;
|
||||||
|
|
||||||
CAircraftModel matchByAlgorithm(const CSimulatedAircraft &remoteAircraft);
|
//! Log. details about mapping of particular aircraft
|
||||||
|
//! threadsafe
|
||||||
//! Synchronize with existing model names, remove unneeded models
|
void logDetails(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const QString &message) const;
|
||||||
int synchronizeWithExistingModels(const QStringList &modelNames, Qt::CaseSensitivity cs = Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
|
MatchingMode m_matchingMode = ModelMatching;
|
||||||
|
BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< model to be used as default model
|
||||||
|
BlackMisc::LockFree<BlackMisc::Simulation::CAircraftModelList> m_models; //!< models used for model matching
|
||||||
std::unique_ptr<BlackMisc::Simulation::IModelMappingsProvider> m_mappingsProvider; //!< Provides all mapping definitions
|
std::unique_ptr<BlackMisc::Simulation::IModelMappingsProvider> m_mappingsProvider; //!< Provides all mapping definitions
|
||||||
std::atomic<InitState> m_initState { NotInitialized };
|
std::atomic<bool> m_logDetails { false }; //!< log details
|
||||||
QPointer<BlackMisc::CWorker> m_initWorker;
|
|
||||||
MatchingMode m_matchingMode = ModelMatching;
|
|
||||||
CAircraftModelList m_installedModels; //!< my simulator`s installed models
|
|
||||||
CAircraftModelList m_modelsFromDatastoreInstalled; //!< models from datastore I do actually have installed
|
|
||||||
BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< model to be used as default model
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace BlackMisc
|
|||||||
QString CAircraftModel::convertToQString(bool i18n) const
|
QString CAircraftModel::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
QString s = this->m_modelString;
|
QString s = this->m_modelString;
|
||||||
if (!s.isEmpty()) { s += ' '; }
|
if (!s.isEmpty()) { s += " tpye: "; }
|
||||||
s += this->getModelTypeAsString();
|
s += this->getModelTypeAsString();
|
||||||
s += ' ';
|
s += ' ';
|
||||||
s += this->m_aircraftIcao.toQString(i18n);
|
s += this->m_aircraftIcao.toQString(i18n);
|
||||||
@@ -339,6 +339,7 @@ namespace BlackMisc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->m_callsign.isEmpty()) { this->setCallsign(otherModel.getCallsign()); }
|
||||||
if (this->m_modelString.isEmpty()) { this->setModelString(otherModel.getModelString()); }
|
if (this->m_modelString.isEmpty()) { this->setModelString(otherModel.getModelString()); }
|
||||||
if (this->m_description.isEmpty()) { this->setDescription(otherModel.getDescription()); }
|
if (this->m_description.isEmpty()) { this->setDescription(otherModel.getDescription()); }
|
||||||
if (this->m_fileName.isEmpty()) { this->setFileName(otherModel.getFileName()); }
|
if (this->m_fileName.isEmpty()) { this->setFileName(otherModel.getFileName()); }
|
||||||
|
|||||||
@@ -215,6 +215,44 @@ namespace BlackMisc
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CAircraftModelList::removeAllWithoutModelString()
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return 0; }
|
||||||
|
int c = 0;
|
||||||
|
for (auto it = this->begin(); it != this->end();)
|
||||||
|
{
|
||||||
|
if (it->hasModelString())
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c++;
|
||||||
|
it = this->erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CAircraftModelList::removeIfExcluded()
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return 0; }
|
||||||
|
int c = 0;
|
||||||
|
for (auto it = this->begin(); it != this->end();)
|
||||||
|
{
|
||||||
|
if (it->getModelMode() != CAircraftModel::Exclude)
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c++;
|
||||||
|
it = this->erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
int CAircraftModelList::replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
|
int CAircraftModelList::replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
|
||||||
{
|
{
|
||||||
if (addOrReplaceList.isEmpty()) { return 0; }
|
if (addOrReplaceList.isEmpty()) { return 0; }
|
||||||
|
|||||||
@@ -102,8 +102,17 @@ namespace BlackMisc
|
|||||||
int removeModelsWithString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity);
|
int removeModelsWithString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity);
|
||||||
|
|
||||||
//! Remove if not matching simulator
|
//! Remove if not matching simulator
|
||||||
|
//! \return number of elements removed
|
||||||
int removeIfNotMatchingSimulator(const CSimulatorInfo &needToMatch);
|
int removeIfNotMatchingSimulator(const CSimulatorInfo &needToMatch);
|
||||||
|
|
||||||
|
//! Remove if having no model string
|
||||||
|
//! \return number of elements removed
|
||||||
|
int removeAllWithoutModelString();
|
||||||
|
|
||||||
|
//! Remove if excluded CAircraftModel::Exclude
|
||||||
|
//! \return number of elements removed
|
||||||
|
int removeIfExcluded();
|
||||||
|
|
||||||
//! Replace or add based on model string
|
//! Replace or add based on model string
|
||||||
//! \return number of elements removed
|
//! \return number of elements removed
|
||||||
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity);
|
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "simulatorfscommon.h"
|
#include "simulatorfscommon.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/simulation/fscommon/modelmappingsprovidervpilot.h"
|
#include "blackmisc/simulation/modelmappingsprovider.h"
|
||||||
|
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Simulation;
|
using namespace BlackMisc::Simulation;
|
||||||
@@ -33,41 +33,17 @@ namespace BlackSimPlugin
|
|||||||
QObject *parent) :
|
QObject *parent) :
|
||||||
CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, weatherGridProvider, parent),
|
CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, weatherGridProvider, parent),
|
||||||
m_fsuipc(new CFsuipc()),
|
m_fsuipc(new CFsuipc()),
|
||||||
m_aircraftCfgParser(CAircraftCfgParser::createModelLoader(CSimulatorInfo(info.getIdentifier()))),
|
|
||||||
m_modelMatcher(CAircraftMatcher::AllModes, this)
|
m_modelMatcher(CAircraftMatcher::AllModes, this)
|
||||||
{
|
{
|
||||||
// hack to init mapper
|
// init mapper
|
||||||
connect(&m_modelMatcher, &CAircraftMatcher::initializationFinished, this, &CSimulatorFsCommon::ps_mapperInitialized);
|
CSimulatorInfo sim(info.getIdentifier());
|
||||||
auto modelMappingsProvider = std::unique_ptr<IModelMappingsProvider> { std::make_unique<CModelMappingsProviderVPilot>(true) };
|
this->m_modelMatcher.setModelMappingProvider(
|
||||||
m_modelMatcher.setModelMappingProvider(std::move(modelMappingsProvider));
|
std::make_unique<CachedModelSetProvider>(sim, this)
|
||||||
|
);
|
||||||
bool c = connect(m_aircraftCfgParser.get(), &CAircraftCfgParser::loadingFinished, this, &CSimulatorFsCommon::ps_aircraftCfgParsingFinished);
|
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect signal");
|
|
||||||
Q_UNUSED(c);
|
|
||||||
|
|
||||||
//! \todo remove from plugin if data there are cached as well
|
|
||||||
/**
|
|
||||||
CVariant aircraftCfg = getPluginData(this, "aircraft_cfg");
|
|
||||||
if (aircraftCfg.isValid())
|
|
||||||
{
|
|
||||||
// will behave like parsing was finished
|
|
||||||
m_aircraftCfgParser->updateCfgEntriesList(aircraftCfg.value<CAircraftCfgEntriesList>());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_aircraftCfgParser->startLoading(CAircraftCfgParser::LoadInBackground);
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
m_aircraftCfgParser->startLoading(CAircraftCfgParser::InBackgroundWithCache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorFsCommon::~CSimulatorFsCommon() { }
|
CSimulatorFsCommon::~CSimulatorFsCommon() { }
|
||||||
|
|
||||||
void CSimulatorFsCommon::ps_mapperInitialized()
|
|
||||||
{
|
|
||||||
emit this->installedAircraftModelsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSimulatorFsCommon::disconnectFrom()
|
bool CSimulatorFsCommon::disconnectFrom()
|
||||||
{
|
{
|
||||||
if (this->m_fsuipc) { this->m_fsuipc->disconnect(); }
|
if (this->m_fsuipc) { this->m_fsuipc->disconnect(); }
|
||||||
@@ -125,18 +101,19 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
CAircraftModelList CSimulatorFsCommon::getInstalledModels() const
|
CAircraftModelList CSimulatorFsCommon::getInstalledModels() const
|
||||||
{
|
{
|
||||||
return m_modelMatcher.getInstalledModelsList();
|
return m_modelMatcher.getMatchingModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsCommon::reloadInstalledModels()
|
void CSimulatorFsCommon::reloadInstalledModels()
|
||||||
{
|
{
|
||||||
m_aircraftCfgParser->startLoading();
|
this->m_modelMatcher.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
CPixmap CSimulatorFsCommon::iconForModel(const QString &modelString) const
|
CPixmap CSimulatorFsCommon::iconForModel(const QString &modelString) const
|
||||||
{
|
{
|
||||||
CStatusMessage msg;
|
CStatusMessage msg;
|
||||||
CPixmap pm(m_aircraftCfgParser->iconForModel(modelString, msg));
|
// CPixmap pm(m_aircraftCfgParser->iconForModel(modelString, msg));
|
||||||
|
CPixmap pm;
|
||||||
if (!msg.isEmpty()) { CLogMessage::preformatted(msg);}
|
if (!msg.isEmpty()) { CLogMessage::preformatted(msg);}
|
||||||
return pm;
|
return pm;
|
||||||
}
|
}
|
||||||
@@ -172,23 +149,5 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
CSimulatorCommon::enableDebugMessages(driver, interpolator);
|
CSimulatorCommon::enableDebugMessages(driver, interpolator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsCommon::unload()
|
|
||||||
{
|
|
||||||
this->m_aircraftCfgParser->cancelLoading();
|
|
||||||
this->m_modelMatcher.cancelInit();
|
|
||||||
CSimulatorCommon::unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSimulatorFsCommon::ps_aircraftCfgParsingFinished(bool success)
|
|
||||||
{
|
|
||||||
if (!success) { return; }
|
|
||||||
setPluginData(this, "aircraft_cfg", CVariant::from(m_aircraftCfgParser->getAircraftCfgEntriesList()));
|
|
||||||
m_modelMatcher.setInstalledModels(m_aircraftCfgParser->getAircraftCfgEntriesList().toAircraftModelList());
|
|
||||||
|
|
||||||
// Now the matcher has all required information to be initialized
|
|
||||||
m_modelMatcher.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -73,9 +73,6 @@ namespace BlackSimPlugin
|
|||||||
//! \copydoc BlackCore::ISimulator::enableDebugMessages
|
//! \copydoc BlackCore::ISimulator::enableDebugMessages
|
||||||
virtual void enableDebugMessages(bool driver, bool interpolator) override;
|
virtual void enableDebugMessages(bool driver, bool interpolator) override;
|
||||||
|
|
||||||
//! \copydoc BlackCore::ISimulator::unload
|
|
||||||
virtual void unload() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CSimulatorFsCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
CSimulatorFsCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||||
@@ -91,15 +88,14 @@ namespace BlackSimPlugin
|
|||||||
bool m_simPaused = false; //!< Simulator paused?
|
bool m_simPaused = false; //!< Simulator paused?
|
||||||
bool m_simTimeSynced = false; //!< Time synchronized?
|
bool m_simTimeSynced = false; //!< Time synchronized?
|
||||||
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset
|
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset
|
||||||
BlackMisc::Aviation::CAirportList m_airportsInRange; //!< aiports in range of own aircraft
|
BlackMisc::Aviation::CAirportList m_airportsInRange; //!< airports in range of own aircraft
|
||||||
|
|
||||||
// cockpit as set in SIM
|
// cockpit as set in SIM
|
||||||
BlackMisc::Aviation::CComSystem m_simCom1; //!< cockpit COM1 state in simulator
|
BlackMisc::Aviation::CComSystem m_simCom1; //!< cockpit COM1 state in simulator
|
||||||
BlackMisc::Aviation::CComSystem m_simCom2; //!< cockpit COM2 state in simulator
|
BlackMisc::Aviation::CComSystem m_simCom2; //!< cockpit COM2 state in simulator
|
||||||
BlackMisc::Aviation::CTransponder m_simTransponder; //!< cockpit xpdr state in simulator
|
BlackMisc::Aviation::CTransponder m_simTransponder; //!< cockpit xpdr state in simulator
|
||||||
|
|
||||||
// parser / matcher
|
// parser / matcher
|
||||||
std::unique_ptr<BlackMisc::Simulation::FsCommon::CAircraftCfgParser> m_aircraftCfgParser; //!< aircraft.cfg parser
|
|
||||||
BlackMisc::Simulation::CAircraftMatcher m_modelMatcher; //!< Model matcher
|
BlackMisc::Simulation::CAircraftMatcher m_modelMatcher; //!< Model matcher
|
||||||
|
|
||||||
//! Set own model
|
//! Set own model
|
||||||
@@ -107,13 +103,6 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
//! Set own model
|
//! Set own model
|
||||||
void setOwnAircraftModel(const QString &modelName);
|
void setOwnAircraftModel(const QString &modelName);
|
||||||
|
|
||||||
protected slots:
|
|
||||||
//! Mapper has been initialized
|
|
||||||
void ps_mapperInitialized();
|
|
||||||
|
|
||||||
//! aircraft.cfg files parsing is finished
|
|
||||||
void ps_aircraftCfgParsingFinished(bool success);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -191,9 +191,6 @@ namespace BlackSimPlugin
|
|||||||
CAircraftModel aircraftModel(*modelStringsIt, CAircraftModel::TypeDatabaseEntry, QString(), aircraftIcao, livery);
|
CAircraftModel aircraftModel(*modelStringsIt, CAircraftModel::TypeDatabaseEntry, QString(), aircraftIcao, livery);
|
||||||
m_installedModels.push_back(aircraftModel);
|
m_installedModels.push_back(aircraftModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_modelMatcher.setInstalledModels(m_installedModels);
|
|
||||||
m_modelMatcher.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorXPlane::isConnected() const
|
bool CSimulatorXPlane::isConnected() const
|
||||||
|
|||||||
Reference in New Issue
Block a user