swift
simulatedaircraft.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_SIMULATION_SIMULATEDAIRCRAFT_H
7 #define SWIFT_MISC_SIMULATION_SIMULATEDAIRCRAFT_H
8 
9 #include <array>
10 
11 #include <QMetaType>
12 #include <QString>
13 #include <QVector3D>
14 #include <QtGlobal>
15 
20 #include "misc/aviation/callsign.h"
22 #include "misc/aviation/livery.h"
23 #include "misc/aviation/selcal.h"
26 #include "misc/geo/latitude.h"
27 #include "misc/geo/longitude.h"
28 #include "misc/metaclass.h"
30 #include "misc/network/user.h"
31 #include "misc/pq/frequency.h"
32 #include "misc/pq/length.h"
33 #include "misc/propertyindexref.h"
35 #include "misc/swiftmiscexport.h"
36 #include "misc/valueobject.h"
37 
38 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::simulation, CSimulatedAircraft)
39 
40 namespace swift::misc
41 {
42  namespace aviation
43  {
44  class CAircraftIcaoCode;
45  class CAltitude;
46  class CHeading;
47  } // namespace aviation
48  namespace physical_quantities
49  {
50  class CAngle;
51  class CSpeed;
52  } // namespace physical_quantities
53 
54  namespace simulation
55  {
58  public CValueObject<CSimulatedAircraft>,
60  {
61  public:
64  {
65  IndexCallsign = CPropertyIndexRef::GlobalIndexCSimulatedAircraft,
66  IndexPilot,
67  IndexRelativeDistance,
68  IndexCom1System,
69  IndexCom2System,
70  IndexTransponder,
71  IndexSituation,
72  IndexAircraftIcaoCode,
73  IndexLivery,
74  IndexParts,
75  IndexIsVtol,
76  IndexCombinedIcaoLiveryString,
77  IndexCombinedIcaoLiveryStringNetworkModel,
78  IndexModel,
79  IndexNetworkModel,
80  IndexNetworkModelAircraftIcaoDifference,
81  IndexNetworkModelAirlineIcaoDifference,
82  IndexNetworkModelLiveryDifference,
83  IndexEnabled,
84  IndexRendered,
85  IndexPartsSynchronized,
86  IndexFastPositionUpdates,
87  IndexSupportsGndFlag
88  };
89 
92 
94  explicit CSimulatedAircraft(const CAircraftModel &model);
95 
97  CSimulatedAircraft(const aviation::CCallsign &callsign, const network::CUser &user,
98  const aviation::CAircraftSituation &situation);
99 
101  CSimulatedAircraft(const aviation::CCallsign &callsign, const CAircraftModel &model,
102  const network::CUser &user, const aviation::CAircraftSituation &situation);
103 
105  const aviation::CCallsign &getCallsign() const { return m_callsign; }
106 
108  QString getCallsignAsString() const { return m_callsign.asString(); }
109 
111  const aviation::CAircraftSituation &getSituation() const { return m_situation; }
112 
114  void setSituation(const aviation::CAircraftSituation &situation);
115 
117  const aviation::CAircraftVelocity &getVelocity() const { return m_situation.getVelocity(); }
118 
120  void setVelocity(const aviation::CAircraftVelocity &velocity) { m_situation.setVelocity(velocity); }
121 
123  const network::CUser &getPilot() const { return m_pilot; }
124 
126  QString getPilotRealName() const { return m_pilot.getRealName(); }
127 
129  QString getPilotId() { return m_pilot.getId(); }
130 
132  const aviation::CAircraftIcaoCode &getAircraftIcaoCode() const;
133 
135  const QString &getAircraftIcaoCodeDesignator() const;
136 
138  QString getAirlineAndAircraftIcaoCodeDesignators() const;
139 
141  const QString &getAircraftIcaoCombinedType() const;
142 
144  bool setAircraftIcaoCode(const aviation::CAircraftIcaoCode &aircraftIcaoCode)
145  {
146  return m_models[CurrentModel].setAircraftIcaoCode(aircraftIcaoCode);
147  }
148 
152  bool setIcaoCodes(const aviation::CAircraftIcaoCode &aircraftIcaoCode,
153  const aviation::CAirlineIcaoCode &airlineIcaoCode);
154 
156  const aviation::CLivery &getLivery() const { return m_models[CurrentModel].getLivery(); }
157 
159  const aviation::CAirlineIcaoCode &getAirlineIcaoCode() const;
160 
162  const QString &getAirlineIcaoCodeDesignator() const;
163 
165  void setAircraftIcaoDesignator(const QString &designator);
166 
168  bool hasRealName() const { return m_pilot.hasRealName(); }
169 
171  bool hasId() const { return m_pilot.hasId(); }
172 
174  bool hasAircraftDesignator() const;
175 
177  bool hasAirlineDesignator() const { return m_models[CurrentModel].getLivery().hasValidAirlineDesignator(); }
178 
180  bool hasAircraftAndAirlineDesignator() const;
181 
183  bool hasValidCallsign() const
184  {
185  return aviation::CCallsign::isValidAircraftCallsign(this->getCallsign().asString());
186  }
187 
189  bool hasCallsign() const { return !getCallsign().isEmpty(); }
190 
192  geo::CCoordinateGeodetic getPosition() const { return m_situation.getPosition(); }
193 
195  void setPosition(const geo::CCoordinateGeodetic &position) { m_situation.setPosition(position); }
196 
198  const aviation::CAltitude &getAltitude() const { return m_situation.getAltitude(); }
199 
201  void setAltitude(const aviation::CAltitude &altitude) { m_situation.setAltitude(altitude); }
202 
204  const aviation::CAltitude &getPressureAltitude() const { return m_situation.getPressureAltitude(); }
205 
207  void setPressureAltitude(const aviation::CAltitude &altitude) { m_situation.setPressureAltitude(altitude); }
208 
210  const physical_quantities::CSpeed &getGroundSpeed() const { return m_situation.getGroundSpeed(); }
211 
213  geo::CLatitude latitude() const override { return m_situation.latitude(); }
214 
216  geo::CLongitude longitude() const override { return m_situation.longitude(); }
217 
219  const aviation::CAltitude &geodeticHeight() const override { return m_situation.geodeticHeight(); }
220 
222  QVector3D normalVector() const override { return m_situation.normalVector(); }
223 
225  std::array<double, 3> normalVectorDouble() const override { return m_situation.normalVectorDouble(); }
226 
228  const aviation::CAltitude &getGroundElevation() const { return m_situation.getGroundElevation(); }
229 
233  {
234  m_situation.setGroundElevation(elevation, info);
235  }
236 
240  {
241  m_situation.setGroundElevationChecked(elevation, info);
242  }
243 
245  const aviation::CHeading &getHeading() const { return m_situation.getHeading(); }
246 
248  const physical_quantities::CAngle &getPitch() const { return m_situation.getPitch(); }
249 
251  const physical_quantities::CAngle &getBank() const { return m_situation.getBank(); }
252 
254  const aviation::CComSystem &getCom1System() const { return m_com1system; }
255 
257  const aviation::CComSystem &getCom2System() const { return m_com2system; }
258 
260  aviation::CComSystem getComSystem(aviation::CComSystem::ComUnit unit) const;
261 
263  void setComSystem(const aviation::CComSystem &com, aviation::CComSystem::ComUnit unit);
264 
266  void setCom1System(const aviation::CComSystem &comSystem) { m_com1system = comSystem; }
267 
269  void setCom2System(const aviation::CComSystem &comSystem) { m_com2system = comSystem; }
270 
272  bool setCom1ActiveFrequency(const physical_quantities::CFrequency &frequency);
273 
275  bool setCom2ActiveFrequency(const physical_quantities::CFrequency &frequency);
276 
278  bool setComActiveFrequency(const physical_quantities::CFrequency &frequency,
280 
282  bool isSelcalSelected(const aviation::CSelcal &selcal) const { return m_selcal == selcal; }
283 
285  bool hasValidSelcal() const { return m_selcal.isValid(); }
286 
288  const aviation::CSelcal getSelcal() const { return m_selcal; }
289 
291  void setCockpit(const CSimulatedAircraft &aircraft);
292 
294  void setCockpit(const aviation::CComSystem &com1, const aviation::CComSystem &com2,
295  const aviation::CTransponder &transponder);
296 
298  void setCockpit(const aviation::CComSystem &com1, const aviation::CComSystem &com2, int transponderCode,
300 
302  void setSelcal(const aviation::CSelcal &selcal) { m_selcal = selcal; }
303 
305  bool hasChangedCockpitData(const aviation::CComSystem &com1, const aviation::CComSystem &com2,
306  const aviation::CTransponder &transponder) const;
307 
309  bool hasSameComData(const aviation::CComSystem &com1, const aviation::CComSystem &com2,
310  const aviation::CTransponder &transponder);
311 
314  bool hasComActiveFrequency(const physical_quantities::CFrequency &comFrequency) const;
315 
317  const aviation::CTransponder &getTransponder() const { return m_transponder; }
318 
320  void setTransponder(const aviation::CTransponder &transponder) { m_transponder = transponder; }
321 
323  bool setTransponderMode(aviation::CTransponder::TransponderMode mode);
324 
326  void setTransponderCode(int code) { m_transponder.setTransponderCode(code); }
327 
329  QString getTransponderCodeFormatted() const { return m_transponder.getTransponderCodeFormatted(); }
330 
332  qint32 getTransponderCode() const { return m_transponder.getTransponderCode(); }
333 
336  {
337  return m_transponder.getTransponderMode();
338  }
339 
341  bool isValidForLogin() const;
342 
344  void initComSystems();
345 
347  void initTransponder();
348 
350  const aviation::CAircraftParts &getParts() const { return m_parts; }
351 
353  int getEnginesCount() const;
354 
356  aviation::CAircraftLights getLights() const;
357 
359  void setParts(const aviation::CAircraftParts &parts);
360 
362  void setLights(aviation::CAircraftLights &lights);
363 
365  void setAllLightsOn();
366 
368  void setAllLightsOff();
369 
371  bool isVtol() const;
372 
374  bool isMilitary() const;
375 
377  QString getCombinedIcaoLiveryString(bool networkModel = false) const;
378 
380  int comparePropertyByIndex(CPropertyIndexRef index, const CSimulatedAircraft &compareValue) const;
381 
383  const simulation::CAircraftModel &getModel() const { return m_models[CurrentModel]; }
384 
386  bool isTerrainProbe() const { return this->getModel().isTerrainProbe(); }
387 
389  const simulation::CAircraftModel &getNetworkModel() const { return m_models[NetworkModel]; }
390 
392  const simulation::CAircraftModel &getNetworkModelOrModel() const;
393 
395  bool hasNetworkModel() const;
396 
398  QString getNetworkModelAircraftIcaoDifference() const;
399 
401  QString getNetworkModelAirlineIcaoDifference() const;
402 
404  QString getNetworkModelLiveryDifference() const;
405 
407  const QString &getModelString() const { return m_models[CurrentModel].getModelString(); }
408 
410  void setModelString(const QString &modelString);
411 
413  bool hasModelString() const { return m_models[CurrentModel].hasModelString(); }
414 
416  void setModel(const CAircraftModel &model);
417 
419  void setNetworkModel(const CAircraftModel &model);
420 
422  const physical_quantities::CLength &getCG() const { return m_models[CurrentModel].getCG(); }
423 
425  bool hasCG() const { return !this->getCG().isNull(); }
426 
428  bool resetToNetworkModel();
429 
431  bool setCG(const physical_quantities::CLength &cg);
432 
434  void setCallsign(const aviation::CCallsign &callsign);
435 
437  void setPilot(const network::CUser &user);
438 
440  bool isEnabled() const;
441 
443  bool setEnabled(bool enabled);
444 
446  bool isRendered() const { return m_rendered; }
447 
449  bool fastPositionUpdates() const { return m_fastPositionUpdates; }
450 
452  bool setFastPositionUpdates(bool useFastPositions);
453 
455  bool toggleFastPositionUpdates();
456 
458  bool setRendered(bool rendered);
459 
461  bool isPartsSynchronized() const { return m_partsSynchronized; }
462 
464  void setPartsSynchronized(bool synchronized) { m_partsSynchronized = synchronized; }
465 
467  bool isSupportingGndFlag() const { return m_supportsGndFlag; }
468 
472  void setSupportingGndFlag(bool supports) { m_supportsGndFlag = supports; }
473 
475  QVariant propertyByIndex(CPropertyIndexRef index) const;
476 
478  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
479 
481  QString convertToQString(bool i18n = false) const;
482 
484  CIcons::IconIndex toIcon() const { return m_callsign.toIcon(); }
485 
486  private:
487  static constexpr int CurrentModel = 0;
488  static constexpr int NetworkModel = 1;
489  aviation::CCallsign m_callsign;
490  network::CUser m_pilot;
491  aviation::CAircraftSituation m_situation;
492  aviation::CComSystem m_com1system;
493  aviation::CComSystem m_com2system;
494  aviation::CTransponder m_transponder;
495  aviation::CAircraftParts m_parts;
496  aviation::CSelcal m_selcal;
497  CAircraftModelList m_models = {
499  };
500  bool m_enabled = true;
501  bool m_rendered = false;
502  bool m_partsSynchronized = false;
503  bool m_fastPositionUpdates = false;
504  bool m_supportsGndFlag = false;
505 
507  void init();
508 
510  CSimulatedAircraft,
511  SWIFT_METAMEMBER(callsign),
512  SWIFT_METAMEMBER(pilot),
513  SWIFT_METAMEMBER(situation),
514  SWIFT_METAMEMBER(com1system),
515  SWIFT_METAMEMBER(com2system),
516  SWIFT_METAMEMBER(transponder),
517  SWIFT_METAMEMBER(parts),
518  SWIFT_METAMEMBER(selcal),
519  SWIFT_METAMEMBER(models),
520  SWIFT_METAMEMBER(enabled),
521  SWIFT_METAMEMBER(rendered),
522  SWIFT_METAMEMBER(partsSynchronized),
523  SWIFT_METAMEMBER(fastPositionUpdates),
524  // ICoordinateWithRelativePosition
525  SWIFT_METAMEMBER(relativeDistance),
526  SWIFT_METAMEMBER(relativeBearing));
527  };
528  } // namespace simulation
529 } // namespace swift::misc
530 
532 
533 #endif // SWIFT_MISC_SIMULATION_SIMULATEDAIRCRAFT_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Value object for ICAO classification.
Value object encapsulating information about aircraft's lights.
Value object encapsulating information of aircraft's parts.
Definition: aircraftparts.h:26
Value object encapsulating information of an aircraft's situation.
GndElevationInfo
Where did we get elevation from?
Velocity and angular velocity for 6DOF bodies.
Value object for ICAO classification.
Altitude as used in aviation, can be AGL or MSL altitude.
Definition: altitude.h:52
Value object encapsulating information of a callsign.
Definition: callsign.h:30
static bool isValidAircraftCallsign(const QString &callsign)
Valid callsign?
Definition: callsign.cpp:369
COM system (aka "radio")
Definition: comsystem.h:37
Heading as used in aviation, can be true or magnetic heading.
Definition: heading.h:41
Value object encapsulating information about an airpot.
Definition: livery.h:29
Value object for SELCAL.
Definition: selcal.h:31
Plane of same elevation, can be a single point or larger area (e.g. airport)
Interface (actually more an abstract class) of coordinates and relative position to something (normal...
Value object encapsulating information of a user.
Definition: user.h:28
Physical unit angle (radians, degrees)
Definition: angle.h:23
Physical unit length (length)
Definition: length.h:18
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
Value object encapsulating a list of aircraft models.
Comprehensive information of an aircraft.
bool hasRealName() const
Has valid realname?
void setGroundElevation(const geo::CElevationPlane &elevation, aviation::CAircraftSituation::GndElevationInfo info)
Elevation of the ground directly beneath at the given situation.
bool hasAirlineDesignator() const
Valid airline designator.
void setPartsSynchronized(bool synchronized)
Set the synchronisation flag.
bool hasModelString() const
Has model string?
const aviation::CSelcal getSelcal() const
SELCAL.
aviation::CTransponder::TransponderMode getTransponderMode() const
Get transponder mode.
QVector3D normalVector() const
Normal vector.
const aviation::CAircraftSituation & getSituation() const
Get situation.
geo::CLongitude longitude() const
Longitude.
bool isPartsSynchronized() const
Have parts been synchronized with a remote client?
const aviation::CComSystem & getCom2System() const
Get COM2 system.
const aviation::CAircraftVelocity & getVelocity() const
Get 6DOF velocity.
bool isSupportingGndFlag() const
Is supporting gnd.flag?
const aviation::CTransponder & getTransponder() const
Get transponder.
bool fastPositionUpdates() const
Support fast position updates.
QString getPilotRealName() const
Get user's real name.
void setGroundElevationChecked(const geo::CElevationPlane &elevation, aviation::CAircraftSituation::GndElevationInfo info)
Elevation of the ground directly beneath at the given situation.
geo::CLatitude latitude() const
Latitude.
CIcons::IconIndex toIcon() const
As icon, not implemented by all classes.
void setSelcal(const aviation::CSelcal &selcal)
Own SELCAL code.
const aviation::CAltitude & getPressureAltitude() const
Get pressure altitude.
void setPosition(const geo::CCoordinateGeodetic &position)
Set position.
const physical_quantities::CAngle & getPitch() const
Get pitch.
void setVelocity(const aviation::CAircraftVelocity &velocity)
Set 6DOF velocity.
bool setAircraftIcaoCode(const aviation::CAircraftIcaoCode &aircraftIcaoCode)
Set aicraft ICAO code.
void setPressureAltitude(const aviation::CAltitude &altitude)
Set pressure altitude.
const aviation::CHeading & getHeading() const
Get heading.
void setCom1System(const aviation::CComSystem &comSystem)
Set COM1 system.
std::array< double, 3 > normalVectorDouble() const
Normal vector with double precision.
const network::CUser & getPilot() const
Get user.
const aviation::CAltitude & geodeticHeight() const
Height, ellipsoidal or geodetic height (used in GPS)
const simulation::CAircraftModel & getNetworkModel() const
Get network model.
qint32 getTransponderCode() const
Get transponder code.
bool isSelcalSelected(const aviation::CSelcal &selcal) const
Given SELCAL selected?
bool hasCallsign() const
Callsign not empty, no further checks.
const aviation::CCallsign & getCallsign() const
Get callsign.
const aviation::CLivery & getLivery() const
Get livery.
QString getTransponderCodeFormatted() const
Get transponder code.
geo::CCoordinateGeodetic getPosition() const
Get position.
bool hasValidCallsign() const
Valid callsign?
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping)
void setSupportingGndFlag(bool supports)
Indicate gnd.flag is supported.
const aviation::CAltitude & getGroundElevation() const
Elevation of the ground directly beneath.
const physical_quantities::CSpeed & getGroundSpeed() const
Get groundspeed.
const physical_quantities::CAngle & getBank() const
Get bank (angle)
void setTransponder(const aviation::CTransponder &transponder)
Set transponder.
void setCom2System(const aviation::CComSystem &comSystem)
Set COM2 system.
QString getCallsignAsString() const
Get callsign.
void setTransponderCode(int code)
Set transponder code.
const aviation::CAltitude & getAltitude() const
Get altitude.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
const physical_quantities::CLength & getCG() const
Get CG from model.
const aviation::CAircraftParts & getParts() const
Get aircraft parts.
void setAltitude(const aviation::CAltitude &altitude)
Set altitude.
const QString & getModelString() const
Get model string.
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:52
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65