12 using namespace swift::config;
13 using namespace swift::misc::aviation;
14 using namespace swift::misc::physical_quantities;
15 using namespace swift::misc::network;
20 namespace swift::misc::simulation
22 CInterpolationAndRenderingSetupBase::CInterpolationAndRenderingSetupBase()
28 bool CInterpolationAndRenderingSetupBase::setSendingGndFlagToSimulator(
bool sendFLag)
30 if (sendFLag == m_sendGndToSim) {
return false; }
31 m_sendGndToSim = sendFLag;
35 bool CInterpolationAndRenderingSetupBase::setPitchOnGround(
const CAngle &pitchOnGround)
37 if (pitchOnGround == m_pitchOnGround) {
return false; }
38 m_pitchOnGround = pitchOnGround;
42 void CInterpolationAndRenderingSetupBase::consolidateWithClient(
const CClient &client)
50 const int m =
static_cast<int>(mode);
51 if (m_interpolatorMode == m) {
return false; }
52 m_interpolatorMode = m;
56 bool CInterpolationAndRenderingSetupBase::setInterpolatorMode(
const QString &mode)
58 if (mode.contains(
"spline", Qt::CaseInsensitive)) {
return this->setInterpolatorMode(Spline); }
59 if (mode.contains(
"linear", Qt::CaseInsensitive)) {
return this->setInterpolatorMode(Linear); }
63 const QString &CInterpolationAndRenderingSetupBase::modeToString(
InterpolatorMode mode)
65 static const QString l(
"linear");
66 static const QString s(
"spline");
70 case Linear:
return l;
71 case Spline:
return s;
76 bool CInterpolationAndRenderingSetupBase::setLogInterpolation(
bool log)
78 if (m_logInterpolation == log) {
return false; }
79 m_logInterpolation = log;
83 bool CInterpolationAndRenderingSetupBase::setEnabledAircraftParts(
bool enabled)
85 if (m_enabledAircraftParts == enabled) {
return false; }
86 m_enabledAircraftParts = enabled;
90 bool CInterpolationAndRenderingSetupBase::maskEnabledAircraftParts(
bool mask)
92 const bool masked = mask && m_enabledAircraftParts;
93 return this->setEnabledAircraftParts(masked);
96 QVariant CInterpolationAndRenderingSetupBase::propertyByIndex(
CPropertyIndexRef index)
const
101 case IndexLogInterpolation:
return QVariant::fromValue(m_logInterpolation);
102 case IndexSimulatorDebugMessages:
return QVariant::fromValue(m_simulatorDebugMessages);
103 case IndexForceFullInterpolation:
return QVariant::fromValue(m_forceFullInterpolation);
104 case IndexEnabledAircraftParts:
return QVariant::fromValue(m_enabledAircraftParts);
105 case IndexSendGndFlagToSimulator:
return QVariant::fromValue(m_sendGndToSim);
106 case IndexInterpolatorMode:
return QVariant::fromValue(m_interpolatorMode);
107 case IndexInterpolatorModeAsString:
return QVariant::fromValue(this->getInterpolatorModeAsString());
108 case IndexFixSceneryOffset:
return QVariant::fromValue(m_fixSceneryOffset);
109 case IndexPitchOnGround:
return QVariant::fromValue(m_pitchOnGround);
113 return QStringLiteral(
"Wrong index for %1").arg(i);
116 void CInterpolationAndRenderingSetupBase::setPropertyByIndex(
CPropertyIndexRef index,
const QVariant &variant)
121 case IndexLogInterpolation: m_logInterpolation = variant.toBool();
return;
122 case IndexSimulatorDebugMessages: m_simulatorDebugMessages = variant.toBool();
return;
123 case IndexForceFullInterpolation: m_forceFullInterpolation = variant.toBool();
return;
124 case IndexEnabledAircraftParts: m_enabledAircraftParts = variant.toBool();
return;
125 case IndexSendGndFlagToSimulator: m_sendGndToSim = variant.toBool();
return;
126 case IndexInterpolatorMode: m_interpolatorMode = variant.toInt();
return;
127 case IndexInterpolatorModeAsString: this->setInterpolatorMode(variant.toString());
return;
128 case IndexFixSceneryOffset: m_fixSceneryOffset = variant.toBool();
return;
129 case IndexPitchOnGround: m_pitchOnGround.setPropertyByIndex(index.
copyFrontRemoved(), variant);
return;
135 QString CInterpolationAndRenderingSetupBase::convertToQString(
bool i18n)
const
138 return QStringLiteral(
"Interpolator: ") % this->getInterpolatorModeAsString() %
139 QStringLiteral(
" | Dbg.sim.msgs: ") % boolToYesNo(m_simulatorDebugMessages) %
140 QStringLiteral(
" | log interpolation: ") % boolToYesNo(m_logInterpolation) %
141 QStringLiteral(
" | force VTOL interpolation: ") % boolToYesNo(m_forceFullInterpolation) %
142 QStringLiteral(
" | enable parts: ") % boolToYesNo(m_enabledAircraftParts) %
143 QStringLiteral(
" | send gnd: ") % boolToYesNo(m_sendGndToSim) %
144 QStringLiteral(
" | fix.scenery offset: ") % boolToYesNo(m_fixSceneryOffset) %
145 QStringLiteral(
" | pitch on gnd.: ") % m_pitchOnGround.valueRoundedWithUnit(CAngleUnit::deg(), 1,
true);
148 bool CInterpolationAndRenderingSetupBase::canHandleIndex(
int index)
150 return index >= CInterpolationAndRenderingSetupBase::IndexLogInterpolation &&
151 index <= CInterpolationAndRenderingSetupBase::IndexFixSceneryOffset;
154 CInterpolationAndRenderingSetupGlobal::CInterpolationAndRenderingSetupGlobal() {}
156 int CInterpolationAndRenderingSetupGlobal::InfiniteAircraft() {
return 100; }
158 bool CInterpolationAndRenderingSetupGlobal::isRenderingEnabled()
const
160 if (m_maxRenderedAircraft < 1) {
return false; }
161 if (!isMaxDistanceRestricted()) {
return true; }
162 return m_maxRenderedDistance.isPositiveWithEpsilonConsidered();
165 bool CInterpolationAndRenderingSetupGlobal::isRenderingRestricted()
const
167 return isRenderingEnabled() && (isMaxAircraftRestricted() || isMaxDistanceRestricted());
170 int CInterpolationAndRenderingSetupGlobal::getMaxRenderedAircraft()
const
172 return (m_maxRenderedAircraft <= InfiniteAircraft()) ? m_maxRenderedAircraft : InfiniteAircraft();
175 bool CInterpolationAndRenderingSetupGlobal::setMaxRenderedAircraft(
int maxRenderedAircraft)
177 if (maxRenderedAircraft == m_maxRenderedAircraft) {
return false; }
178 if (maxRenderedAircraft < 1)
181 this->disableRendering();
183 else if (maxRenderedAircraft >= InfiniteAircraft()) { m_maxRenderedAircraft = InfiniteAircraft(); }
184 else { m_maxRenderedAircraft = maxRenderedAircraft; }
188 bool CInterpolationAndRenderingSetupGlobal::setMaxRenderedDistance(
const CLength &distance)
191 if (distance == m_maxRenderedDistance) {
return false; }
194 m_maxRenderedDistance =
CLength(0.0,
nullptr);
199 this->disableRendering();
204 m_maxRenderedDistance = distance;
209 void CInterpolationAndRenderingSetupGlobal::clearMaxRenderedDistance()
211 this->setMaxRenderedDistance(
CLength(0.0,
nullptr));
214 bool CInterpolationAndRenderingSetupGlobal::isMaxAircraftRestricted()
const
216 return m_maxRenderedAircraft < InfiniteAircraft();
219 void CInterpolationAndRenderingSetupGlobal::clearAllRenderingRestrictions()
221 m_maxRenderedDistance =
CLength(0,
nullptr);
222 m_maxRenderedAircraft = InfiniteAircraft();
225 void CInterpolationAndRenderingSetupGlobal::disableRendering()
227 m_maxRenderedAircraft = 0;
228 m_maxRenderedDistance =
CLength(0, CLengthUnit::NM());
231 bool CInterpolationAndRenderingSetupGlobal::isMaxDistanceRestricted()
const
233 return !m_maxRenderedDistance.isNull();
236 QString CInterpolationAndRenderingSetupGlobal::getRenderRestrictionText()
const
238 if (!this->isRenderingRestricted()) {
return "none"; }
240 if (this->isMaxAircraftRestricted())
242 rt.append(QString::number(this->getMaxRenderedAircraft())).append(
" A/C");
244 if (this->isMaxDistanceRestricted())
246 if (!rt.isEmpty()) { rt.append(
" "); }
247 rt.append(this->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0));
264 QString CInterpolationAndRenderingSetupGlobal::convertToQString(
bool i18n)
const
267 return CInterpolationAndRenderingSetupBase::convertToQString(i18n) % QStringLiteral(
" max.aircraft:") %
268 QString::number(m_maxRenderedAircraft) % QStringLiteral(
" max.distance:") %
274 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
278 case IndexMaxRenderedAircraft:
return QVariant::fromValue(m_maxRenderedAircraft);
279 case IndexMaxRenderedDistance:
return QVariant::fromValue(m_maxRenderedDistance);
282 if (CInterpolationAndRenderingSetupBase::canHandleIndex(i))
284 return CInterpolationAndRenderingSetupBase::propertyByIndex(index);
286 return CValueObject::propertyByIndex(index);
289 void CInterpolationAndRenderingSetupGlobal::setPropertyByIndex(
CPropertyIndexRef index,
const QVariant &variant)
299 case IndexMaxRenderedAircraft: m_maxRenderedAircraft = variant.toInt();
return;
300 case IndexMaxRenderedDistance: m_maxRenderedDistance = variant.value<
CLength>();
return;
303 if (CInterpolationAndRenderingSetupBase::canHandleIndex(i))
305 CInterpolationAndRenderingSetupBase::setPropertyByIndex(index, variant);
308 CValueObject::setPropertyByIndex(index, variant);
311 CInterpolationAndRenderingSetupPerCallsign::CInterpolationAndRenderingSetupPerCallsign() {}
313 CInterpolationAndRenderingSetupPerCallsign::CInterpolationAndRenderingSetupPerCallsign(
325 diff.
push_back(IndexSimulatorDebugMessages);
329 diff.
push_back(IndexForceFullInterpolation);
333 diff.
push_back(IndexEnabledAircraftParts);
337 diff.
push_back(IndexSendGndFlagToSimulator);
351 const bool equal = il.
isEmpty();
357 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
368 const QVariant &variant)
Value object encapsulating a list of property indexes.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void push_back(const T &value)
Appends an element at the end of the sequence.
bool isEmpty() const
Synonym for empty.
Value object encapsulating information of a callsign.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
ColumnIndex
Base class enums.
bool hasAircraftPartsCapability() const
Supports aircraft parts?
Physical unit angle (radians, degrees)
Physical unit length (length)
bool isNegativeWithEpsilonConsidered() const
Value <= 0 epsilon considered.
bool isNull() const
Is quantity null?
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
bool isZeroEpsilonConsidered() const
Quantity value <= epsilon.
Value object for interpolator and rendering base class.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
ColumnIndex
Properties by index.
InterpolatorMode
Interpolator type.
bool logInterpolation() const
Log.interpolation.
bool isSendingGndFlagToSimulator() const
Send GND flag to simulator.
bool isFixingSceneryOffset() const
Fix scenery offset if it has been detected.
bool isAircraftPartsEnabled() const
Aircraft parts enabled (still requires the other aircraft to send parts)
InterpolatorMode getInterpolatorMode() const
Interpolator mode.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
const physical_quantities::CAngle & getPitchOnGround() const
Force a given pitch on ground.
bool showSimulatorDebugMessages() const
Debugging messages for simulation.
bool isForcingFullInterpolation() const
Full interpolation (skip optimizations like checking if aircraft moves etc.)
Value object for interpolator and rendering.
Value object for interpolator and rendering per callsign.
bool isEqualToGlobal(const CInterpolationAndRenderingSetupGlobal &globalSetup) const
Equal to global setup?
static const CInterpolationAndRenderingSetupPerCallsign & null()
NULL object.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
CPropertyIndexList unequalToGlobal(const CInterpolationAndRenderingSetupGlobal &globalSetup) const
Properties unequal to global setup.
#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.