From 0aded912c3ea8dd78112b2d62a83b8984c175f7f Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 19 Aug 2016 16:09:52 +0100 Subject: [PATCH] Launcher sets location via properties. Bypass the options system to set location from the launcher; this allows the same code to be used in-sim for repositioning, while keeping compatibility with other repositions approaches. --- src/GUI/LocationWidget.cxx | 132 +++++++++++++++++++++---------------- src/GUI/LocationWidget.hxx | 4 +- src/GUI/QtLauncher.cxx | 8 ++- 3 files changed, 84 insertions(+), 60 deletions(-) diff --git a/src/GUI/LocationWidget.cxx b/src/GUI/LocationWidget.cxx index 97d149104..4c3048cd4 100644 --- a/src/GUI/LocationWidget.cxx +++ b/src/GUI/LocationWidget.cxx @@ -532,47 +532,49 @@ void LocationWidget::saveSettings() // recent locations is saved on modification } -void LocationWidget::setLocationOptions() +void LocationWidget::setLocationProperties() { - flightgear::Options* opt = flightgear::Options::sharedInstance(); - std::string altStr = QString::number(m_ui->altitudeSpinbox->value()).toStdString(); - std::string vcStr = QString::number(m_ui->airspeedSpinbox->value()).toStdString(); - std::string headingStr = QString::number(m_ui->headingSpinbox->value()).toStdString(); + SGPropertyNode_ptr presets = fgGetNode("/sim/presets", true); + + QStringList props = QStringList() << "vor-id" << "fix" << "ndb-id" << + "runway-requested" << "navaid-id" << "offset-azimuth-deg" << + "offset-distance-nm" << "glideslope-deg" << + "speed-set" << "on-ground" << "airspeed-kt" << "heading-deg" << + "airport-id" << "runway" << "parkpos"; + + Q_FOREACH(QString s, props) { + SGPropertyNode* c = presets->getChild(s.toStdString()); + if (c) { + c->clearValue(); + } + } + - // flip direction of azimuth to balance the flip done in fgApplyStartOffset - // I don't know why that flip exists but changing it there will break - // command-line compatability so compensating here instead - int offsetAzimuth = m_ui->offsetBearingSpinbox->value() - 180; - std::string azimuthStr = QString::number(offsetAzimuth).toStdString(); - std::string distanceStr = QString::number(m_ui->offsetNmSpinbox->value()).toStdString(); if (m_locationIsLatLon) { - // bypass the options mechanism because converting to deg:min:sec notation - // just to parse back again is nasty. fgSetDouble("/sim/presets/latitude-deg", m_geodLocation.getLatitudeDeg()); fgSetDouble("/position/latitude-deg", m_geodLocation.getLatitudeDeg()); fgSetDouble("/sim/presets/longitude-deg", m_geodLocation.getLongitudeDeg()); fgSetDouble("/position/longitude-deg", m_geodLocation.getLongitudeDeg()); - opt->addOption("altitude", altStr); - opt->addOption("vc", vcStr); - opt->addOption("heading", headingStr); - - if (m_ui->offsetGroup->isChecked()) { - opt->addOption("offset-azimuth", azimuthStr); - opt->addOption("offset-distance", distanceStr); - } + applyPositionOffset(); return; } + fgSetDouble("/sim/presets/latitude-deg", -9999.0); + fgSetDouble("/sim/presets/longitude-deg", -9999.0); + fgSetDouble("/sim/presets/altitude-ft", -9999.0); + + if (!m_location) { return; } if (FGAirport::isAirportType(m_location.ptr())) { FGAirport* apt = static_cast(m_location.ptr()); - opt->addOption("airport", apt->ident()); + fgSetString("/sim/presets/airport-id", apt->ident()); + fgSetBool("/sim/presets/on-ground", true); if (m_ui->runwayRadio->isChecked()) { if (apt->type() == FGPositioned::AIRPORT) { @@ -580,27 +582,29 @@ void LocationWidget::setLocationOptions() if (index >= 0) { // explicit runway choice FGRunwayRef runway = apt->getRunwayByIndex(index); - opt->addOption("runway", runway->ident()); + fgSetString("/sim/presets/runway", runway->ident() ); + fgSetBool("/sim/presets/runway-requested", true ); // set nav-radio 1 based on selected runway if (runway->ILS()) { double mhz = runway->ILS()->get_freq() / 100.0; - QString navOpt = QString("%1:%2").arg(runway->headingDeg()).arg(mhz); - opt->addOption("nav1", navOpt.toStdString()); + fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", runway->headingDeg()); + fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", mhz); } } if (m_ui->onFinalCheckbox->isChecked()) { - opt->addOption("glideslope", "3.0"); - double offsetNm = m_ui->approachDistanceSpin->value(); - opt->addOption("offset-distance", QString::number(offsetNm).toStdString()); + fgSetDouble("/sim/presets/glideslope-deg", 3.0); + fgSetDouble("/sim/presets/offset-distance-nm", m_ui->approachDistanceSpin->value()); + fgSetBool("/sim/presets/on-ground", false); } } else if (apt->type() == FGPositioned::HELIPORT) { int index = m_ui->runwayCombo->itemData(m_ui->runwayCombo->currentIndex()).toInt(); if (index >= 0) { // explicit pad choice FGHelipadRef pad = apt->getHelipadByIndex(index); - opt->addOption("runway", pad->ident()); + fgSetString("/sim/presets/runway", pad->ident() ); + fgSetBool("/sim/presets/runway-requested", true ); } } else { qWarning() << Q_FUNC_INFO << "implement me"; @@ -608,48 +612,64 @@ void LocationWidget::setLocationOptions() } else if (m_ui->parkingRadio->isChecked()) { // parking selection - opt->addOption("parkpos", m_ui->parkingCombo->currentText().toStdString()); + fgSetString("/sim/presets/parkpos", m_ui->parkingCombo->currentText().toStdString()); } // of location is an airport } else { + fgSetString("/sim/presets/airport-id", ""); + // location is a navaid // note setting the ident here is ambigious, we really only need and // want the 'navaid-id' property. However setting the 'real' option // gives a better UI experience (eg existing Position in Air dialog) FGPositioned::Type ty = m_location->type(); switch (ty) { - case FGPositioned::VOR: - opt->addOption("vor", m_location->ident()); - setNavRadioOption(); - break; - - case FGPositioned::NDB: - opt->addOption("ndb", m_location->ident()); - setNavRadioOption(); - break; - - case FGPositioned::FIX: - opt->addOption("fix", m_location->ident()); - break; - default: - break; - } - - opt->addOption("altitude", altStr); - opt->addOption("vc", vcStr); - opt->addOption("heading", headingStr); - + case FGPositioned::VOR: + fgSetString("/sim/presets/vor-id", m_location->ident()); + setNavRadioOption(); + break; + + case FGPositioned::NDB: + fgSetString("/sim/presets/ndb-id", m_location->ident()); + setNavRadioOption(); + break; + + case FGPositioned::FIX: + fgSetString("/sim/presets/fix", m_location->ident()); + break; + default: + break; + }; + // set disambiguation property globals->get_props()->setIntValue("/sim/presets/navaid-id", static_cast(m_location->guid())); - - if (m_ui->offsetGroup->isChecked()) { - opt->addOption("offset-azimuth", azimuthStr); - opt->addOption("offset-distance", distanceStr); - } + + applyPositionOffset(); } // of navaid location } +void LocationWidget::applyPositionOffset() +{ + fgSetDouble("/sim/presets/altitude-ft", m_ui->altitudeSpinbox->value()); + fgSetBool("/sim/presets/on-ground", m_ui->altitudeSpinbox->value() > 0); + + fgSetString("/sim/presets/speed-set", "knots"); + fgSetDouble("/sim/presets/airspeed-kt", m_ui->airspeedSpinbox->value()); + + fgSetDouble("/sim/presets/heading-deg", m_ui->headingSpinbox->value()); + + if (m_ui->offsetGroup->isChecked()) { + // flip direction of azimuth to balance the flip done in fgApplyStartOffset + // I don't know why that flip exists but changing it there will break + // command-line compatability so compensating here instead + int offsetAzimuth = m_ui->offsetBearingSpinbox->value() - 180; + + fgSetDouble("/sim/presets/offset-azimuth-deg", offsetAzimuth); + fgSetDouble("/sim/presets/offset-distance-nm", m_ui->offsetNmSpinbox->value()); + } +} + void LocationWidget::setNavRadioOption() { flightgear::Options* opt = flightgear::Options::sharedInstance(); diff --git a/src/GUI/LocationWidget.hxx b/src/GUI/LocationWidget.hxx index 0aed3e59e..5e9aaf350 100644 --- a/src/GUI/LocationWidget.hxx +++ b/src/GUI/LocationWidget.hxx @@ -55,7 +55,7 @@ public: bool shouldStartPaused() const; - void setLocationOptions(); + void setLocationProperties(); Q_SIGNALS: void descriptionChanged(QString t); @@ -82,6 +82,8 @@ private: void setNavRadioOption(); void onShowHistory(); + void applyPositionOffset(); + Ui::LocationWidget *m_ui; NavSearchModel* m_searchModel; diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 65e6ca0fb..e56db78c7 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -708,8 +708,8 @@ void QtLauncher::setSceneryPaths() void QtLauncher::setInAppMode() { m_inAppMode = true; - m_ui->tabWidget->removeTab(2); - m_ui->tabWidget->removeTab(2); + m_ui->tabWidget->removeTab(3); + m_ui->tabWidget->removeTab(3); m_ui->runButton->setText(tr("Apply")); m_ui->quitButton->setText(tr("Cancel")); @@ -900,7 +900,7 @@ void QtLauncher::onRun() globals->get_props()->setIntValue("/sim/multiplay/txport", port); } - m_ui->location->setLocationOptions(); + m_ui->location->setLocationProperties(); // time of day if (m_ui->timeOfDayCombo->currentIndex() != 0) { @@ -1001,6 +1001,8 @@ void QtLauncher::onApply() globals->get_props()->setStringValue("/sim/aircraft-dir", aircraftDir); } + // location + m_ui->location->setLocationProperties(); saveSettings(); } -- 2.39.5