ChangeRouteModeCommand refactoring
This commit is contained in:
parent
e528262d66
commit
1f1b1b33ab
1 changed files with 15 additions and 25 deletions
|
@ -19,42 +19,28 @@ public class ChangeRouteModeCommand extends MeasurementModeCommand {
|
|||
CalculationMode oldCalculationMode;
|
||||
CalculationMode newCalculationMode;
|
||||
|
||||
|
||||
public ChangeRouteModeCommand(MeasurementToolLayer measurementLayer, ApplicationMode newMode,
|
||||
CalculationMode newCalculationMode) {
|
||||
super(measurementLayer);
|
||||
this.newMode = newMode;
|
||||
this.newCalculationMode = newCalculationMode;
|
||||
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
oldMode = editingCtx.getSnapToRoadAppMode();
|
||||
oldCalculationMode = editingCtx.getCalculationMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
points = new LinkedList<>(editingCtx.getPoints());
|
||||
pointIdx = points.size() - 1;
|
||||
if (pointIdx > 0 && newCalculationMode != CalculationMode.WHOLE_TRACK) {
|
||||
if (newMode != null) {
|
||||
points.get(pointIdx).setProfileType(newMode.getStringKey());
|
||||
} else {
|
||||
points.get(pointIdx).removeProfileType();
|
||||
}
|
||||
}
|
||||
editingCtx.setCalculationMode(newCalculationMode);
|
||||
editingCtx.setInSnapToRoadMode(true);
|
||||
editingCtx.setSnapToRoadAppMode(newMode);
|
||||
if (newCalculationMode == CalculationMode.WHOLE_TRACK) {
|
||||
editingCtx.clearSnappedToRoadPoints();
|
||||
}
|
||||
editingCtx.setNeedUpdateCacheForSnap(true);
|
||||
executeCommand();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
editingCtx.getPoints().clear();
|
||||
editingCtx.addPoints(points);
|
||||
editingCtx.setSnapToRoadAppMode(oldMode);
|
||||
|
@ -68,8 +54,17 @@ public class ChangeRouteModeCommand extends MeasurementModeCommand {
|
|||
|
||||
@Override
|
||||
public void redo() {
|
||||
MeasurementEditingContext editingCtx = measurementLayer.getEditingCtx();
|
||||
if (pointIdx > 0) {
|
||||
executeCommand();
|
||||
}
|
||||
|
||||
@Override
|
||||
MeasurementCommandType getType() {
|
||||
return MeasurementCommandType.CHANGE_ROUTE_MODE;
|
||||
}
|
||||
|
||||
private void executeCommand() {
|
||||
MeasurementEditingContext editingCtx = getEditingCtx();
|
||||
if (pointIdx > 0 && newCalculationMode != CalculationMode.WHOLE_TRACK) {
|
||||
if (newMode != null) {
|
||||
points.get(pointIdx).setProfileType(newMode.getStringKey());
|
||||
} else {
|
||||
|
@ -84,9 +79,4 @@ public class ChangeRouteModeCommand extends MeasurementModeCommand {
|
|||
}
|
||||
editingCtx.setNeedUpdateCacheForSnap(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
MeasurementCommandType getType() {
|
||||
return MeasurementCommandType.CHANGE_ROUTE_MODE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue