Flightplans: add clearAll, rename clear -> clearLegs
Improve naming of clear() methods, and expose the new ones to Nasal. this will allow RouteManager dialog ‘clear’ button to clear all, soon. See ticket: https://sourceforge.net/p/flightgear/codetickets/2064/
This commit is contained in:
parent
06a14b4b27
commit
a297c89144
6 changed files with 67 additions and 11 deletions
|
@ -558,7 +558,7 @@ void FGRouteMgr::update( double dt )
|
|||
void FGRouteMgr::clearRoute()
|
||||
{
|
||||
if (_plan) {
|
||||
_plan->clear();
|
||||
_plan->clearLegs();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -460,7 +460,7 @@ bool FlightPlanController::tryGenerateRoute()
|
|||
return false;
|
||||
}
|
||||
|
||||
_fp->clear();
|
||||
_fp->clearLegs();
|
||||
_fp->insertWayptAtIndex(fromWp, -1);
|
||||
_fp->insertWayptsAtIndex(path, -1);
|
||||
_fp->insertWayptAtIndex(toWp, -1);
|
||||
|
@ -470,7 +470,7 @@ bool FlightPlanController::tryGenerateRoute()
|
|||
|
||||
void FlightPlanController::clearRoute()
|
||||
{
|
||||
_fp->clear();
|
||||
_fp->clearAll();
|
||||
}
|
||||
|
||||
QString FlightPlanController::icaoRoute() const
|
||||
|
|
|
@ -249,8 +249,32 @@ void FlightPlan::deleteIndex(int aIndex)
|
|||
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
void FlightPlan::clear()
|
||||
|
||||
void FlightPlan::clearAll()
|
||||
{
|
||||
lockDelegates();
|
||||
_departure.clear();
|
||||
_departureRunway = nullptr;
|
||||
_destinationRunway = nullptr;
|
||||
_destination.clear();
|
||||
_sid.clear();
|
||||
_sidTransition.clear();
|
||||
_star.clear();
|
||||
_starTransition.clear();
|
||||
_approach.clear();
|
||||
_approachTransition.clear();
|
||||
_alternate.clear();
|
||||
|
||||
_cruiseAirspeedMach = 0.0;
|
||||
_cruiseAirspeedKnots = 0;
|
||||
_cruiseFlightLevel = 0;
|
||||
_cruiseAltitudeFt = 0;
|
||||
|
||||
clearLegs();
|
||||
unlockDelegates();
|
||||
}
|
||||
|
||||
void FlightPlan::clearLegs()
|
||||
{
|
||||
// some badly behaved CDU implementations call clear on a Nasal timer
|
||||
// during startup.
|
||||
|
@ -1015,7 +1039,7 @@ bool FlightPlan::loadGpxFormat(const SGPath& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
clear();
|
||||
clearAll();
|
||||
|
||||
// copy in case we need to modify
|
||||
WayptVec wps = gpxVisitor.waypoints();
|
||||
|
|
|
@ -207,7 +207,8 @@ public:
|
|||
void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
|
||||
|
||||
void deleteIndex(int index);
|
||||
void clear();
|
||||
void clearAll();
|
||||
void clearLegs();
|
||||
int clearWayptsWithFlag(WayptFlag flag);
|
||||
|
||||
int currentIndex() const
|
||||
|
|
|
@ -1673,17 +1673,29 @@ static naRef f_flightplan_deleteWP(naContext c, naRef me, int argc, naRef* args)
|
|||
return naNil();
|
||||
}
|
||||
|
||||
static naRef f_flightplan_clearPlan(naContext c, naRef me, int argc, naRef* args)
|
||||
static naRef f_flightplan_clearLegs(naContext c, naRef me, int argc, naRef* args)
|
||||
{
|
||||
FlightPlan* fp = flightplanGhost(me);
|
||||
if (!fp) {
|
||||
naRuntimeError(c, "flightplan.clearPlan called on non-flightplan object");
|
||||
naRuntimeError(c, "flightplan.clearLegs called on non-flightplan object");
|
||||
}
|
||||
|
||||
fp->clear();
|
||||
fp->clearLegs();
|
||||
return naNil();
|
||||
}
|
||||
|
||||
static naRef f_flightplan_clearAll(naContext c, naRef me, int argc, naRef* args)
|
||||
{
|
||||
FlightPlan* fp = flightplanGhost(me);
|
||||
if (!fp) {
|
||||
naRuntimeError(c, "flightplan.clearAll called on non-flightplan object");
|
||||
}
|
||||
|
||||
fp->clearAll();
|
||||
return naNil();
|
||||
}
|
||||
|
||||
|
||||
static naRef f_flightplan_clearWPType(naContext c, naRef me, int argc, naRef* args)
|
||||
{
|
||||
FlightPlan* fp = flightplanGhost(me);
|
||||
|
@ -2097,7 +2109,15 @@ naRef initNasalFlightPlan(naRef globals, naContext c)
|
|||
hashset(c, flightplanPrototype, "deleteWP", naNewFunc(c, naNewCCode(c, f_flightplan_deleteWP)));
|
||||
hashset(c, flightplanPrototype, "insertWPAfter", naNewFunc(c, naNewCCode(c, f_flightplan_insertWPAfter)));
|
||||
hashset(c, flightplanPrototype, "insertWaypoints", naNewFunc(c, naNewCCode(c, f_flightplan_insertWaypoints)));
|
||||
hashset(c, flightplanPrototype, "cleanPlan", naNewFunc(c, naNewCCode(c, f_flightplan_clearPlan)));
|
||||
|
||||
auto f = naNewFunc(c, naNewCCode(c, f_flightplan_clearLegs));
|
||||
hashset(c, flightplanPrototype, "cleanPlan", f); // original name for compat
|
||||
// alias to a better name
|
||||
hashset(c, flightplanPrototype, "clearLegs", f);
|
||||
|
||||
|
||||
hashset(c, flightplanPrototype, "clearAll", naNewFunc(c, naNewCCode(c, f_flightplan_clearAll)));
|
||||
|
||||
hashset(c, flightplanPrototype, "clearWPType", naNewFunc(c, naNewCCode(c, f_flightplan_clearWPType)));
|
||||
hashset(c, flightplanPrototype, "clone", naNewFunc(c, naNewCCode(c, f_flightplan_clone)));
|
||||
|
||||
|
|
|
@ -94,6 +94,17 @@ void FPNasalTests::testBasic()
|
|||
CPPUNIT_ASSERT(ok);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(string{"COSTA VOR-DME"}, fp1->legAtIndex(3)->waypoint()->source()->name());
|
||||
|
||||
ok = FGTestApi::executeNasal(R"(
|
||||
var fp = flightplan();
|
||||
fp.clearAll();
|
||||
unitTest.assert_equal(fp.getPlanSize(), 0);
|
||||
unitTest.assert_equal(fp.current, -1);
|
||||
unitTest.assert_equal(fp.departure, nil);
|
||||
unitTest.assert_equal(fp.sid, nil);
|
||||
unitTest.assert_equal(fp.cruiseSpeedKt, 0);
|
||||
)");
|
||||
CPPUNIT_ASSERT(ok);
|
||||
}
|
||||
|
||||
void FPNasalTests::testRestrictions()
|
||||
|
|
Loading…
Add table
Reference in a new issue