swift
xswiftbustrafficproxy.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_SIMPLUGIN_XSWIFTBUS_TRAFFIC_PROXY_H
7 #define SWIFT_SIMPLUGIN_XSWIFTBUS_TRAFFIC_PROXY_H
8 
9 #include <QObject>
10 #include <QString>
11 #include <QStringList>
12 
15 #include "misc/aviation/callsign.h"
18 #include "misc/logcategories.h"
19 
20 // clazy:excludeall=const-signal-or-slot
21 
22 class QDBusConnection;
23 
25 #define XSWIFTBUS_TRAFFIC_INTERFACENAME "org.swift_project.xswiftbus.traffic"
26 #define XSWIFTBUS_TRAFFIC_OBJECTPATH "/xswiftbus/traffic"
28 
29 namespace swift::simplugin::xplane
30 {
32  using QDoubleList = QList<double>;
33 
35  using QBoolList = QList<bool>;
36 
39  {
41  bool isEmpty() const { return callsigns.isEmpty(); }
42 
44  bool hasSameSizes() const
45  {
46  const int s = callsigns.size();
47  if (s != latitudesDeg.size()) { return false; }
48  if (s != longitudesDeg.size()) { return false; }
49  if (s != altitudesFt.size()) { return false; }
50  if (s != pitchesDeg.size()) { return false; }
51  if (s != rollsDeg.size()) { return false; }
52  if (s != headingsDeg.size()) { return false; }
53  return true;
54  }
55 
58  {
59  this->callsigns.push_back(situation.getCallsign().asString());
60  this->latitudesDeg.push_back(
62  this->longitudesDeg.push_back(
64  this->altitudesFt.push_back(
68  this->headingsDeg.push_back(
70  this->onGrounds.push_back(situation.isOnGround());
71  }
72 
73  QStringList callsigns;
74  QList<double> latitudesDeg;
75  QList<double> longitudesDeg;
76  QList<double> altitudesFt;
77  QList<double> pitchesDeg;
78  QList<double> rollsDeg;
79  QList<double> headingsDeg;
80  QList<bool> onGrounds;
81  };
82 
85  {
87  bool isEmpty() const { return callsigns.isEmpty(); }
88 
92  {
93  this->callsigns.push_back(callsign.asString());
94  this->gears.push_back(parts.isFixedGearDown() ? 1 : 0);
95  this->flaps.push_back(parts.getFlapsPercent() / 100.0);
96  this->spoilers.push_back(parts.isSpoilersOut() ? 1 : 0);
97  this->speedBrakes.push_back(parts.isSpoilersOut() ? 1 : 0);
98  this->slats.push_back(parts.getFlapsPercent() / 100.0);
99  this->wingSweeps.push_back(0.0);
100  this->thrusts.push_back(parts.isAnyEngineOn() ? 0.75 : 0);
101  this->elevators.push_back(0.0);
102  this->rudders.push_back(0.0);
103  this->ailerons.push_back(0.0);
104  this->landLights.push_back(parts.getLights().isLandingOn());
105  this->taxiLights.push_back(parts.getLights().isTaxiOn());
106  this->beaconLights.push_back(parts.getLights().isBeaconOn());
107  this->strobeLights.push_back(parts.getLights().isStrobeOn());
108  this->navLights.push_back(parts.getLights().isNavOn());
109  this->lightPatterns.push_back(0);
110  }
111 
112  QStringList callsigns;
113  QList<double> gears;
114  QList<double> flaps;
115  QList<double> spoilers;
116  QList<double> speedBrakes;
117  QList<double> slats;
118  QList<double> wingSweeps;
119  QList<double> thrusts;
120  QList<double> elevators;
121  QList<double> rudders;
122  QList<double> ailerons;
123  QList<bool> landLights;
124  QList<bool> taxiLights;
125  QList<bool> beaconLights;
126  QList<bool> strobeLights;
127  QList<bool> navLights;
128  QList<int> lightPatterns;
129  };
130 
133  {
135  bool isEmpty() const { return callsigns.isEmpty(); }
136 
137  QStringList callsigns;
138  QList<int> codes;
139  QList<bool> modeCs;
140  QList<bool> idents;
141  };
142 
145  {
146  bool hasAcquired;
147  QString owner;
148  };
149 
153  class CXSwiftBusTrafficProxy : public QObject
154  {
155  Q_OBJECT
156 
157  public:
159  using ElevationCallback = std::function<void(const swift::misc::geo::CElevationPlane &,
160  const swift::misc::aviation::CCallsign &, bool)>;
161 
164  std::function<void(const QStringList &, const QDoubleList &, const QDoubleList &, const QDoubleList &,
165  const QBoolList &, const QDoubleList &)>;
166 
168  static const QString &InterfaceName()
169  {
170  static QString s(XSWIFTBUS_TRAFFIC_INTERFACENAME);
171  return s;
172  }
173 
175  static const QString &ObjectPath()
176  {
177  static QString s(XSWIFTBUS_TRAFFIC_OBJECTPATH);
178  return s;
179  }
180 
182  static const QStringList &getLogCategories();
183 
185  CXSwiftBusTrafficProxy(QDBusConnection &connection, QObject *parent = nullptr, bool dummy = false);
186 
188  bool isValid() const { return m_dbusInterface->isValid(); }
189 
190  signals:
193  void simFrame();
194 
196  void remoteAircraftAdded(const QString &callsign);
197 
199  void remoteAircraftAddingFailed(const QString &callsign);
200 
201  public slots:
204 
206  bool initialize();
207 
209  void cleanup();
210 
212  QString loadPlanesPackage(const QString &path);
213 
215  void setDefaultIcao(const QString &defaultIcao);
216 
218  void setMaxPlanes(int planes);
219 
221  void setMaxDrawDistance(double nauticalMiles);
222 
224  void addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao,
225  const QString &airlineIcao, const QString &livery);
226 
228  void removePlane(const QString &callsign);
229 
231  void removeAllPlanes();
232 
235 
238 
241 
243  void setInterpolatorMode(const QString &callsign, bool spline);
244 
246  void getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const;
247 
249  void getElevationAtPosition(const swift::misc::aviation::CCallsign &callsign, double latitudeDeg,
250  double longitudeDeg, double altitudeMeters, const ElevationCallback &setter) const;
251 
253  void setFollowedAircraft(const QString &callsign);
254 
255  private:
256  swift::misc::CGenericDBusInterface *m_dbusInterface = nullptr;
257  };
258 } // namespace swift::simplugin::xplane
259 
260 #endif // SWIFT_SIMPLUGIN_XSWIFTBUS_TRAFFIC_PROXY_H
Used for hand written interface based on virtual methods.
bool isLandingOn() const
Landing lights on?
bool isBeaconOn() const
Beacon lights on?
bool isNavOn() const
Nac lights on?
bool isTaxiOn() const
Taxi lights on?
bool isStrobeOn() const
Strobes lights on?
Value object encapsulating information of aircraft's parts.
Definition: aircraftparts.h:26
CAircraftLights getLights() const
Get aircraft lights.
Definition: aircraftparts.h:72
bool isSpoilersOut() const
Are spoilers out?
bool isFixedGearDown() const
Is fixed gear down?
bool isAnyEngineOn() const
Any engine on?
int getFlapsPercent() const
Get flaps position in percent.
Value object encapsulating information of an aircraft's situation.
const CHeading & getHeading() const
Get heading.
const CCallsign & getCallsign() const
Corresponding callsign.
virtual geo::CLatitude latitude() const
Latitude.
const CAltitude & getAltitude() const
Get altitude.
const physical_quantities::CAngle & getBank() const
Get bank (angle)
const physical_quantities::CAngle & getPitch() const
Get pitch.
virtual geo::CLongitude longitude() const
Longitude.
Value object encapsulating information of a callsign.
Definition: callsign.h:30
const QString & asString() const
Get callsign (normalized)
Definition: callsign.h:96
Plane of same elevation, can be a single point or larger area (e.g. airport)
static CAngleUnit deg()
Degrees.
Definition: units.h:278
static CLengthUnit ft()
Foot ft.
Definition: units.h:159
double value(MU unit) const
Value in given unit.
Proxy object connected to a real XSwiftBus::CTraffic object via DBus.
void cleanup()
Reverse the actions of initialize().
static const QString & ObjectPath()
Service path.
void setMaxPlanes(int planes)
Set the maximum number of aircraft.
void addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
Introduce a new traffic aircraft.
MultiplayerAcquireInfo acquireMultiplayerPlanes()
Returns whether multiplayer planes have been acquired. If not, owner will be set to the plugin that a...
void remoteAircraftAddingFailed(const QString &callsign)
Remote aircraft adding failed.
bool initialize()
Initialize the multiplayer planes rendering and return true if successful.
void setPlanesPositions(const swift::simplugin::xplane::PlanesPositions &planesPositions)
Set the position of multiple traffic aircrafts.
void setFollowedAircraft(const QString &callsign)
Sets the aircraft with callsign to be followed in plane view.
void setMaxDrawDistance(double nauticalMiles)
Set the maximum distance at which to draw aircraft (nautical miles).
void setPlanesSurfaces(const swift::simplugin::xplane::PlanesSurfaces &planesSurfaces)
Set the flight control surfaces and lights of multiple traffic aircrafts.
void getElevationAtPosition(const swift::misc::aviation::CCallsign &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters, const ElevationCallback &setter) const
Get the ground elevation at an arbitrary position.
void setInterpolatorMode(const QString &callsign, bool spline)
QString loadPlanesPackage(const QString &path)
Load a collection of planes from the given directory and return error message if unsuccessful.
static const QString & InterfaceName()
Service name.
CXSwiftBusTrafficProxy(QDBusConnection &connection, QObject *parent=nullptr, bool dummy=false)
Constructor.
void setDefaultIcao(const QString &defaultIcao)
Set the ICAO code to use for aircraft without a model match.
void setPlanesTransponders(const swift::simplugin::xplane::PlanesTransponders &planesTransponders)
Set the transponder of multiple traffic aircraft.
std::function< void(const swift::misc::geo::CElevationPlane &, const swift::misc::aviation::CCallsign &, bool)> ElevationCallback
Elevation callback.
void removePlane(const QString &callsign)
Remove a traffic aircraft.
std::function< void(const QStringList &, const QDoubleList &, const QDoubleList &, const QDoubleList &, const QBoolList &, const QDoubleList &)> RemoteAircraftDataCallback
Remote aircrafts data callback.
bool isValid() const
Does the remote object exist?
void remoteAircraftAdded(const QString &callsign)
Remote aircraft successfully added.
static const QStringList & getLogCategories()
Log. categories.
void getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const
Get remote aircrafts data (lat, lon, elevation and CG)
bool hasAcquired
Has xswiftbus acquired multiplayer planes?
QString owner
Name of the plugin having multiplayer planes acquired.
QList< double > pitchesDeg
List of pitches.
QList< double > altitudesFt
List of altitudes.
QList< double > headingsDeg
List of headings.
QList< bool > onGrounds
List of onGrounds.
void push_back(const swift::misc::aviation::CAircraftSituation &situation)
Push back the latest situation.
QList< double > latitudesDeg
List of latitudes.
QList< double > longitudesDeg
List of longitudes.
void push_back(const swift::misc::aviation::CCallsign &callsign, const swift::misc::aviation::CAircraftParts &parts)
Push back the latest parts.
QList< bool > beaconLights
List of beacon lights.
QList< bool > landLights
List of landing lights.
QList< double > speedBrakes
List of speed brakes.
QList< bool > strobeLights
List of strobe lights.
QList< double > rudders
List of rudders.
QList< double > ailerons
List of ailerons.
QList< bool > navLights
List of nav lights.
QList< double > thrusts
List of thrusts.
QList< double > elevators
List of elevators.
QList< bool > taxiLights
List of taxi lights.
QList< int > lightPatterns
List of light patterns.
QList< double > spoilers
List of spoilers.
QList< double > wingSweeps
List of wing sweeps.
QList< bool > idents
List of active idents.
QList< bool > modeCs
List of active mode C's.
QList< int > codes
List of transponder codes.
QList< bool > QBoolList
List of bools.
QList< double > QDoubleList
List of doubles.