QGCHilConfiguration.cc 3.11 KB
Newer Older
1 2
#include <QSettings>

3 4 5
#include "QGCHilConfiguration.h"
#include "ui_QGCHilConfiguration.h"

6
#include "QGCHilFlightGearConfiguration.h"
7
#include "QGCHilJSBSimConfiguration.h"
8 9 10
#include "QGCHilXPlaneConfiguration.h"

QGCHilConfiguration::QGCHilConfiguration(UAS *mav, QWidget *parent) :
11
    QWidget(parent),
12
    mav(mav),
13 14 15
    ui(new Ui::QGCHilConfiguration)
{
    ui->setupUi(this);
16 17 18 19 20 21 22 23 24 25 26 27

    // XXX its quite wrong that this is implicitely a factory
    // class, but this is something to clean up for later.

    QSettings settings;
    int i = settings.value("SIMULATOR_INDEX", -1).toInt();
    settings.beginGroup("QGC_HILCONFIG");

    if (i > 0) {
        ui->simComboBox->blockSignals(true);
        ui->simComboBox->setCurrentIndex(i);
        ui->simComboBox->blockSignals(false);
Lorenz Meier's avatar
Lorenz Meier committed
28
        on_simComboBox_currentIndexChanged(i);
29 30 31
    }

    settings.endGroup();
32 33
}

34 35 36 37 38
void QGCHilConfiguration::receiveStatusMessage(const QString& message)
{
    ui->statusLabel->setText(message);
}

39 40
QGCHilConfiguration::~QGCHilConfiguration()
{
41 42 43 44 45
    QSettings settings;
    settings.beginGroup("QGC_HILCONFIG");
    settings.setValue("SIMULATOR_INDEX", ui->simComboBox->currentIndex());
    settings.endGroup();
    settings.sync();
46 47 48 49
    delete ui;
}

void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
50
{
51 52 53 54
    //clean up
    QLayoutItem *child;
    while ((child = ui->simulatorConfigurationLayout->takeAt(0)) != 0)
    {
55 56
        delete child->widget();
        delete child;
57 58
    }

59
    if(1 == index)
60
    {
Lorenz Meier's avatar
Lorenz Meier committed
61 62
        // Ensure the sim exists and is disabled
        mav->enableHilFlightGear(false, "");
63 64
        QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(mav, this);
        hfgconf->show();
65 66 67 68 69 70
        ui->simulatorConfigurationLayout->addWidget(hfgconf);
        QGCFlightGearLink* fg = dynamic_cast<QGCFlightGearLink*>(mav->getHILSimulation());
        if (fg)
        {
            connect(fg, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
        }
71

72
    }
73
    else if (2 == index || 3 == index)
74
    {
Lorenz Meier's avatar
Lorenz Meier committed
75 76
        // Ensure the sim exists and is disabled
        mav->enableHilXPlane(false);
77 78
        QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(mav->getHILSimulation(), this);
        hxpconf->show();
79
        ui->simulatorConfigurationLayout->addWidget(hxpconf);
80

Lorenz Meier's avatar
Lorenz Meier committed
81 82 83 84 85
        // Select correct version of XPlane
        QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(mav->getHILSimulation());
        if (xplane)
        {
            xplane->setVersion((index == 2) ? 10 : 9);
86
            connect(xplane, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
Lorenz Meier's avatar
Lorenz Meier committed
87
        }
88
    }
89 90 91 92 93 94 95 96 97 98 99 100 101
    else if (4)
    {
        // Ensure the sim exists and is disabled
        mav->enableHilJSBSim(false, "");
        QGCHilJSBSimConfiguration* hfgconf = new QGCHilJSBSimConfiguration(mav, this);
        hfgconf->show();
        ui->simulatorConfigurationLayout->addWidget(hfgconf);
        QGCJSBSimLink* jsb = dynamic_cast<QGCJSBSimLink*>(mav->getHILSimulation());
        if (jsb)
        {
            connect(jsb, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
        }
    }
102
}