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

    connect(mav, SIGNAL(destroyed()), this, SLOT(deleteLater()));
34 35
}

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

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

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

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

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

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

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