From 8f95857fb15e6fca5ba67efc403b9747c1dc300c Mon Sep 17 00:00:00 2001 From: banigreyling Date: Tue, 8 Jun 2010 20:59:43 +0000 Subject: [PATCH] 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 --- ground/src/plugins/scope/plotdata.cpp | 138 +++++++++ ground/src/plugins/scope/plotdata.h | 142 +++++++++ ground/src/plugins/scope/scope.pro | 39 +-- ground/src/plugins/scope/scopegadget.cpp | 29 +- ground/src/plugins/scope/scopegadget.h | 45 ++- .../scope/scopegadgetconfiguration.cpp | 72 +++++ .../plugins/scope/scopegadgetconfiguration.h | 46 +++ .../src/plugins/scope/scopegadgetfactory.cpp | 44 ++- ground/src/plugins/scope/scopegadgetfactory.h | 35 ++- .../plugins/scope/scopegadgetoptionspage.cpp | 75 +++++ .../plugins/scope/scopegadgetoptionspage.h | 66 ++++ .../plugins/scope/scopegadgetoptionspage.ui | 239 +++++++++++++++ .../src/plugins/scope/scopegadgetwidget.cpp | 288 ++++++++++++++++-- ground/src/plugins/scope/scopegadgetwidget.h | 105 ++++++- ground/src/plugins/scope/scopeplugin.cpp | 47 ++- ground/src/plugins/scope/scopeplugin.h | 41 ++- 16 files changed, 1360 insertions(+), 91 deletions(-) create mode 100644 ground/src/plugins/scope/plotdata.cpp create mode 100644 ground/src/plugins/scope/plotdata.h create mode 100644 ground/src/plugins/scope/scopegadgetconfiguration.cpp create mode 100644 ground/src/plugins/scope/scopegadgetconfiguration.h create mode 100644 ground/src/plugins/scope/scopegadgetoptionspage.cpp create mode 100644 ground/src/plugins/scope/scopegadgetoptionspage.h create mode 100644 ground/src/plugins/scope/scopegadgetoptionspage.ui diff --git a/ground/src/plugins/scope/plotdata.cpp b/ground/src/plugins/scope/plotdata.cpp new file mode 100644 index 000000000..7120796c6 --- /dev/null +++ b/ground/src/plugins/scope/plotdata.cpp @@ -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 + +PlotData::PlotData(QString* p_uavObject, QString* p_uavField) +{ + uavObject = new QString(*p_uavObject); + uavField = new QString(*p_uavField); + + xData = new QVector(); + yData = new QVector(); + + 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; +} + diff --git a/ground/src/plugins/scope/plotdata.h b/ground/src/plugins/scope/plotdata.h new file mode 100644 index 000000000..9e4b64424 --- /dev/null +++ b/ground/src/plugins/scope/plotdata.h @@ -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 +#include +#include + +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* xData; + QVector* 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 diff --git a/ground/src/plugins/scope/scope.pro b/ground/src/plugins/scope/scope.pro index 2fc7ae286..85c485fa1 100644 --- a/ground/src/plugins/scope/scope.pro +++ b/ground/src/plugins/scope/scope.pro @@ -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 diff --git a/ground/src/plugins/scope/scopegadget.cpp b/ground/src/plugins/scope/scopegadget.cpp index 15ff5d870..723856c9d 100644 --- a/ground/src/plugins/scope/scopegadget.cpp +++ b/ground/src/plugins/scope/scopegadget.cpp @@ -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" diff --git a/ground/src/plugins/scope/scopegadget.h b/ground/src/plugins/scope/scopegadget.h index c5a15d3aa..0c4564446 100644 --- a/ground/src/plugins/scope/scopegadget.h +++ b/ground/src/plugins/scope/scopegadget.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 context() const { return m_context; } - QWidget *widget() { return m_widget; } - QString contextHelpId() const { return QString(); } + QList context() const { + return m_context; + } + QWidget *widget() { + return m_widget; + } + QString contextHelpId() const { + return QString(); + } private: - QWidget *m_widget; - QList m_context; + QWidget *m_widget; + QList m_context; }; diff --git a/ground/src/plugins/scope/scopegadgetconfiguration.cpp b/ground/src/plugins/scope/scopegadgetconfiguration.cpp new file mode 100644 index 000000000..963622c2a --- /dev/null +++ b/ground/src/plugins/scope/scopegadgetconfiguration.cpp @@ -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 + +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; +} + diff --git a/ground/src/plugins/scope/scopegadgetconfiguration.h b/ground/src/plugins/scope/scopegadgetconfiguration.h new file mode 100644 index 000000000..bed54cb19 --- /dev/null +++ b/ground/src/plugins/scope/scopegadgetconfiguration.h @@ -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 + +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 diff --git a/ground/src/plugins/scope/scopegadgetfactory.cpp b/ground/src/plugins/scope/scopegadgetfactory.cpp index b093fc380..93cefaaa0 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.cpp +++ b/ground/src/plugins/scope/scopegadgetfactory.cpp @@ -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 @@ -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(config)); +} diff --git a/ground/src/plugins/scope/scopegadgetfactory.h b/ground/src/plugins/scope/scopegadgetfactory.h index a2c1e3e6b..7c479b08b 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.h +++ b/ground/src/plugins/scope/scopegadgetfactory.h @@ -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 -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_ diff --git a/ground/src/plugins/scope/scopegadgetoptionspage.cpp b/ground/src/plugins/scope/scopegadgetoptionspage.cpp new file mode 100644 index 000000000..63ee1aecf --- /dev/null +++ b/ground/src/plugins/scope/scopegadgetoptionspage.cpp @@ -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() +{ + +} diff --git a/ground/src/plugins/scope/scopegadgetoptionspage.h b/ground/src/plugins/scope/scopegadgetoptionspage.h new file mode 100644 index 000000000..f457bfa10 --- /dev/null +++ b/ground/src/plugins/scope/scopegadgetoptionspage.h @@ -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 +#include + +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 diff --git a/ground/src/plugins/scope/scopegadgetoptionspage.ui b/ground/src/plugins/scope/scopegadgetoptionspage.ui new file mode 100644 index 000000000..ec67ffa77 --- /dev/null +++ b/ground/src/plugins/scope/scopegadgetoptionspage.ui @@ -0,0 +1,239 @@ + + + ScopeGadgetOptionsPage + + + + 0 + 0 + 653 + 580 + + + + Form + + + + + 0 + 0 + 531 + 361 + + + + + + 0 + 20 + 251 + 111 + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + Chronological Plot + + + + + Sequencial Plot + + + + + + + + Plot Type: + + + + + + + seconds + + + 5000 + + + 10 + + + 300 + + + + + + + Data Size: + + + + + + + seconds + + + 1 + + + 30 + + + 5 + + + + + + + Refresh Time: + + + + + + + + + 0 + 160 + 481 + 131 + + + + + + + + + UAVObject: + + + + + + + + + + Color: + + + + + + + + + + UAVField: + + + + + + + + + + Scale: + + + + + + + + + + + + QLayout::SetFixedSize + + + + + >> + + + + + + + << + + + + + + + + + + + 100 + + + + + + + + + + + 0 + 140 + 81 + 17 + + + + + Bitstream Charter + 75 + true + + + + Plot curves + + + + + + 0 + 0 + 62 + 17 + + + + + Bitstream Charter + 75 + true + + + + X-Axis + + + + + + + diff --git a/ground/src/plugins/scope/scopegadgetwidget.cpp b/ground/src/plugins/scope/scopegadgetwidget.cpp index c2809e99f..5dfa0014e 100644 --- a/ground/src/plugins/scope/scopegadgetwidget.cpp +++ b/ground/src/plugins/scope/scopegadgetwidget.cpp @@ -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 +#include #include #include #include #include #include + +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(); + UAVDataObject* obj = dynamic_cast(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; i0)?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(); + + foreach(QString uavObjName, m_connectedUAVObjects) { + UAVDataObject* obj = dynamic_cast(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(); + + 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; +} + + diff --git a/ground/src/plugins/scope/scopegadgetwidget.h b/ground/src/plugins/scope/scopegadgetwidget.h index de52f5407..17363bc32 100644 --- a/ground/src/plugins/scope/scopegadgetwidget.h +++ b/ground/src/plugins/scope/scopegadgetwidget.h @@ -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 -//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 +#include +#include + +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 m_connectedUAVObjects; + QMap m_curvesData; + + static TestDataGen* testDataGen; }; + #endif /* SCOPEGADGETWIDGET_H_ */ diff --git a/ground/src/plugins/scope/scopeplugin.cpp b/ground/src/plugins/scope/scopeplugin.cpp index bc9cba2d1..44a3e73a8 100644 --- a/ground/src/plugins/scope/scopeplugin.cpp +++ b/ground/src/plugins/scope/scopeplugin.cpp @@ -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 @@ -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) diff --git a/ground/src/plugins/scope/scopeplugin.h b/ground/src/plugins/scope/scopeplugin.h index 1daba10c9..9d8299c8a 100644 --- a/ground/src/plugins/scope/scopeplugin.h +++ b/ground/src/plugins/scope/scopeplugin.h @@ -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_ */