refs #768, misc adjustments

* changed signature of ownAircraftModelChanged to model
* added function for a reverse lookup of a model (string->model) and use it when model changed
* renamed function to updateByLocalFileNames
This commit is contained in:
Klaus Basan
2016-10-06 21:24:54 +02:00
committed by Mathew Sutcliffe
parent 501bea0960
commit bf8198e2c2
10 changed files with 112 additions and 42 deletions

View File

@@ -11,6 +11,8 @@
#include "blackcore/context/contextaudio.h" #include "blackcore/context/contextaudio.h"
#include "blackcore/context/contextnetwork.h" #include "blackcore/context/contextnetwork.h"
#include "blackcore/context/contextownaircraftimpl.h" #include "blackcore/context/contextownaircraftimpl.h"
#include "blackcore/application.h"
#include "blackcore/webdataservices.h"
#include "blackmisc/audio/voiceroom.h" #include "blackmisc/audio/voiceroom.h"
#include "blackmisc/audio/voiceroomlist.h" #include "blackmisc/audio/voiceroomlist.h"
#include "blackmisc/aviation/aircrafticaocode.h" #include "blackmisc/aviation/aircrafticaocode.h"
@@ -42,6 +44,7 @@ using namespace BlackMisc::Network;
using namespace BlackMisc::Geo; using namespace BlackMisc::Geo;
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
using namespace BlackCore;
namespace BlackCore namespace BlackCore
{ {
@@ -54,6 +57,11 @@ namespace BlackCore
Q_ASSERT(this->getRuntime()); Q_ASSERT(this->getRuntime());
this->setObjectName("CContextOwnAircraft"); this->setObjectName("CContextOwnAircraft");
if (sApp && sApp->getWebDataServices())
{
connect(sApp->getWebDataServices(), &CWebDataServices::allSwiftDbDataRead, this, &CContextOwnAircraft::ps_allSwiftWebDataRead);
}
// Init own aircraft // Init own aircraft
this->initOwnAircraft(); this->initOwnAircraft();
} }
@@ -100,10 +108,15 @@ namespace BlackCore
void CContextOwnAircraft::initOwnAircraft() void CContextOwnAircraft::initOwnAircraft()
{ {
Q_ASSERT(this->getRuntime()); Q_ASSERT(this->getRuntime());
CSimulatedAircraft ownAircraft;
{ {
QWriteLocker l(&m_lockAircraft); // use copy to minimize lock time
this->m_ownAircraft.initComSystems(); QReadLocker rl(&m_lockAircraft);
this->m_ownAircraft.initTransponder(); ownAircraft = this->m_ownAircraft;
}
ownAircraft.initComSystems();
ownAircraft.initTransponder();
CAircraftSituation situation( CAircraftSituation situation(
CCoordinateGeodetic( CCoordinateGeodetic(
CLatitude::fromWgs84("N 049° 18' 17"), CLatitude::fromWgs84("N 049° 18' 17"),
@@ -111,19 +124,35 @@ namespace BlackCore
CLength(0, CLengthUnit::m())), CLength(0, CLengthUnit::m())),
CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()) CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft())
); );
this->m_ownAircraft.setSituation(situation); ownAircraft.setSituation(situation);
this->m_ownAircraft.setPilot(this->m_currentNetworkServer.getThreadLocal().getUser()); ownAircraft.setPilot(this->m_currentNetworkServer.getThreadLocal().getUser());
// from simulator, if available // reverse lookup if possible
this->m_ownAircraft.setCallsign(CCallsign("SWIFT")); // would come from settings if (!ownAircraft.getModel().isLoadedFromDb() && !ownAircraft.getModelString().isEmpty())
{
ownAircraft.setModel(reverseLookupModel(ownAircraft.getModelString()));
}
//! \todo Own aircraft ICAO default data, this would need to come from somewhere (mappings) -> Own callsign, plane ICAO status, model used // override empty values
this->m_ownAircraft.setIcaoCodes( if (!ownAircraft.hasValidCallsign())
{
ownAircraft.setCallsign(CCallsign("SWIFT"));
}
if (!ownAircraft.getAircraftIcaoCode().hasValidDesignator())
{
ownAircraft.setIcaoCodes(
CAircraftIcaoCode("C172", "L1P"), CAircraftIcaoCode("C172", "L1P"),
CAirlineIcaoCode() CAirlineIcaoCode()
); );
} }
// update object
{
QWriteLocker l(&m_lockAircraft);
m_ownAircraft = ownAircraft;
}
// voice rooms, if network is already available // voice rooms, if network is already available
if (this->getIContextNetwork()) if (this->getIContextNetwork())
{ {
@@ -154,12 +183,37 @@ namespace BlackCore
emit this->getIContextApplication()->fakedSetComVoiceRoom(rooms); emit this->getIContextApplication()->fakedSetComVoiceRoom(rooms);
} }
CAircraftModel CContextOwnAircraft::reverseLookupModel(const QString &modelString)
{
if (modelString.isEmpty()) { return CAircraftModel(); }
if (!sApp || !sApp->hasWebDataServices()) { return CAircraftModel(); }
const CAircraftModel reverseLookupModel = sApp->getWebDataServices()->getModelForModelString(modelString);
return reverseLookupModel;
}
bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model) bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model)
{ {
// reverse lookup if not yet from DB:
// this is the central place where we keep our own model, so we use best effort
// to make that model as accuarate as we can
CAircraftModel updateModel(model);
if (!updateModel.isLoadedFromDb())
{
CAircraftModel reverseModel = reverseLookupModel(model.getModelString());
if (reverseModel.isLoadedFromDb())
{
// special case here, as we have some specific values for a local model
updateModel = reverseModel;
updateModel.updateMissingParts(model);
updateModel.setFileName(model.getFileName());
}
}
QWriteLocker l(&m_lockAircraft); QWriteLocker l(&m_lockAircraft);
bool changed = (this->m_ownAircraft.getModel() != model); const bool changed = (this->m_ownAircraft.getModel() != updateModel);
if (!changed) { return false; } if (!changed) { return false; }
this->m_ownAircraft.setModel(model); updateModel.setModelType(CAircraftModel::TypeOwnSimulatorModel);
this->m_ownAircraft.setModel(updateModel);
return true; return true;
} }
@@ -292,11 +346,18 @@ namespace BlackCore
this->resolveVoiceRooms(); this->resolveVoiceRooms();
} }
void CContextOwnAircraft::ps_changedSimulatorModel(const CSimulatedAircraft &ownAircraft) void CContextOwnAircraft::ps_changedSimulatorModel(const CAircraftModel &model)
{ {
CAircraftModel model(ownAircraft.getModel()); this->updateOwnModel(model);
QWriteLocker l(&m_lockAircraft); }
this->m_ownAircraft.setModel(model);
void CContextOwnAircraft::ps_allSwiftWebDataRead()
{
const CAircraftModel model = this->getOwnAircraftModel();
if (model.isLoadedFromDb()) { return; }
// a reverse lookup of the model could make sense
this->updateOwnModel(model); // force reverse lookup
} }
void CContextOwnAircraft::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) void CContextOwnAircraft::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url)

View File

@@ -89,6 +89,7 @@ namespace BlackCore
//! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnModel //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnModel
//! \ingroup ownaircraftprovider //! \ingroup ownaircraftprovider
//! \remark perform reverse lookup if possible
virtual bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model) override; virtual bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model) override;
//! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnSituation //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnSituation
@@ -161,7 +162,10 @@ namespace BlackCore
//! Simulator model has been changed //! Simulator model has been changed
//! \note Connected in runtime //! \note Connected in runtime
void ps_changedSimulatorModel(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); void ps_changedSimulatorModel(const BlackMisc::Simulation::CAircraftModel &model);
//! Web data loaded
void ps_allSwiftWebDataRead();
private: private:
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft
@@ -177,6 +181,9 @@ namespace BlackCore
//! Resolve voice rooms //! Resolve voice rooms
void resolveVoiceRooms(); void resolveVoiceRooms();
//! Reverse lookup of the model
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const QString &modelString);
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -100,7 +100,7 @@ namespace BlackCore
void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Emitted when own aircraft model changes //! Emitted when own aircraft model changes
void ownAircraftModelChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); void ownAircraftModelChanged(const BlackMisc::Simulation::CAircraftModel &model);
//! An airspace snapshot was handled //! An airspace snapshot was handled
void airspaceSnapshotHandled(); void airspaceSnapshotHandled();

View File

@@ -45,7 +45,7 @@ namespace BlackCore
"installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged())); "installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged()));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"ownAircraftModelChanged", this, SIGNAL(ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft))); "ownAircraftModelChanged", this, SIGNAL(ownAircraftModelChanged(BlackMisc::Simulation::CAircraftModel)));
Q_ASSERT(s); Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft))); "modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft)));

View File

@@ -33,10 +33,11 @@ namespace BlackCore
const int distributorOrder = model.getDistributorOrder(); // later restore that order const int distributorOrder = model.getDistributorOrder(); // later restore that order
CAircraftModel dbModel(sApp->getWebDataServices()->getModelForModelString(model.getModelString())); CAircraftModel dbModel(sApp->getWebDataServices()->getModelForModelString(model.getModelString()));
if (dbModel.hasValidDbKey()) if (dbModel.isLoadedFromDb())
{ {
// take the db model as original
if (modified) { *modified = true; } if (modified) { *modified = true; }
dbModel.updateByLocalFileNames(model); dbModel.updateMissingParts(model);
dbModel.setDistributorOrder(distributorOrder); dbModel.setDistributorOrder(distributorOrder);
return dbModel; return dbModel;
} }
@@ -70,7 +71,7 @@ namespace BlackCore
if (modified) { *modified = true; } if (modified) { *modified = true; }
consolidatedModel.setDistributor(dbDistributor); consolidatedModel.setDistributor(dbDistributor);
} }
consolidatedModel.updateByLocalFileNames(model); consolidatedModel.updateLocalFileNames(model);
consolidatedModel.setDistributorOrder(distributorOrder); consolidatedModel.setDistributorOrder(distributorOrder);
return consolidatedModel; return consolidatedModel;
} }

View File

@@ -188,13 +188,13 @@ namespace BlackCore
void simulatorStatusChanged(int status); void simulatorStatusChanged(int status);
//! Emitted when own aircraft model has changed //! Emitted when own aircraft model has changed
void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft); void ownAircraftModelChanged(const BlackMisc::Simulation::CAircraftModel &model);
//! Render restrictions have been changed //! Render restrictions have been changed
void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
//! Aircraft rendering changed //! Aircraft rendering changed
void aircraftRenderingChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft); void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Installed aircraft models ready or changed //! Installed aircraft models ready or changed
void installedAircraftModelsChanged(); void installedAircraftModelsChanged();

View File

@@ -101,7 +101,7 @@ namespace BlackMisc
QString CAircraftModel::toDatabaseJsonString(QJsonDocument::JsonFormat format) const QString CAircraftModel::toDatabaseJsonString(QJsonDocument::JsonFormat format) const
{ {
return QJsonDocument(toDatabaseJson()).toJson(format); return QJsonDocument(this->toDatabaseJson()).toJson(format);
} }
bool CAircraftModel::canInitializeFromFsd() const bool CAircraftModel::canInitializeFromFsd() const
@@ -453,12 +453,13 @@ namespace BlackMisc
return; return;
} }
this->updateByLocalFileNames(otherModel); this->updateLocalFileNames(otherModel);
if (this->m_callsign.isEmpty()) { this->setCallsign(otherModel.getCallsign()); } 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->m_description.startsWith(CAircraftModel::autoGenerated(), Qt::CaseInsensitive)) { this->setDescription(otherModel.getDescription()); } if (this->m_name.isEmpty()) { this->setName(otherModel.getName()); }
if (this->m_modelType == TypeUnknown) { this->m_modelType = otherModel.getModelType(); } if (this->m_modelType == TypeUnknown) { this->m_modelType = otherModel.getModelType(); }
if (this->m_modelMode == Undefined) { this->m_modelType = otherModel.getModelType(); } if (this->m_modelMode == Undefined) { this->m_modelType = otherModel.getModelType(); }
if (this->m_description.isEmpty() || this->m_description.startsWith(CAircraftModel::autoGenerated(), Qt::CaseInsensitive)) { this->setDescription(otherModel.getDescription()); }
if (this->m_simulator.isUnspecified()) if (this->m_simulator.isUnspecified())
{ {
this->setSimulator(otherModel.getSimulator()); this->setSimulator(otherModel.getSimulator());
@@ -517,7 +518,7 @@ namespace BlackMisc
this->m_fileName = CAircraftModel::normalizeFileNameForDb(this->m_fileName); this->m_fileName = CAircraftModel::normalizeFileNameForDb(this->m_fileName);
} }
void CAircraftModel::updateByLocalFileNames(const CAircraftModel &model) void CAircraftModel::updateLocalFileNames(const CAircraftModel &model)
{ {
if (this->getModelType() == CAircraftModel::TypeOwnSimulatorModel) if (this->getModelType() == CAircraftModel::TypeOwnSimulatorModel)
{ {

View File

@@ -326,7 +326,7 @@ namespace BlackMisc
void normalizeFileNameForDb(); void normalizeFileNameForDb();
//! If we have local file names, we use those //! If we have local file names, we use those
void updateByLocalFileNames(const CAircraftModel &model); void updateLocalFileNames(const CAircraftModel &model);
//! Matches model string? //! Matches model string?
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const; bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;

View File

@@ -81,7 +81,7 @@ namespace BlackSimPlugin
CAircraftModel newModel(model); CAircraftModel newModel(model);
newModel.setModelType(CAircraftModel::TypeOwnSimulatorModel); newModel.setModelType(CAircraftModel::TypeOwnSimulatorModel);
updateOwnModel(newModel); updateOwnModel(newModel);
emit ownAircraftModelChanged(getOwnAircraft()); emit ownAircraftModelChanged(newModel);
} }
} }

View File

@@ -102,7 +102,8 @@ namespace BlackSimPlugin
m_fastTimer->start(100); m_fastTimer->start(100);
m_slowTimer->start(1000); m_slowTimer->start(1000);
m_defaultModel = { m_defaultModel =
{
"Jets A320_a A320_a_Austrian_Airlines A320_a_Austrian_Airlines", "Jets A320_a A320_a_Austrian_Airlines A320_a_Austrian_Airlines",
CAircraftModel::TypeModelMatchingDefaultModel, CAircraftModel::TypeModelMatchingDefaultModel,
"A320 AUA", "A320 AUA",
@@ -309,10 +310,9 @@ namespace BlackSimPlugin
model.setFileName(path + "/" + filename); model.setFileName(path + "/" + filename);
model.setLivery(CLivery("XPLANE." + livery, airlineIcaoCode, "XP livery", "", "", false)); model.setLivery(CLivery("XPLANE." + livery, airlineIcaoCode, "XP livery", "", "", false));
// updates // updated model.
updateOwnIcaoCodes(model.getAircraftIcaoCode(), airlineIcaoCode); // Hint: will update in own model context by using reverse lookup
updateOwnModel(model); emit ownAircraftModelChanged(model);
emit ownAircraftModelChanged(getOwnAircraft());
} }
void CSimulatorXPlane::displayStatusMessage(const BlackMisc::CStatusMessage &message) const void CSimulatorXPlane::displayStatusMessage(const BlackMisc::CStatusMessage &message) const