public CutRouteData Cut(ParameterizedLocation parameterizedLocation, CutType cutType) { var cutRoute = new CutRouteData { CutType = cutType }; switch (cutType) { case CutType.Before: cutRoute.Segments.AddRange(segments.GetRange(0, parameterizedLocation.SegmentIndex)); if (!parameterizedLocation.IsNode) { // cut between two waypoints: create cut waypoint Waypoint cutWaypoint = CreateWaypointFromParameterizedLocation(parameterizedLocation); var rs = new RouteSegment(); segments.RemoveRange(0, parameterizedLocation.SegmentIndex); rs.Waypoints.AddRange(segments[0].Waypoints.GetRange(0, (int)parameterizedLocation.Ceiling().Value)); cutRoute.Segments.Add(rs); segments[0].Waypoints.RemoveRange(0, (int)parameterizedLocation.Ceiling().Value); segments[0].Waypoints.Insert(0, cutWaypoint); cutRoute.WaypointInsertedAtCut = cutWaypoint; } else { // cut exactly at a waypoint var rs = new RouteSegment(); segments.RemoveRange(0, parameterizedLocation.SegmentIndex); rs.Waypoints.AddRange(segments[0].Waypoints.GetRange(0, (int)parameterizedLocation.Value)); cutRoute.Segments.Add(rs); segments[0].Waypoints.RemoveRange(0, (int)parameterizedLocation.Value); } // handle map readings nicely if (waypointAttributeExists[WaypointAttribute.MapReadingDuration] && segments[0].FirstWaypoint.MapReadingState == MapReadingState.Reading) { segments[0].FirstWaypoint.MapReadingState = MapReadingState.StartReading; } break; case CutType.After: if (parameterizedLocation.SegmentIndex < segments.Count - 1) { cutRoute.Segments.AddRange(segments.GetRange(parameterizedLocation.SegmentIndex + 1, segments.Count - 1 - parameterizedLocation.SegmentIndex)); segments.RemoveRange(parameterizedLocation.SegmentIndex + 1, segments.Count - 1 - parameterizedLocation.SegmentIndex); } var i = (int)parameterizedLocation.Ceiling().Value; int count = segments[parameterizedLocation.SegmentIndex].Waypoints.Count; if (!parameterizedLocation.IsNode) { // cut between two waypoints: create cut waypoint Waypoint cutWaypoint = CreateWaypointFromParameterizedLocation(parameterizedLocation); var rs = new RouteSegment(); rs.Waypoints.AddRange(segments[parameterizedLocation.SegmentIndex].Waypoints.GetRange(i, count - i)); cutRoute.Segments.Insert(0, rs); segments[parameterizedLocation.SegmentIndex].Waypoints.RemoveRange(i, count - i); segments[parameterizedLocation.SegmentIndex].Waypoints.Insert(i, cutWaypoint); cutRoute.WaypointInsertedAtCut = cutWaypoint; } else { // cut exactly at a waypoint var rs = new RouteSegment(); rs.Waypoints.AddRange(segments[parameterizedLocation.SegmentIndex].Waypoints.GetRange(i + 1, count - 1 - i)); cutRoute.Segments.Insert(0, rs); segments[parameterizedLocation.SegmentIndex].Waypoints.RemoveRange(i + 1, count - 1 - i); } // handle map readings nicely var lastWaypoint = segments[segments.Count - 1].LastWaypoint; if (waypointAttributeExists[WaypointAttribute.MapReadingDuration] && lastWaypoint.MapReadingState == MapReadingState.Reading) { lastWaypoint.MapReadingState = MapReadingState.EndReading; } break; } return cutRoute; }
public void UnCut(CutRouteData cutRouteData) { Waypoint cutWaypoint; switch (cutRouteData.CutType) { case CutType.Before: cutWaypoint = segments[0].FirstWaypoint; var beforeCutWaypoint = cutRouteData.Segments[cutRouteData.Segments.Count - 1].LastWaypoint; if (cutRouteData.WaypointInsertedAtCut != null) { segments[0].Waypoints.Remove(cutRouteData.WaypointInsertedAtCut); } segments.InsertRange(0, cutRouteData.Segments.GetRange(0, cutRouteData.Segments.Count - 1)); segments[cutRouteData.Segments.Count - 1].Waypoints. InsertRange(0, cutRouteData.Segments[cutRouteData.Segments.Count - 1].Waypoints); // handle map reading if (cutRouteData.WaypointInsertedAtCut == null) { if (cutWaypoint.MapReadingState == MapReadingState.StartReading && (beforeCutWaypoint.MapReadingState == MapReadingState.Reading || beforeCutWaypoint.MapReadingState == MapReadingState.StartReading)) { cutWaypoint.MapReadingState = MapReadingState.Reading; } } break; case CutType.After: cutWaypoint = segments[segments.Count - 1].LastWaypoint; var afterCutWaypoint = cutRouteData.Segments[0].FirstWaypoint; if (cutRouteData.WaypointInsertedAtCut != null) { segments[segments.Count - 1].Waypoints.Remove(cutRouteData.WaypointInsertedAtCut); } segments[segments.Count - 1].Waypoints.AddRange(cutRouteData.Segments[0].Waypoints); segments.AddRange(cutRouteData.Segments.GetRange(1, cutRouteData.Segments.Count - 1)); // handle map reading if (cutRouteData.WaypointInsertedAtCut == null) { if (cutWaypoint.MapReadingState == MapReadingState.EndReading && (afterCutWaypoint.MapReadingState == MapReadingState.Reading || afterCutWaypoint.MapReadingState == MapReadingState.EndReading)) { cutWaypoint.MapReadingState = MapReadingState.Reading; } } break; } }