swift
fgswiftbustrafficproxy.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 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_FLIGHTGEAR_TRAFFIC_PROXY_H
7 #define SWIFT_SIMPLUGIN_FLIGHTGEAR_TRAFFIC_PROXY_H
8 
9 #include <QObject>
10 #include <QString>
11 #include <QStringList>
12 
15 #include "misc/aviation/callsign.h"
18 
19 // clazy:excludeall=const-signal-or-slot
20 
21 class QDBusConnection;
22 
24 #define FGSWIFTBUS_TRAFFIC_INTERFACENAME "org.swift_project.fgswiftbus.traffic"
25 #define FGSWIFTBUS_TRAFFIC_OBJECTPATH "/fgswiftbus/traffic"
27 
28 namespace swift::simplugin::flightgear
29 {
31  using QDoubleList = QList<double>;
32 
35  {
37  bool isEmpty() const { return callsigns.isEmpty(); }
38 
40  bool hasSameSizes() const
41  {
42  const int s = callsigns.size();
43  if (s != latitudesDeg.size()) { return false; }
44  if (s != longitudesDeg.size()) { return false; }
45  if (s != altitudesFt.size()) { return false; }
46  if (s != pitchesDeg.size()) { return false; }
47  if (s != rollsDeg.size()) { return false; }
48  if (s != headingsDeg.size()) { return false; }
49  return true;
50  }
51 
54  {
55  this->callsigns.push_back(situation.getCallsign().asString());
56  this->latitudesDeg.push_back(
58  this->longitudesDeg.push_back(
60  this->altitudesFt.push_back(
64  this->headingsDeg.push_back(
66  this->onGrounds.push_back(situation.isOnGround());
67  this->groundSpeedKts.push_back(
69  }
70 
71  QStringList callsigns;
72  QList<double> latitudesDeg;
73  QList<double> longitudesDeg;
74  QList<double> altitudesFt;
75  QList<double> pitchesDeg;
76  QList<double> rollsDeg;
77  QList<double> headingsDeg;
78  QList<double> groundSpeedKts;
79  QList<bool> onGrounds;
80  };
81 
84  {
86  bool isEmpty() const { return callsigns.isEmpty(); }
87 
91  {
92  this->callsigns.push_back(callsign.asString());
93  this->gears.push_back(parts.isFixedGearDown() ? 1 : 0);
94  this->flaps.push_back(parts.getFlapsPercent() / 100.0);
95  this->spoilers.push_back(parts.isSpoilersOut() ? 1 : 0);
96  this->speedBrakes.push_back(parts.isSpoilersOut() ? 1 : 0);
97  this->slats.push_back(parts.getFlapsPercent() / 100.0);
98  this->wingSweeps.push_back(0.0);
99  this->thrusts.push_back(parts.isAnyEngineOn() ? 0 : 0.75);
100  this->elevators.push_back(0.0);
101  this->rudders.push_back(0.0);
102  this->ailerons.push_back(0.0);
103  this->landLights.push_back(parts.getLights().isLandingOn());
104  this->beaconLights.push_back(parts.getLights().isBeaconOn());
105  this->strobeLights.push_back(parts.getLights().isStrobeOn());
106  this->navLights.push_back(parts.getLights().isNavOn());
107  this->lightPatterns.push_back(0);
108  this->taxiLights.push_back(parts.getLights().isTaxiOn());
109  }
110 
111  QStringList callsigns;
112  QList<double> gears;
113  QList<double> flaps;
114  QList<double> spoilers;
115  QList<double> speedBrakes;
116  QList<double> slats;
117  QList<double> wingSweeps;
118  QList<double> thrusts;
119  QList<double> elevators;
120  QList<double> rudders;
121  QList<double> ailerons;
122  QList<bool> landLights;
123  QList<bool> beaconLights;
124  QList<bool> strobeLights;
125  QList<bool> navLights;
126  QList<int> lightPatterns;
127  QList<bool> taxiLights;
128  };
129 
132  {
134  bool isEmpty() const { return callsigns.isEmpty(); }
135 
136  QStringList callsigns;
137  QList<int> codes;
138  QList<bool> modeCs;
139  QList<bool> idents;
140  };
141 
144  {
145  bool hasAcquired;
146  QString owner;
147  };
148 
152  class CFGSwiftBusTrafficProxy : public QObject
153  {
154  Q_OBJECT
155 
156  public:
159  std::function<void(const swift::misc::geo::CElevationPlane &, const swift::misc::aviation::CCallsign &)>;
160 
162  using RemoteAircraftDataCallback = std::function<void(
163  const QStringList &, const QDoubleList &, const QDoubleList &, const QDoubleList &, const QDoubleList &)>;
164 
166  static const QString &InterfaceName()
167  {
168  static QString s(FGSWIFTBUS_TRAFFIC_INTERFACENAME);
169  return s;
170  }
171 
173  static const QString &ObjectPath()
174  {
175  static QString s(FGSWIFTBUS_TRAFFIC_OBJECTPATH);
176  return s;
177  }
178 
180  CFGSwiftBusTrafficProxy(QDBusConnection &connection, QObject *parent = nullptr, bool dummy = false);
181 
183  bool isValid() const { return m_dbusInterface->isValid(); }
184 
185  signals:
188  void simFrame();
189 
191  void remoteAircraftAdded(const QString &callsign);
192 
194  void remoteAircraftAddingFailed(const QString &callsign);
195 
196  public slots:
200 
202  bool initialize();
203 
205  void cleanup();
206 
208  void addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao,
209  const QString &airlineIcao, const QString &livery);
210 
212  void removePlane(const QString &callsign);
213 
215  void removeAllPlanes();
216 
219 
222 
225 
227  void getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const;
228 
230  void getElevationAtPosition(const swift::misc::aviation::CCallsign &callsign, double latitudeDeg,
231  double longitudeDeg, double altitudeMeters, const ElevationCallback &setter) const;
232 
233  private:
234  swift::misc::CGenericDBusInterface *m_dbusInterface = nullptr;
235  };
236 } // namespace swift::simplugin::flightgear
237 
238 #endif // SWIFT_SIMPLUGIN_FLIGHTGEAR_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 physical_quantities::CSpeed & getGroundSpeed() const
Get ground speed.
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.
static CSpeedUnit kts()
Knots.
Definition: units.h:833
Proxy object connected to a real FGSwiftBus::CTraffic object via DBus.
void remoteAircraftAdded(const QString &callsign)
Remote aircraft successfully added.
void setPlanesTransponders(const swift::simplugin::flightgear::PlanesTransponders &planesTransponders)
Set the transponders of multiple traffic aircrafts.
void setPlanesSurfaces(const swift::simplugin::flightgear::PlanesSurfaces &planesSurfaces)
Set the surfaces of multiple traffic aircrafts.
void cleanup()
Reverse the actions of initialize().
std::function< void(const QStringList &, const QDoubleList &, const QDoubleList &, const QDoubleList &, const QDoubleList &)> RemoteAircraftDataCallback
Remote aircrafts data callback.
void remoteAircraftAddingFailed(const QString &callsign)
Remote aircraft adding failed.
void addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
Introduce a new traffic aircraft.
bool initialize()
Initialize the multiplayer planes rendering and return true if successful.
bool isValid() const
Does the remote object exist?
MultiplayerAcquireInfo acquireMultiplayerPlanes()
Returns whether multiplayer planes have been acquired. If not, owner will be set to the plugin that a...
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.
std::function< void(const swift::misc::geo::CElevationPlane &, const swift::misc::aviation::CCallsign &)> ElevationCallback
Elevation callback.
void getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const
Get remote aircrafts data (lat, lon, elevation and CG)
void removePlane(const QString &callsign)
Remove a traffic aircraft.
CFGSwiftBusTrafficProxy(QDBusConnection &connection, QObject *parent=nullptr, bool dummy=false)
Constructor.
void setPlanesPositions(const swift::simplugin::flightgear::PlanesPositions &planesPositions)
Set the position of multiple traffic aircrafts.
QList< double > QDoubleList
List of doubles.
QString owner
Name of the plugin having multiplayer planes acquired.
bool hasAcquired
Has FGSwiftBus acquired multiplayer planes?
QList< double > altitudesFt
List of altitudes.
QList< double > latitudesDeg
List of latitudes.
void push_back(const swift::misc::aviation::CAircraftSituation &situation)
Push back the latest situation.
QList< double > longitudesDeg
List of longitudes.
QList< double > groundSpeedKts
List of groundspeeds.
QList< bool > strobeLights
List of strobeLights.
QList< double > wingSweeps
List of wingSweeps.
QList< bool > taxiLights
List of taxi lights.
QList< int > lightPatterns
List of lightPatterns.
QList< double > speedBrakes
List of speedBrakes.
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 beaconLights.
QList< int > codes
List of transponder codes.
QList< bool > modeCs
List of active mode C's.