QGCHilConfiguration.cc 3.19 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
    QSettings settings;
    settings.beginGroup("QGC_HILCONFIG");
    settings.setValue("SIMULATOR_INDEX", ui->simComboBox->currentIndex());
    settings.endGroup();
45 46 47
    delete ui;
}

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

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

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

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

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