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, double aIlsWt) const
102 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
104 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
107 int ils = (_ils != 0);
109 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + ils * aIlsWt + 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);
127 void FGRunway::setReciprocalRunway(PositionedID other)
129 assert(_reciprocal==0);
133 FGAirport* FGRunway::airport() const
135 return loadById<FGAirport>(_airport);
138 FGRunway* FGRunway::reciprocalRunway() const
140 return loadById<FGRunway>(_reciprocal);
143 FGNavRecord* FGRunway::ILS() const
149 return loadById<FGNavRecord>(_ils);
152 FGNavRecord* FGRunway::glideslope() const
154 flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
155 PositionedID gsId = cache->findNavaidForRunway(guid(), FGPositioned::GS);
160 return loadById<FGNavRecord>(gsId);
163 flightgear::SIDList FGRunway::getSIDs() const
165 FGAirport* apt = airport();
166 flightgear::SIDList 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 flightgear::STARList FGRunway::getSTARs() const
179 FGAirport* apt = airport();
180 flightgear::STARList 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 flightgear::ApproachList
192 FGRunway::getApproaches(flightgear::ProcedureType type) const
194 FGAirport* apt = airport();
195 flightgear::ApproachList result;
196 for (unsigned int i=0; i<apt->numApproaches(); ++i)
198 flightgear::Approach* s = apt->getApproachByIndex(i);
199 if( s->runway() == this
200 && (type == flightgear::PROCEDURE_INVALID || type == s->type()) )
204 } // of approaches at the airport iteration
209 void FGRunway::updateThreshold(const SGGeod& newThreshold, double newHeading,
210 double newDisplacedThreshold,
213 modifyPosition(newThreshold);
214 _heading = newHeading;
215 _stopway = newStopway;
216 _displ_thresh = newDisplacedThreshold;
219 FGHelipad::FGHelipad(PositionedID aGuid,
220 PositionedID aAirport, const string& aIdent,
222 const double heading, const double length,
224 const int surface_code) :
225 FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
226 heading, length, width, surface_code)