]> git.mxchange.org Git - flightgear.git/commitdiff
ICAO.twr.xml works in read-only mode.
authorJames Turner <zakalawe@mac.com>
Fri, 21 Feb 2014 18:11:09 +0000 (10:11 -0800)
committerJames Turner <zakalawe@mac.com>
Wed, 12 Mar 2014 09:50:39 +0000 (09:50 +0000)
src/Airports/airport.cxx
src/Airports/airport.hxx

index 9d07d6b997ad2b78dcb60ab1147bcbf46a1c5b5b..62515f05d800ba4350e559557620c98459d20a0d 100644 (file)
@@ -630,16 +630,7 @@ void FGAirport::processThreshold(SGPropertyNode* aThreshold)
 SGGeod FGAirport::getTowerLocation() const
 {
   validateTowerData();
-  
-  NavDataCache* cache = NavDataCache::instance();
-  PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
-  if (towers.empty()) {
-    SG_LOG(SG_GENERAL, SG_ALERT, "No towers defined for:" <<ident());
-    return SGGeod();
-  }
-  
-  FGPositionedRef tower = cache->loadById(towers.front());
-  return tower->geod();
+  return mTowerPosition;
 }
 
 void FGAirport::validateTowerData() const
@@ -647,33 +638,34 @@ void FGAirport::validateTowerData() const
   if (mTowerDataLoaded) {
     return;
   }
-
+  
   mTowerDataLoaded = true;
+
+// first, load data from the cache (apt.dat)
   NavDataCache* cache = NavDataCache::instance();
-    if (cache->isReadOnly()) {
-        return;
-    }
-    
+  PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
+  if (towers.empty()) {
+    SG_LOG(SG_GENERAL, SG_ALERT, "No towers defined for:" <<ident());
+    mTowerPosition = geod(); // use airport position
+    // increase tower elevation by 20 metres above the field elevation
+    mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
+  } else {
+    FGPositionedRef tower = cache->loadById(towers.front());
+    mTowerPosition = tower->geod();
+  }
+  
   SGPath path;
   if (!XMLLoader::findAirportData(ident(), "twr", path)) {
-    return; // no XML tower data
+    return; // no XML tower data, base position is fine
   }
   
-  if (!cache->isCachedFileModified(path)) {
-  // cached values are correct, we're all done
-    return;
+  try {
+    SGPropertyNode_ptr rootNode = new SGPropertyNode;
+    readProperties(path.str(), rootNode);
+    const_cast<FGAirport*>(this)->readTowerData(rootNode);
+  } catch (sg_exception& e){
+    SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
   }
-
-    try {
-        flightgear::NavDataCache::Transaction txn(cache);
-        SGPropertyNode_ptr rootNode = new SGPropertyNode;
-        readProperties(path.str(), rootNode);
-        const_cast<FGAirport*>(this)->readTowerData(rootNode);
-        cache->stampCacheFile(path);
-        txn.commit();
-    } catch (sg_exception& e){
-        SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
-    }
 }
 
 void FGAirport::readTowerData(SGPropertyNode* aRoot)
@@ -685,17 +677,8 @@ void FGAirport::readTowerData(SGPropertyNode* aRoot)
 // 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 = elevationM();
-  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);
-  }
+  double fieldElevationM = geod().getElevationM();
+  mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
 }
 
 bool FGAirport::validateILSData()
index 8301069802ea1a6f6e9c4a987acd5d06838614cf..ce026fe25ab7dc5ce6d9d46e06282d7294f3b67b 100644 (file)
@@ -314,6 +314,8 @@ private:
     void loadProcedures() const;
     
     mutable bool mTowerDataLoaded;
+    mutable SGGeod mTowerPosition;
+  
     mutable bool mRunwaysLoaded;
     mutable bool mHelipadsLoaded;
     mutable bool mTaxiwaysLoaded;