Skip to content
Snippets Groups Projects
QGCHilConfiguration.cc 3.8 KiB
Newer Older
  • Learn to ignore specific revisions
  • /****************************************************************************
     *
     *   (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.
     *
     ****************************************************************************/
    
    
    #include "QGCHilConfiguration.h"
    #include "ui_QGCHilConfiguration.h"
    
    
    Thomas Gubler's avatar
    Thomas Gubler committed
    #include "QGCHilFlightGearConfiguration.h"
    
    Thomas Gubler's avatar
    Thomas Gubler committed
    #include "QGCHilXPlaneConfiguration.h"
    
    #include "UAS.h"
    
    QGCHilConfiguration::QGCHilConfiguration(Vehicle* vehicle, QWidget *parent)
        : QWidget(parent)
        , _vehicle(vehicle)
        , ui(new Ui::QGCHilConfiguration)
    
    
        // 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");
    
    Lorenz Meier's avatar
    Lorenz Meier committed
        int i = settings.value("SIMULATOR_INDEX", -1).toInt();
    
    //        ui->simComboBox->blockSignals(true);
    
            ui->simComboBox->setCurrentIndex(i);
    
    //        ui->simComboBox->blockSignals(false);
    
    Lorenz Meier's avatar
    Lorenz Meier committed
            on_simComboBox_currentIndexChanged(i);
    
    void QGCHilConfiguration::receiveStatusMessage(const QString& message)
    {
        ui->statusLabel->setText(message);
    }
    
    
    Thomas Gubler's avatar
    Thomas Gubler committed
    QGCHilConfiguration::~QGCHilConfiguration()
    {
    
        QSettings settings;
        settings.beginGroup("QGC_HILCONFIG");
        settings.setValue("SIMULATOR_INDEX", ui->simComboBox->currentIndex());
        settings.endGroup();
    
    Thomas Gubler's avatar
    Thomas Gubler committed
        delete ui;
    }
    
    
    void QGCHilConfiguration::setVersion(QString version)
    {
    
    Thomas Gubler's avatar
    Thomas Gubler committed
    void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
    
        //clean up
        QLayoutItem *child;
        while ((child = ui->simulatorConfigurationLayout->takeAt(0)) != 0)
        {
    
            delete child->widget();
            delete child;
    
    Thomas Gubler's avatar
    Thomas Gubler committed
        if(1 == index)
    
    Lorenz Meier's avatar
    Lorenz Meier committed
            // Ensure the sim exists and is disabled
    
            _vehicle->uas()->enableHilFlightGear(false, "", true, this);
    
            QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(_vehicle, this);
    
    Thomas Gubler's avatar
    Thomas Gubler committed
            hfgconf->show();
    
            ui->simulatorConfigurationLayout->addWidget(hfgconf);
    
            QGCFlightGearLink* fg = dynamic_cast<QGCFlightGearLink*>(_vehicle->uas()->getHILSimulation());
    
                connect(fg, &QGCFlightGearLink::statusMessage, ui->statusLabel, &QLabel::setText);
    
    Lorenz Meier's avatar
    Lorenz Meier committed
            // Ensure the sim exists and is disabled
    
            _vehicle->uas()->enableHilXPlane(false);
            QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(_vehicle->uas()->getHILSimulation(), this);
    
    Thomas Gubler's avatar
    Thomas Gubler committed
            hxpconf->show();
    
            ui->simulatorConfigurationLayout->addWidget(hxpconf);
    
    Lorenz Meier's avatar
    Lorenz Meier committed
            // Select correct version of XPlane
    
            QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(_vehicle->uas()->getHILSimulation());
    
    Lorenz Meier's avatar
    Lorenz Meier committed
            if (xplane)
            {
                xplane->setVersion((index == 2) ? 10 : 9);
    
                connect(xplane, &QGCXPlaneLink::statusMessage, ui->statusLabel, &QLabel::setText);
    
    Lorenz Meier's avatar
    Lorenz Meier committed
            }
    
    // 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)));
    //        }
    //    }