mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
refactor: Remove airport view
This commit is contained in:
@@ -32,8 +32,6 @@ add_library(xswiftbus SHARED
|
||||
menus.h
|
||||
messages.cpp
|
||||
messages.h
|
||||
navdatareference.cpp
|
||||
navdatareference.h
|
||||
plugin.cpp
|
||||
plugin.h
|
||||
service.cpp
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \cond PRIVATE
|
||||
|
||||
#include "navdatareference.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
inline double degreeToRadian(double angle)
|
||||
{
|
||||
static const double PI = acos(-1);
|
||||
return PI * angle / 180.0;
|
||||
}
|
||||
|
||||
double calculateGreatCircleDistance(const CNavDataReference &a, const CNavDataReference &b)
|
||||
{
|
||||
const static double c_earthRadiusKm = 6372.8;
|
||||
|
||||
const double latRad1 = degreeToRadian(a.latitude());
|
||||
const double latRad2 = degreeToRadian(b.latitude());
|
||||
const double lonRad1 = degreeToRadian(a.longitude());
|
||||
const double lonRad2 = degreeToRadian(b.longitude());
|
||||
|
||||
const double diffLa = latRad2 - latRad1;
|
||||
const double doffLo = lonRad2 - lonRad1;
|
||||
|
||||
const double computation = asin(
|
||||
sqrt(sin(diffLa / 2) * sin(diffLa / 2) + cos(latRad1) * cos(latRad2) * sin(doffLo / 2) * sin(doffLo / 2)));
|
||||
return 2 * c_earthRadiusKm * computation;
|
||||
}
|
||||
} // namespace XSwiftBus
|
||||
|
||||
//! \endcond
|
||||
@@ -1,43 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef SWIFT_SIM_XSWIFTBUS_NAVDATAREFERENCE_H
|
||||
#define SWIFT_SIM_XSWIFTBUS_NAVDATAREFERENCE_H
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
//! Simplified version of CNavDataReference of \sa swift::misc::simulation::XPlane::CNavDataReference
|
||||
class CNavDataReference
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
CNavDataReference() = default;
|
||||
|
||||
//! Constructor
|
||||
CNavDataReference(int id, double latitudeDegrees, double longitudeDegrees)
|
||||
: m_id(id), m_latitudeDegrees(latitudeDegrees), m_longitudeDegrees(longitudeDegrees)
|
||||
{}
|
||||
|
||||
//! \copydoc swift::misc::simulation::xplane::CNavDataReference::id
|
||||
int id() const { return m_id; }
|
||||
|
||||
//! \copydoc swift::misc::simulation::xplane::CNavDataReference::latitude
|
||||
double latitude() const { return m_latitudeDegrees; }
|
||||
|
||||
//! \copydoc swift::misc::simulation::xplane::CNavDataReference::longitude
|
||||
double longitude() const { return m_longitudeDegrees; }
|
||||
|
||||
private:
|
||||
int m_id = 0;
|
||||
double m_latitudeDegrees = 0.0;
|
||||
double m_longitudeDegrees = 0.0;
|
||||
};
|
||||
|
||||
//! Free function to calculate great circle distance
|
||||
double calculateGreatCircleDistance(const CNavDataReference &a, const CNavDataReference &b);
|
||||
|
||||
} // namespace XSwiftBus
|
||||
|
||||
#endif // SWIFT_SIM_XSWIFTBUS_NAVDATAREFERENCE_H
|
||||
@@ -150,11 +150,7 @@ namespace XSwiftBus
|
||||
|
||||
void CPlugin::onAircraftRepositioned()
|
||||
{
|
||||
if (m_service)
|
||||
{
|
||||
m_service->updateAirportsInRange();
|
||||
m_service->resetFrameTotals();
|
||||
}
|
||||
if (m_service) { m_service->resetFrameTotals(); }
|
||||
}
|
||||
|
||||
void CPlugin::onSceneryLoaded()
|
||||
|
||||
@@ -91,7 +91,6 @@ namespace XSwiftBus
|
||||
CService::CService(CSettingsProvider *settingsProvider)
|
||||
: CDBusObject(settingsProvider), m_framePeriodSampler(std::make_unique<FramePeriodSampler>())
|
||||
{
|
||||
this->updateAirportsInRange();
|
||||
this->updateMessageBoxFromSettings();
|
||||
m_framePeriodSampler->show();
|
||||
}
|
||||
@@ -259,42 +258,6 @@ namespace XSwiftBus
|
||||
if (w) { INFO_LOG("Written new config file"); }
|
||||
}
|
||||
|
||||
void CService::readAirportsDatabase()
|
||||
{
|
||||
auto first = XPLMFindFirstNavAidOfType(xplm_Nav_Airport);
|
||||
auto last = XPLMFindLastNavAidOfType(xplm_Nav_Airport);
|
||||
if (first != XPLM_NAV_NOT_FOUND)
|
||||
{
|
||||
for (auto i = first; i <= last; ++i)
|
||||
{
|
||||
float lat, lon;
|
||||
char icao[32];
|
||||
XPLMGetNavAidInfo(i, nullptr, &lat, &lon, nullptr, nullptr, nullptr, icao, nullptr, nullptr);
|
||||
if (icao[0] != 0) { m_airports.emplace_back(i, lat, lon); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CService::updateAirportsInRange()
|
||||
{
|
||||
if (m_airports.empty()) { readAirportsDatabase(); }
|
||||
std::vector<std::string> icaos, names;
|
||||
std::vector<double> lats, lons, alts;
|
||||
std::vector<CNavDataReference> closestAirports = findClosestAirports(20, getLatitudeDeg(), getLongitudeDeg());
|
||||
for (const auto &navref : closestAirports)
|
||||
{
|
||||
float lat, lon, alt;
|
||||
char icao[32], name[256];
|
||||
XPLMGetNavAidInfo(navref.id(), nullptr, &lat, &lon, &alt, nullptr, nullptr, icao, name, nullptr);
|
||||
icaos.emplace_back(icao);
|
||||
names.emplace_back(name);
|
||||
lats.push_back(lat);
|
||||
lons.push_back(lon);
|
||||
alts.push_back(alt);
|
||||
}
|
||||
emitAirportsInRangeUpdated(icaos, names, lats, lons, alts);
|
||||
}
|
||||
|
||||
static const char *introspection_service = DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
|
||||
#include "org.swift_project.xswiftbus.service.xml"
|
||||
;
|
||||
@@ -475,11 +438,6 @@ namespace XSwiftBus
|
||||
sendDBusMessage(reply);
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "updateAirportsInRange")
|
||||
{
|
||||
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
||||
queueDBusCall([=]() { updateAirportsInRange(); });
|
||||
}
|
||||
else if (message.getMethodName() == "getAircraftModelPath")
|
||||
{
|
||||
queueDBusCall([=]() { sendDBusReply(sender, serial, getAircraftModelPath()); });
|
||||
@@ -836,21 +794,6 @@ namespace XSwiftBus
|
||||
sendDBusMessage(signalAircraftModelChanged);
|
||||
}
|
||||
|
||||
void CService::emitAirportsInRangeUpdated(const std::vector<std::string> &icaoCodes,
|
||||
const std::vector<std::string> &names, const std::vector<double> &lats,
|
||||
const std::vector<double> &lons, const std::vector<double> &alts)
|
||||
{
|
||||
CDBusMessage signalAirportsInRangeUpdated = CDBusMessage::createSignal(
|
||||
XSWIFTBUS_SERVICE_OBJECTPATH, XSWIFTBUS_SERVICE_INTERFACENAME, "airportsInRangeUpdated");
|
||||
signalAirportsInRangeUpdated.beginArgumentWrite();
|
||||
signalAirportsInRangeUpdated.appendArgument(icaoCodes);
|
||||
signalAirportsInRangeUpdated.appendArgument(names);
|
||||
signalAirportsInRangeUpdated.appendArgument(lats);
|
||||
signalAirportsInRangeUpdated.appendArgument(lons);
|
||||
signalAirportsInRangeUpdated.appendArgument(alts);
|
||||
sendDBusMessage(signalAirportsInRangeUpdated);
|
||||
}
|
||||
|
||||
void CService::emitSceneryLoaded()
|
||||
{
|
||||
CDBusMessage signal =
|
||||
@@ -858,22 +801,6 @@ namespace XSwiftBus
|
||||
sendDBusMessage(signal);
|
||||
}
|
||||
|
||||
std::vector<CNavDataReference> CService::findClosestAirports(int number, double latitude, double longitude)
|
||||
{
|
||||
CNavDataReference ref(0, latitude, longitude);
|
||||
auto compareFunction = [&](const CNavDataReference &a, const CNavDataReference &b) {
|
||||
return calculateGreatCircleDistance(a, ref) < calculateGreatCircleDistance(b, ref);
|
||||
};
|
||||
|
||||
number = std::min(static_cast<int>(m_airports.size()), number);
|
||||
|
||||
std::vector<CNavDataReference> closestAirports = m_airports;
|
||||
std::partial_sort(closestAirports.begin(), closestAirports.begin() + number, closestAirports.end(),
|
||||
compareFunction);
|
||||
closestAirports.resize(static_cast<std::vector<CNavDataReference>::size_type>(number));
|
||||
return closestAirports;
|
||||
}
|
||||
|
||||
void CService::updateMessageBoxFromSettings()
|
||||
{
|
||||
// left, top, right, bottom, height size percentage
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "dbusobject.h"
|
||||
#include "datarefs.h"
|
||||
#include "messages.h"
|
||||
#include "navdatareference.h"
|
||||
#include "terrainprobe.h"
|
||||
#include <XPLM/XPLMNavigation.h>
|
||||
#include <string>
|
||||
@@ -70,9 +69,6 @@ namespace XSwiftBus
|
||||
//! Add a text message to the on-screen display, with RGB components in the range [0,1]
|
||||
void addTextMessage(const std::string &text, double red, double green, double blue);
|
||||
|
||||
//! Called by newly connected client to cause airportsInRangeUpdated to be emitted.
|
||||
void updateAirportsInRange();
|
||||
|
||||
//! Get full path to current aircraft model
|
||||
std::string getAircraftModelPath() const;
|
||||
|
||||
@@ -335,10 +331,6 @@ namespace XSwiftBus
|
||||
const std::string &icao, const std::string &modelString, const std::string &name,
|
||||
const std::string &description);
|
||||
|
||||
void emitAirportsInRangeUpdated(const std::vector<std::string> &icaoCodes,
|
||||
const std::vector<std::string> &names, const std::vector<double> &lats,
|
||||
const std::vector<double> &lons, const std::vector<double> &alts);
|
||||
|
||||
void emitSceneryLoaded();
|
||||
|
||||
CMessageBoxControl m_messages { 16, 16, 16 };
|
||||
@@ -346,12 +338,8 @@ namespace XSwiftBus
|
||||
bool m_disappearMessageWindow = true;
|
||||
int m_disapperMessageWindowTimeMs = 5000;
|
||||
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
|
||||
std::vector<CNavDataReference> m_airports;
|
||||
CTerrainProbe m_terrainProbe;
|
||||
|
||||
void readAirportsDatabase();
|
||||
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);
|
||||
|
||||
//! Redraw message box after reading from the settings
|
||||
void updateMessageBoxFromSettings();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user