diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 9abce9574..762d472b6 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -558,7 +558,7 @@ void FGRouteMgr::update( double dt ) void FGRouteMgr::clearRoute() { if (_plan) { - _plan->clear(); + _plan->clearLegs(); } } diff --git a/src/GUI/FlightPlanController.cxx b/src/GUI/FlightPlanController.cxx index 002db7e3d..7e8b8ca6f 100644 --- a/src/GUI/FlightPlanController.cxx +++ b/src/GUI/FlightPlanController.cxx @@ -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 diff --git a/src/Navaids/FlightPlan.cxx b/src/Navaids/FlightPlan.cxx index 9573caf62..840e8616b 100644 --- a/src/Navaids/FlightPlan.cxx +++ b/src/Navaids/FlightPlan.cxx @@ -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(); diff --git a/src/Navaids/FlightPlan.hxx b/src/Navaids/FlightPlan.hxx index f5c13b230..3b5a0de49 100644 --- a/src/Navaids/FlightPlan.hxx +++ b/src/Navaids/FlightPlan.hxx @@ -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 diff --git a/src/Scripting/NasalFlightPlan.cxx b/src/Scripting/NasalFlightPlan.cxx index 1cf7dea78..d7436f213 100644 --- a/src/Scripting/NasalFlightPlan.cxx +++ b/src/Scripting/NasalFlightPlan.cxx @@ -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))); diff --git a/test_suite/unit_tests/Navaids/test_fpNasal.cxx b/test_suite/unit_tests/Navaids/test_fpNasal.cxx index 21e8f4fdf..f2cb07fea 100644 --- a/test_suite/unit_tests/Navaids/test_fpNasal.cxx +++ b/test_suite/unit_tests/Navaids/test_fpNasal.cxx @@ -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()