+ elevM = twrNode->getDoubleValue("elev-m");
+// tower elevation is AGL, not AMSL. Since we don't want to depend on the
+// scenery for a precise terrain elevation, we use the field elevation
+// (this is also what the apt.dat code does)
+ double fieldElevationM = geod().getElevationM();
+ SGGeod towerLocation(SGGeod::fromDegM(lon, lat, fieldElevationM + elevM));
+
+ NavDataCache* cache = NavDataCache::instance();
+ PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
+ if (towers.empty()) {
+ cache->insertTower(guid(), towerLocation);
+ } else {
+ // update the position
+ cache->updatePosition(towers.front(), towerLocation);
+ }
+}
+
+bool FGAirport::validateILSData()
+{
+ if (mILSDataLoaded) {
+ return false;
+ }
+
+ mILSDataLoaded = true;
+ NavDataCache* cache = NavDataCache::instance();
+ SGPath path;
+ if (!XMLLoader::findAirportData(ident(), "ils", path)) {
+ return false; // no XML tower data
+ }
+
+ if (!cache->isCachedFileModified(path)) {
+ // cached values are correct, we're all done
+ return false;
+ }
+
+ SGPropertyNode_ptr rootNode = new SGPropertyNode;
+ readProperties(path.str(), rootNode);
+ readILSData(rootNode);
+ cache->stampCacheFile(path);
+
+// we loaded data, tell the caller it might need to reload things
+ return true;
+}
+
+void FGAirport::readILSData(SGPropertyNode* aRoot)
+{
+ NavDataCache* cache = NavDataCache::instance();
+
+ // find the entry matching the runway
+ SGPropertyNode* runwayNode, *ilsNode;
+ for (int i=0; (runwayNode = aRoot->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)
+ PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
+ ilsNode->getStringValue("nav-id"));
+ if (ils == 0) {
+ SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
+ ", couldn;t find runway/navaid for:" <<
+ ilsNode->getStringValue("rwy") << "/" <<
+ ilsNode->getStringValue("nav-id"));
+ continue;
+ }
+
+ double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
+ lon = ilsNode->getDoubleValue("lon"),
+ lat = ilsNode->getDoubleValue("lat"),
+ elevM = ilsNode->getDoubleValue("elev-m");
+
+ cache->updateILS(ils, SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
+ } // of ILS iteration
+ } // of runway iteration
+}
+
+void FGAirport::addSID(flightgear::SID* aSid)
+{
+ mSIDs.push_back(aSid);
+}
+
+void FGAirport::addSTAR(STAR* aStar)
+{
+ mSTARs.push_back(aStar);
+}
+
+void FGAirport::addApproach(Approach* aApp)
+{
+ mApproaches.push_back(aApp);
+}
+
+unsigned int FGAirport::numSIDs() const
+{
+ loadProcedures();
+ return mSIDs.size();
+}
+
+flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
+{
+ loadProcedures();
+ return mSIDs[aIndex];
+}
+
+flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
+{
+ loadProcedures();
+ for (unsigned int i=0; i<mSIDs.size(); ++i) {
+ if (mSIDs[i]->ident() == aIdent) {
+ return mSIDs[i];
+ }
+ }
+
+ return NULL;
+}
+
+unsigned int FGAirport::numSTARs() const
+{
+ loadProcedures();
+ return mSTARs.size();
+}
+
+STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
+{
+ loadProcedures();
+ return mSTARs[aIndex];
+}
+
+STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
+{
+ loadProcedures();
+ for (unsigned int i=0; i<mSTARs.size(); ++i) {
+ if (mSTARs[i]->ident() == aIdent) {
+ return mSTARs[i];
+ }
+ }
+
+ return NULL;
+}
+
+unsigned int FGAirport::numApproaches() const
+{
+ loadProcedures();
+ return mApproaches.size();
+}
+
+Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
+{
+ loadProcedures();
+ return mApproaches[aIndex];
+}
+
+Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
+{
+ loadProcedures();
+ for (unsigned int i=0; i<mApproaches.size(); ++i) {
+ if (mApproaches[i]->ident() == aIdent) {
+ return mApproaches[i];
+ }
+ }
+
+ return NULL;
+}
+
+CommStationList
+FGAirport::commStations() const
+{
+ NavDataCache* cache = NavDataCache::instance();
+ CommStationList result;
+ BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
+ FGPositioned::FREQ_GROUND,
+ FGPositioned::FREQ_UNICOM))
+ {
+ result.push_back((CommStation*) cache->loadById(pos));
+ }
+
+ return result;
+}
+
+CommStationList
+FGAirport::commStationsOfType(FGPositioned::Type aTy) const
+{
+ NavDataCache* cache = NavDataCache::instance();
+ CommStationList result;
+ BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
+ result.push_back((CommStation*) cache->loadById(pos));
+ }
+
+ return result;