Merge pull request #7 from parched/OP-1879_remove_openpilot_hardcoding
[librepilot.git] / ground / openpilotgcs / src / plugins / hitl / hitloptionspage.cpp
blob6cb69ddc7af9c5a7ec9d2ece2c2cd8f4f6dc48a3
1 /**
2 ******************************************************************************
4 * @file hitloptionspage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup HITLPlugin HITL Plugin
9 * @{
10 * @brief The Hardware In The Loop plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "hitloptionspage.h"
29 #include "hitlconfiguration.h"
30 #include "ui_hitloptionspage.h"
31 #include <hitlplugin.h>
33 #include <QFileDialog>
34 #include <QtAlgorithms>
35 #include <QStringList>
36 #include <simulator.h>
39 HITLOptionsPage::HITLOptionsPage(HITLConfiguration *conf, QObject *parent) :
40 IOptionsPage(parent),
41 config(conf)
44 QWidget *HITLOptionsPage::createPage(QWidget *parent)
46 Q_UNUSED(parent);
48 // Create page
49 m_optionsPage = new Ui::HITLOptionsPage();
50 QWidget *optionsPageWidget = new QWidget;
51 m_optionsPage->setupUi(optionsPageWidget);
52 int index = 0;
53 foreach(SimulatorCreator * creator, HITLPlugin::typeSimulators) {
54 m_optionsPage->chooseFlightSimulator->insertItem(index++, creator->Description(), creator->ClassId());
57 // QString classId = widget->listSimulators->itemData(0).toString();
58 // SimulatorCreator* creator = HITLPlugin::getSimulatorCreator(classId);
60 // QWidget* embedPage = creator->createOptionsPage();
61 // m_optionsPage->verticalLayout->addWidget(embedPage);
63 m_optionsPage->executablePath->setExpectedKind(Utils::PathChooser::File);
64 m_optionsPage->executablePath->setPromptDialogTitle(tr("Choose flight simulator executable"));
65 m_optionsPage->dataPath->setExpectedKind(Utils::PathChooser::Directory);
66 m_optionsPage->dataPath->setPromptDialogTitle(tr("Choose flight simulator data directory"));
68 // Restore the contents from the settings:
69 foreach(SimulatorCreator * creator, HITLPlugin::typeSimulators) {
70 QString id = config->Settings().simulatorId;
72 if (creator->ClassId() == id) {
73 m_optionsPage->chooseFlightSimulator->setCurrentIndex(HITLPlugin::typeSimulators.indexOf(creator));
77 m_optionsPage->executablePath->setPath(config->Settings().binPath);
78 m_optionsPage->dataPath->setPath(config->Settings().dataPath);
80 m_optionsPage->manualControlRadioButton->setChecked(config->Settings().manualControlEnabled);
81 m_optionsPage->gcsReceiverRadioButton->setChecked(config->Settings().gcsReceiverEnabled);
83 m_optionsPage->startSim->setChecked(config->Settings().startSim);
84 m_optionsPage->noiseCheckBox->setChecked(config->Settings().addNoise);
86 m_optionsPage->hostAddress->setText(config->Settings().hostAddress);
87 m_optionsPage->remoteAddress->setText(config->Settings().remoteAddress);
88 m_optionsPage->outputPort->setText(QString::number(config->Settings().outPort));
89 m_optionsPage->inputPort->setText(QString::number(config->Settings().inPort));
90 m_optionsPage->latitude->setText(config->Settings().latitude);
91 m_optionsPage->longitude->setText(config->Settings().longitude);
93 m_optionsPage->groundTruthCheckbox->setChecked(config->Settings().groundTruthEnabled);
94 m_optionsPage->gpsPositionCheckbox->setChecked(config->Settings().gpsPositionEnabled);
95 m_optionsPage->attStateCheckbox->setChecked(config->Settings().attStateEnabled);
96 m_optionsPage->attRawCheckbox->setChecked(config->Settings().attRawEnabled);
99 m_optionsPage->attRawRateSpinbox->setValue(config->Settings().attRawRate);
100 m_optionsPage->gpsPosRateSpinbox->setValue(config->Settings().gpsPosRate);
101 m_optionsPage->groundTruthRateSpinbox->setValue(config->Settings().groundTruthRate);
102 // m_optionsPage->attStateRate->setValue(config->Settings().attStateRate);
104 m_optionsPage->baroAltitudeCheckbox->setChecked(config->Settings().baroSensorEnabled);
105 m_optionsPage->baroAltRateSpinbox->setValue(config->Settings().baroAltRate);
107 m_optionsPage->minOutputPeriodSpinbox->setValue(config->Settings().minOutputPeriod);
109 m_optionsPage->attActHW->setChecked(config->Settings().attActHW);
110 m_optionsPage->attActCalc->setChecked(config->Settings().attActCalc);
111 m_optionsPage->attActSim->setChecked(config->Settings().attActSim);
113 m_optionsPage->airspeedStateCheckbox->setChecked(config->Settings().airspeedStateEnabled);
114 m_optionsPage->airspeedRateSpinbox->setValue(config->Settings().airspeedStateRate);
116 return optionsPageWidget;
119 void HITLOptionsPage::apply()
121 SimulatorSettings settings;
122 int i = m_optionsPage->chooseFlightSimulator->currentIndex();
124 settings.simulatorId = m_optionsPage->chooseFlightSimulator->itemData(i).toString();
125 settings.binPath = m_optionsPage->executablePath->path();
126 settings.dataPath = m_optionsPage->dataPath->path();
127 settings.startSim = m_optionsPage->startSim->isChecked();
128 settings.addNoise = m_optionsPage->noiseCheckBox->isChecked();
129 settings.hostAddress = m_optionsPage->hostAddress->text();
130 settings.remoteAddress = m_optionsPage->remoteAddress->text();
132 settings.inPort = m_optionsPage->inputPort->text().toInt();
133 settings.outPort = m_optionsPage->outputPort->text().toInt();
134 settings.longitude = m_optionsPage->longitude->text();
135 settings.latitude = m_optionsPage->latitude->text();
137 settings.addNoise = m_optionsPage->noiseCheckBox->isChecked();
139 settings.attRawEnabled = m_optionsPage->attRawCheckbox->isChecked();
140 settings.attRawRate = m_optionsPage->attRawRateSpinbox->value();
142 settings.attStateEnabled = m_optionsPage->attStateCheckbox->isChecked();
144 settings.gpsPositionEnabled = m_optionsPage->gpsPositionCheckbox->isChecked();
145 settings.gpsPosRate = m_optionsPage->gpsPosRateSpinbox->value();
147 settings.groundTruthEnabled = m_optionsPage->groundTruthCheckbox->isChecked();
148 settings.groundTruthRate = m_optionsPage->groundTruthRateSpinbox->value();
150 settings.baroSensorEnabled = m_optionsPage->baroAltitudeCheckbox->isChecked();
151 settings.baroAltRate = m_optionsPage->baroAltRateSpinbox->value();
153 settings.minOutputPeriod = m_optionsPage->minOutputPeriodSpinbox->value();
155 settings.manualControlEnabled = m_optionsPage->manualControlRadioButton->isChecked();
156 settings.gcsReceiverEnabled = m_optionsPage->gcsReceiverRadioButton->isChecked();
158 settings.attActHW = m_optionsPage->attActHW->isChecked();
159 settings.attActSim = m_optionsPage->attActSim->isChecked();
160 settings.attActCalc = m_optionsPage->attActCalc->isChecked();
162 settings.airspeedStateEnabled = m_optionsPage->airspeedStateCheckbox->isChecked();
163 settings.airspeedStateRate = m_optionsPage->airspeedRateSpinbox->value();
165 // Write settings to file
166 config->setSimulatorSettings(settings);
169 void HITLOptionsPage::finish()
171 delete m_optionsPage;