Ref T261, interpolator mode is now part of setup

* added attribute in setup
* adjusted UI
* adjusted interpolator / simulator functions
This commit is contained in:
Klaus Basan
2018-05-04 22:31:25 +02:00
committed by Roland Winklmeier
parent eb815ab987
commit 3d2a74a652
21 changed files with 175 additions and 270 deletions

View File

@@ -41,7 +41,34 @@ namespace BlackMisc
void CInterpolationAndRenderingSetupBase::consolidateWithClient(const CClient &client)
{
m_enabledAircraftParts &= client.hasAircraftPartsCapability();
// m_enabledGndFlag &= client.hasGndFlagCapability();
}
bool CInterpolationAndRenderingSetupBase::setInterpolatorMode(CInterpolationAndRenderingSetupBase::InterpolatorMode mode)
{
const int m = static_cast<int>(mode);
if (m_interpolatorMode == m) { return false; }
m_interpolatorMode = m;
return true;
}
bool CInterpolationAndRenderingSetupBase::setInterpolatorMode(const QString &mode)
{
if (mode.contains("spline", Qt::CaseInsensitive)) { return this->setInterpolatorMode(Spline); }
if (mode.contains("linear", Qt::CaseInsensitive)) { return this->setInterpolatorMode(Linear); }
return false;
}
const QString &CInterpolationAndRenderingSetupBase::modeToString(InterpolatorMode mode)
{
static const QString l("linear");
static const QString s("spline");
switch (mode)
{
case Linear: return l;
case Spline: return s;
default: return s;
}
}
bool CInterpolationAndRenderingSetupBase::setEnabledAircraftParts(bool enabled)
@@ -94,7 +121,8 @@ namespace BlackMisc
{
Q_UNUSED(i18n);
return
QStringLiteral("Dbg.sim.msgs: ") % boolToYesNo(m_simulatorDebugMessages) %
QStringLiteral("Interpolator: ") % this->getInterpolatorModeAsString() %
QStringLiteral(" | Dbg.sim.msgs: ") % boolToYesNo(m_simulatorDebugMessages) %
QStringLiteral(" | log interpolation: ") % boolToYesNo(m_logInterpolation) %
QStringLiteral(" | force full interpolation: ") % boolToYesNo(m_forceFullInterpolation) %
QStringLiteral(" | enable parts: ") % boolToYesNo(m_enabledAircraftParts) %

View File

@@ -36,7 +36,15 @@ namespace BlackMisc
IndexForceFullInterpolation,
IndexSendGndFlagToSimulator,
IndexEnableGndFlag,
IndexEnabledAircraftParts
IndexEnabledAircraftParts,
IndexInterpolatorMode
};
//! Interpolator type
enum InterpolatorMode
{
Spline,
Linear
};
//! Debugging messages for simulation
@@ -81,6 +89,18 @@ namespace BlackMisc
//! Consolidate with a network client
void consolidateWithClient(const Network::CClient &client);
//! Interpolator mode
InterpolatorMode getInterpolatorMode() const { return static_cast<InterpolatorMode>(m_interpolatorMode); }
//! Interpolator mode
const QString &getInterpolatorModeAsString() const { return modeToString(this->getInterpolatorMode()); }
//! Set interpolator mode
bool setInterpolatorMode(InterpolatorMode mode);
//! Set interpolator mode
bool setInterpolatorMode(const QString &mode);
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
@@ -90,6 +110,9 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
//! Interpolator mode as string
static const QString &modeToString(InterpolatorMode mode);
protected:
//! Constructor
CInterpolationAndRenderingSetupBase();
@@ -103,6 +126,7 @@ namespace BlackMisc
bool m_enabledAircraftParts = true; //!< Enable aircraft parts
bool m_enabledGndFlag = true; //!< Enable gnd.flag
bool m_sendGndToSim = true; //!< Send the gnd.flag to simulator
int m_interpolatorMode = static_cast<int>(Spline); //!< interpolator mode (spline, ...)
};
//! Value object for interpolator and rendering
@@ -184,6 +208,7 @@ namespace BlackMisc
BLACK_METAMEMBER(sendGndToSim),
BLACK_METAMEMBER(enabledAircraftParts),
BLACK_METAMEMBER(enabledGndFlag),
BLACK_METAMEMBER(interpolatorMode),
BLACK_METAMEMBER(maxRenderedAircraft),
BLACK_METAMEMBER(maxRenderedDistance)
);
@@ -241,7 +266,8 @@ namespace BlackMisc
BLACK_METAMEMBER(forceFullInterpolation),
BLACK_METAMEMBER(sendGndToSim),
BLACK_METAMEMBER(enabledAircraftParts),
BLACK_METAMEMBER(enabledGndFlag)
BLACK_METAMEMBER(enabledGndFlag),
BLACK_METAMEMBER(interpolatorMode)
);
};
} // namespace
@@ -249,5 +275,6 @@ namespace BlackMisc
Q_DECLARE_METATYPE(BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CInterpolationAndRenderingSetupBase::InterpolatorMode)
#endif // guard

View File

@@ -26,10 +26,10 @@ namespace BlackMisc
const CInterpolationAndRenderingSetupPerCallsign &setup,
CInterpolationStatus &status)
{
switch (m_mode)
switch (setup.getInterpolatorMode())
{
case ModeLinear: return m_linear.getInterpolatedSituation(currentTimeSinceEpoc, setup, status);
case ModeSpline: return m_spline.getInterpolatedSituation(currentTimeSinceEpoc, setup, status);
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getInterpolatedSituation(currentTimeSinceEpoc, setup, status);
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getInterpolatedSituation(currentTimeSinceEpoc, setup, status);
default: break;
}
return {};
@@ -39,11 +39,11 @@ namespace BlackMisc
qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup,
CPartsStatus &partsStatus, bool log) const
{
switch (m_mode)
switch (setup.getInterpolatorMode())
{
// currently calls the same interpolation for parts
case ModeLinear: return m_linear.getInterpolatedParts(currentTimeSinceEpoc, setup, partsStatus, log);
case ModeSpline: return m_spline.getInterpolatedParts(currentTimeSinceEpoc, setup, partsStatus, log);
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getInterpolatedParts(currentTimeSinceEpoc, setup, partsStatus, log);
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getInterpolatedParts(currentTimeSinceEpoc, setup, partsStatus, log);
default: break;
}
return {};
@@ -53,22 +53,22 @@ namespace BlackMisc
qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup,
CPartsStatus &partsStatus, bool log) const
{
switch (m_mode)
switch (setup.getInterpolatorMode())
{
// currently calls the same interpolation for parts
case ModeLinear: return m_linear.getInterpolatedOrGuessedParts(currentTimeSinceEpoc, setup, partsStatus, log);
case ModeSpline: return m_spline.getInterpolatedOrGuessedParts(currentTimeSinceEpoc, setup, partsStatus, log);
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getInterpolatedOrGuessedParts(currentTimeSinceEpoc, setup, partsStatus, log);
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getInterpolatedOrGuessedParts(currentTimeSinceEpoc, setup, partsStatus, log);
default: break;
}
return {};
}
const CAircraftSituation &CInterpolatorMulti::getLastInterpolatedSituation() const
const CAircraftSituation &CInterpolatorMulti::getLastInterpolatedSituation(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
{
switch (m_mode)
switch (mode)
{
case ModeLinear: return m_linear.getLastInterpolatedSituation();
case ModeSpline: return m_spline.getLastInterpolatedSituation();
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getLastInterpolatedSituation();
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getLastInterpolatedSituation();
default: break;
}
return CAircraftSituation::null();
@@ -86,63 +86,17 @@ namespace BlackMisc
m_spline.initCorrespondingModel(model);
}
bool CInterpolatorMulti::setMode(Mode mode)
QString CInterpolatorMulti::getInterpolatorInfo(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
{
if (m_mode == mode) { return false; }
m_mode = mode;
return true;
}
bool CInterpolatorMulti::setMode(const QString &mode)
{
Mode m = modeFromString(mode);
if (m == ModeUnknown) { return false; }
return setMode(m);
}
void CInterpolatorMulti::toggleMode()
{
switch (m_mode)
switch (mode)
{
case ModeSpline: m_mode = ModeLinear; break;
case ModeLinear: m_mode = ModeSpline; break;
default: m_mode = ModeSpline; break;
}
}
QString CInterpolatorMulti::getInterpolatorInfo() const
{
switch (m_mode)
{
case ModeSpline: return m_spline.getInterpolatorInfo();
case ModeLinear: return m_linear.getInterpolatorInfo();
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getInterpolatorInfo();
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getInterpolatorInfo();
default: break;
}
return ("Illegal mode");
}
CInterpolatorMulti::Mode CInterpolatorMulti::modeFromString(const QString &mode)
{
if (mode.contains("spli"), Qt::CaseInsensitive) { return ModeSpline; }
if (mode.contains("lin"), Qt::CaseInsensitive) { return ModeLinear; }
return ModeUnknown;
}
const QString &CInterpolatorMulti::modeToString(CInterpolatorMulti::Mode mode)
{
static const QString l("linear");
static const QString s("spline");
static const QString u("unknown");
switch (mode)
{
case ModeLinear: return l;
case ModeSpline: return s;
case ModeUnknown:
default: return u;
}
}
CInterpolatorMultiWrapper::CInterpolatorMultiWrapper()
{ }

View File

@@ -44,7 +44,7 @@ namespace BlackMisc
CPartsStatus &partsStatus, bool log) const;
//! \copydoc CInterpolator::getLastInterpolatedSituation
const Aviation::CAircraftSituation &getLastInterpolatedSituation() const;
const Aviation::CAircraftSituation &getLastInterpolatedSituation(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const;
//! \copydoc CInterpolator::attachLogger
void attachLogger(CInterpolationLogger *logger);
@@ -52,37 +52,10 @@ namespace BlackMisc
//! \copydoc CInterpolator::initCorrespondingModel
void initCorrespondingModel(const CAircraftModel &model);
//! Supported interpolation modes.
enum Mode
{
ModeSpline, //!< spline interpolation mode
ModeLinear, //!< linear interpolation mode
ModeUnknown
};
//! Set interpolation mode. Return true if mode was changed. Mode will not be changed in release build.
bool setMode(Mode mode);
//! Set interpolation mode. Return true if mode was changed. Mode will not be changed in release build.
bool setMode(const QString &mode);
//! Get active interpolation mode.
Mode getMode() const { return m_mode; }
//! Toogle interpolator Mode
void toggleMode();
//! Info string
QString getInterpolatorInfo() const;
//! Mode from string
static Mode modeFromString(const QString &mode);
//! Mode to string
static const QString &modeToString(Mode mode);
QString getInterpolatorInfo(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const;
private:
Mode m_mode = ModeSpline;
CInterpolatorSpline m_spline;
CInterpolatorLinear m_linear;
};