1
0
Fork 0

Convert the only remaining user of FGFixList to use an FGPositioned query,

and hence remove the query code from fix-list. The only remaining code deals
with parsing fix.dat.
This commit is contained in:
jmt 2008-12-23 14:41:58 +00:00
parent d6277068f5
commit 059f2e6a8e
5 changed files with 11 additions and 155 deletions

View file

@ -939,11 +939,10 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
// Set current_options lon/lat given an airport id and heading (degrees) // Set current_options lon/lat given an airport id and heading (degrees)
static bool fgSetPosFromFix( const string& id ) static bool fgSetPosFromFix( const string& id )
{ {
FGFix* fix; FGPositioned::TypeFilter fixFilter(FGPositioned::FIX);
FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter);
// set initial position from runway and heading if (!fix) {
if ( !globals->get_fixlist()->query( id.c_str(), fix ) ) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id );
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = " << id );
return false; return false;
} }
@ -951,7 +950,6 @@ static bool fgSetPosFromFix( const string& id )
return true; return true;
} }
/** /**
* Initialize vor/ndb/ils/fix list management and query systems (as * Initialize vor/ndb/ils/fix list management and query systems (as
* well as simple airport db list) * well as simple airport db list)
@ -1000,7 +998,6 @@ fgInitNav ()
p_fix.append( "Navaids/fix.dat" ); p_fix.append( "Navaids/fix.dat" );
FGFixList *fixlist = new FGFixList; FGFixList *fixlist = new FGFixList;
fixlist->init( p_fix ); fixlist->init( p_fix );
globals->set_fixlist( fixlist );
SG_LOG(SG_GENERAL, SG_INFO, " Airways"); SG_LOG(SG_GENERAL, SG_INFO, " Airways");
SGPath p_awy( globals->get_fg_root() ); SGPath p_awy( globals->get_fg_root() );

View file

@ -108,7 +108,6 @@ FGGlobals::FGGlobals() :
tacanlist( NULL ), tacanlist( NULL ),
carrierlist( NULL ), carrierlist( NULL ),
channellist( NULL ), channellist( NULL ),
fixlist( NULL ),
airwaynet( NULL ), airwaynet( NULL ),
multiplayer_mgr( NULL ) multiplayer_mgr( NULL )
{ {
@ -160,7 +159,6 @@ FGGlobals::~FGGlobals()
delete tacanlist; delete tacanlist;
delete carrierlist; delete carrierlist;
delete channellist; delete channellist;
delete fixlist;
delete airwaynet; delete airwaynet;
delete multiplayer_mgr; delete multiplayer_mgr;
} }

View file

@ -64,7 +64,6 @@ class FGIO;
class FGNavList; class FGNavList;
class FGAirwayNetwork; class FGAirwayNetwork;
class FGTACANList; class FGTACANList;
class FGFixList;
class FGLight; class FGLight;
class FGModelMgr; class FGModelMgr;
class FGRouteMgr; class FGRouteMgr;
@ -188,7 +187,6 @@ private:
FGNavList *tacanlist; FGNavList *tacanlist;
FGNavList *carrierlist; FGNavList *carrierlist;
FGTACANList *channellist; FGTACANList *channellist;
FGFixList *fixlist;
FGAirwayNetwork *airwaynet; FGAirwayNetwork *airwaynet;
//Mulitplayer managers //Mulitplayer managers
@ -335,8 +333,6 @@ public:
inline void set_carrierlist( FGNavList *n ) { carrierlist = n; } inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
inline FGNavList *get_mkrlist() const { return mkrlist; } inline FGNavList *get_mkrlist() const { return mkrlist; }
inline void set_mkrlist( FGNavList *n ) { mkrlist = n; } inline void set_mkrlist( FGNavList *n ) { mkrlist = n; }
inline FGFixList *get_fixlist() const { return fixlist; }
inline void set_fixlist( FGFixList *f ) { fixlist = f; }
inline FGTACANList *get_channellist() const { return channellist; } inline FGTACANList *get_channellist() const { return channellist; }
inline void set_channellist( FGTACANList *c ) { channellist = c; } inline void set_channellist( FGTACANList *c ) { channellist = c; }

View file

@ -29,6 +29,7 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx> #include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>
#include "fixlist.hxx" #include "fixlist.hxx"
@ -51,9 +52,7 @@ FGFixList::~FGFixList( void ) {
// load the navaids and build the map // load the navaids and build the map
bool FGFixList::init( SGPath path ) { bool FGFixList::init(const SGPath& path ) {
fixlist.erase( fixlist.begin(), fixlist.end() );
sg_gzifstream in( path.str() ); sg_gzifstream in( path.str() );
if ( !in.is_open() ) { if ( !in.is_open() ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() ); SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
@ -71,106 +70,10 @@ bool FGFixList::init( SGPath path ) {
in >> lat >> lon >> ident; in >> lat >> lon >> ident;
if (lat > 95) break; if (lat > 95) break;
FGFix* fix = new FGFix(ident, SGGeod::fromDeg(lon, lat)); // fix gets added to the FGPositioned spatial indices, so we don't need
fixlist.insert(std::make_pair(fix->ident(), fix)); // to hold onto it here.
new FGFix(ident, SGGeod::fromDeg(lon, lat));
in >> skipcomment; in >> skipcomment;
} }
return true; return true;
} }
// query the database for the specified fix, lon and lat are in
// degrees, elev is in meters
bool FGFixList::query( const string& ident, FGFix* &fix ) {
fix_map_const_iterator it = fixlist.find(ident);
if ( it != fixlist.end() ) {
fix = it->second;
return true;
} else {
return false;
}
}
// query the database for the specified fix, lon and lat are in
// degrees, elev is in meters
bool FGFixList::query_and_offset( const string& ident, double lon, double lat,
double elev, FGFix* &fix, double *heading,
double *dist )
{
std::pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident);
if (range.first == range.second) {
return false;
}
double min_s = -1.0;
for (fix_map_const_iterator current = range.first; current != range.second; ++current) {
double az1, az2, s;
geo_inverse_wgs_84( elev, lat, lon,
current->second->get_lat(), current->second->get_lon(),
&az1, &az2, &s );
// cout << " dist = " << s << endl;
if (min_s < 0 || s < min_s) {
*heading = az2;
*dist = s;
min_s = s;
fix = current->second;
}
}
return true;
}
const FGFix* FGFixList::search(const string& ident)
{
fix_map_iterator itr = fixlist.find(ident);
if (itr == fixlist.end()) {
return NULL;
}
return itr->second;
}
class orderingFunctor
{
public:
orderingFunctor(FGIdentOrdering* aOrder) :
mOrdering(aOrder)
{ assert(aOrder); }
bool operator()(const fix_map_type::value_type& aA, const std::string& aB) const
{
return mOrdering->compare(aA.first,aB);
}
bool operator()(const std::string& aA, const fix_map_type::value_type& aB) const
{
return mOrdering->compare(aA, aB.first);
}
bool operator()(const fix_map_type::value_type& aA, const fix_map_type::value_type& aB) const
{
return mOrdering->compare(aA.first, aB.first);
}
private:
FGIdentOrdering* mOrdering;
};
const FGFix* FGFixList::findFirstByIdent( const string& ident, FGIdentOrdering* aOrder)
{
fix_map_iterator itr;
if (aOrder) {
orderingFunctor func(aOrder);
itr = std::lower_bound(fixlist.begin(),fixlist.end(), ident, func);
} else {
itr = fixlist.lower_bound(ident);
}
if (itr == fixlist.end()) {
return NULL;
}
return itr->second;
}

View file

@ -26,56 +26,18 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/misc/sg_path.hxx>
#include <map>
#include <vector>
#include <string>
class FGFix; class FGFix;
class SGPath;
using std::multimap;
using std::vector;
using std::string;
// fix names may be globally non-unique. Allow for this.
typedef multimap < string, FGFix* > fix_map_type;
typedef fix_map_type::iterator fix_map_iterator;
typedef fix_map_type::const_iterator fix_map_const_iterator;
class FGIdentOrdering; // FIXME, currently declared in Airports/simple.hxx
class FGFixList { class FGFixList {
fix_map_type fixlist;
public: public:
FGFixList(); FGFixList();
~FGFixList(); ~FGFixList();
// load the navaids and build the map // load the navaids and build the map
bool init( SGPath path ); bool init(const SGPath& path);
// query the database for the specified fix
bool query( const string& ident, FGFix* &f );
const FGFix* search(const string& ident);
// Find fix of requested type with closest exact or following ident
// (by ACSII values) to that supplied (ie. a lower-bound lookup).
// Supplying true for exact forces only exact matches to be returned (similar to above function)
// Returns NULL if no match found.
const FGFix* findFirstByIdent( const string& ident, FGIdentOrdering* aOrder = NULL);
// query the database for the specified fix, lon and lat are
// in degrees, elev is in meters
bool query_and_offset( const string& ident, double lon, double lat,
double elev, FGFix* &f, double *heading,
double *dist );
// Return a pointer to the master fixlist
// inline const fix_map_type* getFixList() { return(&fixlist); }
}; };