1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Linear dial: now connects to objects and prints field name. I will add field value + unit later. Tests welcome on real HW. Need to also add a font chooser in the config. Use with dials-master-linear.svg

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@715 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-06-04 10:43:54 +00:00 committed by edouard
parent 207e4b6a75
commit dbcfea244e
9 changed files with 179 additions and 25 deletions

View File

@ -217,6 +217,13 @@
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective2940"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
@ -225,16 +232,16 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="137.09042"
inkscape:zoom="7.9195959"
inkscape:cx="197.58205"
inkscape:cy="20.867055"
inkscape:document-units="px"
inkscape:current-layer="layer6"
inkscape:current-layer="g2932"
showgrid="false"
inkscape:window-width="1280"
inkscape:window-height="744"
inkscape:window-height="998"
inkscape:window-x="-4"
inkscape:window-y="1020"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:object-paths="true"
showguides="true"
@ -313,7 +320,7 @@
id="bargraph-outer"
style="fill:#332d2d;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<rect
style="fill:#332d2d;fill-opacity:1;stroke:none;stroke-width:2;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
style="fill:#332d2d;fill-opacity:1;stroke:none"
id="bargraph"
width="260.53882"
height="9.2538376"
@ -324,6 +331,18 @@
inkscape:export-xdpi="88.809998"
inkscape:export-ydpi="88.809998"
inkscape:label="#rect4388" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 249.16159,372.07875 1.13642,0.12627"
id="field"
sodipodi:nodetypes="cc"
inkscape:label="#path2930" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline"
d="m 451.7298,372.12602 1.13642,0.12627"
id="value"
sodipodi:nodetypes="cc"
inkscape:label="#path2930" />
</g>
</g>
<g
@ -421,16 +440,16 @@
inkscape:label="Text"
style="display:inline">
<text
transform="translate(-227.44331,-365.7337)"
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans"
x="247.64636"
y="386.07877"
id="text4390"><tspan
x="22.203053"
y="20.345066"
id="bb"
inkscape:label="#text4390"><tspan
sodipodi:role="line"
id="tspan4392"
x="247.64636"
y="386.07877"
x="22.203053"
y="20.345066"
style="font-size:18px;fill:#ffffff;fill-opacity:1">Vbat</tspan></text>
<text
transform="translate(-227.44331,-365.7337)"

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -6,5 +6,6 @@
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="0.0.1"/>
</dependencyList>
</plugin>

View File

@ -3,7 +3,7 @@ TARGET = LineardialGadget
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/qwt/qwt.pri)
include(lineardial_dependencies.pri)
HEADERS += lineardialplugin.h
HEADERS += lineardialgadget.h
HEADERS += lineardialgadgetwidget.h

View File

@ -28,6 +28,9 @@
#include "lineardialgadgetoptionspage.h"
#include "lineardialgadgetconfiguration.h"
#include "ui_lineardialgadgetoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavdataobject.h"
#include <QFileDialog>
#include <QtAlgorithms>
@ -60,10 +63,36 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
options_page->redMin->setValue(m_config->getRedMin());
options_page->redMax->setValue(m_config->getRedMax());
// Fills the combo boxes for the UAVObjects
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->objectName->addItem(obj->getName());
}
}
//select saved UAV Object field values
if(options_page->objectName->findText(m_config->getSourceDataObject())!=-1){
options_page->objectName->setCurrentIndex(options_page->objectName->findText(m_config->getSourceDataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getSourceDataObject()) );
if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->objectField->addItem(field->getName());
}
// And set the highlighed value from the settings:
options_page->objectField->setCurrentIndex(options_page->objectField->findText(m_config->getSourceObjectField()));
}
}
connect(options_page->objectName, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_objectName_currentIndexChanged(QString)));
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
return optionsPageWidget;
}
/**
* Called when the user presses apply or OK.
*
@ -77,6 +106,8 @@ void LineardialGadgetOptionsPage::apply()
m_config->setGreenRange(options_page->greenMin->value(),options_page->greenMax->value());
m_config->setYellowRange(options_page->yellowMin->value(),options_page->yellowMax->value());
m_config->setRedRange(options_page->redMin->value(),options_page->redMax->value());
m_config->setSourceDataObject(options_page->objectName->currentText());
m_config->setSourceObjField(options_page->objectField->currentText());
}
/**
@ -98,6 +129,20 @@ void LineardialGadgetOptionsPage::on_loadFile_clicked()
}
/*
Fills in the field1 combo box when value is changed in the
object1 field
*/
void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val) {
options_page->objectField->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
options_page->objectField->addItem(field->getName());
}
}
void LineardialGadgetOptionsPage::finish()
{

View File

@ -61,6 +61,8 @@ private:
private slots:
void on_loadFile_clicked();
void on_objectName_currentIndexChanged(QString val);
};
#endif // LINEARDIALGADGETOPTIONSPAGE_H

View File

@ -394,7 +394,14 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QComboBox" name="objectName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
@ -404,7 +411,14 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
<widget class="QComboBox" name="objectField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>

View File

@ -44,8 +44,13 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
yellow = new QGraphicsSvgItem();
red = new QGraphicsSvgItem();
index = new QGraphicsSvgItem();
fieldName = new QGraphicsTextItem("Field");
fieldName->setDefaultTextColor(QColor("White"));
fieldValue = new QGraphicsTextItem("3.0 V");
paint();
obj1 = NULL;
indexTarget = 0;
indexValue = 0;
@ -53,10 +58,12 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
dialTimer.start(30);
#if 0
// Test code for timer to move the index
testSpeed=0;
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
m_testTimer.start(1000);
#endif
}
LineardialGadgetWidget::~LineardialGadgetWidget()
@ -64,11 +71,47 @@ LineardialGadgetWidget::~LineardialGadgetWidget()
// Do nothing
}
void LineardialGadgetWidget::connectInput(QString object1, QString field1) {
/*!
\brief Connects the widget to the relevant UAVObjects
*/
void LineardialGadgetWidget::connectInput(QString object1, QString nfield1) {
if (obj1 != NULL)
disconnect(obj1,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateIndex(UAVObject*)));
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
std::cout << "Lineadial Connect needles - " << object1.toStdString() << "-"<< nfield1.toStdString() << std::endl;
// Check validity of arguments first, reject empty args and unknown fields.
if (!(object1.isEmpty() || nfield1.isEmpty())) {
obj1 = dynamic_cast<UAVDataObject*>( objManager->getObject(object1) );
if (obj1 != NULL ) {
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateIndex(UAVObject*)));
field1 = nfield1;
fieldName->setPlainText(nfield1);
} else {
std::cout << "Error: Object is unknown (" << object1.toStdString() << ") this should not happen." << std::endl;
}
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
// Double check that the field exists:
UAVObjectField* field = object1->getField(field1);
if (field) {
double v = field->getDouble();
setIndex(v);
QString s;
s.sprintf("%.2f",v);
fieldValue->setPlainText(s);
} else {
std::cout << "Wrong field, maybe an issue with object disconnection ?" << std::endl;
}
}
void LineardialGadgetWidget::setDialFile(QString dfn)
{
@ -83,8 +126,6 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
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);
@ -97,22 +138,38 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
foreground->setElementId("foreground");
fgenabled = true;
}
std::cout<<"Dial file loaded"<<std::endl;
//std::cout<<"Dial file loaded"<<std::endl;
QGraphicsScene *l_scene = scene();
QMatrix textMatrix = m_renderer->matrixForElement("field");
startX = textMatrix.mapRect(m_renderer->boundsOnElement("field")).x();
startY = textMatrix.mapRect(m_renderer->boundsOnElement("field")).y();
QTransform matrix;
matrix.translate(startX,startY);
fieldName->setTransform(matrix,false);
textMatrix = m_renderer->matrixForElement("value");
startX = textMatrix.mapRect(m_renderer->boundsOnElement("field")).x();
startY = textMatrix.mapRect(m_renderer->boundsOnElement("field")).y();
matrix.reset();
matrix.translate(startX,startY);
fieldValue->setTransform(matrix,false);
// In order to properly render the Green/Yellow/Red graphs, we need to find out
// the starting location of the bargraph rendering area:
QMatrix barMatrix = m_renderer->matrixForElement("bargraph");
startX = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).x();
startY = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).y();
std::cout << "StartX: " << startX << std::endl;
std::cout << "StartY: " << startY << std::endl;
//std::cout << "StartX: " << startX << std::endl;
//std::cout << "StartY: " << startY << std::endl;
bargraphWidth = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
indexHeight = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).height();
indexWidth = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).width();
std::cout << "Index height: " << indexHeight << std::endl;
//std::cout << "Index height: " << indexHeight << std::endl;
QTransform matrix;
// QTransform matrix;
matrix.reset();
matrix.translate(startX-indexWidth/2,startY-indexHeight/2);
index->setTransform(matrix,false);
// Now adjust the red/yellow/green zones:
@ -163,6 +220,7 @@ void LineardialGadgetWidget::paint()
l_scene->addItem(yellow);
l_scene->addItem(green);
l_scene->addItem(index);
l_scene->addItem(fieldName);
l_scene->addItem(foreground);
update();

View File

@ -29,6 +29,9 @@
#define LINEARDIALGADGETWIDGET_H_
#include "lineardialgadgetconfiguration.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobject.h"
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
@ -50,9 +53,12 @@ public:
void setYellowRange(double min, double max) {yellowMin=min; yellowMax=max;}
void setRedRange(double min, double max) {redMin=min; redMax=max;}
void connectInput(QString obj, QString field);
void setIndex(double val);
public slots:
void updateIndex(UAVObject *object1);
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
@ -73,6 +79,9 @@ private:
QGraphicsSvgItem *yellow;
QGraphicsSvgItem *red;
QGraphicsTextItem *fieldName;
QGraphicsTextItem *fieldValue;
// Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
@ -101,6 +110,11 @@ private:
// Rotation timer
QTimer dialTimer;
// Name of the fields to read when an update is received:
UAVDataObject* obj1;
QString field1;
// Test variables
int testSpeed;
QTimer m_testTimer;

View File

@ -81,6 +81,7 @@ SUBDIRS += plugin_airspeed
#Linear Dial Gadget
plugin_lineardial.subdir = lineardial
plugin_lineardial.depends = plugin_coreplugin
plugin_lineardial.depends = plugin_uavobjects
SUBDIRS += plugin_lineardial
#System health Gadget