mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 15:49:30 +08:00
Ref T292, Ref T285 removed model set loader
The model set loader is actually no loader (unlike the model loader which really loads the models from disk) but only a cache and will be replaced by CCentralMultiSimulatorModelSetCachesProvider
This commit is contained in:
@@ -1,151 +0,0 @@
|
|||||||
/* Copyright (C) 2015
|
|
||||||
* swift project Community / Contributors
|
|
||||||
*
|
|
||||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
||||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
|
||||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
|
||||||
* contained in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "blackmisc/simulation/aircraftmodelsetloader.h"
|
|
||||||
|
|
||||||
#include <Qt>
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
using namespace BlackMisc::Simulation::Data;
|
|
||||||
|
|
||||||
namespace BlackMisc
|
|
||||||
{
|
|
||||||
namespace Simulation
|
|
||||||
{
|
|
||||||
CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) : QObject(parent)
|
|
||||||
{
|
|
||||||
connect(&m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::onModelsCacheChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAircraftModelSetLoader::~CAircraftModelSetLoader()
|
|
||||||
{
|
|
||||||
this->gracefulShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
CStatusMessage CAircraftModelSetLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
|
||||||
{
|
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
|
||||||
const CStatusMessage m(m_caches.setCachedModels(models, simulator));
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
|
|
||||||
{
|
|
||||||
if (m_currentSimulator == simulator) { return; }
|
|
||||||
m_currentSimulator = simulator;
|
|
||||||
m_caches.synchronizeCache(simulator);
|
|
||||||
emit this->simulatorChanged(simulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
|
|
||||||
{
|
|
||||||
return m_caches.getCachedModels(m_currentSimulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator)
|
|
||||||
{
|
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
|
||||||
return m_caches.getSynchronizedCachedModels(simulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
int CAircraftModelSetLoader::getAircraftModelsCount() const
|
|
||||||
{
|
|
||||||
return this->getAircraftModels().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
CAircraftModel CAircraftModelSetLoader::getModelForModelString(const QString &modelString) const
|
|
||||||
{
|
|
||||||
if (modelString.isEmpty()) { return CAircraftModel(); }
|
|
||||||
return this->getAircraftModels().findFirstByModelStringOrDefault(modelString);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAircraftModelList CAircraftModelSetLoader::getCachedModels(const CSimulatorInfo &simulator) const
|
|
||||||
{
|
|
||||||
return m_caches.getCachedModels(simulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDateTime CAircraftModelSetLoader::getCacheTimestamp() const
|
|
||||||
{
|
|
||||||
return m_caches.getCacheTimestamp(m_currentSimulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftModelSetLoader::synchronizeCache()
|
|
||||||
{
|
|
||||||
m_caches.synchronizeCache(m_currentSimulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftModelSetLoader::admitCache()
|
|
||||||
{
|
|
||||||
m_caches.admitCache(m_currentSimulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CAircraftModelSetLoader::hasCachedData() const
|
|
||||||
{
|
|
||||||
return !m_caches.getCachedModels(m_currentSimulator).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
CStatusMessage CAircraftModelSetLoader::clearCache()
|
|
||||||
{
|
|
||||||
return m_caches.clearCachedModels(this->getSimulator());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftModelSetLoader::onModelsCacheChanged(const CSimulatorInfo &simulator)
|
|
||||||
{
|
|
||||||
this->changeSimulator(simulator);
|
|
||||||
emit this->cacheChanged(simulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CAircraftModelSetLoader::getSimulatorAsString() const
|
|
||||||
{
|
|
||||||
return this->getSimulator().toQString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftModelSetLoader::setSimulator(const CSimulatorInfo &simulator)
|
|
||||||
{
|
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
|
||||||
if (this->getSimulator() == simulator) { return; }
|
|
||||||
this->changeSimulator(simulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info)
|
|
||||||
{
|
|
||||||
return this->getSimulator().matchesAny(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSimulatorInfo CAircraftModelSetLoader::simulatorsWithInitializedModelSet() const
|
|
||||||
{
|
|
||||||
return m_caches.simulatorsWithInitializedCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAircraftModelSetLoader::gracefulShutdown()
|
|
||||||
{
|
|
||||||
// void
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CAircraftModelSetLoader::getInfoString() const
|
|
||||||
{
|
|
||||||
return m_caches.getInfoString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CAircraftModelSetLoader::getInfoStringFsFamily() const
|
|
||||||
{
|
|
||||||
return m_caches.getInfoStringFsFamily();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CAircraftModelSetLoader::getModelCacheCountAndTimestamp() const
|
|
||||||
{
|
|
||||||
return m_caches.getCacheCountAndTimestamp(this->getSimulator());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CAircraftModelSetLoader::getModelCacheCountAndTimestamp(const CSimulatorInfo &simulator) const
|
|
||||||
{
|
|
||||||
return m_caches.getCacheCountAndTimestamp(simulator);
|
|
||||||
}
|
|
||||||
} // ns
|
|
||||||
} // ns
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/* Copyright (C) 2016
|
|
||||||
* 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_SIMULATION_AIRCRAFTMODELSETLOADER_H
|
|
||||||
#define BLACKMISC_SIMULATION_AIRCRAFTMODELSETLOADER_H
|
|
||||||
|
|
||||||
#include "blackmisc/blackmiscexport.h"
|
|
||||||
#include "blackmisc/simulation/aircraftmodel.h"
|
|
||||||
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
|
|
||||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
|
||||||
#include "blackmisc/simulation/data/modelcaches.h"
|
|
||||||
#include "blackmisc/simulation/simulatorinfo.h"
|
|
||||||
#include "blackmisc/statusmessage.h"
|
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace BlackMisc
|
|
||||||
{
|
|
||||||
namespace Simulation
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* Handling of current set for simulator
|
|
||||||
*/
|
|
||||||
class BLACKMISC_EXPORT CAircraftModelSetLoader :
|
|
||||||
public QObject,
|
|
||||||
public IModelsSetable,
|
|
||||||
public IModelsUpdatable,
|
|
||||||
public IModelsForSimulatorSetable,
|
|
||||||
public IModelsForSimulatorUpdatable
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_INTERFACES(BlackMisc::Simulation::IModelsSetable)
|
|
||||||
Q_INTERFACES(BlackMisc::Simulation::IModelsUpdatable)
|
|
||||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorSetable)
|
|
||||||
Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorUpdatable)
|
|
||||||
|
|
||||||
public:
|
|
||||||
//! Constructor
|
|
||||||
CAircraftModelSetLoader(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
//! Destructor
|
|
||||||
virtual ~CAircraftModelSetLoader();
|
|
||||||
|
|
||||||
//! Make sure cache is synchronized
|
|
||||||
void synchronizeCache();
|
|
||||||
|
|
||||||
//! Admit current cache
|
|
||||||
void admitCache();
|
|
||||||
|
|
||||||
//! The loaded models
|
|
||||||
//! \threadsafe
|
|
||||||
CAircraftModelList getAircraftModels() const;
|
|
||||||
|
|
||||||
//! The loaded models for given simulator
|
|
||||||
//! \threadsafe
|
|
||||||
//! \remark non-const because it synchronizes cache
|
|
||||||
CAircraftModelList getAircraftModels(const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
//! Count of loaded models
|
|
||||||
//! \threadsafe
|
|
||||||
int getAircraftModelsCount() const;
|
|
||||||
|
|
||||||
//! Model for given model string
|
|
||||||
//! \threadsafe
|
|
||||||
CAircraftModel getModelForModelString(const QString &modelString) const;
|
|
||||||
|
|
||||||
//! Models from cache
|
|
||||||
//! \threadsafe
|
|
||||||
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const;
|
|
||||||
|
|
||||||
//! Current simulator
|
|
||||||
//! \threadsafe
|
|
||||||
CSimulatorInfo getSimulator() const { return m_currentSimulator; }
|
|
||||||
|
|
||||||
//! Supported simulators as string
|
|
||||||
QString getSimulatorAsString() const;
|
|
||||||
|
|
||||||
//! Set simulator
|
|
||||||
//! \remark checked version, does nothing if simulator is alread set
|
|
||||||
void setSimulator(const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
//! Is the given simulator supported?
|
|
||||||
bool supportsSimulator(const CSimulatorInfo &info);
|
|
||||||
|
|
||||||
//! Simulators with initialized caches
|
|
||||||
CSimulatorInfo simulatorsWithInitializedModelSet() const;
|
|
||||||
|
|
||||||
//! Shutdown
|
|
||||||
void gracefulShutdown();
|
|
||||||
|
|
||||||
//! \copydoc Data::CModelCaches::getInfoString
|
|
||||||
QString getInfoString() const;
|
|
||||||
|
|
||||||
//! \copydoc Data::CModelCaches::getInfoStringFsFamily
|
|
||||||
QString getInfoStringFsFamily() const;
|
|
||||||
|
|
||||||
//! \copydoc Data::CModelCaches::getCacheCountAndTimestamp
|
|
||||||
QString getModelCacheCountAndTimestamp() const;
|
|
||||||
|
|
||||||
//! \copydoc Data::CModelCaches::getCacheCountAndTimestamp
|
|
||||||
QString getModelCacheCountAndTimestamp(const CSimulatorInfo &simulator) const;
|
|
||||||
|
|
||||||
//! \name Implementations of the models interfaces
|
|
||||||
//! @{
|
|
||||||
virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
|
|
||||||
virtual int updateModels(const CAircraftModelList &models) override { return m_caches.updateModelsForSimulator(models, this->getSimulator()); }
|
|
||||||
virtual void setModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
|
|
||||||
virtual int updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { return m_caches.updateModelsForSimulator(models, simulator); }
|
|
||||||
//! @}
|
|
||||||
|
|
||||||
//! Set cached models
|
|
||||||
CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
//! Simulator has been changed
|
|
||||||
void simulatorChanged(const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
//! Cache changed
|
|
||||||
void cacheChanged(const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Data::CModelSetCaches m_caches { true, this }; //!< caches
|
|
||||||
CSimulatorInfo m_currentSimulator = CSimulatorInfo::guessDefaultSimulator();
|
|
||||||
|
|
||||||
private:
|
|
||||||
//! Change the simulator
|
|
||||||
//! \remark unckecked, does not check if simulator is the same
|
|
||||||
void changeSimulator(const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
//! Model cache has changed
|
|
||||||
void onModelsCacheChanged(const CSimulatorInfo &simulator);
|
|
||||||
|
|
||||||
//! Any cached data?
|
|
||||||
bool hasCachedData() const;
|
|
||||||
|
|
||||||
//! Cache timestamp
|
|
||||||
QDateTime getCacheTimestamp() const;
|
|
||||||
|
|
||||||
//! Clear cache
|
|
||||||
BlackMisc::CStatusMessage clearCache();
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#endif // guard
|
|
||||||
Reference in New Issue
Block a user