diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 79566bbdb..e657f2d63 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -33,6 +33,7 @@ #include <FDM/flight.hxx> #include <Main/fg_props.hxx> #include <Navaids/fixlist.hxx> +#include <Navaids/fix.hxx> #include <Navaids/navlist.hxx> #include "route_mgr.hxx" @@ -347,13 +348,13 @@ int FGRouteMgr::make_waypoint( SGWayPoint **wp, const string& tgt ) { } // check for fix id - FGFix f; + FGFix* f; double heading; double dist; - if ( globals->get_fixlist()->query_and_offset( target, lon, lat, 0, &f, &heading, &dist ) ) { + if ( globals->get_fixlist()->query_and_offset( target, lon, lat, 0, f, &heading, &dist ) ) { SG_LOG( SG_GENERAL, SG_INFO, "Adding waypoint (fix) = " << target ); - *wp = new SGWayPoint( f.get_lon(), f.get_lat(), alt, SGWayPoint::WGS84, target ); + *wp = new SGWayPoint( f->get_lon(), f->get_lat(), alt, SGWayPoint::WGS84, target ); return 3; } diff --git a/src/Instrumentation/KLN89/kln89_page_int.cxx b/src/Instrumentation/KLN89/kln89_page_int.cxx index ba7c7b6e5..581580f2a 100644 --- a/src/Instrumentation/KLN89/kln89_page_int.cxx +++ b/src/Instrumentation/KLN89/kln89_page_int.cxx @@ -26,6 +26,7 @@ #endif #include "kln89_page_int.hxx" +#include "Navaids/fix.hxx" KLN89IntPage::KLN89IntPage(KLN89* parent) : KLN89Page(parent) { diff --git a/src/Instrumentation/KLN89/kln89_page_int.hxx b/src/Instrumentation/KLN89/kln89_page_int.hxx index 902e5c125..2b990225f 100644 --- a/src/Instrumentation/KLN89/kln89_page_int.hxx +++ b/src/Instrumentation/KLN89/kln89_page_int.hxx @@ -26,6 +26,8 @@ #include "kln89.hxx" +class FGFix; + class KLN89IntPage : public KLN89Page { public: diff --git a/src/Instrumentation/dclgps.cxx b/src/Instrumentation/dclgps.cxx index bff360b94..ecd4b2211 100644 --- a/src/Instrumentation/dclgps.cxx +++ b/src/Instrumentation/dclgps.cxx @@ -31,6 +31,8 @@ #include <simgear/magvar/magvar.hxx> #include <Main/fg_props.hxx> +#include <Navaids/fix.hxx> + #include <iostream> using std::cout; diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx index b56bd2974..2a11ab9bc 100644 --- a/src/Instrumentation/gps.cxx +++ b/src/Instrumentation/gps.cxx @@ -22,6 +22,7 @@ #include <Main/fg_props.hxx> #include <Main/util.hxx> #include <Navaids/fixlist.hxx> +#include <Navaids/fix.hxx> #include <Navaids/navlist.hxx> #include "gps.hxx" @@ -350,11 +351,11 @@ GPS::update (double delta_time_sec) } } else if (waypont_type == "fix") { - FGFix f; - if ( globals->get_fixlist()->query(wp0_ID, &f) ) { + FGFix* f; + if ( globals->get_fixlist()->query(wp0_ID, f) ) { //cout << "Fix found" << endl; - wp0_longitude_deg = f.get_lon(); - wp0_latitude_deg = f.get_lat(); + wp0_longitude_deg = f->get_lon(); + wp0_latitude_deg = f->get_lat(); _wp0_name_node->setStringValue(wp0_ID.c_str()); } } @@ -387,11 +388,11 @@ GPS::update (double delta_time_sec) } } else if (waypont_type == "fix") { - FGFix f; - if ( globals->get_fixlist()->query(wp1_ID, &f) ) { + FGFix* f; + if ( globals->get_fixlist()->query(wp1_ID, f) ) { //cout << "Fix found" << endl; - wp1_longitude_deg = f.get_lon(); - wp1_latitude_deg = f.get_lat(); + wp1_longitude_deg = f->get_lon(); + wp1_latitude_deg = f->get_lat(); _wp1_name_node->setStringValue(wp1_ID.c_str()); } } diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 20b2f2447..1ec3e2960 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -99,6 +99,7 @@ #include <AIModel/AIManager.hxx> #include <Navaids/navdb.hxx> #include <Navaids/navlist.hxx> +#include <Navaids/fix.hxx> #include <Scenery/scenery.hxx> #include <Scenery/tilemgr.hxx> #include <Scripting/NasalSys.hxx> @@ -1083,15 +1084,15 @@ 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; + FGFix* fix; // set initial position from runway and heading - if ( globals->get_fixlist()->query( id.c_str(), &fix ) ) { + if ( globals->get_fixlist()->query( id.c_str(), fix ) ) { SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for " << id ); - double lon = fix.get_lon(); - double lat = fix.get_lat(); + double lon = fix->get_lon(); + double lat = fix->get_lat(); if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON ) { diff --git a/src/Navaids/fix.hxx b/src/Navaids/fix.hxx index c5451be57..d6ee8da17 100644 --- a/src/Navaids/fix.hxx +++ b/src/Navaids/fix.hxx @@ -24,63 +24,21 @@ #ifndef _FG_FIX_HXX #define _FG_FIX_HXX - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - #include <simgear/compiler.h> -#include <simgear/misc/sgstream.hxx> - -# include <istream> #include <string> -// using std::cout; -// using std::endl; - - -class FGFix { - - std::string ident; - double lon, lat; +#include "positioned.hxx" +class FGFix : public FGPositioned +{ public: + FGFix(const std::string& aIdent, const SGGeod& aPos); + inline ~FGFix(void) {} - inline FGFix(void); - inline ~FGFix(void) {} - - inline const std::string& get_ident() const { return ident; } - inline double get_lon() const { return lon; } - inline double get_lat() const { return lat; } - - friend std::istream& operator>> ( std::istream&, FGFix& ); + inline const std::string& get_ident() const { return ident(); } + inline double get_lon() const { return longitude(); } + inline double get_lat() const { return latitude(); } }; - -inline -FGFix::FGFix() - : ident(""), - lon(0.0), - lat(0.0) -{ -} - - -inline std::istream& -operator >> ( std::istream& in, FGFix& f ) -{ - in >> f.lat; - - if ( f.lat > 95.0 ) { - return in >> skipeol; - } - in >> f.lon >> f.ident; - - // cout << "id = " << f.ident << endl; - - return in >> skipeol; -} - - #endif // _FG_FIX_HXX diff --git a/src/Navaids/fixlist.cxx b/src/Navaids/fixlist.cxx index a07429f06..b189613e2 100644 --- a/src/Navaids/fixlist.cxx +++ b/src/Navaids/fixlist.cxx @@ -32,10 +32,13 @@ #include <simgear/math/sg_geodesy.hxx> #include "fixlist.hxx" +#include "Navaids/fix.hxx" #include "Airports/simple.hxx" -using std::pair; - +FGFix::FGFix(const std::string& aIdent, const SGGeod& aPos) : + FGPositioned(FIX, aIdent, aPos) +{ +} // Constructor FGFixList::FGFixList( void ) { @@ -63,19 +66,14 @@ bool FGFixList::init( SGPath path ) { // read in each remaining line of the file while ( ! in.eof() ) { + double lat, lon; + string ident; + in >> lat >> lon >> ident; + if (lat > 95) break; - FGFix fix; - in >> fix; - if ( fix.get_lat() > 95.0 ) { - break; - } - - /* cout << "ident=" << fix.get_ident() - << ", lat=" << fix.get_lat() - << ", lon=" << fix.get_lon() << endl; */ - - fixlist.insert(pair<string, FGFix>(fix.get_ident(), fix)); - in >> skipcomment; + FGFix* fix = new FGFix(ident, SGGeod::fromDeg(lon, lat)); + fixlist.insert(std::make_pair(fix->ident(), fix)); + in >> skipcomment; } return true; } @@ -83,10 +81,10 @@ bool FGFixList::init( SGPath path ) { // 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 ) { +bool FGFixList::query( const string& ident, FGFix* &fix ) { fix_map_const_iterator it = fixlist.find(ident); if ( it != fixlist.end() ) { - *fix = it->second; + fix = it->second; return true; } else { return false; @@ -97,10 +95,10 @@ bool FGFixList::query( const string& ident, FGFix *fix ) { // 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 elev, FGFix* &fix, double *heading, double *dist ) { - pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident); + std::pair<fix_map_const_iterator, fix_map_const_iterator> range = fixlist.equal_range(ident); if (range.first == range.second) { return false; @@ -110,14 +108,14 @@ bool FGFixList::query_and_offset( const string& ident, double lon, double lat, 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(), + 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; + fix = current->second; } } @@ -131,7 +129,7 @@ const FGFix* FGFixList::search(const string& ident) return NULL; } - return &itr->second; + return itr->second; } class orderingFunctor @@ -174,5 +172,5 @@ const FGFix* FGFixList::findFirstByIdent( const string& ident, FGIdentOrdering* return NULL; } - return &itr->second; + return itr->second; } diff --git a/src/Navaids/fixlist.hxx b/src/Navaids/fixlist.hxx index d0b32eb80..737776971 100644 --- a/src/Navaids/fixlist.hxx +++ b/src/Navaids/fixlist.hxx @@ -32,14 +32,14 @@ #include <vector> #include <string> -#include "fix.hxx" +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 multimap < string, FGFix* > fix_map_type; typedef fix_map_type::iterator fix_map_iterator; typedef fix_map_type::const_iterator fix_map_const_iterator; @@ -58,7 +58,7 @@ public: bool init( SGPath path ); // query the database for the specified fix - bool query( const string& ident, FGFix *f ); + bool query( const string& ident, FGFix* &f ); const FGFix* search(const string& ident); @@ -71,11 +71,11 @@ public: // 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 elev, FGFix* &f, double *heading, double *dist ); // Return a pointer to the master fixlist - inline const fix_map_type* getFixList() { return(&fixlist); } + // inline const fix_map_type* getFixList() { return(&fixlist); } }; diff --git a/src/Navaids/navdb.cxx b/src/Navaids/navdb.cxx index a8d2fbdd7..54ab04b17 100644 --- a/src/Navaids/navdb.cxx +++ b/src/Navaids/navdb.cxx @@ -29,6 +29,8 @@ #include <string> #include <simgear/debug/logstream.hxx> +#include <simgear/misc/sgstream.hxx> + #include <simgear/math/sg_geodesy.hxx> #include <simgear/misc/strutils.hxx>