]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runways.cxx
c38d1dc91bc131d62f3c99ae2ce04613ea56b6c5
[flightgear.git] / src / Airports / runways.cxx
1 // runways.cxx -- a simple class to manage airport runway info
2 //
3 // Written by Curtis Olson, started August 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <cmath>               // fabs()
29 #include <cstdio>              // sprintf()
30 #include <cstdlib>             // atoi()
31
32 #include <simgear/compiler.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <Main/fg_props.hxx>
35
36 #include <string>
37 #include <map>
38
39 #include "runways.hxx"
40
41 using std::istream;
42 using std::multimap;
43 using std::string;
44
45 /*
46  * surface codes
47  * 1 - asphalt
48  * 2 - concrete
49  * 3 - turf
50  * 4 - dirt
51  * 5 - gravel
52  * 6 - asphalt helipad
53  * 7 - concrete helipad
54  * 8 - turf helipad
55  * 9 - dirt helipad
56  * 12 -  lakebed
57  */
58  
59 static FGPositioned::Type runwayTypeFromNumber(const std::string& aRwyNo)
60 {
61   return (aRwyNo[0] == 'x') ? FGPositioned::TAXIWAY : FGPositioned::RUNWAY;
62 }
63
64 static std::string cleanRunwayNo(const std::string& aRwyNo)
65 {
66   if (aRwyNo[0] == 'x') {
67     return std::string(); // no ident for taxiways
68   }
69   
70   string result(aRwyNo);
71   // canonicalise runway ident
72   if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
73           result = "0" + aRwyNo;
74   }
75
76   // trim off trailing garbage
77   if (result.size() > 2) {
78     char suffix = toupper(result[2]);
79     if (suffix == 'X') {
80        result = result.substr(0, 2);
81     }
82   }
83   
84   return result;
85 }
86
87 FGRunway::FGRunway(FGAirport* aAirport, const string& rwy_no,
88                         const SGGeod& aGeod,
89                         const double heading, const double length,
90                         const double width,
91                         const double displ_thresh,
92                         const double stopway,
93                         const int surface_code,
94                         bool reciprocal) :
95   FGPositioned(runwayTypeFromNumber(rwy_no), cleanRunwayNo(rwy_no), aGeod, 
96     (runwayTypeFromNumber(rwy_no) == FGPositioned::RUNWAY)),
97   _airport(aAirport),
98   _reciprocal(reciprocal)
99 {
100   _heading = heading;
101   _length = length;
102   _width = width;
103   _displ_thresh = displ_thresh;
104   _stopway = stopway;
105
106   _surface_code = surface_code;
107 }
108
109 string FGRunway::reverseIdent(const string& aRunwayIdent)
110 {
111   // Helipads don't have a seperate number per end
112   if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
113     return aRunwayIdent;
114   }
115
116   std::string ident(aRunwayIdent);
117     
118   char buf[4];
119   int rn = atoi(ident.substr(0,2).c_str());
120   rn += 18;
121   while(rn > 36) {
122           rn -= 36;
123   }
124   
125   sprintf(buf, "%02i", rn);
126   if(ident.size() == 3) {
127     char suffix = toupper(ident[2]);
128     if(suffix == 'L') {
129       buf[2] = 'R';
130     } else if (suffix == 'R') {
131       buf[2] = 'L';
132     } else {
133       // something else, just copy
134       buf[2] = suffix;
135     }
136     
137     buf[3] = 0;
138   }
139   
140   return buf;
141 }
142
143 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
144 {
145   int surface = 1;
146   if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
147     surface = 2;
148   else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
149     surface = 3;
150     
151   return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
152 }
153
154 bool FGRunway::isTaxiway() const
155 {
156   return (type() == TAXIWAY);
157 }
158
159 SGGeod FGRunway::threshold() const
160 {
161   return pointOnCenterline(0.0);
162 }
163
164 SGGeod FGRunway::reverseThreshold() const
165 {
166   return pointOnCenterline(lengthM());
167 }
168
169 SGGeod FGRunway::displacedThreshold() const
170 {
171   return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
172 }
173
174 SGGeod FGRunway::pointOnCenterline(double aOffset) const
175 {
176   SGGeod result;
177   double dummyAz2;
178   double halfLengthMetres = lengthM() * 0.5;
179   
180   SGGeodesy::direct(mPosition, _heading, 
181     aOffset - halfLengthMetres,
182     result, dummyAz2);
183   return result;
184 }
185
186 bool FGRunway::isHardSurface() const
187 {
188   return ((_surface_code == 1) || (_surface_code == 2));
189 }
190