QGCHilConfiguration.cc 4.38 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
#include "QGCHilXPlaneConfiguration.h"
32
#include "UAS.h"
33

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

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

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

    settings.endGroup();
56 57
}

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

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

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

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

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

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

Lorenz Meier's avatar
Lorenz Meier committed
109
        // Select correct version of XPlane
110
        QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(_vehicle->uas()->getHILSimulation());
Lorenz Meier's avatar
Lorenz Meier committed
111 112 113
        if (xplane)
        {
            xplane->setVersion((index == 2) ? 10 : 9);
114
            connect(xplane, &QGCXPlaneLink::statusMessage, ui->statusLabel, &QLabel::setText);
Lorenz Meier's avatar
Lorenz Meier committed
115
        }
116
    }
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
// 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)));
//        }
//    }
132
}