8 #include <QStringBuilder>
18 using namespace swift::misc::physical_quantities;
19 using namespace swift::misc::aviation;
20 using namespace swift::misc::network;
24 namespace swift::misc::simulation
26 CSimulatedAircraft::CSimulatedAircraft() { this->init(); }
28 CSimulatedAircraft::CSimulatedAircraft(
const CAircraftModel &model) : m_models({ model, model })
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");
90 if (m_callsign.
isEmpty()) {
return false; }
91 if (m_pilot.
isNull()) {
return false; }
98 m_situation = situation;
107 return m_models[CurrentModel].getAircraftIcaoCode();
124 if (m_enabled == enabled) {
return false; }
131 if (m_fastPositionUpdates == useFastPositions) {
return false; }
132 m_fastPositionUpdates = useFastPositions;
143 if (m_rendered == rendered) {
return false; }
144 m_rendered = rendered;
174 const CLivery newLivery(CLivery::getStandardCode(airlineIcaoCode), airlineIcaoCode,
175 "Standard auto generated");
176 m_models[CurrentModel].setLivery(newLivery);
178 return m_models[CurrentModel].setAircraftIcaoCode(aircraftIcaoCode);
183 return m_models[CurrentModel].getAirlineIcaoCode();
193 m_models[CurrentModel].setAircraftIcaoDesignator(designator);
233 if (!CComSystem::isValidComFrequency(frequency)) {
return false; }
240 if (!CComSystem::isValidComFrequency(frequency)) {
return false; }
247 if (!CComSystem::isValidComFrequency(frequency)) {
return false; }
259 CComSystem com1(
"COM1", CPhysicalQuantitiesConstants::FrequencyUnicom(),
260 CPhysicalQuantitiesConstants::FrequencyUnicom());
261 CComSystem com2(
"COM2", CPhysicalQuantitiesConstants::FrequencyUnicom(),
262 CPhysicalQuantitiesConstants::FrequencyUnicom());
269 const CTransponder xpdr(7000, CTransponder::StateStandby);
300 static const QString s(
"%1 (%2 %3)");
306 static const QString s(
"%1 (%2)");
314 static const QString s(
"%1 (%2)");
323 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
332 case IndexEnabled:
return QVariant::fromValue(this->
isEnabled());
333 case IndexRendered:
return QVariant::fromValue(this->
isRendered());
347 case IndexIsVtol:
return QVariant::fromValue(this->
isVtol());
349 case IndexCombinedIcaoLiveryStringNetworkModel:
352 return (ICoordinateWithRelativePosition::canHandleIndex(index)) ?
353 ICoordinateWithRelativePosition::propertyByIndex(index) :
376 case IndexNetworkModel: m_models[NetworkModel].setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
377 case IndexEnabled: m_enabled = variant.toBool();
break;
378 case IndexRendered: m_rendered = variant.toBool();
break;
379 case IndexPartsSynchronized: m_partsSynchronized = variant.toBool();
break;
380 case IndexFastPositionUpdates: m_fastPositionUpdates = variant.toBool();
break;
381 case IndexSupportsGndFlag: m_supportsGndFlag = variant.toBool();
break;
382 case IndexLivery: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Unsupported");
break;
384 m_models[CurrentModel].setPropertyByIndex(index.
copyFrontRemoved(), variant);
385 this->
setModel(m_models[CurrentModel]);
388 if (ICoordinateWithRelativePosition::canHandleIndex(index))
390 ICoordinateWithRelativePosition::setPropertyByIndex(index, variant);
412 case IndexRelativeDistance:
415 case IndexCom1System:
417 case IndexCom2System:
419 case IndexTransponder:
427 case IndexNetworkModel:
429 case IndexNetworkModelAircraftIcaoDifference:
432 case IndexNetworkModelAirlineIcaoDifference:
435 case IndexNetworkModelLiveryDifference:
437 case IndexEnabled:
return Compare::compare(this->
isEnabled(), compareValue.
isEnabled());
439 case IndexPartsSynchronized:
441 case IndexFastPositionUpdates:
443 case IndexSupportsGndFlag:
445 case IndexCombinedIcaoLiveryString:
447 case IndexCombinedIcaoLiveryStringNetworkModel:
450 if (ICoordinateWithRelativePosition::canHandleIndex(index))
452 return ICoordinateWithRelativePosition::comparePropertyByIndex(index, compareValue);
462 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
463 return this->
hasNetworkModel() ? m_models[NetworkModel] : m_models[CurrentModel];
468 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
469 return m_models[NetworkModel].hasModelString() || !m_models[NetworkModel].getCallsign().
isEmpty();
475 if (!icaoNw.
hasDesignator()) {
return QStringLiteral(
"[x] no nw. ICAO"); }
478 if (!icaoModel.
hasDesignator()) {
return QStringLiteral(
"[x] no sim. ICAO"); }
487 static const QString diff(
"%1 -> %2");
512 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
516 if (livery.
isDbEqual(liveryNw) || livery == liveryNw)
529 static const QString diff(
"%1 -> %2");
535 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
538 m_models[CurrentModel] = model;
545 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
546 m_models[NetworkModel] = model;
551 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
553 m_models[CurrentModel] = nwModel;
559 if (cg.
isNull()) {
return false; }
561 const int c = m_models.
setCG(cg);
567 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
568 m_models[CurrentModel].setModelString(modelString);
573 Q_ASSERT_X(m_models.
size() == 2, Q_FUNC_INFO,
"Wrong model size");
574 m_callsign = callsign;
575 m_models[CurrentModel].setCallsign(callsign);
576 m_models[NetworkModel].setCallsign(callsign);
593 const QString s = m_callsign.
toQString(i18n) % u
' ' % m_pilot.
toQString(i18n) % u
' ' %
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.
bool isEmpty() const
Synonym for empty.
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.
const QString & getDesignator() const
Get ICAO designator, e.g. "B737".
QString getDesignatorDbKey() const
Designator and DB key.
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.
CAircraftLights getLights() const
Get aircraft lights.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setLights(const CAircraftLights &lights)
Set aircraft lights.
int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftParts &compareValue) const
Compare for index.
void setAllLightsOn()
Set all lights on.
void setAllLightsOff()
Set all lights off.
int getEnginesCount() const
Number of engines.
Value object encapsulating information of an aircraft's situation.
void setCallsign(const CCallsign &callsign)
Corresponding callsign.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
const CAircraftVelocity & getVelocity() const
Get 6DOF velocity.
int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftSituation &compareValue) const
Compare for index.
void setVelocity(const CAircraftVelocity &velocity)
Set 6DOF velocity.
bool hasInboundGroundDetails() const
Has inbound ground details.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
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.
int comparePropertyByIndex(CPropertyIndexRef index, const CCallsign &compareValue) const
Compare for index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isEmpty() const
Is empty?
bool isActiveFrequencySameFrequency(const physical_quantities::CFrequency &comFrequency) const
Is active frequency the same frequency.
void setFrequencyActive(const physical_quantities::CFrequency &frequency)
Set active frequency.
Value object encapsulating information about an airpot.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
const QString & getCombinedCode() const
Combined code.
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.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(swift::misc::CPropertyIndexRef index, const AVIO &compareValue) const
Compare by property index.
void setTransponderCode(int transponderCode)
Set transponder code.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int getTransponderCode() const
Transponder code.
bool setTransponderMode(TransponderMode mode)
Set transponder mode.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
TransponderMode
Transponder codes.
bool isDbEqual(const IDatastoreObjectWithIntegerKey &other) const
Same DB key and hence equal.
ColumnIndex
Properties by index.
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.
int comparePropertyByIndex(CPropertyIndexRef index, const CUser &compareValue) const
Compare for index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool setCallsign(const aviation::CCallsign &callsign)
Set associated callsign.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Physical unit length (length)
bool isNull() const
Is quantity null?
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const PQ &pq) const
Compare for index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Aircraft model (used by another pilot, my models on disk)
const aviation::CCallsign & getCallsign() const
Corresponding callsign if applicable.
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code.
const aviation::CLivery & getLivery() const
Get livery.
const QString & getAircraftIcaoCodeDesignator() const
Aircraft ICAO code designator.
bool hasAircraftAndAirlineDesignator() const
Designators.
bool isVtol() const
VTOL aircraft?
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Aircraft ICAO code.
const QString & getAirlineIcaoCodeDesignator() const
Airline ICAO code designator.
bool isMilitary() const
Military model?
int setCG(const physical_quantities::CLength &cg)
Set center of gravity.
Comprehensive information of an aircraft.
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.
void initTransponder()
Meaningful default settings for Transponder.
bool isMilitary() const
Is military aircraft.
const aviation::CAircraftSituation & getSituation() const
Get situation.
void setCockpit(const CSimulatedAircraft &aircraft)
Set COM unit (all values + transponder and SELCAL)
bool isPartsSynchronized() const
Have parts been synchronized with a remote client?
const aviation::CComSystem & getCom2System() const
Get COM2 system.
void initComSystems()
Meaningful default settings for COM Systems.
QString convertToQString(bool i18n=false) const
Cast as QString.
bool isSupportingGndFlag() const
Is supporting gnd.flag?
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
const aviation::CTransponder & getTransponder() const
Get transponder.
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.
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?
const network::CUser & getPilot() const
Get user.
const simulation::CAircraftModel & getNetworkModel() const
Get network model.
const aviation::CCallsign & getCallsign() const
Get callsign.
const aviation::CLivery & getLivery() const
Get livery.
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 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?
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping)
CSimulatedAircraft()
Default constructor.
void setSupportingGndFlag(bool supports)
Indicate gnd.flag is supported.
aviation::CComSystem getComSystem(aviation::CComSystem::ComUnit unit) const
Get COM unit.
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.
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?
bool setIcaoCodes(const aviation::CAircraftIcaoCode &aircraftIcaoCode, const aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO info.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code if any.
bool resetToNetworkModel()
Reset to the newtork model.
int getEnginesCount() const
Number of engines.
const aviation::CAircraftParts & getParts() const
Get aircraft parts.
void setPilot(const network::CUser &user)
Set pilot.
bool setFastPositionUpdates(bool useFastPositions)
Support fast position updates.
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
#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.