From 4709e97b21cd6d2c02947fde964cc00ea05780f5 Mon Sep 17 00:00:00 2001 From: edouard Date: Sun, 11 Jul 2010 22:04:11 +0000 Subject: [PATCH] OP-82: Fallback default artwork in case of error (no crash anymore), added GPS satellites count to PFD. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1076 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/share/openpilotgcs/pfd/default/pfd.svg | 14 +- ground/src/plugins/dial/dialgadgetwidget.cpp | 1 - ground/src/plugins/pfd/images/pfd-default.svg | 394 ++++++++++++++++++ ground/src/plugins/pfd/pfd.pro | 41 +- ground/src/plugins/pfd/pfd.qrc | 5 + ground/src/plugins/pfd/pfdgadgetwidget.cpp | 70 +++- ground/src/plugins/pfd/pfdgadgetwidget.h | 5 +- 7 files changed, 491 insertions(+), 39 deletions(-) create mode 100644 ground/src/plugins/pfd/images/pfd-default.svg create mode 100644 ground/src/plugins/pfd/pfd.qrc diff --git a/ground/share/openpilotgcs/pfd/default/pfd.svg b/ground/share/openpilotgcs/pfd/default/pfd.svg index 5808c2449..c1e4dade4 100755 --- a/ground/share/openpilotgcs/pfd/default/pfd.svg +++ b/ground/share/openpilotgcs/pfd/default/pfd.svg @@ -15,7 +15,7 @@ id="svg2" version="1.1" inkscape:version="0.47 r22583" - sodipodi:docname="PFD-2.svg" + sodipodi:docname="pfd.svg" style="display:inline" inkscape:export-filename="H:\Documents\Hobbies\OpenPilot\SVN\artwork\PFD-2.png" inkscape:export-xdpi="269.53" @@ -3663,13 +3663,13 @@ inkscape:label="#rect7029" /> + style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:4.18869495;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline" /> clear(); // This also deletes all items contained in the scene. m_background = new QGraphicsSvgItem(); m_background->setSharedRenderer(m_renderer); - m_background->setElementId(bg); l_scene->addItem(m_background); m_text1 = NULL; m_text2 = NULL; diff --git a/ground/src/plugins/pfd/images/pfd-default.svg b/ground/src/plugins/pfd/images/pfd-default.svg new file mode 100644 index 000000000..0fdc3669b --- /dev/null +++ b/ground/src/plugins/pfd/images/pfd-default.svg @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ground/src/plugins/pfd/pfd.pro b/ground/src/plugins/pfd/pfd.pro index eb6c8185c..f0c9956c4 100644 --- a/ground/src/plugins/pfd/pfd.pro +++ b/ground/src/plugins/pfd/pfd.pro @@ -1,20 +1,21 @@ -TEMPLATE = lib -TARGET = PFDGadget -QT += svg -include(../../openpilotgcsplugin.pri) -include(../../plugins/coreplugin/coreplugin.pri) -include(pfd_dependencies.pri) -HEADERS += pfdplugin.h -HEADERS += pfdgadget.h -HEADERS += pfdgadgetwidget.h -HEADERS += pfdgadgetfactory.h -HEADERS += pfdgadgetconfiguration.h -HEADERS += pfdgadgetoptionspage.h -SOURCES += pfdplugin.cpp -SOURCES += pfdgadget.cpp -SOURCES += pfdgadgetfactory.cpp -SOURCES += pfdgadgetwidget.cpp -SOURCES += pfdgadgetconfiguration.cpp -SOURCES += pfdgadgetoptionspage.cpp -OTHER_FILES += PFDGadget.pluginspec -FORMS += pfdgadgetoptionspage.ui +TEMPLATE = lib +TARGET = PFDGadget +QT += svg +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(pfd_dependencies.pri) +HEADERS += pfdplugin.h +HEADERS += pfdgadget.h +HEADERS += pfdgadgetwidget.h +HEADERS += pfdgadgetfactory.h +HEADERS += pfdgadgetconfiguration.h +HEADERS += pfdgadgetoptionspage.h +SOURCES += pfdplugin.cpp +SOURCES += pfdgadget.cpp +SOURCES += pfdgadgetfactory.cpp +SOURCES += pfdgadgetwidget.cpp +SOURCES += pfdgadgetconfiguration.cpp +SOURCES += pfdgadgetoptionspage.cpp +OTHER_FILES += PFDGadget.pluginspec +FORMS += pfdgadgetoptionspage.ui +RESOURCES += pfd.qrc diff --git a/ground/src/plugins/pfd/pfd.qrc b/ground/src/plugins/pfd/pfd.qrc new file mode 100644 index 000000000..278dd281e --- /dev/null +++ b/ground/src/plugins/pfd/pfd.qrc @@ -0,0 +1,5 @@ + + + images/pfd-default.svg + + diff --git a/ground/src/plugins/pfd/pfdgadgetwidget.cpp b/ground/src/plugins/pfd/pfdgadgetwidget.cpp index 930188866..9e78bdc60 100644 --- a/ground/src/plugins/pfd/pfdgadgetwidget.cpp +++ b/ground/src/plugins/pfd/pfdgadgetwidget.cpp @@ -38,12 +38,14 @@ PFDGadgetWidget::PFDGadgetWidget(QWidget *parent) : QGraphicsView(parent) setMinimumSize(64,64); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setScene(new QGraphicsScene(this)); - setRenderHints(QPainter::Antialiasing); + //setRenderHints(QPainter::Antialiasing || QPainter::TextAntialiasing); + setRenderHints(QPainter::TextAntialiasing); m_renderer = new QSvgRenderer(); attitudeObj = NULL; headingObj = NULL; + gcsBatteryObj = NULL; compassBandWidth = 0; /* obj2 = NULL; @@ -80,6 +82,9 @@ void PFDGadgetWidget::connectNeedles() { if (gcsBatteryObj != NULL) disconnect(gcsBatteryObj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateBattery(UAVObject*))); + // Safeguard: if artwork did not load properly, don't go further + if (pfdError) + return; ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); @@ -114,7 +119,7 @@ void PFDGadgetWidget::connectNeedles() { } /*! - \brief Updates the link stats + \brief Updates the link stats */ void PFDGadgetWidget::updateLinkStatus(UAVObject *object1) { // Double check that the field exists: @@ -199,6 +204,14 @@ void PFDGadgetWidget::updateHeading(UAVObject *object1) { altitudeTarget = field->getDouble()*altitudeScaleHeight/(30); } + // GPS Stats + fieldname = QString("Satellites"); + field = object1->getField(fieldname); + if (field) { + QString s = QString("GPS: ") + field->getValue().toString(); + gcsGPSStats->setPlainText(s); + } + if (!dialTimer.isActive()) dialTimer.start(); // Rearm the dial Timer which might be stopped. @@ -249,11 +262,9 @@ void PFDGadgetWidget::updateBattery(UAVObject *object1) { */ void PFDGadgetWidget::setDialFile(QString dfn) { - if (QFile::exists(dfn)) + QGraphicsScene *l_scene = scene(); + if (QFile::exists(dfn) && m_renderer->load(dfn) && m_renderer->isValid()) { - m_renderer->load(dfn); - if(m_renderer->isValid()) - { /* The PFD element IDs are fixed, not like with the analog dial. - Background: background - Foreground: foreground (contains all fixed elements, including plane) @@ -276,7 +287,6 @@ void PFDGadgetWidget::setDialFile(QString dfn) - GPS status text: gps-txt - Battery stats: battery-txt */ - QGraphicsScene *l_scene = scene(); l_scene->clear(); // Deletes all items contained in the scene as well. m_background = new QGraphicsSvgItem(); // All other items will be clipped to the shape of the background @@ -546,7 +556,7 @@ void PFDGadgetWidget::setDialFile(QString dfn) //////////////// // GCS Battery Indicator //////////////// - /* + /* (to be used the day I add a green/yellow/red indicator) compassMatrix = m_renderer->matrixForElement("gcstelemetry-Disconnected"); startX = compassMatrix.mapRect(m_renderer->boundsOnElement("gcstelemetry-Disconnected")).x(); startY = compassMatrix.mapRect(m_renderer->boundsOnElement("gcstelemetry-Disconnected")).y(); @@ -571,6 +581,34 @@ void PFDGadgetWidget::setDialFile(QString dfn) matrix.translate(startX,startY-batStatHeight/2); gcsBatteryStats->setTransform(matrix,false); + //////////////// + // GCS GPS Indicator + //////////////// + /* (to be used the day I add a green/yellow/red indicator) + compassMatrix = m_renderer->matrixForElement("gcstelemetry-Disconnected"); + startX = compassMatrix.mapRect(m_renderer->boundsOnElement("gcstelemetry-Disconnected")).x(); + startY = compassMatrix.mapRect(m_renderer->boundsOnElement("gcstelemetry-Disconnected")).y(); + gcsTelemetryArrow = new QGraphicsSvgItem(); + gcsTelemetryArrow->setSharedRenderer(m_renderer); + gcsTelemetryArrow->setElementId("gcstelemetry-Disconnected"); + l_scene->addItem(gcsTelemetryArrow); + matrix.reset(); + matrix.translate(startX,startY); + gcsTelemetryArrow->setTransform(matrix,false); + */ + + compassMatrix = m_renderer->matrixForElement("gps-txt"); + startX = compassMatrix.mapRect(m_renderer->boundsOnElement("gps-txt")).x(); + startY = compassMatrix.mapRect(m_renderer->boundsOnElement("gps-txt")).y(); + qreal gpsStatHeight = compassMatrix.mapRect(m_renderer->boundsOnElement("gps-txt")).height(); + gcsGPSStats = new QGraphicsTextItem(); + gcsGPSStats->setDefaultTextColor(QColor("White")); + gcsGPSStats->setFont(QFont("Arial",(int) gpsStatHeight)); + l_scene->addItem(gcsGPSStats); + matrix.reset(); + matrix.translate(startX,startY-gpsStatHeight/2); + gcsGPSStats->setTransform(matrix,false); + l_scene->setSceneRect(m_background->boundingRect()); @@ -608,12 +646,19 @@ void PFDGadgetWidget::setDialFile(QString dfn) headingValue = 0; groundspeedValue = 0; altitudeValue = 0; + pfdError = false; if (!dialTimer.isActive()) dialTimer.start(); // Rearm the dial Timer which might be stopped. - } } else - { qDebug()<<"no file."; } + { qDebug()<<"Error on PFD artwork file."; + m_renderer->load(QString(":/pfd/images/pfd-default.svg")); + l_scene->clear(); // This also deletes all items contained in the scene. + m_background = new QGraphicsSvgItem(); + m_background->setSharedRenderer(m_renderer); + l_scene->addItem(m_background); + pfdError = true; + } } void PFDGadgetWidget::paint() @@ -658,6 +703,11 @@ void PFDGadgetWidget::moveNeedles() /// TODO: optimize!!! + if (pfdError) { + dialTimer.stop(); + return; + } + ////// // Roll ////// diff --git a/ground/src/plugins/pfd/pfdgadgetwidget.h b/ground/src/plugins/pfd/pfdgadgetwidget.h index f7e4d99bc..39d1f07ea 100644 --- a/ground/src/plugins/pfd/pfdgadgetwidget.h +++ b/ground/src/plugins/pfd/pfdgadgetwidget.h @@ -101,6 +101,7 @@ private: QGraphicsSvgItem *gcsTelemetryArrow; QGraphicsTextItem *gcsTelemetryStats; QGraphicsTextItem *gcsBatteryStats; + QGraphicsTextItem *gcsGPSStats; // The Value and target variables // are expressed in degrees @@ -127,7 +128,9 @@ private: // Rotation timer QTimer dialTimer; - QTimer dialTimer2; + + // Flag to check for pfd Error + bool pfdError; }; #endif /* PFDGADGETWIDGET_H_ */