X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fnavdb.cxx;h=b1a813d6173f61a4d9ddc1aaa901c9bd5eec24b7;hb=038251e8af6ff9c24afcc08169c2bcca2c5a63c5;hp=95f7f77eef15f1b72d1e4f32cefc360fa9331230;hpb=f9de92f53db91c45e4bd885ba606749e9597fdbb;p=flightgear.git diff --git a/src/Navaids/navdb.cxx b/src/Navaids/navdb.cxx index 95f7f77ee..b1a813d61 100644 --- a/src/Navaids/navdb.cxx +++ b/src/Navaids/navdb.cxx @@ -34,16 +34,24 @@ #include #include #include +#include #include "navrecord.hxx" #include "navlist.hxx" #include "navdb.hxx" -#include "Main/globals.hxx" -#include "Navaids/markerbeacon.hxx" -#include "Airports/simple.hxx" +#include
+#include +#include +#include +#include +#include
using std::string; +typedef std::map AirportPropertyMap; + +static AirportPropertyMap static_airportIlsData; + static FGPositioned::Type mapRobinTypeToFGPType(int aTy) { @@ -51,8 +59,8 @@ mapRobinTypeToFGPType(int aTy) // case 1: case 2: return FGPositioned::NDB; case 3: return FGPositioned::VOR; - case 4: return FGPositioned::LOC; - case 5: return FGPositioned::ILS; + case 4: return FGPositioned::ILS; + case 5: return FGPositioned::LOC; case 6: return FGPositioned::GS; case 12: case 13: return FGPositioned::DME; @@ -223,9 +231,62 @@ bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist, // end ReadChanFile + // flush all the parsed ils.xml data, we don't need it anymore, + // since it's been meregd into the FGNavRecords + static_airportIlsData.clear(); + return true; } +SGPropertyNode* ilsDataForRunwayAndNavaid(FGRunway* aRunway, const std::string& aNavIdent) +{ + if (!fgGetBool("/sim/paths/use-custom-scenery-data")) { + return NULL; + } + + if (!aRunway) { + return NULL; + } + + FGAirport* apt = aRunway->airport(); +// find (or load) the airprot ILS data + AirportPropertyMap::iterator it = static_airportIlsData.find(apt); + if (it == static_airportIlsData.end()) { + SGPath path; + if (!XMLLoader::findAirportData(apt->ident(), "ils", path)) { + // no ils.xml file for this airpot, insert a NULL entry so we don't + // check again + static_airportIlsData.insert(it, std::make_pair(apt, SGPropertyNode_ptr())); + return NULL; + } + + SGPropertyNode_ptr rootNode = new SGPropertyNode; + readProperties(path.str(), rootNode); + it = static_airportIlsData.insert(it, std::make_pair(apt, rootNode)); + } // of ils.xml file not loaded + + if (!it->second) { + return NULL; + } + +// find the entry matching the runway + SGPropertyNode* runwayNode, *ilsNode; + for (int i=0; (runwayNode = it->second->getChild("runway", i)) != NULL; ++i) { + for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) { + // must match on both nav-ident and runway ident, to support the following: + // - runways with multiple distinct ILS installations (KEWD, for example) + // - runways where both ends share the same nav ident (LFAT, for example) + if ((ilsNode->getStringValue("nav-id") == aNavIdent) && + (ilsNode->getStringValue("rwy") == aRunway->ident())) + { + return ilsNode; + } + } // of ILS iteration + } // of runway iteration + + return NULL; +} + FGRunway* getRunwayFromName(const std::string& aName) { vector parts = simgear::strutils::split(aName); @@ -236,15 +297,14 @@ FGRunway* getRunwayFromName(const std::string& aName) const FGAirport* apt = fgFindAirportID(parts[0]); if (!apt) { - SG_LOG(SG_GENERAL, SG_WARN, "navaid " << aName << " associated with bogus airport ID:" << parts[0]); + SG_LOG(SG_GENERAL, SG_DEBUG, "navaid " << aName << " associated with bogus airport ID:" << parts[0]); return NULL; } - FGRunway* runway = apt->getRunwayByIdent(parts[1]); - if (!runway) { - SG_LOG(SG_GENERAL, SG_WARN, "navaid " << aName << " associated with bogus runway ID:" << parts[1]); + if (!apt->hasRunwayWithIdent(parts[1])) { + SG_LOG(SG_GENERAL, SG_DEBUG, "navaid " << aName << " associated with bogus runway ID:" << parts[1]); return NULL; } - return runway; + return apt->getRunwayByIdent(parts[1]); }