]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/auto_gui.cxx
working on the termination of the last hardcoded dialogs in Autopilot/auto_gui.cxx:
[flightgear.git] / src / Autopilot / auto_gui.cxx
index a126df2b3e1778b172c142cba7317535a787b1fd..01ebce80e2f4d3595b3789ecf7380532f006e6f7 100644 (file)
@@ -17,7 +17,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
@@ -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,10 +641,9 @@ 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;
   FGFix f;
 
   double alt = 0.0;
@@ -660,15 +660,15 @@ int NewWaypoint( string Tgt_Alt )
   }
 
   FGRouteMgr *rm = (FGRouteMgr *)globals->get_subsystem("route-manager");
-
-  if ( fgFindAirportID( TgtAptId, &a ) ) {
+  const FGAirport *a = fgFindAirportID( TgtAptId);
+  if (a) {
 
       SG_LOG( SG_GENERAL, SG_INFO,
               "Adding waypoint (airport) = " << TgtAptId );
 
       sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
 
-      SGWayPoint wp( a.longitude, a.latitude, alt,
+      SGWayPoint wp( a->getLongitude(), a->getLatitude(), alt,
                      SGWayPoint::WGS84, TgtAptId );
       rm->add_waypoint( wp );
 
@@ -691,7 +691,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;
+         }
   }
 }