#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/structure/exception.hxx>
#include "fixlist.hxx"
-#include "Navaids/fix.hxx"
-#include "Airports/simple.hxx"
+#include <Navaids/fix.hxx>
+#include <Navaids/NavDataCache.hxx>
-FGFix::FGFix(const std::string& aIdent, const SGGeod& aPos) :
- FGPositioned(FIX, aIdent, aPos)
+FGFix::FGFix(PositionedID aGuid, const std::string& aIdent, const SGGeod& aPos) :
+ FGPositioned(aGuid, FIX, aIdent, aPos)
{
}
-// Constructor
-FGFixList::FGFixList( void ) {
-}
-
-
-// Destructor
-FGFixList::~FGFixList( void ) {
-}
-
-// load the navaids and build the map
-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() );
- exit(-1);
- }
-
- // toss the first two lines of the file
- in >> skipeol;
- in >> skipeol;
-
- // read in each remaining line of the file
- while ( ! in.eof() ) {
- double lat, lon;
- string ident;
- in >> lat >> lon >> ident;
- if (lat > 95) break;
+namespace flightgear
+{
+
+void loadFixes(const SGPath& path)
+{
+ sg_gzifstream in( path.str() );
+ if ( !in.is_open() ) {
+ throw sg_io_exception("Cannot open file:", path);
+ }
+
+ // toss the first two lines of the file
+ in >> skipeol;
+ in >> skipeol;
+
+ NavDataCache* cache = NavDataCache::instance();
+
+ // read in each remaining line of the file
+ while ( ! in.eof() ) {
+ double lat, lon;
+ std::string ident;
+ in >> lat >> lon >> ident;
+ if (lat > 95) break;
+
+ cache->insertFix(ident, SGGeod::fromDeg(lon, lat));
+ in >> skipcomment;
+ }
- // 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;
}
+
+} // of namespace flightgear;