mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
refs #791, adjusted own aircraft context
* function for default model and situation in context (so they can be reused as in login component) * use CDatabaseUtils::consolidateOwnAircraftModelWithDbData for lookup
This commit is contained in:
@@ -7,12 +7,20 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "blackcore/application.h"
|
||||||
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackcore/context/contextownaircraft.h"
|
#include "blackcore/context/contextownaircraft.h"
|
||||||
#include "blackcore/context/contextownaircraftempty.h"
|
#include "blackcore/context/contextownaircraftempty.h"
|
||||||
#include "blackcore/context/contextownaircraftimpl.h"
|
#include "blackcore/context/contextownaircraftimpl.h"
|
||||||
#include "blackcore/context/contextownaircraftproxy.h"
|
#include "blackcore/context/contextownaircraftproxy.h"
|
||||||
|
#include "blackmisc/aviation/aircraftsituation.h"
|
||||||
#include "blackmisc/dbusserver.h"
|
#include "blackmisc/dbusserver.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
using namespace BlackMisc::Geo;
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
namespace Context
|
namespace Context
|
||||||
@@ -31,5 +39,35 @@ namespace BlackCore
|
|||||||
return new CContextOwnAircraftEmpty(parent);
|
return new CContextOwnAircraftEmpty(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BlackMisc::Aviation::CAircraftSituation &IContextOwnAircraft::getDefaultSituation()
|
||||||
|
{
|
||||||
|
static const CAircraftSituation situation(
|
||||||
|
CCoordinateGeodetic(
|
||||||
|
CLatitude::fromWgs84("N 049° 18' 17"),
|
||||||
|
CLongitude::fromWgs84("E 008° 27' 05"),
|
||||||
|
CLength(0, CLengthUnit::m())),
|
||||||
|
CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft())
|
||||||
|
);
|
||||||
|
return situation;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackMisc::Simulation::CAircraftModel IContextOwnAircraft::getDefaultOwnAircraftModel()
|
||||||
|
{
|
||||||
|
// if all fails
|
||||||
|
static const CAircraftModel defaultModel(
|
||||||
|
"", CAircraftModel::TypeOwnSimulatorModel, "default model",
|
||||||
|
CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0));
|
||||||
|
|
||||||
|
// create one from DB data
|
||||||
|
if (sApp && sApp->hasWebDataServices())
|
||||||
|
{
|
||||||
|
static const CAircraftIcaoCode icao = sApp->getWebDataServices()->getAircraftIcaoCodeForDesignator("C172");
|
||||||
|
static const CLivery livery = sApp->getWebDataServices()->getLiveryForCombinedCode("_CC_WHITE_WHITE");
|
||||||
|
static const CAircraftModel model("", CAircraftModel::TypeOwnSimulatorModel, icao, livery);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
return defaultModel;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace BlackCore
|
|||||||
//! Own ICAO was changed
|
//! Own ICAO was changed
|
||||||
void changedAircraftIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode);
|
void changedAircraftIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode);
|
||||||
|
|
||||||
//! own pilot (aka the swift user) changed
|
//! Own pilot (aka the swift user) changed
|
||||||
void changedPilot(const BlackMisc::Network::CUser &pilot);
|
void changedPilot(const BlackMisc::Network::CUser &pilot);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@@ -142,6 +142,14 @@ namespace BlackCore
|
|||||||
//! Parse command line
|
//! Parse command line
|
||||||
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0;
|
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0;
|
||||||
|
|
||||||
|
//! Default situation
|
||||||
|
//! \remark normally used when no driver is attached
|
||||||
|
static const BlackMisc::Aviation::CAircraftSituation &getDefaultSituation();
|
||||||
|
|
||||||
|
//! Default own aircraft
|
||||||
|
//! \remark normally used when no driver is attached
|
||||||
|
static BlackMisc::Simulation::CAircraftModel getDefaultOwnAircraftModel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
IContextOwnAircraft(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {}
|
IContextOwnAircraft(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "blackcore/db/databaseutils.h"
|
||||||
#include "blackcore/context/contextapplication.h"
|
#include "blackcore/context/contextapplication.h"
|
||||||
#include "blackcore/context/contextaudio.h"
|
#include "blackcore/context/contextaudio.h"
|
||||||
#include "blackcore/context/contextnetwork.h"
|
#include "blackcore/context/contextnetwork.h"
|
||||||
@@ -45,6 +46,7 @@ using namespace BlackMisc::Geo;
|
|||||||
using namespace BlackMisc::Audio;
|
using namespace BlackMisc::Audio;
|
||||||
using namespace BlackMisc::Simulation;
|
using namespace BlackMisc::Simulation;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
|
using namespace BlackCore::Db;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -66,6 +68,8 @@ namespace BlackCore
|
|||||||
this->initOwnAircraft();
|
this->initOwnAircraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CContextOwnAircraft::~CContextOwnAircraft() { }
|
||||||
|
|
||||||
CContextOwnAircraft *CContextOwnAircraft::registerWithDBus(CDBusServer *server)
|
CContextOwnAircraft *CContextOwnAircraft::registerWithDBus(CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this;
|
if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this;
|
||||||
@@ -73,8 +77,6 @@ namespace BlackCore
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CContextOwnAircraft::~CContextOwnAircraft() { }
|
|
||||||
|
|
||||||
CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const
|
CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const
|
||||||
{
|
{
|
||||||
if (this->m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
if (this->m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||||
@@ -117,20 +119,14 @@ namespace BlackCore
|
|||||||
|
|
||||||
ownAircraft.initComSystems();
|
ownAircraft.initComSystems();
|
||||||
ownAircraft.initTransponder();
|
ownAircraft.initTransponder();
|
||||||
const CAircraftSituation situation(
|
ownAircraft.setSituation(getDefaultSituation());
|
||||||
CCoordinateGeodetic(
|
ownAircraft.setPilot(this->m_currentNetworkServer.get().getUser());
|
||||||
CLatitude::fromWgs84("N 049° 18' 17"),
|
|
||||||
CLongitude::fromWgs84("E 008° 27' 05"),
|
|
||||||
CLength(0, CLengthUnit::m())),
|
|
||||||
CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft())
|
|
||||||
);
|
|
||||||
ownAircraft.setSituation(situation);
|
|
||||||
ownAircraft.setPilot(this->m_currentNetworkServer.getThreadLocal().getUser());
|
|
||||||
|
|
||||||
// reverse lookup if possible
|
// If we already have a model from somehwere, keep it, otherwise init default
|
||||||
if (!ownAircraft.getModel().isLoadedFromDb() && !ownAircraft.getModelString().isEmpty())
|
ownAircraft.setModel(this->reverseLookupModel(ownAircraft.getModel()));
|
||||||
|
if (!ownAircraft.getAircraftIcaoCode().hasValidDesignator())
|
||||||
{
|
{
|
||||||
ownAircraft.setModel(this->reverseLookupModel(ownAircraft.getModelString()));
|
ownAircraft.setModel(getDefaultOwnAircraftModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
// override empty values
|
// override empty values
|
||||||
@@ -139,14 +135,6 @@ namespace BlackCore
|
|||||||
ownAircraft.setCallsign(CCallsign("SWIFT"));
|
ownAircraft.setCallsign(CCallsign("SWIFT"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ownAircraft.getAircraftIcaoCode().hasValidDesignator())
|
|
||||||
{
|
|
||||||
ownAircraft.setIcaoCodes(
|
|
||||||
CAircraftIcaoCode("C172", "L1P"),
|
|
||||||
CAirlineIcaoCode()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update object
|
// update object
|
||||||
{
|
{
|
||||||
QWriteLocker l(&m_lockAircraft);
|
QWriteLocker l(&m_lockAircraft);
|
||||||
@@ -183,34 +171,16 @@ namespace BlackCore
|
|||||||
emit this->getIContextApplication()->fakedSetComVoiceRoom(rooms);
|
emit this->getIContextApplication()->fakedSetComVoiceRoom(rooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModel CContextOwnAircraft::reverseLookupModel(const QString &modelString)
|
CAircraftModel CContextOwnAircraft::reverseLookupModel(const CAircraftModel &model)
|
||||||
{
|
{
|
||||||
if (modelString.isEmpty()) { return CAircraftModel(); }
|
bool modified = false;
|
||||||
if (!sApp || !sApp->hasWebDataServices()) { return CAircraftModel(); }
|
CAircraftModel reverseModel = CDatabaseUtils::consolidateOwnAircraftModelWithDbData(model, false, &modified);
|
||||||
if (sApp->getWebDataServices()->getModelsCount() < 1) { return CAircraftModel(); }
|
return reverseModel;
|
||||||
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:
|
CAircraftModel updateModel(this->reverseLookupModel(model));
|
||||||
// this is the central place where we keep our own model, so we use best effort
|
|
||||||
// to make that model as accurate 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateModel.setModelType(CAircraftModel::TypeOwnSimulatorModel);
|
|
||||||
QWriteLocker l(&m_lockAircraft);
|
QWriteLocker l(&m_lockAircraft);
|
||||||
const bool changed = (this->m_ownAircraft.getModel() != updateModel);
|
const bool changed = (this->m_ownAircraft.getModel() != updateModel);
|
||||||
if (!changed) { return false; }
|
if (!changed) { return false; }
|
||||||
|
|||||||
@@ -182,8 +182,8 @@ namespace BlackCore
|
|||||||
//! Resolve voice rooms
|
//! Resolve voice rooms
|
||||||
void resolveVoiceRooms();
|
void resolveVoiceRooms();
|
||||||
|
|
||||||
//! Reverse lookup of the model
|
//! Reverse lookup of the model against DB data
|
||||||
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const QString &modelString);
|
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -672,26 +672,9 @@ namespace BlackGui
|
|||||||
|
|
||||||
CAircraftModel CLoginComponent::getPrefillModel() const
|
CAircraftModel CLoginComponent::getPrefillModel() const
|
||||||
{
|
{
|
||||||
// if all fails
|
|
||||||
static const CAircraftModel defaultModel(
|
|
||||||
"", CAircraftModel::TypeOwnSimulatorModel, "default model",
|
|
||||||
CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0));
|
|
||||||
|
|
||||||
CAircraftModel model = this->m_currentAircraftModel.get();
|
CAircraftModel model = this->m_currentAircraftModel.get();
|
||||||
if (model.hasAircraftDesignator()) { return model; }
|
if (model.hasAircraftDesignator()) { return model; }
|
||||||
|
return IContextOwnAircraft::getDefaultOwnAircraftModel();
|
||||||
// create one from DB data
|
|
||||||
if (sGui && sGui->hasWebDataServices())
|
|
||||||
{
|
|
||||||
const CAircraftIcaoCode icao = sGui->getWebDataServices()->getAircraftIcaoCodeForDesignator("C172");
|
|
||||||
const CLivery livery = sGui->getWebDataServices()->getLiveryForCombinedCode("_CC_WHITE_WHITE");
|
|
||||||
model = CAircraftModel("", CAircraftModel::TypeOwnSimulatorModel);
|
|
||||||
model.setLivery(livery);
|
|
||||||
model.setAircraftIcaoCode(icao);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoginComponent::updateOwnCallsignAndPilotFromGuiValue()
|
void CLoginComponent::updateOwnCallsignAndPilotFromGuiValue()
|
||||||
|
|||||||
Reference in New Issue
Block a user