Skip to content
HDDisplay.cc 32.9 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/*=====================================================================
======================================================================*/

/**
 * @file
 *   @brief Implementation of Head Down Display (HDD)
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#include <QFile>
#include <QGLWidget>
pixhawk's avatar
pixhawk committed
#include <QStringList>
#include <QDockWidget>
#include <QInputDialog>
#include <QMenu>
#include <QSettings>
pixhawk's avatar
pixhawk committed
#include "UASManager.h"
#include "HDDisplay.h"
#include "ui_HDDisplay.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
pixhawk's avatar
pixhawk committed
#include <QDebug>

HDDisplay::HDDisplay(QStringList* plotList, QString title, QWidget *parent) :
pixhawk's avatar
pixhawk committed
        uas(NULL),
        values(QMap<QString, float>()),
        valuesDot(QMap<QString, float>()),
        valuesMean(QMap<QString, float>()),
        valuesCount(QMap<QString, int>()),
        lastUpdate(QMap<QString, quint64>()),
pixhawk's avatar
pixhawk committed
        minValues(),
        maxValues(),
        goodRanges(),
        critRanges(),
pixhawk's avatar
pixhawk committed
        xCenterOffset(0.0f),
        yCenterOffset(0.0f),
        vwidth(80.0f),
        vheight(80.0f),
        backgroundColor(QColor(0, 0, 0)),
        defaultColor(QColor(70, 200, 70)),
        setPointColor(QColor(200, 20, 200)),
        warningColor(Qt::yellow),
        criticalColor(Qt::red),
        infoColor(QColor(20, 200, 20)),
        fuelColor(criticalColor),
        warningBlinkRate(5),
        refreshTimer(new QTimer(this)),
        hardwareAcceleration(true),
        strongStrokeWidth(1.5f),
        normalStrokeWidth(1.0f),
        fineStrokeWidth(0.5f),
pixhawk's avatar
pixhawk committed
        m_ui(new Ui::HDDisplay)
{
pixhawk's avatar
pixhawk committed
    //m_ui->setupUi(this);

    // Add all items in accept list to gauge
    if (plotList)
        for(int i = 0; i < plotList->length(); ++i)
        {
            addGauge(plotList->at(i));
        }
    // Set minimum size
    setMinimumSize(80, 80);
    // Set preferred size
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    createActions();

    //    setBackgroundBrush(QBrush(backgroundColor));
    //    setDragMode(QGraphicsView::ScrollHandDrag);
    //    setCacheMode(QGraphicsView::CacheBackground);
    //    // FIXME Handle full update with care - ressource intensive
    //    setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    //
    //    setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    //
    //    //Set-up the scene
    //    QGraphicsScene* Scene = new QGraphicsScene(this);
    //    setScene(Scene);
    //
    //    //Populate the scene
    //    for(int x = 0; x < 1000; x = x + 25) {
    //        for(int y = 0; y < 1000; y = y + 25) {
    //
    //            if(x % 100 == 0 && y % 100 == 0) {
    //                Scene->addRect(x, y, 2, 2);
    //
    //                QString pointString;
    //                QTextStream stream(&pointString);
    //                stream << "(" << x << "," << y << ")";
    //                QGraphicsTextItem* item = Scene->addText(pointString);
    //                item->setPos(x, y);
    //            } else {
    //                Scene->addRect(x, y, 1, 1);
    //            }
    //        }
    //    }
    //
    //    //Set-up the view
    //    setSceneRect(0, 0, 1000, 1000);
    //    setCenter(QPointF(500.0, 500.0)); //A modified version of centerOn(), handles special cases
    //    setCursor(Qt::OpenHandCursor);
    this->setMinimumHeight(125);
    this->setMinimumWidth(100);
pixhawk's avatar
pixhawk committed

    // Refresh timer
    refreshTimer->setInterval(180); //
    connect(refreshTimer, SIGNAL(timeout()), this, SLOT(triggerUpdate()));
pixhawk's avatar
pixhawk committed
    //connect(refreshTimer, SIGNAL(timeout()), this, SLOT(paintGL()));

    fontDatabase = QFontDatabase();
    const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app
    const QString fontFamilyName = "Bitstream Vera Sans";
    if(!QFile::exists(fontFileName)) qDebug() << "ERROR! font file: " << fontFileName << " DOES NOT EXIST!";

    fontDatabase.addApplicationFont(fontFileName);
    font = fontDatabase.font(fontFamilyName, "Roman", qMax(5, (int)(10*scalingFactor*1.2f+0.5f)));
pixhawk's avatar
pixhawk committed
    if (font.family() != fontFamilyName) qDebug() << "ERROR! Font not loaded: " << fontFamilyName;

    // Connect with UAS
pixhawk's avatar
pixhawk committed
    connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
pixhawk's avatar
pixhawk committed
    //start();
pixhawk's avatar
pixhawk committed
}

HDDisplay::~HDDisplay()
{
pixhawk's avatar
pixhawk committed
    delete m_ui;
}

QSize HDDisplay::sizeHint() const
{
    return QSize(400, 400*(vwidth/vheight));
}

void HDDisplay::enableGLRendering(bool enable)
{
void HDDisplay::triggerUpdate()
{
    // Only repaint the regions necessary
pixhawk's avatar
pixhawk committed
void HDDisplay::paintEvent(QPaintEvent * event)
{
lm's avatar
lm committed
    //qDebug() << "INTERVAL:" << MG::TIME::getGroundTimeNow() - interval << __FILE__ << __LINE__;
    interval = MG::TIME::getGroundTimeNow();
void HDDisplay::contextMenuEvent (QContextMenuEvent* event)
{
    QMenu menu(this);
    menu.addAction(addGaugeAction);
    menu.addActions(getItemRemoveActions());
    menu.addSeparator();
    menu.addAction(setColumnsAction);
    menu.addAction(setTitleAction);
    menu.exec(event->globalPos());
}

void HDDisplay::saveState()
{
    QSettings settings;

    QString instruments;
    // Restore instrument settings
    for (int i = 0; i < acceptList->count(); i++)
    {
        QString key = acceptList->at(i);
        instruments += "|" + QString::number(minValues.value(key, -1.0))+","+key+","+QString::number(maxValues.value(key, +1.0))+","+((symmetric.value(key, false)) ? "s" : "");
   // qDebug() << "Saving" << instruments;
Loading
Loading full blame...