]> git.mxchange.org Git - flightgear.git/blob - src/Airports/runways.cxx
Merge branch 'jmt/cleanup' into next
[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
35 #include <string>
36
37 #include "runways.hxx"
38
39 using std::string;
40
41 static std::string cleanRunwayNo(const std::string& aRwyNo)
42 {
43   if (aRwyNo[0] == 'x') {
44     return std::string(); // no ident for taxiways
45   }
46   
47   string result(aRwyNo);
48   // canonicalise runway ident
49   if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
50           result = "0" + aRwyNo;
51   }
52
53   // trim off trailing garbage
54   if (result.size() > 2) {
55     char suffix = toupper(result[2]);
56     if (suffix == 'X') {
57        result = result.substr(0, 2);
58     }
59   }
60   
61   return result;
62 }
63
64 FGRunway::FGRunway(FGAirport* aAirport, const string& aIdent,
65                         const SGGeod& aGeod,
66                         const double heading, const double length,
67                         const double width,
68                         const double displ_thresh,
69                         const double stopway,
70                         const int surface_code,
71                         bool reciprocal) :
72   FGRunwayBase(RUNWAY, cleanRunwayNo(aIdent), aGeod, heading, length, width, surface_code, true),
73   _airport(aAirport),
74   _isReciprocal(reciprocal),
75   _reciprocal(NULL),
76   _displ_thresh(displ_thresh),
77   _stopway(stopway),
78   _ils(NULL)
79 {
80 }
81
82 string FGRunway::reverseIdent(const string& aRunwayIdent)
83 {
84   // Helipads don't have a seperate number per end
85   if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
86     return aRunwayIdent;
87   }
88
89   std::string ident(aRunwayIdent);
90     
91   char buf[4];
92   int rn = atoi(ident.substr(0,2).c_str());
93   rn += 18;
94   while(rn > 36) {
95           rn -= 36;
96   }
97   
98   sprintf(buf, "%02i", rn);
99   if(ident.size() == 3) {
100     char suffix = toupper(ident[2]);
101     if(suffix == 'L') {
102       buf[2] = 'R';
103     } else if (suffix == 'R') {
104       buf[2] = 'L';
105     } else {
106       // something else, just copy
107       buf[2] = suffix;
108     }
109     
110     buf[3] = 0;
111   }
112   
113   return buf;
114 }
115
116 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
117 {
118   int surface = 1;
119   if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
120     surface = 2;
121   else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
122     surface = 3;
123     
124   return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
125 }
126
127 SGGeod FGRunway::begin() const
128 {
129   return pointOnCenterline(0.0);
130 }
131
132 SGGeod FGRunway::end() const
133 {
134   return pointOnCenterline(lengthM());
135 }
136
137 SGGeod FGRunway::threshold() const
138 {
139   return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
140 }
141
142 void FGRunway::processThreshold(SGPropertyNode* aThreshold)
143 {
144   assert(ident() == aThreshold->getStringValue("rwy"));
145   
146   double lon = aThreshold->getDoubleValue("lon"),
147     lat = aThreshold->getDoubleValue("lat");
148   SGGeod newThreshold(SGGeod::fromDegM(lon, lat, mPosition.getElevationM()));
149   
150   _heading = aThreshold->getDoubleValue("hdg-deg");
151   _displ_thresh = aThreshold->getDoubleValue("displ-m") * SG_METER_TO_FEET;
152   _stopway = aThreshold->getDoubleValue("stopw-m") * SG_METER_TO_FEET;
153   
154   // compute the new runway center, based on the threshold lat/lon, length,
155   // and any displaced threshold.
156   double offsetFt = (0.5 * _length) - _displ_thresh;
157   SGGeod newCenter;
158   double dummy;
159   SGGeodesy::direct(newThreshold, _heading, offsetFt * SG_FEET_TO_METER, newCenter, dummy);
160   mPosition = newCenter;
161
162
163 void FGRunway::setReciprocalRunway(FGRunway* other)
164 {
165   assert(_reciprocal==NULL);
166   assert((other->_reciprocal == NULL) || (other->_reciprocal == this));
167   
168   _reciprocal = other;
169 }
170