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/dynamics.hxx>
50 #include <Airports/xmlloader.hxx>
51 #include <Navaids/procedure.hxx>
52 #include <Navaids/waypoint.hxx>
53 #include <ATC/CommStation.hxx>
54 #include <Navaids/NavDataCache.hxx>
55 #include <Navaids/navrecord.hxx>
60 using namespace flightgear;
62 /***************************************************************************
64 ***************************************************************************/
66 AirportCache FGAirport::airportCache;
68 FGAirport::FGAirport( PositionedID aGuid,
69 const std::string &id,
70 const SGGeod& location,
71 const std::string &name,
74 FGPositioned(aGuid, aType, id, location),
76 _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()
96 bool FGAirport::isAirport() const
98 return type() == AIRPORT;
101 bool FGAirport::isSeaport() const
103 return type() == SEAPORT;
106 bool FGAirport::isHeliport() const
108 return type() == HELIPORT;
111 bool FGAirport::isAirportType(FGPositioned* pos)
117 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
120 FGAirportDynamics * FGAirport::getDynamics()
126 _dynamics = new FGAirportDynamics(this);
127 XMLLoader::load(_dynamics);
130 FGRunwayPreference rwyPrefs(this);
131 XMLLoader::load(&rwyPrefs);
132 _dynamics->setRwyUse(rwyPrefs);
137 //------------------------------------------------------------------------------
138 unsigned int FGAirport::numRunways() const
141 return mRunways.size();
144 //------------------------------------------------------------------------------
145 unsigned int FGAirport::numHelipads() const
148 return mHelipads.size();
151 //------------------------------------------------------------------------------
152 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
155 return mRunways.at(aIndex);
158 //------------------------------------------------------------------------------
159 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
162 return loadById<FGHelipad>(mHelipads, aIndex);
165 //------------------------------------------------------------------------------
166 FGRunwayMap FGAirport::getRunwayMap() const
171 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
173 BOOST_FOREACH(FGRunwayRef rwy, mRunways)
175 // ignore unusably short runways
176 // TODO other methods don't check this...
177 if( rwy->lengthFt() >= minLengthFt )
178 map[ rwy->ident() ] = rwy;
184 //------------------------------------------------------------------------------
185 FGHelipadMap FGAirport::getHelipadMap() const
190 BOOST_FOREACH(PositionedID id, mHelipads)
192 FGHelipad* rwy = loadById<FGHelipad>(id);
193 map[ rwy->ident() ] = rwy;
199 //------------------------------------------------------------------------------
200 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
203 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
204 if (rwy->ident() == aIdent) {
212 //------------------------------------------------------------------------------
213 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
215 return flightgear::NavDataCache::instance()
216 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
219 //------------------------------------------------------------------------------
220 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
223 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
224 if (rwy->ident() == aIdent) {
229 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
230 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
233 //------------------------------------------------------------------------------
234 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
236 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
238 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
239 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
242 return loadById<FGHelipad>(id);
245 //------------------------------------------------------------------------------
246 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
250 FGRunway* result = NULL;
251 double currentBestQuality = 0.0;
253 struct FindBestRunwayForHeadingParams fbrfhp;
254 if( NULL != parms ) fbrfhp = *parms;
256 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
257 if( searchNode.valid() ) {
258 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
259 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
260 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
261 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
262 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
265 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
266 double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
267 double dev = aHeading - rwy->headingDeg();
268 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
269 double bad = fabs( fbrfhp.deviationWeight * dev) + 1e-20;
270 double quality = good / bad;
272 if (quality > currentBestQuality) {
273 currentBestQuality = quality;
281 //------------------------------------------------------------------------------
282 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
286 FGRunway* result = NULL;
287 double currentLowestDev = 180.0;
289 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
290 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
291 double dev = inboundCourse - rwy->headingDeg();
292 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
295 if (dev < currentLowestDev) { // new best match
296 currentLowestDev = dev;
299 } // of runway iteration
305 //------------------------------------------------------------------------------
306 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
310 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
311 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
312 return true; // we're done!
314 } // of runways iteration
319 FGRunwayRef FGAirport::longestRunway() const
324 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
325 if (!r || (r->lengthFt() < rwy->lengthFt())) {
328 } // of runways iteration
333 //------------------------------------------------------------------------------
334 FGRunwayList FGAirport::getRunways() const
341 //------------------------------------------------------------------------------
342 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
348 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
349 FGRunway* recip = rwy->reciprocalRunway();
351 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
353 continue; // reciprocal already in result set, don't include us
363 //------------------------------------------------------------------------------
364 unsigned int FGAirport::numTaxiways() const
367 return mTaxiways.size();
370 //------------------------------------------------------------------------------
371 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
374 return loadById<FGTaxiway>(mTaxiways, aIndex);
377 //------------------------------------------------------------------------------
378 FGTaxiwayList FGAirport::getTaxiways() const
381 return loadAllById<FGTaxiway>(mTaxiways);
384 //------------------------------------------------------------------------------
385 unsigned int FGAirport::numPavements() const
388 return mPavements.size();
391 //------------------------------------------------------------------------------
392 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
395 return loadById<FGPavement>(mPavements, aIndex);
398 //------------------------------------------------------------------------------
399 FGPavementList FGAirport::getPavements() const
402 return loadAllById<FGPavement>(mPavements);
405 //------------------------------------------------------------------------------
406 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
408 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
410 // This forces West-facing rwys to be used in no-wind situations
411 // which is consistent with Flightgear's initial setup.
415 FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
417 double windSpeed = stationWeather.get_wind_speed_kt();
418 if (windSpeed > 0.0) {
419 hdg = stationWeather.get_wind_from_heading_deg();
423 return findBestRunwayForHeading(hdg);
426 //------------------------------------------------------------------------------
427 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
431 AirportFilter aptFilter;
435 return static_pointer_cast<FGAirport>
437 FGPositioned::findClosest(aPos, aCuttofNm, filter)
441 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
442 mMinLengthFt(minLengthFt)
444 if (minLengthFt < 0.0) {
445 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
449 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
451 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
454 //------------------------------------------------------------------------------
455 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
456 _type(FGPositioned::AIRPORT),
457 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
462 //------------------------------------------------------------------------------
463 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
465 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
466 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
467 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
473 //------------------------------------------------------------------------------
474 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
476 FGAirport* apt = static_cast<FGAirport*>(pos);
477 if( (apt->type() == FGPositioned::AIRPORT)
478 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
485 //------------------------------------------------------------------------------
486 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
488 AirportCache::iterator it = airportCache.find(aIdent);
489 if (it != airportCache.end())
493 FGAirportRef r = static_pointer_cast<FGAirport>
495 FGPositioned::findFirstWithIdent(aIdent, &filter)
498 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
499 airportCache[aIdent] = r;
501 // we don't warn here when r==NULL, let the caller do that
505 //------------------------------------------------------------------------------
506 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
508 FGAirportRef r = findByIdent(aIdent);
510 throw sg_range_exception("No such airport with ident: " + aIdent);
514 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
516 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
519 // find basic airport location info from airport database
520 const FGAirport *fgFindAirportID( const std::string& id)
526 return FGAirport::findByIdent(id);
529 PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
531 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
532 return cache->airportItemsOfType(guid(), ty);
535 void FGAirport::loadRunways() const
537 if (mRunwaysLoaded) {
538 return; // already loaded, great
541 loadSceneryDefinitions();
543 mRunwaysLoaded = true;
544 PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
545 BOOST_FOREACH(PositionedID id, rwys) {
546 mRunways.push_back(loadById<FGRunway>(id));
550 void FGAirport::loadHelipads() const
552 if (mHelipadsLoaded) {
553 return; // already loaded, great
556 mHelipadsLoaded = true;
557 mHelipads = itemsOfType(FGPositioned::HELIPAD);
560 void FGAirport::loadTaxiways() const
562 if (mTaxiwaysLoaded) {
563 return; // already loaded, great
566 mTaxiwaysLoaded = true;
567 mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
570 void FGAirport::loadProcedures() const
572 if (mProceduresLoaded) {
576 mProceduresLoaded = true;
578 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
579 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
583 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
584 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
587 void FGAirport::loadSceneryDefinitions() const
589 if (mThresholdDataLoaded) {
593 mThresholdDataLoaded = true;
596 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
597 return; // no XML threshold data
601 SGPropertyNode_ptr rootNode = new SGPropertyNode;
602 readProperties(path.str(), rootNode);
603 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
604 } catch (sg_exception& e) {
605 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
609 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
611 SGPropertyNode* runway;
613 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
614 SGPropertyNode* t0 = runway->getChild("threshold", 0),
615 *t1 = runway->getChild("threshold", 1);
617 assert(t1); // too strict? maybe we should finally allow single-ended runways
619 processThreshold(t0);
620 processThreshold(t1);
621 } // of runways iteration
624 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
626 // first, let's identify the current runway
627 std::string rwyIdent(aThreshold->getStringValue("rwy"));
628 NavDataCache* cache = NavDataCache::instance();
629 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
631 double lon = aThreshold->getDoubleValue("lon"),
632 lat = aThreshold->getDoubleValue("lat");
633 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
635 double newHeading = aThreshold->getDoubleValue("hdg-deg");
636 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
637 double newStopway = aThreshold->getDoubleValue("stopw-m");
640 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
641 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
642 // enable this code when threshold.xml contains sufficient data to
643 // fully specify a new runway, *and* we figure out how to assign runtime
644 // Positioned IDs and insert temporary items into the spatial map.
646 double newLength = 0.0, newWidth = 0.0;
648 FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
651 newDisplacedThreshold, newStopway,
653 // insert into the spatial map too
654 mRunways.push_back(rwy);
657 FGRunway* rwy = loadById<FGRunway>(id);
658 rwy->updateThreshold(newThreshold, newHeading,
659 newDisplacedThreshold, newStopway);
664 SGGeod FGAirport::getTowerLocation() const
667 return mTowerPosition;
670 void FGAirport::validateTowerData() const
672 if (mTowerDataLoaded) {
676 mTowerDataLoaded = true;
678 // first, load data from the cache (apt.dat)
679 NavDataCache* cache = NavDataCache::instance();
680 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
681 if (towers.empty()) {
683 mTowerPosition = geod(); // use airport position
685 // offset the tower position away from the runway centerline, if
686 // airport has a single runway. Offset by eight times the runway width,
687 // an entirely guessed figure.
688 int runwayCount = numRunways();
689 if ((runwayCount > 0) && (runwayCount <= 2)) {
690 FGRunway* runway = getRunwayByIndex(0);
691 double hdg = runway->headingDeg() + 90;
692 mTowerPosition = SGGeodesy::direct(geod(), hdg, runway->widthM() * 8);
695 // increase tower elevation by 20 metres above the field elevation
696 mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
698 FGPositionedRef tower = cache->loadById(towers.front());
699 mTowerPosition = tower->geod();
704 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
705 return; // no XML tower data, base position is fine
709 SGPropertyNode_ptr rootNode = new SGPropertyNode;
710 readProperties(path.str(), rootNode);
711 const_cast<FGAirport*>(this)->readTowerData(rootNode);
713 } catch (sg_exception& e){
714 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
718 void FGAirport::readTowerData(SGPropertyNode* aRoot)
720 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
721 double lat = twrNode->getDoubleValue("lat"),
722 lon = twrNode->getDoubleValue("lon"),
723 elevM = twrNode->getDoubleValue("elev-m");
724 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
725 // scenery for a precise terrain elevation, we use the field elevation
726 // (this is also what the apt.dat code does)
727 double fieldElevationM = geod().getElevationM();
728 mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
731 void FGAirport::validateILSData()
733 if (mILSDataLoaded) {
737 // to avoid re-entrancy on this code-path, ensure we set loaded
739 mILSDataLoaded = true;
742 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
743 return; // no XML tower data
747 SGPropertyNode_ptr rootNode = new SGPropertyNode;
748 readProperties(path.str(), rootNode);
749 readILSData(rootNode);
750 } catch (sg_exception& e){
751 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
755 bool FGAirport::hasTower() const
761 void FGAirport::readILSData(SGPropertyNode* aRoot)
763 NavDataCache* cache = NavDataCache::instance();
764 // find the entry matching the runway
765 SGPropertyNode* runwayNode, *ilsNode;
766 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
767 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
768 // must match on both nav-ident and runway ident, to support the following:
769 // - runways with multiple distinct ILS installations (KEWD, for example)
770 // - runways where both ends share the same nav ident (LFAT, for example)
771 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
772 ilsNode->getStringValue("nav-id"));
774 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
775 ", couldn't find runway/navaid for:" <<
776 ilsNode->getStringValue("rwy") << "/" <<
777 ilsNode->getStringValue("nav-id"));
781 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
782 lon = ilsNode->getDoubleValue("lon"),
783 lat = ilsNode->getDoubleValue("lat"),
784 elevM = ilsNode->getDoubleValue("elev-m");
786 FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
788 nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
789 } // of ILS iteration
790 } // of runway iteration
793 void FGAirport::addSID(flightgear::SID* aSid)
795 mSIDs.push_back(aSid);
798 void FGAirport::addSTAR(STAR* aStar)
800 mSTARs.push_back(aStar);
803 void FGAirport::addApproach(Approach* aApp)
805 mApproaches.push_back(aApp);
808 //------------------------------------------------------------------------------
809 unsigned int FGAirport::numSIDs() const
815 //------------------------------------------------------------------------------
816 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
819 return mSIDs[aIndex];
822 //------------------------------------------------------------------------------
823 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
826 for (unsigned int i=0; i<mSIDs.size(); ++i) {
827 if (mSIDs[i]->ident() == aIdent) {
835 //------------------------------------------------------------------------------
836 flightgear::SIDList FGAirport::getSIDs() const
839 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
842 //------------------------------------------------------------------------------
843 unsigned int FGAirport::numSTARs() const
846 return mSTARs.size();
849 //------------------------------------------------------------------------------
850 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
853 return mSTARs[aIndex];
856 //------------------------------------------------------------------------------
857 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
860 for (unsigned int i=0; i<mSTARs.size(); ++i) {
861 if (mSTARs[i]->ident() == aIdent) {
869 //------------------------------------------------------------------------------
870 STARList FGAirport::getSTARs() const
873 return STARList(mSTARs.begin(), mSTARs.end());
876 unsigned int FGAirport::numApproaches() const
879 return mApproaches.size();
882 //------------------------------------------------------------------------------
883 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
886 return mApproaches[aIndex];
889 //------------------------------------------------------------------------------
890 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
893 for (unsigned int i=0; i<mApproaches.size(); ++i) {
894 if (mApproaches[i]->ident() == aIdent) {
895 return mApproaches[i];
902 //------------------------------------------------------------------------------
903 ApproachList FGAirport::getApproaches(ProcedureType type) const
906 if( type == PROCEDURE_INVALID )
907 return ApproachList(mApproaches.begin(), mApproaches.end());
910 for(size_t i = 0; i < mApproaches.size(); ++i)
912 if( mApproaches[i]->type() == type )
913 ret.push_back(mApproaches[i]);
919 FGAirport::commStations() const
921 NavDataCache* cache = NavDataCache::instance();
922 CommStationList result;
923 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
924 FGPositioned::FREQ_GROUND,
925 FGPositioned::FREQ_UNICOM))
927 result.push_back( loadById<CommStation>(pos) );
934 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
936 NavDataCache* cache = NavDataCache::instance();
937 CommStationList result;
938 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
939 result.push_back( loadById<CommStation>(pos) );
945 class AirportWithSize
948 AirportWithSize(FGPositionedRef pos) :
952 assert(pos->type() == FGPositioned::AIRPORT);
953 FGAirport* apt = static_cast<FGAirport*>(pos.get());
954 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
955 _sizeMetric += static_cast<int>(rwy->lengthFt());
959 bool operator<(const AirportWithSize& other) const
961 return _sizeMetric < other._sizeMetric;
964 FGPositionedRef pos() const
967 FGPositionedRef _pos;
968 unsigned int _sizeMetric;
972 void FGAirport::sortBySize(FGPositionedList& airportList)
974 std::vector<AirportWithSize> annotated;
975 BOOST_FOREACH(FGPositionedRef p, airportList) {
976 annotated.push_back(AirportWithSize(p));
978 std::sort(annotated.begin(), annotated.end());
980 for (unsigned int i=0; i<annotated.size(); ++i) {
981 airportList[i] = annotated[i].pos();
985 // get airport elevation
986 double fgGetAirportElev( const std::string& id )
988 const FGAirport *a=fgFindAirportID( id);
990 return a->getElevation();
997 // get airport position
998 SGGeod fgGetAirportPos( const std::string& id )
1000 const FGAirport *a = fgFindAirportID( id);
1003 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
1005 return SGGeod::fromDegM(0.0, 0.0, -9999.0);