QGCHilConfiguration.cc 3.2 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

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

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

    if (i > 0) {
25
//        ui->simComboBox->blockSignals(true);
26
        ui->simComboBox->setCurrentIndex(i);
27
//        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
    delete ui;
}

49 50
void QGCHilConfiguration::setVersion(QString version)
{
51
    Q_UNUSED(version);
52 53
}

54
void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
55
{
56 57 58 59
    //clean up
    QLayoutItem *child;
    while ((child = ui->simulatorConfigurationLayout->takeAt(0)) != 0)
    {
60 61
        delete child->widget();
        delete child;
62 63
    }

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

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

Lorenz Meier's avatar
Lorenz Meier committed
86 87 88 89 90
        // Select correct version of XPlane
        QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(mav->getHILSimulation());
        if (xplane)
        {
            xplane->setVersion((index == 2) ? 10 : 9);
91
            connect(xplane, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
Lorenz Meier's avatar
Lorenz Meier committed
92
        }
93
    }
94 95 96 97 98 99 100 101 102 103 104 105 106
    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)));
        }
    }
107
}