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()
93 SG_LOG(SG_NAVAID, SG_INFO, "deleting airport:" << ident());
97 bool FGAirport::isAirport() const
99 return type() == AIRPORT;
102 bool FGAirport::isSeaport() const
104 return type() == SEAPORT;
107 bool FGAirport::isHeliport() const
109 return type() == HELIPORT;
112 bool FGAirport::isAirportType(FGPositioned* pos)
118 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
121 FGAirportDynamics * FGAirport::getDynamics()
127 _dynamics = new FGAirportDynamics(this);
128 XMLLoader::load(_dynamics);
131 FGRunwayPreference rwyPrefs(this);
132 XMLLoader::load(&rwyPrefs);
133 _dynamics->setRwyUse(rwyPrefs);
138 //------------------------------------------------------------------------------
139 unsigned int FGAirport::numRunways() const
142 return mRunways.size();
145 //------------------------------------------------------------------------------
146 unsigned int FGAirport::numHelipads() const
149 return mHelipads.size();
152 //------------------------------------------------------------------------------
153 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
156 return mRunways.at(aIndex);
159 //------------------------------------------------------------------------------
160 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
163 return loadById<FGHelipad>(mHelipads, aIndex);
166 //------------------------------------------------------------------------------
167 FGRunwayMap FGAirport::getRunwayMap() const
172 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
174 BOOST_FOREACH(FGRunwayRef rwy, mRunways)
176 // ignore unusably short runways
177 // TODO other methods don't check this...
178 if( rwy->lengthFt() >= minLengthFt )
179 map[ rwy->ident() ] = rwy;
185 //------------------------------------------------------------------------------
186 FGHelipadMap FGAirport::getHelipadMap() const
191 BOOST_FOREACH(PositionedID id, mHelipads)
193 FGHelipad* rwy = loadById<FGHelipad>(id);
194 map[ rwy->ident() ] = rwy;
200 //------------------------------------------------------------------------------
201 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
204 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
205 if (rwy->ident() == aIdent) {
213 //------------------------------------------------------------------------------
214 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
216 return flightgear::NavDataCache::instance()
217 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
220 //------------------------------------------------------------------------------
221 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
224 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
225 if (rwy->ident() == aIdent) {
230 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
231 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
234 //------------------------------------------------------------------------------
235 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
237 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
239 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
240 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
243 return loadById<FGHelipad>(id);
246 //------------------------------------------------------------------------------
247 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
251 FGRunway* result = NULL;
252 double currentBestQuality = 0.0;
254 struct FindBestRunwayForHeadingParams fbrfhp;
255 if( NULL != parms ) fbrfhp = *parms;
257 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
258 if( searchNode.valid() ) {
259 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
260 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
261 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
262 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
263 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
266 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
267 double good = rwy->score( fbrfhp.lengthWeight, fbrfhp.widthWeight, fbrfhp.surfaceWeight, fbrfhp.ilsWeight );
268 double dev = aHeading - rwy->headingDeg();
269 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
270 double bad = fabs( fbrfhp.deviationWeight * dev) + 1e-20;
271 double quality = good / bad;
273 if (quality > currentBestQuality) {
274 currentBestQuality = quality;
282 //------------------------------------------------------------------------------
283 FGRunwayRef FGAirport::findBestRunwayForPos(const SGGeod& aPos) const
287 FGRunway* result = NULL;
288 double currentLowestDev = 180.0;
290 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
291 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
292 double dev = inboundCourse - rwy->headingDeg();
293 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
296 if (dev < currentLowestDev) { // new best match
297 currentLowestDev = dev;
300 } // of runway iteration
306 //------------------------------------------------------------------------------
307 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
311 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
312 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
313 return true; // we're done!
315 } // of runways iteration
320 FGRunwayRef FGAirport::longestRunway() const
325 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
326 if (!r || (r->lengthFt() < rwy->lengthFt())) {
329 } // of runways iteration
334 //------------------------------------------------------------------------------
335 FGRunwayList FGAirport::getRunways() const
342 //------------------------------------------------------------------------------
343 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
349 BOOST_FOREACH(FGRunwayRef rwy, mRunways) {
350 FGRunway* recip = rwy->reciprocalRunway();
352 FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
354 continue; // reciprocal already in result set, don't include us
364 //------------------------------------------------------------------------------
365 unsigned int FGAirport::numTaxiways() const
368 return mTaxiways.size();
371 //------------------------------------------------------------------------------
372 FGTaxiwayRef FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
375 return loadById<FGTaxiway>(mTaxiways, aIndex);
378 //------------------------------------------------------------------------------
379 FGTaxiwayList FGAirport::getTaxiways() const
382 return loadAllById<FGTaxiway>(mTaxiways);
385 //------------------------------------------------------------------------------
386 unsigned int FGAirport::numPavements() const
389 return mPavements.size();
392 //------------------------------------------------------------------------------
393 FGPavementRef FGAirport::getPavementByIndex(unsigned int aIndex) const
396 return loadById<FGPavement>(mPavements, aIndex);
399 //------------------------------------------------------------------------------
400 FGPavementList FGAirport::getPavements() const
403 return loadAllById<FGPavement>(mPavements);
406 //------------------------------------------------------------------------------
407 FGRunwayRef FGAirport::getActiveRunwayForUsage() const
409 FGEnvironmentMgr* envMgr = (FGEnvironmentMgr *) globals->get_subsystem("environment");
411 // This forces West-facing rwys to be used in no-wind situations
412 // which is consistent with Flightgear's initial setup.
416 FGEnvironment stationWeather(envMgr->getEnvironment(geod()));
418 double windSpeed = stationWeather.get_wind_speed_kt();
419 if (windSpeed > 0.0) {
420 hdg = stationWeather.get_wind_from_heading_deg();
424 return findBestRunwayForHeading(hdg);
427 //------------------------------------------------------------------------------
428 FGAirportRef FGAirport::findClosest( const SGGeod& aPos,
432 AirportFilter aptFilter;
436 return static_pointer_cast<FGAirport>
438 FGPositioned::findClosest(aPos, aCuttofNm, filter)
442 FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
443 mMinLengthFt(minLengthFt)
445 if (minLengthFt < 0.0) {
446 mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
450 bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
452 return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
455 //------------------------------------------------------------------------------
456 FGAirport::TypeRunwayFilter::TypeRunwayFilter():
457 _type(FGPositioned::AIRPORT),
458 _min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
463 //------------------------------------------------------------------------------
464 bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
466 if( type == "heliport" ) _type = FGPositioned::HELIPORT;
467 else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
468 else if( type == "airport" ) _type = FGPositioned::AIRPORT;
474 //------------------------------------------------------------------------------
475 bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
477 FGAirport* apt = static_cast<FGAirport*>(pos);
478 if( (apt->type() == FGPositioned::AIRPORT)
479 && !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
486 //------------------------------------------------------------------------------
487 FGAirportRef FGAirport::findByIdent(const std::string& aIdent)
489 AirportCache::iterator it = airportCache.find(aIdent);
490 if (it != airportCache.end())
494 FGAirportRef r = static_pointer_cast<FGAirport>
496 FGPositioned::findFirstWithIdent(aIdent, &filter)
499 // add airport to the cache (even when it's NULL, so we don't need to search in vain again)
500 airportCache[aIdent] = r;
502 // we don't warn here when r==NULL, let the caller do that
506 //------------------------------------------------------------------------------
507 FGAirportRef FGAirport::getByIdent(const std::string& aIdent)
509 FGAirportRef r = findByIdent(aIdent);
511 throw sg_range_exception("No such airport with ident: " + aIdent);
515 char** FGAirport::searchNamesAndIdents(const std::string& aFilter)
517 return NavDataCache::instance()->searchAirportNamesAndIdents(aFilter);
520 // find basic airport location info from airport database
521 const FGAirport *fgFindAirportID( const std::string& id)
527 return FGAirport::findByIdent(id);
530 PositionedIDVec FGAirport::itemsOfType(FGPositioned::Type ty) const
532 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
533 return cache->airportItemsOfType(guid(), ty);
536 void FGAirport::loadRunways() const
538 if (mRunwaysLoaded) {
539 return; // already loaded, great
542 loadSceneryDefinitions();
544 mRunwaysLoaded = true;
545 PositionedIDVec rwys(itemsOfType(FGPositioned::RUNWAY));
546 BOOST_FOREACH(PositionedID id, rwys) {
547 mRunways.push_back(loadById<FGRunway>(id));
551 void FGAirport::loadHelipads() const
553 if (mHelipadsLoaded) {
554 return; // already loaded, great
557 mHelipadsLoaded = true;
558 mHelipads = itemsOfType(FGPositioned::HELIPAD);
561 void FGAirport::loadTaxiways() const
563 if (mTaxiwaysLoaded) {
564 return; // already loaded, great
567 mTaxiwaysLoaded = true;
568 mTaxiways = itemsOfType(FGPositioned::TAXIWAY);
571 void FGAirport::loadProcedures() const
573 if (mProceduresLoaded) {
577 mProceduresLoaded = true;
579 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
580 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
584 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
585 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
588 void FGAirport::loadSceneryDefinitions() const
590 if (mThresholdDataLoaded) {
594 mThresholdDataLoaded = true;
597 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
598 return; // no XML threshold data
602 SGPropertyNode_ptr rootNode = new SGPropertyNode;
603 readProperties(path.str(), rootNode);
604 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
605 } catch (sg_exception& e) {
606 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading threshold XML failed:" << e.getFormattedMessage());
610 void FGAirport::readThresholdData(SGPropertyNode* aRoot)
612 SGPropertyNode* runway;
614 for (; (runway = aRoot->getChild("runway", runwayIndex)) != NULL; ++runwayIndex) {
615 SGPropertyNode* t0 = runway->getChild("threshold", 0),
616 *t1 = runway->getChild("threshold", 1);
618 assert(t1); // too strict? maybe we should finally allow single-ended runways
620 processThreshold(t0);
621 processThreshold(t1);
622 } // of runways iteration
625 void FGAirport::processThreshold(SGPropertyNode* aThreshold)
627 // first, let's identify the current runway
628 std::string rwyIdent(aThreshold->getStringValue("rwy"));
629 NavDataCache* cache = NavDataCache::instance();
630 PositionedID id = cache->airportItemWithIdent(guid(), FGPositioned::RUNWAY, rwyIdent);
632 double lon = aThreshold->getDoubleValue("lon"),
633 lat = aThreshold->getDoubleValue("lat");
634 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
636 double newHeading = aThreshold->getDoubleValue("hdg-deg");
637 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
638 double newStopway = aThreshold->getDoubleValue("stopw-m");
641 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
642 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
643 // enable this code when threshold.xml contains sufficient data to
644 // fully specify a new runway, *and* we figure out how to assign runtime
645 // Positioned IDs and insert temporary items into the spatial map.
647 double newLength = 0.0, newWidth = 0.0;
649 FGRunway* rwy = new FGRunway(id, guid(), rwyIdent, newThreshold,
652 newDisplacedThreshold, newStopway,
654 // insert into the spatial map too
655 mRunways.push_back(rwy);
658 FGRunway* rwy = loadById<FGRunway>(id);
659 rwy->updateThreshold(newThreshold, newHeading,
660 newDisplacedThreshold, newStopway);
665 SGGeod FGAirport::getTowerLocation() const
668 return mTowerPosition;
671 void FGAirport::validateTowerData() const
673 if (mTowerDataLoaded) {
677 mTowerDataLoaded = true;
679 // first, load data from the cache (apt.dat)
680 NavDataCache* cache = NavDataCache::instance();
681 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
682 if (towers.empty()) {
684 mTowerPosition = geod(); // use airport position
686 // offset the tower position away from the runway centerline, if
687 // airport has a single runway. Offset by eight times the runway width,
688 // an entirely guessed figure.
689 int runwayCount = numRunways();
690 if ((runwayCount > 0) && (runwayCount <= 2)) {
691 FGRunway* runway = getRunwayByIndex(0);
692 double hdg = runway->headingDeg() + 90;
693 mTowerPosition = SGGeodesy::direct(geod(), hdg, runway->widthM() * 8);
696 // increase tower elevation by 20 metres above the field elevation
697 mTowerPosition.setElevationM(geod().getElevationM() + 20.0);
699 FGPositionedRef tower = cache->loadById(towers.front());
700 mTowerPosition = tower->geod();
705 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
706 return; // no XML tower data, base position is fine
710 SGPropertyNode_ptr rootNode = new SGPropertyNode;
711 readProperties(path.str(), rootNode);
712 const_cast<FGAirport*>(this)->readTowerData(rootNode);
714 } catch (sg_exception& e){
715 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
719 void FGAirport::readTowerData(SGPropertyNode* aRoot)
721 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
722 double lat = twrNode->getDoubleValue("lat"),
723 lon = twrNode->getDoubleValue("lon"),
724 elevM = twrNode->getDoubleValue("elev-m");
725 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
726 // scenery for a precise terrain elevation, we use the field elevation
727 // (this is also what the apt.dat code does)
728 double fieldElevationM = geod().getElevationM();
729 mTowerPosition = SGGeod::fromDegM(lon, lat, fieldElevationM + elevM);
732 void FGAirport::validateILSData()
734 if (mILSDataLoaded) {
738 // to avoid re-entrancy on this code-path, ensure we set loaded
740 mILSDataLoaded = true;
743 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
744 return; // no XML tower data
748 SGPropertyNode_ptr rootNode = new SGPropertyNode;
749 readProperties(path.str(), rootNode);
750 readILSData(rootNode);
751 } catch (sg_exception& e){
752 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
756 bool FGAirport::hasTower() const
762 void FGAirport::readILSData(SGPropertyNode* aRoot)
764 NavDataCache* cache = NavDataCache::instance();
765 // find the entry matching the runway
766 SGPropertyNode* runwayNode, *ilsNode;
767 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
768 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
769 // must match on both nav-ident and runway ident, to support the following:
770 // - runways with multiple distinct ILS installations (KEWD, for example)
771 // - runways where both ends share the same nav ident (LFAT, for example)
772 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
773 ilsNode->getStringValue("nav-id"));
775 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
776 ", couldn't find runway/navaid for:" <<
777 ilsNode->getStringValue("rwy") << "/" <<
778 ilsNode->getStringValue("nav-id"));
782 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
783 lon = ilsNode->getDoubleValue("lon"),
784 lat = ilsNode->getDoubleValue("lat"),
785 elevM = ilsNode->getDoubleValue("elev-m");
787 FGNavRecordRef nav(FGPositioned::loadById<FGNavRecord>(ils));
789 nav->updateFromXML(SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
790 } // of ILS iteration
791 } // of runway iteration
794 void FGAirport::addSID(flightgear::SID* aSid)
796 mSIDs.push_back(aSid);
799 void FGAirport::addSTAR(STAR* aStar)
801 mSTARs.push_back(aStar);
804 void FGAirport::addApproach(Approach* aApp)
806 mApproaches.push_back(aApp);
809 //------------------------------------------------------------------------------
810 unsigned int FGAirport::numSIDs() const
816 //------------------------------------------------------------------------------
817 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
820 return mSIDs[aIndex];
823 //------------------------------------------------------------------------------
824 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
827 for (unsigned int i=0; i<mSIDs.size(); ++i) {
828 if (mSIDs[i]->ident() == aIdent) {
836 //------------------------------------------------------------------------------
837 flightgear::SIDList FGAirport::getSIDs() const
840 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
843 //------------------------------------------------------------------------------
844 unsigned int FGAirport::numSTARs() const
847 return mSTARs.size();
850 //------------------------------------------------------------------------------
851 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
854 return mSTARs[aIndex];
857 //------------------------------------------------------------------------------
858 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
861 for (unsigned int i=0; i<mSTARs.size(); ++i) {
862 if (mSTARs[i]->ident() == aIdent) {
870 //------------------------------------------------------------------------------
871 STARList FGAirport::getSTARs() const
874 return STARList(mSTARs.begin(), mSTARs.end());
877 unsigned int FGAirport::numApproaches() const
880 return mApproaches.size();
883 //------------------------------------------------------------------------------
884 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
887 return mApproaches[aIndex];
890 //------------------------------------------------------------------------------
891 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
894 for (unsigned int i=0; i<mApproaches.size(); ++i) {
895 if (mApproaches[i]->ident() == aIdent) {
896 return mApproaches[i];
903 //------------------------------------------------------------------------------
904 ApproachList FGAirport::getApproaches(ProcedureType type) const
907 if( type == PROCEDURE_INVALID )
908 return ApproachList(mApproaches.begin(), mApproaches.end());
911 for(size_t i = 0; i < mApproaches.size(); ++i)
913 if( mApproaches[i]->type() == type )
914 ret.push_back(mApproaches[i]);
920 FGAirport::commStations() const
922 NavDataCache* cache = NavDataCache::instance();
923 CommStationList result;
924 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
925 FGPositioned::FREQ_GROUND,
926 FGPositioned::FREQ_UNICOM))
928 result.push_back( loadById<CommStation>(pos) );
935 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
937 NavDataCache* cache = NavDataCache::instance();
938 CommStationList result;
939 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
940 result.push_back( loadById<CommStation>(pos) );
946 class AirportWithSize
949 AirportWithSize(FGPositionedRef pos) :
953 assert(pos->type() == FGPositioned::AIRPORT);
954 FGAirport* apt = static_cast<FGAirport*>(pos.get());
955 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
956 _sizeMetric += static_cast<int>(rwy->lengthFt());
960 bool operator<(const AirportWithSize& other) const
962 return _sizeMetric < other._sizeMetric;
965 FGPositionedRef pos() const
968 FGPositionedRef _pos;
969 unsigned int _sizeMetric;
973 void FGAirport::sortBySize(FGPositionedList& airportList)
975 std::vector<AirportWithSize> annotated;
976 BOOST_FOREACH(FGPositionedRef p, airportList) {
977 annotated.push_back(AirportWithSize(p));
979 std::sort(annotated.begin(), annotated.end());
981 for (unsigned int i=0; i<annotated.size(); ++i) {
982 airportList[i] = annotated[i].pos();
986 // get airport elevation
987 double fgGetAirportElev( const std::string& id )
989 const FGAirport *a=fgFindAirportID( id);
991 return a->getElevation();
998 // get airport position
999 SGGeod fgGetAirportPos( const std::string& id )
1001 const FGAirport *a = fgFindAirportID( id);
1004 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
1006 return SGGeod::fromDegM(0.0, 0.0, -9999.0);