From: jmt Date: Wed, 21 Oct 2009 07:18:19 +0000 (+0000) Subject: GPS commands to edit the route manager route. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2a86384da7e233d295fce3e2b601b311e2e465f8;p=flightgear.git GPS commands to edit the route manager route. --- diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx index 0080ed7d0..290dc6e4d 100644 --- a/src/Instrumentation/gps.cxx +++ b/src/Instrumentation/gps.cxx @@ -24,6 +24,7 @@ #include #include #include +#include using std::auto_ptr; using std::string; @@ -1287,8 +1288,40 @@ void GPS::setCommand(const char* aCmd) previousResult(); } else if (!strcmp(aCmd, "define-user-wpt")) { defineWaypoint(); + } else if (!strcmp(aCmd, "route-insert-before")) { + int index = _scratchNode->getIntValue("index"); + if (index < 0) { + index = _routeMgr->size(); + } else if (index >= _routeMgr->size()) { + SG_LOG(SG_INSTR, SG_WARN, "GPS:route-insert-before, bad index:" << index); + return; + } + + insertWaypointAtIndex(index); + } else if (!strcmp(aCmd, "route-insert-after")) { + int index = _scratchNode->getIntValue("index"); + if (index < 0) { + index = _routeMgr->size(); + } else if (index >= _routeMgr->size()) { + SG_LOG(SG_INSTR, SG_WARN, "GPS:route-insert-after, bad index:" << index); + return; + } else { + ++index; + } + + insertWaypointAtIndex(index); + } else if (!strcmp(aCmd, "route-delete")) { + int index = _scratchNode->getIntValue("index"); + if (index < 0) { + index = _routeMgr->size(); + } else if (index >= _routeMgr->size()) { + SG_LOG(SG_INSTR, SG_WARN, "GPS:route-delete, bad index:" << index); + return; + } + + removeWaypointAtIndex(index); } else { - SG_LOG(SG_INSTR, SG_WARN, "GPS:unrecognzied command:" << aCmd); + SG_LOG(SG_INSTR, SG_WARN, "GPS:unrecognized command:" << aCmd); } } @@ -1679,4 +1712,31 @@ void GPS::defineWaypoint() setScratchFromPositioned(wpt.get(), -1); } +void GPS::insertWaypointAtIndex(int aIndex) +{ + // note we do allow index = routeMgr->size(), that's an append + if ((aIndex < 0) || (aIndex > _routeMgr->size())) { + throw sg_range_exception("GPS::insertWaypointAtIndex: index out of bounds"); + } + + if (!isScratchPositionValid()) { + SG_LOG(SG_INSTR, SG_WARN, "GPS:insertWaypointAtIndex: invalid lat/lon"); + return; + } + + string ident = _scratchNode->getStringValue("ident"); + string name = _scratchNode->getStringValue("name"); + + _routeMgr->add_waypoint(SGWayPoint(_scratchPos, ident, name), aIndex); +} + +void GPS::removeWaypointAtIndex(int aIndex) +{ + if ((aIndex < 0) || (aIndex >= _routeMgr->size())) { + throw sg_range_exception("GPS::removeWaypointAtIndex: index out of bounds"); + } + + _routeMgr->pop_waypoint(aIndex); +} + // end of gps.cxx diff --git a/src/Instrumentation/gps.hxx b/src/Instrumentation/gps.hxx index 47f40b661..e745418d6 100644 --- a/src/Instrumentation/gps.hxx +++ b/src/Instrumentation/gps.hxx @@ -258,6 +258,8 @@ private: void nextResult(); void previousResult(); void defineWaypoint(); + void insertWaypointAtIndex(int aIndex); + void removeWaypointAtIndex(int aIndex); // tied-property getter/setters void setCommand(const char* aCmd);