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