refs #444 Use CAircraftMatcher to match a model and send it to xbus

In case the model name is empty, xbus falls back to its former
behaviour and lets libxplanemp do the matching. If aircraft matcher
does provide a model this will be used instead.
Until model mapping database is ready, a dummy provider has been added.
Hence CAircraftMatcher will always return a default model.
This commit is contained in:
Roland Winklmeier
2015-06-18 23:20:54 +02:00
committed by Mathew Sutcliffe
parent b28634e586
commit 1ac89d477f
7 changed files with 72 additions and 13 deletions

View File

@@ -11,6 +11,8 @@
#include "xbus_service_proxy.h"
#include "xbus_traffic_proxy.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/simulation/modelmappingsprovider.h"
#include "blackmisc/geo/coordinategeodetic.h"
#include <QDBusServiceWatcher>
#include <QTimer>
@@ -58,6 +60,15 @@ namespace BlackSimPlugin
connect(m_slowTimer, &QTimer::timeout, this, &CSimulatorXPlane::ps_slowTimerTimeout);
m_fastTimer->start(100);
m_slowTimer->start(1000);
m_modelMatcher.setModelMappingProvider(BlackMisc::make_unique<CModelMappingsProviderDummy>());
m_modelMatcher.setDefaultModel(CAircraftModel(
"__A319/A319_CFM.obj __A319/DAL.png",
CAircraftModel::TypeModelMatchingDefaultModel,
"A319 CFM DAL",
CAircraftIcaoData(CAircraftIcaoCode("A319", "L2J"), CAirlineIcaoCode(), "FFFFFF")
));
resetData();
}
@@ -166,6 +177,9 @@ namespace BlackSimPlugin
CAircraftModel aircraftModel { *modelStringsIt, CAircraftModel::TypeModelMapping, QString(), icaoData };
m_installedModels.push_back(aircraftModel);
}
m_modelMatcher.setInstalledModels(m_installedModels);
m_modelMatcher.init();
}
bool CSimulatorXPlane::isConnected() const
@@ -357,13 +371,26 @@ namespace BlackSimPlugin
Q_ASSERT(isConnected());
//! \todo XPlane driver check if already exists, how?
//! \todo XPlane driver set correct return value
// KB: from what I can see here all data are available
// Is there any model matching required ????
// matched models
CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(newRemoteAircraft);
Q_ASSERT_X(newRemoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns");
CCallsign callsign(newRemoteAircraft.getCallsign());
this->updateAircraftModel(callsign, aircraftModel, identifier());
CSimulatedAircraft aircraftAfterModelApplied(getAircraftInRangeForCallsign(newRemoteAircraft.getCallsign()));
CAircraftIcaoData icao = newRemoteAircraft.getIcaoInfo();
m_traffic->addPlane(newRemoteAircraft.getCallsign().asString(), icao.getAircraftDesignator(), icao.getAirlineDesignator(), icao.getLivery());
m_traffic->addPlane(newRemoteAircraft.getCallsign().asString(), aircraftModel.getModelString(), icao.getAircraftDesignator(), icao.getAirlineDesignator(), icao.getLivery());
updateAircraftRendered(newRemoteAircraft.getCallsign(), true, identifier());
CLogMessage(this).info("XP: Added aircraft %1") << newRemoteAircraft.getCallsign().toQString();
return true;
bool rendered = true;
aircraftAfterModelApplied.setRendered(rendered);
this->updateAircraftRendered(callsign, rendered, identifier());
emit modelMatchingCompleted(aircraftAfterModelApplied);
return rendered;
}
void CSimulatorXPlane::ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation)
@@ -419,6 +446,10 @@ namespace BlackSimPlugin
bool CSimulatorXPlane::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
{
if (originator == this->identifier()) { return false; }
// remove upfront, and then enable / disable again
this->physicallyRemoveRemoteAircraft(aircraft.getCallsign());
return this->changeRemoteAircraftEnabled(aircraft, originator);
}

View File

@@ -13,6 +13,7 @@
#define BLACKSIMPLUGIN_SIMULATOR_XPLANE_H
#include "blackcore/simulator_common.h"
#include "blackmisc/simulation/aircraftmatcher.h"
#include "blackmisc/simulation/ownaircraftprovider.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/pixmap.h"
@@ -141,6 +142,7 @@ namespace BlackSimPlugin
QTimer *m_slowTimer { nullptr };
BlackMisc::Aviation::CAirportList m_airportsInRange; //!< aiports in range of own aircraft
BlackMisc::Simulation::CAircraftModelList m_installedModels;
BlackMisc::Simulation::CAircraftMatcher m_modelMatcher { BlackMisc::Simulation::CAircraftMatcher::AllModes, this }; //!< Model matcher
//! \todo Add units to members? pitchDeg?, altitudeFt?
struct // data is written by DBus async method callbacks

View File

@@ -69,9 +69,9 @@ namespace BlackSimPlugin
m_dbusInterface->callDBus(QLatin1String("updateInstalledModels"));
}
void CXBusTrafficProxy::addPlane(const QString &callsign, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
void CXBusTrafficProxy::addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
{
m_dbusInterface->callDBus(QLatin1String("addPlane"), callsign, aircraftIcao, airlineIcao, livery);
m_dbusInterface->callDBus(QLatin1String("addPlane"), callsign, modelName, aircraftIcao, airlineIcao, livery);
}
void CXBusTrafficProxy::removePlane(const QString &callsign)

View File

@@ -80,7 +80,7 @@ namespace BlackSimPlugin
void updateInstalledModels() const;
//! \copydoc XBus::CTraffic::addPlane
void addPlane(const QString &callsign, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery);
void addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery);
//! \copydoc XBus::CTraffic::removePlane
void removePlane(const QString &callsign);