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  virtual geo::CLatitude latitude() const override { return m_situation.latitude(); }
214 
216  virtual geo::CLongitude longitude() const override { return m_situation.longitude(); }
217 
219  const aviation::CAltitude &geodeticHeight() const override { return m_situation.geodeticHeight(); }
220 
222  virtual QVector3D normalVector() const override { return m_situation.normalVector(); }
223 
225  virtual std::array<double, 3> normalVectorDouble() const override
226  {
227  return m_situation.normalVectorDouble();
228  }
229 
231  const aviation::CAltitude &getGroundElevation() const { return m_situation.getGroundElevation(); }
232 
236  {
237  m_situation.setGroundElevation(elevation, info);
238  }
239 
243  {
244  m_situation.setGroundElevationChecked(elevation, info);
245  }
246 
248  const aviation::CHeading &getHeading() const { return m_situation.getHeading(); }
249 
251  const physical_quantities::CAngle &getPitch() const { return m_situation.getPitch(); }
252 
254  const physical_quantities::CAngle &getBank() const { return m_situation.getBank(); }
255 
257  const aviation::CComSystem &getCom1System() const { return m_com1system; }
258 
260  const aviation::CComSystem &getCom2System() const { return m_com2system; }
261 
263  aviation::CComSystem getComSystem(aviation::CComSystem::ComUnit unit) const;
264 
266  void setComSystem(const aviation::CComSystem &com, aviation::CComSystem::ComUnit unit);
267 
269  void setCom1System(const aviation::CComSystem &comSystem) { m_com1system = comSystem; }
270 
272  void setCom2System(const aviation::CComSystem &comSystem) { m_com2system = comSystem; }
273 
275  bool setCom1ActiveFrequency(const physical_quantities::CFrequency &frequency);
276 
278  bool setCom2ActiveFrequency(const physical_quantities::CFrequency &frequency);
279 
281  bool setComActiveFrequency(const physical_quantities::CFrequency &frequency,
283 
285  bool isSelcalSelected(const aviation::CSelcal &selcal) const { return m_selcal == selcal; }
286 
288  bool hasValidSelcal() const { return m_selcal.isValid(); }
289 
291  const aviation::CSelcal getSelcal() const { return m_selcal; }
292 
294  void setCockpit(const CSimulatedAircraft &aircraft);
295 
297  void setCockpit(const aviation::CComSystem &com1, const aviation::CComSystem &com2,
298  const aviation::CTransponder &transponder);
299 
301  void setCockpit(const aviation::CComSystem &com1, const aviation::CComSystem &com2, int transponderCode,
303 
305  void setSelcal(const aviation::CSelcal &selcal) { m_selcal = selcal; }
306 
308  bool hasChangedCockpitData(const aviation::CComSystem &com1, const aviation::CComSystem &com2,
309  const aviation::CTransponder &transponder) const;
310 
312  bool hasSameComData(const aviation::CComSystem &com1, const aviation::CComSystem &com2,
313  const aviation::CTransponder &transponder);
314 
317  bool hasComActiveFrequency(const physical_quantities::CFrequency &comFrequency) const;
318 
320  const aviation::CTransponder &getTransponder() const { return m_transponder; }
321 
323  void setTransponder(const aviation::CTransponder &transponder) { m_transponder = transponder; }
324 
326  bool setTransponderMode(aviation::CTransponder::TransponderMode mode);
327 
329  void setTransponderCode(int code) { m_transponder.setTransponderCode(code); }
330 
332  QString getTransponderCodeFormatted() const { return m_transponder.getTransponderCodeFormatted(); }
333 
335  qint32 getTransponderCode() const { return m_transponder.getTransponderCode(); }
336 
339  {
340  return m_transponder.getTransponderMode();
341  }
342 
344  bool isValidForLogin() const;
345 
347  void initComSystems();
348 
350  void initTransponder();
351 
353  const aviation::CAircraftParts &getParts() const { return m_parts; }
354 
356  int getEnginesCount() const;
357 
359  aviation::CAircraftLights getLights() const;
360 
362  void setParts(const aviation::CAircraftParts &parts);
363 
365  void setLights(aviation::CAircraftLights &lights);
366 
368  void setAllLightsOn();
369 
371  void setAllLightsOff();
372 
374  bool isVtol() const;
375 
377  bool isMilitary() const;
378 
380  QString getCombinedIcaoLiveryString(bool networkModel = false) const;
381 
383  int comparePropertyByIndex(CPropertyIndexRef index, const CSimulatedAircraft &compareValue) const;
384 
386  const simulation::CAircraftModel &getModel() const { return m_models[CurrentModel]; }
387 
389  bool isTerrainProbe() const { return this->getModel().isTerrainProbe(); }
390 
392  const simulation::CAircraftModel &getNetworkModel() const { return m_models[NetworkModel]; }
393 
395  const simulation::CAircraftModel &getNetworkModelOrModel() const;
396 
398  bool hasNetworkModel() const;
399 
401  QString getNetworkModelAircraftIcaoDifference() const;
402 
404  QString getNetworkModelAirlineIcaoDifference() const;
405 
407  QString getNetworkModelLiveryDifference() const;
408 
410  const QString &getModelString() const { return m_models[CurrentModel].getModelString(); }
411 
413  void setModelString(const QString &modelString);
414 
416  bool hasModelString() const { return m_models[CurrentModel].hasModelString(); }
417 
419  void setModel(const CAircraftModel &model);
420 
422  void setNetworkModel(const CAircraftModel &model);
423 
425  const physical_quantities::CLength &getCG() const { return m_models[CurrentModel].getCG(); }
426 
428  bool hasCG() const { return !this->getCG().isNull(); }
429 
431  bool resetToNetworkModel();
432 
434  bool setCG(const physical_quantities::CLength &cg);
435 
437  void setCallsign(const aviation::CCallsign &callsign);
438 
440  void setPilot(const network::CUser &user);
441 
443  bool isEnabled() const;
444 
446  bool setEnabled(bool enabled);
447 
449  bool isRendered() const { return m_rendered; }
450 
452  bool fastPositionUpdates() const { return m_fastPositionUpdates; }
453 
455  bool setFastPositionUpdates(bool useFastPositions);
456 
458  bool toggleFastPositionUpdates();
459 
461  bool setRendered(bool rendered);
462 
464  bool isPartsSynchronized() const { return m_partsSynchronized; }
465 
467  void setPartsSynchronized(bool synchronized) { m_partsSynchronized = synchronized; }
468 
470  bool isSupportingGndFlag() const { return m_supportsGndFlag; }
471 
475  void setSupportingGndFlag(bool supports) { m_supportsGndFlag = supports; }
476 
478  QVariant propertyByIndex(CPropertyIndexRef index) const;
479 
481  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
482 
484  QString convertToQString(bool i18n = false) const;
485 
487  CIcons::IconIndex toIcon() const { return m_callsign.toIcon(); }
488 
489  private:
490  static constexpr int CurrentModel = 0;
491  static constexpr int NetworkModel = 1;
492  aviation::CCallsign m_callsign;
493  network::CUser m_pilot;
494  aviation::CAircraftSituation m_situation;
495  aviation::CComSystem m_com1system;
496  aviation::CComSystem m_com2system;
497  aviation::CTransponder m_transponder;
498  aviation::CAircraftParts m_parts;
499  aviation::CSelcal m_selcal;
500  CAircraftModelList m_models = {
502  };
503  bool m_enabled = true;
504  bool m_rendered = false;
505  bool m_partsSynchronized = false;
506  bool m_fastPositionUpdates = false;
507  bool m_supportsGndFlag = false;
508 
510  void init();
511 
513  CSimulatedAircraft,
514  SWIFT_METAMEMBER(callsign),
515  SWIFT_METAMEMBER(pilot),
516  SWIFT_METAMEMBER(situation),
517  SWIFT_METAMEMBER(com1system),
518  SWIFT_METAMEMBER(com2system),
519  SWIFT_METAMEMBER(transponder),
520  SWIFT_METAMEMBER(parts),
521  SWIFT_METAMEMBER(selcal),
522  SWIFT_METAMEMBER(models),
523  SWIFT_METAMEMBER(enabled),
524  SWIFT_METAMEMBER(rendered),
525  SWIFT_METAMEMBER(partsSynchronized),
526  SWIFT_METAMEMBER(fastPositionUpdates),
527  // ICoordinateWithRelativePosition
528  SWIFT_METAMEMBER(relativeDistance),
529  SWIFT_METAMEMBER(relativeBearing));
530  };
531  } // namespace simulation
532 } // namespace swift::misc
533 
535 
536 #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.
virtual geo::CLatitude latitude() const
Latitude.
const aviation::CAircraftSituation & getSituation() const
Get situation.
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.
virtual geo::CLongitude longitude() const
Longitude.
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.
virtual std::array< double, 3 > normalVectorDouble() const
Normal vector with double precision.
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.
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)
virtual QVector3D normalVector() const
Normal vector.
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:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
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