mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
OP-42 GCS/Scope: The completed basic set of features to make this plug-in usable.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@978 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
13168b6b4c
commit
760fc69cba
@ -1,138 +1,133 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file plotdata.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of plotdata.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "plotdata.h"
|
||||
#include <math.h>
|
||||
|
||||
PlotData::PlotData(QString* p_uavObject, QString* p_uavField)
|
||||
{
|
||||
uavObject = new QString(*p_uavObject);
|
||||
uavField = new QString(*p_uavField);
|
||||
|
||||
xData = new QVector<double>();
|
||||
yData = new QVector<double>();
|
||||
|
||||
curve = 0;
|
||||
scalePower = 0;
|
||||
yMinimum = 0;
|
||||
yMaximum = 0;
|
||||
|
||||
m_xWindowSize = 0;
|
||||
}
|
||||
|
||||
PlotData::~PlotData()
|
||||
{
|
||||
delete uavObject;
|
||||
delete uavField;
|
||||
delete xData;
|
||||
delete yData;
|
||||
}
|
||||
|
||||
|
||||
bool SequencialPlotData::append(UAVObject* obj)
|
||||
{
|
||||
if (*uavObject == obj->getName()) {
|
||||
//Get the field of interest
|
||||
UAVObjectField* field = obj->getField(*uavField);
|
||||
|
||||
if (field) {
|
||||
//Shift data forward and put the new value at the front
|
||||
yData->append(field->getDouble() * pow(10, scalePower));
|
||||
if (yData->size() > m_xWindowSize) {
|
||||
yData->pop_front();
|
||||
|
||||
//Make the x-axis values scroll...
|
||||
//xData->append( xData->last() + 1 );
|
||||
//xData->pop_front();
|
||||
} else
|
||||
xData->insert(xData->size(), xData->size());
|
||||
|
||||
dataChanged();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChronoPlotData::append(UAVObject* obj)
|
||||
{
|
||||
if (*uavObject == obj->getName()) {
|
||||
//Get the field of interest
|
||||
UAVObjectField* field = obj->getField(*uavField);
|
||||
|
||||
if (field) {
|
||||
//Put the new value at the front
|
||||
QDateTime NOW = QDateTime::currentDateTime();
|
||||
|
||||
double newestValue = NOW.toTime_t() + NOW.time().msec() / 1000.0;
|
||||
xData->append(newestValue);
|
||||
yData->append(field->getDouble() * pow(10, scalePower));
|
||||
|
||||
//Remove stale data
|
||||
removeStaleData();
|
||||
|
||||
dataChanged();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChronoPlotData::removeStaleData()
|
||||
{
|
||||
double newestValue;
|
||||
double oldestValue;
|
||||
|
||||
while (1) {
|
||||
if (xData->size() == 0)
|
||||
break;
|
||||
|
||||
newestValue = xData->last();
|
||||
oldestValue = xData->first();
|
||||
|
||||
if (newestValue - oldestValue > m_xWindowSize) {
|
||||
yData->pop_front();
|
||||
xData->pop_front();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ChronoPlotData::removeStaleDataTimeout()
|
||||
{
|
||||
removeStaleData();
|
||||
dataChanged();
|
||||
}
|
||||
|
||||
bool UAVObjectPlotData::append(UAVObject* obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file plotdata.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Implementation of plotdata.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "plotdata.h"
|
||||
#include <math.h>
|
||||
|
||||
PlotData::PlotData(QString p_uavObject, QString p_uavField)
|
||||
{
|
||||
uavObject = p_uavObject;
|
||||
uavField = p_uavField;
|
||||
|
||||
xData = new QVector<double>();
|
||||
yData = new QVector<double>();
|
||||
|
||||
curve = 0;
|
||||
scalePower = 0;
|
||||
yMinimum = 0;
|
||||
yMaximum = 0;
|
||||
|
||||
m_xWindowSize = 0;
|
||||
}
|
||||
|
||||
PlotData::~PlotData()
|
||||
{
|
||||
delete xData;
|
||||
delete yData;
|
||||
}
|
||||
|
||||
|
||||
bool SequencialPlotData::append(UAVObject* obj)
|
||||
{
|
||||
if (uavObject == obj->getName()) {
|
||||
//Get the field of interest
|
||||
UAVObjectField* field = obj->getField(uavField);
|
||||
|
||||
if (field) {
|
||||
//Shift data forward and put the new value at the front
|
||||
yData->append(field->getDouble() * pow(10, scalePower));
|
||||
if (yData->size() > m_xWindowSize) {
|
||||
yData->pop_front();
|
||||
} else
|
||||
xData->insert(xData->size(), xData->size());
|
||||
|
||||
//notify the gui of changes in the data
|
||||
dataChanged();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChronoPlotData::append(UAVObject* obj)
|
||||
{
|
||||
if (uavObject == obj->getName()) {
|
||||
//Get the field of interest
|
||||
UAVObjectField* field = obj->getField(uavField);
|
||||
|
||||
if (field) {
|
||||
//Put the new value at the front
|
||||
QDateTime NOW = QDateTime::currentDateTime();
|
||||
|
||||
double newestValue = NOW.toTime_t() + NOW.time().msec() / 1000.0;
|
||||
xData->append(newestValue);
|
||||
yData->append(field->getDouble() * pow(10, scalePower));
|
||||
|
||||
//Remove stale data
|
||||
removeStaleData();
|
||||
|
||||
//notify the gui of chages in the data
|
||||
dataChanged();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChronoPlotData::removeStaleData()
|
||||
{
|
||||
double newestValue;
|
||||
double oldestValue;
|
||||
|
||||
while (1) {
|
||||
if (xData->size() == 0)
|
||||
break;
|
||||
|
||||
newestValue = xData->last();
|
||||
oldestValue = xData->first();
|
||||
|
||||
if (newestValue - oldestValue > m_xWindowSize) {
|
||||
yData->pop_front();
|
||||
xData->pop_front();
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ChronoPlotData::removeStaleDataTimeout()
|
||||
{
|
||||
removeStaleData();
|
||||
dataChanged();
|
||||
}
|
||||
|
||||
bool UAVObjectPlotData::append(UAVObject* obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1,142 +1,162 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file plotdata.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Object that manages the data for a curve.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PLOTDATA_H
|
||||
#define PLOTDATA_H
|
||||
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/altitudeactual.h"
|
||||
#include "uavobjects/positionactual.h"
|
||||
|
||||
|
||||
#include "qwt/src/qwt.h"
|
||||
#include "qwt/src/qwt_plot.h"
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_scale_draw.h"
|
||||
#include "qwt/src/qwt_scale_widget.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QVector>
|
||||
|
||||
enum PlotType {
|
||||
SequencialPlot,
|
||||
ChronoPlot,
|
||||
UAVObjectPlot,
|
||||
|
||||
NPlotTypes
|
||||
};
|
||||
|
||||
|
||||
class PlotData : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlotData(QString* uavObject, QString* uavField);
|
||||
~PlotData();
|
||||
|
||||
QString* uavObject;
|
||||
QString* uavField;
|
||||
QwtPlotCurve* curve;
|
||||
QVector<double>* xData;
|
||||
QVector<double>* yData;
|
||||
int scalePower; //This is the power to wich each value must be raised
|
||||
double yMinimum;
|
||||
double yMaximum;
|
||||
|
||||
double m_xWindowSize;
|
||||
|
||||
virtual bool append(UAVObject* obj) = 0;
|
||||
virtual PlotType plotType() = 0;
|
||||
|
||||
signals:
|
||||
void dataChanged();
|
||||
};
|
||||
|
||||
class SequencialPlotData : public PlotData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequencialPlotData(QString* uavObject, QString* uavField)
|
||||
: PlotData(uavObject, uavField) {}
|
||||
~SequencialPlotData() {}
|
||||
|
||||
bool append(UAVObject* obj);
|
||||
|
||||
virtual PlotType plotType() {
|
||||
return SequencialPlot;
|
||||
}
|
||||
};
|
||||
|
||||
class ChronoPlotData : public PlotData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChronoPlotData(QString* uavObject, QString* uavField)
|
||||
: PlotData(uavObject, uavField) {
|
||||
scalePower = 1;
|
||||
//Setup timer
|
||||
timer = new QTimer();
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(removeStaleDataTimeout()));
|
||||
timer->start(100);
|
||||
}
|
||||
~ChronoPlotData() {
|
||||
delete timer;
|
||||
}
|
||||
|
||||
bool append(UAVObject* obj);
|
||||
|
||||
virtual PlotType plotType() {
|
||||
return ChronoPlot;
|
||||
}
|
||||
private:
|
||||
//QDateTime m_epoch;
|
||||
void removeStaleData();
|
||||
|
||||
QTimer *timer;
|
||||
|
||||
private slots:
|
||||
void removeStaleDataTimeout();
|
||||
};
|
||||
|
||||
class UAVObjectPlotData : public PlotData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UAVObjectPlotData(QString* uavObject, QString* uavField)
|
||||
: PlotData(uavObject, uavField) {}
|
||||
~UAVObjectPlotData() {}
|
||||
|
||||
bool append(UAVObject* obj);
|
||||
|
||||
virtual PlotType plotType() {
|
||||
return UAVObjectPlot;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PLOTDATA_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file plotdata.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Object that manages the data for a curve.
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PLOTDATA_H
|
||||
#define PLOTDATA_H
|
||||
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/altitudeactual.h"
|
||||
#include "uavobjects/positionactual.h"
|
||||
|
||||
|
||||
#include "qwt/src/qwt.h"
|
||||
#include "qwt/src/qwt_plot.h"
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_scale_draw.h"
|
||||
#include "qwt/src/qwt_scale_widget.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QVector>
|
||||
|
||||
/*!
|
||||
\brief Defines the different type of plots.
|
||||
*/
|
||||
enum PlotType {
|
||||
SequencialPlot,
|
||||
ChronoPlot,
|
||||
UAVObjectPlot,
|
||||
|
||||
NPlotTypes
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief Base class that keeps the data for each curve in the plot.
|
||||
*/
|
||||
class PlotData : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlotData(QString uavObject, QString uavField);
|
||||
~PlotData();
|
||||
|
||||
QString uavObject;
|
||||
QString uavField;
|
||||
int scalePower; //This is the power to which each value must be raised
|
||||
double yMinimum;
|
||||
double yMaximum;
|
||||
double m_xWindowSize;
|
||||
QwtPlotCurve* curve;
|
||||
QVector<double>* xData;
|
||||
QVector<double>* yData;
|
||||
|
||||
virtual bool append(UAVObject* obj) = 0;
|
||||
virtual PlotType plotType() = 0;
|
||||
|
||||
signals:
|
||||
void dataChanged();
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief The sequencial plot have a fixed size buffer of data. All the curves in one plot
|
||||
have the same size buffer.
|
||||
*/
|
||||
class SequencialPlotData : public PlotData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequencialPlotData(QString uavObject, QString uavField)
|
||||
: PlotData(uavObject, uavField) {}
|
||||
~SequencialPlotData() {}
|
||||
|
||||
/*!
|
||||
\brief Append new data to the plot
|
||||
*/
|
||||
bool append(UAVObject* obj);
|
||||
|
||||
/*!
|
||||
\brief The type of plot
|
||||
*/
|
||||
virtual PlotType plotType() {
|
||||
return SequencialPlot;
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief The chrono plot have a variable sized buffer of data, where the data is for a specified time period.
|
||||
*/
|
||||
class ChronoPlotData : public PlotData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChronoPlotData(QString uavObject, QString uavField, double refreshInterval)
|
||||
: PlotData(uavObject, uavField) {
|
||||
scalePower = 1;
|
||||
//Setup timer that removes stale data
|
||||
timer = new QTimer();
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(removeStaleDataTimeout()));
|
||||
timer->start(refreshInterval * 1000);
|
||||
}
|
||||
~ChronoPlotData() {
|
||||
delete timer;
|
||||
}
|
||||
|
||||
bool append(UAVObject* obj);
|
||||
|
||||
virtual PlotType plotType() {
|
||||
return ChronoPlot;
|
||||
}
|
||||
private:
|
||||
void removeStaleData();
|
||||
|
||||
QTimer *timer;
|
||||
|
||||
private slots:
|
||||
void removeStaleDataTimeout();
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief UAVObject plot use a fixed size buffer of data, where the horizontal axis values come from
|
||||
a UAVObject field.
|
||||
*/
|
||||
class UAVObjectPlotData : public PlotData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UAVObjectPlotData(QString uavObject, QString uavField)
|
||||
: PlotData(uavObject, uavField) {}
|
||||
~UAVObjectPlotData() {}
|
||||
|
||||
bool append(UAVObject* obj);
|
||||
|
||||
virtual PlotType plotType() {
|
||||
return UAVObjectPlot;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PLOTDATA_H
|
||||
|
@ -1,40 +1,67 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "scopegadget.h"
|
||||
#include "scopegadgetwidget.h"
|
||||
|
||||
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
ScopeGadget::~ScopeGadget()
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "scopegadget.h"
|
||||
#include "scopegadgetconfiguration.h"
|
||||
#include "scopegadgetwidget.h"
|
||||
|
||||
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration*>(config);
|
||||
ScopeGadgetWidget* widget = qobject_cast<ScopeGadgetWidget*>(m_widget);
|
||||
|
||||
widget->setXWindowSize(sgConfig->dataSize());
|
||||
widget->setRefreshInterval(sgConfig->refreshInterval());
|
||||
|
||||
if(sgConfig->plotType() == SequencialPlot )
|
||||
widget->setupSequencialPlot();
|
||||
else if(sgConfig->plotType() == ChronoPlot)
|
||||
widget->setupChronoPlot();
|
||||
// else if(sgConfig->plotType() == UAVObjectPlot)
|
||||
// widget->setupUAVObjectPlot();
|
||||
|
||||
foreach (PlotCurveConfiguration* plotCurveConfig, sgConfig->plotCurveConfigs()) {
|
||||
|
||||
QString uavObject = plotCurveConfig->uavObject;
|
||||
QString uavField = plotCurveConfig->uavField;
|
||||
int scale = plotCurveConfig->yScalePower;
|
||||
QRgb color = plotCurveConfig->color;
|
||||
|
||||
widget->addCurvePlot(uavObject,uavField,scale,QPen(QColor(color)));
|
||||
}
|
||||
}
|
||||
|
||||
ScopeGadget::~ScopeGadget()
|
||||
{
|
||||
|
||||
}
|
@ -1,65 +1,67 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadget.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SCOPEGADGET_H_
|
||||
#define SCOPEGADGET_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
class IUAVGadget;
|
||||
//class QList<int>;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class ScopeGadgetWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ScopeGadget : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent = 0);
|
||||
~ScopeGadget();
|
||||
|
||||
QList<int> context() const {
|
||||
return m_context;
|
||||
}
|
||||
QWidget *widget() {
|
||||
return m_widget;
|
||||
}
|
||||
QString contextHelpId() const {
|
||||
return QString();
|
||||
}
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
QList<int> m_context;
|
||||
};
|
||||
|
||||
|
||||
#endif // SCOPEGADGET_H_
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadget.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SCOPEGADGET_H_
|
||||
#define SCOPEGADGET_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
class IUAVGadget;
|
||||
//class QList<int>;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class ScopeGadgetWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ScopeGadget : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent = 0);
|
||||
~ScopeGadget();
|
||||
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
QList<int> context() const {
|
||||
return m_context;
|
||||
}
|
||||
QWidget *widget() {
|
||||
return m_widget;
|
||||
}
|
||||
QString contextHelpId() const {
|
||||
return QString();
|
||||
}
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
QList<int> m_context;
|
||||
};
|
||||
|
||||
|
||||
#endif // SCOPEGADGET_H_
|
@ -1,72 +1,166 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetconfiguration.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "scopegadgetconfiguration.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a configuration.
|
||||
*
|
||||
*/
|
||||
IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
|
||||
{
|
||||
ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId());
|
||||
//m->m_defaultDial=m_defaultDial;
|
||||
return m;
|
||||
}
|
||||
/**
|
||||
* Saves a configuration.
|
||||
*
|
||||
*/
|
||||
QByteArray ScopeGadgetConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
// QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
// stream << m_defaultDial;
|
||||
// stream << dialBackgroundID;
|
||||
// stream << dialForegroundID;
|
||||
// stream << dialNeedleID1;
|
||||
// stream << dialNeedleID2;
|
||||
// stream << needle1MinValue;
|
||||
// stream << needle1MaxValue;
|
||||
// stream << needle2MinValue;
|
||||
// stream << needle2MaxValue;
|
||||
// stream << needle1DataObject;
|
||||
// stream << needle1ObjectField;
|
||||
// stream << needle2DataObject;
|
||||
// stream << needle2ObjectField;
|
||||
// stream << needle1Factor;
|
||||
// stream << needle2Factor;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetconfiguration.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "scopegadgetconfiguration.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
|
||||
ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_plotType((int)ChronoPlot),
|
||||
m_dataSize(60),
|
||||
m_refreshInterval(1)
|
||||
{
|
||||
uint currentStreamVersion = 0;
|
||||
int plotCurveCount = 0;
|
||||
|
||||
if (state.count() > 0) {
|
||||
|
||||
QDataStream stream(state);
|
||||
stream >> currentStreamVersion;
|
||||
|
||||
if(currentStreamVersion != m_configurationStreamVersion)
|
||||
return;
|
||||
|
||||
stream >> m_plotType;
|
||||
stream >> m_dataSize;
|
||||
stream >> m_refreshInterval;
|
||||
stream >> plotCurveCount;
|
||||
|
||||
while(plotCurveCount-- > 0)
|
||||
{
|
||||
QString uavObject;
|
||||
QString uavField;
|
||||
QRgb color;
|
||||
|
||||
PlotCurveConfiguration* plotCurveConf = new PlotCurveConfiguration();
|
||||
stream >> uavObject;
|
||||
plotCurveConf->uavObject = uavObject;
|
||||
stream >> uavField;
|
||||
plotCurveConf->uavField = uavField;
|
||||
stream >> color;
|
||||
plotCurveConf->color = color;
|
||||
stream >> plotCurveConf->yScalePower;
|
||||
stream >> plotCurveConf->yMinimum;
|
||||
stream >> plotCurveConf->yMaximum;
|
||||
|
||||
m_PlotCurveConfigs.append(plotCurveConf);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScopeGadgetConfiguration::clearPlotData()
|
||||
{
|
||||
PlotCurveConfiguration* poltCurveConfig;
|
||||
|
||||
while(m_PlotCurveConfigs.size() > 0)
|
||||
{
|
||||
poltCurveConfig = m_PlotCurveConfigs.first();
|
||||
m_PlotCurveConfigs.pop_front();
|
||||
|
||||
delete poltCurveConfig;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a configuration.
|
||||
*
|
||||
*/
|
||||
IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
|
||||
{
|
||||
int plotCurveCount = 0;
|
||||
int plotDatasLoadIndex = 0;
|
||||
|
||||
ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId());
|
||||
m->setPlotType(m_plotType);
|
||||
m->setDataSize( m_dataSize);
|
||||
m->setRefreashInterval( m_refreshInterval);
|
||||
|
||||
plotCurveCount = m_PlotCurveConfigs.size();
|
||||
|
||||
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++)
|
||||
{
|
||||
PlotCurveConfiguration* currentPlotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex);
|
||||
|
||||
PlotCurveConfiguration* newPlotCurveConf = new PlotCurveConfiguration();
|
||||
newPlotCurveConf->uavObject = currentPlotCurveConf->uavObject;
|
||||
newPlotCurveConf->uavField = currentPlotCurveConf->uavField;
|
||||
newPlotCurveConf->color = currentPlotCurveConf->color;
|
||||
newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower;
|
||||
newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum;
|
||||
newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum;
|
||||
|
||||
m->addPlotCurveConfig(newPlotCurveConf);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a configuration.
|
||||
*
|
||||
*/
|
||||
QByteArray ScopeGadgetConfiguration::saveState() const
|
||||
{
|
||||
int plotCurveCount = m_PlotCurveConfigs.size();
|
||||
int plotDatasLoadIndex = 0;
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << m_configurationStreamVersion;
|
||||
stream << m_plotType;
|
||||
stream << m_dataSize;
|
||||
stream << m_refreshInterval;
|
||||
stream << plotCurveCount;
|
||||
|
||||
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++)
|
||||
{
|
||||
PlotCurveConfiguration* plotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex);
|
||||
|
||||
stream << plotCurveConf->uavObject;
|
||||
stream << plotCurveConf->uavField;
|
||||
stream << plotCurveConf->color;
|
||||
stream << plotCurveConf->yScalePower;
|
||||
stream << plotCurveConf->yMinimum;
|
||||
stream << plotCurveConf->yMaximum;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration*> newPlotCurveConfigs)
|
||||
{
|
||||
clearPlotData();
|
||||
|
||||
m_PlotCurveConfigs.append(newPlotCurveConfigs);
|
||||
}
|
||||
|
||||
ScopeGadgetConfiguration::~ScopeGadgetConfiguration()
|
||||
{
|
||||
clearPlotData();
|
||||
}
|
||||
|
@ -1,46 +1,85 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetconfiguration.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SCOPEGADGETCONFIGURATION_H
|
||||
#define SCOPEGADGETCONFIGURATION_H
|
||||
|
||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ScopeGadgetConfiguration : public IUAVGadgetConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScopeGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||
|
||||
|
||||
QByteArray saveState() const;
|
||||
IUAVGadgetConfiguration *clone();
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETCONFIGURATION_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetconfiguration.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SCOPEGADGETCONFIGURATION_H
|
||||
#define SCOPEGADGETCONFIGURATION_H
|
||||
|
||||
#include "plotdata.h"
|
||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||
|
||||
#include <QVector>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
struct PlotCurveConfiguration
|
||||
{
|
||||
QString uavObject;
|
||||
QString uavField;
|
||||
int yScalePower; //This is the power to which each value must be raised
|
||||
QRgb color;
|
||||
double yMinimum;
|
||||
double yMaximum;
|
||||
};
|
||||
|
||||
class ScopeGadgetConfiguration : public IUAVGadgetConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScopeGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||
~ScopeGadgetConfiguration();
|
||||
|
||||
//configuration setter functions
|
||||
void setPlotType(int value){m_plotType = value;}
|
||||
void setDataSize(int value){m_dataSize = value;}
|
||||
void setRefreashInterval(int value){m_refreshInterval = value;}
|
||||
void addPlotCurveConfig(PlotCurveConfiguration* value){m_PlotCurveConfigs.append(value);}
|
||||
void replacePlotCurveConfig(QList<PlotCurveConfiguration*> m_PlotCurveConfigs);
|
||||
|
||||
|
||||
//configurations getter functions
|
||||
int plotType(){return m_plotType;}
|
||||
int dataSize(){return m_dataSize;}
|
||||
int refreshInterval(){return m_refreshInterval;}
|
||||
QList<PlotCurveConfiguration*> plotCurveConfigs(){return m_PlotCurveConfigs;}
|
||||
|
||||
QByteArray saveState() const;
|
||||
IUAVGadgetConfiguration *clone();
|
||||
|
||||
private:
|
||||
|
||||
static const uint m_configurationStreamVersion = 1000;//Increment this if the stream format is not compatible with previous versions. This would cause existing configs to be discarded.
|
||||
int m_plotType; //The type of the plot
|
||||
int m_dataSize; //The size of the data buffer to render in the curve plot
|
||||
int m_refreshInterval; //The interval to replot the curve widget. The data buffer is refresh as the data comes in.
|
||||
QList<PlotCurveConfiguration*> m_PlotCurveConfigs;
|
||||
|
||||
void clearPlotData();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETCONFIGURATION_H
|
@ -1,75 +1,266 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetoptionspage.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "scopegadgetoptionspage.h"
|
||||
#include "scopegadgetconfiguration.h"
|
||||
#include "ui_scopegadgetoptionspage.h"
|
||||
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavdataobject.h"
|
||||
|
||||
ScopeGadgetOptionsPage::ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
{
|
||||
//nothing to do here...
|
||||
}
|
||||
|
||||
//creates options page widget (uses the UI file)
|
||||
QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
options_page = new Ui::ScopeGadgetOptionsPage();
|
||||
//main widget
|
||||
QWidget *optionsPageWidget = new QWidget;
|
||||
//main layout
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
//TODO: Rest of the init stuff here
|
||||
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user presses apply or OK.
|
||||
*
|
||||
* Saves the current values
|
||||
*
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::apply()
|
||||
{
|
||||
|
||||
//Apply configuration changes
|
||||
// m_config->setDialFile(options_page->svgSourceFile->text());
|
||||
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::finish()
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetoptionspage.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "scopegadgetoptionspage.h"
|
||||
#include "scopegadgetconfiguration.h"
|
||||
#include "ui_scopegadgetoptionspage.h"
|
||||
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavdataobject.h"
|
||||
|
||||
|
||||
|
||||
ScopeGadgetOptionsPage::ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
{
|
||||
//nothing to do here...
|
||||
}
|
||||
|
||||
//creates options page widget (uses the UI file)
|
||||
QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
options_page = new Ui::ScopeGadgetOptionsPage();
|
||||
//main widget
|
||||
QWidget *optionsPageWidget = new QWidget;
|
||||
//main layout
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
options_page->cmbPlotType->addItem("Sequencial Plot","");
|
||||
options_page->cmbPlotType->addItem("Chronological Plot","");
|
||||
|
||||
// Fills the combo boxes for the UAVObjects
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
|
||||
foreach (QList<UAVDataObject*> list, objList) {
|
||||
foreach (UAVDataObject* obj, list) {
|
||||
options_page->cmbUAVObjects->addItem(obj->getName());
|
||||
}
|
||||
}
|
||||
|
||||
//Connect signals to slots cmbUAVObjects.currentIndexChanged
|
||||
connect(options_page->cmbUAVObjects, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_cmbUAVObjects_currentIndexChanged(QString)));
|
||||
|
||||
if(options_page->cmbUAVObjects->currentIndex() >= 0)
|
||||
on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText());
|
||||
|
||||
options_page->cmbColor->addItem("Black", QVariant(qRgb(0,0,0)));
|
||||
options_page->cmbColor->addItem("Red", QVariant(qRgb(255,0,0)));
|
||||
options_page->cmbColor->addItem("Green", QVariant(qRgb(0,255,0)));
|
||||
options_page->cmbColor->addItem("Blue", QVariant(qRgb(0,0,255)));
|
||||
|
||||
options_page->cmbScale->addItem("E-9", -9);
|
||||
options_page->cmbScale->addItem("E-6", -6);
|
||||
options_page->cmbScale->addItem("E-5",-5);
|
||||
options_page->cmbScale->addItem("E-4",-4);
|
||||
options_page->cmbScale->addItem("E-3",-3);
|
||||
options_page->cmbScale->addItem("E-2",-2);
|
||||
options_page->cmbScale->addItem("E-1",-1);
|
||||
options_page->cmbScale->addItem("E0",0);
|
||||
options_page->cmbScale->addItem("E1",1);
|
||||
options_page->cmbScale->addItem("E2",2);
|
||||
options_page->cmbScale->addItem("E3",3);
|
||||
options_page->cmbScale->addItem("E4",4);
|
||||
options_page->cmbScale->addItem("E5",5);
|
||||
options_page->cmbScale->addItem("E6",6);
|
||||
options_page->cmbScale->addItem("E9",9);
|
||||
options_page->cmbScale->addItem("E12",12);
|
||||
options_page->cmbScale->setCurrentIndex(7);
|
||||
|
||||
//Set widget values from settings
|
||||
options_page->cmbPlotType->setCurrentIndex(m_config->plotType());
|
||||
options_page->spnDataSize->setValue(m_config->dataSize());
|
||||
options_page->spnRefreshInterval->setValue(m_config->refreshInterval());
|
||||
|
||||
//add the configured curves
|
||||
foreach (PlotCurveConfiguration* plotData, m_config->plotCurveConfigs()) {
|
||||
|
||||
QString uavObject = plotData->uavObject;
|
||||
QString uavField = plotData->uavField;
|
||||
int scale = plotData->yScalePower;
|
||||
QVariant varColor = plotData->color;
|
||||
|
||||
addPlotCurveConfig(uavObject,uavField,scale,varColor);
|
||||
}
|
||||
|
||||
|
||||
connect(options_page->btnAddCurve, SIGNAL(clicked()), this, SLOT(on_btnAddCurve_clicked()));
|
||||
connect(options_page->btnRemoveCurve, SIGNAL(clicked()), this, SLOT(on_btnRemoveCurve_clicked()));
|
||||
connect(options_page->lstCurves, SIGNAL(currentRowChanged(int)), this, SLOT(on_lstCurves_currentRowChanged(int)));
|
||||
|
||||
setYAxisWidgetFromPlotCurve();
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Populate the widgets that containts the configs for the Y-Axis from
|
||||
the selected plot curve
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
|
||||
{
|
||||
QListWidgetItem* listItem = options_page->lstCurves->currentItem();
|
||||
|
||||
if(listItem == 0)
|
||||
return;
|
||||
|
||||
int currentIndex = options_page->cmbUAVObjects->findText( listItem->data(Qt::UserRole + 0).toString());
|
||||
options_page->cmbUAVObjects->setCurrentIndex(currentIndex);
|
||||
|
||||
currentIndex = options_page->cmbUAVField->findText( listItem->data(Qt::UserRole + 1).toString());
|
||||
options_page->cmbUAVField->setCurrentIndex(currentIndex);
|
||||
|
||||
currentIndex = options_page->cmbScale->findData( listItem->data(Qt::UserRole + 2), Qt::UserRole, Qt::MatchExactly);
|
||||
options_page->cmbScale->setCurrentIndex(currentIndex);
|
||||
|
||||
currentIndex = options_page->cmbColor->findData( listItem->data(Qt::UserRole + 3), Qt::UserRole, Qt::MatchExactly);
|
||||
options_page->cmbColor->setCurrentIndex(currentIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief When a new UAVObject is selected, populate the UAVObject field combo box with the correct values.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged(QString val)
|
||||
{
|
||||
options_page->cmbUAVField->clear();
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
|
||||
|
||||
QList<UAVObjectField*> fieldList = obj->getFields();
|
||||
foreach (UAVObjectField* field, fieldList) {
|
||||
options_page->cmbUAVField->addItem(field->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user presses apply or OK.
|
||||
*
|
||||
* Saves the current values
|
||||
*
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::apply()
|
||||
{
|
||||
|
||||
bool parseOK = false;
|
||||
|
||||
//Apply configuration changes
|
||||
m_config->setPlotType(options_page->cmbPlotType->currentIndex());
|
||||
m_config->setDataSize(options_page->spnDataSize->value());
|
||||
m_config->setRefreashInterval(options_page->spnRefreshInterval->value());
|
||||
|
||||
QList<PlotCurveConfiguration*> m_PlotCurveConfigs;
|
||||
for(int iIndex = 0; iIndex < options_page->lstCurves->count();iIndex++) {
|
||||
QListWidgetItem* listItem = options_page->lstCurves->item(iIndex);
|
||||
|
||||
PlotCurveConfiguration* newPlotCurveConfigs = new PlotCurveConfiguration();
|
||||
newPlotCurveConfigs->uavObject = listItem->data(Qt::UserRole + 0).toString();
|
||||
newPlotCurveConfigs->uavField = listItem->data(Qt::UserRole + 1).toString();
|
||||
newPlotCurveConfigs->yScalePower = listItem->data(Qt::UserRole + 2).toInt(&parseOK);
|
||||
if(!parseOK)
|
||||
newPlotCurveConfigs->yScalePower = 0;
|
||||
|
||||
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
||||
int rgb = varColor.toInt(&parseOK);
|
||||
if(!parseOK)
|
||||
newPlotCurveConfigs->color = QColor(Qt::black).rgb();
|
||||
else
|
||||
newPlotCurveConfigs->color = (QRgb)rgb;
|
||||
|
||||
m_PlotCurveConfigs.append(newPlotCurveConfigs);
|
||||
}
|
||||
|
||||
m_config->replacePlotCurveConfig(m_PlotCurveConfigs);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Add a new curve to the plot.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
|
||||
{
|
||||
bool parseOK = false;
|
||||
QString uavObject = options_page->cmbUAVObjects->currentText();
|
||||
QString uavField = options_page->cmbUAVField->currentText();
|
||||
int scale = options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK);
|
||||
|
||||
if(!parseOK)
|
||||
scale = 0;
|
||||
|
||||
//TODO: Find an existing plot curve config based on the uavobject and uav field. If it
|
||||
//exists, update it, else add a new one.
|
||||
|
||||
QVariant varColor = options_page->cmbColor->itemData(options_page->cmbColor->currentIndex());
|
||||
|
||||
addPlotCurveConfig(uavObject,uavField,scale,varColor);
|
||||
|
||||
options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1);
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor)
|
||||
{
|
||||
bool parseOK = false;
|
||||
|
||||
//Add a new curve config to the list
|
||||
QString listItemDisplayText = uavObject + "." + uavField;
|
||||
options_page->lstCurves->addItem(listItemDisplayText);
|
||||
QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1);
|
||||
|
||||
//Set the properties of the newly added list item
|
||||
QColor color = QColor( (QRgb)varColor.toInt(&parseOK) );
|
||||
listWidgetItem->setText(listItemDisplayText);
|
||||
listWidgetItem->setTextColor( color );
|
||||
|
||||
//Store some additional data for the plot curve on the list item
|
||||
listWidgetItem->setData(Qt::UserRole + 0,QVariant(uavObject));
|
||||
listWidgetItem->setData(Qt::UserRole + 1,QVariant(uavField));
|
||||
listWidgetItem->setData(Qt::UserRole + 2,QVariant(scale));
|
||||
listWidgetItem->setData(Qt::UserRole + 3,varColor);
|
||||
}
|
||||
|
||||
/*!
|
||||
Remove a curve config from the plot.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_btnRemoveCurve_clicked()
|
||||
{
|
||||
options_page->lstCurves->takeItem(options_page->lstCurves->currentIndex().row());
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::finish()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
When a different plot curve config is selected, populate its values into the widgets.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_lstCurves_currentRowChanged(int currentRow)
|
||||
{
|
||||
setYAxisWidgetFromPlotCurve();
|
||||
}
|
||||
|
@ -1,66 +1,76 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetoptionspage.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SCOPEGADGETOPTIONSPAGE_H
|
||||
#define SCOPEGADGETOPTIONSPAGE_H
|
||||
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include "QString"
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class IUAVGadgetConfiguration;
|
||||
}
|
||||
|
||||
class ScopeGadgetConfiguration;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ScopeGadgetOptionsPage;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ScopeGadgetOptionsPage : public IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent = 0);
|
||||
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
private:
|
||||
Ui::ScopeGadgetOptionsPage *options_page;
|
||||
ScopeGadgetConfiguration *m_config;
|
||||
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETOPTIONSPAGE_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetoptionspage.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SCOPEGADGETOPTIONSPAGE_H
|
||||
#define SCOPEGADGETOPTIONSPAGE_H
|
||||
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class IUAVGadgetConfiguration;
|
||||
}
|
||||
|
||||
class ScopeGadgetConfiguration;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ScopeGadgetOptionsPage;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ScopeGadgetOptionsPage : public IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent = 0);
|
||||
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
private:
|
||||
Ui::ScopeGadgetOptionsPage *options_page;
|
||||
ScopeGadgetConfiguration *m_config;
|
||||
|
||||
void addPlotCurveConfig(QString uavObject, QString uavField, int scale, QVariant varColor);
|
||||
void setYAxisWidgetFromPlotCurve();
|
||||
|
||||
|
||||
|
||||
private slots:
|
||||
void on_lstCurves_currentRowChanged(int currentRow);
|
||||
void on_btnRemoveCurve_clicked();
|
||||
void on_btnAddCurve_clicked();
|
||||
void on_cmbUAVObjects_currentIndexChanged(QString val);
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETOPTIONSPAGE_H
|
@ -1,239 +1,238 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ScopeGadgetOptionsPage</class>
|
||||
<widget class="QWidget" name="ScopeGadgetOptionsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>653</width>
|
||||
<height>580</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>531</width>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="formLayoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>20</y>
|
||||
<width>251</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Chronological Plot</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Sequencial Plot</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Plot Type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>5000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>300</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Data Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_2">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Refresh Time:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>160</y>
|
||||
<width>481</width>
|
||||
<height>131</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>UAVObject:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBox_2"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboBox_4"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>UAVField:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBox_3"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Scale:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="comboBox_5"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>>></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string><<</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="batchSize">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>140</y>
|
||||
<width>81</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Bitstream Charter</family>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Plot curves</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>62</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Bitstream Charter</family>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X-Axis</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ScopeGadgetOptionsPage</class>
|
||||
<widget class="QWidget" name="ScopeGadgetOptionsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>653</width>
|
||||
<height>580</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>531</width>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="formLayoutWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>20</y>
|
||||
<width>251</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cmbPlotType"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Plot Type:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="spnDataSize">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>5000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>300</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Data Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spnRefreshInterval">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Data Timeout:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>160</y>
|
||||
<width>481</width>
|
||||
<height>102</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>UAVObject:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="cmbUAVObjects"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="cmbColor"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>UAVField:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cmbUAVField"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Scale:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="cmbScale">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnAddCurve">
|
||||
<property name="text">
|
||||
<string>>></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRemoveCurve">
|
||||
<property name="text">
|
||||
<string><<</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="lstCurves">
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectItems</enum>
|
||||
</property>
|
||||
<property name="batchSize">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>140</y>
|
||||
<width>81</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Bitstream Charter</family>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Plot curves</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>62</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Bitstream Charter</family>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X-Axis</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,315 +1,300 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetwidget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Gadget Widget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
//#include "uavobjects/uavobject.h"
|
||||
//#include "uavobjects/uavdataobject.h"
|
||||
//#include "uavobjects/uavobjectfield.h"
|
||||
//#include "uavobjects/uavmetaobject.h"
|
||||
|
||||
#include "scopegadgetwidget.h"
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_legend.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QPushButton>
|
||||
|
||||
|
||||
TestDataGen* ScopeGadgetWidget::testDataGen;
|
||||
|
||||
ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
||||
{
|
||||
//setupExamplePlot();
|
||||
//Setup defaults
|
||||
//setupSequencialPlot();
|
||||
setupChronoPlot();
|
||||
addCurvePlot(QString("AltitudeActual"), QString("Altitude"), -1, QPen(Qt::blue));
|
||||
addCurvePlot(QString("AltitudeActual"), QString("Temperature"), 0, QPen(Qt::red));
|
||||
|
||||
//if(testDataGen == 0)
|
||||
// testDataGen = new TestDataGen();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
||||
{
|
||||
m_plotType = plotType;
|
||||
|
||||
clearCurvePlots();
|
||||
|
||||
setMinimumSize(64, 64);
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
// Show a title
|
||||
setTitle("Scope");
|
||||
|
||||
// Show a legend at the bottom
|
||||
if (legend() == 0) {
|
||||
QwtLegend *legend = new QwtLegend();
|
||||
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
||||
insertLegend(legend, QwtPlot::BottomLegend);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::setupSequencialPlot()
|
||||
{
|
||||
//setAutoReplot(true);
|
||||
m_xWindowSize = 100;
|
||||
preparePlot(SequencialPlot);
|
||||
|
||||
setAxisTitle(QwtPlot::xBottom, "Index");
|
||||
setAxisScale(QwtPlot::xBottom, 0, m_xWindowSize);
|
||||
//setAxisLabelRotation(QwtPlot::xBottom, -50.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::setupChronoPlot()
|
||||
{
|
||||
//setAutoReplot(true);
|
||||
m_xWindowSize = 100;
|
||||
preparePlot(ChronoPlot);
|
||||
|
||||
setAxisTitle(QwtPlot::xBottom, "Time [h:m:s]");
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
|
||||
uint NOW = QDateTime::currentDateTime().toTime_t();
|
||||
setAxisScale(QwtPlot::xBottom, NOW - m_xWindowSize, NOW);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, -50.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
const int fmh = QFontMetrics(scaleWidget->font()).height();
|
||||
scaleWidget->setMinBorderDist(0, fmh / 2);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavField, int scaleOrderFactor, QPen pen)
|
||||
{
|
||||
PlotData* plotData;
|
||||
|
||||
if (m_plotType == SequencialPlot)
|
||||
plotData = new SequencialPlotData(&uavObject, &uavField);
|
||||
else if (m_plotType == ChronoPlot)
|
||||
plotData = new ChronoPlotData(&uavObject, &uavField);
|
||||
else if (m_plotType == UAVObjectPlot)
|
||||
plotData = new UAVObjectPlotData(&uavObject, &uavField);
|
||||
|
||||
plotData->m_xWindowSize = m_xWindowSize;
|
||||
plotData->scalePower = scaleOrderFactor;
|
||||
|
||||
//If the y-bounds are supplied, set them
|
||||
if (plotData->yMinimum != plotData->yMaximum)
|
||||
setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum);
|
||||
|
||||
//Create the curve
|
||||
QString curveName = *(plotData->uavObject) + "." + *(plotData->uavField);
|
||||
QwtPlotCurve* plotCurve = new QwtPlotCurve(curveName);
|
||||
plotCurve->setPen(pen);
|
||||
plotCurve->setData(*plotData->xData, *plotData->yData);
|
||||
plotCurve->attach(this);
|
||||
plotData->curve = plotCurve;
|
||||
|
||||
//Keep the curve details for later
|
||||
m_curvesData.insert(curveName, plotData);
|
||||
|
||||
//Get the object to monitor
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(*(plotData->uavObject)));
|
||||
|
||||
//Link to the signal of new data only if this UAVObject has not been to connected yet
|
||||
if (!m_connectedUAVObjects.contains(obj->getName())) {
|
||||
m_connectedUAVObjects.append(obj->getName());
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*)));
|
||||
}
|
||||
|
||||
connect(plotData, SIGNAL(dataChanged()), this, SLOT(replotNewData()));
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::removeCurvePlot(QString uavObject, QString uavField)
|
||||
{
|
||||
QString curveName = uavObject + "." + uavField;
|
||||
|
||||
PlotData* plotData = m_curvesData.take(curveName);
|
||||
m_curvesData.remove(curveName);
|
||||
plotData->curve->detach();
|
||||
|
||||
delete plotData;
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::uavObjectReceived(UAVObject* obj)
|
||||
{
|
||||
foreach(PlotData* plotData, m_curvesData.values()) {
|
||||
plotData->append(obj);
|
||||
plotData->curve->setData(*plotData->xData, *plotData->yData);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::replotNewData()
|
||||
{
|
||||
if (m_plotType == ChronoPlot) {
|
||||
uint NOW = QDateTime::currentDateTime().toTime_t();
|
||||
setAxisScale(QwtPlot::xBottom, NOW - m_xWindowSize, NOW);
|
||||
}
|
||||
replot();
|
||||
}
|
||||
|
||||
|
||||
void ScopeGadgetWidget::setupExamplePlot()
|
||||
{
|
||||
preparePlot(SequencialPlot);
|
||||
|
||||
// Show the axes
|
||||
|
||||
setAxisTitle(xBottom, "x");
|
||||
setAxisTitle(yLeft, "y");
|
||||
|
||||
// Calculate the data, 500 points each
|
||||
const int points = 500;
|
||||
double x[ points ];
|
||||
double sn[ points ];
|
||||
double cs[ points ];
|
||||
double sg[ points ];
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
x[i] = (3.0 * 3.14 / double(points)) * double(i);
|
||||
sn[i] = 2.0 * sin(x[i]);
|
||||
cs[i] = 3.0 * cos(x[i]);
|
||||
sg[i] = (sn[i] > 0) ? 1 : ((sn[i] < 0) ? -1 : 0);
|
||||
}
|
||||
|
||||
// add curves
|
||||
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
|
||||
curve1->setPen(QPen(Qt::blue));
|
||||
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
|
||||
curve2->setPen(QPen(Qt::red));
|
||||
QwtPlotCurve *curve3 = new QwtPlotCurve("Curve 3");
|
||||
curve3->setPen(QPen(Qt::green));
|
||||
|
||||
// copy the data into the curves
|
||||
curve1->setData(x, sn, points);
|
||||
curve2->setData(x, cs, points);
|
||||
curve3->setData(x, sg, points);
|
||||
|
||||
|
||||
|
||||
curve1->attach(this);
|
||||
curve2->attach(this);
|
||||
curve3->attach(this);
|
||||
|
||||
|
||||
|
||||
// finally, refresh the plot
|
||||
replot();
|
||||
}
|
||||
|
||||
|
||||
ScopeGadgetWidget::~ScopeGadgetWidget()
|
||||
{
|
||||
//Get the object to de-monitor
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
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*)));
|
||||
}
|
||||
|
||||
clearCurvePlots();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::clearCurvePlots()
|
||||
{
|
||||
foreach(PlotData* plotData, m_curvesData.values()) {
|
||||
plotData->curve->detach();
|
||||
delete plotData->curve;
|
||||
|
||||
delete plotData;
|
||||
}
|
||||
|
||||
m_curvesData.clear();
|
||||
}
|
||||
|
||||
TestDataGen::TestDataGen()
|
||||
{
|
||||
// Get required UAVObjects
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
altActual = AltitudeActual::GetInstance(objManager);
|
||||
gps = PositionActual::GetInstance(objManager);
|
||||
|
||||
//Setup timer
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(genTestData()));
|
||||
timer->start(100);
|
||||
}
|
||||
|
||||
void TestDataGen::genTestData()
|
||||
{
|
||||
// Update AltitudeActual object
|
||||
AltitudeActual::DataFields altActualData;
|
||||
altActualData.Altitude = 500 * sin(0.1 * testTime) + 200 * cos(0.4 * testTime) + 800;
|
||||
altActualData.Temperature = 30 * sin(0.05 * testTime);
|
||||
altActualData.Pressure = 100;
|
||||
altActual->setData(altActualData);
|
||||
|
||||
|
||||
// Update gps objects
|
||||
PositionActual::DataFields gpsData;
|
||||
gpsData.Altitude = 0;
|
||||
gpsData.Heading = 0;
|
||||
gpsData.Groundspeed = 0;
|
||||
gpsData.Latitude = 0;
|
||||
gpsData.Longitude = 0;
|
||||
gpsData.Satellites = 10;
|
||||
gps->setData(gpsData);
|
||||
|
||||
testTime++;
|
||||
}
|
||||
|
||||
TestDataGen::~TestDataGen()
|
||||
{
|
||||
if (timer)
|
||||
timer->stop();
|
||||
|
||||
delete timer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetwidget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Gadget Widget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "scopegadgetwidget.h"
|
||||
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_legend.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QPushButton>
|
||||
|
||||
|
||||
TestDataGen* ScopeGadgetWidget::testDataGen;
|
||||
|
||||
ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
||||
{
|
||||
// if(testDataGen == 0)
|
||||
// testDataGen = new TestDataGen();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
||||
{
|
||||
m_plotType = plotType;
|
||||
|
||||
clearCurvePlots();
|
||||
|
||||
setMinimumSize(64, 64);
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
// Show a title
|
||||
setTitle("Scope");
|
||||
|
||||
// Show a legend at the bottom
|
||||
if (legend() == 0) {
|
||||
QwtLegend *legend = new QwtLegend();
|
||||
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
||||
insertLegend(legend, QwtPlot::BottomLegend);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::setupSequencialPlot()
|
||||
{
|
||||
preparePlot(SequencialPlot);
|
||||
|
||||
setAxisTitle(QwtPlot::xBottom, "Index");
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
|
||||
setAxisScale(QwtPlot::xBottom, 0, m_xWindowSize);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, 0.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::setupChronoPlot()
|
||||
{
|
||||
preparePlot(ChronoPlot);
|
||||
|
||||
setAxisTitle(QwtPlot::xBottom, "Time [h:m:s]");
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
|
||||
uint NOW = QDateTime::currentDateTime().toTime_t();
|
||||
setAxisScale(QwtPlot::xBottom, NOW - m_xWindowSize, NOW);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, -50.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
const int fmh = QFontMetrics(scaleWidget->font()).height();
|
||||
scaleWidget->setMinBorderDist(0, fmh / 2);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavField, int scaleOrderFactor, QPen pen)
|
||||
{
|
||||
PlotData* plotData;
|
||||
|
||||
if (m_plotType == SequencialPlot)
|
||||
plotData = new SequencialPlotData(uavObject, uavField);
|
||||
else if (m_plotType == ChronoPlot)
|
||||
plotData = new ChronoPlotData(uavObject, uavField, m_refreshInterval);
|
||||
//else if (m_plotType == UAVObjectPlot)
|
||||
// plotData = new UAVObjectPlotData(uavObject, uavField);
|
||||
|
||||
plotData->m_xWindowSize = m_xWindowSize;
|
||||
plotData->scalePower = scaleOrderFactor;
|
||||
|
||||
//If the y-bounds are supplied, set them
|
||||
if (plotData->yMinimum != plotData->yMaximum)
|
||||
setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum);
|
||||
|
||||
//Create the curve
|
||||
QString curveName = (plotData->uavObject) + "." + (plotData->uavField);
|
||||
QwtPlotCurve* plotCurve = new QwtPlotCurve(curveName);
|
||||
plotCurve->setPen(pen);
|
||||
plotCurve->setData(*plotData->xData, *plotData->yData);
|
||||
plotCurve->attach(this);
|
||||
plotData->curve = plotCurve;
|
||||
|
||||
//Keep the curve details for later
|
||||
m_curvesData.insert(curveName, plotData);
|
||||
|
||||
//Get the object to monitor
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject((plotData->uavObject)));
|
||||
|
||||
//Link to the signal of new data only if this UAVObject has not been to connected yet
|
||||
if (!m_connectedUAVObjects.contains(obj->getName())) {
|
||||
m_connectedUAVObjects.append(obj->getName());
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*)));
|
||||
}
|
||||
|
||||
connect(plotData, SIGNAL(dataChanged()), this, SLOT(replotNewData()));
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::removeCurvePlot(QString uavObject, QString uavField)
|
||||
{
|
||||
QString curveName = uavObject + "." + uavField;
|
||||
|
||||
PlotData* plotData = m_curvesData.take(curveName);
|
||||
m_curvesData.remove(curveName);
|
||||
plotData->curve->detach();
|
||||
|
||||
delete plotData->curve;
|
||||
delete plotData;
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::uavObjectReceived(UAVObject* obj)
|
||||
{
|
||||
foreach(PlotData* plotData, m_curvesData.values()) {
|
||||
plotData->append(obj);
|
||||
plotData->curve->setData(*plotData->xData, *plotData->yData);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::replotNewData()
|
||||
{
|
||||
if (m_plotType == ChronoPlot) {
|
||||
uint NOW = QDateTime::currentDateTime().toTime_t();
|
||||
setAxisScale(QwtPlot::xBottom, NOW - m_xWindowSize, NOW);
|
||||
}
|
||||
replot();
|
||||
}
|
||||
|
||||
|
||||
void ScopeGadgetWidget::setupExamplePlot()
|
||||
{
|
||||
preparePlot(SequencialPlot);
|
||||
|
||||
// Show the axes
|
||||
|
||||
setAxisTitle(xBottom, "x");
|
||||
setAxisTitle(yLeft, "y");
|
||||
|
||||
// Calculate the data, 500 points each
|
||||
const int points = 500;
|
||||
double x[ points ];
|
||||
double sn[ points ];
|
||||
double cs[ points ];
|
||||
double sg[ points ];
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
x[i] = (3.0 * 3.14 / double(points)) * double(i);
|
||||
sn[i] = 2.0 * sin(x[i]);
|
||||
cs[i] = 3.0 * cos(x[i]);
|
||||
sg[i] = (sn[i] > 0) ? 1 : ((sn[i] < 0) ? -1 : 0);
|
||||
}
|
||||
|
||||
// add curves
|
||||
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
|
||||
curve1->setPen(QPen(Qt::blue));
|
||||
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
|
||||
curve2->setPen(QPen(Qt::red));
|
||||
QwtPlotCurve *curve3 = new QwtPlotCurve("Curve 3");
|
||||
curve3->setPen(QPen(Qt::green));
|
||||
|
||||
// copy the data into the curves
|
||||
curve1->setData(x, sn, points);
|
||||
curve2->setData(x, cs, points);
|
||||
curve3->setData(x, sg, points);
|
||||
|
||||
|
||||
|
||||
curve1->attach(this);
|
||||
curve2->attach(this);
|
||||
curve3->attach(this);
|
||||
|
||||
|
||||
|
||||
// finally, refresh the plot
|
||||
replot();
|
||||
}
|
||||
|
||||
|
||||
ScopeGadgetWidget::~ScopeGadgetWidget()
|
||||
{
|
||||
//Get the object to de-monitor
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
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*)));
|
||||
}
|
||||
|
||||
clearCurvePlots();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::clearCurvePlots()
|
||||
{
|
||||
foreach(PlotData* plotData, m_curvesData.values()) {
|
||||
plotData->curve->detach();
|
||||
|
||||
delete plotData->curve;
|
||||
delete plotData;
|
||||
}
|
||||
|
||||
m_curvesData.clear();
|
||||
}
|
||||
|
||||
TestDataGen::TestDataGen()
|
||||
{
|
||||
// Get required UAVObjects
|
||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
altActual = AltitudeActual::GetInstance(objManager);
|
||||
gps = PositionActual::GetInstance(objManager);
|
||||
|
||||
//Setup timer
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(genTestData()));
|
||||
timer->start(5000);
|
||||
}
|
||||
|
||||
void TestDataGen::genTestData()
|
||||
{
|
||||
// Update AltitudeActual object
|
||||
AltitudeActual::DataFields altActualData;
|
||||
altActualData.Altitude = 500 * sin(0.1 * testTime) + 200 * cos(0.4 * testTime) + 800;
|
||||
altActualData.Temperature = 30 * sin(0.05 * testTime);
|
||||
altActualData.Pressure = 100;
|
||||
altActual->setData(altActualData);
|
||||
|
||||
|
||||
// Update gps objects
|
||||
PositionActual::DataFields gpsData;
|
||||
gpsData.Altitude = 0;
|
||||
gpsData.Heading = 0;
|
||||
gpsData.Groundspeed = 0;
|
||||
gpsData.Latitude = 0;
|
||||
gpsData.Longitude = 0;
|
||||
gpsData.Satellites = 10;
|
||||
gps->setData(gpsData);
|
||||
|
||||
testTime++;
|
||||
}
|
||||
|
||||
TestDataGen::~TestDataGen()
|
||||
{
|
||||
if (timer)
|
||||
timer->stop();
|
||||
|
||||
delete timer;
|
||||
}
|
@ -1,117 +1,133 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetwidget.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget Widget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SCOPEGADGETWIDGET_H_
|
||||
#define SCOPEGADGETWIDGET_H_
|
||||
|
||||
#include "plotdata.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/altitudeactual.h"
|
||||
#include "uavobjects/positionactual.h"
|
||||
|
||||
|
||||
#include "qwt/src/qwt.h"
|
||||
#include "qwt/src/qwt_plot.h"
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_scale_draw.h"
|
||||
#include "qwt/src/qwt_scale_widget.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QVector>
|
||||
|
||||
class TimeScaleDraw : public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
TimeScaleDraw() {
|
||||
baseTime = QDateTime::currentDateTime().toTime_t();
|
||||
}
|
||||
virtual QwtText label(double v) const {
|
||||
QDateTime upTime = QDateTime::fromTime_t((uint)v);
|
||||
return upTime.toLocalTime().toString("hh:mm:ss");
|
||||
}
|
||||
private:
|
||||
double baseTime;
|
||||
};
|
||||
|
||||
class TestDataGen : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
TestDataGen();
|
||||
~TestDataGen();
|
||||
|
||||
private:
|
||||
AltitudeActual* altActual;
|
||||
PositionActual* gps;
|
||||
|
||||
QTimer *timer;
|
||||
double testTime;
|
||||
|
||||
private slots:
|
||||
void genTestData();
|
||||
};
|
||||
|
||||
|
||||
class ScopeGadgetWidget : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScopeGadgetWidget(QWidget *parent = 0);
|
||||
~ScopeGadgetWidget();
|
||||
|
||||
|
||||
private slots:
|
||||
void uavObjectReceived(UAVObject*);
|
||||
void replotNewData();
|
||||
|
||||
private:
|
||||
|
||||
void preparePlot(PlotType plotType);
|
||||
void setupExamplePlot();
|
||||
void setupSequencialPlot();
|
||||
void setupChronoPlot();
|
||||
void setupUAVObjectPlot();
|
||||
|
||||
void addCurvePlot(QString uavObject, QString uavField, int scaleOrderFactor = 0, QPen pen = QPen(Qt::black));
|
||||
void removeCurvePlot(QString uavObject, QString uavField);
|
||||
void clearCurvePlots();
|
||||
|
||||
PlotType m_plotType;
|
||||
|
||||
double m_xWindowSize;
|
||||
QVector<QString> m_connectedUAVObjects;
|
||||
QMap<QString, PlotData*> m_curvesData;
|
||||
|
||||
static TestDataGen* testDataGen;
|
||||
};
|
||||
|
||||
|
||||
#endif /* SCOPEGADGETWIDGET_H_ */
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file scopegadgetwidget.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget Widget
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup scopeplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef SCOPEGADGETWIDGET_H_
|
||||
#define SCOPEGADGETWIDGET_H_
|
||||
|
||||
#include "plotdata.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "uavobjects/altitudeactual.h"
|
||||
#include "uavobjects/positionactual.h"
|
||||
|
||||
|
||||
#include "qwt/src/qwt.h"
|
||||
#include "qwt/src/qwt_plot.h"
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_scale_draw.h"
|
||||
#include "qwt/src/qwt_scale_widget.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QVector>
|
||||
|
||||
/*!
|
||||
\brief This class is used to render the time values on the horizontal axis for the
|
||||
ChronoPlot.
|
||||
*/
|
||||
class TimeScaleDraw : public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
TimeScaleDraw() {
|
||||
baseTime = QDateTime::currentDateTime().toTime_t();
|
||||
}
|
||||
virtual QwtText label(double v) const {
|
||||
QDateTime upTime = QDateTime::fromTime_t((uint)v);
|
||||
return upTime.toLocalTime().toString("hh:mm:ss");
|
||||
}
|
||||
private:
|
||||
double baseTime;
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief This class is used to inject UAVTalk messages for testing.
|
||||
*/
|
||||
class TestDataGen : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
TestDataGen();
|
||||
~TestDataGen();
|
||||
|
||||
private:
|
||||
AltitudeActual* altActual;
|
||||
PositionActual* gps;
|
||||
|
||||
QTimer *timer;
|
||||
double testTime;
|
||||
|
||||
private slots:
|
||||
void genTestData();
|
||||
};
|
||||
|
||||
|
||||
class ScopeGadgetWidget : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScopeGadgetWidget(QWidget *parent = 0);
|
||||
~ScopeGadgetWidget();
|
||||
|
||||
void setupSequencialPlot();
|
||||
void setupChronoPlot();
|
||||
void setupUAVObjectPlot();
|
||||
PlotType plotType(){return m_plotType;}
|
||||
|
||||
void setXWindowSize(double xWindowSize){m_xWindowSize = xWindowSize;}
|
||||
double xWindowSize(){return m_xWindowSize;}
|
||||
void setRefreshInterval(double refreshInterval){m_refreshInterval = refreshInterval;}
|
||||
int refreshInterval(){return m_refreshInterval;}
|
||||
|
||||
|
||||
void addCurvePlot(QString uavObject, QString uavField, int scaleOrderFactor = 0, QPen pen = QPen(Qt::black));
|
||||
void removeCurvePlot(QString uavObject, QString uavField);
|
||||
void clearCurvePlots();
|
||||
|
||||
|
||||
private slots:
|
||||
void uavObjectReceived(UAVObject*);
|
||||
void replotNewData();
|
||||
|
||||
private:
|
||||
|
||||
void preparePlot(PlotType plotType);
|
||||
void setupExamplePlot();
|
||||
|
||||
PlotType m_plotType;
|
||||
|
||||
double m_xWindowSize;
|
||||
int m_refreshInterval;
|
||||
QList<QString> m_connectedUAVObjects;
|
||||
QMap<QString, PlotData*> m_curvesData;
|
||||
|
||||
static TestDataGen* testDataGen;
|
||||
};
|
||||
|
||||
|
||||
#endif /* SCOPEGADGETWIDGET_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user