]> git.mxchange.org Git - flightgear.git/commitdiff
FGAirportList is gone. Everything should work as before, especially the
authorjmt <jmt>
Sat, 27 Dec 2008 13:20:08 +0000 (13:20 +0000)
committerjmt <jmt>
Sat, 27 Dec 2008 13:20:08 +0000 (13:20 +0000)
AirportList dialog. (It would now be possible to trivially implement a
VOR or NDB named search, if anyone wants such a thing).

src/Airports/apt_loader.cxx
src/Airports/apt_loader.hxx
src/Airports/simple.cxx
src/Airports/simple.hxx
src/GUI/AirportList.cxx
src/GUI/AirportList.hxx
src/Instrumentation/KLN89/kln89.cxx
src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Navaids/positioned.cxx

index d0602ac69c5c5c379a54d8c857e309e7b40603cf..ef825295f9159cd874a7e0eef380f11b0c663e7e 100644 (file)
@@ -57,7 +57,7 @@ static FGPositioned::Type fptypeFromRobinType(int aType)
   }
 }
 
-FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const string& apt_name,
+FGAirport* addAirport(const string& apt_id, const string& apt_name,
     int rwy_count, double rwy_lat_accum, double rwy_lon_accum, double last_rwy_heading,
     double apt_elev, SGGeod& tower, bool got_tower, int type)
 {
@@ -82,17 +82,14 @@ FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const strin
         tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height);
     }
 
-  
-
-    return airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
+    return new FGAirport(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
         fptypeFromRobinType(type));
 }
 
 // Load the airport data base from the specified aptdb file.  The
 // metar file is used to mark the airports as having metar available
 // or not.
-bool fgAirportDBLoad( FGAirportList *airports, 
-                      const string &aptdb_file, const string &metar_file )
+bool fgAirportDBLoad( const string &aptdb_file, const string &metar_file )
 {
     //
     // Load the apt.dat file
@@ -166,7 +163,7 @@ bool fgAirportDBLoad( FGAirportList *airports,
             SG_LOG( SG_GENERAL, SG_BULK, "Next airport = " << id << " "
                     << elev );
 
-            FGAirport* apt = addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
+            FGAirport* apt = addAirport(last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
                 last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type);
 
             for (unsigned int r=0; r< runways.size(); ++r) {
@@ -269,7 +266,7 @@ bool fgAirportDBLoad( FGAirportList *airports,
     }
 
     // add the last airport being processed if any
-    addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
+    addAirport( last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
         last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type);
 
 
index 883e0384d56fd8906d353689d2df12850491e7ec..af2d46aeba47c0547e9817da4b3b6295e77b2e31 100644 (file)
@@ -35,7 +35,7 @@
 // Load the airport data base from the specified aptdb file.  The
 // metar file is used to mark the airports as having metar available
 // or not.
-bool fgAirportDBLoad( FGAirportList *airports, const string &aptdb_file, const std::string &metar_file );
+bool fgAirportDBLoad( const string &aptdb_file, const std::string &metar_file );
 
 
 #endif // _FG_APT_LOADER_HXX
index af1e0de195e04eb42219494a52aaed80ce140e6d..0907030fbd0a304bdbf0f4ec5984e743425f33c5 100644 (file)
 #  include <config.h>
 #endif
 
-#include <math.h>
-#include <algorithm>
-
-#include <simgear/compiler.h>
+#include "simple.hxx"
 
-#include <Environment/environment_mgr.hxx>
-#include <Environment/environment.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/props/props.hxx>
-#include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/debug/logstream.hxx>
-#include <Main/globals.hxx>
+#include <simgear/sg_inlines.h>
+
+#include <Environment/environment_mgr.hxx>
+#include <Environment/environment.hxx>
 #include <Main/fg_props.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/dynamics.hxx>
-
-#include <string>
-
-#include "simple.hxx"
-#include "xmlloader.hxx"
-
-using std::sort;
-using std::random_shuffle;
+#include <Airports/xmlloader.hxx>
 
 // magic import of a helper which uses FGPositioned internals
 extern char** searchAirportNamesAndIdents(const std::string& aFilter);
@@ -151,19 +141,6 @@ FGAirport::getIteratorForRunwayIdent(const string& aIdent) const
   return it; // end()
 }
 
-static double normaliseBearing(double aBearing)
-{
-  while (aBearing < -180) {
-    aBearing += 360.0;
-  }
-  
-  while (aBearing > 180.0) {
-    aBearing -= 360.0;
-  }
-  
-  return aBearing;
-}
-
 FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
 {
   Runway_iterator it = mRunways.begin();
@@ -179,7 +156,8 @@ FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
   for (; it != mRunways.end(); ++it) {
     double good = (*it)->score(lengthWeight, widthWeight, surfaceWeight);
     
-    double dev = normaliseBearing(aHeading - (*it)->headingDeg());
+    double dev = aHeading - (*it)->headingDeg();
+    SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
     double bad = fabs(deviationWeight * dev) + 1e-20;
     double quality = good / bad;
     
@@ -308,49 +286,6 @@ char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
   return searchAirportNamesAndIdents(aFilter);
 }
 
-/******************************************************************************
- * FGAirportList
- *****************************************************************************/
-
-FGAirportList::FGAirportList()
-{
-}
-
-
-FGAirportList::~FGAirportList( void )
-{
-    for (unsigned int i = 0; i < airports_array.size(); ++i) {
-        delete airports_array[i];
-    }
-}
-
-
-// add an entry to the list
-FGAirport* FGAirportList::add( const string &id, const SGGeod& location, const SGGeod& tower_location,
-                         const string &name, bool has_metar, FGPositioned::Type aType)
-{
-    FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar, aType);
-    // try and read in an auxilary file
-    airports_array.push_back( a );
-    return a;
-}
-
-int
-FGAirportList::size () const
-{
-    return airports_array.size();
-}
-
-
-const FGAirport *FGAirportList::getAirport( unsigned int index ) const
-{
-    if (index < airports_array.size()) {
-        return(airports_array[index]);
-    } else {
-        return(NULL);
-    }
-}
-
 // find basic airport location info from airport database
 const FGAirport *fgFindAirportID( const string& id)
 {
index 6d95bcf87626a1fadbca11c60873fc3145580e00..f79b6187be777f79f6240f4453f9a8879e6acf49 100644 (file)
@@ -156,40 +156,6 @@ private:
     std::vector<FGRunwayPtr> mTaxiways;
 };
 
-typedef std::vector < FGAirport * > airport_list;
-typedef airport_list::iterator airport_list_iterator;
-typedef airport_list::const_iterator const_airport_list_iterator;
-
-
-
-class FGAirportList {
-private:
-
-    airport_list airports_array;
-
-public:
-    // Constructor (new)
-    FGAirportList();
-
-    // Destructor
-    ~FGAirportList();
-
-    // add an entry to the list
-    FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower,
-              const std::string& name, bool has_metar, FGPositioned::Type aType);
-
-    /**
-     * Return the number of airports in the list.
-     */
-    int size() const;
-
-    /**
-     * Return a specific airport, by position.
-     */
-    const FGAirport *getAirport( unsigned int index ) const;
-
-};
-
 // find basic airport location info from airport database
 const FGAirport *fgFindAirportID( const std::string& id);
 
index 133b2b9ea65f147f20c88880f795e64d5f495df6..bcbe06e09c90dea778a4430228f2d208d93f4313 100644 (file)
@@ -2,17 +2,14 @@
 #  include "config.h"
 #endif
 
-#include <locale>
 #include <Main/globals.hxx>
 #include <Airports/simple.hxx>
 
 #include "AirportList.hxx"
 
-
 AirportList::AirportList(int x, int y, int width, int height) :
     puaList(x, y, width, height),
     GUI_ID(FGCLASS_AIRPORTLIST),
-    _airports(globals->get_airports()),
     _content(0)
 {
     create_list();
@@ -28,28 +25,9 @@ AirportList::~AirportList()
 void
 AirportList::create_list()
 {
-    const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
-    int num_apt = _airports->size();
-    char **content = new char *[num_apt + 1];
-
-    int n = 0;
-    for (int i = 0; i < num_apt; i++) {
-        const FGAirport *apt = _airports->getAirport(i);
-        std::string entry(' ' + apt->getName() + "   (" + apt->getId() + ')');
-
-        if (!_filter.empty()) {
-            std::string upper(entry.data());
-            ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
-
-            if (upper.find(_filter) == std::string::npos)
-                continue;
-        }
-
-        content[n] = new char[entry.size() + 1];
-        strcpy(content[n], entry.c_str());
-        n++;
-    }
-    content[n] = 0;
+   char **content = FGAirport::searchNamesAndIdents(_filter);
+   int n = (content[0] != NULL) ? 1 : 0;
+    
     // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
     newList(n > 0 ? content : 0);
 
index dabd6977829dc81c1419dedd24b0b1450c047dd2..bc745930c3e7601041dfc39c5374738eec2db735 100644 (file)
@@ -19,7 +19,6 @@ public:
     virtual void setValue(const char *);
 
 private:
-    FGAirportList *_airports;
     char **_content;
     std::string _filter;
 };
index 70c948fd957e862d74a7b8aedab03c49c52bf3b2..6ee1c21ac40f60df68db2c24ec6c96f9e1969020 100644 (file)
@@ -577,7 +577,6 @@ void KLN89::DrawMap(bool draw_avs) {
        // Annotation then gets drawn by Nav page, NOT this function.
 
        if(_drawApt && draw_avs) {
-               airport_list apt;
                /*
                bool have_apt = _overlays->FindArpByRegion(&apt, bottomLeft.lat(), bottomLeft.lon(), topRight.lat(), topRight.lon());
                //cout << "Vors enclosed are: ";
index bc24739af70825fa1fee7c71af5bf4bd96c7aabf..c3cebfe09ba3daafc859bcda3ed24ffaae66bc7e 100644 (file)
@@ -965,10 +965,7 @@ fgInitNav ()
     SGPath p_metar( globals->get_fg_root() );
     p_metar.append( "Airports/metar.dat" );
 
-    FGAirportList *airports = new FGAirportList();
-    globals->set_airports( airports );
-
-    fgAirportDBLoad( airports, aptdb.str(), p_metar.str() );
+    fgAirportDBLoad( aptdb.str(), p_metar.str() );
 
     FGNavList *navlist = new FGNavList;
     FGNavList *loclist = new FGNavList;
index 1bcbbea678ea03b71e8fb53953e7ff8f04ae0b62..782a229a88a7498568d031ae670bd5a6192dc489 100644 (file)
@@ -47,7 +47,6 @@
 #include <Navaids/awynet.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
-#include <Airports/simple.hxx>
 #include <Navaids/navlist.hxx>
 #include <Navaids/fixlist.hxx>
 
@@ -83,7 +82,6 @@ FGGlobals::FGGlobals() :
     route_mgr( NULL ),
     current_panel( NULL ),
     soundmgr( NULL ),
-    airports( NULL ),
     ATC_mgr( NULL ),
     AI_mgr( NULL ),
     controls( NULL ),
@@ -133,7 +131,6 @@ FGGlobals::~FGGlobals()
     delete route_mgr;
     delete current_panel;
     delete soundmgr;
-    delete airports;
 
     delete ATC_mgr;
     delete AI_mgr;
index 4b21c77f8b402887deaaed165ca06adb7eedeac5..d962bae2c2937bbc6e2f12de46e177e6ac6d0f53 100644 (file)
@@ -54,7 +54,6 @@ class SGEventMgr;
 class SGSubsystemMgr;
 class SGSubsystem;
 
-class FGAirportList;
 class FGAIMgr;
 class FGATCMgr;
 class FGAircraftModel;
@@ -137,9 +136,6 @@ private:
     // sound manager
     SGSoundMgr *soundmgr;
 
-    // Simple Airport List
-    FGAirportList *airports;
-
     // ATC manager
     FGATCMgr *ATC_mgr;
 
@@ -243,9 +239,6 @@ public:
     inline SGMaterialLib *get_matlib() const { return matlib; }
     inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
 
-    inline FGAirportList *get_airports() const { return airports; }
-    inline void set_airports( FGAirportList *a ) {airports = a; }
-
     inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
     inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }
 
index a705c8495c5c58f0336d5a3fd6b3d54b8a751862..b01418a17367a1814dea1b8cbd5427f80192d2e7 100644 (file)
@@ -370,6 +370,7 @@ char** searchAirportNamesAndIdents(const std::string& aFilter)
   // may get very large and smart-pointer-atomicity-locking then becomes a
   // bottleneck for this case.
   std::vector<FGPositioned*> matches;
+  std::string upper;
   
   for (; it != end; ++it) {
     FGPositioned::Type ty = it->second->type();
@@ -377,10 +378,12 @@ char** searchAirportNamesAndIdents(const std::string& aFilter)
       continue;
     }
     
-    if (hasFilter &&
-        (it->second->name().find(aFilter) == std::string::npos) &&
-        (it->second->ident().find(aFilter) == std::string::npos)) {
-      continue;
+    if (hasFilter && (it->second->ident().find(aFilter) == std::string::npos)) {
+      upper = it->second->name(); // string copy, sadly
+      ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
+      if (upper.find(aFilter) == std::string::npos) {
+        continue;
+      }
     }
     
     matches.push_back(it->second);
@@ -396,23 +399,27 @@ char** searchAirportNamesAndIdents(const std::string& aFilter)
   
   // nasty code to avoid excessive string copying and allocations.
   // We format results as follows (note whitespace!):
-  //   ' name-of-airport-chars   (icao)'
+  //   ' name-of-airport-chars   (ident)'
   // so the total length is:
-  //    1 + strlen(name) + 4 + 4 (for the ICAO) + 1 + 1 (for the null)
+  //    1 + strlen(name) + 4 + 4 (for the ident) + 1 + 1 (for the null)
   // which gives a grand total of 11 + the length of the name.
-  
+  // note the ident is sometimes only three letters for non-ICAO small strips
   for (unsigned int i=0; i<numMatches; ++i) {
     int nameLength = matches[i]->name().size();
+    int icaoLength = matches[i]->ident().size();
     char* entry = new char[nameLength + 11];
-    entry[0] = ' ';
-    memcpy(entry + 1, matches[i]->name().c_str(), nameLength);
-    entry[nameLength + 1] = ' ';
-    entry[nameLength + 2] = ' ';
-    entry[nameLength + 3] = ' ';
-    entry[nameLength + 4] = '(';
-    memcpy(entry + nameLength + 5, matches[i]->ident().c_str(), 4);
-    entry[nameLength + 9] = ')';
-    entry[nameLength + 10] = 0;
+    char* dst = entry;
+    *dst++ = ' ';
+    memcpy(dst, matches[i]->name().c_str(), nameLength);
+    dst += nameLength;
+    *dst++ = ' ';
+    *dst++ = ' ';
+    *dst++ = ' ';
+    *dst++ = '(';
+    memcpy(dst, matches[i]->ident().c_str(), icaoLength);
+    dst += icaoLength;
+    *dst++ = ')';
+    *dst++ = 0;
     result[i] = entry;
   }