refs #796, allow to toggle full interpolation

* add setup class, metadata registration, property index ...
* removed enableDebugMessages, added setInterpolatorSetup
* adjusted contexts
* used in interolator
This commit is contained in:
Klaus Basan
2016-11-05 01:26:03 +01:00
parent f1ce5fc173
commit 3f6cef1c9f
20 changed files with 241 additions and 79 deletions

View File

@@ -0,0 +1,71 @@
/* Copyright (C) 2016
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackmisc/interpolationsetup.h"
#include "stringutils.h"
namespace BlackMisc
{
CInterpolationAndRenderingSetup::CInterpolationAndRenderingSetup()
{ }
QString CInterpolationAndRenderingSetup::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
QString s("Setup: debug sim: ");
s += boolToYesNo(this->m_simulatorDebugMessages);
s += " debug interpolator: ";
s += boolToYesNo(this->m_interpolatorDebugMessage);
s += " force full interpolation: ";
s += boolToYesNo(this->m_forceFullInterpolation);
return s;
}
CVariant CInterpolationAndRenderingSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexInterpolatorDebugMessages:
return CVariant::fromValue(m_interpolatorDebugMessage);
case IndexSimulatorDebugMessages:
return CVariant::fromValue(m_simulatorDebugMessages);
case IndexForceFullInterpolation:
return CVariant::fromValue(m_forceFullInterpolation);
default:
return CValueObject::propertyByIndex(index);
}
}
void CInterpolationAndRenderingSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself())
{
*this = variant.value<CInterpolationAndRenderingSetup>();
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexInterpolatorDebugMessages:
this->m_interpolatorDebugMessage = variant.toBool();
break;
case IndexSimulatorDebugMessages:
this->m_simulatorDebugMessages = variant.toBool();
break;
case IndexForceFullInterpolation:
this->m_forceFullInterpolation = variant.toBool();
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
} // ns

View File

@@ -0,0 +1,83 @@
/* Copyright (C) 2016
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INTERPOLATION_SETUP_H
#define BLACKMISC_INTERPOLATION_SETUP_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/valueobject.h"
#include <QString>
namespace BlackMisc
{
/*!
* Value object for interpolator and rendering
*/
class BLACKMISC_EXPORT CInterpolationAndRenderingSetup :
public CValueObject<CInterpolationAndRenderingSetup>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexInterpolatorDebugMessages = BlackMisc::CPropertyIndex::GloablIndexInterpolatorSetup,
IndexSimulatorDebugMessages,
IndexForceFullInterpolation
};
//! Constructor.
CInterpolationAndRenderingSetup();
//! Debugging messages
bool showInterpolatorDebugMessages() const { return m_interpolatorDebugMessage; }
//! Debugging messages
void setInterpolatorDebuggingMessages(bool debug) { m_interpolatorDebugMessage = debug; }
//! Debugging messages
bool showSimulatorDebugMessages() const { return m_simulatorDebugMessages; }
//! Debugging messages
void setDriverDebuggingMessages(bool debug) { m_simulatorDebugMessages = debug; }
//! Full interpolation
bool forceFullInterpolation() const { return m_forceFullInterpolation; }
//! Force full interpolation
void setForceFullInterpolation(bool force) { m_forceFullInterpolation = force; }
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
private:
bool m_interpolatorDebugMessage = false; //! Debug messages in interpolator
bool m_simulatorDebugMessages = false; //! Debug messages of simulator (aka plugin)
bool m_forceFullInterpolation = false; //! always do a full interpolation, even if aircraft is not moving
BLACK_METACLASS(
CInterpolationAndRenderingSetup,
BLACK_METAMEMBER(interpolatorDebugMessage),
BLACK_METAMEMBER(simulatorDebugMessages),
BLACK_METAMEMBER(forceFullInterpolation)
);
};
} // namespace
Q_DECLARE_METATYPE(BlackMisc::CInterpolationAndRenderingSetup)
#endif // guard

View File

@@ -25,7 +25,7 @@ namespace BlackMisc
}
BlackMisc::Aviation::CAircraftSituation IInterpolator::getInterpolatedSituation(const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
bool isVtolAircraft, InterpolationStatus &status) const
bool isVtolAircraft, InterpolationStatus &status) const
{
// has to be thread safe
@@ -56,9 +56,16 @@ namespace BlackMisc
return this->remoteAircraftParts(callsign, cutoffTime);
}
void IInterpolator::enableDebugMessages(bool enabled)
void IInterpolator::setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup)
{
this->m_withDebugMsg = enabled;
QWriteLocker l(&m_lock);
m_setup = setup;
}
CInterpolationAndRenderingSetup IInterpolator::getInterpolatorSetup() const
{
QReadLocker l(&m_lock);
return m_setup;
}
bool IInterpolator::InterpolationStatus::allTrue() const
@@ -81,5 +88,4 @@ namespace BlackMisc
{
supportsParts = false;
}
} // namespace

View File

@@ -13,6 +13,7 @@
#define BLACKMISC_INTERPOLATOR_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/interpolationsetup.h"
#include "blackmisc/aviation/aircraftpartslist.h"
#include "blackmisc/aviation/aircraftsituation.h"
#include "blackmisc/simulation/remoteaircraftprovider.h"
@@ -65,18 +66,19 @@ namespace BlackMisc
void reset();
};
//! Current interpolated situation
//! \threadsafe
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc,
bool isVtolAircraft, InterpolationStatus &status) const = 0;
//! Current interpolated situation
//! \threadsafe
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
bool isVtolAircraft, InterpolationStatus &status) const;
//! Current interpolated situation, to be implemented by subclass
//! \threadsafe
//! \remark public only for XP driver
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc,
bool isVtolAircraft, InterpolationStatus &status) const = 0;
//! Parts before given offset time (aka pending parts)
//! \threadsafe
virtual BlackMisc::Aviation::CAircraftPartsList getPartsBeforeTime(
@@ -89,16 +91,21 @@ namespace BlackMisc
const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime,
PartsStatus &partsStatus) const;
//! Enable debug messages
void enableDebugMessages(bool enabled);
//! Enable debug messages etc.
//! \threadsafe
void setInterpolatorSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup);
protected:
//! Constructor
IInterpolator(BlackMisc::Simulation::IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent);
bool m_withDebugMsg = false; //!< allows to disable debug messages
};
//! Enable debug messages etc.
//! \threadsafe
BlackMisc::CInterpolationAndRenderingSetup getInterpolatorSetup() const;
BlackMisc::CInterpolationAndRenderingSetup m_setup; //!< allows to disable debug messages
mutable QReadWriteLock m_lock; //!< lock interpolator
};
} // namespace
#endif // guard

View File

@@ -39,7 +39,7 @@ namespace BlackMisc
CAircraftSituation CInterpolatorLinear::getInterpolatedSituation(const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeMsSinceEpoc, bool vtolAiracraft, InterpolationStatus &status) const
{
// has to be thread safe
const CInterpolationAndRenderingSetup setup = this->getInterpolatorSetup();
status.reset();
// any data at all?
@@ -107,7 +107,7 @@ namespace BlackMisc
double simulationTimeFraction = 1 - (distanceToSplitTime / deltaTime);
if (simulationTimeFraction > 2.0)
{
if (this->m_withDebugMsg)
if (setup.showInterpolatorDebugMessages())
{
CLogMessage(this).warning("Extrapolation, fraction > 1: %1 for callsign: %2") << simulationTimeFraction << oldSituation.getCallsign();
}
@@ -132,7 +132,7 @@ namespace BlackMisc
+ oldAlt,
oldAlt.getReferenceDatum()));
if (!vtolAiracraft && newVec == oldVec && oldAlt == newAlt)
if (!setup.forceFullInterpolation() && !vtolAiracraft && newVec == oldVec && oldAlt == newAlt)
{
// stop interpolation here, does not work for VTOL aircraft. We need a flag for VTOL aircraft
return currentSituation;

View File

@@ -35,11 +35,12 @@ namespace BlackMisc
IInterpolator(provider, "CInterpolatorLinear", parent)
{}
// public base class signature
using IInterpolator::getInterpolatedSituation;
//! \copydoc IInterpolator::getInterpolatedSituation
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc, bool vtolAiracraft, InterpolationStatus &status) const override;
using IInterpolator::getInterpolatedSituation;
//! Log category
static QString getLogCategory() { return "swift.interpolatorlinear"; }
};

View File

@@ -110,21 +110,21 @@ namespace BlackMisc
GlobalIndexICoordinateWithRelativePosition = 5100,
GlobalIndexCCoordinateGeodetic = 5200,
GlobalIndexCClient = 6000,
GlobalIndexClientCapabilities = 6050, //!< used with map key
GlobalIndexCUser = 6100,
GlobalIndexCAuthenticatedUser = 6200,
GlobalIndexCRole = 6300,
GlobalIndexCServer = 6400,
GlobalIndexCFsdSetup = 6500,
GlobalIndexCUrl = 6600,
GlobalIndexCAircraftModel = 6700,
GlobalIndexCSimulatedAircraft = 6800,
GlobalIndexCTextMessage = 6900,
GlobalIndexCSimulatorSetup = 7000,
GlobalIndexCSimulatorSettings = 7100,
GlobalIndexCSimulatorMessageSettings = 7200,
GlobalIndexCAircraftCfgEntries = 7300,
GlobalIndexCDistributor = 7400,
GlobalIndexClientCapabilities = 6100, //!< used with map key
GlobalIndexCUser = 6200,
GlobalIndexCAuthenticatedUser = 6300,
GlobalIndexCRole = 6400,
GlobalIndexCServer = 6500,
GlobalIndexCFsdSetup = 6600,
GlobalIndexCUrl = 6700,
GlobalIndexCAircraftModel = 6800,
GlobalIndexCSimulatedAircraft = 6900,
GlobalIndexCTextMessage = 7000,
GlobalIndexCSimulatorSetup = 7100,
GlobalIndexCSimulatorSettings = 7200,
GlobalIndexCSimulatorMessageSettings = 7300,
GlobalIndexCAircraftCfgEntries = 7400,
GlobalIndexCDistributor = 7500,
GlobalIndexCVPilotModelRule = 8000,
GlobalIndexCVoiceRoom = 9000,
GlobalIndexCSettingKeyboardHotkey = 10000,
@@ -139,6 +139,7 @@ namespace BlackMisc
GlobalIndexCDockWidgetSettings = 14200,
GlobalIndexCNavigatorSettings = 14300,
GlobalIndexCSettingsReaders = 14400,
GloablIndexInterpolatorSetup = 15000,
GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers
};

View File

@@ -34,12 +34,10 @@
namespace BlackMisc
{
class CPropertyIndexVariantMap;
namespace Mixin
{
/*!
* CRTP class template from which a derived class can inherit property indexing functions.
*

View File

@@ -21,6 +21,7 @@
#include "blackmisc/iconlist.h"
#include "blackmisc/identifier.h"
#include "blackmisc/identifierlist.h"
#include "blackmisc/interpolationsetup.h"
#include "blackmisc/input/registermetadatainput.h"
#include "blackmisc/logcategory.h"
#include "blackmisc/logcategorylist.h"
@@ -88,6 +89,7 @@ namespace BlackMisc
CVariant::registerMetadata();
CVariantList::registerMetadata();
CVariantMap::registerMetadata();
CInterpolationAndRenderingSetup::registerMetadata();
// sub namespaces
Audio::registerMetadata();