]> git.mxchange.org Git - flightgear.git/commitdiff
Launcher sets location via properties.
authorJames Turner <zakalawe@mac.com>
Fri, 19 Aug 2016 15:09:52 +0000 (16:09 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:49 +0000 (23:27 +0200)
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
src/GUI/LocationWidget.hxx
src/GUI/QtLauncher.cxx

index 97d149104682171f81815bc6eac581f96d340e13..4c3048cd4d8cba9057d84ec59e03373dc1e9e025 100644 (file)
@@ -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<FGAirport*>(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<int>(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();
index 0aed3e59e465241e4e651cb820bfdeae99e2d331..5e9aaf350062869618d1edfa500637498ac28db4 100644 (file)
@@ -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;
index 65e6ca0fb3994f4544e406cefc3153e33065f769..e56db78c7ad7372867756ca4c039337f1e717edf 100644 (file)
@@ -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();
 }