Fix save route point as line. Do not calculate straight segments always.
This commit is contained in:
parent
b8d64ec5ed
commit
2b55f1dcb3
3 changed files with 59 additions and 15 deletions
|
@ -191,6 +191,10 @@ public class MeasurementEditingContext {
|
|||
return gpxData != null && gpxData.getGpxFile() != null && gpxData.getGpxFile().hasRtePt();
|
||||
}
|
||||
|
||||
public boolean hasSavedRoute() {
|
||||
return gpxData != null && gpxData.getGpxFile() != null && gpxData.getGpxFile().hasRoute();
|
||||
}
|
||||
|
||||
public CalculationMode getCalculationMode() {
|
||||
return calculationMode;
|
||||
}
|
||||
|
@ -321,6 +325,7 @@ public class MeasurementEditingContext {
|
|||
public void clearSegments() {
|
||||
clearBeforeSegments();
|
||||
clearAfterSegments();
|
||||
clearSnappedToRoadPoints();
|
||||
}
|
||||
|
||||
public void clearBeforeSegments() {
|
||||
|
@ -378,6 +383,16 @@ public class MeasurementEditingContext {
|
|||
}
|
||||
|
||||
private void recreateCacheForSnap(TrkSegment cache, TrkSegment original, boolean calculateIfNeeded) {
|
||||
boolean hasDefaultModeOnly = true;
|
||||
if (original.points.size() > 1) {
|
||||
for (int i = 0; i < original.points.size(); i++) {
|
||||
String profileType = original.points.get(i).getProfileType();
|
||||
if (profileType != null && !profileType.equals(DEFAULT_APP_MODE.getStringKey())) {
|
||||
hasDefaultModeOnly = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (original.points.size() > 1) {
|
||||
for (int i = 0; i < original.points.size() - 1; i++) {
|
||||
Pair<WptPt, WptPt> pair = new Pair<>(original.points.get(i), original.points.get(i + 1));
|
||||
|
@ -386,7 +401,7 @@ public class MeasurementEditingContext {
|
|||
if (pts != null) {
|
||||
cache.points.addAll(pts);
|
||||
} else {
|
||||
if (calculateIfNeeded) {
|
||||
if (calculateIfNeeded && !hasDefaultModeOnly) {
|
||||
scheduleRouteCalculateIfNotEmpty();
|
||||
}
|
||||
cache.points.addAll(Arrays.asList(pair.first, pair.second));
|
||||
|
@ -450,7 +465,7 @@ public class MeasurementEditingContext {
|
|||
}
|
||||
}
|
||||
|
||||
public void setPoints(GpxRouteApproximation gpxApproximation) {
|
||||
public void setPoints(GpxRouteApproximation gpxApproximation, ApplicationMode mode) {
|
||||
if (gpxApproximation == null || Algorithms.isEmpty(gpxApproximation.finalPoints) || Algorithms.isEmpty(gpxApproximation.result)) {
|
||||
return;
|
||||
}
|
||||
|
@ -463,12 +478,14 @@ public class MeasurementEditingContext {
|
|||
WptPt p1 = new WptPt();
|
||||
p1.lat = rp1.loc.getLatitude();
|
||||
p1.lon = rp1.loc.getLongitude();
|
||||
p1.setProfileType(mode.getStringKey());
|
||||
if (i == 0) {
|
||||
routePoints.add(p1);
|
||||
}
|
||||
WptPt p2 = new WptPt();
|
||||
p2.lat = rp2.loc.getLatitude();
|
||||
p2.lon = rp2.loc.getLongitude();
|
||||
p2.setProfileType(mode.getStringKey());
|
||||
routePoints.add(p2);
|
||||
Pair<WptPt, WptPt> pair = new Pair<>(p1, p2);
|
||||
List<WptPt> points = new ArrayList<>();
|
||||
|
@ -640,6 +657,24 @@ public class MeasurementEditingContext {
|
|||
return params;
|
||||
}
|
||||
|
||||
public List<WptPt> getDistinctRoutePoints() {
|
||||
List<WptPt> res = new ArrayList<>();
|
||||
List<WptPt> points = new ArrayList<>(before.points);
|
||||
points.addAll(after.points);
|
||||
int size = points.size();
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
Pair<WptPt, WptPt> pair = new Pair<>(points.get(i), points.get(i + 1));
|
||||
RoadSegmentData data = this.roadSegmentData.get(pair);
|
||||
if (data != null) {
|
||||
res.addAll(data.points);
|
||||
if (i < size - 2) {
|
||||
res.remove(res.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public GPXFile exportRouteAsGpx(@NonNull String gpxName) {
|
||||
if (application == null || before.points.isEmpty() || !hasRoute()) {
|
||||
|
|
|
@ -429,7 +429,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (editingCtx.isNewData() && planRouteMode) {
|
||||
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
createStartPlanRouteListener());
|
||||
} else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute()) {
|
||||
} else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) {
|
||||
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
|
||||
}
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
toolBarController.setTitle(getString(R.string.route_between_points));
|
||||
mapActivity.refreshMap();
|
||||
|
||||
if (editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.hasRoute()) {
|
||||
if (editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.hasRoute() || editingCtx.getPointsCount() < 2) {
|
||||
RouteBetweenPointsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
this, editingCtx.getCalculationMode(),
|
||||
editingCtx.getAppMode());
|
||||
|
@ -594,7 +594,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (editingCtx.getPointsCount() > 0) {
|
||||
GpxData gpxData = editingCtx.getGpxData();
|
||||
if (editingCtx.isNewData()) {
|
||||
saveAsGpx(SaveType.ROUTE_POINT);
|
||||
saveAsGpx(SaveType.ROUTE_POINT, close);
|
||||
} else if (isInEditMode() && gpxData.getActionType() == ActionType.EDIT_SEGMENT) {
|
||||
openSaveAsNewTrackMenu(mapActivity);
|
||||
} else {
|
||||
|
@ -799,6 +799,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (measurementLayer != null) {
|
||||
editingCtx.getCommandManager().execute(new ChangeRouteModeCommand(measurementLayer, mode, calculationMode));
|
||||
updateUndoRedoButton(false, redoBtn);
|
||||
updateUndoRedoButton(true, undoBtn);
|
||||
disable(upDownBtn);
|
||||
updateSnapToRoadControls();
|
||||
updateDistancePointsText();
|
||||
|
@ -912,12 +913,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
return new SaveAsNewTrackFragmentListener() {
|
||||
@Override
|
||||
public void saveAsRoutePointOnClick() {
|
||||
saveAsGpx(SaveType.ROUTE_POINT);
|
||||
saveAsGpx(SaveType.ROUTE_POINT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAsLineOnClick() {
|
||||
saveAsGpx(SaveType.LINE);
|
||||
saveAsGpx(SaveType.LINE, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1326,7 +1327,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
}
|
||||
|
||||
private void saveAsGpx(final SaveType saveType) {
|
||||
private void saveAsGpx(final SaveType saveType, final boolean close) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
|
@ -1365,7 +1366,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
fout = new File(dir, fileName);
|
||||
}
|
||||
}
|
||||
saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, false);
|
||||
saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, close);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
|
@ -1471,8 +1472,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (measurementLayer != null) {
|
||||
if (saveType == SaveType.LINE) {
|
||||
TrkSegment segment = new TrkSegment();
|
||||
segment.points.addAll(before.points);
|
||||
segment.points.addAll(after.points);
|
||||
if (editingCtx.hasRoute()) {
|
||||
segment.points.addAll(editingCtx.getDistinctRoutePoints());
|
||||
} else {
|
||||
segment.points.addAll(before.points);
|
||||
segment.points.addAll(after.points);
|
||||
}
|
||||
Track track = new Track();
|
||||
track.name = trackName;
|
||||
track.segments.add(segment);
|
||||
|
@ -1501,8 +1506,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (planRouteMode) {
|
||||
if (saveType == SaveType.LINE) {
|
||||
TrkSegment segment = new TrkSegment();
|
||||
segment.points.addAll(before.points);
|
||||
segment.points.addAll(after.points);
|
||||
if (editingCtx.hasRoute()) {
|
||||
segment.points.addAll(editingCtx.getDistinctRoutePoints());
|
||||
} else {
|
||||
segment.points.addAll(before.points);
|
||||
segment.points.addAll(after.points);
|
||||
}
|
||||
Track track = new Track();
|
||||
track.name = trackName;
|
||||
track.segments.add(segment);
|
||||
|
@ -1673,7 +1682,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
}
|
||||
if (!editMode && editingCtx.getPointsCount() > 1) {
|
||||
toolBarController.setTitle(fileName);
|
||||
toolBarController.setTitle(fileName.replace('_', ' '));
|
||||
toolBarController.setDescription(actionStr);
|
||||
} else {
|
||||
toolBarController.setTitle(actionStr);
|
||||
|
|
|
@ -66,6 +66,6 @@ public class ApplyGpxApproximationCommand extends MeasurementModeCommand {
|
|||
public void applyApproximation() {
|
||||
getEditingCtx().setAppMode(mode);
|
||||
getEditingCtx().clearSegments();
|
||||
getEditingCtx().setPoints(approximation);
|
||||
getEditingCtx().setPoints(approximation, mode);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue