1 // runways.cxx -- a simple class to manage airport runway info
3 // Written by Curtis Olson, started August 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <cstdio> // sprintf()
29 #include <cstdlib> // atoi()
32 #include <simgear/compiler.h>
34 #include <simgear/props/props.hxx>
38 #include "runways.hxx"
40 #include <Airports/simple.hxx>
41 #include <Navaids/procedure.hxx>
42 #include <Navaids/navrecord.hxx>
43 #include <Navaids/NavDataCache.hxx>
47 FGRunway::FGRunway(PositionedID aGuid,
48 PositionedID aAirport, const string& aIdent,
50 const double heading, const double length,
52 const double displ_thresh,
54 const int surface_code,
56 FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
57 heading, length, width, surface_code),
59 _isReciprocal(reciprocal),
61 _displ_thresh(displ_thresh),
67 string FGRunway::reverseIdent(const string& aRunwayIdent)
69 // Helipads don't have a seperate number per end
70 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
74 std::string ident(aRunwayIdent);
77 int rn = atoi(ident.substr(0,2).c_str());
83 sprintf(buf, "%02i", rn);
84 if(ident.size() == 3) {
85 char suffix = toupper(ident[2]);
88 } else if (suffix == 'R') {
91 // something else, just copy
101 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
104 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
106 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
109 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
112 SGGeod FGRunway::begin() const
114 return pointOnCenterline(0.0);
117 SGGeod FGRunway::end() const
119 return pointOnCenterline(lengthM());
122 SGGeod FGRunway::threshold() const
124 return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
127 void FGRunway::setReciprocalRunway(PositionedID other)
129 assert(_reciprocal==0);
133 FGAirport* FGRunway::airport() const
135 return (FGAirport*) flightgear::NavDataCache::instance()->loadById(_airport);
138 FGRunway* FGRunway::reciprocalRunway() const
140 return (FGRunway*) flightgear::NavDataCache::instance()->loadById(_reciprocal);
143 FGNavRecord* FGRunway::ILS() const
149 return (FGNavRecord*) flightgear::NavDataCache::instance()->loadById(_ils);
152 FGNavRecord* FGRunway::glideslope() const
154 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
155 PositionedID gsId = cache->findNavaidForRunway(guid(), FGPositioned::GS);
160 return (FGNavRecord*) cache->loadById(gsId);
163 std::vector<flightgear::SID*> FGRunway::getSIDs() const
165 FGAirport* apt = airport();
166 std::vector<flightgear::SID*> result;
167 for (unsigned int i=0; i<apt->numSIDs(); ++i) {
168 flightgear::SID* s = apt->getSIDByIndex(i);
169 if (s->isForRunway(this)) {
172 } // of SIDs at the airport iteration
177 std::vector<flightgear::STAR*> FGRunway::getSTARs() const
179 FGAirport* apt = airport();
180 std::vector<flightgear::STAR*> result;
181 for (unsigned int i=0; i<apt->numSTARs(); ++i) {
182 flightgear::STAR* s = apt->getSTARByIndex(i);
183 if (s->isForRunway(this)) {
186 } // of STARs at the airport iteration
191 std::vector<flightgear::Approach*> FGRunway::getApproaches() const
193 FGAirport* apt = airport();
194 std::vector<flightgear::Approach*> result;
195 for (unsigned int i=0; i<apt->numApproaches(); ++i) {
196 flightgear::Approach* s = apt->getApproachByIndex(i);
197 if (s->runway() == this) {
200 } // of approaches at the airport iteration