1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-27 16:54:15 +01:00

OP-1554 Changed some visuals.

Fixed logging to include enum types.
This commit is contained in:
m_thread 2014-10-31 10:14:46 +01:00
parent 3e6c5debc5
commit 5d89a78649
3 changed files with 83 additions and 36 deletions

View File

@ -37,7 +37,7 @@ PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
m_meanSum(0.0f), m_mathFunction(mathFunction), m_correctionSum(0.0f), m_meanSum(0.0f), m_mathFunction(mathFunction), m_correctionSum(0.0f),
m_correctionCount(0), m_plotDataSize(plotDataSize), m_correctionCount(0), m_plotDataSize(plotDataSize),
m_object(object), m_field(field), m_element(element), m_object(object), m_field(field), m_element(element),
m_plotCurve(NULL), m_isVisible(true), m_pen(pen), isEnumPlot(false) m_plotCurve(NULL), m_isVisible(true), m_pen(pen), m_isEnumPlot(false)
{ {
if (!m_field->getNumElements() > 1) { if (!m_field->getNumElements() > 1) {
m_elementName = m_field->getElementNames().at(m_element); m_elementName = m_field->getElementNames().at(m_element);
@ -63,7 +63,7 @@ PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
m_plotCurve->setPen(m_pen); m_plotCurve->setPen(m_pen);
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries); m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
isEnumPlot = m_field->getType() == UAVObjectField::ENUM; m_isEnumPlot = m_field->getType() == UAVObjectField::ENUM;
} }
PlotData::~PlotData() PlotData::~PlotData()
@ -91,6 +91,22 @@ void PlotData::updatePlotData()
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries); m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
} }
bool PlotData::hasData() const {
if (!m_isEnumPlot) {
return !m_xDataEntries.isEmpty();
} else {
return !m_enumMarkerList.isEmpty();
}
}
QString PlotData::lastDataAsString() {
if (!m_isEnumPlot) {
return QString().sprintf("%3.10g", m_yDataEntries.last());
} else {
return m_enumMarkerList.last()->title().text();
}
}
void PlotData::attach(QwtPlot *plot) void PlotData::attach(QwtPlot *plot)
{ {
m_plotCurve->attach(plot); m_plotCurve->attach(plot);
@ -138,10 +154,33 @@ void PlotData::calcMathFunction(double currentValue)
} }
} }
bool SequentialPlotData::append(UAVObject *obj, QwtPlot *plot) QwtPlotMarker *PlotData::createMarker(QString value)
{
QwtPlotMarker *marker = new QwtPlotMarker(value);
marker->setZ(10);
QwtText label(QString(" %1 ").arg(value));
label.setColor(QColor(Qt::black));
label.setBorderPen(QPen(m_pen.color(), 1));
label.setBorderRadius(2);
QColor labelBackColor = QColor(Qt::white);
labelBackColor.setAlpha(200);
label.setBackgroundBrush(labelBackColor);
QFont fnt(label.font());
fnt.setPointSize(8);
label.setFont(fnt);
marker->setLabel(label);
marker->setTitle(value);
marker->setLabelOrientation(Qt::Vertical);
marker->setLabelAlignment(Qt::AlignBottom);
marker->setLineStyle(QwtPlotMarker::VLine);
marker->setLinePen(QPen(m_pen.color(), 1, Qt::DashDotLine));
return marker;
}
bool SequentialPlotData::append(UAVObject *obj)
{ {
if (m_object == obj && m_field) { if (m_object == obj && m_field) {
if (!isEnumPlot) { if (!m_isEnumPlot) {
double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower); double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower);
// Perform scope math, if necessary // Perform scope math, if necessary
@ -160,20 +199,34 @@ bool SequentialPlotData::append(UAVObject *obj, QwtPlot *plot)
} }
return true; return true;
} else { } else {
// Enum markers
QString value = m_field->getValue(m_element).toString();
QwtPlotMarker *marker = m_enumMarkerList.isEmpty() ? NULL : m_enumMarkerList.last();
if (!marker || marker->title() != value) {
marker = createMarker(value);
marker->setXValue(m_enumMarkerList.size());
if (m_plotCurve->isVisible()) {
marker->attach(m_plotCurve->plot());
}
m_enumMarkerList.append(marker);
}
} }
} }
return false; return false;
} }
bool ChronoPlotData::append(UAVObject *obj, QwtPlot *plot) bool ChronoPlotData::append(UAVObject *obj)
{ {
if (m_object == obj && m_field) { if (m_object == obj && m_field) {
// Get the field of interest // Get the field of interest
QDateTime NOW = QDateTime::currentDateTime(); // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
QDateTime NOW = QDateTime::currentDateTime();
double xValue = NOW.toTime_t() + NOW.time().msec() / 1000.0; double xValue = NOW.toTime_t() + NOW.time().msec() / 1000.0;
if (!isEnumPlot) { if (!m_isEnumPlot) {
double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower); double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower);
// Perform scope math, if necessary // Perform scope math, if necessary
@ -185,38 +238,24 @@ bool ChronoPlotData::append(UAVObject *obj, QwtPlot *plot)
m_xDataEntries.append(xValue); m_xDataEntries.append(xValue);
// Remove stale data
removeStaleData();
return true;
} else { } else {
// Enum markers // Enum markers
QString value = m_field->getValue(m_element).toString(); QString value = m_field->getValue(m_element).toString();
QwtPlotMarker *marker = m_enumMarkerList.isEmpty() ? NULL : m_enumMarkerList.last(); QwtPlotMarker *marker = m_enumMarkerList.isEmpty() ? NULL : m_enumMarkerList.last();
if (!marker || marker->title() != value) { if (!marker || marker->title() != value) {
marker = new QwtPlotMarker(value);
QwtText label(QString(" %1 ").arg(value)); marker = createMarker(value);
label.setColor(QColor(Qt::black));
label.setBorderPen(QPen(QColor(Qt::black), 1));
label.setBorderRadius(3);
QColor labelBackColor = QColor(Qt::white);
labelBackColor.setAlpha(160);
label.setBackgroundBrush(labelBackColor);
label.font().setPointSize(7);
marker->setLabel(label);
marker->setTitle(value);
marker->setLabelOrientation(Qt::Vertical);
marker->setLabelAlignment(Qt::AlignTop);
marker->setLineStyle(QwtPlotMarker::VLine);
marker->setXValue(xValue); marker->setXValue(xValue);
marker->setLinePen(QPen(m_pen.color(), 1, Qt::DashLine));
if (m_plotCurve->isVisible()) { if (m_plotCurve->isVisible()) {
marker->attach(plot); marker->attach(m_plotCurve->plot());
} }
m_enumMarkerList.append(marker); m_enumMarkerList.append(marker);
} }
removeStaleData();
} }
removeStaleData();
return true;
} }
return false; return false;
} }

View File

@ -68,14 +68,16 @@ public:
bool isVisible() const; bool isVisible() const;
void setVisible(bool visible); void setVisible(bool visible);
virtual bool append(UAVObject *obj, QwtPlot* plot) = 0; bool wantsInitialData() { return m_isEnumPlot; }
virtual bool append(UAVObject *obj) = 0;
virtual PlotType plotType() const = 0; virtual PlotType plotType() const = 0;
virtual void removeStaleData() = 0; virtual void removeStaleData() = 0;
void updatePlotData(); void updatePlotData();
bool hasData() const { return !m_xDataEntries.isEmpty(); } bool hasData() const;
double lastData() { return m_yDataEntries.last(); } QString lastDataAsString();
void attach(QwtPlot *plot); void attach(QwtPlot *plot);
@ -105,8 +107,10 @@ protected:
QList<QwtPlotMarker *> m_enumMarkerList; QList<QwtPlotMarker *> m_enumMarkerList;
bool m_isVisible; bool m_isVisible;
QPen m_pen; QPen m_pen;
bool isEnumPlot; bool m_isEnumPlot;
virtual void calcMathFunction(double currentValue); virtual void calcMathFunction(double currentValue);
QwtPlotMarker *createMarker(QString value);
}; };
/*! /*!
@ -123,7 +127,7 @@ public:
mathFunction, plotDataSize, pen, antialiased) {} mathFunction, plotDataSize, pen, antialiased) {}
~SequentialPlotData() {} ~SequentialPlotData() {}
bool append(UAVObject *obj, QwtPlot* plot); bool append(UAVObject *obj);
PlotType plotType() const { return SequentialPlot; } PlotType plotType() const { return SequentialPlot; }
void removeStaleData() {} void removeStaleData() {}
}; };
@ -143,7 +147,7 @@ public:
} }
~ChronoPlotData() {} ~ChronoPlotData() {}
bool append(UAVObject *obj, QwtPlot* plot); bool append(UAVObject *obj);
PlotType plotType() const { return ChronoPlot; } PlotType plotType() const { return ChronoPlot; }
void removeStaleData(); void removeStaleData();
}; };

View File

@ -363,11 +363,15 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
} else if (m_plotType == ChronoPlot) { } else if (m_plotType == ChronoPlot) {
plotData = new ChronoPlotData(object, field, element, scaleFactor, plotData = new ChronoPlotData(object, field, element, scaleFactor,
meanSamples, mathFunction, m_plotDataSize, meanSamples, mathFunction, m_plotDataSize,
pen, antialiased); pen, antialiased);
} }
connect(this, SIGNAL(visibilityChanged(QwtPlotItem*)), plotData, SLOT(visibilityChanged(QwtPlotItem*))); connect(this, SIGNAL(visibilityChanged(QwtPlotItem*)), plotData, SLOT(visibilityChanged(QwtPlotItem*)));
plotData->attach(this); plotData->attach(this);
if (plotData->wantsInitialData()) {
plotData->append(object);
}
// Keep the curve details for later // Keep the curve details for later
m_curvesData.insert(plotData->plotName(), plotData); m_curvesData.insert(plotData->plotName(), plotData);
@ -385,7 +389,7 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
void ScopeGadgetWidget::uavObjectReceived(UAVObject *obj) void ScopeGadgetWidget::uavObjectReceived(UAVObject *obj)
{ {
foreach(PlotData * plotData, m_curvesData.values()) { foreach(PlotData * plotData, m_curvesData.values()) {
if (plotData->append(obj, this)) { if (plotData->append(obj)) {
m_csvLoggingDataUpdated = 1; m_csvLoggingDataUpdated = 1;
} }
} }
@ -564,7 +568,7 @@ int ScopeGadgetWidget::csvLoggingAddData()
foreach(PlotData * plotData2, m_curvesData.values()) { foreach(PlotData * plotData2, m_curvesData.values()) {
ss << ", "; ss << ", ";
if (plotData2->hasData()) { if (plotData2->hasData()) {
ss << QString().sprintf("%3.10g", plotData2->lastData()); ss << plotData2->lastDataAsString();
m_csvLoggingDataValid = true; m_csvLoggingDataValid = true;
} }
} }