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/airport.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) :
55 FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
56 heading, length, width, surface_code),
59 _displ_thresh(displ_thresh),
65 string FGRunway::reverseIdent(const string& aRunwayIdent)
67 // Helipads don't have a seperate number per end
68 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
72 std::string ident(aRunwayIdent);
75 int rn = atoi(ident.substr(0,2).c_str());
81 sprintf(buf, "%02i", rn);
82 if(ident.size() == 3) {
83 char suffix = toupper(ident[2]);
86 } else if (suffix == 'R') {
89 // something else, just copy
99 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
102 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
104 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
107 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
110 SGGeod FGRunway::begin() const
112 return pointOnCenterline(0.0);
115 SGGeod FGRunway::end() const
117 return pointOnCenterline(lengthM());
120 SGGeod FGRunway::threshold() const
122 return pointOnCenterline(_displ_thresh);
125 void FGRunway::setReciprocalRunway(PositionedID other)
127 assert(_reciprocal==0);
131 FGAirport* FGRunway::airport() const
133 return loadById<FGAirport>(_airport);
136 FGRunway* FGRunway::reciprocalRunway() const
138 return loadById<FGRunway>(_reciprocal);
141 FGNavRecord* FGRunway::ILS() const
147 return loadById<FGNavRecord>(_ils);
150 FGNavRecord* FGRunway::glideslope() const
152 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
153 PositionedID gsId = cache->findNavaidForRunway(guid(), FGPositioned::GS);
158 return loadById<FGNavRecord>(gsId);
161 flightgear::SIDList FGRunway::getSIDs() const
163 FGAirport* apt = airport();
164 flightgear::SIDList result;
165 for (unsigned int i=0; i<apt->numSIDs(); ++i) {
166 flightgear::SID* s = apt->getSIDByIndex(i);
167 if (s->isForRunway(this)) {
170 } // of SIDs at the airport iteration
175 flightgear::STARList FGRunway::getSTARs() const
177 FGAirport* apt = airport();
178 flightgear::STARList result;
179 for (unsigned int i=0; i<apt->numSTARs(); ++i) {
180 flightgear::STAR* s = apt->getSTARByIndex(i);
181 if (s->isForRunway(this)) {
184 } // of STARs at the airport iteration
189 flightgear::ApproachList
190 FGRunway::getApproaches(flightgear::ProcedureType type) const
192 FGAirport* apt = airport();
193 flightgear::ApproachList result;
194 for (unsigned int i=0; i<apt->numApproaches(); ++i)
196 flightgear::Approach* s = apt->getApproachByIndex(i);
197 if( s->runway() == this
198 && (type == flightgear::PROCEDURE_INVALID || type == s->type()) )
202 } // of approaches at the airport iteration
207 FGHelipad::FGHelipad(PositionedID aGuid,
208 PositionedID aAirport, const string& aIdent,
210 const double heading, const double length,
212 const int surface_code) :
213 FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
214 heading, length, width, surface_code)