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