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()
31 #include <simgear/compiler.h>
33 #include <simgear/props/props.hxx>
37 #include "runways.hxx"
41 static std::string cleanRunwayNo(const std::string& aRwyNo)
43 if (aRwyNo[0] == 'x') {
44 return std::string(); // no ident for taxiways
47 string result(aRwyNo);
48 // canonicalise runway ident
49 if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
50 result = "0" + aRwyNo;
53 // trim off trailing garbage
54 if (result.size() > 2) {
55 char suffix = toupper(result[2]);
57 result = result.substr(0, 2);
64 FGRunway::FGRunway(FGAirport* aAirport, const string& aIdent,
66 const double heading, const double length,
68 const double displ_thresh,
70 const int surface_code,
72 FGRunwayBase(RUNWAY, cleanRunwayNo(aIdent), aGeod, heading, length, width, surface_code, true),
74 _reciprocal(reciprocal),
75 _displ_thresh(displ_thresh),
81 string FGRunway::reverseIdent(const string& aRunwayIdent)
83 // Helipads don't have a seperate number per end
84 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
88 std::string ident(aRunwayIdent);
91 int rn = atoi(ident.substr(0,2).c_str());
97 sprintf(buf, "%02i", rn);
98 if(ident.size() == 3) {
99 char suffix = toupper(ident[2]);
102 } else if (suffix == 'R') {
105 // something else, just copy
115 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
118 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
120 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
123 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
126 SGGeod FGRunway::begin() const
128 return pointOnCenterline(0.0);
131 SGGeod FGRunway::end() const
133 return pointOnCenterline(lengthM());
136 SGGeod FGRunway::threshold() const
138 return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
141 void FGRunway::processThreshold(SGPropertyNode* aThreshold)
143 assert(ident() == aThreshold->getStringValue("rwy"));
145 double lon = aThreshold->getDoubleValue("lon"),
146 lat = aThreshold->getDoubleValue("lat");
147 SGGeod newThreshold(SGGeod::fromDegM(lon, lat, mPosition.getElevationM()));
149 _heading = aThreshold->getDoubleValue("hdg-deg");
150 _displ_thresh = aThreshold->getDoubleValue("displ-m") * SG_METER_TO_FEET;
151 _stopway = aThreshold->getDoubleValue("stopw-m") * SG_METER_TO_FEET;
153 // compute the new runway center, based on the threshold lat/lon, length,
154 // and any displaced threshold.
155 double offsetFt = (0.5 * _length) - _displ_thresh;
158 SGGeodesy::direct(newThreshold, _heading, offsetFt * SG_FEET_TO_METER, newCenter, dummy);
159 mPosition = newCenter;