1
0
Fork 0

Simplify code for taxiways.

This commit is contained in:
Stuart Buchanan 2012-09-20 21:53:31 +01:00
parent ac1fc699b7
commit a3a40af860
3 changed files with 26 additions and 59 deletions

View file

@ -239,22 +239,6 @@ FGTaxiway* FGAirport::getTaxiwayByIndex(unsigned int aIndex) const
return (FGTaxiway*) flightgear::NavDataCache::instance()->loadById(mTaxiways[aIndex]); return (FGTaxiway*) flightgear::NavDataCache::instance()->loadById(mTaxiways[aIndex]);
} }
bool FGAirport::hasTaxiwayWithIdent(const string& aIdent) const
{
return flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent) != 0;
}
FGTaxiway* FGAirport::getTaxiwayByIdent(const string& aIdent) const
{
PositionedID id = flightgear::NavDataCache::instance()->airportItemWithIdent(guid(), FGPositioned::RUNWAY, aIdent);
if (id == 0) {
SG_LOG(SG_GENERAL, SG_ALERT, "no such runway '" << aIdent << "' at airport " << ident());
throw sg_range_exception("unknown runway " + aIdent + " at airport:" + ident(), "FGAirport::getTaxiwayByIdent");
}
return (FGTaxiway*) flightgear::NavDataCache::instance()->loadById(id);
}
unsigned int FGAirport::numPavements() const unsigned int FGAirport::numPavements() const
{ {
loadTaxiways(); loadTaxiways();

View file

@ -123,9 +123,6 @@ public:
unsigned int numTaxiways() const; unsigned int numTaxiways() const;
FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const; FGTaxiway* getTaxiwayByIndex(unsigned int aIndex) const;
bool hasTaxiwayWithIdent(const std::string& aIdent) const;
FGTaxiway* getTaxiwayByIdent(const std::string& aIdent) const;
unsigned int numPavements() const; unsigned int numPavements() const;
FGPavement* getPavementByIndex(unsigned int aIndex) const; FGPavement* getPavementByIndex(unsigned int aIndex) const;

View file

@ -71,9 +71,7 @@ naGhostType NavaidGhostType = { positionedGhostDestroy, "navaid", navaidGhostGet
static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out); static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out);
naGhostType RunwayGhostType = { positionedGhostDestroy, "runway", runwayGhostGetMember, 0 }; naGhostType RunwayGhostType = { positionedGhostDestroy, "runway", runwayGhostGetMember, 0 };
naGhostType TaxiwayGhostType = { positionedGhostDestroy, "taxiway", runwayGhostGetMember, 0 };
static const char* taxiwayGhostGetMember(naContext c, void* g, naRef field, naRef* out);
naGhostType TaxiwayGhostType = { positionedGhostDestroy, "taxiway", taxiwayGhostGetMember, 0 };
static const char* fixGhostGetMember(naContext c, void* g, naRef field, naRef* out); static const char* fixGhostGetMember(naContext c, void* g, naRef field, naRef* out);
naGhostType FixGhostType = { positionedGhostDestroy, "fix", fixGhostGetMember, 0 }; naGhostType FixGhostType = { positionedGhostDestroy, "fix", fixGhostGetMember, 0 };
@ -722,45 +720,33 @@ static const char* procedureGhostGetMember(naContext c, void* g, naRef field, na
static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out) static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out)
{ {
const char* fieldName = naStr_data(field); const char* fieldName = naStr_data(field);
FGRunway* rwy = (FGRunway*) g; FGRunwayBase* base = (FGRunwayBase*) g;
if (!strcmp(fieldName, "id")) *out = stringToNasal(c, rwy->ident()); if (!strcmp(fieldName, "id")) *out = stringToNasal(c, base->ident());
else if (!strcmp(fieldName, "lat")) *out = naNum(rwy->latitude()); else if (!strcmp(fieldName, "lat")) *out = naNum(base->latitude());
else if (!strcmp(fieldName, "lon")) *out = naNum(rwy->longitude()); else if (!strcmp(fieldName, "lon")) *out = naNum(base->longitude());
else if (!strcmp(fieldName, "heading")) *out = naNum(rwy->headingDeg()); else if (!strcmp(fieldName, "heading")) *out = naNum(base->headingDeg());
else if (!strcmp(fieldName, "length")) *out = naNum(rwy->lengthM()); else if (!strcmp(fieldName, "length")) *out = naNum(base->lengthM());
else if (!strcmp(fieldName, "width")) *out = naNum(rwy->widthM()); else if (!strcmp(fieldName, "width")) *out = naNum(base->widthM());
else if (!strcmp(fieldName, "threshold")) *out = naNum(rwy->displacedThresholdM()); else if (!strcmp(fieldName, "surface")) *out = naNum(base->surface());
else if (!strcmp(fieldName, "stopway")) *out = naNum(rwy->stopwayM()); else if (base->type() == FGRunwayBase::RUNWAY) {
else if (!strcmp(fieldName, "surface")) *out = naNum(rwy->surface()); FGRunway* rwy = (FGRunway*) g;
else if (!strcmp(fieldName, "ils_frequency_mhz")) { if (!strcmp(fieldName, "threshold")) *out = naNum(rwy->displacedThresholdM());
*out = rwy->ILS() ? naNum(rwy->ILS()->get_freq() / 100.0) : naNil(); else if (!strcmp(fieldName, "stopway")) *out = naNum(rwy->stopwayM());
} else if (!strcmp(fieldName, "ils")) { else if (!strcmp(fieldName, "ils_frequency_mhz")) {
*out = ghostForNavaid(c, rwy->ILS()); *out = rwy->ILS() ? naNum(rwy->ILS()->get_freq() / 100.0) : naNil();
} else if (!strcmp(fieldName, "ils")) {
*out = ghostForNavaid(c, rwy->ILS());
} else {
return 0;
}
} else { } else {
return 0; return 0;
} }
return ""; return "";
} }
static const char* taxiwayGhostGetMember(naContext c, void* g, naRef field, naRef* out)
{
const char* fieldName = naStr_data(field);
FGTaxiway* taxi = (FGTaxiway*) g;
if (!strcmp(fieldName, "id")) *out = stringToNasal(c, taxi->ident());
else if (!strcmp(fieldName, "lat")) *out = naNum(taxi->latitude());
else if (!strcmp(fieldName, "lon")) *out = naNum(taxi->longitude());
else if (!strcmp(fieldName, "heading")) *out = naNum(taxi->headingDeg());
else if (!strcmp(fieldName, "length")) *out = naNum(taxi->lengthM());
else if (!strcmp(fieldName, "width")) *out = naNum(taxi->widthM());
else if (!strcmp(fieldName, "surface")) *out = naNum(taxi->surface());
else return 0;
return "";
}
static const char* navaidGhostGetMember(naContext c, void* g, naRef field, naRef* out) static const char* navaidGhostGetMember(naContext c, void* g, naRef field, naRef* out)
{ {
const char* fieldName = naStr_data(field); const char* fieldName = naStr_data(field);
@ -1197,13 +1183,13 @@ static naRef f_airport_taxiway(naContext c, naRef me, int argc, naRef* args)
naRuntimeError(c, "airport.taxiway expects a taxiway ident argument"); naRuntimeError(c, "airport.taxiway expects a taxiway ident argument");
} }
std::string ident(naStr_data(args[0])); naRef taxiways = naNewVector(c);
boost::to_upper(ident);
if (!apt->hasTaxiwayWithIdent(ident)) { for (unsigned int i = 0; i < apt->numTaxiways(); i++) {
return naNil(); naVec_append(taxiways, ghostForTaxiway(c, apt->getTaxiwayByIndex(i)));
} }
return ghostForTaxiway(c, apt->getTaxiwayByIdent(ident)); return taxiways;
} }
static naRef f_airport_sids(naContext c, naRef me, int argc, naRef* args) static naRef f_airport_sids(naContext c, naRef me, int argc, naRef* args)