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>
59 using namespace flightgear;
61 /***************************************************************************
63 ***************************************************************************/
65 AirportCache FGAirport::airportCache;
67 FGAirport::FGAirport( PositionedID aGuid,
68 const std::string &id,
69 const SGGeod& location,
70 const std::string &name,
73 FGPositioned(aGuid, aType, id, location),
75 _has_metar(has_metar),
77 mTowerDataLoaded(false),
78 mRunwaysLoaded(false),
79 mHelipadsLoaded(false),
80 mTaxiwaysLoaded(false),
81 mProceduresLoaded(false),
87 FGAirport::~FGAirport()
92 bool FGAirport::isAirport() const
94 return type() == AIRPORT;
97 bool FGAirport::isSeaport() const
99 return type() == SEAPORT;
102 bool FGAirport::isHeliport() const
104 return type() == HELIPORT;
107 bool FGAirport::isAirportType(FGPositioned* pos)
113 return (pos->type() >= AIRPORT) && (pos->type() <= SEAPORT);
116 FGAirportDynamics * FGAirport::getDynamics()
122 _dynamics = new FGAirportDynamics(this);
123 XMLLoader::load(_dynamics);
126 FGRunwayPreference rwyPrefs(this);
127 XMLLoader::load(&rwyPrefs);
128 _dynamics->setRwyUse(rwyPrefs);
133 //------------------------------------------------------------------------------
134 unsigned int FGAirport::numRunways() const
137 return mRunways.size();
140 //------------------------------------------------------------------------------
141 unsigned int FGAirport::numHelipads() const
144 return mHelipads.size();
147 //------------------------------------------------------------------------------
148 FGRunwayRef FGAirport::getRunwayByIndex(unsigned int aIndex) const
151 return loadById<FGRunway>(mRunways, aIndex);
154 //------------------------------------------------------------------------------
155 FGHelipadRef FGAirport::getHelipadByIndex(unsigned int aIndex) const
158 return loadById<FGHelipad>(mHelipads, aIndex);
161 //------------------------------------------------------------------------------
162 FGRunwayMap FGAirport::getRunwayMap() const
167 double minLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft");
169 BOOST_FOREACH(PositionedID id, mRunways)
171 FGRunway* rwy = loadById<FGRunway>(id);
173 // ignore unusably short runways
174 // TODO other methods don't check this...
175 if( rwy->lengthFt() >= minLengthFt )
176 map[ rwy->ident() ] = rwy;
182 //------------------------------------------------------------------------------
183 FGHelipadMap FGAirport::getHelipadMap() const
188 BOOST_FOREACH(PositionedID id, mHelipads)
190 FGHelipad* rwy = loadById<FGHelipad>(id);
191 map[ rwy->ident() ] = rwy;
197 //------------------------------------------------------------------------------
198 bool FGAirport::hasRunwayWithIdent(const std::string& aIdent) const
200 return flightgear::NavDataCache::instance()
201 ->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent) != 0;
204 //------------------------------------------------------------------------------
205 bool FGAirport::hasHelipadWithIdent(const std::string& aIdent) const
207 return flightgear::NavDataCache::instance()
208 ->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent) != 0;
211 //------------------------------------------------------------------------------
212 FGRunwayRef FGAirport::getRunwayByIdent(const std::string& aIdent) const
215 flightgear::NavDataCache::instance()
216 ->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent);
219 SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
220 throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
223 return loadById<FGRunway>(id);
226 //------------------------------------------------------------------------------
227 FGHelipadRef FGAirport::getHelipadByIdent(const std::string& aIdent) const
229 PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::HELIPAD, aIdent);
231 SG_LOG(SG_GENERAL, SG_ALERT, "no such helipad '" << aIdent << "' at airport " << ident());
232 throw sg_range_exception("unknown helipad " + aIdent + " at airport:" + ident(), "FGAirport::getRunwayByIdent");
235 return loadById<FGHelipad>(id);
238 //------------------------------------------------------------------------------
239 FGRunwayRef FGAirport::findBestRunwayForHeading(double aHeading, struct FindBestRunwayForHeadingParams * parms ) const
243 FGRunway* result = NULL;
244 double currentBestQuality = 0.0;
246 struct FindBestRunwayForHeadingParams fbrfhp;
247 if( NULL != parms ) fbrfhp = *parms;
249 SGPropertyNode_ptr searchNode = fgGetNode("/sim/airport/runways/search");
250 if( searchNode.valid() ) {
251 fbrfhp.lengthWeight = searchNode->getDoubleValue("length-weight", fbrfhp.lengthWeight );
252 fbrfhp.widthWeight = searchNode->getDoubleValue("width-weight", fbrfhp.widthWeight );
253 fbrfhp.surfaceWeight = searchNode->getDoubleValue("surface-weight", fbrfhp.surfaceWeight );
254 fbrfhp.deviationWeight = searchNode->getDoubleValue("deviation-weight", fbrfhp.deviationWeight );
255 fbrfhp.ilsWeight = searchNode->getDoubleValue("ils-weight", fbrfhp.ilsWeight );
258 BOOST_FOREACH(PositionedID id, mRunways) {
259 FGRunway* rwy = loadById<FGRunway>(id);
260 // bug http://code.google.com/p/flightgear-bugs/issues/detail?id=1149
261 // (and probably some other issues besides).
262 if (rwy->type() == FGPositioned::HELIPAD) {
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(PositionedID id, mRunways) {
290 FGRunway* rwy = loadById<FGRunway>(id);
292 double inboundCourse = SGGeodesy::courseDeg(aPos, rwy->end());
293 double dev = inboundCourse - rwy->headingDeg();
294 SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
297 if (dev < currentLowestDev) { // new best match
298 currentLowestDev = dev;
301 } // of runway iteration
307 //------------------------------------------------------------------------------
308 bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
312 BOOST_FOREACH(PositionedID id, mRunways) {
313 FGRunway* rwy = loadById<FGRunway>(id);
314 if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
315 return true; // we're done!
317 } // of runways iteration
322 //------------------------------------------------------------------------------
323 FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
329 BOOST_FOREACH(PositionedID id, mRunways) {
330 FGRunway* rwy = loadById<FGRunway>(id);
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 void FGAirport::loadRunways() const
513 if (mRunwaysLoaded) {
514 return; // already loaded, great
517 loadSceneryDefinitions();
519 mRunwaysLoaded = true;
520 mRunways = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::RUNWAY);
523 void FGAirport::loadHelipads() const
525 if (mHelipadsLoaded) {
526 return; // already loaded, great
529 loadSceneryDefinitions();
531 mHelipadsLoaded = true;
532 mHelipads = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::HELIPAD);
535 void FGAirport::loadTaxiways() const
537 if (mTaxiwaysLoaded) {
538 return; // already loaded, great
541 mTaxiwaysLoaded = true;
542 mTaxiways = flightgear::NavDataCache::instance()->airportItemsOfType(guid(), FGPositioned::TAXIWAY);
545 void FGAirport::loadProcedures() const
547 if (mProceduresLoaded) {
551 mProceduresLoaded = true;
553 if (!XMLLoader::findAirportData(ident(), "procedures", path)) {
554 SG_LOG(SG_GENERAL, SG_INFO, "no procedures data available for " << ident());
558 SG_LOG(SG_GENERAL, SG_INFO, ident() << ": loading procedures from " << path.str());
559 RouteBase::loadAirportProcedures(path, const_cast<FGAirport*>(this));
562 void FGAirport::loadSceneryDefinitions() const
564 NavDataCache* cache = NavDataCache::instance();
565 if (cache->isReadOnly()) {
570 if (!XMLLoader::findAirportData(ident(), "threshold", path)) {
571 return; // no XML threshold data
574 if (!cache->isCachedFileModified(path)) {
575 // cached values are correct, we're all done
580 flightgear::NavDataCache::Transaction txn(cache);
581 SGPropertyNode_ptr rootNode = new SGPropertyNode;
582 readProperties(path.str(), rootNode);
583 const_cast<FGAirport*>(this)->readThresholdData(rootNode);
584 cache->stampCacheFile(path);
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 SG_LOG(SG_GENERAL, SG_DEBUG, "FGAirport::processThreshold: "
614 "found runway not defined in the global data:" << ident() << "/" << rwyIdent);
618 double lon = aThreshold->getDoubleValue("lon"),
619 lat = aThreshold->getDoubleValue("lat");
620 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, elevationM()));
622 double newHeading = aThreshold->getDoubleValue("hdg-deg");
623 double newDisplacedThreshold = aThreshold->getDoubleValue("displ-m");
624 double newStopway = aThreshold->getDoubleValue("stopw-m");
626 cache->updateRunwayThreshold(id, newThreshold,
627 newHeading, newDisplacedThreshold, newStopway);
630 SGGeod FGAirport::getTowerLocation() const
634 NavDataCache* cache = NavDataCache::instance();
635 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
636 if (towers.empty()) {
637 SG_LOG(SG_GENERAL, SG_ALERT, "No towers defined for:" <<ident());
641 FGPositionedRef tower = cache->loadById(towers.front());
642 return tower->geod();
645 void FGAirport::validateTowerData() const
647 if (mTowerDataLoaded) {
651 mTowerDataLoaded = true;
652 NavDataCache* cache = NavDataCache::instance();
653 if (cache->isReadOnly()) {
658 if (!XMLLoader::findAirportData(ident(), "twr", path)) {
659 return; // no XML tower data
662 if (!cache->isCachedFileModified(path)) {
663 // cached values are correct, we're all done
668 flightgear::NavDataCache::Transaction txn(cache);
669 SGPropertyNode_ptr rootNode = new SGPropertyNode;
670 readProperties(path.str(), rootNode);
671 const_cast<FGAirport*>(this)->readTowerData(rootNode);
672 cache->stampCacheFile(path);
674 } catch (sg_exception& e){
675 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading twr XML failed:" << e.getFormattedMessage());
679 void FGAirport::readTowerData(SGPropertyNode* aRoot)
681 SGPropertyNode* twrNode = aRoot->getChild("tower")->getChild("twr");
682 double lat = twrNode->getDoubleValue("lat"),
683 lon = twrNode->getDoubleValue("lon"),
684 elevM = twrNode->getDoubleValue("elev-m");
685 // tower elevation is AGL, not AMSL. Since we don't want to depend on the
686 // scenery for a precise terrain elevation, we use the field elevation
687 // (this is also what the apt.dat code does)
688 double fieldElevationM = elevationM();
689 SGGeod towerLocation(SGGeod::fromDegM(lon, lat, fieldElevationM + elevM));
691 NavDataCache* cache = NavDataCache::instance();
692 PositionedIDVec towers = cache->airportItemsOfType(guid(), FGPositioned::TOWER);
693 if (towers.empty()) {
694 cache->insertTower(guid(), towerLocation);
696 // update the position
697 cache->updatePosition(towers.front(), towerLocation);
701 bool FGAirport::validateILSData()
703 if (mILSDataLoaded) {
707 mILSDataLoaded = true;
708 NavDataCache* cache = NavDataCache::instance();
709 if (cache->isReadOnly()) {
714 if (!XMLLoader::findAirportData(ident(), "ils", path)) {
715 return false; // no XML tower data
718 if (!cache->isCachedFileModified(path)) {
719 // cached values are correct, we're all done
724 SGPropertyNode_ptr rootNode = new SGPropertyNode;
725 readProperties(path.str(), rootNode);
727 flightgear::NavDataCache::Transaction txn(cache);
728 readILSData(rootNode);
729 cache->stampCacheFile(path);
731 // we loaded data, tell the caller it might need to reload things
733 } catch (sg_exception& e){
734 SG_LOG(SG_NAVAID, SG_WARN, ident() << "loading ils XML failed:" << e.getFormattedMessage());
740 void FGAirport::readILSData(SGPropertyNode* aRoot)
742 NavDataCache* cache = NavDataCache::instance();
744 // find the entry matching the runway
745 SGPropertyNode* runwayNode, *ilsNode;
746 for (int i=0; (runwayNode = aRoot->getChild("runway", i)) != NULL; ++i) {
747 for (int j=0; (ilsNode = runwayNode->getChild("ils", j)) != NULL; ++j) {
748 // must match on both nav-ident and runway ident, to support the following:
749 // - runways with multiple distinct ILS installations (KEWD, for example)
750 // - runways where both ends share the same nav ident (LFAT, for example)
751 PositionedID ils = cache->findILS(guid(), ilsNode->getStringValue("rwy"),
752 ilsNode->getStringValue("nav-id"));
754 SG_LOG(SG_GENERAL, SG_INFO, "reading ILS data for " << ident() <<
755 ", couldn;t find runway/navaid for:" <<
756 ilsNode->getStringValue("rwy") << "/" <<
757 ilsNode->getStringValue("nav-id"));
761 double hdgDeg = ilsNode->getDoubleValue("hdg-deg"),
762 lon = ilsNode->getDoubleValue("lon"),
763 lat = ilsNode->getDoubleValue("lat"),
764 elevM = ilsNode->getDoubleValue("elev-m");
766 cache->updateILS(ils, SGGeod::fromDegM(lon, lat, elevM), hdgDeg);
767 } // of ILS iteration
768 } // of runway iteration
771 void FGAirport::addSID(flightgear::SID* aSid)
773 mSIDs.push_back(aSid);
776 void FGAirport::addSTAR(STAR* aStar)
778 mSTARs.push_back(aStar);
781 void FGAirport::addApproach(Approach* aApp)
783 mApproaches.push_back(aApp);
786 //------------------------------------------------------------------------------
787 unsigned int FGAirport::numSIDs() const
793 //------------------------------------------------------------------------------
794 flightgear::SID* FGAirport::getSIDByIndex(unsigned int aIndex) const
797 return mSIDs[aIndex];
800 //------------------------------------------------------------------------------
801 flightgear::SID* FGAirport::findSIDWithIdent(const std::string& aIdent) const
804 for (unsigned int i=0; i<mSIDs.size(); ++i) {
805 if (mSIDs[i]->ident() == aIdent) {
813 //------------------------------------------------------------------------------
814 flightgear::SIDList FGAirport::getSIDs() const
817 return flightgear::SIDList(mSIDs.begin(), mSIDs.end());
820 //------------------------------------------------------------------------------
821 unsigned int FGAirport::numSTARs() const
824 return mSTARs.size();
827 //------------------------------------------------------------------------------
828 STAR* FGAirport::getSTARByIndex(unsigned int aIndex) const
831 return mSTARs[aIndex];
834 //------------------------------------------------------------------------------
835 STAR* FGAirport::findSTARWithIdent(const std::string& aIdent) const
838 for (unsigned int i=0; i<mSTARs.size(); ++i) {
839 if (mSTARs[i]->ident() == aIdent) {
847 //------------------------------------------------------------------------------
848 STARList FGAirport::getSTARs() const
851 return STARList(mSTARs.begin(), mSTARs.end());
854 unsigned int FGAirport::numApproaches() const
857 return mApproaches.size();
860 //------------------------------------------------------------------------------
861 Approach* FGAirport::getApproachByIndex(unsigned int aIndex) const
864 return mApproaches[aIndex];
867 //------------------------------------------------------------------------------
868 Approach* FGAirport::findApproachWithIdent(const std::string& aIdent) const
871 for (unsigned int i=0; i<mApproaches.size(); ++i) {
872 if (mApproaches[i]->ident() == aIdent) {
873 return mApproaches[i];
880 //------------------------------------------------------------------------------
881 ApproachList FGAirport::getApproaches(ProcedureType type) const
884 if( type == PROCEDURE_INVALID )
885 return ApproachList(mApproaches.begin(), mApproaches.end());
888 for(size_t i = 0; i < mApproaches.size(); ++i)
890 if( mApproaches[i]->type() == type )
891 ret.push_back(mApproaches[i]);
897 FGAirport::commStations() const
899 NavDataCache* cache = NavDataCache::instance();
900 CommStationList result;
901 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(),
902 FGPositioned::FREQ_GROUND,
903 FGPositioned::FREQ_UNICOM))
905 result.push_back( loadById<CommStation>(pos) );
912 FGAirport::commStationsOfType(FGPositioned::Type aTy) const
914 NavDataCache* cache = NavDataCache::instance();
915 CommStationList result;
916 BOOST_FOREACH(PositionedID pos, cache->airportItemsOfType(guid(), aTy)) {
917 result.push_back( loadById<CommStation>(pos) );
923 class AirportWithSize
926 AirportWithSize(FGPositionedRef pos) :
930 assert(pos->type() == FGPositioned::AIRPORT);
931 FGAirport* apt = static_cast<FGAirport*>(pos.get());
932 BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
933 _sizeMetric += static_cast<int>(rwy->lengthFt());
937 bool operator<(const AirportWithSize& other) const
939 return _sizeMetric < other._sizeMetric;
942 FGPositionedRef pos() const
945 FGPositionedRef _pos;
946 unsigned int _sizeMetric;
950 void FGAirport::sortBySize(FGPositionedList& airportList)
952 std::vector<AirportWithSize> annotated;
953 BOOST_FOREACH(FGPositionedRef p, airportList) {
954 annotated.push_back(AirportWithSize(p));
956 std::sort(annotated.begin(), annotated.end());
958 for (unsigned int i=0; i<annotated.size(); ++i) {
959 airportList[i] = annotated[i].pos();
963 // get airport elevation
964 double fgGetAirportElev( const std::string& id )
966 const FGAirport *a=fgFindAirportID( id);
968 return a->getElevation();
975 // get airport position
976 SGGeod fgGetAirportPos( const std::string& id )
978 const FGAirport *a = fgFindAirportID( id);
981 return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
983 return SGGeod::fromDegM(0.0, 0.0, -9999.0);