Finished gpx approximation

This commit is contained in:
max-klaus 2020-08-14 17:18:16 +03:00
parent 2ab38a54b5
commit ea83bc6d5d
14 changed files with 265 additions and 116 deletions

View file

@ -310,7 +310,7 @@ public class RoutePlannerFrontEnd {
System.out.println(gctx);
}
if (resultMatcher != null) {
resultMatcher.publish(gctx);
resultMatcher.publish(gctx.calculationCancelled ? null : gctx);
}
gctx.calculationDone = true;
return gctx;

View file

@ -31,8 +31,6 @@ import net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation;
import org.apache.commons.logging.Log;
import java.io.IOException;
import static net.osmand.plus.measurementtool.ProfileCard.ProfileCardListener;
import static net.osmand.plus.measurementtool.SliderCard.SliderCardListener;
@ -40,7 +38,7 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
implements SliderCardListener, ProfileCardListener {
private static final Log LOG = PlatformUtil.getLog(GpxApproximationFragment.class);
public static final String TAG = GpxApproximationFragment.class.getSimpleName();
public static final String TAG = GpxApproximationFragment.class.getName();
public static final String DISTANCE_THRESHOLD_KEY = "distance_threshold";
public static final String SNAP_TO_ROAD_APP_MODE_STRING_KEY = "snap_to_road_app_mode";
@ -49,11 +47,14 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
private int menuTitleHeight;
private ApplicationMode snapToRoadAppMode = ApplicationMode.CAR;
private int distanceThreshold = 50;
private boolean applyApproximation;
private LocationsHolder locationsHolder;
@Nullable
private GpxApproximator gpxApproximator;
private ProgressBar progressBar;
private View cancelButton;
private View applyButton;
@Override
public int getMainLayoutId() {
@ -139,6 +140,8 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
});
}
applyButton = mainView.findViewById(R.id.right_bottom_button);
cancelButton = mainView.findViewById(R.id.dismiss_button);
if (isPortrait()) {
updateCardsLayout();
}
@ -182,10 +185,15 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
@Override
public void onDestroyView() {
super.onDestroyView();
if (gpxApproximator != null) {
gpxApproximator.cancelApproximation();
}
exitGpxApproximationMode();
Fragment fragment = getTargetFragment();
if (fragment instanceof GpxApproximationFragmentListener) {
((GpxApproximationFragmentListener) fragment).onCancelGpxApproximation();
if (!applyApproximation) {
Fragment fragment = getTargetFragment();
if (fragment instanceof GpxApproximationFragmentListener) {
((GpxApproximationFragmentListener) fragment).onCancelGpxApproximation();
}
}
}
@ -213,7 +221,6 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
private void updateButtons(View view) {
View buttonsContainer = view.findViewById(R.id.buttons_container);
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg));
View applyButton = view.findViewById(R.id.right_bottom_button);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -221,11 +228,10 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
if (fragment instanceof GpxApproximationFragmentListener) {
((GpxApproximationFragmentListener) fragment).onApplyGpxApproximation();
}
applyApproximation = true;
dismiss();
}
});
View cancelButton = view.findViewById(R.id.dismiss_button);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -235,14 +241,18 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
}
}
});
UiUtilities.setupDialogButton(isNightMode(), cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(isNightMode(), applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
AndroidUiHelper.updateVisibility(applyButton, true);
AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true);
}
private void setApplyButtonEnabled(boolean enabled) {
if (applyButton != null) {
applyButton.setEnabled(enabled);
}
}
private void updateCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -328,14 +338,18 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
@Override
public void onSliderChange(int sliderValue) {
distanceThreshold = sliderValue;
calculateGpxApproximation();
if (distanceThreshold != sliderValue) {
distanceThreshold = sliderValue;
calculateGpxApproximation();
}
}
@Override
public void onProfileSelect(ApplicationMode applicationMode) {
snapToRoadAppMode = applicationMode;
calculateGpxApproximation();
if (snapToRoadAppMode != applicationMode) {
snapToRoadAppMode = applicationMode;
calculateGpxApproximation();
}
}
public LocationsHolder getLocationsHolder() {
@ -370,6 +384,7 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
private void approximateGpx() {
if (gpxApproximator != null) {
setApplyButtonEnabled(false);
gpxApproximator.calculateGpxApproximation(new ResultMatcher<GpxRouteApproximation>() {
@Override
public boolean publish(final GpxRouteApproximation gpxApproximation) {
@ -380,8 +395,9 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
public void run() {
Fragment fragment = getTargetFragment();
if (fragment instanceof GpxApproximationFragmentListener) {
((GpxApproximationFragmentListener) fragment).onGpxApproximationDone(gpxApproximation);
((GpxApproximationFragmentListener) fragment).onGpxApproximationDone(gpxApproximation, gpxApproximator.getMode());
}
setApplyButtonEnabled(gpxApproximation != null);
}
});
return true;
@ -399,7 +415,7 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
public interface GpxApproximationFragmentListener {
void onGpxApproximationDone(GpxRouteApproximation gpxApproximation);
void onGpxApproximationDone(GpxRouteApproximation gpxApproximation, ApplicationMode mode);
void onApplyGpxApproximation();

View file

@ -17,7 +17,6 @@ import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RoutePlannerFrontEnd;
import net.osmand.router.RoutePlannerFrontEnd.GpxPoint;
import net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation;
import net.osmand.router.RouteSegmentResult;
@ -32,7 +31,7 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType.*;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationType.WHOLE_TRACK;
public class MeasurementEditingContext {
@ -111,7 +110,7 @@ public class MeasurementEditingContext {
this.inAddPointMode = inAddPointMode;
}
void setInSnapToRoadMode(boolean inSnapToRoadMode) {
public void setInSnapToRoadMode(boolean inSnapToRoadMode) {
this.inSnapToRoadMode = inSnapToRoadMode;
}
@ -147,7 +146,7 @@ public class MeasurementEditingContext {
return snapToRoadAppMode;
}
void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
public void setSnapToRoadAppMode(ApplicationMode snapToRoadAppMode) {
if (this.snapToRoadAppMode != null && snapToRoadAppMode != null
&& !this.snapToRoadAppMode.getStringKey().equals(snapToRoadAppMode.getStringKey())) {
if (calculationType == WHOLE_TRACK) {
@ -327,36 +326,50 @@ public class MeasurementEditingContext {
}
}
void setPoints(GpxRouteApproximation gpxApproximation) {
public void setPoints(GpxRouteApproximation gpxApproximation) {
if (gpxApproximation == null || Algorithms.isEmpty(gpxApproximation.finalPoints) || Algorithms.isEmpty(gpxApproximation.result)) {
return;
}
clearSegments();
List<GpxPoint> routePoints = gpxApproximation.finalPoints;
for (int i = 0; i < routePoints.size() - 1; i++) {
GpxPoint rp1 = routePoints.get(i);
GpxPoint rp2 = routePoints.get(i + 1);
snappedToRoadPoints.clear();
List<WptPt> routePoints = new ArrayList<>();
List<GpxPoint> gpxPoints = gpxApproximation.finalPoints;
for (int i = 0; i < gpxPoints.size() - 1; i++) {
GpxPoint rp1 = gpxPoints.get(i);
GpxPoint rp2 = gpxPoints.get(i + 1);
WptPt p1 = new WptPt();
p1.lat = rp1.loc.getLatitude();
p1.lon = rp1.loc.getLongitude();
if (i == 0) {
routePoints.add(p1);
}
WptPt p2 = new WptPt();
p2.lat = rp2.loc.getLatitude();
p2.lon = rp2.loc.getLongitude();
routePoints.add(p2);
Pair<WptPt, WptPt> pair = new Pair<>(p1, p2);
List<WptPt> cacheSegment = new ArrayList<>();
for (RouteSegmentResult seg : rp1.routeToTarget) {
int start = seg.isForwardDirection() ? seg.getStartPointIndex() : seg.getEndPointIndex();
int end = seg.isForwardDirection() ? seg.getEndPointIndex() : seg.getStartPointIndex();
for (int ik = start; ik <= end; ik++) {
LatLon l = seg.getPoint(ik);
WptPt pt = new WptPt();
pt.lat = l.getLatitude();
pt.lon = l.getLongitude();
cacheSegment.add(pt);
if (seg.isForwardDirection()) {
for (int ik = seg.getStartPointIndex(); ik <= seg.getEndPointIndex(); ik++) {
LatLon l = seg.getPoint(ik);
WptPt pt = new WptPt();
pt.lat = l.getLatitude();
pt.lon = l.getLongitude();
cacheSegment.add(pt);
}
} else {
for (int ik = seg.getEndPointIndex(); ik >= seg.getStartPointIndex(); ik--) {
LatLon l = seg.getPoint(ik);
WptPt pt = new WptPt();
pt.lat = l.getLatitude();
pt.lon = l.getLongitude();
cacheSegment.add(pt);
}
}
}
snappedToRoadPoints.put(pair, cacheSegment);
}
addPoints(routePoints);
}
private int findPointIndex(WptPt point, List<WptPt> points, int firstIndex) {

View file

@ -70,6 +70,7 @@ import net.osmand.plus.measurementtool.SelectedPointBottomSheetDialogFragment.Se
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter.MeasurementAdapterListener;
import net.osmand.plus.measurementtool.command.AddPointCommand;
import net.osmand.plus.measurementtool.command.ApplyGpxApproximationCommand;
import net.osmand.plus.measurementtool.command.ClearPointsCommand;
import net.osmand.plus.measurementtool.command.MovePointCommand;
import net.osmand.plus.measurementtool.command.RemovePointCommand;
@ -477,32 +478,35 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
private void initMeasurementMode(NewGpxData newGpxData) {
editingCtx.getCommandManager().resetMeasurementLayer(getMapActivity().getMapLayers().getMeasurementToolLayer());
enterMeasurementMode();
showSnapToRoadControls();
if (newGpxData != null && !gpxPointsAdded) {
List<WptPt> points = newGpxData.getGpxFile().getRoutePoints();
if (!points.isEmpty()) {
ApplicationMode snapToRoadAppMode = ApplicationMode
.valueOfStringKey(points.get(points.size() - 1).getProfileType(), null);
if (snapToRoadAppMode != null) {
enableSnapToRoadMode(snapToRoadAppMode);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
editingCtx.getCommandManager().setMeasurementLayer(mapActivity.getMapLayers().getMeasurementToolLayer());
enterMeasurementMode();
showSnapToRoadControls();
if (newGpxData != null && !gpxPointsAdded) {
List<WptPt> points = newGpxData.getGpxFile().getRoutePoints();
if (!points.isEmpty()) {
ApplicationMode snapToRoadAppMode = ApplicationMode
.valueOfStringKey(points.get(points.size() - 1).getProfileType(), null);
if (snapToRoadAppMode != null) {
enableSnapToRoadMode(snapToRoadAppMode);
}
}
ActionType actionType = newGpxData.getActionType();
if (actionType == ActionType.ADD_ROUTE_POINTS) {
displayRoutePoints();
gpxPointsAdded = true;
} else if (actionType == ActionType.EDIT_SEGMENT) {
displaySegmentPoints();
gpxPointsAdded = true;
}
}
ActionType actionType = newGpxData.getActionType();
if (actionType == ActionType.ADD_ROUTE_POINTS) {
displayRoutePoints();
gpxPointsAdded = true;
} else if (actionType == ActionType.EDIT_SEGMENT) {
displaySegmentPoints();
gpxPointsAdded = true;
if (saved == null) {
saved = newGpxData != null
&& (newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS
|| newGpxData.getActionType() == ActionType.EDIT_SEGMENT);
}
}
if (saved == null) {
saved = newGpxData != null
&& (newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS
|| newGpxData.getActionType() == ActionType.EDIT_SEGMENT);
}
}
@Override
@ -547,7 +551,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Nullable
private MapActivity getMapActivity() {
Activity activity = getActivity();
if (activity instanceof MapActivity && !activity.isFinishing()) {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
return (MapActivity) activity;
}
return null;
@ -601,7 +605,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setTitle(getString(R.string.route_between_points));
mapActivity.refreshMap();
if (editingCtx.isNewData() || editingCtx.hasRoutePoints()) {
if (editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.isInSnapToRoadMode()) {
RouteBetweenPointsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, editingCtx.getCalculationType(),
editingCtx.getSnapToRoadAppMode());
@ -1057,15 +1061,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
public void displayApproximatedPoints(GpxRouteApproximation gpxApproximation) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
editingCtx.setPoints(gpxApproximation);
adapter.notifyDataSetChanged();
updateDistancePointsText();
}
}
private void openSelectedPointMenu(MapActivity mapActivity) {
SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment();
fragment.setUsedOnMap(true);
@ -1929,17 +1924,28 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
@Override
public void onGpxApproximationDone(GpxRouteApproximation gpxApproximation) {
displayApproximatedPoints(gpxApproximation);
public void onGpxApproximationDone(GpxRouteApproximation gpxApproximation, ApplicationMode mode) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
ApplyGpxApproximationCommand command = new ApplyGpxApproximationCommand(measurementLayer, gpxApproximation, mode);
if (!editingCtx.getCommandManager().update(command)) {
editingCtx.getCommandManager().execute(command);
}
if (pointsListOpened) {
hidePointsList();
}
showSnapToRoadControls();
}
}
@Override
public void onApplyGpxApproximation() {
doAddOrMovePointCommonStuff();
}
@Override
public void onCancelGpxApproximation() {
editingCtx.getCommandManager().undo();
showSnapToRoadControls();
}
}

View file

@ -11,15 +11,16 @@ public class AddPointCommand extends MeasurementModeCommand {
private boolean center;
public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) {
super(measurementLayer);
init(measurementLayer, null, center);
}
public AddPointCommand(MeasurementToolLayer measurementLayer, LatLon latLon) {
super(measurementLayer);
init(measurementLayer, latLon, false);
}
private void init(MeasurementToolLayer measurementLayer, LatLon latLon, boolean center) {
this.measurementLayer = measurementLayer;
if (latLon != null) {
point = new WptPt();
point.lat = latLon.getLatitude();
@ -32,27 +33,27 @@ public class AddPointCommand extends MeasurementModeCommand {
@Override
public boolean execute() {
if (point != null) {
measurementLayer.getEditingCtx().addPoint(point);
getEditingCtx().addPoint(point);
measurementLayer.moveMapToPoint(position);
} else if (center) {
point = measurementLayer.addCenterPoint();
} else {
point = measurementLayer.addPoint();
}
measurementLayer.refreshMap();
refreshMap();
return point != null;
}
@Override
public void undo() {
measurementLayer.getEditingCtx().removePoint(position, true);
measurementLayer.refreshMap();
getEditingCtx().removePoint(position, true);
refreshMap();
}
@Override
public void redo() {
measurementLayer.getEditingCtx().addPoint(position, point);
measurementLayer.refreshMap();
getEditingCtx().addPoint(position, point);
refreshMap();
measurementLayer.moveMapToPoint(position);
}

View file

@ -0,0 +1,77 @@
package net.osmand.plus.measurementtool.command;
import androidx.annotation.NonNull;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation;
import java.util.ArrayList;
import java.util.List;
public class ApplyGpxApproximationCommand extends MeasurementModeCommand {
private ApplicationMode mode;
private GpxRouteApproximation approximation;
private List<WptPt> points;
private boolean needUpdateCache;
public ApplyGpxApproximationCommand(MeasurementToolLayer measurementLayer, GpxRouteApproximation approximation, ApplicationMode mode) {
super(measurementLayer);
this.approximation = approximation;
this.mode = mode;
}
@Override
MeasurementCommandType getType() {
return MeasurementCommandType.APPROXIMATE_POINTS;
}
@Override
public boolean execute() {
List<WptPt> pts = getEditingCtx().getPoints();
needUpdateCache = getEditingCtx().isNeedUpdateCacheForSnap();
points = new ArrayList<>(pts);
applyApproximation();
refreshMap();
return true;
}
@Override
public boolean update(@NonNull Command command) {
if (command instanceof ApplyGpxApproximationCommand) {
ApplyGpxApproximationCommand approxCommand = (ApplyGpxApproximationCommand) command;
approximation = approxCommand.approximation;
applyApproximation();
refreshMap();
return true;
}
return false;
}
@Override
public void undo() {
getEditingCtx().setInSnapToRoadMode(false);
getEditingCtx().clearSegments();
getEditingCtx().setSnapToRoadAppMode(null);
getEditingCtx().addPoints(points);
if (needUpdateCache) {
getEditingCtx().setNeedUpdateCacheForSnap(true);
}
refreshMap();
}
@Override
public void redo() {
applyApproximation();
refreshMap();
}
public void applyApproximation() {
getEditingCtx().setInSnapToRoadMode(true);
getEditingCtx().clearSegments();
getEditingCtx().setSnapToRoadAppMode(mode);
getEditingCtx().setPoints(approximation);
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.measurementtool.command;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@ -12,33 +13,33 @@ public class ClearPointsCommand extends MeasurementModeCommand {
private boolean needUpdateCache;
public ClearPointsCommand(MeasurementToolLayer measurementLayer) {
this.measurementLayer = measurementLayer;
super(measurementLayer);
}
@Override
public boolean execute() {
List<WptPt> pts = measurementLayer.getEditingCtx().getPoints();
needUpdateCache = measurementLayer.getEditingCtx().isNeedUpdateCacheForSnap();
points = new LinkedList<>(pts);
List<WptPt> pts = getEditingCtx().getPoints();
needUpdateCache = getEditingCtx().isNeedUpdateCacheForSnap();
points = new ArrayList<>(pts);
pts.clear();
measurementLayer.getEditingCtx().clearSegments();
measurementLayer.refreshMap();
getEditingCtx().clearSegments();
refreshMap();
return true;
}
@Override
public void undo() {
measurementLayer.getEditingCtx().addPoints(points);
getEditingCtx().addPoints(points);
if (needUpdateCache) {
measurementLayer.getEditingCtx().setNeedUpdateCacheForSnap(true);
getEditingCtx().setNeedUpdateCacheForSnap(true);
}
measurementLayer.refreshMap();
refreshMap();
}
@Override
public void redo() {
measurementLayer.getEditingCtx().clearSegments();
measurementLayer.refreshMap();
getEditingCtx().clearSegments();
refreshMap();
}
@Override

View file

@ -1,9 +1,13 @@
package net.osmand.plus.measurementtool.command;
import androidx.annotation.NonNull;
interface Command {
boolean execute();
boolean update(@NonNull Command command);
void undo();
void redo();

View file

@ -30,6 +30,11 @@ public class MeasurementCommandManager {
return false;
}
public boolean update(MeasurementModeCommand command) {
MeasurementModeCommand prevCommand = undoCommands.peek();
return prevCommand != null && prevCommand.update(command);
}
@Nullable
public MeasurementCommandType undo() {
if (canUndo()) {
@ -52,7 +57,7 @@ public class MeasurementCommandManager {
return null;
}
public void resetMeasurementLayer(MeasurementToolLayer layer) {
public void setMeasurementLayer(MeasurementToolLayer layer) {
for (MeasurementModeCommand command : undoCommands) {
command.setMeasurementLayer(layer);
}

View file

@ -1,23 +1,44 @@
package net.osmand.plus.measurementtool.command;
import androidx.annotation.NonNull;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
public abstract class MeasurementModeCommand implements Command {
MeasurementToolLayer measurementLayer;
public MeasurementModeCommand(MeasurementToolLayer measurementLayer) {
this.measurementLayer = measurementLayer;
}
void setMeasurementLayer(MeasurementToolLayer layer) {
this.measurementLayer = layer;
}
@Override
public boolean update(@NonNull Command command) {
return false;
}
abstract MeasurementCommandType getType();
MeasurementEditingContext getEditingCtx() {
return measurementLayer.getEditingCtx();
}
void refreshMap() {
measurementLayer.refreshMap();
}
public enum MeasurementCommandType {
ADD_POINT,
CLEAR_POINTS,
MOVE_POINT,
REMOVE_POINT,
REORDER_POINT,
SNAP_TO_ROAD
SNAP_TO_ROAD,
APPROXIMATE_POINTS
}
}

View file

@ -10,7 +10,7 @@ public class MovePointCommand extends MeasurementModeCommand {
private final int position;
public MovePointCommand(MeasurementToolLayer measurementLayer, WptPt oldPoint, WptPt newPoint, int position) {
this.measurementLayer = measurementLayer;
super(measurementLayer);
this.oldPoint = oldPoint;
this.newPoint = newPoint;
this.position = position;
@ -23,16 +23,16 @@ public class MovePointCommand extends MeasurementModeCommand {
@Override
public void undo() {
measurementLayer.getEditingCtx().removePoint(position, false);
measurementLayer.getEditingCtx().addPoint(position, oldPoint);
measurementLayer.refreshMap();
getEditingCtx().removePoint(position, false);
getEditingCtx().addPoint(position, oldPoint);
refreshMap();
}
@Override
public void redo() {
measurementLayer.getEditingCtx().removePoint(position, false);
measurementLayer.getEditingCtx().addPoint(position, newPoint);
measurementLayer.refreshMap();
getEditingCtx().removePoint(position, false);
getEditingCtx().addPoint(position, newPoint);
refreshMap();
}
@Override

View file

@ -9,28 +9,28 @@ public class RemovePointCommand extends MeasurementModeCommand {
private WptPt point;
public RemovePointCommand(MeasurementToolLayer measurementLayer, int position) {
this.measurementLayer = measurementLayer;
super(measurementLayer);
this.position = position;
}
@Override
public boolean execute() {
point = measurementLayer.getEditingCtx().removePoint(position, true);
measurementLayer.refreshMap();
point = getEditingCtx().removePoint(position, true);
refreshMap();
return true;
}
@Override
public void undo() {
measurementLayer.getEditingCtx().addPoint(position, point);
measurementLayer.refreshMap();
getEditingCtx().addPoint(position, point);
refreshMap();
measurementLayer.moveMapToPoint(position);
}
@Override
public void redo() {
measurementLayer.getEditingCtx().removePoint(position, true);
measurementLayer.refreshMap();
getEditingCtx().removePoint(position, true);
refreshMap();
}
@Override

View file

@ -11,15 +11,15 @@ public class ReorderPointCommand extends MeasurementModeCommand {
private final int to;
public ReorderPointCommand(MeasurementToolLayer measurementLayer, int from, int to) {
this.measurementLayer = measurementLayer;
super(measurementLayer);
this.from = from;
this.to = to;
}
@Override
public boolean execute() {
measurementLayer.getEditingCtx().setNeedUpdateCacheForSnap(true);
measurementLayer.refreshMap();
getEditingCtx().setNeedUpdateCacheForSnap(true);
refreshMap();
return true;
}
@ -34,10 +34,10 @@ public class ReorderPointCommand extends MeasurementModeCommand {
}
private void reorder(int addTo, int removeFrom) {
List<WptPt> points = measurementLayer.getEditingCtx().getPoints();
List<WptPt> points = getEditingCtx().getPoints();
points.add(addTo, points.remove(removeFrom));
measurementLayer.getEditingCtx().setNeedUpdateCacheForSnap(true);
measurementLayer.refreshMap();
getEditingCtx().setNeedUpdateCacheForSnap(true);
refreshMap();
}
@Override

View file

@ -112,9 +112,8 @@ public class GpxApproximator {
}
public void setMode(ApplicationMode mode) throws IOException {
boolean changed = this.mode != mode;
this.mode = mode;
if (changed) {
if (this.mode != mode) {
this.mode = mode;
prepareEnvironment(ctx, mode);
}
}
@ -139,6 +138,12 @@ public class GpxApproximator {
this.approximationProgress = approximationProgress;
}
public void cancelApproximation() {
if (gctx != null) {
gctx.calculationCancelled = true;
}
}
public void calculateGpxApproximation(@NonNull final ResultMatcher<GpxRouteApproximation> resultMatcher) {
if (gctx != null) {
gctx.calculationCancelled = true;