QGCHilConfiguration.cc 4.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

24 25
#include <QSettings>

26 27 28
#include "QGCHilConfiguration.h"
#include "ui_QGCHilConfiguration.h"

29
#include "QGCHilFlightGearConfiguration.h"
30
#include "QGCHilJSBSimConfiguration.h"
31 32
#include "QGCHilXPlaneConfiguration.h"

33 34 35 36
QGCHilConfiguration::QGCHilConfiguration(Vehicle* vehicle, QWidget *parent)
    : QWidget(parent)
    , _vehicle(vehicle)
    , ui(new Ui::QGCHilConfiguration)
37 38
{
    ui->setupUi(this);
39 40 41 42 43 44

    // 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");
45
    int i = settings.value("SIMULATOR_INDEX", -1).toInt();
46 47

    if (i > 0) {
48
//        ui->simComboBox->blockSignals(true);
49
        ui->simComboBox->setCurrentIndex(i);
50
//        ui->simComboBox->blockSignals(false);
Lorenz Meier's avatar
Lorenz Meier committed
51
        on_simComboBox_currentIndexChanged(i);
52 53 54
    }

    settings.endGroup();
55 56
}

57 58 59 60 61
void QGCHilConfiguration::receiveStatusMessage(const QString& message)
{
    ui->statusLabel->setText(message);
}

62 63
QGCHilConfiguration::~QGCHilConfiguration()
{
64 65 66 67
    QSettings settings;
    settings.beginGroup("QGC_HILCONFIG");
    settings.setValue("SIMULATOR_INDEX", ui->simComboBox->currentIndex());
    settings.endGroup();
68 69 70
    delete ui;
}

71 72
void QGCHilConfiguration::setVersion(QString version)
{
73
    Q_UNUSED(version);
74 75
}

76
void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
77
{
78 79 80 81
    //clean up
    QLayoutItem *child;
    while ((child = ui->simulatorConfigurationLayout->takeAt(0)) != 0)
    {
82 83
        delete child->widget();
        delete child;
84 85
    }

86
    if(1 == index)
87
    {
Lorenz Meier's avatar
Lorenz Meier committed
88
        // Ensure the sim exists and is disabled
89 90
        _vehicle->uas()->enableHilFlightGear(false, "", true, this);
        QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(_vehicle->uas(), this);
91
        hfgconf->show();
92
        ui->simulatorConfigurationLayout->addWidget(hfgconf);
93
        QGCFlightGearLink* fg = dynamic_cast<QGCFlightGearLink*>(_vehicle->uas()->getHILSimulation());
94 95 96 97
        if (fg)
        {
            connect(fg, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
        }
98

99
    }
100
    else if (2 == index || 3 == index)
101
    {
Lorenz Meier's avatar
Lorenz Meier committed
102
        // Ensure the sim exists and is disabled
103 104
        _vehicle->uas()->enableHilXPlane(false);
        QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(_vehicle->uas()->getHILSimulation(), this);
105
        hxpconf->show();
106
        ui->simulatorConfigurationLayout->addWidget(hxpconf);
107

Lorenz Meier's avatar
Lorenz Meier committed
108
        // Select correct version of XPlane
109
        QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(_vehicle->uas()->getHILSimulation());
Lorenz Meier's avatar
Lorenz Meier committed
110 111 112
        if (xplane)
        {
            xplane->setVersion((index == 2) ? 10 : 9);
113
            connect(xplane, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
Lorenz Meier's avatar
Lorenz Meier committed
114
        }
115
    }
116 117 118
    else if (4)
    {
        // Ensure the sim exists and is disabled
119 120
        _vehicle->uas()->enableHilJSBSim(false, "");
        QGCHilJSBSimConfiguration* hfgconf = new QGCHilJSBSimConfiguration(_vehicle->uas(), this);
121 122
        hfgconf->show();
        ui->simulatorConfigurationLayout->addWidget(hfgconf);
123
        QGCJSBSimLink* jsb = dynamic_cast<QGCJSBSimLink*>(_vehicle->uas()->getHILSimulation());
124 125 126 127 128
        if (jsb)
        {
            connect(jsb, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString)));
        }
    }
129
}