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