8#include <QStringBuilder>
18using namespace swift::misc::physical_quantities;
19using namespace swift::misc::aviation;
20using namespace swift::misc::network;
24namespace swift::misc::simulation
30 this->setCallsign(model.getCallsign());
36 : m_callsign(callsign), m_pilot(user), m_situation(situation)
43 : m_callsign(callsign), m_pilot(user), m_situation(situation)
49 void CSimulatedAircraft::init()
51 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
72 m_transponder.setTransponderCode(transponderCode);
73 m_transponder.setTransponderMode(transponderMode);
90 if (m_callsign.isEmpty())
104 m_situation = situation;
107 m_situation.setVelocity(velocity);
116 return m_models[CurrentModel].getAircraftIcaoCode();
136 if (m_enabled == enabled)
146 if (m_fastPositionUpdates == useFastPositions)
150 m_fastPositionUpdates = useFastPositions;
161 if (m_rendered == rendered)
165 m_rendered = rendered;
199 "Standard auto generated");
200 m_models[CurrentModel].setLivery(newLivery);
202 return m_models[CurrentModel].setAircraftIcaoCode(aircraftIcaoCode);
207 return m_models[CurrentModel].getAirlineIcaoCode();
217 m_models[CurrentModel].setAircraftIcaoDesignator(designator);
261 m_com1system.setFrequencyActive(frequency);
271 m_com2system.setFrequencyActive(frequency);
309 return engines >= 0 ? engines : m_parts.getEnginesCount();
333 static const QString s(
"%1 (%2 %3)");
339 static const QString s(
"%1 (%2)");
350 static const QString s(
"%1 (%2)");
376 case IndexCallsign:
return m_callsign.propertyByIndex(index.
copyFrontRemoved());
379 case IndexCom1System:
return m_com1system.propertyByIndex(index.
copyFrontRemoved());
380 case IndexCom2System:
return m_com2system.propertyByIndex(index.
copyFrontRemoved());
381 case IndexTransponder:
return m_transponder.propertyByIndex(index.
copyFrontRemoved());
382 case IndexSituation:
return m_situation.propertyByIndex(index.
copyFrontRemoved());
388 case IndexCombinedIcaoLiveryStringNetworkModel:
391 return (ICoordinateWithRelativePosition::canHandleIndex(index)) ?
392 ICoordinateWithRelativePosition::propertyByIndex(index) :
407 case IndexCallsign: m_callsign.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
408 case IndexPilot: m_pilot.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
410 case IndexCom1System: m_com1system.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
411 case IndexCom2System: m_com2system.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
412 case IndexTransponder: m_transponder.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
413 case IndexSituation: m_situation.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
414 case IndexParts: m_parts.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
415 case IndexNetworkModel: m_models[NetworkModel].setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
416 case IndexEnabled: m_enabled = variant.
toBool();
break;
417 case IndexRendered: m_rendered = variant.
toBool();
break;
418 case IndexPartsSynchronized: m_partsSynchronized = variant.
toBool();
break;
419 case IndexFastPositionUpdates: m_fastPositionUpdates = variant.
toBool();
break;
420 case IndexSupportsGndFlag: m_supportsGndFlag = variant.
toBool();
break;
421 case IndexLivery: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Unsupported");
break;
423 m_models[CurrentModel].setPropertyByIndex(index.
copyFrontRemoved(), variant);
424 this->
setModel(m_models[CurrentModel]);
427 if (ICoordinateWithRelativePosition::canHandleIndex(index))
429 ICoordinateWithRelativePosition::setPropertyByIndex(index, variant);
454 case IndexRelativeDistance:
457 case IndexCom1System:
459 case IndexCom2System:
461 case IndexTransponder:
469 case IndexNetworkModel:
471 case IndexNetworkModelAircraftIcaoDifference:
474 case IndexNetworkModelAirlineIcaoDifference:
477 case IndexNetworkModelLiveryDifference:
481 case IndexPartsSynchronized:
483 case IndexFastPositionUpdates:
485 case IndexSupportsGndFlag:
487 case IndexCombinedIcaoLiveryString:
489 case IndexCombinedIcaoLiveryStringNetworkModel:
492 if (ICoordinateWithRelativePosition::canHandleIndex(index))
494 return ICoordinateWithRelativePosition::comparePropertyByIndex(index, compareValue);
504 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
505 return this->
hasNetworkModel() ? m_models[NetworkModel] : m_models[CurrentModel];
510 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
511 return m_models[NetworkModel].hasModelString() || !m_models[NetworkModel].getCallsign().isEmpty();
519 return QStringLiteral(
"[x] no nw. ICAO");
525 return QStringLiteral(
"[x] no sim. ICAO");
528 if (icaoModel.
isDbEqual(icaoNw) || icaoModel == icaoNw)
541 static const QString diff(
"%1 -> %2");
559 if (icao.
isDbEqual(icaoNw) || icao == icaoNw)
572 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
576 if (livery.
isDbEqual(liveryNw) || livery == liveryNw)
589 static const QString diff(
"%1 -> %2");
595 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
598 m_models[CurrentModel] = model;
605 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
606 m_models[NetworkModel] = model;
611 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
613 m_models[CurrentModel] = nwModel;
624 const int c = m_models.
setCG(cg);
630 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
631 m_models[CurrentModel].setModelString(modelString);
636 Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO,
"Wrong model size");
637 m_callsign = callsign;
638 m_models[CurrentModel].setCallsign(callsign);
639 m_models[NetworkModel].setCallsign(callsign);
640 m_pilot.setCallsign(callsign);
645 return m_com1system.isActiveFrequencySameFrequency(comFrequency) ||
646 m_com2system.isActiveFrequencySameFrequency(comFrequency);
651 return (m_transponder.setTransponderMode(mode));
656 const QString s = m_callsign.toQString(i18n) % u
' ' % m_pilot.toQString(i18n) % u
' ' %
657 m_situation.toQString(i18n) % u
' ' % m_com1system.toQString(i18n) % u
' ' %
658 m_com2system.toQString(i18n) % u
' ' % m_transponder.toQString(i18n) % u
" enabled: " %
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
QString toQString(bool i18n=false) const
Cast as QString.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
size_type size() const
Returns number of elements in the sequence.
Value object for ICAO classification.
bool hasDesignator() const
Aircraft designator?
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
int getEnginesCount() const
Engine count if any, -1 if no value is set.
QString getDesignatorDbKey() const
Designator and DB key.
const QString & getDesignator() const
Get ICAO designator, e.g. "B737".
const QString & getCombinedType() const
Get type, e.g. "L2J".
Value object encapsulating information about aircraft's lights.
Value object encapsulating information of aircraft's parts.
void setLights(const CAircraftLights &lights)
Set aircraft lights.
Value object encapsulating information of an aircraft's situation.
void setCallsign(const CCallsign &callsign)
Corresponding callsign.
bool hasInboundGroundDetails() const
Has inbound ground details.
Velocity and angular velocity for 6DOF bodies.
Value object for ICAO classification.
QString getDesignatorDbKey() const
Designator and DB key.
const QString & getDesignator() const
Get airline, e.g. "DLH".
Value object encapsulating information of a callsign.
COM system (aka "radio").
static bool isValidComFrequency(const physical_quantities::CFrequency &f)
Valid COM frequency (either civil or military).
Value object encapsulating information about an airpot.
const QString & getCombinedCode() const
Combined code.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
static QString getStandardCode(const aviation::CAirlineIcaoCode &airline)
Standard code for airline.
bool isAirlineLivery() const
Livery representing airline.
bool hasCombinedCode() const
Livery combined code available?
int comparePropertyByIndex(CPropertyIndexRef index, const CLivery &compareValue) const
Compare for index.
QString getCombinedCodePlusInfo() const
Combined code plus info.
int getTransponderCode() const
Transponder code.
TransponderMode
Transponder codes.
@ StateStandby
not a real mode, more a state
bool isDbEqual(const IDatastoreObjectWithIntegerKey &other) const
Same DB key and hence equal.
const physical_quantities::CLength & getRelativeDistance() const
Get the distance.
physical_quantities::CLength m_relativeDistance
temporary stored value
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating information of a user.
bool setCallsign(const aviation::CCallsign &callsign)
Set associated callsign.
Physical unit length (length).
static const CFrequency & FrequencyUnicom()
Unicom frequency.
bool isNull() const
Is quantity null?
Aircraft model (used by another pilot, my models on disk).
bool hasAircraftAndAirlineDesignator() const
Designators.
const aviation::CCallsign & getCallsign() const
Corresponding callsign if applicable.
bool isVtol() const
VTOL aircraft?
const QString & getAirlineIcaoCodeDesignator() const
Airline ICAO code designator.
const aviation::CLivery & getLivery() const
Get livery.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setCG(const physical_quantities::CLength &cg)
Get center of gravity.
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code.
const QString & getAircraftIcaoCodeDesignator() const
Aircraft ICAO code designator.
bool isMilitary() const
Military model?
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Aircraft ICAO code.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
const QString & getAirlineIcaoCodeDesignator() const
Airline ICAO code designator.
bool hasAirlineDesignator() const
Valid airline designator.
bool hasModelString() const
Has model string?
const simulation::CAircraftModel & getNetworkModelOrModel() const
Get network model or (if not existing) model.
const aviation::CSelcal getSelcal() const
SELCAL.
void setModel(const CAircraftModel &model)
Set model.
void setAllLightsOff()
Set aircraft lights off.
QString getNetworkModelAirlineIcaoDifference() const
Difference of network and (rendered) airline ICAO code.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
const aviation::CComSystem & getCom2System() const
Get COM2 system.
void initTransponder()
Meaningful default settings for Transponder.
bool isMilitary() const
Is military aircraft.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
void setCockpit(const CSimulatedAircraft &aircraft)
Set COM unit (all values + transponder and SELCAL).
bool isPartsSynchronized() const
Have parts been synchronized with a remote client?
void initComSystems()
Meaningful default settings for COM Systems.
QString convertToQString(bool i18n=false) const
Cast as QString.
bool isSupportingGndFlag() const
Is supporting gnd.flag?
const aviation::CLivery & getLivery() const
Get livery.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool hasNetworkModel() const
Has a network model been set?
bool fastPositionUpdates() const
Support fast position updates.
bool setTransponderMode(aviation::CTransponder::TransponderMode mode)
Set transponder mode.
void setAllLightsOn()
Set aircraft lights on.
bool isRendered() const
Rendered?
aviation::CAircraftLights getLights() const
Get aircraft parts.
const aviation::CCallsign & getCallsign() const
Get callsign.
bool setCG(const physical_quantities::CLength &cg)
Set the center of gravity.
void setModelString(const QString &modelString)
Set model string.
QString getCombinedIcaoLiveryString(bool networkModel=false) const
Combined ICAO / color string.
void setSelcal(const aviation::CSelcal &selcal)
Own SELCAL code.
bool setRendered(bool rendered)
Rendered?
void setSituation(const aviation::CAircraftSituation &situation)
Set situation. Won't overwrite the velocity unless it held the default value.
QString getNetworkModelAircraftIcaoDifference() const
Difference of network and (rendered) aircraft ICAO code.
void setCom1System(const aviation::CComSystem &comSystem)
Set COM1 system.
bool hasComActiveFrequency(const physical_quantities::CFrequency &comFrequency) const
Is comFrequency selected in COM1 or COM2 as active frequency (with 5 kHz spacing for ....
bool setComActiveFrequency(const physical_quantities::CFrequency &frequency, aviation::CComSystem::ComUnit unit)
Set COM frequency.
bool isValidForLogin() const
Is valid for login?
void setComSystem(const aviation::CComSystem &com, aviation::CComSystem::ComUnit unit)
Set COM unit.
bool hasAircraftDesignator() const
Valid designator?
void setLights(aviation::CAircraftLights &lights)
Set aircraft lights.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Get aircraft ICAO info.
bool setCom1ActiveFrequency(const physical_quantities::CFrequency &frequency)
Set COM1 frequency.
QString getNetworkModelLiveryDifference() const
Difference of network and (rendered) livery code.
const aviation::CAircraftParts & getParts() const
Get aircraft parts.
const QString & getAircraftIcaoCombinedType() const
Aircraft ICAO combined code.
bool hasChangedCockpitData(const aviation::CComSystem &com1, const aviation::CComSystem &com2, const aviation::CTransponder &transponder) const
Changed cockpit data?
const QString & getAircraftIcaoCodeDesignator() const
Aircraft ICAO code designator.
bool toggleFastPositionUpdates()
Toggle fast position updates.
bool hasSameComData(const aviation::CComSystem &com1, const aviation::CComSystem &com2, const aviation::CTransponder &transponder)
Identical COM system?
bool hasValidCallsign() const
Valid callsign?
CSimulatedAircraft()
Default constructor.
void setSupportingGndFlag(bool supports)
Indicate gnd.flag is supported.
aviation::CComSystem getComSystem(aviation::CComSystem::ComUnit unit) const
Get COM unit.
const aviation::CTransponder & getTransponder() const
Get transponder.
void setParts(const aviation::CAircraftParts &parts)
Set aircraft parts.
bool hasAircraftAndAirlineDesignator() const
Valid designators?
void setNetworkModel(const CAircraftModel &model)
Set network model.
QString getAirlineAndAircraftIcaoCodeDesignators() const
Aircraft and Airline ICAO code designators.
bool setEnabled(bool enabled)
Enabled / disabled.
const network::CUser & getPilot() const
Get user.
bool setCom2ActiveFrequency(const physical_quantities::CFrequency &frequency)
Set COM2 frequency.
void setAircraftIcaoDesignator(const QString &designator)
Set aircraft ICAO designator.
int comparePropertyByIndex(CPropertyIndexRef index, const CSimulatedAircraft &compareValue) const
Compare for index.
void setTransponder(const aviation::CTransponder &transponder)
Set transponder.
void setCom2System(const aviation::CComSystem &comSystem)
Set COM2 system.
bool isEnabled() const
Enabled? Enable means it shall be displayed in the simulator.
bool isVtol() const
VTOL aircraft?
ColumnIndex
Properties by index.
const aviation::CAircraftSituation & getSituation() const
Get situation.
bool setIcaoCodes(const aviation::CAircraftIcaoCode &aircraftIcaoCode, const aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO info.
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping).
const simulation::CAircraftModel & getNetworkModel() const
Get network model.
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code if any.
bool resetToNetworkModel()
Reset to the newtork model.
int getEnginesCount() const
Number of engines.
void setPilot(const network::CUser &user)
Set pilot.
bool setFastPositionUpdates(bool useFastPositions)
Support fast position updates.
int compare(T a, T b)
Compare arithmetic values.
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
QString arg(Args &&... args) const const
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
QVariant fromValue(T &&value)
bool toBool() const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.