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