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);
**************************************************************************************/
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();
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;
+ }
};
/**
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,
}
-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.
//
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
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);
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);
#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;
//------------------------------------------------------------------------------
// 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")
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) );
}
//------------------------------------------------------------------------------