2003-03-05 18:02:24 +00:00
|
|
|
// runways.cxx -- a simple class to manage airport runway info
|
2000-08-16 01:28:33 +00:00
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started August 2000.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
|
2000-08-16 01:28:33 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-08-16 01:28:33 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-11-08 16:52:51 +00:00
|
|
|
#include <math.h> // fabs()
|
2001-11-07 17:55:28 +00:00
|
|
|
#include <stdio.h> // sprintf()
|
2000-08-16 01:28:33 +00:00
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
|
|
|
#include STL_STRING
|
2003-08-29 04:11:23 +00:00
|
|
|
#include <map>
|
2000-08-16 01:28:33 +00:00
|
|
|
|
|
|
|
#include "runways.hxx"
|
|
|
|
|
2001-03-23 22:59:18 +00:00
|
|
|
SG_USING_NAMESPACE(std);
|
2002-04-04 06:05:51 +00:00
|
|
|
SG_USING_STD(istream);
|
2003-08-29 04:11:23 +00:00
|
|
|
SG_USING_STD(multimap);
|
2000-08-16 01:28:33 +00:00
|
|
|
|
|
|
|
|
2004-12-22 23:57:07 +00:00
|
|
|
// add an entry to the list
|
2005-10-25 13:49:55 +00:00
|
|
|
void FGRunwayList::add( const string& id, const string& rwy_no,
|
2004-12-22 23:57:07 +00:00
|
|
|
const double longitude, const double latitude,
|
|
|
|
const double heading, const double length,
|
|
|
|
const double width,
|
|
|
|
const double displ_thresh1, const double displ_thresh2,
|
|
|
|
const double stopway1, const double stopway2,
|
2005-10-25 13:49:55 +00:00
|
|
|
const string& lighting_flags, const int surface_code,
|
|
|
|
const string& shoulder_code, const int marking_code,
|
2004-12-22 23:57:07 +00:00
|
|
|
const double smoothness, const bool dist_remaining )
|
|
|
|
{
|
|
|
|
FGRunway rwy;
|
2000-08-16 01:28:33 +00:00
|
|
|
|
2004-12-22 23:57:07 +00:00
|
|
|
rwy._id = id;
|
|
|
|
rwy._rwy_no = rwy_no;
|
|
|
|
// strip trailing "x" if it exists in runway number
|
|
|
|
string tmp = rwy._rwy_no.substr(2, 1);
|
|
|
|
if ( tmp == "x" ) {
|
|
|
|
rwy._rwy_no = rwy._rwy_no.substr(0, 2);
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|
|
|
|
|
2004-12-22 23:57:07 +00:00
|
|
|
rwy._lon = longitude;
|
|
|
|
rwy._lat = latitude;
|
|
|
|
rwy._heading = heading;
|
|
|
|
rwy._length = length;
|
|
|
|
rwy._width = width;
|
|
|
|
rwy._displ_thresh1 = displ_thresh1;
|
|
|
|
rwy._displ_thresh2 = displ_thresh2;
|
|
|
|
rwy._stopway1 = stopway1;
|
|
|
|
rwy._stopway2 = stopway2;
|
|
|
|
|
|
|
|
rwy._lighting_flags = lighting_flags;
|
|
|
|
rwy._surface_code = surface_code;
|
|
|
|
rwy._shoulder_code = shoulder_code;
|
|
|
|
rwy._marking_code = marking_code;
|
|
|
|
rwy._smoothness = smoothness;
|
|
|
|
rwy._dist_remaining = dist_remaining;
|
|
|
|
|
2007-09-09 23:21:48 +00:00
|
|
|
if ( rwy_no[0] == 'x' ) {
|
2004-12-22 23:57:07 +00:00
|
|
|
rwy._type = "taxiway";
|
|
|
|
} else {
|
|
|
|
rwy._type = "runway";
|
2003-08-29 04:11:23 +00:00
|
|
|
}
|
2007-09-09 23:21:48 +00:00
|
|
|
runways.insert(pair<const string, FGRunway>(rwy._id, rwy));
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-20 09:38:06 +00:00
|
|
|
// Return reverse rwy number
|
|
|
|
// eg 01 -> 19
|
|
|
|
// 03L -> 21R
|
2005-10-25 13:49:55 +00:00
|
|
|
static string GetReverseRunwayNo(string& rwyno) {
|
2003-03-20 09:38:06 +00:00
|
|
|
// cout << "Original rwyno = " << rwyNo << '\n';
|
|
|
|
|
2006-03-12 21:10:34 +00:00
|
|
|
// Helipads don't have a seperate number per end
|
2007-09-09 23:21:48 +00:00
|
|
|
if(rwyno.size() && (rwyno[0] == 'H' || rwyno[0] == 'h' || rwyno[0] == 'x')) {
|
2006-03-12 21:10:34 +00:00
|
|
|
return rwyno;
|
|
|
|
}
|
|
|
|
|
2003-03-20 09:38:06 +00:00
|
|
|
// standardize input number
|
|
|
|
string tmp = rwyno.substr(1, 1);
|
|
|
|
if (( tmp == "L" || tmp == "R" || tmp == "C" ) || (rwyno.size() == 1)) {
|
|
|
|
tmp = rwyno;
|
|
|
|
rwyno = "0" + tmp;
|
2004-05-28 16:24:43 +00:00
|
|
|
SG_LOG( SG_GENERAL, SG_INFO,
|
|
|
|
"Standardising rwy number from " << tmp << " to " << rwyno );
|
2003-03-20 09:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char buf[4];
|
|
|
|
int rn = atoi(rwyno.substr(0,2).c_str());
|
|
|
|
rn += 18;
|
|
|
|
while(rn > 36) {
|
|
|
|
rn -= 36;
|
|
|
|
}
|
|
|
|
sprintf(buf, "%02i", rn);
|
|
|
|
if(rwyno.size() == 3) {
|
|
|
|
if(rwyno.substr(2,1) == "L") {
|
|
|
|
buf[2] = 'R';
|
|
|
|
buf[3] = '\0';
|
|
|
|
} else if (rwyno.substr(2,1) == "R") {
|
|
|
|
buf[2] = 'L';
|
|
|
|
buf[3] = '\0';
|
|
|
|
} else if (rwyno.substr(2,1) == "C") {
|
|
|
|
buf[2] = 'C';
|
|
|
|
buf[3] = '\0';
|
2004-05-28 16:24:43 +00:00
|
|
|
} else if (rwyno.substr(2,1) == "T") {
|
|
|
|
buf[2] = 'T';
|
|
|
|
buf[3] = '\0';
|
2003-03-20 09:38:06 +00:00
|
|
|
} else {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code "
|
|
|
|
<< rwyno << " passed to GetReverseRunwayNo(...)");
|
|
|
|
}
|
|
|
|
}
|
2003-10-16 14:14:03 +00:00
|
|
|
return(buf);
|
2003-03-20 09:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
// search for the specified apt id (wierd!)
|
|
|
|
bool FGRunwayList::search( const string& aptid, FGRunway* r ) {
|
|
|
|
runway_map_iterator pos;
|
2000-08-16 01:28:33 +00:00
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
pos = runways.lower_bound(aptid);
|
|
|
|
if ( pos != runways.end() ) {
|
|
|
|
current = pos;
|
|
|
|
*r = pos->second;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-15 00:00:08 +00:00
|
|
|
// search for the specified apt id and runway no
|
2003-08-29 04:11:23 +00:00
|
|
|
bool FGRunwayList::search( const string& aptid, const string& rwyno,
|
|
|
|
FGRunway *r )
|
2001-05-15 00:00:08 +00:00
|
|
|
{
|
2004-02-25 02:16:36 +00:00
|
|
|
string revrwyno = "";
|
2003-08-29 04:11:23 +00:00
|
|
|
string runwayno = rwyno;
|
2004-02-25 02:16:36 +00:00
|
|
|
if ( runwayno.length() ) {
|
|
|
|
// standardize input number
|
|
|
|
string tmp = runwayno.substr(1, 1);
|
|
|
|
if (( tmp == "L" || tmp == "R" || tmp == "C" )
|
|
|
|
|| (runwayno.size() == 1))
|
|
|
|
{
|
|
|
|
tmp = runwayno;
|
|
|
|
runwayno = "0" + tmp;
|
|
|
|
SG_LOG( SG_GENERAL, SG_INFO, "Standardising rwy number from "
|
|
|
|
<< tmp << " to " << runwayno );
|
|
|
|
}
|
|
|
|
revrwyno = GetReverseRunwayNo(runwayno);
|
2003-03-20 09:38:06 +00:00
|
|
|
}
|
2003-08-29 04:11:23 +00:00
|
|
|
runway_map_iterator pos;
|
|
|
|
for ( pos = runways.lower_bound( aptid );
|
|
|
|
pos != runways.upper_bound( aptid ); ++pos)
|
|
|
|
{
|
2004-12-22 23:57:07 +00:00
|
|
|
if ( pos->second._rwy_no == runwayno ) {
|
2003-08-29 04:11:23 +00:00
|
|
|
current = pos;
|
|
|
|
*r = pos->second;
|
|
|
|
return true;
|
2004-12-22 23:57:07 +00:00
|
|
|
} else if ( pos->second._rwy_no == revrwyno ) {
|
2003-08-29 04:11:23 +00:00
|
|
|
// Search again with the other-end runway number.
|
|
|
|
// Remember we have to munge the heading and rwy_no
|
|
|
|
// results if this one matches
|
|
|
|
current = pos;
|
|
|
|
*r = pos->second;
|
2003-09-02 19:12:11 +00:00
|
|
|
// NOTE - matching revrwyno implies that runwayno was
|
|
|
|
// actually correct.
|
2004-12-22 23:57:07 +00:00
|
|
|
r->_rwy_no = runwayno;
|
|
|
|
r->_heading += 180.0;
|
2001-05-15 00:00:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
// (wierd!)
|
|
|
|
FGRunway FGRunwayList::search( const string& aptid ) {
|
2000-08-16 01:28:33 +00:00
|
|
|
FGRunway a;
|
2001-05-15 00:00:08 +00:00
|
|
|
search( aptid, &a );
|
2000-08-16 01:28:33 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:55:28 +00:00
|
|
|
// Return the runway closest to a given heading
|
2003-08-29 04:11:23 +00:00
|
|
|
bool FGRunwayList::search( const string& aptid, const int tgt_hdg,
|
|
|
|
FGRunway *runway )
|
2001-11-07 17:55:28 +00:00
|
|
|
{
|
2003-03-05 18:02:24 +00:00
|
|
|
string rwyNo = search(aptid, tgt_hdg);
|
|
|
|
return(rwyNo == "NN" ? false : search(aptid, rwyNo, runway));
|
2001-11-07 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Return the runway number of the runway closest to a given heading
|
2007-10-04 17:11:19 +00:00
|
|
|
#include <Main/fg_props.hxx> // FIXME remove
|
|
|
|
string FGRunwayList::search( const string& aptid, const int hdg ) {
|
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "searching runway for " << aptid
|
|
|
|
// << " with target heading " << hdg);
|
|
|
|
|
2001-11-07 17:55:28 +00:00
|
|
|
FGRunway r;
|
2007-10-04 17:11:19 +00:00
|
|
|
if (!search(aptid, &r)) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to find "
|
|
|
|
<< aptid << " in database.");
|
|
|
|
return "NN";
|
2001-11-07 17:55:28 +00:00
|
|
|
}
|
2007-10-04 17:11:19 +00:00
|
|
|
|
|
|
|
double LENWGT = fgGetDouble("/tmp/runway-search/length", 0.01);
|
|
|
|
double WIDWGT = fgGetDouble("/tmp/runway-search/width", 0.01);
|
|
|
|
double SURFWGT = fgGetDouble("/tmp/runway-search/surface", 10);
|
|
|
|
double DEVWGT = fgGetDouble("/tmp/runway-search/deviation", 1);
|
|
|
|
|
|
|
|
FGRunway best;
|
|
|
|
double max = 0.0;
|
|
|
|
bool reversed = false;
|
|
|
|
|
|
|
|
while (r._id == aptid) {
|
|
|
|
if (r._type != "runway")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int surface = 0;
|
|
|
|
if (r._surface_code == 1 || r._surface_code == 2) // asphalt & concrete
|
|
|
|
surface = 2;
|
|
|
|
else if (r._surface_code == 12 || r._surface_code == 5) // dry lakebed & gravel
|
|
|
|
surface = 1;
|
|
|
|
|
|
|
|
double quality, bad, diff;
|
|
|
|
double good = LENWGT * r._length + WIDWGT * r._width + SURFWGT * surface;
|
|
|
|
|
|
|
|
// this side
|
|
|
|
diff = hdg - r._heading;
|
|
|
|
while (diff < -180)
|
|
|
|
diff += 360;
|
|
|
|
while (diff >= 180)
|
|
|
|
diff -= 360;
|
|
|
|
bad = DEVWGT * fabs(diff) + 1e-20;
|
|
|
|
|
|
|
|
quality = good / bad;
|
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, " runway " << r._rwy_no << " -> " << quality);
|
|
|
|
if (quality > max) {
|
|
|
|
max = quality;
|
|
|
|
best = r;
|
|
|
|
reversed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// other side
|
|
|
|
diff = hdg - r._heading - 180;
|
|
|
|
while (diff < -180)
|
|
|
|
diff += 360;
|
|
|
|
while (diff >= 180)
|
|
|
|
diff -= 360;
|
|
|
|
bad = DEVWGT * fabs(diff) + 1e-20;
|
|
|
|
|
|
|
|
quality = good / bad;
|
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, " runway " << GetReverseRunwayNo(r._rwy_no)
|
|
|
|
// << " -> " << quality);
|
|
|
|
if (quality > max) {
|
|
|
|
max = quality;
|
|
|
|
best = r;
|
|
|
|
reversed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!next(&r))
|
2007-02-09 05:34:34 +00:00
|
|
|
break;
|
2001-11-07 17:55:28 +00:00
|
|
|
}
|
2007-10-04 17:11:19 +00:00
|
|
|
|
|
|
|
return reversed ? GetReverseRunwayNo(best._rwy_no) : best._rwy_no;
|
2001-11-07 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
bool FGRunwayList::next( FGRunway* runway ) {
|
|
|
|
++current;
|
|
|
|
if ( current != runways.end() ) {
|
|
|
|
*runway = current->second;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
FGRunway FGRunwayList::next() {
|
|
|
|
FGRunway result;
|
2000-08-16 01:28:33 +00:00
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
++current;
|
|
|
|
if ( current != runways.end() ) {
|
|
|
|
result = current->second;
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|
|
|
|
|
2003-08-29 04:11:23 +00:00
|
|
|
return result;
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|
2003-08-29 04:11:23 +00:00
|
|
|
|
2000-08-16 01:28:33 +00:00
|
|
|
|
|
|
|
// Destructor
|
2003-08-29 04:11:23 +00:00
|
|
|
FGRunwayList::~FGRunwayList( void ) {
|
2000-08-16 01:28:33 +00:00
|
|
|
}
|