1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

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
This commit is contained in:
chebuzz 2010-04-19 06:38:03 +00:00 committed by chebuzz
parent 6026a6ba61
commit 119280edbc
11 changed files with 545 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<plugin name="AirspeedGadget" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C)David "Buzz" Carlson</copyright>
<license>The GNU Public License (GPL) Version 3</license>
<description>An analog airspeed dial gadget!</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -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

View File

@ -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()
{
}

View File

@ -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 <coreplugin/iuavgadget.h>
#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_

View File

@ -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 <coreplugin/iuavgadget.h>
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);
}

View File

@ -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 <coreplugin/iuavgadgetfactory.h>
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_

View File

@ -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 <iostream>
#include <QtGui/QFileDialog>
#include <QDebug>
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<QWidget*>(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: "<<std::endl; }
}
void AirspeedGadgetWidget::paint()
{
QGraphicsScene *l_scene = scene();
l_scene->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++);
}

View File

@ -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 <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
#include <QFile>
// Used for test purposes
#include <QTimer>
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_ */

View File

@ -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 <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
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)

View File

@ -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 <extensionsystem/iplugin.h>
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_ */

View File

@ -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