Finish porting airportinfo to cppbind
This commit is contained in:
parent
3579a4404a
commit
22a1c9b2af
4 changed files with 111 additions and 70 deletions
|
@ -408,12 +408,44 @@ FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
|
|||
mMinLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
|
||||
{
|
||||
return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
FGAirport::TypeRunwayFilter::TypeRunwayFilter():
|
||||
_type(FGPositioned::AIRPORT),
|
||||
_min_runway_length_ft( fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0) )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool FGAirport::TypeRunwayFilter::fromTypeString(const std::string& type)
|
||||
{
|
||||
if( type == "heliport" ) _type = FGPositioned::HELIPORT;
|
||||
else if( type == "seaport" ) _type = FGPositioned::SEAPORT;
|
||||
else if( type == "airport" ) _type = FGPositioned::AIRPORT;
|
||||
else return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool FGAirport::TypeRunwayFilter::pass(FGPositioned* pos) const
|
||||
{
|
||||
FGAirport* apt = static_cast<FGAirport*>(pos);
|
||||
if( (apt->type() == FGPositioned::AIRPORT)
|
||||
&& !apt->hasHardRunwayOfLengthFt(_min_runway_length_ft)
|
||||
)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
FGAirport* FGAirport::findByIdent(const std::string& aIdent)
|
||||
{
|
||||
AirportCache::iterator it = airportCache.find(aIdent);
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
**************************************************************************************/
|
||||
class FGAirport : public FGPositioned
|
||||
{
|
||||
public:
|
||||
public:
|
||||
FGAirport(PositionedID aGuid, const std::string& id, const SGGeod& location,
|
||||
const std::string& name, bool has_metar, Type aType);
|
||||
~FGAirport();
|
||||
|
@ -133,23 +133,23 @@ public:
|
|||
FGPavementList getPavements() const;
|
||||
|
||||
class AirportFilter : public Filter
|
||||
{
|
||||
public:
|
||||
virtual bool pass(FGPositioned* aPos) const {
|
||||
return passAirport(static_cast<FGAirport*>(aPos));
|
||||
}
|
||||
|
||||
virtual Type minType() const {
|
||||
return AIRPORT;
|
||||
}
|
||||
|
||||
virtual Type maxType() const {
|
||||
return AIRPORT;
|
||||
}
|
||||
|
||||
virtual bool passAirport(FGAirport* aApt) const {
|
||||
return true;
|
||||
}
|
||||
{
|
||||
public:
|
||||
virtual bool pass(FGPositioned* aPos) const {
|
||||
return passAirport(static_cast<FGAirport*>(aPos));
|
||||
}
|
||||
|
||||
virtual Type minType() const {
|
||||
return AIRPORT;
|
||||
}
|
||||
|
||||
virtual Type maxType() const {
|
||||
return AIRPORT;
|
||||
}
|
||||
|
||||
virtual bool passAirport(FGAirport* aApt) const {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -174,6 +174,30 @@ public:
|
|||
double mMinLengthFt;
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter which passes specified port type and in case of airport checks
|
||||
* if a runway larger the /sim/navdb/min-runway-lenght-ft exists.
|
||||
*/
|
||||
class TypeRunwayFilter:
|
||||
public AirportFilter
|
||||
{
|
||||
public:
|
||||
TypeRunwayFilter();
|
||||
|
||||
/**
|
||||
* Construct from string containing type (airport, seaport or heliport)
|
||||
*/
|
||||
bool fromTypeString(const std::string& type);
|
||||
|
||||
virtual FGPositioned::Type minType() const { return _type; }
|
||||
virtual FGPositioned::Type maxType() const { return _type; }
|
||||
virtual bool pass(FGPositioned* pos) const;
|
||||
|
||||
protected:
|
||||
FGPositioned::Type _type;
|
||||
double _min_runway_length_ft;
|
||||
};
|
||||
|
||||
|
||||
void setProcedures(const std::vector<flightgear::SID*>& aSids,
|
||||
const std::vector<flightgear::STAR*>& aStars,
|
||||
|
|
|
@ -983,49 +983,6 @@ static naRef f_geodinfo(naContext c, naRef me, int argc, naRef* args)
|
|||
}
|
||||
|
||||
|
||||
class AirportInfoFilter : public FGAirport::AirportFilter
|
||||
{
|
||||
public:
|
||||
AirportInfoFilter() : type(FGPositioned::AIRPORT) {
|
||||
minRunwayLengthFt = fgGetDouble("/sim/navdb/min-runway-length-ft", 0.0);
|
||||
}
|
||||
|
||||
bool fromArg(naRef arg)
|
||||
{
|
||||
const char *s = naStr_data(arg);
|
||||
if(!strcmp(s, "airport")) type = FGPositioned::AIRPORT;
|
||||
else if(!strcmp(s, "seaport")) type = FGPositioned::SEAPORT;
|
||||
else if(!strcmp(s, "heliport")) type = FGPositioned::HELIPORT;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual FGPositioned::Type minType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
virtual FGPositioned::Type maxType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
virtual bool pass(FGPositioned* aPos) const
|
||||
{
|
||||
FGAirport* apt = (FGAirport*) aPos;
|
||||
if ((apt->type() == FGPositioned::AIRPORT) &&
|
||||
!apt->hasHardRunwayOfLengthFt(minRunwayLengthFt))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FGPositioned::Type type;
|
||||
double minRunwayLengthFt;
|
||||
};
|
||||
|
||||
// Returns data hash for particular or nearest airport of a <type>, or nil
|
||||
// on error.
|
||||
//
|
||||
|
@ -1046,12 +1003,12 @@ static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
|
|||
|
||||
double maxRange = 10000.0; // expose this? or pick a smaller value?
|
||||
|
||||
AirportInfoFilter filter; // defaults to airports only
|
||||
FGAirport::TypeRunwayFilter filter; // defaults to airports only
|
||||
|
||||
if(argc == 0) {
|
||||
// fall through and use AIRPORT
|
||||
} else if(argc == 1 && naIsString(args[0])) {
|
||||
if (filter.fromArg(args[0])) {
|
||||
if (filter.fromTypeString(naStr_data(args[0]))) {
|
||||
// done!
|
||||
} else {
|
||||
// user provided an <id>, hopefully
|
||||
|
@ -1086,10 +1043,10 @@ static naRef f_findAirportsWithinRange(naContext c, naRef me, int argc, naRef* a
|
|||
naRuntimeError(c, "findAirportsWithinRange expected range (in nm) as arg %d", argOffset);
|
||||
}
|
||||
|
||||
AirportInfoFilter filter; // defaults to airports only
|
||||
FGAirport::TypeRunwayFilter filter; // defaults to airports only
|
||||
double rangeNm = args[argOffset++].num;
|
||||
if (argOffset < argc) {
|
||||
filter.fromArg(args[argOffset++]);
|
||||
filter.fromTypeString(naStr_data(args[argOffset++]));
|
||||
}
|
||||
|
||||
naRef r = naNewVector(c);
|
||||
|
@ -1113,9 +1070,9 @@ static naRef f_findAirportsByICAO(naContext c, naRef me, int argc, naRef* args)
|
|||
|
||||
int argOffset = 0;
|
||||
std::string prefix(naStr_data(args[argOffset++]));
|
||||
AirportInfoFilter filter; // defaults to airports only
|
||||
FGAirport::TypeRunwayFilter filter; // defaults to airports only
|
||||
if (argOffset < argc) {
|
||||
filter.fromArg(args[argOffset++]);
|
||||
filter.fromTypeString(naStr_data(args[argOffset++]));
|
||||
}
|
||||
|
||||
naRef r = naNewVector(c);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <Airports/airport.hxx>
|
||||
#include <Airports/dynamics.hxx>
|
||||
#include <ATC/CommStation.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
#include <Navaids/NavDataCache.hxx>
|
||||
|
||||
typedef nasal::Ghost<FGPositionedRef> NasalPositioned;
|
||||
|
@ -252,7 +253,7 @@ f_airport_parking(FGAirport& apt, const nasal::CallContext& ctx)
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
// Returns Nasal ghost for particular or nearest airport of a <type>, or nil
|
||||
// on error. (Currently only airportinfo(<id>) is implemented)
|
||||
// on error.
|
||||
//
|
||||
// airportinfo(<id>); e.g. "KSFO"
|
||||
// airportinfo(<type>); type := ("airport"|"seaport"|"heliport")
|
||||
|
@ -263,7 +264,34 @@ static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
|
|||
nasal::CallContext ctx(c, argc, args);
|
||||
// TODO think of something comfortable to overload functions or use variable
|
||||
// number/types of arguments.
|
||||
return ctx.to_nasal(FGAirport::findByIdent( ctx.requireArg<std::string>(0) ));
|
||||
|
||||
std::string ident = "airport";
|
||||
SGGeod pos = globals->get_aircraft_position();
|
||||
|
||||
if( ctx.argc == 1 )
|
||||
{
|
||||
ident = ctx.requireArg<std::string>(0);
|
||||
}
|
||||
else if( ctx.argc >= 2 )
|
||||
{
|
||||
// Why are lat/lon swapped?
|
||||
pos = SGGeod::fromDeg( ctx.requireArg<double>(1),
|
||||
ctx.requireArg<double>(0) );
|
||||
|
||||
if( ctx.argc >= 3 )
|
||||
ident = ctx.requireArg<std::string>(2);
|
||||
|
||||
if( ctx.argc > 3 )
|
||||
naRuntimeError(ctx.c, "airportinfo() with invalid function arguments");
|
||||
}
|
||||
|
||||
FGAirport::TypeRunwayFilter filter;
|
||||
if( !filter.fromTypeString(ident) )
|
||||
// user provided an <id>, hopefully
|
||||
return ctx.to_nasal(FGAirport::findByIdent(ident));
|
||||
|
||||
double maxRange = 10000.0; // expose this? or pick a smaller value?
|
||||
return ctx.to_nasal( FGAirport::findClosest(pos, maxRange, &filter) );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue