#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <simgear/misc/sgstream.hxx>
+#include <simgear/misc/strutils.hxx>
#include <simgear/misc/interpolator.hxx>
#include <simgear/scene/material/matlib.hxx>
// Set current_options lon/lat given an airport id and heading (degrees)
-static bool fgSetPosFromNAV( const string& id, const double& freq ) {
- FGNavRecord *nav
- = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq );
+static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned::Type type ) {
- if (!nav) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
- << id << ":" << freq );
- return false;
- }
-
- fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
- return true;
+ const nav_list_type navlist
+ = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq, type );
+
+ if (navlist.size() == 0 ) {
+ SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
+ << id << ":" << freq );
+ return false;
+ }
+
+ if( navlist.size() > 1 ) {
+ ostringstream buf;
+ buf << "Ambigous NAV-ID: '" << id << "'. Specify id and frequency. Available stations:" << endl;
+ for( nav_list_type::const_iterator it = navlist.begin(); it != navlist.end(); ++it ) {
+ // NDB stored in kHz, VOR stored in MHz * 100 :-P
+ double factor = (*it)->type() == FGPositioned::NDB ? 1.0 : 1/100.0;
+ string unit = (*it)->type() == FGPositioned::NDB ? "kHz" : "MHz";
+ buf << (*it)->ident() << " "
+ << setprecision(5) << (double)((*it)->get_freq() * factor) << " "
+ << (*it)->get_lat() << "/" << (*it)->get_lon()
+ << endl;
+ }
+
+ SG_LOG( SG_GENERAL, SG_ALERT, buf.str() );
+ return false;
+ }
+
+ FGNavRecord *nav = navlist[0];
+ fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
+ return true;
}
// Set current_options lon/lat given an aircraft carrier id
if ( !set_pos && !vor.empty() ) {
// a VOR is requested
- if ( fgSetPosFromNAV( vor, vor_freq ) ) {
+ if ( fgSetPosFromNAV( vor, vor_freq, FGPositioned::VOR ) ) {
set_pos = true;
}
}
if ( !set_pos && !ndb.empty() ) {
// an NDB is requested
- if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
+ if ( fgSetPosFromNAV( ndb, ndb_freq, FGPositioned::NDB ) ) {
set_pos = true;
}
}