mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
OP-42 Implemented some features for Scope Gadget. It is still hardcoded to display altitude and temperature. Basic config panel layout done without bindings
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@729 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
a32bced9fc
commit
8f95857fb1
138
ground/src/plugins/scope/plotdata.cpp
Normal file
138
ground/src/plugins/scope/plotdata.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
142
ground/src/plugins/scope/plotdata.h
Normal file
142
ground/src/plugins/scope/plotdata.h
Normal file
@ -0,0 +1,142 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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/gpsobject.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
|
@ -1,17 +1,22 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = ScopeGadget
|
||||
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../libs/qwt/qwt.pri)
|
||||
|
||||
HEADERS += scopeplugin.h
|
||||
HEADERS += scopegadget.h
|
||||
HEADERS += scopegadgetwidget.h
|
||||
HEADERS += scopegadgetfactory.h
|
||||
SOURCES += scopeplugin.cpp
|
||||
SOURCES += scopegadget.cpp
|
||||
SOURCES += scopegadgetfactory.cpp
|
||||
SOURCES += scopegadgetwidget.cpp
|
||||
|
||||
OTHER_FILES += ScopeGadget.pluginspec
|
||||
TEMPLATE = lib
|
||||
TARGET = ScopeGadget
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../../libs/qwt/qwt.pri)
|
||||
HEADERS += scopeplugin.h \
|
||||
plotdata.h
|
||||
HEADERS += scopegadgetoptionspage.h
|
||||
HEADERS += scopegadgetconfiguration.h
|
||||
HEADERS += scopegadget.h
|
||||
HEADERS += scopegadgetwidget.h
|
||||
HEADERS += scopegadgetfactory.h
|
||||
SOURCES += scopeplugin.cpp \
|
||||
plotdata.cpp
|
||||
SOURCES += scopegadgetoptionspage.cpp
|
||||
SOURCES += scopegadgetconfiguration.cpp
|
||||
SOURCES += scopegadget.cpp
|
||||
SOURCES += scopegadgetfactory.cpp
|
||||
SOURCES += scopegadgetwidget.cpp
|
||||
OTHER_FILES += ScopeGadget.pluginspec
|
||||
FORMS += scopegadgetoptionspage.ui
|
||||
|
@ -1,9 +1,30 @@
|
||||
/*
|
||||
* scopegadget.cpp
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 11, 2010
|
||||
* Author: peter
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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"
|
||||
|
||||
|
@ -1,10 +1,31 @@
|
||||
/*
|
||||
* scopegadget.h
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 11, 2010
|
||||
* Author: peter
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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_
|
||||
|
||||
@ -25,13 +46,19 @@ 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(); }
|
||||
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;
|
||||
QWidget *m_widget;
|
||||
QList<int> m_context;
|
||||
};
|
||||
|
||||
|
||||
|
72
ground/src/plugins/scope/scopegadgetconfiguration.cpp
Normal file
72
ground/src/plugins/scope/scopegadgetconfiguration.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
46
ground/src/plugins/scope/scopegadgetconfiguration.h
Normal file
46
ground/src/plugins/scope/scopegadgetconfiguration.h
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
@ -1,11 +1,33 @@
|
||||
/*
|
||||
* scopegadgetfactory.cpp
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 11, 2010
|
||||
* Author: peter
|
||||
* @file scopegadgetfactory.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Gadget Factory
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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 "scopegadgetfactory.h"
|
||||
#include "scopegadgetwidget.h"
|
||||
#include "scopegadgetconfiguration.h"
|
||||
#include "scopegadgetoptionspage.h"
|
||||
#include "scopegadget.h"
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
@ -18,10 +40,20 @@ ScopeGadgetFactory::ScopeGadgetFactory(QObject *parent) :
|
||||
|
||||
ScopeGadgetFactory::~ScopeGadgetFactory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Core::IUAVGadget* ScopeGadgetFactory::createGadget(QWidget *parent) {
|
||||
Core::IUAVGadget* ScopeGadgetFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
ScopeGadgetWidget* gadgetWidget = new ScopeGadgetWidget(parent);
|
||||
return new ScopeGadget(QString("ScopeGadget"), gadgetWidget, parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *ScopeGadgetFactory::createConfiguration(const QByteArray &state)
|
||||
{
|
||||
return new ScopeGadgetConfiguration(QString("ScopeGadget"), state);
|
||||
}
|
||||
|
||||
IOptionsPage *ScopeGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
return new ScopeGadgetOptionsPage(qobject_cast<ScopeGadgetConfiguration*>(config));
|
||||
}
|
||||
|
@ -1,8 +1,28 @@
|
||||
/*
|
||||
* scopegadgetfactory.h
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 6, 2010
|
||||
* Author: peter
|
||||
* @file scopegadgetfactory.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin Gadget Factory
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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 SCOPEGADGETFACTORY_H_
|
||||
@ -10,7 +30,8 @@
|
||||
|
||||
#include <coreplugin/iuavgadgetfactory.h>
|
||||
|
||||
namespace Core {
|
||||
namespace Core
|
||||
{
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetFactory;
|
||||
}
|
||||
@ -24,7 +45,9 @@ public:
|
||||
ScopeGadgetFactory(QObject *parent = 0);
|
||||
~ScopeGadgetFactory();
|
||||
|
||||
IUAVGadget *createGadget(QWidget *parent);
|
||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETFACTORY_H_
|
||||
|
75
ground/src/plugins/scope/scopegadgetoptionspage.cpp
Normal file
75
ground/src/plugins/scope/scopegadgetoptionspage.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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()
|
||||
{
|
||||
|
||||
}
|
66
ground/src/plugins/scope/scopegadgetoptionspage.h
Normal file
66
ground/src/plugins/scope/scopegadgetoptionspage.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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
|
239
ground/src/plugins/scope/scopegadgetoptionspage.ui
Normal file
239
ground/src/plugins/scope/scopegadgetoptionspage.ui
Normal file
@ -0,0 +1,239 @@
|
||||
<?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>
|
@ -1,62 +1,316 @@
|
||||
/*
|
||||
* scopegadgetwidget.cpp
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 6, 2010
|
||||
* Author: peter
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
setMinimumSize(64,64);
|
||||
//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("Sine");
|
||||
setTitle("Scope");
|
||||
|
||||
// Show a legend at the bottom
|
||||
// setAutoLegend( true );
|
||||
// setLegendPos( Qwt::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" );
|
||||
|
||||
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] );
|
||||
sg[i] = (sn[i]>0)?1:((sn[i]<0)?-1:0);
|
||||
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, sg, 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()
|
||||
{
|
||||
// Do nothing
|
||||
//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 = GpsObject::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
|
||||
GpsObject::DataFields gpsData;
|
||||
gpsData.Altitude = 0;
|
||||
gpsData.Heading = 0;
|
||||
gpsData.GroundSpeed = 0;
|
||||
gpsData.Latitude = 0;
|
||||
gpsData.Longitude = 0;
|
||||
gpsData.Satellites = 10;
|
||||
gpsData.Updates = 0;
|
||||
gps->setData(gpsData);
|
||||
|
||||
testTime++;
|
||||
}
|
||||
|
||||
TestDataGen::~TestDataGen()
|
||||
{
|
||||
if (timer)
|
||||
timer->stop();
|
||||
|
||||
delete timer;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,18 +1,83 @@
|
||||
/*
|
||||
* scopegadgetwidget.h
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 6, 2010
|
||||
* Author: peter
|
||||
* @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 Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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/gpsobject.h"
|
||||
|
||||
|
||||
#include "qwt/src/qwt.h"
|
||||
#include "qwt/src/qwt_plot.h"
|
||||
//#include <QtGui/QWidget>
|
||||
//class QWidget;
|
||||
class QwtPlot;
|
||||
#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;
|
||||
GpsObject* gps;
|
||||
|
||||
QTimer *timer;
|
||||
double testTime;
|
||||
|
||||
private slots:
|
||||
void genTestData();
|
||||
};
|
||||
|
||||
|
||||
class ScopeGadgetWidget : public QwtPlot
|
||||
{
|
||||
@ -20,9 +85,33 @@ class ScopeGadgetWidget : public QwtPlot
|
||||
|
||||
public:
|
||||
ScopeGadgetWidget(QWidget *parent = 0);
|
||||
~ScopeGadgetWidget();
|
||||
~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_ */
|
||||
|
@ -1,9 +1,30 @@
|
||||
/*
|
||||
* scopeplugin.cpp
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 6, 2010
|
||||
* Author: peter
|
||||
* @file scopeplugin.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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 "scopeplugin.h"
|
||||
#include "scopegadgetfactory.h"
|
||||
#include <QDebug>
|
||||
@ -14,32 +35,32 @@
|
||||
|
||||
ScopePlugin::ScopePlugin()
|
||||
{
|
||||
// Do nothing
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
ScopePlugin::~ScopePlugin()
|
||||
{
|
||||
// Do nothing
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool ScopePlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new ScopeGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new ScopeGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScopePlugin::extensionsInitialized()
|
||||
{
|
||||
// Do nothing
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void ScopePlugin::shutdown()
|
||||
{
|
||||
// Do nothing
|
||||
// Do nothing
|
||||
}
|
||||
Q_EXPORT_PLUGIN(ScopePlugin)
|
||||
|
||||
|
@ -1,10 +1,29 @@
|
||||
/*
|
||||
* scopeplugin.h
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Created on: Mar 6, 2010
|
||||
* Author: peter
|
||||
* @file scopeplugin.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Scope Plugin
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Scope
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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 SCOPEPLUGIN_H_
|
||||
#define SCOPEPLUGIN_H_
|
||||
|
||||
@ -15,13 +34,13 @@ class ScopeGadgetFactory;
|
||||
class ScopePlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
ScopePlugin();
|
||||
~ScopePlugin();
|
||||
ScopePlugin();
|
||||
~ScopePlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
ScopeGadgetFactory *mf;
|
||||
ScopeGadgetFactory *mf;
|
||||
};
|
||||
#endif /* SCOPEPLUGIN_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user