1
0
Fork 0

FGAirportList is gone. Everything should work as before, especially the

AirportList dialog. (It would now be possible to trivially implement a
VOR or NDB named search, if anyone wants such a thing).
This commit is contained in:
jmt 2008-12-27 13:20:08 +00:00
parent b58c8b6f19
commit f1b10eddfa
11 changed files with 41 additions and 173 deletions

View 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, 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) 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); tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height);
} }
return new FGAirport(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
return airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
fptypeFromRobinType(type)); fptypeFromRobinType(type));
} }
// Load the airport data base from the specified aptdb file. The // Load the airport data base from the specified aptdb file. The
// metar file is used to mark the airports as having metar available // metar file is used to mark the airports as having metar available
// or not. // or not.
bool fgAirportDBLoad( FGAirportList *airports, bool fgAirportDBLoad( const string &aptdb_file, const string &metar_file )
const string &aptdb_file, const string &metar_file )
{ {
// //
// Load the apt.dat file // Load the apt.dat file
@ -166,7 +163,7 @@ bool fgAirportDBLoad( FGAirportList *airports,
SG_LOG( SG_GENERAL, SG_BULK, "Next airport = " << id << " " SG_LOG( SG_GENERAL, SG_BULK, "Next airport = " << id << " "
<< elev ); << 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); last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type);
for (unsigned int r=0; r< runways.size(); ++r) { 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 // 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); last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type);

View file

@ -35,7 +35,7 @@
// Load the airport data base from the specified aptdb file. The // Load the airport data base from the specified aptdb file. The
// metar file is used to mark the airports as having metar available // metar file is used to mark the airports as having metar available
// or not. // 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 #endif // _FG_APT_LOADER_HXX

View file

@ -28,29 +28,19 @@
# include <config.h> # include <config.h>
#endif #endif
#include <math.h> #include "simple.hxx"
#include <algorithm>
#include <simgear/compiler.h> #include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/sg_inlines.h>
#include <Environment/environment_mgr.hxx> #include <Environment/environment_mgr.hxx>
#include <Environment/environment.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 <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Airports/runways.hxx> #include <Airports/runways.hxx>
#include <Airports/dynamics.hxx> #include <Airports/dynamics.hxx>
#include <Airports/xmlloader.hxx>
#include <string>
#include "simple.hxx"
#include "xmlloader.hxx"
using std::sort;
using std::random_shuffle;
// magic import of a helper which uses FGPositioned internals // magic import of a helper which uses FGPositioned internals
extern char** searchAirportNamesAndIdents(const std::string& aFilter); extern char** searchAirportNamesAndIdents(const std::string& aFilter);
@ -151,19 +141,6 @@ FGAirport::getIteratorForRunwayIdent(const string& aIdent) const
return it; // end() 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 FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
{ {
Runway_iterator it = mRunways.begin(); Runway_iterator it = mRunways.begin();
@ -179,7 +156,8 @@ FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const
for (; it != mRunways.end(); ++it) { for (; it != mRunways.end(); ++it) {
double good = (*it)->score(lengthWeight, widthWeight, surfaceWeight); 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 bad = fabs(deviationWeight * dev) + 1e-20;
double quality = good / bad; double quality = good / bad;
@ -308,49 +286,6 @@ char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
return searchAirportNamesAndIdents(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 // find basic airport location info from airport database
const FGAirport *fgFindAirportID( const string& id) const FGAirport *fgFindAirportID( const string& id)
{ {

View file

@ -156,40 +156,6 @@ private:
std::vector<FGRunwayPtr> mTaxiways; 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 // find basic airport location info from airport database
const FGAirport *fgFindAirportID( const std::string& id); const FGAirport *fgFindAirportID( const std::string& id);

View file

@ -2,17 +2,14 @@
# include "config.h" # include "config.h"
#endif #endif
#include <locale>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Airports/simple.hxx> #include <Airports/simple.hxx>
#include "AirportList.hxx" #include "AirportList.hxx"
AirportList::AirportList(int x, int y, int width, int height) : AirportList::AirportList(int x, int y, int width, int height) :
puaList(x, y, width, height), puaList(x, y, width, height),
GUI_ID(FGCLASS_AIRPORTLIST), GUI_ID(FGCLASS_AIRPORTLIST),
_airports(globals->get_airports()),
_content(0) _content(0)
{ {
create_list(); create_list();
@ -28,28 +25,9 @@ AirportList::~AirportList()
void void
AirportList::create_list() AirportList::create_list()
{ {
const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale()); char **content = FGAirport::searchNamesAndIdents(_filter);
int num_apt = _airports->size(); int n = (content[0] != NULL) ? 1 : 0;
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;
// work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up
newList(n > 0 ? content : 0); newList(n > 0 ? content : 0);

View file

@ -19,7 +19,6 @@ public:
virtual void setValue(const char *); virtual void setValue(const char *);
private: private:
FGAirportList *_airports;
char **_content; char **_content;
std::string _filter; std::string _filter;
}; };

View file

@ -577,7 +577,6 @@ void KLN89::DrawMap(bool draw_avs) {
// Annotation then gets drawn by Nav page, NOT this function. // Annotation then gets drawn by Nav page, NOT this function.
if(_drawApt && draw_avs) { if(_drawApt && draw_avs) {
airport_list apt;
/* /*
bool have_apt = _overlays->FindArpByRegion(&apt, bottomLeft.lat(), bottomLeft.lon(), topRight.lat(), topRight.lon()); bool have_apt = _overlays->FindArpByRegion(&apt, bottomLeft.lat(), bottomLeft.lon(), topRight.lat(), topRight.lon());
//cout << "Vors enclosed are: "; //cout << "Vors enclosed are: ";

View file

@ -965,10 +965,7 @@ fgInitNav ()
SGPath p_metar( globals->get_fg_root() ); SGPath p_metar( globals->get_fg_root() );
p_metar.append( "Airports/metar.dat" ); p_metar.append( "Airports/metar.dat" );
FGAirportList *airports = new FGAirportList(); fgAirportDBLoad( aptdb.str(), p_metar.str() );
globals->set_airports( airports );
fgAirportDBLoad( airports, aptdb.str(), p_metar.str() );
FGNavList *navlist = new FGNavList; FGNavList *navlist = new FGNavList;
FGNavList *loclist = new FGNavList; FGNavList *loclist = new FGNavList;

View file

@ -47,7 +47,6 @@
#include <Navaids/awynet.hxx> #include <Navaids/awynet.hxx>
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx> #include <Scenery/tilemgr.hxx>
#include <Airports/simple.hxx>
#include <Navaids/navlist.hxx> #include <Navaids/navlist.hxx>
#include <Navaids/fixlist.hxx> #include <Navaids/fixlist.hxx>
@ -83,7 +82,6 @@ FGGlobals::FGGlobals() :
route_mgr( NULL ), route_mgr( NULL ),
current_panel( NULL ), current_panel( NULL ),
soundmgr( NULL ), soundmgr( NULL ),
airports( NULL ),
ATC_mgr( NULL ), ATC_mgr( NULL ),
AI_mgr( NULL ), AI_mgr( NULL ),
controls( NULL ), controls( NULL ),
@ -133,7 +131,6 @@ FGGlobals::~FGGlobals()
delete route_mgr; delete route_mgr;
delete current_panel; delete current_panel;
delete soundmgr; delete soundmgr;
delete airports;
delete ATC_mgr; delete ATC_mgr;
delete AI_mgr; delete AI_mgr;

View file

@ -54,7 +54,6 @@ class SGEventMgr;
class SGSubsystemMgr; class SGSubsystemMgr;
class SGSubsystem; class SGSubsystem;
class FGAirportList;
class FGAIMgr; class FGAIMgr;
class FGATCMgr; class FGATCMgr;
class FGAircraftModel; class FGAircraftModel;
@ -137,9 +136,6 @@ private:
// sound manager // sound manager
SGSoundMgr *soundmgr; SGSoundMgr *soundmgr;
// Simple Airport List
FGAirportList *airports;
// ATC manager // ATC manager
FGATCMgr *ATC_mgr; FGATCMgr *ATC_mgr;
@ -243,9 +239,6 @@ public:
inline SGMaterialLib *get_matlib() const { return matlib; } inline SGMaterialLib *get_matlib() const { return matlib; }
inline void set_matlib( SGMaterialLib *m ) { matlib = m; } 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 FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; } inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }

View file

@ -370,6 +370,7 @@ char** searchAirportNamesAndIdents(const std::string& aFilter)
// may get very large and smart-pointer-atomicity-locking then becomes a // may get very large and smart-pointer-atomicity-locking then becomes a
// bottleneck for this case. // bottleneck for this case.
std::vector<FGPositioned*> matches; std::vector<FGPositioned*> matches;
std::string upper;
for (; it != end; ++it) { for (; it != end; ++it) {
FGPositioned::Type ty = it->second->type(); FGPositioned::Type ty = it->second->type();
@ -377,10 +378,12 @@ char** searchAirportNamesAndIdents(const std::string& aFilter)
continue; continue;
} }
if (hasFilter && if (hasFilter && (it->second->ident().find(aFilter) == std::string::npos)) {
(it->second->name().find(aFilter) == std::string::npos) && upper = it->second->name(); // string copy, sadly
(it->second->ident().find(aFilter) == std::string::npos)) { ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
continue; if (upper.find(aFilter) == std::string::npos) {
continue;
}
} }
matches.push_back(it->second); matches.push_back(it->second);
@ -396,23 +399,27 @@ char** searchAirportNamesAndIdents(const std::string& aFilter)
// nasty code to avoid excessive string copying and allocations. // nasty code to avoid excessive string copying and allocations.
// We format results as follows (note whitespace!): // We format results as follows (note whitespace!):
// ' name-of-airport-chars (icao)' // ' name-of-airport-chars (ident)'
// so the total length is: // 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. // 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) { for (unsigned int i=0; i<numMatches; ++i) {
int nameLength = matches[i]->name().size(); int nameLength = matches[i]->name().size();
int icaoLength = matches[i]->ident().size();
char* entry = new char[nameLength + 11]; char* entry = new char[nameLength + 11];
entry[0] = ' '; char* dst = entry;
memcpy(entry + 1, matches[i]->name().c_str(), nameLength); *dst++ = ' ';
entry[nameLength + 1] = ' '; memcpy(dst, matches[i]->name().c_str(), nameLength);
entry[nameLength + 2] = ' '; dst += nameLength;
entry[nameLength + 3] = ' '; *dst++ = ' ';
entry[nameLength + 4] = '('; *dst++ = ' ';
memcpy(entry + nameLength + 5, matches[i]->ident().c_str(), 4); *dst++ = ' ';
entry[nameLength + 9] = ')'; *dst++ = '(';
entry[nameLength + 10] = 0; memcpy(dst, matches[i]->ident().c_str(), icaoLength);
dst += icaoLength;
*dst++ = ')';
*dst++ = 0;
result[i] = entry; result[i] = entry;
} }