X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAirports%2Frunways.cxx;h=3eb853823e4d39f0927fcba599c71f3d08750217;hb=386aefe69358ce41a11c9afeb8f56e26758fe56b;hp=cf6550aea02001610430ea109521ed584314a630;hpb=771fbd680af324ae04e12193a6de879cb16cffe2;p=flightgear.git diff --git a/src/Airports/runways.cxx b/src/Airports/runways.cxx index cf6550aea..3eb853823 100644 --- a/src/Airports/runways.cxx +++ b/src/Airports/runways.cxx @@ -25,280 +25,145 @@ # include #endif -#include // fabs() -#include // sprintf() +#include // sprintf() +#include // atoi() #include -#include +#include -#include STL_STRING -#include +#include #include "runways.hxx" -SG_USING_NAMESPACE(std); -SG_USING_STD(istream); -SG_USING_STD(multimap); +using std::string; +static std::string cleanRunwayNo(const std::string& aRwyNo) +{ + if (aRwyNo[0] == 'x') { + return std::string(); // no ident for taxiways + } + + string result(aRwyNo); + // canonicalise runway ident + if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) { + result = "0" + aRwyNo; + } + + // trim off trailing garbage + if (result.size() > 2) { + char suffix = toupper(result[2]); + if (suffix == 'X') { + result = result.substr(0, 2); + } + } + + return result; +} -// add an entry to the list -void FGRunwayList::add( const string& id, const string& rwy_no, - const double longitude, const double latitude, +FGRunway::FGRunway(FGAirport* aAirport, const string& aIdent, + const SGGeod& aGeod, const double heading, const double length, const double width, - const double displ_thresh1, const double displ_thresh2, - const double stopway1, const double stopway2, - const string& lighting_flags, const int surface_code, - const string& shoulder_code, const int marking_code, - const double smoothness, const bool dist_remaining ) + const double displ_thresh, + const double stopway, + const int surface_code, + bool reciprocal) : + FGRunwayBase(RUNWAY, cleanRunwayNo(aIdent), aGeod, heading, length, width, surface_code, true), + _airport(aAirport), + _isReciprocal(reciprocal), + _reciprocal(NULL), + _displ_thresh(displ_thresh), + _stopway(stopway), + _ils(NULL) { - FGRunway rwy; - - 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); - } - - 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; - - if ( rwy_no == "xxx" ) { - rwy._type = "taxiway"; - // don't insert taxiways into the DB for now - } else { - rwy._type = "runway"; - runways.insert(pair(rwy._id, rwy)); - } } +string FGRunway::reverseIdent(const string& aRunwayIdent) +{ + // Helipads don't have a seperate number per end + if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) { + return aRunwayIdent; + } -// Return reverse rwy number -// eg 01 -> 19 -// 03L -> 21R -static string GetReverseRunwayNo(string& rwyno) { - // cout << "Original rwyno = " << rwyNo << '\n'; - - // Helipads don't have a seperate number per end - if(rwyno.size() && (rwyno[0] == 'H' || rwyno[0] == 'h')) { - return rwyno; - } + std::string ident(aRunwayIdent); - // standardize input number - string tmp = rwyno.substr(1, 1); - if (( tmp == "L" || tmp == "R" || tmp == "C" ) || (rwyno.size() == 1)) { - tmp = rwyno; - rwyno = "0" + tmp; - SG_LOG( SG_GENERAL, SG_INFO, - "Standardising rwy number from " << tmp << " to " << rwyno ); - } - - 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'; - } else if (rwyno.substr(2,1) == "T") { - buf[2] = 'T'; - buf[3] = '\0'; - } else { - SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code " - << rwyno << " passed to GetReverseRunwayNo(...)"); - } - } - return(buf); -} - - -// search for the specified apt id (wierd!) -bool FGRunwayList::search( const string& aptid, FGRunway* r ) { - runway_map_iterator pos; - - pos = runways.lower_bound(aptid); - if ( pos != runways.end() ) { - current = pos; - *r = pos->second; - return true; + char buf[4]; + int rn = atoi(ident.substr(0,2).c_str()); + rn += 18; + while(rn > 36) { + rn -= 36; + } + + sprintf(buf, "%02i", rn); + if(ident.size() == 3) { + char suffix = toupper(ident[2]); + if(suffix == 'L') { + buf[2] = 'R'; + } else if (suffix == 'R') { + buf[2] = 'L'; } else { - return false; + // something else, just copy + buf[2] = suffix; } + + buf[3] = 0; + } + + return buf; } - -// search for the specified apt id and runway no -bool FGRunwayList::search( const string& aptid, const string& rwyno, - FGRunway *r ) +double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const { - string revrwyno = ""; - string runwayno = rwyno; - 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); - } - runway_map_iterator pos; - for ( pos = runways.lower_bound( aptid ); - pos != runways.upper_bound( aptid ); ++pos) - { - if ( pos->second._rwy_no == runwayno ) { - current = pos; - *r = pos->second; - return true; - } else if ( pos->second._rwy_no == revrwyno ) { - // 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; - // NOTE - matching revrwyno implies that runwayno was - // actually correct. - r->_rwy_no = runwayno; - r->_heading += 180.0; - return true; - } - } - - return false; -} - - -// (wierd!) -FGRunway FGRunwayList::search( const string& aptid ) { - FGRunway a; - search( aptid, &a ); - return a; + int surface = 1; + if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel + surface = 2; + else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete + surface = 3; + + return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20; } - -// Return the runway closest to a given heading -bool FGRunwayList::search( const string& aptid, const int tgt_hdg, - FGRunway *runway ) +SGGeod FGRunway::begin() const { - string rwyNo = search(aptid, tgt_hdg); - return(rwyNo == "NN" ? false : search(aptid, rwyNo, runway)); + return pointOnCenterline(0.0); } - -// Return the runway number of the runway closest to a given heading -string FGRunwayList::search( const string& aptid, const int tgt_hdg ) { - FGRunway r; - FGRunway tmp_r; - string rn; - double found_dir = 0.0; - - if ( !search( aptid, &tmp_r ) ) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Failed to find " << aptid << " in database." ); - return "NN"; - } - - double diff; - double min_diff = 360.0; - - while ( tmp_r._id == aptid ) { - // forward direction - diff = tgt_hdg - tmp_r._heading; - while ( diff < -180.0 ) { diff += 360.0; } - while ( diff > 180.0 ) { diff -= 360.0; } - diff = fabs(diff); - // SG_LOG( SG_GENERAL, SG_INFO, - // "Runway " << tmp_r._rwy_no << " heading = " - // << tmp_r._heading << " diff = " << diff ); - if ( diff < min_diff ) { - min_diff = diff; - r = tmp_r; - found_dir = 0; - } - - // reverse direction - diff = tgt_hdg - tmp_r._heading - 180.0; - while ( diff < -180.0 ) { diff += 360.0; } - while ( diff > 180.0 ) { diff -= 360.0; } - diff = fabs(diff); - // SG_LOG( SG_GENERAL, SG_INFO, - // "Runway -" << tmp_r._rwy_no << " heading = " << - // tmp_r._heading + 180.0 << - // " diff = " << diff ); - if ( diff < min_diff ) { - min_diff = diff; - r = tmp_r; - found_dir = 180.0; - } - - next( &tmp_r ); - } - - // SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << r._rwy_no - // << " + " << found_dir ); - rn = r._rwy_no; - if ( found_dir == 180 ) { - rn = GetReverseRunwayNo(rn); - } - - return rn; +SGGeod FGRunway::end() const +{ + return pointOnCenterline(lengthM()); } - -bool FGRunwayList::next( FGRunway* runway ) { - ++current; - if ( current != runways.end() ) { - *runway = current->second; - return true; - } else { - return false; - } +SGGeod FGRunway::threshold() const +{ + return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER); } - -FGRunway FGRunwayList::next() { - FGRunway result; - - ++current; - if ( current != runways.end() ) { - result = current->second; - } - - return result; +void FGRunway::processThreshold(SGPropertyNode* aThreshold) +{ + assert(ident() == aThreshold->getStringValue("rwy")); + + double lon = aThreshold->getDoubleValue("lon"), + lat = aThreshold->getDoubleValue("lat"); + SGGeod newThreshold(SGGeod::fromDegM(lon, lat, mPosition.getElevationM())); + + _heading = aThreshold->getDoubleValue("hdg-deg"); + _displ_thresh = aThreshold->getDoubleValue("displ-m") * SG_METER_TO_FEET; + _stopway = aThreshold->getDoubleValue("stopw-m") * SG_METER_TO_FEET; + + // compute the new runway center, based on the threshold lat/lon and length, + double offsetFt = (0.5 * _length); + SGGeod newCenter; + double dummy; + SGGeodesy::direct(newThreshold, _heading, offsetFt * SG_FEET_TO_METER, newCenter, dummy); + mPosition = newCenter; +} + +void FGRunway::setReciprocalRunway(FGRunway* other) +{ + assert(_reciprocal==NULL); + assert((other->_reciprocal == NULL) || (other->_reciprocal == this)); + + _reciprocal = other; } - -// Destructor -FGRunwayList::~FGRunwayList( void ) { -}