> hmmm my doxygen didn't find a couple of the calls to findByFreq() that
> do assume radians throughout the code! please don't apply, i'll
> change the comments to say the arguments are in radians then,
> and move the conversion to radians over to the new caller,
> and post a new version soon
>

Here it goes. 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).

Please apply.

Vassilii

Index: src/Autopilot/auto_gui.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Autopilot/auto_gui.cxx,v
retrieving revision 1.12
diff -u -p -r1.12 auto_gui.cxx
--- src/Autopilot/auto_gui.cxx  10 Feb 2005 09:01:51 -0000      1.12
+++ src/Autopilot/auto_gui.cxx  18 Oct 2005 01:29:34 -0000
@@ -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: src/Navaids/navlist.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Navaids/navlist.cxx,v
retrieving revision 1.11
diff -u -p -r1.11 navlist.cxx
--- src/Navaids/navlist.cxx     1 Oct 2005 09:56:53 -0000       1.11
+++ src/Navaids/navlist.cxx     18 Oct 2005 01:29:39 -0000
@@ -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: src/Navaids/navlist.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Navaids/navlist.hxx,v
retrieving revision 1.8
diff -u -p -r1.8 navlist.hxx
--- src/Navaids/navlist.hxx     1 Oct 2005 09:56:53 -0000       1.8
+++ src/Navaids/navlist.hxx     18 Oct 2005 01:29:40 -0000
@@ -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 );



_______________________________________________
Flightgear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to