QGCHilConfiguration.cc 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10

11 12
#include <QSettings>

13 14 15
#include "QGCHilConfiguration.h"
#include "ui_QGCHilConfiguration.h"

16
#include "QGCHilFlightGearConfiguration.h"
17
#include "QGCHilJSBSimConfiguration.h"
18
#include "QGCHilXPlaneConfiguration.h"
19
#include "UAS.h"
20

21 22 23 24
QGCHilConfiguration::QGCHilConfiguration(Vehicle* vehicle, QWidget *parent)
    : QWidget(parent)
    , _vehicle(vehicle)
    , ui(new Ui::QGCHilConfiguration)
25 26
{
    ui->setupUi(this);
27 28 29 30 31 32

    // 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");
33
    int i = settings.value("SIMULATOR_INDEX", -1).toInt();
34 35

    if (i > 0) {
36
//        ui->simComboBox->blockSignals(true);
37
        ui->simComboBox->setCurrentIndex(i);
38
//        ui->simComboBox->blockSignals(false);
Lorenz Meier's avatar
Lorenz Meier committed
39
        on_simComboBox_currentIndexChanged(i);
40 41 42
    }

    settings.endGroup();
43 44
}

45 46 47 48 49
void QGCHilConfiguration::receiveStatusMessage(const QString& message)
{
    ui->statusLabel->setText(message);
}

50 51
QGCHilConfiguration::~QGCHilConfiguration()
{
52 53 54 55
    QSettings settings;
    settings.beginGroup("QGC_HILCONFIG");
    settings.setValue("SIMULATOR_INDEX", ui->simComboBox->currentIndex());
    settings.endGroup();
56 57 58
    delete ui;
}

59 60
void QGCHilConfiguration::setVersion(QString version)
{
61
    Q_UNUSED(version);
62 63
}

64
void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
65
{
66 67 68 69
    //clean up
    QLayoutItem *child;
    while ((child = ui->simulatorConfigurationLayout->takeAt(0)) != 0)
    {
70 71
        delete child->widget();
        delete child;
72 73
    }

74
    if(1 == index)
75
    {
Lorenz Meier's avatar
Lorenz Meier committed
76
        // Ensure the sim exists and is disabled
77
        _vehicle->uas()->enableHilFlightGear(false, "", true, this);
78
        QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(_vehicle, this);
79
        hfgconf->show();
80
        ui->simulatorConfigurationLayout->addWidget(hfgconf);
81
        QGCFlightGearLink* fg = dynamic_cast<QGCFlightGearLink*>(_vehicle->uas()->getHILSimulation());
82 83
        if (fg)
        {
84
            connect(fg, &QGCFlightGearLink::statusMessage, ui->statusLabel, &QLabel::setText);
85
        }
86

87
    }
88
    else if (2 == index || 3 == index)
89
    {
Lorenz Meier's avatar
Lorenz Meier committed
90
        // Ensure the sim exists and is disabled
91 92
        _vehicle->uas()->enableHilXPlane(false);
        QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(_vehicle->uas()->getHILSimulation(), this);
93
        hxpconf->show();
94
        ui->simulatorConfigurationLayout->addWidget(hxpconf);
95

Lorenz Meier's avatar
Lorenz Meier committed
96
        // Select correct version of XPlane
97
        QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(_vehicle->uas()->getHILSimulation());
Lorenz Meier's avatar
Lorenz Meier committed
98 99 100
        if (xplane)
        {
            xplane->setVersion((index == 2) ? 10 : 9);
101
            connect(xplane, &QGCXPlaneLink::statusMessage, ui->statusLabel, &QLabel::setText);
Lorenz Meier's avatar
Lorenz Meier committed
102
        }
103
    }
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
// Disabling JSB Sim since its not well maintained,
// but as refactoring is pending we're not ditching the code yet
//    else if (4)
//    {
//        // Ensure the sim exists and is disabled
//        _vehicle->uas()->enableHilJSBSim(false, "");
//        QGCHilJSBSimConfiguration* hfgconf = new QGCHilJSBSimConfiguration(_vehicle, this);
//        hfgconf->show();
//        ui->simulatorConfigurationLayout->addWidget(hfgconf);
//        QGCJSBSimLink* jsb = dynamic_cast<QGCJSBSimLink*>(_vehicle->uas()->getHILSimulation());
//        if (jsb)
//        {
//            connect(jsb, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
//        }
//    }
119
}