mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #811, airports default implementation
* if no sim data are available use reader data * merge airport data for FSX * Added "network" in .pro (needed for network classes such as readers)
This commit is contained in:
@@ -114,7 +114,7 @@ namespace BlackCore
|
||||
//! Display a text message
|
||||
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const = 0;
|
||||
|
||||
//! Airports in range from simulator
|
||||
//! Airports in range from simulator, or if not available from web service
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const = 0;
|
||||
|
||||
//! Set time synchronization between simulator and user's computer time
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <functional>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
@@ -62,8 +63,8 @@ namespace BlackCore
|
||||
);
|
||||
|
||||
// timer
|
||||
this->m_oneSecondTimer.setObjectName(this->objectName().append(":m_oneSecondTimer"));
|
||||
connect(&m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
|
||||
this->m_oneSecondTimer.setObjectName(this->objectName().append(":m_oneSecondTimer"));
|
||||
this->m_oneSecondTimer.start(1000);
|
||||
|
||||
// swift data
|
||||
@@ -76,14 +77,14 @@ namespace BlackCore
|
||||
CLogMessage(this).info("Initialized simulator driver %1") << m_simulatorPluginInfo.toQString();
|
||||
}
|
||||
|
||||
CSimulatorCommon::~CSimulatorCommon() { }
|
||||
|
||||
const CLogCategoryList &CSimulatorCommon::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats( { CLogCategory::driver(), CLogCategory::plugin() });
|
||||
static const CLogCategoryList cats({ CLogCategory::driver(), CLogCategory::plugin() });
|
||||
return cats;
|
||||
}
|
||||
|
||||
CSimulatorCommon::~CSimulatorCommon() { }
|
||||
|
||||
bool CSimulatorCommon::logicallyAddRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
{
|
||||
Q_ASSERT_X(remoteAircraft.hasModelString(), Q_FUNC_INFO, "Missing model string");
|
||||
@@ -106,6 +107,12 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
int CSimulatorCommon::maxAirportsInRange() const
|
||||
{
|
||||
// might change in future or become a setting or such
|
||||
return 20;
|
||||
}
|
||||
|
||||
void CSimulatorCommon::blinkHighlightedAircraft()
|
||||
{
|
||||
if (m_highlightedAircraft.isEmpty() || m_highlightEndTimeMsEpoch < 1) { return; }
|
||||
@@ -216,6 +223,17 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
CAirportList CSimulatorCommon::getAirportsInRange() const
|
||||
{
|
||||
// default implementation
|
||||
if (!sApp->hasWebDataServices()) { return CAirportList(); }
|
||||
|
||||
const CAirportList airports = sApp->getWebDataServices()->getAirports();
|
||||
if (airports.isEmpty()) { return airports; }
|
||||
const CCoordinateGeodetic ownPosition = this->getOwnAircraftPosition();
|
||||
return airports.findClosest(maxAirportsInRange(), ownPosition);
|
||||
}
|
||||
|
||||
CAircraftModel CSimulatorCommon::reverseLookupModel(const CAircraftModel &model)
|
||||
{
|
||||
bool modified = false;
|
||||
@@ -373,4 +391,15 @@ namespace BlackCore
|
||||
m_aircraftToAddAgainWhenRemoved.clear();
|
||||
}
|
||||
|
||||
CAirportList CSimulatorCommon::getWebServiceAirports() const
|
||||
{
|
||||
if (!sApp->hasWebDataServices()) { return CAirportList(); }
|
||||
return sApp->getWebDataServices()->getAirports();
|
||||
}
|
||||
|
||||
CAirport CSimulatorCommon::getWebServiceAirport(const CAirportIcaoCode &icao) const
|
||||
{
|
||||
if (!sApp->hasWebDataServices()) { return CAirport(); }
|
||||
return sApp->getWebDataServices()->getAirports().findFirstByIcao(icao);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace BlackCore
|
||||
virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override;
|
||||
virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const override;
|
||||
virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const override;
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
virtual void unload() override;
|
||||
virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override;
|
||||
//! @}
|
||||
@@ -100,6 +101,9 @@ namespace BlackCore
|
||||
virtual void ps_remoteProviderRemovedAircraft(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
//! @}
|
||||
|
||||
//! All swift data read from DB
|
||||
virtual void ps_allSwiftDataRead();
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CSimulatorCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
@@ -108,11 +112,14 @@ namespace BlackCore
|
||||
BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider,
|
||||
QObject *parent);
|
||||
|
||||
//! \copydoc ISimulator::logicallyAddRemoteAircraft
|
||||
//! \name Interface implementations
|
||||
//! @{
|
||||
virtual bool logicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
|
||||
|
||||
//! \copydoc ISimulator::logicallyRemoveRemoteAircraft
|
||||
virtual bool logicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
//! @}
|
||||
|
||||
//! Max.airports in range
|
||||
int maxAirportsInRange() const;
|
||||
|
||||
//! Reset state
|
||||
virtual void reset();
|
||||
@@ -120,6 +127,12 @@ namespace BlackCore
|
||||
//! Clear all aircraft related data
|
||||
virtual void clearAllAircraft();
|
||||
|
||||
//! Airports from web services
|
||||
BlackMisc::Aviation::CAirportList getWebServiceAirports() const;
|
||||
|
||||
//! Airport from web services by ICAO code
|
||||
BlackMisc::Aviation::CAirport getWebServiceAirport(const BlackMisc::Aviation::CAirportIcaoCode &icao) const;
|
||||
|
||||
//! Blink the highlighted aircraft
|
||||
void blinkHighlightedAircraft();
|
||||
|
||||
@@ -150,10 +163,6 @@ namespace BlackCore
|
||||
//! Lookup against DB data
|
||||
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model);
|
||||
|
||||
private slots:
|
||||
//! All swift data read from DB
|
||||
void ps_allSwiftDataRead();
|
||||
|
||||
private:
|
||||
bool m_blinkCycle = false; //!< use for highlighting
|
||||
qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
load(common_pre)
|
||||
|
||||
QT += core dbus concurrent xml
|
||||
QT += core dbus concurrent xml network
|
||||
|
||||
TARGET = simulatorfscommon
|
||||
TEMPLATE = lib
|
||||
|
||||
@@ -8,17 +8,18 @@
|
||||
*/
|
||||
|
||||
#include "simulatorfscommon.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackCore;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
@@ -80,7 +81,11 @@ namespace BlackSimPlugin
|
||||
|
||||
CAirportList CSimulatorFsCommon::getAirportsInRange() const
|
||||
{
|
||||
return m_airportsInRange;
|
||||
if (!m_airportsInRangeFromSimulator.isEmpty())
|
||||
{
|
||||
return m_airportsInRangeFromSimulator;
|
||||
}
|
||||
return CSimulatorCommon::getAirportsInRange();
|
||||
}
|
||||
|
||||
bool CSimulatorFsCommon::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft)
|
||||
@@ -104,5 +109,15 @@ namespace BlackSimPlugin
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorFsCommon::ps_allSwiftDataRead()
|
||||
{
|
||||
const CAirportList webServiceAirports = this->getWebServiceAirports();
|
||||
if (!webServiceAirports.isEmpty())
|
||||
{
|
||||
this->m_airportsInRangeFromSimulator.updateMissingParts(webServiceAirports);
|
||||
}
|
||||
CSimulatorCommon::ps_allSwiftDataRead();
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace BlackSimPlugin
|
||||
virtual bool changeRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) override;
|
||||
//! @}
|
||||
|
||||
protected slots:
|
||||
//! \copydoc BlackCore::CSimulatorCommon::ps_allSwiftDataRead
|
||||
virtual void ps_allSwiftDataRead() override;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CSimulatorFsCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
@@ -64,7 +68,7 @@ namespace BlackSimPlugin
|
||||
bool m_simPaused = false; //!< Simulator paused?
|
||||
bool m_simTimeSynced = false; //!< Time synchronized?
|
||||
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset
|
||||
BlackMisc::Aviation::CAirportList m_airportsInRange; //!< airports in range of own aircraft
|
||||
BlackMisc::Aviation::CAirportList m_airportsInRangeFromSimulator; //!< airports in range of own aircraft
|
||||
|
||||
// cockpit as set in SIM
|
||||
BlackMisc::Aviation::CComSystem m_simCom1; //!< cockpit COM1 state in simulator
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace BlackSimPlugin
|
||||
}
|
||||
case SIMCONNECT_RECV_ID_AIRPORT_LIST:
|
||||
{
|
||||
const CLength maxDistance(200.0, CLengthUnit::NM());
|
||||
static const CLength maxDistance(200.0, CLengthUnit::NM());
|
||||
const CCoordinateGeodetic posAircraft(simulatorFsx->getOwnAircraftPosition());
|
||||
SIMCONNECT_RECV_AIRPORT_LIST *pAirportList = (SIMCONNECT_RECV_AIRPORT_LIST *) pData;
|
||||
for (unsigned i = 0; i < pAirportList->dwArraySize; ++i)
|
||||
@@ -224,11 +224,14 @@ namespace BlackSimPlugin
|
||||
CAirport airport(CAirportIcaoCode(icao), pos);
|
||||
const CLength d = airport.calculcateAndUpdateRelativeDistanceAndBearing(posAircraft);
|
||||
if (d > maxDistance) { continue; }
|
||||
simulatorFsx->m_airportsInRange.replaceOrAddByIcao(airport);
|
||||
airport.updateMissingParts(simulatorFsx->getWebServiceAirport(icao));
|
||||
simulatorFsx->m_airportsInRangeFromSimulator.replaceOrAddByIcao(airport);
|
||||
}
|
||||
if (simulatorFsx->m_airportsInRange.size() > 20)
|
||||
|
||||
if (simulatorFsx->m_airportsInRangeFromSimulator.size() > simulatorFsx->maxAirportsInRange())
|
||||
{
|
||||
simulatorFsx->m_airportsInRange.removeIfOutsideRange(posAircraft, maxDistance, true);
|
||||
simulatorFsx->m_airportsInRangeFromSimulator.sortByDistanceToOwnAircraft();
|
||||
simulatorFsx->m_airportsInRangeFromSimulator.truncate(simulatorFsx->maxAirportsInRange());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -351,6 +351,7 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorXPlane::ps_setAirportsInRange(const QStringList &icaos, const QStringList &names, const BlackMisc::CSequence<double> &lats, const BlackMisc::CSequence<double> &lons, const BlackMisc::CSequence<double> &alts)
|
||||
{
|
||||
//! \todo restrict to maxAirportsInRange()
|
||||
m_airportsInRange.clear();
|
||||
auto icaoIt = icaos.begin();
|
||||
auto nameIt = names.begin();
|
||||
|
||||
Reference in New Issue
Block a user