From c941880444c42ed55e5a47060a0b8b3cb37ed250 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 17 Feb 2021 15:02:26 +0200 Subject: [PATCH 1/2] Fix reverse for multisegment --- .../FollowTrackFragment.java | 24 +++++++++---------- .../osmand/plus/routing/RouteProvider.java | 6 ++++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index 82a8ea2d88..dc2d1ec79e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -226,16 +226,14 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute(); boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND; if (rparams != null && osmandRouter) { - boolean showReverseCard = !routingHelper.isCurrentGPXRouteV2(); - if (showReverseCard) { - cardsContainer.addView(buildDividerView(cardsContainer, false)); + cardsContainer.addView(buildDividerView(cardsContainer, false)); + + ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, rparams.isReverse()); + reverseTrackCard.setListener(this); + cardsContainer.addView(reverseTrackCard.build(mapActivity)); - ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, rparams.isReverse()); - reverseTrackCard.setListener(this); - cardsContainer.addView(reverseTrackCard.build(mapActivity)); - } if (!gpxFile.hasRtePt() && !gpxFile.hasRoute()) { - cardsContainer.addView(buildDividerView(cardsContainer, showReverseCard)); + cardsContainer.addView(buildDividerView(cardsContainer, true)); AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity); attachTrackCard.setListener(this); @@ -721,11 +719,11 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca @Override public void onSegmentSelect(GPXFile gpxFile, int selectedSegment) { selectTrackToFollow(gpxFile); - GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); - if (paramsBuilder != null) { - paramsBuilder.setSelectedSegment(selectedSegment); - app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment); - app.getRoutingHelper().onSettingsChanged(true); + GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); + if (paramsBuilder != null) { + paramsBuilder.setSelectedSegment(selectedSegment); + app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment); + app.getRoutingHelper().onSettingsChanged(true); } updateSelectionMode(false); } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 051a5218fa..eb1ffedae5 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -289,7 +289,11 @@ public class RouteProvider { int selectedSegment = builder.getSelectedSegment(); if (OSMAND_ROUTER_V2.equals(file.author)) { route = parseOsmAndGPXRoute(points, file, selectedSegment); - routePoints = file.getRoutePoints(); + if (selectedSegment == -1) { + routePoints = file.getRoutePoints(); + } else { + routePoints = file.getRoutePoints(selectedSegment); + } if (reverse) { Collections.reverse(points); Collections.reverse(routePoints); From 05271e8ac5725e3c4ff9826611f4d7b5a05b8700 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 17 Feb 2021 16:02:00 +0200 Subject: [PATCH 2/2] Show attach roads for multitrack --- .../MeasurementEditingContext.java | 132 ++++++++++-------- .../FollowTrackFragment.java | 1 + 2 files changed, 77 insertions(+), 56 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 74094cd07b..3512de68bc 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -62,6 +62,7 @@ public class MeasurementEditingContext implements IRouteSettingsListener { private List afterSegmentsForSnap; private GpxData gpxData; + private int selectedSegment = -1; private int selectedPointPosition = -1; private WptPt originalPointToMove; @@ -180,6 +181,10 @@ public class MeasurementEditingContext implements IRouteSettingsListener { this.gpxData = gpxData; } + public void setSelectedSegment(int selectedSegment) { + this.selectedSegment = selectedSegment; + } + public boolean hasRoutePoints() { return gpxData != null && gpxData.getGpxFile() != null && gpxData.getGpxFile().hasRtePt(); } @@ -688,7 +693,7 @@ public class MeasurementEditingContext implements IRouteSettingsListener { return res; } - private List> getOrderedRoadSegmentDataKeys() { + private List> getOrderedRoadSegmentDataKeys() { List> keys = new ArrayList<>(); for (List points : Arrays.asList(before.points, after.points)) { for (int i = 0; i < points.size() - 1; i++) { @@ -697,7 +702,7 @@ public class MeasurementEditingContext implements IRouteSettingsListener { } return keys; } - + private void recreateSegments(List segments, List segmentsForSnap, List points, boolean calculateIfNeeded) { List roadSegmentIndexes = new ArrayList<>(); TrkSegment s = new TrkSegment(); @@ -767,67 +772,82 @@ public class MeasurementEditingContext implements IRouteSettingsListener { if (Algorithms.isEmpty(segments)) { return; } - for (int si = 0; si < segments.size(); si++) { - TrkSegment segment = segments.get(si); - List points = segment.points; + if (selectedSegment != -1 && segments.size() > selectedSegment) { + TrkSegment segment = segments.get(selectedSegment); if (segment.hasRoute()) { - RouteImporter routeImporter = new RouteImporter(segment); - List routeSegments = routeImporter.importRoute(); - List routePoints = gpxData.getGpxFile().getRoutePoints(si); - int prevPointIndex = 0; - if (routePoints.isEmpty() && points.size() > 1) { - routePoints.add(points.get(0)); - routePoints.add(points.get(points.size() - 1)); - } - for (int i = 0; i < routePoints.size() - 1; i++) { - Pair pair = new Pair<>(routePoints.get(i), routePoints.get(i + 1)); - int startIndex = pair.first.getTrkPtIndex(); - if (startIndex < 0 || startIndex < prevPointIndex || startIndex >= points.size()) { - startIndex = MeasurementEditingContextUtils.findPointIndex(pair.first, points, prevPointIndex); - } - int endIndex = pair.second.getTrkPtIndex(); - if (endIndex < 0 || endIndex < startIndex || endIndex >= points.size()) { - endIndex = MeasurementEditingContextUtils.findPointIndex(pair.second, points, startIndex); - } - if (startIndex >= 0 && endIndex >= 0) { - List pairPoints = new ArrayList<>(); - for (int j = startIndex; j < endIndex && j < points.size(); j++) { - pairPoints.add(points.get(j)); - prevPointIndex = j; - } - if (points.size() > prevPointIndex + 1 && i == routePoints.size() - 2) { - pairPoints.add(points.get(prevPointIndex + 1)); - } - Iterator it = routeSegments.iterator(); - int k = endIndex - startIndex - 1; - List pairSegments = new ArrayList<>(); - if (k == 0 && !routeSegments.isEmpty()) { - pairSegments.add(routeSegments.remove(0)); - } else { - while (it.hasNext() && k > 0) { - RouteSegmentResult s = it.next(); - pairSegments.add(s); - it.remove(); - k -= Math.abs(s.getEndPointIndex() - s.getStartPointIndex()); - } - } - ApplicationMode appMode = ApplicationMode.valueOfStringKey(pair.first.getProfileType(), DEFAULT_APP_MODE); - roadSegmentData.put(pair, new RoadSegmentData(appMode, pair.first, pair.second, pairPoints, pairSegments)); - } - } - if (!routePoints.isEmpty() && si < segments.size() - 1) { - routePoints.get(routePoints.size() - 1).setGap(); - } - addPoints(routePoints); + addPoints(collectRoutePointsFromSegment(segment, selectedSegment)); } else { - addPoints(points); - if (!points.isEmpty() && si < segments.size() - 1) { - points.get(points.size() - 1).setGap(); + addPoints(segment.points); + } + } else { + for (int si = 0; si < segments.size(); si++) { + TrkSegment segment = segments.get(si); + if (segment.hasRoute()) { + List routePoints = collectRoutePointsFromSegment(segment, si); + if (!routePoints.isEmpty() && si < segments.size() - 1) { + routePoints.get(routePoints.size() - 1).setGap(); + } + addPoints(routePoints); + } else { + List points = segment.points; + addPoints(points); + if (!points.isEmpty() && si < segments.size() - 1) { + points.get(points.size() - 1).setGap(); + } } } } } + private List collectRoutePointsFromSegment(TrkSegment segment, int segmentIndex) { + RouteImporter routeImporter = new RouteImporter(segment); + List routeSegments = routeImporter.importRoute(); + List routePoints = gpxData.getGpxFile().getRoutePoints(segmentIndex); + int prevPointIndex = 0; + List points = segment.points; + if (routePoints.isEmpty() && points.size() > 1) { + routePoints.add(points.get(0)); + routePoints.add(points.get(points.size() - 1)); + } + for (int i = 0; i < routePoints.size() - 1; i++) { + Pair pair = new Pair<>(routePoints.get(i), routePoints.get(i + 1)); + int startIndex = pair.first.getTrkPtIndex(); + if (startIndex < 0 || startIndex < prevPointIndex || startIndex >= points.size()) { + startIndex = MeasurementEditingContextUtils.findPointIndex(pair.first, points, prevPointIndex); + } + int endIndex = pair.second.getTrkPtIndex(); + if (endIndex < 0 || endIndex < startIndex || endIndex >= points.size()) { + endIndex = MeasurementEditingContextUtils.findPointIndex(pair.second, points, startIndex); + } + if (startIndex >= 0 && endIndex >= 0) { + List pairPoints = new ArrayList<>(); + for (int j = startIndex; j < endIndex && j < points.size(); j++) { + pairPoints.add(points.get(j)); + prevPointIndex = j; + } + if (points.size() > prevPointIndex + 1 && i == routePoints.size() - 2) { + pairPoints.add(points.get(prevPointIndex + 1)); + } + Iterator it = routeSegments.iterator(); + int k = endIndex - startIndex - 1; + List pairSegments = new ArrayList<>(); + if (k == 0 && !routeSegments.isEmpty()) { + pairSegments.add(routeSegments.remove(0)); + } else { + while (it.hasNext() && k > 0) { + RouteSegmentResult s = it.next(); + pairSegments.add(s); + it.remove(); + k -= Math.abs(s.getEndPointIndex() - s.getStartPointIndex()); + } + } + ApplicationMode appMode = ApplicationMode.valueOfStringKey(pair.first.getProfileType(), DEFAULT_APP_MODE); + roadSegmentData.put(pair, new RoadSegmentData(appMode, pair.first, pair.second, pairPoints, pairSegments)); + } + } + return routePoints; + } + public List setPoints(GpxRouteApproximation gpxApproximation, List originalPoints, ApplicationMode mode) { if (gpxApproximation == null || Algorithms.isEmpty(gpxApproximation.finalPoints) || Algorithms.isEmpty(gpxApproximation.result)) { return null; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index dc2d1ec79e..067c09025e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -582,6 +582,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca MeasurementEditingContext editingContext = new MeasurementEditingContext(); editingContext.setGpxData(gpxData); editingContext.setAppMode(app.getRoutingHelper().getAppMode()); + editingContext.setSelectedSegment(app.getSettings().GPX_ROUTE_SEGMENT.get()); MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true); } }