mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
OP-1554 Re-factoring
This commit is contained in:
parent
13881dee59
commit
77e876297e
@ -30,17 +30,19 @@
|
||||
#include <math.h>
|
||||
#include <QDebug>
|
||||
|
||||
PlotData::PlotData(QString objectName, QString fieldName, QString elementName,
|
||||
PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleOrderFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize) :
|
||||
m_scalePower(scaleOrderFactor), m_meanSamples(meanSamples),
|
||||
m_mathFunction(mathFunction), m_plotDataSize(plotDataSize),
|
||||
m_objectName(objectName), m_fieldName(fieldName),
|
||||
m_elementName(elementName), m_plotCurve(plotCurve)
|
||||
|
||||
m_object(object), m_field(field),
|
||||
m_element(element), m_plotCurve(plotCurve)
|
||||
{
|
||||
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
|
||||
|
||||
if (!field->getElementNames().isEmpty()) {
|
||||
m_elementName = field->getElementNames().at(element);
|
||||
}
|
||||
m_meanSum = 0.0f;
|
||||
m_correctionSum = 0.0f;
|
||||
m_correctionCount = 0;
|
||||
@ -51,17 +53,7 @@ PlotData::PlotData(QString objectName, QString fieldName, QString elementName,
|
||||
double PlotData::valueAsDouble(UAVObject *obj, UAVObjectField *field)
|
||||
{
|
||||
Q_UNUSED(obj);
|
||||
QVariant value;
|
||||
|
||||
if (!m_elementName.isEmpty()) {
|
||||
int indexOfSubField = field->getElementNames().indexOf(QRegExp(elementName(), Qt::CaseSensitive, QRegExp::FixedString));
|
||||
value = field->getValue(indexOfSubField);
|
||||
} else {
|
||||
value = field->getValue();
|
||||
}
|
||||
|
||||
// qDebug() << "Data (" << value.typeName() << ") " << value.toString();
|
||||
|
||||
QVariant value = field->getValue(m_element);
|
||||
return value.toDouble();
|
||||
}
|
||||
|
||||
@ -78,12 +70,9 @@ void PlotData::updatePlotCurveData()
|
||||
|
||||
bool SequentialPlotData::append(UAVObject *obj)
|
||||
{
|
||||
if (objectName() == obj->getName()) {
|
||||
// Get the field of interest
|
||||
UAVObjectField *field = obj->getField(fieldName());
|
||||
|
||||
if (field) {
|
||||
double currentValue = valueAsDouble(obj, field) * pow(10, m_scalePower);
|
||||
if (m_object == obj) {
|
||||
if (m_field) {
|
||||
double currentValue = valueAsDouble(m_object, m_field) * pow(10, m_scalePower);
|
||||
|
||||
// Perform scope math, if necessary
|
||||
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
||||
@ -137,14 +126,11 @@ bool SequentialPlotData::append(UAVObject *obj)
|
||||
|
||||
bool ChronoPlotData::append(UAVObject *obj)
|
||||
{
|
||||
if (objectName() == obj->getName()) {
|
||||
if (m_object == obj) {
|
||||
// Get the field of interest
|
||||
UAVObjectField *field = obj->getField(fieldName());
|
||||
// qDebug() << "uavObject: " << uavObject << ", uavField: " << uavField;
|
||||
|
||||
if (field) {
|
||||
if (m_field) {
|
||||
QDateTime NOW = QDateTime::currentDateTime(); // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
|
||||
double currentValue = valueAsDouble(obj, field) * pow(10, m_scalePower);
|
||||
double currentValue = valueAsDouble(m_object, m_field) * pow(10, m_scalePower);
|
||||
|
||||
// Perform scope math, if necessary
|
||||
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QVector>
|
||||
#include <uavdataobject.h>
|
||||
|
||||
/*!
|
||||
\brief Defines the different type of plots.
|
||||
@ -52,13 +53,14 @@ class PlotData : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlotData(QString objectName, QString fieldName, QString elementName,
|
||||
PlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleOrderFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize);
|
||||
~PlotData();
|
||||
|
||||
QString objectName() const { return m_objectName; }
|
||||
QString fieldName() const { return m_fieldName; }
|
||||
UAVObject *object() const { return m_object; }
|
||||
UAVObjectField *field() const { return m_field; }
|
||||
int element() const { return m_element; }
|
||||
QString elementName() const { return m_elementName; }
|
||||
|
||||
bool isVisible() const { return m_plotCurve->isVisible(); }
|
||||
@ -90,10 +92,12 @@ protected:
|
||||
QVector<double> m_yDataEntries;
|
||||
QVector<double> m_yDataHistory;
|
||||
|
||||
private:
|
||||
QString m_objectName;
|
||||
QString m_fieldName;
|
||||
UAVObject *m_object;
|
||||
UAVObjectField *m_field;
|
||||
int m_element;
|
||||
QString m_elementName;
|
||||
|
||||
private:
|
||||
double m_yMin;
|
||||
double m_yMax;
|
||||
QwtPlotCurve *m_plotCurve;
|
||||
@ -107,10 +111,10 @@ private:
|
||||
class SequentialPlotData : public PlotData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequentialPlotData(QString objectName, QString fieldName, QString elementName,
|
||||
SequentialPlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize)
|
||||
: PlotData(objectName, fieldName, elementName, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize) {}
|
||||
: PlotData(object, field, element, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize) {}
|
||||
~SequentialPlotData() {}
|
||||
|
||||
/*!
|
||||
@ -138,10 +142,10 @@ public:
|
||||
class ChronoPlotData : public PlotData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChronoPlotData(QString objectname, QString fieldname, QString elementName,
|
||||
ChronoPlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize)
|
||||
: PlotData(objectname, fieldname, elementName, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize)
|
||||
: PlotData(object, field, element, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize)
|
||||
{
|
||||
}
|
||||
~ChronoPlotData() {}
|
||||
|
@ -371,10 +371,13 @@ void ScopeGadgetWidget::setupChronoPlot()
|
||||
// scaleWidget->setMinBorderDist(0, fmw);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubField, int scaleFactor, int meanSamples, QString mathFunction, QPen pen, bool antialiased)
|
||||
void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubField, int scaleFactor,
|
||||
int meanSamples, QString mathFunction, QPen pen, bool antialiased)
|
||||
{
|
||||
QString fieldName = fieldPlusSubField;
|
||||
QString elementName;
|
||||
int element = 0;
|
||||
|
||||
if (fieldPlusSubField.contains("-")) {
|
||||
QStringList fieldSubfield = fieldName.split("-", QString::SkipEmptyParts);
|
||||
fieldName = fieldSubfield.at(0);
|
||||
@ -390,17 +393,28 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
// Get the uav object
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(objectName));
|
||||
if (!obj) {
|
||||
qDebug() << "Object " << objectName << " is missing";
|
||||
UAVDataObject *object = dynamic_cast<UAVDataObject *>(objManager->getObject(objectName));
|
||||
if (!object) {
|
||||
qDebug() << "Object" << objectName << "is missing";
|
||||
return;
|
||||
}
|
||||
UAVObjectField *field = obj->getField(fieldName);
|
||||
|
||||
UAVObjectField *field = object->getField(fieldName);
|
||||
if (!field) {
|
||||
qDebug() << "In scope gadget, in fields loaded from GCS config file, field" <<
|
||||
fieldName << " of object " << objectName << " is missing";
|
||||
fieldName << "of object" << objectName << "is missing";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!elementName.isEmpty()) {
|
||||
element = field->getElementNames().indexOf(QRegExp(elementName, Qt::CaseSensitive, QRegExp::FixedString));
|
||||
if (element < 0) {
|
||||
qDebug() << "In scope gadget, in fields loaded from GCS config file, field" <<
|
||||
fieldName << "of object" << objectName << "element name" << elementName << "is missing";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QString units = field->getUnits();
|
||||
|
||||
if (units == 0) {
|
||||
@ -426,10 +440,10 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
PlotData *plotData;
|
||||
|
||||
if (m_plotType == SequentialPlot) {
|
||||
plotData = new SequentialPlotData(objectName, fieldName, elementName, plotCurve, scaleFactor,
|
||||
plotData = new SequentialPlotData(object, field, element, plotCurve, scaleFactor,
|
||||
meanSamples, mathFunction, m_plotDataSize);
|
||||
} else if (m_plotType == ChronoPlot) {
|
||||
plotData = new ChronoPlotData(objectName, fieldName, elementName, plotCurve, scaleFactor,
|
||||
plotData = new ChronoPlotData(object, field, element, plotCurve, scaleFactor,
|
||||
meanSamples, mathFunction, m_plotDataSize);
|
||||
}
|
||||
|
||||
@ -442,9 +456,9 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
m_curvesData.insert(curveNameScaled, plotData);
|
||||
|
||||
// Link to the new signal data only if this UAVObject has not been connected yet
|
||||
if (!m_connectedUAVObjects.contains(obj->getName())) {
|
||||
m_connectedUAVObjects.append(obj->getName());
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *)));
|
||||
if (!m_connectedUAVObjects.contains(object->getName())) {
|
||||
m_connectedUAVObjects.append(object->getName());
|
||||
connect(object, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *)));
|
||||
}
|
||||
|
||||
mutex.lock();
|
||||
@ -609,7 +623,7 @@ int ScopeGadgetWidget::csvLoggingInsertHeader()
|
||||
foreach(PlotData * plotData2, m_curvesData.values()) {
|
||||
ts << ", ";
|
||||
ts << plotData2->objectName();
|
||||
ts << "." << plotData2->fieldName();
|
||||
ts << "." << plotData2->field()->getName();
|
||||
if (!plotData2->elementName().isEmpty()) {
|
||||
ts << "." << plotData2->elementName();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user