#include "PositionedOctree.hxx"
#include <Airports/apt_loader.hxx>
#include <Navaids/airways.hxx>
+#include "poidb.hxx"
#include <Airports/parking.hxx>
#include <Airports/gnnode.hxx>
namespace {
const int MAX_RETRIES = 10;
-const int SCHEMA_VERSION = 7;
+const int SCHEMA_VERSION = 8;
const int CACHE_SIZE_KBYTES= 16000;
// bind a std::string to a sqlite statement. The std::string must live the
" VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)");
runwayLengthFtQuery = prepare("SELECT length_ft FROM runway WHERE rowid=?1");
+ removePOIQuery = prepare("DELETE FROM positioned WHERE type=?1 AND ident=?2");
+
// query statement
findClosestWithIdent = prepare("SELECT rowid FROM positioned WHERE ident=?1 "
AND_TYPED " ORDER BY distanceCartSqr(cart_x, cart_y, cart_z, ?4, ?5, ?6)");
PositionedID reciprocal = sqlite3_column_int64(loadRunwayStmt, 6);
PositionedID ils = sqlite3_column_int64(loadRunwayStmt, 7);
FGRunway* r = new FGRunway(rowId, apt, id, pos, heading, lengthM, widthM,
- displacedThreshold, stopway, surface, false);
+ displacedThreshold, stopway, surface);
if (reciprocal > 0) {
r->setReciprocalRunway(reciprocal);
deferredOctreeUpdates.clear();
}
+
+ void removePositionedWithIdent(FGPositioned::Type ty, const std::string& aIdent)
+ {
+ sqlite3_bind_int(removePOIQuery, 1, ty);
+ sqlite_bind_stdstring(removePOIQuery, 2, aIdent);
+ execUpdate(removePOIQuery);
+ reset(removePOIQuery);
+ }
NavDataCache* outer;
sqlite3* db;
bool transactionAborted;
sqlite3_stmt_ptr beginTransactionStmt, commitTransactionStmt, rollbackTransactionStmt;
- SGPath aptDatPath, metarDatPath, navDatPath, fixDatPath,
+ SGPath aptDatPath, metarDatPath, navDatPath, fixDatPath, poiDatPath,
carrierDatPath, airwayDatPath;
sqlite3_stmt_ptr readPropertyQuery, writePropertyQuery,
insertCommStation, insertNavaid;
sqlite3_stmt_ptr setAirportMetar, setRunwayReciprocal, setRunwayILS,
setAirportPos, updateRunwayThreshold, updateILS;
+ sqlite3_stmt_ptr removePOIQuery;
sqlite3_stmt_ptr findClosestWithIdent;
// octree (spatial index) related queries
return new FGFix(rowid, ident, pos);
case FGPositioned::WAYPOINT:
+ case FGPositioned::COUNTRY:
+ case FGPositioned::CITY:
+ case FGPositioned::TOWN:
+ case FGPositioned::VILLAGE:
{
- FGPositioned* wpt = new FGPositioned(rowid, FGPositioned::WAYPOINT, ident, pos);
+ FGPositioned* wpt = new FGPositioned(rowid, ty, ident, pos);
return wpt;
}
d->fixDatPath = SGPath(globals->get_fg_root());
d->fixDatPath.append("Navaids/fix.dat.gz");
+
+ d->poiDatPath = SGPath(globals->get_fg_root());
+ d->poiDatPath.append("Navaids/poi.dat.gz");
d->carrierDatPath = SGPath(globals->get_fg_root());
d->carrierDatPath.append("Navaids/carrier_nav.dat.gz");
isCachedFileModified(d->metarDatPath) ||
isCachedFileModified(d->navDatPath) ||
isCachedFileModified(d->fixDatPath) ||
+ isCachedFileModified(d->poiDatPath) ||
isCachedFileModified(d->airwayDatPath))
{
SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: main cache rebuild required");
navDBInit(d->navDatPath);
stampCacheFile(d->navDatPath);
SG_LOG(SG_NAVCACHE, SG_INFO, "nav.dat load took:" << st.elapsedMSec());
+
+ st.stamp();
+ poiDBInit(d->poiDatPath);
+ stampCacheFile(d->poiDatPath);
+ SG_LOG(SG_NAVCACHE, SG_INFO, "poi.dat load took:" << st.elapsedMSec());
loadCarrierNav(d->carrierDatPath);
stampCacheFile(d->carrierDatPath);
sqlite3_bind_int64(d->setRunwayILS, 1, runway);
sqlite3_bind_int64(d->setRunwayILS, 2, ils);
d->execUpdate(d->setRunwayILS);
+
+ // and the in-memory one
+ if (d->cache.find(runway) != d->cache.end()) {
+ FGRunway* instance = (FGRunway*) d->cache[runway].ptr();
+ instance->setILS(ils);
+ }
}
void NavDataCache::updateRunwayThreshold(PositionedID runwayID, const SGGeod &aThreshold,
sqlite3_bind_double(d->updateRunwayThreshold, 3, aDisplacedThreshold);
sqlite3_bind_double(d->updateRunwayThreshold, 4, aStopway);
d->execUpdate(d->updateRunwayThreshold);
-
-// compute the new runway center, based on the threshold lat/lon and length,
- double offsetFt = (0.5 * d->runwayLengthFt(runwayID));
- SGGeod newCenter= SGGeodesy::direct(aThreshold, aHeading, offsetFt * SG_FEET_TO_METER);
- newCenter.setElevationM(aThreshold.getElevationM());
-
-// now update the positional data
- updatePosition(runwayID, newCenter);
+
+ // now update the positional data
+ updatePosition(runwayID, aThreshold);
}
PositionedID
return d->insertPositioned(FGPositioned::FIX, ident, string(), aPos, 0, true);
}
-PositionedID NavDataCache::createUserWaypoint(const std::string& ident, const SGGeod& aPos)
+PositionedID NavDataCache::createPOI(FGPositioned::Type ty, const std::string& ident, const SGGeod& aPos)
{
- return d->insertPositioned(FGPositioned::WAYPOINT, ident, string(), aPos, 0,
+ return d->insertPositioned(ty, ident, string(), aPos, 0,
true /* spatial index */);
}
+
+void NavDataCache::removePOI(FGPositioned::Type ty, const std::string& aIdent)
+{
+ d->removePositionedWithIdent(ty, aIdent);
+ // should remove from the live cache too?
+}
void NavDataCache::setAirportMetar(const string& icao, bool hasMetar)
{