]> git.mxchange.org Git - flightgear.git/commitdiff
Convert the only remaining user of FGFixList to use an FGPositioned query,
authorjmt <jmt>
Tue, 23 Dec 2008 14:41:58 +0000 (14:41 +0000)
committerjmt <jmt>
Tue, 23 Dec 2008 14:41:58 +0000 (14:41 +0000)
and hence remove the query code from fix-list. The only remaining code deals
with parsing fix.dat.

src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Navaids/fixlist.cxx
src/Navaids/fixlist.hxx

index a6d12bf2b48aad456dc03ab2db53b4dbdc63959a..4dd8fdcf82a64bd3cc60a14c0abdff07b690f3ce 100644 (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)
 static bool fgSetPosFromFix( const string& id )
 {
-  FGFix* fix;
-  
-  // set initial position from runway and heading
-  if ( !globals->get_fixlist()->query( id.c_str(), fix ) ) {
-    SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = " << id );
+  FGPositioned::TypeFilter fixFilter(FGPositioned::FIX);
+  FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter);
+  if (!fix) {
+    SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id );
     return false;
   }
   
@@ -951,7 +950,6 @@ static bool fgSetPosFromFix( const string& id )
   return true;
 }
 
-
 /**
  * Initialize vor/ndb/ils/fix list management and query systems (as
  * well as simple airport db list)
@@ -1000,7 +998,6 @@ fgInitNav ()
     p_fix.append( "Navaids/fix.dat" );
     FGFixList *fixlist = new FGFixList;
     fixlist->init( p_fix );
-    globals->set_fixlist( fixlist );
 
     SG_LOG(SG_GENERAL, SG_INFO, "  Airways");
     SGPath p_awy( globals->get_fg_root() );
index 5afb30d42925de7b23be391380b8ae0f5f8f7f9d..8cf9d171d0741c3cdec7f8cbe86ed69104c86e9e 100644 (file)
@@ -108,7 +108,6 @@ FGGlobals::FGGlobals() :
     tacanlist( NULL ),
     carrierlist( NULL ),
     channellist( NULL ),
-    fixlist( NULL ),
     airwaynet( NULL ),
     multiplayer_mgr( NULL )
 {
@@ -160,7 +159,6 @@ FGGlobals::~FGGlobals()
     delete tacanlist;
     delete carrierlist;
     delete channellist;
-    delete fixlist;
     delete airwaynet;
     delete multiplayer_mgr;
 }
index efabd4e72b93fe4969f9f614f42d2cb129871849..64291971f697b92ff8533a88e860b93762a97f1a 100644 (file)
@@ -64,7 +64,6 @@ class FGIO;
 class FGNavList;
 class FGAirwayNetwork;
 class FGTACANList;
-class FGFixList;
 class FGLight;
 class FGModelMgr;
 class FGRouteMgr;
@@ -188,7 +187,6 @@ private:
     FGNavList *tacanlist;
     FGNavList *carrierlist;
     FGTACANList *channellist;
-    FGFixList *fixlist;
     FGAirwayNetwork *airwaynet;
 
     //Mulitplayer managers
@@ -335,8 +333,6 @@ public:
     inline void set_carrierlist( FGNavList *n ) { carrierlist = n; }
     inline FGNavList *get_mkrlist() const { return mkrlist; }
     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 void set_channellist( FGTACANList *c ) { channellist = c; }
 
index b189613e247359faddac886eb978be4e8b15f778..1f685e193fa719b98a8a14904e9e99c303116e59 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sgstream.hxx>
+#include <simgear/misc/sg_path.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 
 #include "fixlist.hxx"
@@ -51,9 +52,7 @@ FGFixList::~FGFixList( void ) {
 
 
 // load the navaids and build the map
-bool FGFixList::init( SGPath path ) {
-    fixlist.erase( fixlist.begin(), fixlist.end() );
-
+bool FGFixList::init(const SGPath& path ) {
     sg_gzifstream in( path.str() );
     if ( !in.is_open() ) {
         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
@@ -71,106 +70,10 @@ bool FGFixList::init( SGPath path ) {
       in >> lat >> lon >> ident;
       if (lat > 95) break;
 
-      FGFix* fix = new FGFix(ident, SGGeod::fromDeg(lon, lat));
-      fixlist.insert(std::make_pair(fix->ident(), fix));
+      // fix gets added to the FGPositioned spatial indices, so we don't need
+      // to hold onto it here.
+      new FGFix(ident, SGGeod::fromDeg(lon, lat));
       in >> skipcomment;
     }
     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;
-}
index 7377769712d79a02d3daa673798fe464e9967925..075f16d027b5296213344a327cf16ad62593ed0f 100644 (file)
 
 
 #include <simgear/compiler.h>
-#include <simgear/misc/sg_path.hxx>
-
-#include <map>
-#include <vector>
-#include <string>
 
 class FGFix;
-
-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 SGPath;
 
 class FGFixList {
-
-    fix_map_type fixlist;
-
 public:
 
     FGFixList();
     ~FGFixList();
 
     // load the navaids and build the map
-    bool init( 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); }
+    bool init(const SGPath& path);
 };