]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/auto_gui.cxx
Changes to keep the various autopilot properties from stepping on each
[flightgear.git] / src / Autopilot / auto_gui.cxx
index 862167b88b1eaa36ed71b9e73ecf9e05ca999b01..43c63b84aa9d4056f6119a0d44cad88d7127bc32 100644 (file)
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
-#include <simgear/misc/fgpath.hxx>
+#include <simgear/misc/sg_path.hxx>
 
 #include <Airports/simple.hxx>
 #include <GUI/gui.h>
-#include <Main/bfi.hxx>
 #include <Main/fg_init.hxx>
-#include <Main/options.hxx>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <Navaids/fixlist.hxx>
 
 #include "auto_gui.hxx"
 #include "newauto.hxx"
@@ -217,9 +218,9 @@ void NewHeadingInit(void)
     char NewHeadingLabel[] = "Enter New Heading";
     char *s;
 
-    float heading = FGBFI::getHeading();
+    float heading = fgGetDouble("/orientation/heading-deg");
     int len = 260/2 -
-       (puGetStringWidth( puGetDefaultLabelFont(), NewHeadingLabel ) /2 );
+       (puGetDefaultLabelFont().getStringWidth( NewHeadingLabel ) / 2 );
 
     ApHeadingDialog = new puDialogBox (150, 50);
     {
@@ -291,12 +292,12 @@ void NewAltitudeInit(void)
 
     float alt = cur_fdm_state->get_Altitude();
 
-    if ( current_options.get_units() == fgOPTIONS::FG_UNITS_METERS) {
-       alt *= FEET_TO_METER;
+    if ( fgGetString("/sim/startup/units") == "meters") {
+       alt *= SG_FEET_TO_METER;
     }
 
     int len = 260/2 -
-       (puGetStringWidth( puGetDefaultLabelFont(), NewAltitudeLabel )/2);
+       (puGetDefaultLabelFont().getStringWidth( NewAltitudeLabel ) / 2);
 
     // ApAltitudeDialog = new puDialogBox (150, 50);
     ApAltitudeDialog = new puDialogBox (150, 200);
@@ -438,7 +439,7 @@ void fgAPAdjustInit( void ) {
     char *s;
 
     int labelX = (DialogWidth / 2) -
-       (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
+       (puGetDefaultLabelFont().getStringWidth( Label ) / 2);
     labelX -= 30;  // KLUDGEY
 
     int nSliders = 4;
@@ -467,8 +468,8 @@ void fgAPAdjustInit( void ) {
 
     puGetDefaultFonts (  &APAdjustLegendFont,  &APAdjustLabelFont );
     APAdjustDialog = new puDialogBox ( DialogX, DialogY ); {
-       int horiz_slider_height = puGetStringHeight (APAdjustLabelFont) +
-           puGetStringDescender (APAdjustLabelFont) +
+       int horiz_slider_height = APAdjustLabelFont.getStringHeight() +
+           APAdjustLabelFont.getStringDescender() +
            PUSTR_TGAP + PUSTR_BGAP + 5;
 
        APAdjustFrame = new puFrame ( 0, 0,
@@ -585,100 +586,99 @@ void TgtAptDialog_OK (puObject *)
     
     char *s;
     TgtAptDialogInput->getValue(&s);
-    TgtAptId = s;
-    
+
+    string tmp = s;
+    double alt = 0.0;
+    unsigned int pos = tmp.find( "@" );
+    if ( pos != string::npos ) {
+       TgtAptId = tmp.substr( 0, pos );
+       string alt_str = tmp.substr( pos + 1 );
+       alt = atof( alt_str.c_str() );
+       if ( fgGetString("/sim/startup/units") == "feet" ) {
+           alt *= SG_FEET_TO_METER;
+       }
+    } else {
+       TgtAptId = tmp;
+    }
+
     TgtAptDialog_Cancel( NULL );
     
-    if ( TgtAptId.length() ) {
-        // set initial position from TgtAirport id
-        
-       FGPath path( current_options.get_fg_root() );
-       path.append( "Airports" );
-       path.append( "simple.mk4" );
-        FGAirports airports( path.c_str() );
-        FGAirport a;
+    FGAirport a;
+    FGFix f;
+    double t1, t2;
+    if ( fgFindAirportID( TgtAptId, &a ) ) {
+
+        SG_LOG( SG_GENERAL, SG_INFO,
+                "Adding waypoint (airport) = " << TgtAptId );
         
-        FG_LOG( FG_GENERAL, FG_INFO,
-                "Attempting to set starting position from airport code "
-                << s );
+        sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+        SGWayPoint wp( a.longitude, a.latitude, alt,
+                       SGWayPoint::WGS84, TgtAptId );
+        globals->get_route()->add_waypoint( wp );
+    } else if ( current_fixlist->query( TgtAptId, 0.0, 0.0, 0.0,
+                                       &f, &t1, &t2 ) )
+    {
+        SG_LOG( SG_GENERAL, SG_INFO,
+                "Adding waypoint (fix) = " << TgtAptId );
         
-        if ( airports.search( TgtAptId, &a ) )
-           {
-               double course, reverse, distance;
-               //            fgAPset_tgt_airport_id( TgtAptId.c_str() );
-               current_options.set_airport_id( TgtAptId.c_str() );
-               sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
-                       
-               current_autopilot->set_WayPoint( a.longitude, a.latitude,
-                                                TgtAptId );
-               // current_autopilot->set_TargetLatitude( a.latitude );
-               // current_autopilot->set_TargetLongitude( a.longitude );
-               current_autopilot->MakeTargetLatLonStr(
-                                    current_autopilot->get_TargetLatitude(),
-                                    current_autopilot->get_TargetLongitude() );
-                       
-               current_autopilot->set_old_lat( FGBFI::getLatitude() );
-               current_autopilot->set_old_lon( FGBFI::getLongitude() );
-                       
-               // need to test for iter
-               if( ! geo_inverse_wgs_84( FGBFI::getAltitude() * FEET_TO_METER,
-                                         FGBFI::getLatitude(),
-                                         FGBFI::getLongitude(),
-                                         current_autopilot->get_TargetLatitude(),
-                                         current_autopilot->get_TargetLongitude(),
-                                         &course,
-                                         &reverse,
-                                         &distance ) ) {
-                   current_autopilot->set_TargetHeading( course );
-                   current_autopilot->MakeTargetHeadingStr(
-                                     current_autopilot->get_TargetHeading() );
-                   current_autopilot->set_TargetDistance( distance );
-                   current_autopilot->MakeTargetDistanceStr( distance );
-                   // This changes the AutoPilot Heading
-                   // following cast needed
-                   ApHeadingDialogInput->
-                       setValue((float)current_autopilot->get_TargetHeading() );
-                   // Force this !
-                   current_autopilot->set_HeadingEnabled( true );
-                   current_autopilot->set_HeadingMode(
-                                             FGAutopilot::FG_HEADING_WAYPOINT );
-               }
-           } else {
-               TgtAptId  += " not in database.";
-               mkDialog(TgtAptId.c_str());
-           }
+        sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+        SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
+                       SGWayPoint::WGS84, TgtAptId );
+        globals->get_route()->add_waypoint( wp );
+    } else {
+       TgtAptId  += " not in database.";
+       mkDialog(TgtAptId.c_str());
     }
-    // get_control_values();
-    //    if( PauseMode != t->getPause() )
-    //        t->togglePauseMode();
 }
 
 void TgtAptDialog_Reset(puObject *)
 {
-    //  strncpy( NewAirportId, current_options.get_airport_id().c_str(), 16 );
-    sprintf( NewTgtAirportId, "%s", current_options.get_airport_id().c_str() );
+    sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
     TgtAptDialogInput->setValue ( NewTgtAirportId );
     TgtAptDialogInput->setCursor( 0 ) ;
 }
 
-void NewTgtAirport(puObject *cb)
+void AddWayPoint(puObject *cb)
 {
-    //  strncpy( NewAirportId, current_options.get_airport_id().c_str(), 16 );
-    sprintf( NewTgtAirportId, "%s", current_options.get_airport_id().c_str() );
+    sprintf( NewTgtAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
     TgtAptDialogInput->setValue( NewTgtAirportId );
     
     FG_PUSH_PUI_DIALOG( TgtAptDialog );
 }
 
+void PopWayPoint(puObject *cb)
+{
+    globals->get_route()->delete_first();
+
+    // see if there are more waypoints on the list
+    if ( globals->get_route()->size() ) {
+       // more waypoints
+       current_autopilot->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
+    } else {
+       // end of the line
+       current_autopilot->set_HeadingMode( FGAutopilot::FG_TC_HEADING_LOCK );
+
+       // use current heading
+       current_autopilot
+            ->set_TargetHeading(fgGetDouble("/orientation/heading-deg"));
+    }
+}
+
+void ClearRoute(puObject *cb)
+{
+    globals->get_route()->clear();
+}
+
 void NewTgtAirportInit(void)
 {
-    FG_LOG( FG_AUTOPILOT, FG_INFO, " enter NewTgtAirportInit()" );
-    // fgAPset_tgt_airport_id( current_options.get_airport_id() );     
-    sprintf( NewTgtAirportId, "%s", current_options.get_airport_id().c_str() );
-    FG_LOG( FG_AUTOPILOT, FG_INFO, " NewTgtAirportId " << NewTgtAirportId );
-    // printf(" NewTgtAirportId %s\n", NewTgtAirportId);
-    int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
-                                      NewTgtAirportLabel ) / 2;
+    SG_LOG( SG_AUTOPILOT, SG_INFO, " enter NewTgtAirportInit()" );
+    sprintf( NewTgtAirportId, "%s",
+             fgGetString("/sim/startup/airport-id").c_str() );
+    SG_LOG( SG_AUTOPILOT, SG_INFO, " NewTgtAirportId " << NewTgtAirportId );
+    int len = 150
+        - puGetDefaultLabelFont().getStringWidth( NewTgtAirportLabel ) / 2;
     
     TgtAptDialog = new puDialogBox (150, 50);
     {