]> git.mxchange.org Git - flightgear.git/commitdiff
Added some airport search functions that are straight copies of a couple of statics...
authordaveluff <daveluff>
Wed, 5 Mar 2003 21:34:58 +0000 (21:34 +0000)
committerdaveluff <daveluff>
Wed, 5 Mar 2003 21:34:58 +0000 (21:34 +0000)
src/ATC/ATCutils.cxx
src/ATC/ATCutils.hxx

index 0c98fa73b00e81f981cab3bee7805035e7452e99..eb89d579a4fbb92375e03a15c691ff656ea76f90 100644 (file)
 #include <math.h>
 #include <simgear/math/point3d.hxx>
 #include <simgear/constants.h>
+#include <simgear/misc/sg_path.hxx>
+#include <simgear/debug/logstream.hxx>
 #include <plib/sg.h>
 //#include <iomanip.h>
 
+#include <Airports/runways.hxx>
+#include <Main/globals.hxx>
+
 #include "ATCutils.hxx"
 
 // Convert any number to spoken digits
@@ -74,6 +79,19 @@ string ConvertRwyNumToSpokenString(int n) {
        return(str);
 }
 
+// Assumes we get a two-digit string optionally appended with R or L
+// eg 01 07L 29R 36
+// Anything else is not guaranteed to be handled correctly!
+string ConvertRwyNumToSpokenString(string s) {
+       if(s.size() < 3) {
+               return(ConvertRwyNumToSpokenString(atoi(s.c_str())));
+       } else {
+               string r = ConvertRwyNumToSpokenString(atoi(s.substr(0,2).c_str()));
+               return(r += (s.substr(2,1) == "L" ? " left" : " right"));       // Warning - not much error checking there!
+       }
+}
+       
+
 // Return the phonetic letter of a letter represented as an integer 1->26
 string GetPhoneticIdent(int i) {
        // TODO - Check i is between 1 and 26 and wrap if necessary
@@ -218,3 +236,47 @@ void dclBoundHeading(double &hdg) {
                hdg -= 360.0;
        }
 }
+
+// Airport stuff.  The next two functions are straight copies of their fg.... equivalents
+// in fg_init.cxx, and are just here temporarily until some rationalisation occurs.
+// find basic airport location info from airport database
+bool dclFindAirportID( const string& id, FGAirport *a ) {
+    if ( id.length() ) {
+        SGPath path( globals->get_fg_root() );
+        path.append( "Airports" );
+        path.append( "simple.mk4" );
+        FGAirports airports( path.c_str() );
+
+        SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
+
+        if ( ! airports.search( id, a ) ) {
+            SG_LOG( SG_GENERAL, SG_ALERT,
+                    "Failed to find " << id << " in " << path.str() );
+            return false;
+        }
+    } else {
+        return false;
+    }
+
+    SG_LOG( SG_GENERAL, SG_INFO,
+            "Position for " << id << " is ("
+            << a->longitude << ", "
+            << a->latitude << ")" );
+
+    return true;
+}
+
+// get airport elevation
+double dclGetAirportElev( const string& id ) {
+    FGAirport a;
+    // double lon, lat;
+
+    SG_LOG( SG_GENERAL, SG_INFO,
+            "Finding elevation for airport: " << id );
+
+    if ( dclFindAirportID( id, &a ) ) {
+        return a.elevation;
+    } else {
+        return -9999.0;
+    }
+}
index 7655ec85c0da8ea5abd67b1f08df479b8a16f384..de50b6e290b7ecd7ebc541fcdc0e62047ffa05c5 100644 (file)
@@ -18,6 +18,8 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+#include <Airports/simple.hxx>
+
 #include <math.h>
 #include <simgear/math/point3d.hxx>
 #include <string>
@@ -40,6 +42,13 @@ string ConvertNumToSpokenDigits(string n);
 // Convert a 2 digit rwy number to a spoken-style string
 string ConvertRwyNumToSpokenString(int n);
 
+// Convert rwy number string to a spoken-style string
+// eg "05L" to "zero five left"
+// Assumes we get a two-digit string optionally appended with R or L
+// eg 01 07L 29R 36
+// Anything else is not guaranteed to be handled correctly!
+string ConvertRwyNumToSpokenString(string s);
+
 // Return the phonetic letter of a letter represented as an integer 1->26
 string GetPhoneticIdent(int i);
 
@@ -66,3 +75,19 @@ double GetHeadingFromTo(Point3D A, Point3D B);
 
 // Given a heading (in degrees), bound it from 0 -> 360
 void dclBoundHeading(double &hdg);
+
+
+/*******************************
+*
+*      Airport-related functions
+*
+********************************/
+
+// The next two functions are straight copies of their fg.... equivalents
+// in fg_init.cxx, and are just here temporarily until some rationalisation occurs.
+
+// find basic airport location info from airport database
+bool dclFindAirportID( const string& id, FGAirport *a );
+
+// get airport elevation
+double dclGetAirportElev( const string& id );