This commit is contained in:
PavelRatushny 2017-08-25 17:15:07 +03:00
parent b6893b4b46
commit b5f0af881b
3 changed files with 8 additions and 40 deletions

View file

@ -135,30 +135,6 @@ public class MeasurementEditingContext {
return after; return after;
} }
// public void recreateSegments() {
// List<WptPt> points = new ArrayList<>();
// points.addAll(before.points);
// points.addAll(after.points);
// before.points.clear();
// if (points.size() > 1) {
// for (int i = 0; i < points.size() - 1; i++) {
// Pair<WptPt, WptPt> pair = new Pair<>(points.get(i), points.get(i + 1));
// List<WptPt> pts = snappedToRoadPoints.get(pair);
// if (pts != null) {
// before.points.addAll(pts);
// } else {
// if (inSnapToRoadMode) {
// scheduleRouteCalculateIfNotEmpty();
// }
// before.points.addAll(Arrays.asList(pair.first, pair.second));
// }
// }
// } else {
// before.points.addAll(points);
// }
// after.points.clear();
// }
public List<WptPt> getPoints() { public List<WptPt> getPoints() {
return getBeforePoints(); return getBeforePoints();
} }
@ -168,7 +144,7 @@ public class MeasurementEditingContext {
} }
public List<WptPt> getAfterPoints() { public List<WptPt> getAfterPoints() {
return after.points; return after.points;
} }
public int getPointsCount() { public int getPointsCount() {
@ -180,9 +156,13 @@ public class MeasurementEditingContext {
points.addAll(before.points); points.addAll(before.points);
points.addAll(after.points); points.addAll(after.points);
before.points.clear(); before.points.clear();
before.points.addAll(points.subList(0, position));
after.points.clear(); after.points.clear();
after.points.addAll(points.subList(position, points.size())); if (position == before.points.size() + after.points.size()) {
before.points.addAll(points);
} else {
before.points.addAll(points.subList(0, position));
after.points.addAll(points.subList(position, points.size()));
}
} }
public void addPoint(WptPt pt) { public void addPoint(WptPt pt) {
@ -283,7 +263,6 @@ public class MeasurementEditingContext {
pts.add(pt); pts.add(pt);
} }
snappedToRoadPoints.put(currentPair, pts); snappedToRoadPoints.put(currentPair, pts);
// recreateSegments();
progressListener.refreshMap(); progressListener.refreshMap();
if (!snapToRoadPairsToCalculate.isEmpty()) { if (!snapToRoadPairsToCalculate.isEmpty()) {
application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true); application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);

View file

@ -303,7 +303,6 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
editingCtx.getCommandManager().undo(); editingCtx.getCommandManager().undo();
// editingCtx.recreateSegments();
if (editingCtx.getCommandManager().canUndo()) { if (editingCtx.getCommandManager().canUndo()) {
enable(undoBtn); enable(undoBtn);
} else { } else {
@ -324,7 +323,6 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
editingCtx.getCommandManager().redo(); editingCtx.getCommandManager().redo();
// editingCtx.recreateSegments();
if (editingCtx.getCommandManager().canRedo()) { if (editingCtx.getCommandManager().canRedo()) {
enable(redoBtn); enable(redoBtn);
} else { } else {
@ -595,7 +593,6 @@ public class MeasurementToolFragment extends Fragment {
@Override @Override
public void clearAllOnClick() { public void clearAllOnClick() {
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer)); editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer));
editingCtx.clearSegments();
editingCtx.cancelSnapToRoad(); editingCtx.cancelSnapToRoad();
if (pointsListOpened) { if (pointsListOpened) {
hidePointsList(); hidePointsList();
@ -625,7 +622,6 @@ public class MeasurementToolFragment extends Fragment {
if (measurementLayer != null) { if (measurementLayer != null) {
removePoint(measurementLayer, editingCtx.getSelectedPointPosition()); removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
} }
// editingCtx.recreateSegments();
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
} }
@ -682,7 +678,6 @@ public class MeasurementToolFragment extends Fragment {
private void removePoint(MeasurementToolLayer layer, int position) { private void removePoint(MeasurementToolLayer layer, int position) {
editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position)); editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position));
// editingCtx.recreateSegments();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
disable(redoBtn); disable(redoBtn);
updateText(); updateText();
@ -749,7 +744,6 @@ public class MeasurementToolFragment extends Fragment {
toPosition = holder.getAdapterPosition(); toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) { if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition)); editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
// editingCtx.recreateSegments();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
disable(redoBtn); disable(redoBtn);
updateText(); updateText();
@ -868,7 +862,6 @@ public class MeasurementToolFragment extends Fragment {
WptPt oldPoint = editingCtx.getOriginalPointToMove(); WptPt oldPoint = editingCtx.getOriginalPointToMove();
int position = editingCtx.getSelectedPointPosition(); int position = editingCtx.getSelectedPointPosition();
editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position)); editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
editingCtx.addPoint(newPoint);
doAddOrMovePointCommonStuff(); doAddOrMovePointCommonStuff();
measurementLayer.exitMovePointMode(false); measurementLayer.exitMovePointMode(false);
measurementLayer.refreshMap(); measurementLayer.refreshMap();
@ -898,7 +891,6 @@ public class MeasurementToolFragment extends Fragment {
private void applyAddPointAfterMode() { private void applyAddPointAfterMode() {
switchAddPointAfterMode(false); switchAddPointAfterMode(false);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
// editingCtx.recreateSegments();
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.exitAddPointAfterMode(); measurementLayer.exitAddPointAfterMode();
@ -909,7 +901,6 @@ public class MeasurementToolFragment extends Fragment {
private void cancelAddPointAfterMode() { private void cancelAddPointAfterMode() {
switchAddPointAfterMode(false); switchAddPointAfterMode(false);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
// editingCtx.recreateSegments();
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointAfterMode(); measurementToolLayer.exitAddPointAfterMode();
@ -930,7 +921,6 @@ public class MeasurementToolFragment extends Fragment {
private void applyAddPointBeforeMode() { private void applyAddPointBeforeMode() {
switchAddPointBeforeMode(false); switchAddPointBeforeMode(false);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
// editingCtx.recreateSegments();
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) { if (measurementLayer != null) {
measurementLayer.exitAddPointBeforeMode(); measurementLayer.exitAddPointBeforeMode();
@ -941,7 +931,6 @@ public class MeasurementToolFragment extends Fragment {
private void cancelAddPointBeforeMode() { private void cancelAddPointBeforeMode() {
switchAddPointBeforeMode(false); switchAddPointBeforeMode(false);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
// editingCtx.recreateSegments();
MeasurementToolLayer measurementToolLayer = getMeasurementLayer(); MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) { if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointBeforeMode(); measurementToolLayer.exitAddPointBeforeMode();

View file

@ -327,9 +327,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
WptPt pt = editingCtx.getOriginalPointToMove(); WptPt pt = editingCtx.getOriginalPointToMove();
editingCtx.addPoint(pt); editingCtx.addPoint(pt);
} }
// editingCtx.recreateSegments();
editingCtx.setOriginalPointToMove(null); editingCtx.setOriginalPointToMove(null);
editingCtx.setSelectedPointPosition(-1); editingCtx.setSelectedPointPosition(-1);
editingCtx.splitSegments(editingCtx.getBeforePoints().size() + editingCtx.getAfterPoints().size());
} }
void exitAddPointAfterMode() { void exitAddPointAfterMode() {