From 10215c96c3ee430d74462c844d25fb0d55050c04 Mon Sep 17 00:00:00 2001 From: edouard Date: Tue, 4 May 2010 23:09:39 +0000 Subject: [PATCH] New "bargraph" dial. Use with the recently uploaded linear dial SVG. Settings to not work at the moment, I'll add them later. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@585 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../lineardial/LineardialGadget.pluginspec | 10 + ground/src/plugins/lineardial/lineardial.pro | 20 ++ .../plugins/lineardial/lineardialgadget.cpp | 59 ++++ .../src/plugins/lineardial/lineardialgadget.h | 56 ++++ .../lineardialgadgetconfiguration.cpp | 96 +++++++ .../lineardialgadgetconfiguration.h | 91 ++++++ .../lineardial/lineardialgadgetfactory.cpp | 60 ++++ .../lineardial/lineardialgadgetfactory.h | 52 ++++ .../lineardialgadgetoptionspage.cpp | 96 +++++++ .../lineardial/lineardialgadgetoptionspage.h | 66 +++++ .../lineardial/lineardialgadgetoptionspage.ui | 269 ++++++++++++++++++ .../lineardial/lineardialgadgetwidget.cpp | 209 ++++++++++++++ .../lineardial/lineardialgadgetwidget.h | 102 +++++++ .../plugins/lineardial/lineardialplugin.cpp | 66 +++++ .../src/plugins/lineardial/lineardialplugin.h | 47 +++ ground/src/plugins/plugins.pro | 5 + 16 files changed, 1304 insertions(+) create mode 100644 ground/src/plugins/lineardial/LineardialGadget.pluginspec create mode 100644 ground/src/plugins/lineardial/lineardial.pro create mode 100644 ground/src/plugins/lineardial/lineardialgadget.cpp create mode 100644 ground/src/plugins/lineardial/lineardialgadget.h create mode 100644 ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp create mode 100644 ground/src/plugins/lineardial/lineardialgadgetconfiguration.h create mode 100644 ground/src/plugins/lineardial/lineardialgadgetfactory.cpp create mode 100644 ground/src/plugins/lineardial/lineardialgadgetfactory.h create mode 100644 ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp create mode 100644 ground/src/plugins/lineardial/lineardialgadgetoptionspage.h create mode 100644 ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui create mode 100644 ground/src/plugins/lineardial/lineardialgadgetwidget.cpp create mode 100644 ground/src/plugins/lineardial/lineardialgadgetwidget.h create mode 100644 ground/src/plugins/lineardial/lineardialplugin.cpp create mode 100644 ground/src/plugins/lineardial/lineardialplugin.h diff --git a/ground/src/plugins/lineardial/LineardialGadget.pluginspec b/ground/src/plugins/lineardial/LineardialGadget.pluginspec new file mode 100644 index 000000000..af13175a3 --- /dev/null +++ b/ground/src/plugins/lineardial/LineardialGadget.pluginspec @@ -0,0 +1,10 @@ + + The OpenPilot Project + (C)Edouard Lafargue + The GNU Public License (GPL) Version 3 + An bargraph gadget with red/yellow/green zones + http://www.openpilot.org + + + + diff --git a/ground/src/plugins/lineardial/lineardial.pro b/ground/src/plugins/lineardial/lineardial.pro new file mode 100644 index 000000000..99135c450 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardial.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +TARGET = lineardialGadget +QT += svg +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../libs/qwt/qwt.pri) +HEADERS += lineardialplugin.h +HEADERS += lineardialgadget.h +HEADERS += lineardialgadgetwidget.h +HEADERS += lineardialgadgetfactory.h +HEADERS += lineardialgadgetconfiguration.h +HEADERS += lineardialgadgetoptionspage.h +SOURCES += lineardialplugin.cpp +SOURCES += lineardialgadget.cpp +SOURCES += lineardialgadgetfactory.cpp +SOURCES += lineardialgadgetwidget.cpp +SOURCES += lineardialgadgetconfiguration.cpp +SOURCES += lineardialgadgetoptionspage.cpp +OTHER_FILES += LineardialGadget.pluginspec +FORMS += lineardialgadgetoptionspage.ui diff --git a/ground/src/plugins/lineardial/lineardialgadget.cpp b/ground/src/plugins/lineardial/lineardialgadget.cpp new file mode 100644 index 000000000..b20025d64 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadget.cpp @@ -0,0 +1,59 @@ +/** + ****************************************************************************** + * + * @file lineardialgadget.cpp + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 "lineardialgadget.h" +#include "lineardialgadgetwidget.h" +#include "lineardialgadgetconfiguration.h" + +LineardialGadget::LineardialGadget(QString classId, LineardialGadgetWidget *widget, QWidget *parent) : + IUAVGadget(classId, parent), + m_widget(widget) +{ +} + +LineardialGadget::~LineardialGadget() +{ +} + +/* + This is called when a configuration is loaded, and updates the plugin's settings. + Careful: the plugin is already drawn before the loadConfiguration method is called the + first time, so you have to be careful not to assume all the plugin values are initialized + the first time you use them + */ +void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config) +{ + LineardialGadgetConfiguration *m = qobject_cast(config); + m_widget->setDialFile(m->getDialFile()); + m_widget->setRange(m->getMin(),m->getMax()); + m_widget->setGreenRange(m->getGreenMin(), m->getGreenMax()); + m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax()); + m_widget->setRedRange(m->getRedMin(), m->getRedMax()); + + m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField()); + +} diff --git a/ground/src/plugins/lineardial/lineardialgadget.h b/ground/src/plugins/lineardial/lineardialgadget.h new file mode 100644 index 000000000..424701e0e --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadget.h @@ -0,0 +1,56 @@ +/** + ****************************************************************************** + * + * @file lineardialgadget.h + * @author Edouard Lafargue Copyright (C) 2010. + * @brief Bargraph gadget with red/yellow/green zones + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 LINEARDIALGADGET_H_ +#define LINEARDIALGADGET_H_ + +#include +#include "lineardialgadgetwidget.h" + +class IUAVGadget; +class QWidget; +class QString; +class LineardialGadgetWidget; + +using namespace Core; + +class LineardialGadget : public Core::IUAVGadget +{ + Q_OBJECT +public: + LineardialGadget(QString classId, LineardialGadgetWidget *widget, QWidget *parent = 0); + ~LineardialGadget(); + + QWidget *widget() { return m_widget; } + void loadConfiguration(IUAVGadgetConfiguration* config); + +private: + LineardialGadgetWidget *m_widget; +}; + + +#endif // LINEARDIALGADGET_H_ diff --git a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp new file mode 100644 index 000000000..301905414 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp @@ -0,0 +1,96 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetconfiguration.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Linear dial Plugin Gadget configuration + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 "lineardialgadgetconfiguration.h" +#include + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + dialFile("Unknown"), + sourceDataObject("Unknown"), + sourceObjectField("Unknown"), + minValue(0), + maxValue(100), + redMin(0), + redMax(33), + yellowMin(33), + yellowMax(66), + greenMin(66), + greenMax(100) +{ + //if a saved configuration exists load it + if (state.count() > 0) { + QDataStream stream(state); + stream >> dialFile; + stream >> sourceDataObject; + stream >> sourceObjectField; + stream >> minValue; + stream >> maxValue; + stream >> redMin; + stream >> redMax; + stream >> yellowMin; + stream >> yellowMax; + stream >> greenMin; + stream >> greenMax; + } +} +/** + * Clones a configuration. + * + */ +IUAVGadgetConfiguration *LineardialGadgetConfiguration::clone() +{ + LineardialGadgetConfiguration *m = new LineardialGadgetConfiguration(this->classId()); + m->dialFile=dialFile; + return m; +} +/** + * Saves a configuration. + * + */ +QByteArray LineardialGadgetConfiguration::saveState() const +{ + QByteArray bytes; + QDataStream stream(&bytes, QIODevice::WriteOnly); + stream << dialFile; + stream << sourceDataObject; + stream << sourceObjectField; + stream << minValue; + stream << maxValue; + stream << redMin; + stream << redMax; + stream << yellowMin; + stream << yellowMax; + stream << greenMin; + stream << greenMax; + + return bytes; +} diff --git a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h new file mode 100644 index 000000000..3980313db --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h @@ -0,0 +1,91 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetconfiguration.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget configuration + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 LINEARDIALGADGETCONFIGURATION_H +#define LINEARDIALGADGETCONFIGURATION_H + +#include + +using namespace Core; + +/* This is a generic bargraph dial + supporting one indicator. + */ +class LineardialGadgetConfiguration : public IUAVGadgetConfiguration +{ +Q_OBJECT +public: + explicit LineardialGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + + //set dial configuration functions + void setDialFile(QString filename){dialFile=filename;} + void setRange(double min, double max) { minValue = min; maxValue = max;} + void setGreenRange(double min, double max) { greenMin = min; greenMax = max;} + void setYellowRange(double min, double max) { yellowMin = min; yellowMax = max;} + void setRedRange(double min, double max) { redMin = min; redMax = max;} + + void setSourceDataObject(QString text) {sourceDataObject = text; } + void setSourceObjField(QString text) { sourceObjectField = text; } + + //get dial configuration functions + QString getDialFile() {return dialFile;} + double getMin() { return minValue;} + double getMax() { return maxValue;} + double getGreenMin(){ return greenMin;} + double getGreenMax(){ return greenMax;} + double getYellowMin(){ return yellowMin;} + double getYellowMax(){ return yellowMax;} + double getRedMin(){ return redMin;} + double getRedMax(){ return redMax;} + QString getSourceDataObject() { return sourceDataObject;} + QString getSourceObjectField() { return sourceObjectField;} + + QByteArray saveState() const; + IUAVGadgetConfiguration *clone(); + +private: + // A linear or "bargraph" dial contains: + // * A SVG background file + // The source file should have at least the following IDs + // defined: "background", "green", "yellow", "red", "needle" + QString dialFile; + // * The name of the UAVObject field to display + QString sourceDataObject; + QString sourceObjectField; + // * The minimum and maximum values to be displayed + double minValue; + double maxValue; + // * Three start-stop values for green/yellow/red + double redMin; + double redMax; + double yellowMin; + double yellowMax; + double greenMin; + double greenMax; +}; + +#endif // LINEARDIALGADGETCONFIGURATION_H diff --git a/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp b/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp new file mode 100644 index 000000000..c1ee706da --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetfactory.cpp @@ -0,0 +1,60 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetfactory.cpp + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 "lineardialgadgetfactory.h" +#include "lineardialgadgetwidget.h" +#include "lineardialgadget.h" +#include "lineardialgadgetconfiguration.h" +#include "lineardialgadgetoptionspage.h" +#include + +LineardialGadgetFactory::LineardialGadgetFactory(QObject *parent) : + IUAVGadgetFactory(QString("LineardialGadget"), + tr("Bargraph Dial Gadget"), + parent) +{ +} + +LineardialGadgetFactory::~LineardialGadgetFactory() +{ +} + +Core::IUAVGadget* LineardialGadgetFactory::createGadget(QWidget *parent) +{ + LineardialGadgetWidget* gadgetWidget = new LineardialGadgetWidget(parent); + return new LineardialGadget(QString("LineardialGadget"), gadgetWidget, parent); +} + +IUAVGadgetConfiguration *LineardialGadgetFactory::createConfiguration(const QByteArray &state) +{ + return new LineardialGadgetConfiguration(QString("LineardialGadget"), state); +} + +IOptionsPage *LineardialGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) +{ + return new LineardialGadgetOptionsPage(qobject_cast(config)); +} + diff --git a/ground/src/plugins/lineardial/lineardialgadgetfactory.h b/ground/src/plugins/lineardial/lineardialgadgetfactory.h new file mode 100644 index 000000000..6c3263a4f --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetfactory.h @@ -0,0 +1,52 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetfactory.h + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 LINEARDIALGADGETFACTORY_H_ +#define LINEARDIALGADGETFACTORY_H_ + +#include + +namespace Core { +class IUAVGadget; +class IUAVGadgetFactory; +} + +using namespace Core; + +class LineardialGadgetFactory : public IUAVGadgetFactory +{ + Q_OBJECT +public: + LineardialGadgetFactory(QObject *parent = 0); + ~LineardialGadgetFactory(); + + Core::IUAVGadget *createGadget(QWidget *parent); + IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); +}; + +#endif // LINEARDIALGADGETFACTORY_H_ diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp new file mode 100644 index 000000000..65d881e28 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp @@ -0,0 +1,96 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetoptionspage.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget options page + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 "lineardialgadgetoptionspage.h" +#include "lineardialgadgetconfiguration.h" +#include "ui_lineardialgadgetoptionspage.h" + +#include +#include +#include + +LineardialGadgetOptionsPage::LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent) : + IOptionsPage(parent), + m_config(config) +{ +} + +//creates options page widget (uses the UI file) +QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent) +{ + + options_page = new Ui::LineardialGadgetOptionsPage(); + //main widget + QWidget *optionsPageWidget = new QWidget; + //main layout + options_page->setupUi(optionsPageWidget); + + // Restore the contents from the settings: + options_page->svgSourceFile->setText(m_config->getDialFile()); + + + connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked())); + + + return optionsPageWidget; +} +/** + * Called when the user presses apply or OK. + * + * Saves the current values + * + */ +void LineardialGadgetOptionsPage::apply() +{ + m_config->setDialFile(options_page->svgSourceFile->text()); + +} + +/** + +Opens an open file dialog. + +*/ +void LineardialGadgetOptionsPage::on_loadFile_clicked() +{ + QFileDialog::Options options; + QString selectedFilter; + QString fileName = QFileDialog::getOpenFileName(qobject_cast(this), + tr("QFileDialog::getOpenFileName()"), + options_page->svgSourceFile->text(), + tr("All Files (*);;SVG Files (*.svg)"), + &selectedFilter, + options); + if (!fileName.isEmpty()) options_page->svgSourceFile->setText(fileName); + +} + + +void LineardialGadgetOptionsPage::finish() +{ + +} diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h new file mode 100644 index 000000000..585ebbf01 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.h @@ -0,0 +1,66 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetoptionspage.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget options page + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 LINEARDIALGADGETOPTIONSPAGE_H +#define LINEARDIALGADGETOPTIONSPAGE_H + +#include "coreplugin/dialogs/ioptionspage.h" +#include "QString" +#include +#include + +namespace Core { +class IUAVGadgetConfiguration; +} + +class LineardialGadgetConfiguration; + +namespace Ui { + class LineardialGadgetOptionsPage; +} + +using namespace Core; + +class LineardialGadgetOptionsPage : public IOptionsPage +{ +Q_OBJECT +public: + explicit LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent = 0); + + QWidget *createPage(QWidget *parent); + void apply(); + void finish(); + +private: + Ui::LineardialGadgetOptionsPage *options_page; + LineardialGadgetConfiguration *m_config; + +private slots: + void on_loadFile_clicked(); +}; + +#endif // LINEARDIALGADGETOPTIONSPAGE_H diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui new file mode 100644 index 000000000..881cdb8ae --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui @@ -0,0 +1,269 @@ + + + LineardialGadgetOptionsPage + + + + 0 + 0 + 486 + 300 + + + + + 0 + 0 + + + + Form + + + + + -1 + -1 + 481 + 339 + + + + + QLayout::SetMinimumSize + + + 10 + + + 5 + + + 10 + + + 10 + + + + + 10 + + + QLayout::SetMaximumSize + + + 10 + + + + + Dial SVG: + + + + + + + + + + Load file... + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Green + + + + + + + Min + + + + + + + + 0 + 0 + + + + + + + + Max + + + + + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Yellow + + + + + + + Min + + + + + + + + 0 + 0 + + + + + + + + Max + + + + + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Red + + + + + + + Min + + + + + + + + 0 + 0 + + + + + + + + Max + + + + + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp new file mode 100644 index 000000000..84a723b9c --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp @@ -0,0 +1,209 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetwidget.cpp + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 "lineardialgadgetwidget.h" + +#include +#include +#include + +LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(parent) +{ + setMinimumSize(64,64); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + setScene(new QGraphicsScene(this)); + + m_renderer = new QSvgRenderer(); + background = new QGraphicsSvgItem(); + foreground = new QGraphicsSvgItem(); + bargraph = new QGraphicsSvgItem(); + green = new QGraphicsSvgItem(); + yellow = new QGraphicsSvgItem(); + red = new QGraphicsSvgItem(); + index = new QGraphicsSvgItem(); + paint(); + + indexTarget = 0; + indexValue = 0; + + // This timer mechanism makes needles rotate smoothly + connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex())); + dialTimer.start(30); + + // Test code for timer to rotate the needle + testSpeed=0; + connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate())); + m_testTimer.start(4000); +} + +LineardialGadgetWidget::~LineardialGadgetWidget() +{ + // Do nothing +} + +void LineardialGadgetWidget::connectInput(QString object1, QString field1) { + +} + + + +void LineardialGadgetWidget::setDialFile(QString dfn) +{ + if (QFile::exists(dfn)) + { + m_renderer->load(dfn); + if(m_renderer->isValid()) + { + fgenabled = false; + + background->setSharedRenderer(m_renderer); + background->setElementId("background"); + index->setSharedRenderer(m_renderer); + index->setElementId("needle"); + // TODO: transform the green, yellow & red zones + // according to their min/max. + green->setSharedRenderer(m_renderer); + green->setElementId("green"); + yellow->setSharedRenderer(m_renderer); + yellow->setElementId("yellow"); + red->setSharedRenderer(m_renderer); + red->setElementId("red"); + + if (m_renderer->elementExists("foreground")) { + foreground->setSharedRenderer(m_renderer); + foreground->setElementId("foreground"); + fgenabled = true; + } + + std::cout<<"Dial file loaded"<boundingRect().width(); + std::cout << "Width:" << green->boundingRect().width(); + QTransform matrix; + matrix.translate(greenStart,0); + matrix.scale(greenScale,1); + green->setTransform(matrix,false); + + double yellowScale = (yellowMax-yellowMin)/range; + double yellowStart = yellowMin/range*yellow->boundingRect().width(); + matrix.reset(); + matrix.translate(yellowStart,0); + matrix.scale(yellowScale,1); + yellow->setTransform(matrix,false); + + double redScale = (redMax-redMin)/range; + double redStart = redMin/range*red->boundingRect().width(); + matrix.reset(); + matrix.translate(redStart,0); + matrix.scale(redScale,1); + red->setTransform(matrix,false); + + + l_scene->setSceneRect(background->boundingRect()); + + } + } + else + { std::cout<<"no file: "<clear(); + + l_scene->addItem(background); + // Order is important: red, then yellow then green + // overlayed on top of each other + l_scene->addItem(red); + l_scene->addItem(yellow); + l_scene->addItem(green); + l_scene->addItem(index); + l_scene->addItem(foreground); + + update(); +} + +void LineardialGadgetWidget::paintEvent(QPaintEvent *event) +{ + // Skip painting until the dial file is loaded + if (! m_renderer->isValid()) { + std::cout<<"Dial file not loaded, not rendering"< 3)) { + indexValue += (indexTarget - indexValue)/10; + index->resetTransform(); + double factor = index->boundingRect().width()/100; + index->translate(indexValue*factor,0); + } + update(); +} + + +// Test function for timer to rotate needles +void LineardialGadgetWidget::testRotate() +{ + int testVal = rand() % (int)maxValue; + setIndex((double)testVal); + +} diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.h b/ground/src/plugins/lineardial/lineardialgadgetwidget.h new file mode 100644 index 000000000..efcd5d2c0 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.h @@ -0,0 +1,102 @@ +/** + ****************************************************************************** + * + * @file lineardialgadgetwidget.h + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 LINEARDIALGADGETWIDGET_H_ +#define LINEARDIALGADGETWIDGET_H_ + +#include "lineardialgadgetconfiguration.h" +#include +#include +#include + +#include +#include + +class LineardialGadgetWidget : public QGraphicsView +{ + Q_OBJECT + +public: + LineardialGadgetWidget(QWidget *parent = 0); + ~LineardialGadgetWidget(); + void setDialFile(QString dfn); + void paint(); + void setRange(double min, double max) { minValue=min; maxValue=max;} + void setGreenRange(double min, double max) {greenMin=min; greenMax=max;} + void setYellowRange(double min, double max) {yellowMin=min; yellowMax=max;} + void setRedRange(double min, double max) {redMin=min; yellowMax=max;} + void connectInput(QString obj, QString field); + + void setIndex(double val); + +protected: + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + +private slots: + // Test function + void testRotate(); + void moveIndex(); + +private: + QSvgRenderer *m_renderer; + QGraphicsSvgItem *background; + QGraphicsSvgItem *foreground; + QGraphicsSvgItem *bargraph; + QGraphicsSvgItem *index; + QGraphicsSvgItem *green; + QGraphicsSvgItem *yellow; + QGraphicsSvgItem *red; + + // Simple flag to skip rendering if the + bool fgenabled; // layer does not exist. + + double minValue; + double maxValue; + double greenMin; + double greenMax; + double yellowMin; + double yellowMax; + double redMin; + double redMax; + + // The Value and target variables + // are expressed in degrees + double indexTarget; + double indexValue; + + // Rotation timer + QTimer dialTimer; + + // Test variables + int testSpeed; + QTimer m_testTimer; + // End test variables +}; +#endif /* LINEARDIALGADGETWIDGET_H_ */ diff --git a/ground/src/plugins/lineardial/lineardialplugin.cpp b/ground/src/plugins/lineardial/lineardialplugin.cpp new file mode 100644 index 000000000..c8587f067 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialplugin.cpp @@ -0,0 +1,66 @@ +/** + ****************************************************************************** + * + * @file lineardialplugin.h + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 "lineardialplugin.h" +#include "lineardialgadgetfactory.h" +#include +#include +#include +#include + + +LineardialPlugin::LineardialPlugin() +{ + // Do nothing +} + +LineardialPlugin::~LineardialPlugin() +{ + // Do nothing +} + +bool LineardialPlugin::initialize(const QStringList& args, QString *errMsg) +{ + Q_UNUSED(args); + Q_UNUSED(errMsg); + mf = new LineardialGadgetFactory(this); + addAutoReleasedObject(mf); + + return true; +} + +void LineardialPlugin::extensionsInitialized() +{ + // Do nothing +} + +void LineardialPlugin::shutdown() +{ + // Do nothing +} +Q_EXPORT_PLUGIN(LineardialPlugin) + diff --git a/ground/src/plugins/lineardial/lineardialplugin.h b/ground/src/plugins/lineardial/lineardialplugin.h new file mode 100644 index 000000000..55395bce7 --- /dev/null +++ b/ground/src/plugins/lineardial/lineardialplugin.h @@ -0,0 +1,47 @@ +/** + ****************************************************************************** + * + * @file lineardialplugin.h + * @author Edouard Lafargue Copyright (C) 2010. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup lineardial + * @{ + * + *****************************************************************************/ +/* + * 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 LINEARDIALPLUGIN_H_ +#define LINEARDIALPLUGIN_H_ + +#include + +class LineardialGadgetFactory; + +class LineardialPlugin : public ExtensionSystem::IPlugin +{ +public: + LineardialPlugin(); + ~LineardialPlugin(); + + void extensionsInitialized(); + bool initialize(const QStringList & arguments, QString * errorString); + void shutdown(); +private: + LineardialGadgetFactory *mf; +}; +#endif /* LINEARDIALPLUGIN_H_ */ diff --git a/ground/src/plugins/plugins.pro b/ground/src/plugins/plugins.pro index 1e5dac744..58e2e84bb 100644 --- a/ground/src/plugins/plugins.pro +++ b/ground/src/plugins/plugins.pro @@ -75,6 +75,11 @@ plugin_airspeed.subdir = airspeed plugin_airspeed.depends = plugin_coreplugin SUBDIRS += plugin_airspeed +#Linear Dial Gadget +plugin_lineardial.subdir = lineardial +plugin_lineardial.depends = plugin_coreplugin +SUBDIRS += plugin_lineardial + #Config Gadget plugin_config.subdir = config plugin_config.depends = plugin_coreplugin