Maintenance: runways
whitespace formatting. increase buf size convert atoi() to stoi()
This commit is contained in:
parent
4a2cbc7389
commit
eb708eb5fe
1 changed files with 112 additions and 116 deletions
|
@ -22,12 +22,12 @@
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstdio> // sprintf()
|
|
||||||
#include <cstdlib> // atoi()
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstdio> // sprintf()
|
||||||
|
#include <cstdlib> // atoi()
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
|
@ -38,177 +38,174 @@
|
||||||
#include "runways.hxx"
|
#include "runways.hxx"
|
||||||
|
|
||||||
#include <Airports/airport.hxx>
|
#include <Airports/airport.hxx>
|
||||||
#include <Navaids/procedure.hxx>
|
|
||||||
#include <Navaids/navrecord.hxx>
|
|
||||||
#include <Navaids/NavDataCache.hxx>
|
#include <Navaids/NavDataCache.hxx>
|
||||||
|
#include <Navaids/navrecord.hxx>
|
||||||
|
#include <Navaids/procedure.hxx>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
FGRunway::FGRunway(PositionedID aGuid,
|
FGRunway::FGRunway(PositionedID aGuid,
|
||||||
PositionedID aAirport, const string& aIdent,
|
PositionedID aAirport, const string& aIdent,
|
||||||
const SGGeod& aGeod,
|
const SGGeod& aGeod,
|
||||||
const double heading, const double length,
|
const double heading, const double length,
|
||||||
const double width,
|
const double width,
|
||||||
const double displ_thresh,
|
const double displ_thresh,
|
||||||
const double stopway,
|
const double stopway,
|
||||||
const int surface_code) :
|
const int surface_code) : FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
|
||||||
FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
|
heading, length, width, surface_code),
|
||||||
heading, length, width, surface_code),
|
_airport(aAirport),
|
||||||
_airport(aAirport),
|
_reciprocal(0),
|
||||||
_reciprocal(0),
|
_displ_thresh(displ_thresh),
|
||||||
_displ_thresh(displ_thresh),
|
_stopway(stopway),
|
||||||
_stopway(stopway),
|
_ils(0)
|
||||||
_ils(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string FGRunway::reverseIdent(const string& aRunwayIdent)
|
string FGRunway::reverseIdent(const string& aRunwayIdent)
|
||||||
{
|
{
|
||||||
// Helipads don't have a seperate number per end
|
// Helipads don't have a seperate number per end
|
||||||
if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
|
if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
|
||||||
return aRunwayIdent;
|
return aRunwayIdent;
|
||||||
}
|
|
||||||
|
|
||||||
std::string ident(aRunwayIdent);
|
|
||||||
|
|
||||||
char buf[4];
|
|
||||||
int rn = atoi(ident.substr(0,2).c_str());
|
|
||||||
rn += 18;
|
|
||||||
while(rn > 36) {
|
|
||||||
rn -= 36;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(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 {
|
|
||||||
// something else, just copy
|
|
||||||
buf[2] = suffix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[3] = 0;
|
std::string ident(aRunwayIdent);
|
||||||
}
|
|
||||||
|
int rn = std::stoi(ident.substr(0, 2));
|
||||||
return buf;
|
rn += 18;
|
||||||
|
while (rn > 36) {
|
||||||
|
rn -= 36;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[16];
|
||||||
|
snprintf(buf, sizeof(buf) - 1, "%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 {
|
||||||
|
// something else, just copy
|
||||||
|
buf[2] = suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[3] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt, double aIlsWt) const
|
double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt, double aIlsWt) const
|
||||||
{
|
{
|
||||||
int surface = 1;
|
int surface = 1;
|
||||||
if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
|
if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
|
||||||
surface = 2;
|
surface = 2;
|
||||||
else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
|
else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
|
||||||
surface = 3;
|
surface = 3;
|
||||||
|
|
||||||
int ils = (_ils != 0);
|
int ils = (_ils != 0);
|
||||||
|
|
||||||
return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + ils * aIlsWt + 1e-20;
|
return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + ils * aIlsWt + 1e-20;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGGeod FGRunway::begin() const
|
SGGeod FGRunway::begin() const
|
||||||
{
|
{
|
||||||
return pointOnCenterline(0.0);
|
return pointOnCenterline(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SGGeod FGRunway::end() const
|
SGGeod FGRunway::end() const
|
||||||
{
|
{
|
||||||
return pointOnCenterline(lengthM());
|
return pointOnCenterline(lengthM());
|
||||||
}
|
}
|
||||||
|
|
||||||
SGGeod FGRunway::threshold() const
|
SGGeod FGRunway::threshold() const
|
||||||
{
|
{
|
||||||
return pointOnCenterline(_displ_thresh);
|
return pointOnCenterline(_displ_thresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGRunway::setReciprocalRunway(PositionedID other)
|
void FGRunway::setReciprocalRunway(PositionedID other)
|
||||||
{
|
{
|
||||||
assert(_reciprocal==0);
|
assert(_reciprocal == 0);
|
||||||
_reciprocal = other;
|
_reciprocal = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAirport* FGRunway::airport() const
|
FGAirport* FGRunway::airport() const
|
||||||
{
|
{
|
||||||
return loadById<FGAirport>(_airport);
|
return loadById<FGAirport>(_airport);
|
||||||
}
|
}
|
||||||
|
|
||||||
FGRunway* FGRunway::reciprocalRunway() const
|
FGRunway* FGRunway::reciprocalRunway() const
|
||||||
{
|
{
|
||||||
return loadById<FGRunway>(_reciprocal);
|
return loadById<FGRunway>(_reciprocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
FGNavRecord* FGRunway::ILS() const
|
FGNavRecord* FGRunway::ILS() const
|
||||||
{
|
{
|
||||||
if (_ils == 0) {
|
if (_ils == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadById<FGNavRecord>(_ils);
|
return loadById<FGNavRecord>(_ils);
|
||||||
}
|
}
|
||||||
|
|
||||||
FGNavRecord* FGRunway::glideslope() const
|
FGNavRecord* FGRunway::glideslope() const
|
||||||
{
|
{
|
||||||
flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
|
flightgear::NavDataCache* cache = flightgear::NavDataCache::instance();
|
||||||
PositionedID gsId = cache->findNavaidForRunway(guid(), FGPositioned::GS);
|
PositionedID gsId = cache->findNavaidForRunway(guid(), FGPositioned::GS);
|
||||||
if (gsId == 0) {
|
if (gsId == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadById<FGNavRecord>(gsId);
|
return loadById<FGNavRecord>(gsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
flightgear::SIDList FGRunway::getSIDs() const
|
flightgear::SIDList FGRunway::getSIDs() const
|
||||||
{
|
{
|
||||||
FGAirport* apt = airport();
|
FGAirport* apt = airport();
|
||||||
flightgear::SIDList result;
|
flightgear::SIDList result;
|
||||||
for (unsigned int i=0; i<apt->numSIDs(); ++i) {
|
for (unsigned int i = 0; i < apt->numSIDs(); ++i) {
|
||||||
flightgear::SID* s = apt->getSIDByIndex(i);
|
flightgear::SID* s = apt->getSIDByIndex(i);
|
||||||
if (s->isForRunway(this)) {
|
if (s->isForRunway(this)) {
|
||||||
result.push_back(s);
|
result.push_back(s);
|
||||||
}
|
}
|
||||||
} // of SIDs at the airport iteration
|
} // of SIDs at the airport iteration
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
flightgear::STARList FGRunway::getSTARs() const
|
flightgear::STARList FGRunway::getSTARs() const
|
||||||
{
|
{
|
||||||
FGAirport* apt = airport();
|
FGAirport* apt = airport();
|
||||||
flightgear::STARList result;
|
flightgear::STARList result;
|
||||||
for (unsigned int i=0; i<apt->numSTARs(); ++i) {
|
for (unsigned int i = 0; i < apt->numSTARs(); ++i) {
|
||||||
flightgear::STAR* s = apt->getSTARByIndex(i);
|
flightgear::STAR* s = apt->getSTARByIndex(i);
|
||||||
if (s->isForRunway(this)) {
|
if (s->isForRunway(this)) {
|
||||||
result.push_back(s);
|
result.push_back(s);
|
||||||
}
|
}
|
||||||
} // of STARs at the airport iteration
|
} // of STARs at the airport iteration
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
flightgear::ApproachList
|
flightgear::ApproachList
|
||||||
FGRunway::getApproaches(flightgear::ProcedureType type) const
|
FGRunway::getApproaches(flightgear::ProcedureType type) const
|
||||||
{
|
{
|
||||||
FGAirport* apt = airport();
|
FGAirport* apt = airport();
|
||||||
flightgear::ApproachList result;
|
flightgear::ApproachList result;
|
||||||
for (unsigned int i=0; i<apt->numApproaches(); ++i)
|
for (unsigned int i = 0; i < apt->numApproaches(); ++i) {
|
||||||
{
|
flightgear::Approach* s = apt->getApproachByIndex(i);
|
||||||
flightgear::Approach* s = apt->getApproachByIndex(i);
|
if (s->runway() == this && (type == flightgear::PROCEDURE_INVALID || type == s->type())) {
|
||||||
if( s->runway() == this
|
result.push_back(s);
|
||||||
&& (type == flightgear::PROCEDURE_INVALID || type == s->type()) )
|
}
|
||||||
{
|
} // of approaches at the airport iteration
|
||||||
result.push_back(s);
|
|
||||||
}
|
return result;
|
||||||
} // of approaches at the airport iteration
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGRunway::updateThreshold(const SGGeod& newThreshold, double newHeading,
|
void FGRunway::updateThreshold(const SGGeod& newThreshold, double newHeading,
|
||||||
double newDisplacedThreshold,
|
double newDisplacedThreshold,
|
||||||
double newStopway)
|
double newStopway)
|
||||||
{
|
{
|
||||||
modifyPosition(newThreshold);
|
modifyPosition(newThreshold);
|
||||||
_heading = newHeading;
|
_heading = newHeading;
|
||||||
|
@ -217,12 +214,11 @@ void FGRunway::updateThreshold(const SGGeod& newThreshold, double newHeading,
|
||||||
}
|
}
|
||||||
|
|
||||||
FGHelipad::FGHelipad(PositionedID aGuid,
|
FGHelipad::FGHelipad(PositionedID aGuid,
|
||||||
PositionedID aAirport, const string& aIdent,
|
PositionedID aAirport, const string& aIdent,
|
||||||
const SGGeod& aGeod,
|
const SGGeod& aGeod,
|
||||||
const double heading, const double length,
|
const double heading, const double length,
|
||||||
const double width,
|
const double width,
|
||||||
const int surface_code) :
|
const int surface_code) : FGRunwayBase(aGuid, HELIPAD, aIdent, aGeod,
|
||||||
FGRunwayBase(aGuid, HELIPAD, aIdent, aGeod,
|
heading, length, width, surface_code)
|
||||||
heading, length, width, surface_code)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue