31#include <simgear/misc/ListDiff.hxx>
32#include <simgear/nasal/cppbind/from_nasal.hxx>
33#include <simgear/nasal/cppbind/to_nasal.hxx>
34#include <simgear/nasal/cppbind/NasalHash.hxx>
35#include <simgear/nasal/cppbind/Ghost.hxx>
60 return nasal::to_nasal(c, sid->
ident());
67 return nasal::to_nasal(c, star->
ident());
74 return nasal::to_nasal(c, iap->
ident());
86 return naNum(SGMiscd::normalizePeriodic(0.5, 360.5, radial));
92 const std::string Id = simgear::strutils::uppercase (ident);
103template<
class T,
class C1,
class C2>
104std::vector<T>
extract(
const std::vector<C1>& in,
105 T (C2::*getter)()
const )
107 std::vector<T> ret(in.size());
108 std::transform(in.begin(), in.end(), ret.begin(), [getter](
const C1& c)
109 { return (c->*getter)(); }
134 const nasal::CallContext& ctx,
137 if( index >= ctx.argc )
142 std::string ident = ctx.getArg<std::string>(index);
156 return ctx.from_nasal<
FGRunwayRef>(ctx.args[index]);
185 const std::string type_str = simgear::strutils::uppercase (ctx.getArg<std::string>(1));
186 if( !type_str.empty() )
207 std::string type = ctx.getArg<std::string>(0);
208 bool only_available = ctx.getArg<
bool>(1);
210 return dynamics->getParkings(only_available, type);
232 result = pos->geod();
237 else if( ctx.isHash(0) )
239 nasal::Hash pos_hash = ctx.requireArg<nasal::Hash>(0);
242 naRef lat = pos_hash.get(
"lat"),
243 lon = pos_hash.get(
"lon");
244 if( naIsNum(lat) && naIsNum(lon) )
246 result = SGGeod::fromDeg( ctx.from_nasal<
double>(lon),
247 ctx.from_nasal<
double>(lat) );
254 lat = pos_hash.get(
"_lat");
255 lon = pos_hash.get(
"_lon");
256 if( naIsNum(lat) && naIsNum(lon) )
258 result = SGGeod::fromRad( ctx.from_nasal<
double>(lon),
259 ctx.from_nasal<
double>(lat) );
264 else if( ctx.isNumeric(0) && ctx.isNumeric(1) )
267 result = SGGeod::fromDeg( ctx.requireArg<
double>(1),
268 ctx.requireArg<
double>(0) );
283 pos =
globals->get_aircraft_position();
301 ctx.runtimeError(
"airportinfo() with invalid function arguments");
304 std::string ident(
"airport");
305 if( ctx.isString(0) )
306 ident = ctx.requireArg<std::string>(0);
309 if( !filter.fromTypeString(ident) )
313 double maxRange = 10000.0;
323 double range_nm = ctx.requireArg<
double>(0);
331 return ctx.to_nasal(apts);
339 std::string prefix = ctx.requireArg<std::string>(0);
362 std::string
id = ctx.getArg<std::string>(0);
365 if( filter.fromTypeString(
id) )
366 id = ctx.getArg<std::string>(1);
367 else if( ctx.argc > 1 )
368 ctx.runtimeError(
"navinfo() already got an ident");
377 double range_nm = ctx.requireArg<
double>(0);
379 std::string typeSpec = ctx.getArg<std::string>(1);
384 return ctx.to_nasal(items);
389 std::string prefix = ctx.requireArg<std::string>(0);
390 std::string typeSpec = ctx.getArg<std::string>(1);
392 bool exact = ctx.getArg<
bool>(2,
false);
399 std::string prefix = ctx.requireArg<std::string>(0);
400 std::string typeSpec = ctx.getArg<std::string>(1);
410 SGGeod from =
globals->get_aircraft_position(), to, pos;
413 ctx.runtimeError(
"invalid arguments to courseAndDistance");
422 double course, course2, d;
423 SGGeodesy::inverse(from, to, course, course2, d);
425 return ctx.to_nasal_vec(course, d * SG_METER_TO_NM);
433 return ctx.to_nasal(items);
450static naRef
f_diff(nasal::CallContext ctx)
452 typedef simgear::ListDiff<FGPositionedRef> Diff;
455 Diff::Callback cb_add = ctx.requireArg<Diff::Callback>(2),
456 cb_rm = ctx.getArg<Diff::Callback>(3);
464 Diff::inplace(old_list, new_list, cb_add, cb_rm);
472 NasalPositioned::init(
"Positioned")
480 NasalRunway::init(
"Runway")
482 NasalParking::init(
"Parking")
484 NasalCommStation::init(
"CommStation")
487 NasalNavRecord::init(
"Navaid")
496 NasalFix::init(
"Fix")
499 NasalAirport::init(
"FGAirport")
519 nasal::Hash
globals(globalsRef, c),
520 positioned(
globals.createHash(
"positioned") );
533 positioned.set(
"diff", &
f_diff);
static naRef f_airport_parking(naContext c, naRef me, int argc, naRef *args)
static naRef f_airport_runway(naContext c, naRef me, int argc, naRef *args)
static naRef f_airport_sids(naContext c, naRef me, int argc, naRef *args)
static naRef f_navinfo(naContext c, naRef me, int argc, naRef *args)
static naRef f_airport_stars(naContext c, naRef me, int argc, naRef *args)
static naRef f_findAirportsWithinRange(naContext c, naRef me, int argc, naRef *args)
static naRef f_courseAndDistance(naContext c, naRef me, int argc, naRef *args)
static naRef f_airport_comms(naContext c, naRef me, int argc, naRef *args)
static naRef f_findAirportsByICAO(naContext c, naRef me, int argc, naRef *args)
static naRef f_findByIdent(naContext c, naRef me, int argc, naRef *args)
static naRef f_airportinfo(naContext c, naRef me, int argc, naRef *args)
static naRef f_airport_approaches(naContext c, naRef me, int argc, naRef *args)
static FGRunwayBaseRef f_airport_runway(FGAirport &apt, const std::string &ident)
static naRef f_airport_approaches(FGAirport &apt, const nasal::CallContext &ctx)
static naRef f_sortByRange(nasal::CallContext ctx)
std::vector< T > extract(const std::vector< C1 > &in, T(C2::*getter)() const)
static naRef f_findByIdent(nasal::CallContext ctx)
static naRef f_airport_stars(FGAirport &apt, const nasal::CallContext &ctx)
nasal::Ghost< FGPositionedRef > NasalPositioned
static naRef f_findWithinRange(nasal::CallContext ctx)
static bool extractGeod(nasal::CallContext &ctx, SGGeod &result)
Extract a SGGeod from a nasal function argument list.
naRef initNasalPositioned_cppbind(naRef globalsRef, naContext c)
static naRef f_diff(nasal::CallContext ctx)
nasal::Ghost< FGNavRecordRef > NasalNavRecord
nasal::Ghost< FGFixRef > NasalFix
static FGParkingList f_airport_parking(FGAirport &apt, nasal::CallContext ctx)
naRef to_nasal_helper(naContext c, flightgear::SID *sid)
static naRef f_findAirportsWithinRange(nasal::CallContext ctx)
findAirportsWithinRange([<position>,] <range-nm> [, type])
static SGGeod getPosition(nasal::CallContext &ctx)
Extract position from ctx or return current aircraft position if not given.
static naRef f_airport_comms(FGAirport &apt, const nasal::CallContext &ctx)
static naRef f_airportinfo(nasal::CallContext ctx)
static naRef f_findAirportsByICAO(nasal::CallContext ctx)
findAirportsByICAO(<ident/prefix> [, type])
nasal::Ghost< flightgear::CommStationRef > NasalCommStation
static naRef f_courseAndDistance(nasal::CallContext ctx)
static naRef f_airport_sids(FGAirport &apt, const nasal::CallContext &ctx)
static naRef f_navinfo(nasal::CallContext ctx)
nasal::Ghost< FGAirportRef > NasalAirport
static naRef f_navaid_course(FGNavRecord &nav, naContext)
FGRunwayRef runwayFromNasalArg(const FGAirport &apt, const nasal::CallContext &ctx, size_t index=0)
nasal::Ghost< FGRunwayRef > NasalRunway
static naRef f_findByName(nasal::CallContext ctx)
nasal::Ghost< FGParkingRef > NasalParking
SGSharedPtr< FGRunwayBase > FGRunwayBaseRef
SGSharedPtr< FGAirportDynamics > FGAirportDynamicsRef
std::vector< FGParkingRef > FGParkingList
SGSharedPtr< FGRunway > FGRunwayRef
SGSharedPtr< FGPositioned > FGPositionedRef
Filter which passes specified port type and in case of airport checks if a runway larger the /sim/nav...
bool fromTypeString(const std::string &type)
Construct from string containing type (airport, seaport or heliport)
FGAirportDynamicsRef getDynamics() const
FGRunwayRef getRunwayByIdent(const std::string &aIdent) const
flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const
std::string toString() const
FGPavementList getPavements() const
static FGAirportRef findClosest(const SGGeod &aPos, double aCuttofNm, Filter *filter=NULL)
Syntactic wrapper around FGPositioned::findClosest - find the closest match for filter,...
static FGAirportRef findByIdent(const std::string &aIdent)
Helper to look up an FGAirport instance by unique ident.
flightgear::STAR * findSTARWithIdent(const std::string &aIdent) const
bool hasHelipadWithIdent(const std::string &aIdent) const
FGTaxiwayList getTaxiways() const
bool hasRunwayWithIdent(const std::string &aIdent) const
flightgear::ApproachList getApproaches(flightgear::ProcedureType type=flightgear::PROCEDURE_INVALID) const
flightgear::CommStationList commStations() const
flightgear::STARList getSTARs() const
SGGeod getTowerLocation() const
flightgear::Approach * findApproachWithIdent(const std::string &aIdent) const
FGRunwayMap getRunwayMap() const
flightgear::SID * findSIDWithIdent(const std::string &aIdent) const
FGHelipadRef getHelipadByIdent(const std::string &aIdent) const
FGHelipadMap getHelipadMap() const
flightgear::SIDList getSIDs() const
static nav_list_type findByIdentAndFreq(const std::string &ident, const double freq, TypeFilter *filter=NULL)
double get_multiuse() const
static TypeFilter fromString(const std::string &aFilterSpec)
static Type typeFromName(const std::string &aName)
Map a candidate type string to a real type.
static FGPositionedList findAllWithName(const std::string &aName, Filter *aFilter=NULL, bool aExact=true)
As above, but searches names instead of idents.
virtual const std::string & name() const
Return the name of this positioned.
const char * typeString() const
static FGPositionedList findWithinRange(const SGGeod &aPos, double aRangeNm, Filter *aFilter)
static void sortByRange(FGPositionedList &, const SGGeod &aPos)
Sort an FGPositionedList by distance from a position.
static FGPositionedList findAllWithIdent(const std::string &aIdent, Filter *aFilter=NULL, bool aExact=true)
Find all items with the specified ident.
double elevationM() const
const std::string & ident() const
flightgear::STARList getSTARs() const
Get STARs associared with this runway.
flightgear::SIDList getSIDs() const
Get SIDs (DPs) associated with this runway.
flightgear::ApproachList getApproaches(flightgear::ProcedureType type=flightgear::PROCEDURE_INVALID) const
Describe an approach procedure, including the missed approach segment.
virtual std::string ident() const
@ PROCEDURE_APPROACH_RNAV
std::vector< FGPositionedRef > FGPositionedList