2 // simple.cxx -- a really simplistic class to manage airport ID,
3 // lat, lon of the center of one of it's runways, and
6 // Written by Curtis Olson, started April 1998.
7 // Updated by Durk Talsma, started December, 2004.
9 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include "airport.hxx"
35 #include <boost/foreach.hpp>
37 #include <simgear/misc/sg_path.hxx>
38 #include <simgear/props/props.hxx>
39 #include <simgear/props/props_io.hxx>
40 #include <simgear/debug/logstream.hxx>
41 #include <simgear/sg_inlines.h>
42 #include <simgear/structure/exception.hxx>
44 #include <Environment/environment_mgr.hxx>
45 #include <Environment/environment.hxx>
46 #include <Main/fg_props.hxx>
47 #include <Airports/runways.hxx>
48 #include <Airports/pavement.hxx>
49 #include <Airports/xmlloader.hxx>
50 #include <Airports/dynamics.hxx>
51 #include <Airports/airportdynamicsmanager.hxx>
52 #include <Navaids/procedure.hxx>
53 #include <Navaids/waypoint.hxx>
54 #include <ATC/CommStation.hxx>
55 #include <Navaids/NavDataCache.hxx>
56 #include <Navaids/navrecord.hxx>
61 using namespace flightgear;
63 /***************************************************************************
65 ***************************************************************************/
67 AirportCache FGAirport::airportCache;
69 FGAirport::FGAirport( PositionedID aGuid,
70 const std::string &id,
71 const SGGeod& location,
72 const std::string &name,
75 FGPositioned(aGuid, aType, id, location),
77 _has_metar(has_metar),
78 mTowerDataLoaded(false),
80 mRunwaysLoaded(false),
81 mHelipadsLoaded(false),
82 mTaxiwaysLoaded(false),
83 mProceduresLoaded(false),
84 mThresholdDataLoaded(false),
87 mIsClosed = (name.find("[x]") != std::string::npos);
91 FGAirport::~FGAirport()
95 bool FGAirport::isAirport() const
97 return type() == AIRPORT;
100 bool FGAirport::isSeaport() const
102 return type() == SEAPORT;
105 bool FGAirport::isHeliport() const
107 return type() == HELIPORT;
110 bool FGAirport::isAirportType(FGPositioned* pos)
116 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
119 //------------------------------------------------------------------------------
120 unsigned int FGAirport::numRunways() const
123 return mRunways.size();
126 //------------------------------------------------------------------------------
127 unsigned int FGAirport::numHelipads() const
130 return mHelipads.size();
133 //------------------------------------------------------------------------------
134 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
137 return mRunways.at(aIndex);
140 //------------------------------------------------------------------------------
141 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
144 return loadById<FGHelipad>(mHelipads, aIndex);
147 //------------------------------------------------------------------------------
148 FGRunwayMap FGAirport::getRunwayMap() const
153 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
155 BOOST_FOREACH(FGRunwayRef rwy, mRunways)
157 // ignore unusably short runways
158 // TODO other methods don't check this...
159 if( rwy->lengthFt() >= minLengthFt )
160 map[ rwy->ident() ] = rwy;
166 //------------------------------------------------------------------------------
167 FGHelipadMap FGAirport::getHelipadMap() const
172 BOOST_FOREACH(PositionedID id, mHelipads)
174 FGHelipad* rwy = loadById<FGHelipad>(id);
175 map[ rwy->ident() ] = rwy;
181 //------------------------------------------------------------------------------
182 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
185 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
186 if (rwy->ident() == aIdent) {
194 //------------------------------------------------------------------------------
195 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
197 return flightgear::NavDataCache::instance()
198 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
201 //------------------------------------------------------------------------------
202 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
205 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
206 if (rwy->ident() == aIdent) {
211 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
212 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
215 //------------------------------------------------------------------------------
216 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
218 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
220 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
221 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
224 return loadById<FGHelipad>(id);
227 //------------------------------------------------------------------------------
228 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
232 FGRunway* result = NULL;
233 double currentBestQuality = 0.0;
235 struct FindBestRunwayForHeadingParams fbrfhp;
236 if( NULL != parms ) fbrfhp = *parms;
238 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
239 if( searchNode.valid() ) {
240 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
241 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
242 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
243 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
244 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
247 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
248 double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
249 double dev = aHeading - rwy->headingDeg();
250 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
251 double bad = fabs( fbrfhp.deviationWeight * dev) + 1e-20;
252 double quality = good / bad;
254 if (quality > currentBestQuality) {
255 currentBestQuality = quality;
263 //------------------------------------------------------------------------------
264 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
268 FGRunway* result = NULL;
269 double currentLowestDev = 180.0;
271 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
272 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
273 double dev = inboundCourse - rwy->headingDeg();
274 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
277 if (dev < currentLowestDev) { // new best match
278 currentLowestDev = dev;
281 } // of runway iteration
287 //------------------------------------------------------------------------------
288 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
292 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
293 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
294 return true; // we're done!
296 } // of runways iteration
301 FGRunwayRef FGAirport::longestRunway() const
306 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
307 if (!r || (r->lengthFt() < rwy->lengthFt())) {
310 } // of runways iteration
315 //------------------------------------------------------------------------------
316 FGRunwayList FGAirport::getRunways() const
323 //------------------------------------------------------------------------------
324 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
330 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
331 FGRunway* recip = rwy->reciprocalRunway();
333 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
335 continue; // reciprocal already in result set, don't include us
345 //------------------------------------------------------------------------------
346 unsigned int FGAirport::numTaxiways() const
349 return mTaxiways.size();
352 //------------------------------------------------------------------------------
353 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
356 return loadById<FGTaxiway>(mTaxiways, aIndex);
359 //------------------------------------------------------------------------------
360 FGTaxiwayList FGAirport::getTaxiways() const
363 return loadAllById<FGTaxiway>(mTaxiways);
366 //------------------------------------------------------------------------------
367 unsigned int FGAirport::numPavements() const
370 return mPavements.size();
373 //------------------------------------------------------------------------------
374 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
377 return loadById<FGPavement>(mPavements, aIndex);
380 //------------------------------------------------------------------------------
381 FGPavementList FGAirport::getPavements() const
384 return loadAllById<FGPavement>(mPavements);
387 //------------------------------------------------------------------------------
388 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
390 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
392 // This forces West-facing rwys to be used in no-wind situations
393 // which is consistent with Flightgear's initial setup.
397 FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
399 double windSpeed = stationWeather.get_wind_speed_kt();
400 if (windSpeed > 0.0) {
401 hdg = stationWeather.get_wind_from_heading_deg();
405 return findBestRunwayForHeading(hdg);
408 //------------------------------------------------------------------------------
409 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
413 AirportFilter aptFilter;
417 return static_pointer_cast<FGAirport>
419 FGPositioned::findClosest(aPos, aCuttofNm, filter)
423 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
424 mMinLengthFt(minLengthFt)
426 if (minLengthFt < 0.0) {
427 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
431 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
433 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
436 //------------------------------------------------------------------------------
437 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
438 _type(FGPositioned::AIRPORT),
439 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
444 //------------------------------------------------------------------------------
445 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
447 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
448 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
449 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
455 //------------------------------------------------------------------------------
456 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
458 FGAirport* apt = static_cast<FGAirport*>(pos);
459 if( (apt->type() == FGPositioned::AIRPORT)
460 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
467 //------------------------------------------------------------------------------
468 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
470 AirportCache::iterator it = airportCache.find(aIdent);
471 if (it != airportCache.end())
475 FGAirportRef r = static_pointer_cast<FGAirport>
477 FGPositioned::findFirstWithIdent(aIdent, &filter)
480 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
481 airportCache[aIdent] = r;
483 // we don't warn here when r==NULL, let the caller do that
487 //------------------------------------------------------------------------------
488 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
490 FGAirportRef r = findByIdent(aIdent);
492 throw sg_range_exception("No such airport with ident: " + aIdent);
496 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
498 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
501 // find basic airport location info from airport database
502 const FGAirport *fgFindAirportID( const std::string& id)
508 return FGAirport::findByIdent(id);
511 PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
513 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
514 return cache->airportItemsOfType(guid(), ty);
517 void FGAirport::loadRunways() const
519 if (mRunwaysLoaded) {
520 return; // already loaded, great
523 loadSceneryDefinitions();
525 mRunwaysLoaded = true;
526 PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
527 BOOST_FOREACH(PositionedID id, rwys) {
528 mRunways.push_back(loadById<FGRunway>(id));
532 void FGAirport::loadHelipads() const
534 if (mHelipadsLoaded) {
535 return; // already loaded, great
538 mHelipadsLoaded = true;
539 mHelipads = itemsOfType(FGPositioned::HELIPAD);
542 void FGAirport::loadTaxiways() const
544 if (mTaxiwaysLoaded) {
545 return; // already loaded, great
548 mTaxiwaysLoaded = true;
549 mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
552 void FGAirport::loadProcedures() const
554 if (mProceduresLoaded) {
558 mProceduresLoaded = true;
560 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
561 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
565 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
566 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
569 void FGAirport::loadSceneryDefinitions() const
571 if (mThresholdDataLoaded) {
575 mThresholdDataLoaded = true;
578 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
579 return; // no XML threshold data
583 SGPropertyNode_ptr rootNode = new SGPropertyNode;
584 readProperties(path.str(), rootNode);
585 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
586 } catch (sg_exception& e) {
587 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
591 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
593 SGPropertyNode* runway;
595 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
596 SGPropertyNode* t0 = runway->getChild("threshold", 0),
597 *t1 = runway->getChild("threshold", 1);
599 assert(t1); // too strict? maybe we should finally allow single-ended runways
601 processThreshold(t0);
602 processThreshold(t1);
603 } // of runways iteration
606 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
608 // first, let's identify the current runway
609 std::string rwyIdent(aThreshold->getStringValue("rwy"));
610 NavDataCache* cache = NavDataCache::instance();
611 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
613 double lon = aThreshold->getDoubleValue("lon"),
614 lat = aThreshold->getDoubleValue("lat");
615 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
617 double newHeading = aThreshold->getDoubleValue("hdg-deg");
618 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
619 double newStopway = aThreshold->getDoubleValue("stopw-m");
622 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
623 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
624 // enable this code when threshold.xml contains sufficient data to
625 // fully specify a new runway, *and* we figure out how to assign runtime
626 // Positioned IDs and insert temporary items into the spatial map.
628 double newLength = 0.0, newWidth = 0.0;
630 FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
633 newDisplacedThreshold, newStopway,
635 // insert into the spatial map too
636 mRunways.push_back(rwy);
639 FGRunway* rwy = loadById<FGRunway>(id);
640 rwy->updateThreshold(newThreshold, newHeading,
641 newDisplacedThreshold, newStopway);
646 SGGeod FGAirport::getTowerLocation() const
649 return mTowerPosition;
652 void FGAirport::validateTowerData() const
654 if (mTowerDataLoaded) {
658 mTowerDataLoaded = true;
660 // first, load data from the cache (apt.dat)
661 NavDataCache* cache = NavDataCache::instance();
662 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
663 if (towers.empty()) {
665 mTowerPosition = geod(); // use airport position
667 // offset the tower position away from the runway centerline, if
668 // airport has a single runway. Offset by eight times the runway width,
669 // an entirely guessed figure.
670 int runwayCount = numRunways();
671 if ((runwayCount > 0) && (runwayCount <= 2)) {
672 FGRunway* runway = getRunwayByIndex(0);
673 double hdg = runway->headingDeg() + 90;
674 mTowerPosition = SGGeodesy::direct(geod(), hdg, runway->widthM() * 8);
677 // increase tower elevation by 20 metres above the field elevation
678 mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
680 FGPositionedRef tower = cache->loadById(towers.front());
681 mTowerPosition = tower->geod();
686 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
687 return; // no XML tower data, base position is fine
691 SGPropertyNode_ptr rootNode = new SGPropertyNode;
692 readProperties(path.str(), rootNode);
693 const_cast<FGAirport*>(this)->readTowerData(rootNode);
695 } catch (sg_exception& e){
696 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
700 void FGAirport::readTowerData(SGPropertyNode* aRoot)
702 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
703 double lat = twrNode->getDoubleValue("lat"),
704 lon = twrNode->getDoubleValue("lon"),
705 elevM = twrNode->getDoubleValue("elev-m");
706 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
707 // scenery for a precise terrain elevation, we use the field elevation
708 // (this is also what the apt.dat code does)
709 double fieldElevationM = geod().getElevationM();
710 mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
713 void FGAirport::validateILSData()
715 if (mILSDataLoaded) {
719 // to avoid re-entrancy on this code-path, ensure we set loaded
721 mILSDataLoaded = true;
724 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
725 return; // no XML tower data
729 SGPropertyNode_ptr rootNode = new SGPropertyNode;
730 readProperties(path.str(), rootNode);
731 readILSData(rootNode);
732 } catch (sg_exception& e){
733 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
737 bool FGAirport::hasTower() const
743 void FGAirport::readILSData(SGPropertyNode* aRoot)
745 NavDataCache* cache = NavDataCache::instance();
746 // find the entry matching the runway
747 SGPropertyNode* runwayNode, *ilsNode;
748 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
749 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
750 // must match on both nav-ident and runway ident, to support the following:
751 // - runways with multiple distinct ILS installations (KEWD, for example)
752 // - runways where both ends share the same nav ident (LFAT, for example)
753 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
754 ilsNode->getStringValue("nav-id"));
756 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
757 ", couldn't find runway/navaid for:" <<
758 ilsNode->getStringValue("rwy") << "/" <<
759 ilsNode->getStringValue("nav-id"));
763 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
764 lon = ilsNode->getDoubleValue("lon"),
765 lat = ilsNode->getDoubleValue("lat"),
766 elevM = ilsNode->getDoubleValue("elev-m");
768 FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
770 nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
771 } // of ILS iteration
772 } // of runway iteration
775 void FGAirport::addSID(flightgear::SID* aSid)
777 mSIDs.push_back(aSid);
780 void FGAirport::addSTAR(STAR* aStar)
782 mSTARs.push_back(aStar);
785 void FGAirport::addApproach(Approach* aApp)
787 mApproaches.push_back(aApp);
790 //------------------------------------------------------------------------------
791 unsigned int FGAirport::numSIDs() const
797 //------------------------------------------------------------------------------
798 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
801 return mSIDs[aIndex];
804 //------------------------------------------------------------------------------
805 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
808 for (unsigned int i=0; i<mSIDs.size(); ++i) {
809 if (mSIDs[i]->ident() == aIdent) {
817 //------------------------------------------------------------------------------
818 flightgear::SIDList FGAirport::getSIDs() const
821 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
824 //------------------------------------------------------------------------------
825 unsigned int FGAirport::numSTARs() const
828 return mSTARs.size();
831 //------------------------------------------------------------------------------
832 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
835 return mSTARs[aIndex];
838 //------------------------------------------------------------------------------
839 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
842 for (unsigned int i=0; i<mSTARs.size(); ++i) {
843 if (mSTARs[i]->ident() == aIdent) {
851 //------------------------------------------------------------------------------
852 STARList FGAirport::getSTARs() const
855 return STARList(mSTARs.begin(), mSTARs.end());
858 unsigned int FGAirport::numApproaches() const
861 return mApproaches.size();
864 //------------------------------------------------------------------------------
865 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
868 return mApproaches[aIndex];
871 //------------------------------------------------------------------------------
872 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
875 for (unsigned int i=0; i<mApproaches.size(); ++i) {
876 if (mApproaches[i]->ident() == aIdent) {
877 return mApproaches[i];
884 //------------------------------------------------------------------------------
885 ApproachList FGAirport::getApproaches(ProcedureType type) const
888 if( type == PROCEDURE_INVALID )
889 return ApproachList(mApproaches.begin(), mApproaches.end());
892 for(size_t i = 0; i < mApproaches.size(); ++i)
894 if( mApproaches[i]->type() == type )
895 ret.push_back(mApproaches[i]);
901 FGAirport::commStations() const
903 NavDataCache* cache = NavDataCache::instance();
904 CommStationList result;
905 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
906 FGPositioned::FREQ_GROUND,
907 FGPositioned::FREQ_UNICOM))
909 result.push_back( loadById<CommStation>(pos) );
916 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
918 NavDataCache* cache = NavDataCache::instance();
919 CommStationList result;
920 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
921 result.push_back( loadById<CommStation>(pos) );
927 class AirportWithSize
930 AirportWithSize(FGPositionedRef pos) :
934 assert(pos->type() == FGPositioned::AIRPORT);
935 FGAirport* apt = static_cast<FGAirport*>(pos.get());
936 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
937 _sizeMetric += static_cast<int>(rwy->lengthFt());
941 bool operator<(const AirportWithSize& other) const
943 return _sizeMetric < other._sizeMetric;
946 FGPositionedRef pos() const
949 FGPositionedRef _pos;
950 unsigned int _sizeMetric;
954 void FGAirport::sortBySize(FGPositionedList& airportList)
956 std::vector<AirportWithSize> annotated;
957 BOOST_FOREACH(FGPositionedRef p, airportList) {
958 annotated.push_back(AirportWithSize(p));
960 std::sort(annotated.begin(), annotated.end());
962 for (unsigned int i=0; i<annotated.size(); ++i) {
963 airportList[i] = annotated[i].pos();
967 FGAirportDynamicsRef FGAirport::getDynamics() const
969 return flightgear::AirportDynamicsManager::find(const_cast<FGAirport*>(this));
972 // get airport elevation
973 double fgGetAirportElev( const std::string& id )
975 const FGAirport *a=fgFindAirportID( id);
977 return a->getElevation();
984 // get airport position
985 SGGeod fgGetAirportPos( const std::string& id )
987 const FGAirport *a = fgFindAirportID( id);
990 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
992 return SGGeod::fromDegM(0.0, 0.0, -9999.0);