X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fnavdb.cxx;h=99453022a826c45185b2b48a032939adffd3ca1e;hb=3e46c7998ce2bf23ec322d1dfe65c8da35621d51;hp=5c592c1c4bbed9b6f7c178e22ef080f5f9c7e8c1;hpb=9b900e94304b95337e2731946525cde4ef377da9;p=flightgear.git diff --git a/src/Navaids/navdb.cxx b/src/Navaids/navdb.cxx index 5c592c1c4..99453022a 100644 --- a/src/Navaids/navdb.cxx +++ b/src/Navaids/navdb.cxx @@ -40,7 +40,7 @@ #include "navlist.hxx" #include
#include -#include +#include #include #include #include
@@ -74,10 +74,10 @@ static bool autoAlignLocalizers = false; static double autoAlignThreshold = 0.0; /** - * Given a runway, and proposed localiser data (ident, positioned and heading), - * precisely align the localiser with the actual runway heading, providing the - * difference between the localiser course and runway heading is less than a - * threshold. (To allow for localizers such as Kai-Tek requiring a turn on final). + * Given a runway, and proposed localizer data (ident, positioned and heading), + * precisely align the localizer with the actual runway heading, providing the + * difference between the localizer course and runway heading is less than a + * threshold. (To allow for localizers such as Kai-Tak requiring a turn on final). * * The positioned and heading argument are modified if changes are made. */ @@ -97,7 +97,7 @@ void alignLocaliserWithRunway(FGRunway* rwy, const string& ident, SGGeod& pos, d pos = SGGeod::fromGeodFt(newPos, pos.getElevationFt()); heading = rwy->headingDeg(); } else { - SG_LOG(SG_GENERAL, SG_DEBUG, "localizer:" << ident << ", aligning with runway " + SG_LOG(SG_NAVAID, SG_DEBUG, "localizer:" << ident << ", aligning with runway " << rwy->ident() << " exceeded heading threshold"); } } @@ -107,7 +107,7 @@ static double defaultNavRange(const string& ident, FGPositioned::Type type) // Ranges are included with the latest data format, no need to // assign our own defaults, unless the range is not set for some // reason. - SG_LOG(SG_GENERAL, SG_DEBUG, "navaid " << ident << " has no range set, using defaults"); + SG_LOG(SG_NAVAID, SG_DEBUG, "navaid " << ident << " has no range set, using defaults"); switch (type) { case FGPositioned::NDB: case FGPositioned::VOR: @@ -126,7 +126,7 @@ static double defaultNavRange(const string& ident, FGPositioned::Type type) namespace flightgear { - + static PositionedID readNavFromStream(std::istream& aStream, FGPositioned::Type type = FGPositioned::INVALID) { @@ -164,7 +164,7 @@ static PositionedID readNavFromStream(std::istream& aStream, assert(runway); pos.setElevationFt(runway->geod().getElevationFt()); } - + return cache->insertNavaid(type, string(), name, pos, 0, 0, 0, arp.first, arp.second); } @@ -175,18 +175,49 @@ static PositionedID readNavFromStream(std::istream& aStream, AirportRunwayPair arp; FGRunway* runway = NULL; - - // FIXME - also relate DMEs, but only ILS/LOC DMEs - need a heuristic - // on the DME naming string + PositionedID navaid_dme = 0; + + if (type == FGPositioned::DME) { + FGPositioned::TypeFilter f(FGPositioned::INVALID); + if ( name.find("VOR-DME") != std::string::npos ) { + f.addType(FGPositioned::VOR); + } else if ( name.find("DME-ILS") != std::string::npos ) { + f.addType(FGPositioned::ILS); + f.addType(FGPositioned::LOC); + } else if ( name.find("VORTAC") != std::string::npos ) { + f.addType(FGPositioned::VOR); + } else if ( name.find("NDB-DME") != std::string::npos ) { + f.addType(FGPositioned::NDB); + } else if ( name.find("TACAN") != std::string::npos ) { + f.addType(FGPositioned::VOR); + } + + if (f.maxType() > 0) { + FGPositionedRef ref = FGPositioned::findClosestWithIdent(ident, pos, &f); + if (ref.valid()) { + string_list dme_part = simgear::strutils::split(name , 0 ,1); + string_list navaid_part = simgear::strutils::split(ref.get()->name(), 0 ,1); + + if ( simgear::strutils::uppercase(navaid_part[0]) == simgear::strutils::uppercase(dme_part[0]) ) { + navaid_dme = ref.get()->guid(); + } + } + } + } + if ((type >= FGPositioned::ILS) && (type <= FGPositioned::GS)) { arp = cache->findAirportRunway(name); if (arp.second) { - runway = static_cast(cache->loadById(arp.second)); + runway = FGPositioned::loadById(arp.second); assert(runway); +#if 0 + // code is disabled since it's causing some problems, see + // http://code.google.com/p/flightgear-bugs/issues/detail?id=926 if (elev_ft < 0.01) { // snap to runway elevation pos.setElevationFt(runway->geod().getElevationFt()); } +#endif } // of found runway in the DB } // of type is runway-related @@ -207,6 +238,10 @@ static PositionedID readNavFromStream(std::istream& aStream, if (isLoc) { cache->setRunwayILS(arp.second, r); } + + if (navaid_dme) { + cache->setNavaidColocated(navaid_dme, r); + } return r; } @@ -216,7 +251,7 @@ bool navDBInit(const SGPath& path) { sg_gzifstream in( path.str() ); if ( !in.is_open() ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() ); + SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() ); return false; } @@ -238,11 +273,11 @@ bool navDBInit(const SGPath& path) bool loadCarrierNav(const SGPath& path) { - SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() ); + SG_LOG( SG_NAVAID, SG_INFO, "opening file: " << path.str() ); sg_gzifstream incarrier( path.str() ); if ( !incarrier.is_open() ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() ); + SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() ); return false; } @@ -256,11 +291,11 @@ bool loadCarrierNav(const SGPath& path) bool loadTacan(const SGPath& path, FGTACANList *channellist) { - SG_LOG( SG_GENERAL, SG_INFO, "opening file: " << path.str() ); + SG_LOG( SG_NAVAID, SG_INFO, "opening file: " << path.str() ); sg_gzifstream inchannel( path.str() ); if ( !inchannel.is_open() ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() ); + SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() ); return false; }