delete cur;
}
}
+
+// delete legs
+ BOOST_FOREACH(Leg* l, _legs) {
+ delete l;
+ }
}
FlightPlan* FlightPlan::clone(const string& newIdent) const
}
_legs.clear();
+ if (_delegate) {
+ _delegate->runCleared();
+ }
unlockDelegate();
}
++count;
}
}
+
+ // test if the current leg will be removed
+ bool currentIsBeingCleared = false;
+ Leg* curLeg = currentLeg();
+ if (curLeg) {
+ currentIsBeingCleared = curLeg->waypoint()->flag(flag);
+ }
_currentIndex -= count;
+
+ // if we're clearing the current waypoint, what shall we do with the
+ // index? there's various options, but safest is to select no waypoint
+ // and let the use re-activate.
+ // http://code.google.com/p/flightgear-bugs/issues/detail?id=1134
+ if (currentIsBeingCleared) {
+ SG_LOG(SG_GENERAL, SG_INFO, "currentIsBeingCleared:" << currentIsBeingCleared);
+ _currentIndex = -1;
+ }
// now delete and remove
RemoveWithFlag rf(flag);
lockDelegate();
_waypointsChanged = true;
- if (count > 0) {
+ if ((count > 0) || currentIsBeingCleared) {
_currentWaypointChanged = true;
}
_legs.erase(it, _legs.end());
+
+ if (_legs.empty()) { // maybe all legs were deleted
+ if (_delegate) {
+ _delegate->runCleared();
+ }
+ }
+
unlockDelegate();
return rf.numDeleted();
}
_currentWaypointChanged = true;
unlockDelegate();
}
+
+void FlightPlan::finish()
+{
+ if (_currentIndex == -1) {
+ return;
+ }
+
+ lockDelegate();
+ _currentIndex = -1;
+ _currentWaypointChanged = true;
+
+ if (_delegate) {
+ _delegate->runFinished();
+ }
+
+ unlockDelegate();
+}
int FlightPlan::findWayptIndex(const SGGeod& aPos) const
{
_deleteWithPlan(false),
_inner(NULL)
{
-
}
FlightPlan::Delegate::~Delegate()
-{
-
+{
}
void FlightPlan::Delegate::removeInner(Delegate* d)
{
if (!_inner) {
- return;
+ throw sg_exception("FlightPlan delegate not found");
}
if (_inner == d) {
if (_inner) _inner->runCurrentWaypointChanged();
currentWaypointChanged();
}
-
+
+void FlightPlan::Delegate::runCleared()
+{
+ if (_inner) _inner->runCleared();
+ cleared();
+}
+
+void FlightPlan::Delegate::runFinished()
+{
+ if (_inner) _inner->runFinished();
+ endOfFlightPlan();
+}
+
} // of namespace flightgear