From 3188b395c8cd7011b21c11d2ab054cb045a45671 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 22 Oct 2005 13:37:13 +0000 Subject: [PATCH] Vassilii Khachaturov: I found that all the current users of the companion function, findByFreq() actually did assume radians despite the misleading comment in the .hxx and .cxx saying it's degrees. I've fixed the comment now, and no longer change the Navaids code. The new Navaids user in NewWaypoint() is now passing radians to the findByIdent(). Note that along with fixing the comments in the navlist.hxx, I removed an obsolete method findByLoc() declaration (there is no definition anywhere). --- src/Autopilot/auto_gui.cxx | 42 +++++++++++++++++++++++++++++++++++++- src/Navaids/navlist.cxx | 4 ---- src/Navaids/navlist.hxx | 15 +++++--------- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/Autopilot/auto_gui.cxx b/src/Autopilot/auto_gui.cxx index f328d49b8..c42fc3812 100644 --- a/src/Autopilot/auto_gui.cxx +++ b/src/Autopilot/auto_gui.cxx @@ -51,6 +51,8 @@ #include
#include
#include +#include +#include #include "auto_gui.hxx" #include "route_mgr.hxx" @@ -691,7 +693,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; + } } } diff --git a/src/Navaids/navlist.cxx b/src/Navaids/navlist.cxx index 84c3b430c..c5234dea4 100644 --- a/src/Navaids/navlist.cxx +++ b/src/Navaids/navlist.cxx @@ -143,10 +143,6 @@ bool FGTACANList::add( FGTACANRecord *c ) { return true; } -// Query the database for the specified frequency. It is assumed that -// there will be multiple stations with matching frequencies so a -// position must be specified. Lon and lat are in degrees, elev is in -// meters. FGNavRecord *FGNavList::findByFreq( double freq, double lon, double lat, double elev ) { nav_list_type stations = navaids[(int)(freq*100.0 + 0.5)]; diff --git a/src/Navaids/navlist.hxx b/src/Navaids/navlist.hxx index aa9970026..be18ad291 100644 --- a/src/Navaids/navlist.hxx +++ b/src/Navaids/navlist.hxx @@ -78,18 +78,13 @@ public: bool add( FGNavRecord *n ); //bool add( FGTACANRecord *r ); - // Query the database for the specified frequency. It is assumed - // that there will be multiple stations with matching frequencies - // so a position must be specified. Lon and lat are in degrees, - // elev is in meters. + /** Query the database for the specified station. It is assumed + * that there will be multiple stations with matching frequencies + * so a position must be specified. Lon and lat are in radians, + * elev is in meters. + */ FGNavRecord *findByFreq( double freq, double lon, double lat, double elev ); - // Query the database for the specified frequency. It is assumed - // that there will be multiple stations with matching frequencies - // so a position must be specified. Lon and lat are in degrees, - // elev is in meters. - FGNavRecord *findByLoc( double lon, double lat, double elev ); - // locate closest item in the DB matching the requested ident FGNavRecord *findByIdent( const char* ident, const double lon, const double lat );