1
0
Fork 0

Added some airport search functions that are straight copies of a couple of statics in fg_init, and will probably be removed again at some point, and added a function to convert a runway designator string to a spoken style phrase

This commit is contained in:
daveluff 2003-03-05 21:34:58 +00:00
parent f930c93ddb
commit 8bbaba3193
2 changed files with 87 additions and 0 deletions

View file

@ -21,9 +21,14 @@
#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;
}
}

View 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 );