]> git.mxchange.org Git - flightgear.git/commitdiff
Vassilii Khachaturov:
authorehofman <ehofman>
Sat, 22 Oct 2005 13:37:13 +0000 (13:37 +0000)
committerehofman <ehofman>
Sat, 22 Oct 2005 13:37:13 +0000 (13:37 +0000)
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
src/Navaids/navlist.cxx
src/Navaids/navlist.hxx

index f328d49b8c00305cbce641cfbf70d1a0e02e0cdc..c42fc38126d7ad085b1478aba8e0b9f8ddd58bd3 100644 (file)
@@ -51,6 +51,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"
@@ -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;
+         }
   }
 }
 
index 84c3b430c763b9f9bf7e0fd1d0d571ff4bcd79e9..c5234dea48eee130e94082ff1a2ab429edaaa258 100644 (file)
@@ -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)];
index aa9970026d3d6ffdade1c87071b872e51c8f1dd3..be18ad291d29d30cd84a2989c15dae07262c0e63 100644 (file)
@@ -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 );