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