]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/NavDataCache.cxx
ICAO.threshold.xml works read-only.
[flightgear.git] / src / Navaids / NavDataCache.cxx
index 80422483d2d2130cd2be74501bce8734f14418c8..1772de951e85d0475f56f2a076c24cc09b164a5b 100644 (file)
@@ -474,7 +474,6 @@ public:
     setRunwayReciprocal = prepare("UPDATE runway SET reciprocal=?2 WHERE rowid=?1");
     setRunwayILS = prepare("UPDATE runway SET ils=?2 WHERE rowid=?1");
     setNavaidColocated = prepare("UPDATE navaid SET colocated=?2 WHERE rowid=?1");
-    updateRunwayThreshold = prepare("UPDATE runway SET heading=?2, displaced_threshold=?3, stopway=?4 WHERE rowid=?1");
     
     insertPositionedQuery = prepare("INSERT INTO positioned "
                                     "(type, ident, name, airport, lon, lat, elev_m, octree_node, "
@@ -536,6 +535,11 @@ public:
     sqlite3_bind_int(searchAirports, 2, FGPositioned::AIRPORT);
     sqlite3_bind_int(searchAirports, 3, FGPositioned::SEAPORT);
     
+    getAllAirports = prepare("SELECT ident, name FROM positioned WHERE type>=?1 AND type <=?2");
+    sqlite3_bind_int(getAllAirports, 1, FGPositioned::AIRPORT);
+    sqlite3_bind_int(getAllAirports, 2, FGPositioned::SEAPORT);
+
+    
     getAirportItemByIdent = prepare("SELECT rowid FROM positioned WHERE airport=?1 AND ident=?2 AND type=?3");
     
     findAirportRunway = prepare("SELECT airport, rowid FROM positioned WHERE ident=?2 AND type=?3 AND airport="
@@ -711,10 +715,15 @@ public:
     PositionedID colocated = sqlite3_column_int64(loadNavaid, 4);
     reset(loadNavaid);
 
-    FGNavRecord* n = new FGNavRecord(rowId, ty, id, name, pos, freq, rangeNm, mulituse, runway);
-    if (colocated) {
-        n->setColocatedDME(colocated);
-    }
+    FGNavRecord* n =
+      (ty == FGPositioned::MOBILE_TACAN)
+      ? new FGMobileNavRecord
+            (rowId, ty, id, name, pos, freq, rangeNm, mulituse, runway)
+      : new FGNavRecord
+            (rowId, ty, id, name, pos, freq, rangeNm, mulituse, runway);
+
+    if (colocated)
+      n->setColocatedDME(colocated);
 
     return n;
   }
@@ -889,7 +898,7 @@ public:
   sqlite3_stmt_ptr insertPositionedQuery, insertAirport, insertTower, insertRunway,
   insertCommStation, insertNavaid;
   sqlite3_stmt_ptr setAirportMetar, setRunwayReciprocal, setRunwayILS, setNavaidColocated,
-    setAirportPos, updateRunwayThreshold, updateILS;
+    setAirportPos, updateILS;
   sqlite3_stmt_ptr removePOIQuery;
   
   sqlite3_stmt_ptr findClosestWithIdent;
@@ -897,7 +906,7 @@ public:
   sqlite3_stmt_ptr getOctreeChildren, insertOctree, updateOctreeChildren,
     getOctreeLeafChildren;
 
-  sqlite3_stmt_ptr searchAirports;
+  sqlite3_stmt_ptr searchAirports, getAllAirports;
   sqlite3_stmt_ptr findCommByFreq, findNavsByFreq,
   findNavsByFreqNoPos, findNavaidForRunway;
   sqlite3_stmt_ptr getAirportItems, getAirportItemByIdent;
@@ -942,6 +951,7 @@ FGPositioned* NavDataCache::NavDataCachePrivate::loadById(sqlite3_int64 rowid)
   assert(rowid == sqlite3_column_int64(loadPositioned, 0));
   FGPositioned::Type ty = (FGPositioned::Type) sqlite3_column_int(loadPositioned, 1);
   
+  PositionedID prowid = static_cast<PositionedID>(rowid);
   string ident = (char*) sqlite3_column_text(loadPositioned, 2);
   string name = (char*) sqlite3_column_text(loadPositioned, 3);
   sqlite3_int64 aptId = sqlite3_column_int64(loadPositioned, 4);
@@ -959,7 +969,7 @@ FGPositioned* NavDataCache::NavDataCachePrivate::loadById(sqlite3_int64 rowid)
       return loadAirport(rowid, ty, ident, name, pos);
       
     case FGPositioned::TOWER:
-      return new AirportTower(rowid, aptId, ident, pos);
+      return new AirportTower(prowid, aptId, ident, pos);
       
     case FGPositioned::RUNWAY:
     case FGPositioned::HELIPAD:
@@ -1118,6 +1128,7 @@ bool NavDataCache::isRebuildRequired()
   if (isCachedFileModified(d->aptDatPath) ||
       isCachedFileModified(d->metarDatPath) ||
       isCachedFileModified(d->navDatPath) ||
+      isCachedFileModified(d->carrierDatPath) ||
       isCachedFileModified(d->fixDatPath) ||
 // since POI loading is disabled on Windows, don't check for it
 // this caused: https://code.google.com/p/flightgear-bugs/issues/detail?id=1227
@@ -1554,21 +1565,6 @@ void NavDataCache::setRunwayILS(PositionedID runway, PositionedID ils)
   }
 }
   
-void NavDataCache::updateRunwayThreshold(PositionedID runwayID, const SGGeod &aThreshold,
-                                  double aHeading, double aDisplacedThreshold,
-                                  double aStopway)
-{
-// update the runway information
-  sqlite3_bind_int64(d->updateRunwayThreshold, 1, runwayID);
-  sqlite3_bind_double(d->updateRunwayThreshold, 2, aHeading);
-  sqlite3_bind_double(d->updateRunwayThreshold, 3, aDisplacedThreshold);
-  sqlite3_bind_double(d->updateRunwayThreshold, 4, aStopway);
-  d->execUpdate(d->updateRunwayThreshold);
-
-  // now update the positional data
-  updatePosition(runwayID, aThreshold);
-}
-  
 PositionedID
 NavDataCache::insertNavaid(FGPositioned::Type ty, const string& ident,
                           const string& name, const SGGeod& pos,
@@ -1755,13 +1751,19 @@ NavDataCache::getOctreeLeafChildren(int64_t octreeNodeId)
  */
 char** NavDataCache::searchAirportNamesAndIdents(const std::string& aFilter)
 {
-  string s = "%" + aFilter + "%";
-  sqlite_bind_stdstring(d->searchAirports, 1, s);
-  
+  sqlite3_stmt_ptr stmt;
   unsigned int numMatches = 0, numAllocated = 16;
-  char** result = (char**) malloc(sizeof(char*) * numAllocated);
+  if (aFilter.empty()) {
+    stmt = d->getAllAirports;
+    numAllocated = 4096; // start much larger for all airports
+  } else {
+    stmt = d->searchAirports;
+    string s = "%" + aFilter + "%";
+    sqlite_bind_stdstring(stmt, 1, s);
+  }
   
-  while (d->stepSelect(d->searchAirports)) {
+  char** result = (char**) malloc(sizeof(char*) * numAllocated);
+  while (d->stepSelect(stmt)) {
     if ((numMatches + 1) >= numAllocated) {
       numAllocated <<= 1; // double in size!
     // reallocate results array
@@ -1779,18 +1781,18 @@ char** NavDataCache::searchAirportNamesAndIdents(const std::string& aFilter)
     // which gives a grand total of 7 + name-length + icao-length.
     // note the ident can be three letters (non-ICAO local strip), four
     // (default ICAO) or more (extended format ICAO)
-    int nameLength = sqlite3_column_bytes(d->searchAirports, 1);
-    int icaoLength = sqlite3_column_bytes(d->searchAirports, 0);
+    int nameLength = sqlite3_column_bytes(stmt, 1);
+    int icaoLength = sqlite3_column_bytes(stmt, 0);
     char* entry = (char*) malloc(7 + nameLength + icaoLength);
     char* dst = entry;
     *dst++ = ' ';
-    memcpy(dst, sqlite3_column_text(d->searchAirports, 1), nameLength);
+    memcpy(dst, sqlite3_column_text(stmt, 1), nameLength);
     dst += nameLength;
     *dst++ = ' ';
     *dst++ = ' ';
     *dst++ = ' ';
     *dst++ = '(';
-    memcpy(dst, sqlite3_column_text(d->searchAirports, 0), icaoLength);
+    memcpy(dst, sqlite3_column_text(stmt, 0), icaoLength);
     dst += icaoLength;
     *dst++ = ')';
     *dst++ = 0;
@@ -1799,7 +1801,7 @@ char** NavDataCache::searchAirportNamesAndIdents(const std::string& aFilter)
   }
   
   result[numMatches] = NULL; // end of list marker
-  d->reset(d->searchAirports);
+  d->reset(stmt);
   return result;
 }