#include <Navaids/waypoint.hxx>
#include <ATC/CommStation.hxx>
#include <Navaids/NavDataCache.hxx>
+#include <Navaids/navrecord.hxx>
using std::vector;
using std::pair;
mHelipadsLoaded(false),
mTaxiwaysLoaded(false),
mProceduresLoaded(false),
+ mThresholdDataLoaded(false),
mILSDataLoaded(false)
{
}
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
return; // already loaded, great
}
- 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;
- }
-
+ if (mThresholdDataLoaded) {
+ return;
+ }
+
+ mThresholdDataLoaded = true;
+
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
mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
}
-bool FGAirport::validateILSData()
+void FGAirport::validateILSData()
{
if (mILSDataLoaded) {
- return false;
+ return;
}
+ // to avoid re-entrancy on this code-path, ensure we set loaded
+ // immediately.
mILSDataLoaded = true;
- NavDataCache* cache = NavDataCache::instance();
- if (cache->isReadOnly()) {
- return false;
- }
SGPath path;
if (!XMLLoader::findAirportData(ident(), "ils", path)) {
- return false; // no XML tower data
+ return; // no XML tower data
}
- if (!cache->isCachedFileModified(path)) {
- // cached values are correct, we're all done
- return false;
+ try {
+ SGPropertyNode_ptr rootNode = new SGPropertyNode;
+ readProperties(path.str(), rootNode);
+ readILSData(rootNode);
+ } catch (sg_exception& e){
+ SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
}
-
- try {
- SGPropertyNode_ptr rootNode = new SGPropertyNode;
- readProperties(path.str(), rootNode);
-
- flightgear::NavDataCache::Transaction txn(cache);
- readILSData(rootNode);
- cache->stampCacheFile(path);
- txn.commit();
-// we loaded data, tell the caller it might need to reload things
- return true;
- } catch (sg_exception& e){
- SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
- }
-
- return false;
}
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) {
ilsNode->getStringValue("nav-id"));
if (ils == 0) {
SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
- ", couldn;t find runway/navaid for:" <<
+ ", couldn't find runway/navaid for:" <<
ilsNode->getStringValue("rwy") << "/" <<
ilsNode->getStringValue("nav-id"));
continue;
lat = ilsNode->getDoubleValue("lat"),
elevM = ilsNode->getDoubleValue("elev-m");
- cache->updateILS(ils, SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
+ FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
+ assert(nav.valid());
+ nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
} // of ILS iteration
} // of runway iteration
}