FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
{
loadRunways();
- return loadById<FGRunway>(mRunways, aIndex);
+ return mRunways.at(aIndex);
}
//------------------------------------------------------------------------------
double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
- BOOST_FOREACH(PositionedID id, mRunways)
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways)
{
- FGRunway* rwy = loadById<FGRunway>(id);
-
// ignore unusably short runways
// TODO other methods don't check this...
if( rwy->lengthFt() >= minLengthFt )
//------------------------------------------------------------------------------
bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
{
- return flightgear::NavDataCache::instance()
- ->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent) != 0;
+ loadRunways();
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
+ if (rwy->ident() == aIdent) {
+ return true;
+ }
+ }
+
+ return false;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
{
- PositionedID id =
- flightgear::NavDataCache::instance()
- ->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent);
-
- if (id == 0) {
- SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
- throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
+ loadRunways();
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
+ if (rwy->ident() == aIdent) {
+ return rwy;
+ }
}
- return loadById<FGRunway>(id);
+ SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
+ throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
}
//------------------------------------------------------------------------------
fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
}
- BOOST_FOREACH(PositionedID id, mRunways) {
- FGRunway* rwy = loadById<FGRunway>(id);
- // bug http://code.google.com/p/flightgear-bugs/issues/detail?id=1149
- // (and probably some other issues besides).
- if (rwy->type() == FGPositioned::HELIPAD) {
- continue;
- }
-
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
double dev = aHeading - rwy->headingDeg();
SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
FGRunway* result = NULL;
double currentLowestDev = 180.0;
- BOOST_FOREACH(PositionedID id, mRunways) {
- FGRunway* rwy = loadById<FGRunway>(id);
-
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
double dev = inboundCourse - rwy->headingDeg();
SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
{
loadRunways();
- BOOST_FOREACH(PositionedID id, mRunways) {
- FGRunway* rwy = loadById<FGRunway>(id);
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
return true; // we're done!
}
FGRunwayList r;
- BOOST_FOREACH(PositionedID id, mRunways) {
- FGRunway* rwy = loadById<FGRunway>(id);
+ BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
FGRunway* recip = rwy->reciprocalRunway();
if (recip) {
FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
return FGAirport::findByIdent(id);
}
+PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
+{
+ flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
+ return cache->airportItemsOfType(guid(), ty);
+}
+
void FGAirport::loadRunways() const
{
if (mRunwaysLoaded) {
loadSceneryDefinitions();
mRunwaysLoaded = true;
- mRunways = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::RUNWAY);
+ PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
+ BOOST_FOREACH(PositionedID id, rwys) {
+ mRunways.push_back(loadById<FGRunway>(id));
+ }
}
void FGAirport::loadHelipads() const
loadSceneryDefinitions();
mHelipadsLoaded = true;
- mHelipads = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::HELIPAD);
+ mHelipads = itemsOfType(FGPositioned::HELIPAD);
}
void FGAirport::loadTaxiways() const
}
mTaxiwaysLoaded = true;
- mTaxiways = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::TAXIWAY);
+ mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
}
void FGAirport::loadProcedures() const
void FGAirport::loadSceneryDefinitions() const
{
- NavDataCache* cache = NavDataCache::instance();
- if (cache->isReadOnly()) {
- return;
- }
-
SGPath path;
if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
return; // no XML threshold data
}
- 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)->readThresholdData(rootNode);
+ } catch (sg_exception& e) {
+ SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
}
-
- try {
- flightgear::NavDataCache::Transaction txn(cache);
- SGPropertyNode_ptr rootNode = new SGPropertyNode;
- readProperties(path.str(), rootNode);
- const_cast<FGAirport*>(this)->readThresholdData(rootNode);
- cache->stampCacheFile(path);
- txn.commit();
- } catch (sg_exception& e) {
- SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
- }
}
void FGAirport::readThresholdData(SGPropertyNode* aRoot)
std::string rwyIdent(aThreshold->getStringValue("rwy"));
NavDataCache* cache = NavDataCache::instance();
PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
- if (id == 0) {
- SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
- "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
- return;
- }
double lon = aThreshold->getDoubleValue("lon"),
lat = aThreshold->getDoubleValue("lat");
double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
double newStopway = aThreshold->getDoubleValue("stopw-m");
- cache->updateRunwayThreshold(id, newThreshold,
- newHeading, newDisplacedThreshold, newStopway);
+ if (id == 0) {
+ SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
+ "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
+ // enable this code when threshold.xml contains sufficient data to
+ // fully specify a new runway, *and* we figure out how to assign runtime
+ // Positioned IDs and insert temporary items into the spatial map.
+#if 0
+ double newLength = 0.0, newWidth = 0.0;
+ int surfaceCode = 0;
+ FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
+ newHeading,
+ newLength, newWidth,
+ newDisplacedThreshold, newStopway,
+ surfaceCode);
+ // insert into the spatial map too
+ mRunways.push_back(rwy);
+#endif
+ } else {
+ FGRunway* rwy = loadById<FGRunway>(id);
+ rwy->updateThreshold(newThreshold, newHeading,
+ newDisplacedThreshold, newStopway);
+
+ }
}
SGGeod FGAirport::getTowerLocation() const
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, "
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;
}
}
-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,