From 119280edbcb3214fd15a0672ecb1c4ad1eaa8d5b Mon Sep 17 00:00:00 2001 From: chebuzz Date: Mon, 19 Apr 2010 06:38:03 +0000 Subject: [PATCH] OP-60 GCS/Dials: Create first analog dial. This uses a single multi-layer SVG file created by Edouard. Work remaining involves accepting a UAVObject to update display and smoothing the rotation of the two needles. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@526 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../airspeed/AirspeedGadget.pluginspec | 10 ++ ground/src/plugins/airspeed/airspeed.pro | 17 +++ .../src/plugins/airspeed/airspeedgadget.cpp | 40 ++++++ ground/src/plugins/airspeed/airspeedgadget.h | 55 ++++++++ .../airspeed/airspeedgadgetfactory.cpp | 48 +++++++ .../plugins/airspeed/airspeedgadgetfactory.h | 50 +++++++ .../plugins/airspeed/airspeedgadgetwidget.cpp | 133 ++++++++++++++++++ .../plugins/airspeed/airspeedgadgetwidget.h | 74 ++++++++++ .../src/plugins/airspeed/airspeedplugin.cpp | 66 +++++++++ ground/src/plugins/airspeed/airspeedplugin.h | 47 +++++++ ground/src/plugins/plugins.pro | 5 + 11 files changed, 545 insertions(+) create mode 100644 ground/src/plugins/airspeed/AirspeedGadget.pluginspec create mode 100644 ground/src/plugins/airspeed/airspeed.pro create mode 100644 ground/src/plugins/airspeed/airspeedgadget.cpp create mode 100644 ground/src/plugins/airspeed/airspeedgadget.h create mode 100644 ground/src/plugins/airspeed/airspeedgadgetfactory.cpp create mode 100644 ground/src/plugins/airspeed/airspeedgadgetfactory.h create mode 100644 ground/src/plugins/airspeed/airspeedgadgetwidget.cpp create mode 100644 ground/src/plugins/airspeed/airspeedgadgetwidget.h create mode 100644 ground/src/plugins/airspeed/airspeedplugin.cpp create mode 100644 ground/src/plugins/airspeed/airspeedplugin.h diff --git a/ground/src/plugins/airspeed/AirspeedGadget.pluginspec b/ground/src/plugins/airspeed/AirspeedGadget.pluginspec new file mode 100644 index 000000000..cad6ade35 --- /dev/null +++ b/ground/src/plugins/airspeed/AirspeedGadget.pluginspec @@ -0,0 +1,10 @@ + + The OpenPilot Project + (C)David "Buzz" Carlson + The GNU Public License (GPL) Version 3 + An analog airspeed dial gadget! + http://www.openpilot.org + + + + diff --git a/ground/src/plugins/airspeed/airspeed.pro b/ground/src/plugins/airspeed/airspeed.pro new file mode 100644 index 000000000..905288df1 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeed.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +TARGET = AirspeedGadget + +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../libs/qwt/qwt.pri) + +HEADERS += airspeedplugin.h +HEADERS += airspeedgadget.h +HEADERS += airspeedgadgetwidget.h +HEADERS += airspeedgadgetfactory.h +SOURCES += airspeedplugin.cpp +SOURCES += airspeedgadget.cpp +SOURCES += airspeedgadgetfactory.cpp +SOURCES += airspeedgadgetwidget.cpp + +OTHER_FILES += AirspeedGadget.pluginspec diff --git a/ground/src/plugins/airspeed/airspeedgadget.cpp b/ground/src/plugins/airspeed/airspeedgadget.cpp new file mode 100644 index 000000000..2096e499a --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadget.cpp @@ -0,0 +1,40 @@ +/** + ****************************************************************************** + * + * @file airspeedgadget.cpp + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 "airspeedgadget.h" +#include "airspeedgadgetwidget.h" + +AirspeedGadget::AirspeedGadget(QString classId, AirspeedGadgetWidget *widget, QWidget *parent) : + IUAVGadget(classId, parent), + m_widget(widget) +{ +} + +AirspeedGadget::~AirspeedGadget() +{ + +} diff --git a/ground/src/plugins/airspeed/airspeedgadget.h b/ground/src/plugins/airspeed/airspeedgadget.h new file mode 100644 index 000000000..f3108e233 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadget.h @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * + * @file airspeedgadget.h + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 AIRSPEEDGADGET_H_ +#define AIRSPEEDGADGET_H_ + +#include +#include "airspeedgadgetwidget.h" + +class IUAVGadget; +class QWidget; +class QString; +class AirspeedGadgetWidget; + +using namespace Core; + +class AirspeedGadget : public Core::IUAVGadget +{ + Q_OBJECT +public: + AirspeedGadget(QString classId, AirspeedGadgetWidget *widget, QWidget *parent = 0); + ~AirspeedGadget(); + + QWidget *widget() { return m_widget; } + +private: + AirspeedGadgetWidget *m_widget; +}; + + +#endif // AIRSPEEDGADGET_H_ diff --git a/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp b/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp new file mode 100644 index 000000000..53eacaae0 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp @@ -0,0 +1,48 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetfactory.cpp + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 "airspeedgadgetfactory.h" +#include "airspeedgadgetwidget.h" +#include "airspeedgadget.h" +#include + +AirspeedGadgetFactory::AirspeedGadgetFactory(QObject *parent) : + IUAVGadgetFactory(QString("AirspeedGadget"), + tr("Analog Airspeed Gadget"), + parent) +{ +} + +AirspeedGadgetFactory::~AirspeedGadgetFactory() +{ + +} + +Core::IUAVGadget* AirspeedGadgetFactory::createGadget(QWidget *parent) { + AirspeedGadgetWidget* gadgetWidget = new AirspeedGadgetWidget(parent); + return new AirspeedGadget(QString("AirspeedGadget"), gadgetWidget, parent); +} diff --git a/ground/src/plugins/airspeed/airspeedgadgetfactory.h b/ground/src/plugins/airspeed/airspeedgadgetfactory.h new file mode 100644 index 000000000..d23ad393d --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetfactory.h @@ -0,0 +1,50 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetfactory.h + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 AIRSPEEDGADGETFACTORY_H_ +#define AIRSPEEDGADGETFACTORY_H_ + +#include + +namespace Core { +class IUAVGadget; +class IUAVGadgetFactory; +} + +using namespace Core; + +class AirspeedGadgetFactory : public IUAVGadgetFactory +{ + Q_OBJECT +public: + AirspeedGadgetFactory(QObject *parent = 0); + ~AirspeedGadgetFactory(); + + IUAVGadget *createGadget(QWidget *parent); +}; + +#endif // AIRSPEEDGADGETFACTORY_H_ diff --git a/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp b/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp new file mode 100644 index 000000000..cbf8ec8f9 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp @@ -0,0 +1,133 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetwidget.cpp + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 "airspeedgadgetwidget.h" + +#include +#include +#include + +AirspeedGadgetWidget::AirspeedGadgetWidget(QWidget *parent) : QGraphicsView(parent) +{ + setMinimumSize(64,64); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + setScene(new QGraphicsScene(this)); + + m_renderer = new QSvgRenderer(); + m_background = new QGraphicsSvgItem(); + m_foreground = new QGraphicsSvgItem(); + m_desired = new QGraphicsSvgItem(); + m_actual = new QGraphicsSvgItem(); + setDialFile(QFileDialog::getOpenFileName(qobject_cast(this), + tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) ); + //setDialFile(QString("/usr/src/openpilot/artwork/Dials/extracts/speed-complete.svg")); + paint(); + + // Test code for timer to rotate the needle + testSpeed=0; + connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate())); + m_testTimer.start(60); +} + +AirspeedGadgetWidget::~AirspeedGadgetWidget() +{ + // Do nothing +} + +void AirspeedGadgetWidget::setDialFile(QString dfn) +{ + if (QFile::exists(dfn)) + { + m_renderer->load(dfn); + if(m_renderer->isValid()) + { + m_background->setSharedRenderer(m_renderer); + m_background->setElementId(QString("background")); + + m_foreground->setSharedRenderer(m_renderer); + m_foreground->setElementId(QString("foreground")); + + m_desired->setSharedRenderer(m_renderer); + m_desired->setElementId(QString("desired")); + + m_actual->setSharedRenderer(m_renderer); + m_actual->setElementId(QString("needle")); + } + } + else + { std::cout<<"no file: "<clear(); + + l_scene->addItem(m_background); + l_scene->addItem(m_foreground); + l_scene->addItem(m_desired); + l_scene->addItem(m_actual); + + l_scene->setSceneRect(m_background->boundingRect()); + update(); +} + +void AirspeedGadgetWidget::paintEvent(QPaintEvent *event) +{ + QGraphicsView::paintEvent(event); +} + +// Take a unitless speed value and sets the actual needle accordingly +// scale fixed at 0-90 for now +void AirspeedGadgetWidget::setActual(int speed) +{ + m_actual->resetTransform(); + QRectF rect = m_actual->boundingRect(); + m_actual->translate(rect.width()/2,rect.height()/2); + m_actual->rotate(speed*3); + m_actual->translate(-rect.width()/2,-rect.height()/2); + update(); +} + +// Take a unitless speed value and sets the desired needle accordingly +// scale fixed at 0-90 for now +void AirspeedGadgetWidget::setDesired(int speed) +{ + m_desired->resetTransform(); + QRectF rect = m_desired->boundingRect(); + m_desired->translate(rect.width()/2,rect.height()/2); + m_desired->rotate(speed*3); + m_desired->translate(-rect.width()/2,-rect.height()/2); + update(); +} + +// Test function for timer to rotate needles +void AirspeedGadgetWidget::testRotate() +{ + if(testSpeed==90) testSpeed=0; + setActual(testSpeed++); +} diff --git a/ground/src/plugins/airspeed/airspeedgadgetwidget.h b/ground/src/plugins/airspeed/airspeedgadgetwidget.h new file mode 100644 index 000000000..7c3070018 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetwidget.h @@ -0,0 +1,74 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetwidget.h + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 AIRSPEEDGADGETWIDGET_H_ +#define AIRSPEEDGADGETWIDGET_H_ + +#include +#include +#include + +#include +// Used for test purposes +#include + +class AirspeedGadgetWidget : public QGraphicsView +{ + Q_OBJECT + +public: + AirspeedGadgetWidget(QWidget *parent = 0); + ~AirspeedGadgetWidget(); + void setDialFile(QString dfn); + void paint(); + void setActual(int speed); + void setDesired(int speed); + +protected: + void paintEvent(QPaintEvent *event); + +private: + +// Test functions +private slots: + void testRotate(); +// End test functions + +private: + QString dialFilename; + QSvgRenderer *m_renderer; + QGraphicsSvgItem *m_background; + QGraphicsSvgItem *m_foreground; + QGraphicsSvgItem *m_desired; + QGraphicsSvgItem *m_actual; + + // Test variables + int testSpeed; + QTimer m_testTimer; + // End test variables +}; +#endif /* AIRSPEEDGADGETWIDGET_H_ */ diff --git a/ground/src/plugins/airspeed/airspeedplugin.cpp b/ground/src/plugins/airspeed/airspeedplugin.cpp new file mode 100644 index 000000000..cdcb6da11 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedplugin.cpp @@ -0,0 +1,66 @@ +/** + ****************************************************************************** + * + * @file airspeedplugin.h + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 "airspeedplugin.h" +#include "airspeedgadgetfactory.h" +#include +#include +#include +#include + + +AirspeedPlugin::AirspeedPlugin() +{ + // Do nothing +} + +AirspeedPlugin::~AirspeedPlugin() +{ + // Do nothing +} + +bool AirspeedPlugin::initialize(const QStringList& args, QString *errMsg) +{ + Q_UNUSED(args); + Q_UNUSED(errMsg); + mf = new AirspeedGadgetFactory(this); + addAutoReleasedObject(mf); + + return true; +} + +void AirspeedPlugin::extensionsInitialized() +{ + // Do nothing +} + +void AirspeedPlugin::shutdown() +{ + // Do nothing +} +Q_EXPORT_PLUGIN(AirspeedPlugin) + diff --git a/ground/src/plugins/airspeed/airspeedplugin.h b/ground/src/plugins/airspeed/airspeedplugin.h new file mode 100644 index 000000000..0eab9f133 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedplugin.h @@ -0,0 +1,47 @@ +/** + ****************************************************************************** + * + * @file airspeedplugin.h + * @author David "Buzz" Carlson Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup airspeed + * @{ + * + *****************************************************************************/ +/* + * 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 AIRSPEEDPLUGIN_H_ +#define AIRSPEEDPLUGIN_H_ + +#include + +class AirspeedGadgetFactory; + +class AirspeedPlugin : public ExtensionSystem::IPlugin +{ +public: + AirspeedPlugin(); + ~AirspeedPlugin(); + + void extensionsInitialized(); + bool initialize(const QStringList & arguments, QString * errorString); + void shutdown(); +private: + AirspeedGadgetFactory *mf; +}; +#endif /* AIRSPEEDPLUGIN_H_ */ diff --git a/ground/src/plugins/plugins.pro b/ground/src/plugins/plugins.pro index 7846ef2cd..4ecf9a707 100644 --- a/ground/src/plugins/plugins.pro +++ b/ground/src/plugins/plugins.pro @@ -69,3 +69,8 @@ SUBDIRS += plugin_uavobjectbrowser plugin_uploader.subdir = uploader plugin_uploader.depends = plugin_coreplugin SUBDIRS += plugin_uploader + +#Airspeed Dial Gadget +plugin_airspeed.subdir = airspeed +plugin_airspeed.depends = plugin_coreplugin +SUBDIRS += plugin_airspeed