QGCHilXPlaneConfiguration.cc 2.98 KB
Newer Older
1 2 3
#include "QGCHilXPlaneConfiguration.h"
#include "ui_QGCHilXPlaneConfiguration.h"
#include "QGCXPlaneLink.h"
4
#include "QGCHilConfiguration.h"
5

Bart Slinger's avatar
Bart Slinger committed
6
QGCHilXPlaneConfiguration::QGCHilXPlaneConfiguration(QGCHilLink* link, QGCHilConfiguration *parent) :
7 8 9 10
    QWidget(parent),
    ui(new Ui::QGCHilXPlaneConfiguration)
{
    ui->setupUi(this);
Lorenz Meier's avatar
Lorenz Meier committed
11
    this->link = link;
12

13 14
    connect(ui->startButton, &QPushButton::clicked, this, &QGCHilXPlaneConfiguration::toggleSimulation);

Bart Slinger's avatar
Bart Slinger committed
15
    connect(ui->hostComboBox, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated),
16 17 18 19
            link, &QGCHilLink::setRemoteHost);

    connect(link, &QGCHilLink::remoteChanged, ui->hostComboBox, &QComboBox::setEditText);
    connect(link, &QGCHilLink::statusMessage, parent, &QGCHilConfiguration::receiveStatusMessage);
Lorenz Meier's avatar
Lorenz Meier committed
20 21 22

//    connect(mav->getHILSimulation(), SIGNAL(statusMessage(QString)), this, SLOT(receiveStatusMessage(QString)));
//    connect(ui->simComboBox, SIGNAL(activated(QString)), mav->getHILSimulation(), SLOT(setVersion(QString)));
23 24 25

    ui->startButton->setText(tr("Connect"));

Bart Slinger's avatar
Bart Slinger committed
26
    QGCXPlaneLink* xplane = dynamic_cast<QGCXPlaneLink*>(link);
27 28 29

    if (xplane)
    {
30 31
//        connect(ui->randomAttitudeButton, SIGNAL(clicked()), link, SLOT(setRandomAttitude()));
//        connect(ui->randomPositionButton, SIGNAL(clicked()), link, SLOT(setRandomPosition()));
32

33 34
        //ui->airframeComboBox->setCurrentIndex(link->getAirFrameIndex());
        //connect(ui->airframeComboBox, SIGNAL(activated(QString)), link, SLOT(selectAirframe(QString)));
35
        // XXX not implemented yet
36
        //ui->airframeComboBox->hide();
37
        ui->sensorHilCheckBox->setChecked(xplane->sensorHilEnabled());
38
        ui->useHilActuatorControlsCheckBox->setChecked(true);
39 40
        connect(xplane, &QGCXPlaneLink::sensorHilChanged, ui->sensorHilCheckBox, &QCheckBox::setChecked);
        connect(ui->sensorHilCheckBox, &QCheckBox::clicked, xplane, &QGCXPlaneLink::enableSensorHIL);
41 42
        connect(xplane, &QGCXPlaneLink::useHilActuatorControlsChanged, ui->useHilActuatorControlsCheckBox, &QCheckBox::setChecked);
        connect(ui->useHilActuatorControlsCheckBox, &QCheckBox::clicked, xplane, &QGCXPlaneLink::enableHilActuatorControls);
43

44 45
        connect(link, static_cast<void (QGCHilLink::*)(int)>(&QGCHilLink::versionChanged),
                this, &QGCHilXPlaneConfiguration::setVersion);
46 47 48 49 50 51
    }

    ui->hostComboBox->clear();
    ui->hostComboBox->addItem(link->getRemoteHost());


52 53 54 55
}

void QGCHilXPlaneConfiguration::setVersion(int version)
{
56
    Q_UNUSED(version);
57 58 59 60
}

void QGCHilXPlaneConfiguration::toggleSimulation(bool connect)
{
Bart Slinger's avatar
Bart Slinger committed
61
    if (!link) {
62 63 64
        return;
    }

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    Q_UNUSED(connect);
    if (!link->isConnected())
    {
        link->setRemoteHost(ui->hostComboBox->currentText());
        link->connectSimulation();
        ui->startButton->setText(tr("Disconnect"));
    }
    else
    {
        link->disconnectSimulation();
        ui->startButton->setText(tr("Connect"));
    }
}

QGCHilXPlaneConfiguration::~QGCHilXPlaneConfiguration()
{
    delete ui;
}