]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runways.cxx
c3686bcaca481d9763759b40394628c81e24ee3b
[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 <cstdio>              // sprintf()
29 #include <cstdlib>             // atoi()
30
31 #include <simgear/compiler.h>
32
33 #include <simgear/props/props.hxx>
34 #include <string>
35
36 #include "runways.hxx"
37
38 using std::string;
39
40 static std::string cleanRunwayNo(const std::string& aRwyNo)
41 {
42   if (aRwyNo[0] == 'x') {
43     return std::string(); // no ident for taxiways
44   }
45   
46   string result(aRwyNo);
47   // canonicalise runway ident
48   if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
49           result = "0" + aRwyNo;
50   }
51
52   // trim off trailing garbage
53   if (result.size() > 2) {
54     char suffix = toupper(result[2]);
55     if (suffix == 'X') {
56        result = result.substr(0, 2);
57     }
58   }
59   
60   return result;
61 }
62
63 FGRunway::FGRunway(FGAirport* aAirport, const string& aIdent,
64                         const SGGeod& aGeod,
65                         const double heading, const double length,
66                         const double width,
67                         const double displ_thresh,
68                         const double stopway,
69                         const int surface_code,
70                         bool reciprocal) :
71   FGRunwayBase(RUNWAY, cleanRunwayNo(aIdent), aGeod, heading, length, width, surface_code, true),
72   _airport(aAirport),
73   _reciprocal(reciprocal),
74   _displ_thresh(displ_thresh),
75   _stopway(stopway),
76   _ils(NULL)
77 {
78 }
79
80 string FGRunway::reverseIdent(const string& aRunwayIdent)
81 {
82   // Helipads don't have a seperate number per end
83   if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
84     return aRunwayIdent;
85   }
86
87   std::string ident(aRunwayIdent);
88     
89   char buf[4];
90   int rn = atoi(ident.substr(0,2).c_str());
91   rn += 18;
92   while(rn > 36) {
93           rn -= 36;
94   }
95   
96   sprintf(buf, "%02i", rn);
97   if(ident.size() == 3) {
98     char suffix = toupper(ident[2]);
99     if(suffix == 'L') {
100       buf[2] = 'R';
101     } else if (suffix == 'R') {
102       buf[2] = 'L';
103     } else {
104       // something else, just copy
105       buf[2] = suffix;
106     }
107     
108     buf[3] = 0;
109   }
110   
111   return buf;
112 }
113
114 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
115 {
116   int surface = 1;
117   if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
118     surface = 2;
119   else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
120     surface = 3;
121     
122   return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
123 }
124
125 SGGeod FGRunway::begin() const
126 {
127   return pointOnCenterline(0.0);
128 }
129
130 SGGeod FGRunway::end() const
131 {
132   return pointOnCenterline(lengthM());
133 }
134
135 SGGeod FGRunway::threshold() const
136 {
137   return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
138 }
139
140 void FGRunway::processThreshold(SGPropertyNode* aThreshold)
141 {
142   assert(ident() == aThreshold->getStringValue("rwy"));
143 }