]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/auto_gui.cxx
replace depreciated plib symbols with their new forms
[flightgear.git] / src / Autopilot / auto_gui.cxx
index f328d49b8c00305cbce641cfbf70d1a0e02e0cdc..21a435513b51080c371e2cf58d211cf904f0f208 100644 (file)
@@ -36,7 +36,6 @@
 
 #include <Aircraft/aircraft.hxx>
 #include <FDM/flight.hxx>
-#include <Controls/controls.hxx>
 #include <Scenery/scenery.hxx>
 
 #include <simgear/constants.h>
@@ -51,6 +50,8 @@
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Navaids/fixlist.hxx>
+#include <Navaids/navlist.hxx>
+#include <Navaids/navrecord.hxx>
 
 #include "auto_gui.hxx"
 #include "route_mgr.hxx"
@@ -640,7 +641,7 @@ void TgtAptDialog_OK (puObject *)
 
 /* add new waypoint (either from above popup window 'ok button or telnet session) */
 
-int NewWaypoint( string Tgt_Alt )
+int NewWaypoint( const string& Tgt_Alt )
 {
   string TgtAptId;
   FGAirport a;
@@ -691,7 +692,45 @@ int NewWaypoint( string Tgt_Alt )
       fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
       return 2;
   } else {
-      return 0;
+         // Try finding a nav matching the ID
+         double lat, lon;
+         // The base lon/lat are determined by the last WP,
+         // or the current pos if the WP list is empty.
+         const int wps = rm->size();
+         if (wps > 0) {
+                 SGWayPoint wp = rm->get_waypoint(wps-1);
+                 lat = wp.get_target_lat();
+                 lon = wp.get_target_lon();
+         }
+         else {
+                 lat = fgGetNode("/position/latitude-deg")->getDoubleValue();
+                 lon = fgGetNode("/position/longitude-deg")->getDoubleValue();
+         }
+
+         lat *= SGD_DEGREES_TO_RADIANS;
+         lon *= SGD_DEGREES_TO_RADIANS;
+
+         SG_LOG( SG_GENERAL, SG_INFO,
+                         "Looking for nav " << TgtAptId << " at " << lon << " " << lat);
+         if (FGNavRecord* nav =
+                         globals->get_navlist()->findByIdent(TgtAptId.c_str(), lon, lat))
+         {
+                 SG_LOG( SG_GENERAL, SG_INFO,
+                                 "Adding waypoint (nav) = " << TgtAptId );
+
+                 sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+                 SGWayPoint wp( nav->get_lon(), nav->get_lat(), alt,
+                                                SGWayPoint::WGS84, TgtAptId );
+                 rm->add_waypoint( wp );
+
+                 /* and turn on the autopilot */
+                 fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
+                 return 3;
+         }
+         else {
+                 return 0;
+         }
   }
 }
 
@@ -813,7 +852,7 @@ void NewTgtAirportInit()
         
         TgtAptDialogWPList = new puListBox ( 50, 130, 300, 320 ) ;
         TgtAptDialogWPList -> setLabel ( "Flight Plan" );
-        TgtAptDialogWPList -> setLabelPlace ( PUPLACE_ABOVE ) ;
+        TgtAptDialogWPList -> setLabelPlace ( PUPLACE_TOP_LEFT ) ;
         TgtAptDialogWPList -> setStyle ( -PUSTYLE_SMALL_SHADED ) ;
         TgtAptDialogWPList -> setValue ( 0 ) ;
 
@@ -833,7 +872,7 @@ void NewTgtAirportInit()
 
         TgtAptDialogInput   = new puInput           (50, 70, 300, 100);
         TgtAptDialogInput -> setLabel ( NewTgtAirportLabel );
-        TgtAptDialogInput -> setLabelPlace ( PUPLACE_ABOVE ) ;
+        TgtAptDialogInput -> setLabelPlace ( PUPLACE_TOP_LEFT ) ;
         TgtAptDialogInput   ->    setValue          (NewTgtAirportId);
         TgtAptDialogInput   ->    acceptInput();