}
}
-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)
{
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
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) {
}
// 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);
// 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
# 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);
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();
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;
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)
{
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);
# 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();
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);
virtual void setValue(const char *);
private:
- FGAirportList *_airports;
char **_content;
std::string _filter;
};
// 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: ";
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;
#include <Navaids/awynet.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
-#include <Airports/simple.hxx>
#include <Navaids/navlist.hxx>
#include <Navaids/fixlist.hxx>
route_mgr( NULL ),
current_panel( NULL ),
soundmgr( NULL ),
- airports( NULL ),
ATC_mgr( NULL ),
AI_mgr( NULL ),
controls( NULL ),
delete route_mgr;
delete current_panel;
delete soundmgr;
- delete airports;
delete ATC_mgr;
delete AI_mgr;
class SGSubsystemMgr;
class SGSubsystem;
-class FGAirportList;
class FGAIMgr;
class FGATCMgr;
class FGAircraftModel;
// sound manager
SGSoundMgr *soundmgr;
- // Simple Airport List
- FGAirportList *airports;
-
// ATC manager
FGATCMgr *ATC_mgr;
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; }
// 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();
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);
// 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;
}