mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-22 14:19:42 +01:00
OP-1554 Re-factoring
This commit is contained in:
parent
482f8e3b29
commit
959f197502
@ -103,85 +103,62 @@ void PlotData::calcMathFunction(double currentValue)
|
||||
|
||||
bool SequentialPlotData::append(UAVObject *obj)
|
||||
{
|
||||
if (m_object == obj) {
|
||||
if (m_field) {
|
||||
double currentValue = valueAsDouble(m_object, m_field) * pow(10, m_scalePower);
|
||||
if (m_object == obj && 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") {
|
||||
calcMathFunction(currentValue);
|
||||
} else {
|
||||
m_yDataEntries.append(currentValue);
|
||||
}
|
||||
|
||||
if (m_yDataEntries.size() > m_plotDataSize) {
|
||||
// If new data overflows the window, remove old data...
|
||||
m_yDataEntries.pop_front();
|
||||
} else {
|
||||
// ...otherwise, add a new y point at position xData
|
||||
m_xDataEntries.insert(m_xDataEntries.size(), m_xDataEntries.size());
|
||||
}
|
||||
|
||||
return true;
|
||||
// Perform scope math, if necessary
|
||||
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
||||
calcMathFunction(currentValue);
|
||||
} else {
|
||||
m_yDataEntries.append(currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_yDataEntries.size() > m_plotDataSize) {
|
||||
// If new data overflows the window, remove old data...
|
||||
m_yDataEntries.pop_front();
|
||||
} else {
|
||||
// ...otherwise, add a new y point at position xData
|
||||
m_xDataEntries.insert(m_xDataEntries.size(), m_xDataEntries.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChronoPlotData::append(UAVObject *obj)
|
||||
{
|
||||
if (m_object == obj) {
|
||||
if (m_object == obj && m_field) {
|
||||
// Get the field of interest
|
||||
if (m_field) {
|
||||
QDateTime NOW = QDateTime::currentDateTime(); // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
|
||||
double currentValue = valueAsDouble(m_object, m_field) * pow(10, m_scalePower);
|
||||
QDateTime NOW = QDateTime::currentDateTime(); // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
|
||||
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") {
|
||||
calcMathFunction(currentValue);
|
||||
} else {
|
||||
m_yDataEntries.append(currentValue);
|
||||
}
|
||||
|
||||
double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
|
||||
m_xDataEntries.append(valueX);
|
||||
|
||||
// Remove stale data
|
||||
removeStaleData();
|
||||
return true;
|
||||
// Perform scope math, if necessary
|
||||
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
||||
calcMathFunction(currentValue);
|
||||
} else {
|
||||
m_yDataEntries.append(currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
|
||||
m_xDataEntries.append(valueX);
|
||||
|
||||
// Remove stale data
|
||||
removeStaleData();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChronoPlotData::removeStaleData()
|
||||
{
|
||||
double newestValue;
|
||||
double oldestValue;
|
||||
|
||||
while (1) {
|
||||
if (m_xDataEntries.size() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
newestValue = m_xDataEntries.last();
|
||||
oldestValue = m_xDataEntries.first();
|
||||
|
||||
if (newestValue - oldestValue > m_plotDataSize) {
|
||||
while (!m_xDataEntries.isEmpty() &&
|
||||
(m_xDataEntries.last() - m_xDataEntries.first()) > m_plotDataSize) {
|
||||
m_yDataEntries.pop_front();
|
||||
m_xDataEntries.pop_front();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// qDebug() << "removeStaleData ";
|
||||
}
|
||||
|
||||
void ChronoPlotData::removeStaleDataTimeout()
|
||||
{
|
||||
removeStaleData();
|
||||
// qDebug() << "removeStaleDataTimeout";
|
||||
}
|
||||
|
@ -97,7 +97,6 @@ ScopeGadgetWidget::~ScopeGadgetWidget()
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
foreach(QString uavObjName, m_connectedUAVObjects) {
|
||||
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(uavObjName));
|
||||
|
||||
disconnect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *)));
|
||||
}
|
||||
|
||||
@ -180,33 +179,24 @@ void ScopeGadgetWidget::showEvent(QShowEvent *e)
|
||||
*/
|
||||
void ScopeGadgetWidget::startPlotting()
|
||||
{
|
||||
if (!replotTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!replotTimer->isActive()) {
|
||||
if (replotTimer && !replotTimer->isActive()) {
|
||||
replotTimer->start(m_refreshInterval);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::stopPlotting()
|
||||
{
|
||||
if (!replotTimer) {
|
||||
return;
|
||||
if (replotTimer) {
|
||||
replotTimer->stop();
|
||||
}
|
||||
|
||||
replotTimer->stop();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::deleteLegend()
|
||||
{
|
||||
if (!legend()) {
|
||||
return;
|
||||
if (legend()) {
|
||||
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
|
||||
insertLegend(NULL, QwtPlot::TopLegend);
|
||||
}
|
||||
|
||||
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
|
||||
|
||||
insertLegend(NULL, QwtPlot::TopLegend);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::addLegend()
|
||||
@ -292,12 +282,6 @@ void ScopeGadgetWidget::setupSequentialPlot()
|
||||
{
|
||||
preparePlot(SequentialPlot);
|
||||
|
||||
// QwtText title("Index");
|
||||
//// title.setFont(QFont("Helvetica", 20));
|
||||
// title.font().setPointSize(title.font().pointSize() / 2);
|
||||
// setAxisTitle(QwtPlot::xBottom, title);
|
||||
//// setAxisTitle(QwtPlot::xBottom, "Index");
|
||||
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
|
||||
setAxisScale(QwtPlot::xBottom, 0, m_plotDataSize);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, 0.0);
|
||||
@ -319,22 +303,13 @@ void ScopeGadgetWidget::setupChronoPlot()
|
||||
{
|
||||
preparePlot(ChronoPlot);
|
||||
|
||||
// QwtText title("Time [h:m:s]");
|
||||
//// title.setFont(QFont("Helvetica", 20));
|
||||
// title.font().setPointSize(title.font().pointSize() / 2);
|
||||
// setAxisTitle(QwtPlot::xBottom, title);
|
||||
//// setAxisTitle(QwtPlot::xBottom, "Time [h:m:s]");
|
||||
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
|
||||
uint NOW = QDateTime::currentDateTime().toTime_t();
|
||||
setAxisScale(QwtPlot::xBottom, NOW - m_plotDataSize / 1000, NOW);
|
||||
// setAxisLabelRotation(QwtPlot::xBottom, -15.0);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, 0.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
// setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignCenter | Qt::AlignBottom);
|
||||
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
// QwtScaleDraw *scaleDraw = axisScaleDraw();
|
||||
|
||||
// reduce the gap between the scope canvas and the axis scale
|
||||
scaleWidget->setMargin(0);
|
||||
@ -344,31 +319,6 @@ void ScopeGadgetWidget::setupChronoPlot()
|
||||
fnt.setPointSize(7);
|
||||
setAxisFont(QwtPlot::xBottom, fnt); // x-axis
|
||||
setAxisFont(QwtPlot::yLeft, fnt); // y-axis
|
||||
|
||||
// set the axis colours .. can't seem to change the background colour :(
|
||||
// QPalette pal = scaleWidget->palette();
|
||||
// QPalette::ColorRole cr = scaleWidget->backgroundRole();
|
||||
// pal.setColor(cr, QColor(128, 128, 128)); // background colour
|
||||
// cr = scaleWidget->foregroundRole();
|
||||
// pal.setColor(cr, QColor(255, 255, 255)); // tick colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
// scaleWidget->setPalette(pal);
|
||||
|
||||
/*
|
||||
In situations, when there is a label at the most right position of the
|
||||
scale, additional space is needed to display the overlapping part
|
||||
of the label would be taken by reducing the width of scale and canvas.
|
||||
To avoid this "jumping canvas" effect, we add a permanent margin.
|
||||
We don't need to do the same for the left border, because there
|
||||
is enough space for the overlapping label below the left scale.
|
||||
*/
|
||||
|
||||
// const int fmh = QFontMetrics(scaleWidget->font()).height();
|
||||
// scaleWidget->setMinBorderDist(0, fmh / 2);
|
||||
|
||||
// const int fmw = QFontMetrics(scaleWidget->font()).width(" 00:00:00 ");
|
||||
// const int fmw = QFontMetrics(scaleWidget->font()).width(" ");
|
||||
// scaleWidget->setMinBorderDist(0, fmw);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubField, int scaleFactor,
|
||||
@ -495,8 +445,6 @@ void ScopeGadgetWidget::replotNewData()
|
||||
setAxisScale(QwtPlot::xBottom, toTime - m_plotDataSize, toTime);
|
||||
}
|
||||
|
||||
// qDebug() << "replotNewData from " << NOW.addSecs(- m_xWindowSize) << " to " << NOW;
|
||||
|
||||
csvLoggingInsertData();
|
||||
|
||||
replot();
|
||||
@ -574,7 +522,6 @@ int ScopeGadgetWidget::csvLoggingStart()
|
||||
PathCheck.mkpath("./");
|
||||
}
|
||||
|
||||
|
||||
if (m_csvLoggingNameSet) {
|
||||
m_csvLoggingFile.setFileName(QString("%1/%2_%3_%4.csv").arg(m_csvLoggingPath).arg(m_csvLoggingName).arg(NOW.toString("yyyy-MM-dd")).arg(NOW.toString("hh-mm-ss")));
|
||||
} else {
|
||||
|
@ -48,8 +48,8 @@ bool ScopePlugin::initialize(const QStringList & args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new ScopeGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
m_scopeFactory = new ScopeGadgetFactory(this);
|
||||
addAutoReleasedObject(m_scopeFactory);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class ScopeGadgetFactory;
|
||||
|
||||
class ScopePlugin : public ExtensionSystem::IPlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "OpenPilot.Scope")
|
||||
Q_PLUGIN_METADATA(IID "OpenPilot.Scope")
|
||||
|
||||
public:
|
||||
ScopePlugin();
|
||||
@ -45,7 +45,7 @@ public:
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
ScopeGadgetFactory *mf;
|
||||
ScopeGadgetFactory *m_scopeFactory;
|
||||
};
|
||||
|
||||
#endif /* SCOPEPLUGIN_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user