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),
90 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 FGAirportDynamics * FGAirport::getDynamics()
125 _dynamics = new FGAirportDynamics(this);
126 XMLLoader::load(_dynamics);
129 FGRunwayPreference rwyPrefs(this);
130 XMLLoader::load(&rwyPrefs);
131 _dynamics->setRwyUse(rwyPrefs);
136 //------------------------------------------------------------------------------
137 unsigned int FGAirport::numRunways() const
140 return mRunways.size();
143 //------------------------------------------------------------------------------
144 unsigned int FGAirport::numHelipads() const
147 return mHelipads.size();
150 //------------------------------------------------------------------------------
151 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
154 return mRunways.at(aIndex);
157 //------------------------------------------------------------------------------
158 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
161 return loadById<FGHelipad>(mHelipads, aIndex);
164 //------------------------------------------------------------------------------
165 FGRunwayMap FGAirport::getRunwayMap() const
170 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
172 BOOST_FOREACH(FGRunwayRef rwy, mRunways)
174 // ignore unusably short runways
175 // TODO other methods don't check this...
176 if( rwy->lengthFt() >= minLengthFt )
177 map[ rwy->ident() ] = rwy;
183 //------------------------------------------------------------------------------
184 FGHelipadMap FGAirport::getHelipadMap() const
189 BOOST_FOREACH(PositionedID id, mHelipads)
191 FGHelipad* rwy = loadById<FGHelipad>(id);
192 map[ rwy->ident() ] = rwy;
198 //------------------------------------------------------------------------------
199 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
202 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
203 if (rwy->ident() == aIdent) {
211 //------------------------------------------------------------------------------
212 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
214 return flightgear::NavDataCache::instance()
215 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
218 //------------------------------------------------------------------------------
219 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
222 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
223 if (rwy->ident() == aIdent) {
228 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
229 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
232 //------------------------------------------------------------------------------
233 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
235 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
237 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
238 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
241 return loadById<FGHelipad>(id);
244 //------------------------------------------------------------------------------
245 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
249 FGRunway* result = NULL;
250 double currentBestQuality = 0.0;
252 struct FindBestRunwayForHeadingParams fbrfhp;
253 if( NULL != parms ) fbrfhp = *parms;
255 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
256 if( searchNode.valid() ) {
257 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
258 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
259 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
260 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
261 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
264 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
265 double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
266 double dev = aHeading - rwy->headingDeg();
267 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
268 double bad = fabs( fbrfhp.deviationWeight * dev) + 1e-20;
269 double quality = good / bad;
271 if (quality > currentBestQuality) {
272 currentBestQuality = quality;
280 //------------------------------------------------------------------------------
281 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
285 FGRunway* result = NULL;
286 double currentLowestDev = 180.0;
288 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
289 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
290 double dev = inboundCourse - rwy->headingDeg();
291 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
294 if (dev < currentLowestDev) { // new best match
295 currentLowestDev = dev;
298 } // of runway iteration
304 //------------------------------------------------------------------------------
305 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
309 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
310 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
311 return true; // we're done!
313 } // of runways iteration
318 FGRunwayRef FGAirport::longestRunway() const
323 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
324 if (!r || (r->lengthFt() < rwy->lengthFt())) {
327 } // of runways iteration
332 //------------------------------------------------------------------------------
333 FGRunwayList FGAirport::getRunways() const
340 //------------------------------------------------------------------------------
341 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
347 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
348 FGRunway* recip = rwy->reciprocalRunway();
350 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
352 continue; // reciprocal already in result set, don't include us
362 //------------------------------------------------------------------------------
363 unsigned int FGAirport::numTaxiways() const
366 return mTaxiways.size();
369 //------------------------------------------------------------------------------
370 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
373 return loadById<FGTaxiway>(mTaxiways, aIndex);
376 //------------------------------------------------------------------------------
377 FGTaxiwayList FGAirport::getTaxiways() const
380 return loadAllById<FGTaxiway>(mTaxiways);
383 //------------------------------------------------------------------------------
384 unsigned int FGAirport::numPavements() const
387 return mPavements.size();
390 //------------------------------------------------------------------------------
391 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
394 return loadById<FGPavement>(mPavements, aIndex);
397 //------------------------------------------------------------------------------
398 FGPavementList FGAirport::getPavements() const
401 return loadAllById<FGPavement>(mPavements);
404 //------------------------------------------------------------------------------
405 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
407 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
409 // This forces West-facing rwys to be used in no-wind situations
410 // which is consistent with Flightgear's initial setup.
414 FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
416 double windSpeed = stationWeather.get_wind_speed_kt();
417 if (windSpeed > 0.0) {
418 hdg = stationWeather.get_wind_from_heading_deg();
422 return findBestRunwayForHeading(hdg);
425 //------------------------------------------------------------------------------
426 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
430 AirportFilter aptFilter;
434 return static_pointer_cast<FGAirport>
436 FGPositioned::findClosest(aPos, aCuttofNm, filter)
440 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
441 mMinLengthFt(minLengthFt)
443 if (minLengthFt < 0.0) {
444 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
448 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
450 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
453 //------------------------------------------------------------------------------
454 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
455 _type(FGPositioned::AIRPORT),
456 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
461 //------------------------------------------------------------------------------
462 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
464 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
465 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
466 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
472 //------------------------------------------------------------------------------
473 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
475 FGAirport* apt = static_cast<FGAirport*>(pos);
476 if( (apt->type() == FGPositioned::AIRPORT)
477 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
484 //------------------------------------------------------------------------------
485 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
487 AirportCache::iterator it = airportCache.find(aIdent);
488 if (it != airportCache.end())
492 FGAirportRef r = static_pointer_cast<FGAirport>
494 FGPositioned::findFirstWithIdent(aIdent, &filter)
497 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
498 airportCache[aIdent] = r;
500 // we don't warn here when r==NULL, let the caller do that
504 //------------------------------------------------------------------------------
505 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
507 FGAirportRef r = findByIdent(aIdent);
509 throw sg_range_exception("No such airport with ident: " + aIdent);
513 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
515 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
518 // find basic airport location info from airport database
519 const FGAirport *fgFindAirportID( const std::string& id)
525 return FGAirport::findByIdent(id);
528 PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
530 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
531 return cache->airportItemsOfType(guid(), ty);
534 void FGAirport::loadRunways() const
536 if (mRunwaysLoaded) {
537 return; // already loaded, great
540 loadSceneryDefinitions();
542 mRunwaysLoaded = true;
543 PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
544 BOOST_FOREACH(PositionedID id, rwys) {
545 mRunways.push_back(loadById<FGRunway>(id));
549 void FGAirport::loadHelipads() const
551 if (mHelipadsLoaded) {
552 return; // already loaded, great
555 mHelipadsLoaded = true;
556 mHelipads = itemsOfType(FGPositioned::HELIPAD);
559 void FGAirport::loadTaxiways() const
561 if (mTaxiwaysLoaded) {
562 return; // already loaded, great
565 mTaxiwaysLoaded = true;
566 mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
569 void FGAirport::loadProcedures() const
571 if (mProceduresLoaded) {
575 mProceduresLoaded = true;
577 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
578 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
582 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
583 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
586 void FGAirport::loadSceneryDefinitions() const
588 if (mThresholdDataLoaded) {
592 mThresholdDataLoaded = true;
595 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
596 return; // no XML threshold data
600 SGPropertyNode_ptr rootNode = new SGPropertyNode;
601 readProperties(path.str(), rootNode);
602 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
603 } catch (sg_exception& e) {
604 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
608 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
610 SGPropertyNode* runway;
612 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
613 SGPropertyNode* t0 = runway->getChild("threshold", 0),
614 *t1 = runway->getChild("threshold", 1);
616 assert(t1); // too strict? maybe we should finally allow single-ended runways
618 processThreshold(t0);
619 processThreshold(t1);
620 } // of runways iteration
623 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
625 // first, let's identify the current runway
626 std::string rwyIdent(aThreshold->getStringValue("rwy"));
627 NavDataCache* cache = NavDataCache::instance();
628 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
630 double lon = aThreshold->getDoubleValue("lon"),
631 lat = aThreshold->getDoubleValue("lat");
632 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
634 double newHeading = aThreshold->getDoubleValue("hdg-deg");
635 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
636 double newStopway = aThreshold->getDoubleValue("stopw-m");
639 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
640 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
641 // enable this code when threshold.xml contains sufficient data to
642 // fully specify a new runway, *and* we figure out how to assign runtime
643 // Positioned IDs and insert temporary items into the spatial map.
645 double newLength = 0.0, newWidth = 0.0;
647 FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
650 newDisplacedThreshold, newStopway,
652 // insert into the spatial map too
653 mRunways.push_back(rwy);
656 FGRunway* rwy = loadById<FGRunway>(id);
657 rwy->updateThreshold(newThreshold, newHeading,
658 newDisplacedThreshold, newStopway);
663 SGGeod FGAirport::getTowerLocation() const
666 return mTowerPosition;
669 void FGAirport::validateTowerData() const
671 if (mTowerDataLoaded) {
675 mTowerDataLoaded = true;
677 // first, load data from the cache (apt.dat)
678 NavDataCache* cache = NavDataCache::instance();
679 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
680 if (towers.empty()) {
682 mTowerPosition = geod(); // use airport position
684 // offset the tower position away from the runway centerline, if
685 // airport has a single runway. Offset by eight times the runway width,
686 // an entirely guessed figure.
687 int runwayCount = numRunways();
688 if ((runwayCount > 0) && (runwayCount <= 2)) {
689 FGRunway* runway = getRunwayByIndex(0);
690 double hdg = runway->headingDeg() + 90;
691 mTowerPosition = SGGeodesy::direct(geod(), hdg, runway->widthM() * 8);
694 // increase tower elevation by 20 metres above the field elevation
695 mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
697 FGPositionedRef tower = cache->loadById(towers.front());
698 mTowerPosition = tower->geod();
703 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
704 return; // no XML tower data, base position is fine
708 SGPropertyNode_ptr rootNode = new SGPropertyNode;
709 readProperties(path.str(), rootNode);
710 const_cast<FGAirport*>(this)->readTowerData(rootNode);
712 } catch (sg_exception& e){
713 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
717 void FGAirport::readTowerData(SGPropertyNode* aRoot)
719 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
720 double lat = twrNode->getDoubleValue("lat"),
721 lon = twrNode->getDoubleValue("lon"),
722 elevM = twrNode->getDoubleValue("elev-m");
723 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
724 // scenery for a precise terrain elevation, we use the field elevation
725 // (this is also what the apt.dat code does)
726 double fieldElevationM = geod().getElevationM();
727 mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
730 void FGAirport::validateILSData()
732 if (mILSDataLoaded) {
736 // to avoid re-entrancy on this code-path, ensure we set loaded
738 mILSDataLoaded = true;
741 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
742 return; // no XML tower data
746 SGPropertyNode_ptr rootNode = new SGPropertyNode;
747 readProperties(path.str(), rootNode);
748 readILSData(rootNode);
749 } catch (sg_exception& e){
750 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
754 bool FGAirport::hasTower() const
760 void FGAirport::readILSData(SGPropertyNode* aRoot)
762 NavDataCache* cache = NavDataCache::instance();
763 // find the entry matching the runway
764 SGPropertyNode* runwayNode, *ilsNode;
765 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
766 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
767 // must match on both nav-ident and runway ident, to support the following:
768 // - runways with multiple distinct ILS installations (KEWD, for example)
769 // - runways where both ends share the same nav ident (LFAT, for example)
770 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
771 ilsNode->getStringValue("nav-id"));
773 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
774 ", couldn't find runway/navaid for:" <<
775 ilsNode->getStringValue("rwy") << "/" <<
776 ilsNode->getStringValue("nav-id"));
780 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
781 lon = ilsNode->getDoubleValue("lon"),
782 lat = ilsNode->getDoubleValue("lat"),
783 elevM = ilsNode->getDoubleValue("elev-m");
785 FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
787 nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
788 } // of ILS iteration
789 } // of runway iteration
792 void FGAirport::addSID(flightgear::SID* aSid)
794 mSIDs.push_back(aSid);
797 void FGAirport::addSTAR(STAR* aStar)
799 mSTARs.push_back(aStar);
802 void FGAirport::addApproach(Approach* aApp)
804 mApproaches.push_back(aApp);
807 //------------------------------------------------------------------------------
808 unsigned int FGAirport::numSIDs() const
814 //------------------------------------------------------------------------------
815 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
818 return mSIDs[aIndex];
821 //------------------------------------------------------------------------------
822 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
825 for (unsigned int i=0; i<mSIDs.size(); ++i) {
826 if (mSIDs[i]->ident() == aIdent) {
834 //------------------------------------------------------------------------------
835 flightgear::SIDList FGAirport::getSIDs() const
838 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
841 //------------------------------------------------------------------------------
842 unsigned int FGAirport::numSTARs() const
845 return mSTARs.size();
848 //------------------------------------------------------------------------------
849 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
852 return mSTARs[aIndex];
855 //------------------------------------------------------------------------------
856 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
859 for (unsigned int i=0; i<mSTARs.size(); ++i) {
860 if (mSTARs[i]->ident() == aIdent) {
868 //------------------------------------------------------------------------------
869 STARList FGAirport::getSTARs() const
872 return STARList(mSTARs.begin(), mSTARs.end());
875 unsigned int FGAirport::numApproaches() const
878 return mApproaches.size();
881 //------------------------------------------------------------------------------
882 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
885 return mApproaches[aIndex];
888 //------------------------------------------------------------------------------
889 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
892 for (unsigned int i=0; i<mApproaches.size(); ++i) {
893 if (mApproaches[i]->ident() == aIdent) {
894 return mApproaches[i];
901 //------------------------------------------------------------------------------
902 ApproachList FGAirport::getApproaches(ProcedureType type) const
905 if( type == PROCEDURE_INVALID )
906 return ApproachList(mApproaches.begin(), mApproaches.end());
909 for(size_t i = 0; i < mApproaches.size(); ++i)
911 if( mApproaches[i]->type() == type )
912 ret.push_back(mApproaches[i]);
918 FGAirport::commStations() const
920 NavDataCache* cache = NavDataCache::instance();
921 CommStationList result;
922 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
923 FGPositioned::FREQ_GROUND,
924 FGPositioned::FREQ_UNICOM))
926 result.push_back( loadById<CommStation>(pos) );
933 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
935 NavDataCache* cache = NavDataCache::instance();
936 CommStationList result;
937 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
938 result.push_back( loadById<CommStation>(pos) );
944 class AirportWithSize
947 AirportWithSize(FGPositionedRef pos) :
951 assert(pos->type() == FGPositioned::AIRPORT);
952 FGAirport* apt = static_cast<FGAirport*>(pos.get());
953 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
954 _sizeMetric += static_cast<int>(rwy->lengthFt());
958 bool operator<(const AirportWithSize& other) const
960 return _sizeMetric < other._sizeMetric;
963 FGPositionedRef pos() const
966 FGPositionedRef _pos;
967 unsigned int _sizeMetric;
971 void FGAirport::sortBySize(FGPositionedList& airportList)
973 std::vector<AirportWithSize> annotated;
974 BOOST_FOREACH(FGPositionedRef p, airportList) {
975 annotated.push_back(AirportWithSize(p));
977 std::sort(annotated.begin(), annotated.end());
979 for (unsigned int i=0; i<annotated.size(); ++i) {
980 airportList[i] = annotated[i].pos();
984 // get airport elevation
985 double fgGetAirportElev( const std::string& id )
987 const FGAirport *a=fgFindAirportID( id);
989 return a->getElevation();
996 // get airport position
997 SGGeod fgGetAirportPos( const std::string& id )
999 const FGAirport *a = fgFindAirportID( id);
1002 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
1004 return SGGeod::fromDegM(0.0, 0.0, -9999.0);