Remove measurementsPoints

This commit is contained in:
PavelRatushny 2017-08-25 14:47:42 +03:00
parent 45bb24baeb
commit b6893b4b46
7 changed files with 130 additions and 111 deletions

View file

@ -50,8 +50,6 @@ public class MeasurementEditingContext {
private Queue<Pair<WptPt, WptPt>> snapToRoadPairsToCalculate = new LinkedList<>();
private Map<Pair<WptPt, WptPt>, List<WptPt>> snappedToRoadPoints = new ConcurrentHashMap<>();
private List<WptPt> measurementPoints = new LinkedList<>();
public void setApplication(OsmandApplication application) {
this.application = application;
}
@ -60,24 +58,6 @@ public class MeasurementEditingContext {
return commandManager;
}
public void setBefore(TrkSegment before) {
this.before = before;
addBeforeRenders();
}
public void setAfter(TrkSegment after) {
this.after = after;
addAfterRenders();
}
private void addBeforeRenders() {
before.renders.add(new Renderable.StandardTrack(before.points, 17.2));
}
private void addAfterRenders() {
after.renders.add(new Renderable.StandardTrack(after.points, 17.2));
}
public boolean isInMovePointMode() {
return inMovePointMode;
}
@ -142,14 +122,6 @@ public class MeasurementEditingContext {
return snappedToRoadPoints;
}
public List<WptPt> getPoints() {
return measurementPoints;
}
public int getPointsCount() {
return measurementPoints.size();
}
public TrkSegment getBeforeTrkSegmentLine() {
// check if all segments calculated for snap to road
// if(beforeCacheForSnap != null) {
@ -163,48 +135,83 @@ public class MeasurementEditingContext {
return after;
}
public void recreateSegments() {
before = new TrkSegment();
if (measurementPoints.size() > 1) {
for (int i = 0; i < measurementPoints.size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(measurementPoints.get(i), measurementPoints.get(i + 1));
List<WptPt> pts = snappedToRoadPoints.get(pair);
if (pts != null) {
before.points.addAll(pts);
} else {
if (inSnapToRoadMode) {
scheduleRouteCalculateIfNotEmpty();
// 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() {
return getBeforePoints();
}
before.points.addAll(Arrays.asList(pair.first, pair.second));
public List<WptPt> getBeforePoints() {
return before.points;
}
public List<WptPt> getAfterPoints() {
return after.points;
}
} else {
before.points.addAll(measurementPoints);
}
addBeforeRenders();
after = new TrkSegment();
public int getPointsCount() {
return before.points.size();
}
public void splitSegments(int position) {
before = new TrkSegment();
before.points.addAll(measurementPoints.subList(0, position));
addBeforeRenders();
after = new TrkSegment();
after.points.addAll(measurementPoints.subList(position, measurementPoints.size()));
addAfterRenders();
List<WptPt> points = new ArrayList<>();
points.addAll(before.points);
points.addAll(after.points);
before.points.clear();
before.points.addAll(points.subList(0, position));
after.points.clear();
after.points.addAll(points.subList(position, points.size()));
}
public void addPoint(WptPt pt) {
before.points.add(pt);
}
public void addPoint(int position, WptPt pt) {
before.points.add(position, pt);
}
public void addPoints(List<WptPt> points) {
before.points.addAll(points);
}
public WptPt removePoint(int position) {
return before.points.remove(position);
}
public void clearSegments() {
before = new TrkSegment();
after = new TrkSegment();
before.points.clear();
after.points.clear();
}
void scheduleRouteCalculateIfNotEmpty() {
if (application == null || measurementPoints.size() < 1) {
if (application == null || before.points.size() < 1) {
return;
}
for (int i = 0; i < measurementPoints.size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(measurementPoints.get(i), measurementPoints.get(i + 1));
for (int i = 0; i < before.points.size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(before.points.get(i), before.points.get(i + 1));
if (snappedToRoadPoints.get(pair) == null && !snapToRoadPairsToCalculate.contains(pair)) {
snapToRoadPairsToCalculate.add(pair);
}
@ -276,7 +283,7 @@ public class MeasurementEditingContext {
pts.add(pt);
}
snappedToRoadPoints.put(currentPair, pts);
recreateSegments();
// recreateSegments();
progressListener.refreshMap();
if (!snapToRoadPairsToCalculate.isEmpty()) {
application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);

View file

@ -303,7 +303,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().undo();
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
if (editingCtx.getCommandManager().canUndo()) {
enable(undoBtn);
} else {
@ -324,7 +324,7 @@ public class MeasurementToolFragment extends Fragment {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().redo();
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
if (editingCtx.getCommandManager().canRedo()) {
enable(redoBtn);
} else {
@ -625,7 +625,7 @@ public class MeasurementToolFragment extends Fragment {
if (measurementLayer != null) {
removePoint(measurementLayer, editingCtx.getSelectedPointPosition());
}
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
editingCtx.setSelectedPointPosition(-1);
}
@ -682,7 +682,7 @@ public class MeasurementToolFragment extends Fragment {
private void removePoint(MeasurementToolLayer layer, int position) {
editingCtx.getCommandManager().execute(new RemovePointCommand(layer, position));
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
adapter.notifyDataSetChanged();
disable(redoBtn);
updateText();
@ -749,7 +749,7 @@ public class MeasurementToolFragment extends Fragment {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
adapter.notifyDataSetChanged();
disable(redoBtn);
updateText();
@ -811,7 +811,7 @@ public class MeasurementToolFragment extends Fragment {
GPXFile gpx = newGpxData.getGpxFile();
List<WptPt> points = gpx.getRoutePoints();
if (measurementLayer != null) {
editingCtx.getPoints().addAll(points);
editingCtx.addPoints(points);
adapter.notifyDataSetChanged();
updateText();
}
@ -823,7 +823,7 @@ public class MeasurementToolFragment extends Fragment {
TrkSegment segment = newGpxData.getTrkSegment();
List<WptPt> points = segment.points;
if (measurementLayer != null) {
editingCtx.getPoints().addAll(points);
editingCtx.addPoints(points);
adapter.notifyDataSetChanged();
updateText();
}
@ -868,7 +868,7 @@ public class MeasurementToolFragment extends Fragment {
WptPt oldPoint = editingCtx.getOriginalPointToMove();
int position = editingCtx.getSelectedPointPosition();
editingCtx.getCommandManager().execute(new MovePointCommand(measurementLayer, oldPoint, newPoint, position));
editingCtx.getPoints().add(position, newPoint);
editingCtx.addPoint(newPoint);
doAddOrMovePointCommonStuff();
measurementLayer.exitMovePointMode(false);
measurementLayer.refreshMap();
@ -898,7 +898,7 @@ public class MeasurementToolFragment extends Fragment {
private void applyAddPointAfterMode() {
switchAddPointAfterMode(false);
editingCtx.setSelectedPointPosition(-1);
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
measurementLayer.exitAddPointAfterMode();
@ -909,7 +909,7 @@ public class MeasurementToolFragment extends Fragment {
private void cancelAddPointAfterMode() {
switchAddPointAfterMode(false);
editingCtx.setSelectedPointPosition(-1);
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointAfterMode();
@ -930,7 +930,7 @@ public class MeasurementToolFragment extends Fragment {
private void applyAddPointBeforeMode() {
switchAddPointBeforeMode(false);
editingCtx.setSelectedPointPosition(-1);
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
measurementLayer.exitAddPointBeforeMode();
@ -941,7 +941,7 @@ public class MeasurementToolFragment extends Fragment {
private void cancelAddPointBeforeMode() {
switchAddPointBeforeMode(false);
editingCtx.setSelectedPointPosition(-1);
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
MeasurementToolLayer measurementToolLayer = getMeasurementLayer();
if (measurementToolLayer != null) {
measurementToolLayer.exitAddPointBeforeMode();
@ -1019,7 +1019,6 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
editingCtx.getCommandManager().execute(new AddPointCommand(measurementLayer, false));
editingCtx.recreateSegments();
doAddOrMovePointCommonStuff();
}
}
@ -1028,7 +1027,6 @@ public class MeasurementToolFragment extends Fragment {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
editingCtx.getCommandManager().execute(new AddPointCommand(measurementLayer, true));
editingCtx.recreateSegments();
doAddOrMovePointCommonStuff();
}
}
@ -1473,7 +1471,7 @@ public class MeasurementToolFragment extends Fragment {
private void dismiss(MapActivity mapActivity) {
try {
editingCtx.getPoints().clear();
editingCtx.clearSegments();
if (pointsListOpened) {
hidePointsList();
}

View file

@ -18,8 +18,10 @@ import net.osmand.plus.R;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.Renderable;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
@ -100,11 +102,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
String getDistanceSt() {
float dist = 0;
List<WptPt> measurementPoints = editingCtx.getPoints();
if (measurementPoints.size() > 0) {
for (int i = 1; i < measurementPoints.size(); i++) {
dist += MapUtils.getDistance(measurementPoints.get(i - 1).lat, measurementPoints.get(i - 1).lon,
measurementPoints.get(i).lat, measurementPoints.get(i).lon);
List<WptPt> points = editingCtx.getPoints();
if (points.size() > 0) {
for (int i = 1; i < points.size(); i++) {
dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon,
points.get(i).lat, points.get(i).lon);
}
}
return OsmAndFormatter.getFormattedDistance(dist, view.getApplication());
@ -151,7 +153,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
void enterMovingPointMode() {
editingCtx.setInMovePointMode(true);
moveMapToPoint(editingCtx.getSelectedPointPosition());
WptPt pt = editingCtx.getPoints().remove(editingCtx.getSelectedPointPosition());
WptPt pt = editingCtx.removePoint(editingCtx.getSelectedPointPosition());
editingCtx.setOriginalPointToMove(pt);
editingCtx.splitSegments(editingCtx.getSelectedPointPosition());
}
@ -199,9 +201,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
lineAttrs.updatePaints(view, settings, tb);
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
before.renders.clear();
before.renders.add(new Renderable.StandardTrack(before.points, 17.2));
before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
after.renders.clear();
after.renders.add(new Renderable.StandardTrack(after.points, 17.2));
after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
}
}
@ -263,11 +269,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
canvas.drawPath(path, lineAttrs.paint);
}
List<WptPt> measurementPoints = editingCtx.getPoints();
List<WptPt> points = new ArrayList<>();
points.addAll(editingCtx.getBeforePoints());
points.addAll(editingCtx.getAfterPoints());
overlapped = false;
int drawn = 0;
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
for (int i = 0; i < points.size(); i++) {
WptPt pt = points.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
@ -279,13 +287,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
}
if (overlapped) {
WptPt pt = measurementPoints.get(0);
WptPt pt = points.get(0);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
}
pt = measurementPoints.get(measurementPoints.size() - 1);
pt = points.get(points.size() - 1);
locX = tb.getPixXFromLonNoRot(pt.lon);
locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
@ -293,8 +301,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
} else {
for (int i = 0; i < measurementPoints.size(); i++) {
WptPt pt = measurementPoints.get(i);
for (int i = 0; i < points.size(); i++) {
WptPt pt = points.get(i);
int locX = tb.getPixXFromLonNoRot(pt.lon);
int locY = tb.getPixYFromLatNoRot(pt.lat);
if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
@ -317,9 +325,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
editingCtx.setInMovePointMode(false);
if (saveOriginalPoint) {
WptPt pt = editingCtx.getOriginalPointToMove();
editingCtx.getPoints().add(editingCtx.getSelectedPointPosition(), pt);
editingCtx.addPoint(pt);
}
editingCtx.recreateSegments();
// editingCtx.recreateSegments();
editingCtx.setOriginalPointToMove(null);
editingCtx.setSelectedPointPosition(-1);
}
@ -344,7 +352,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
canvas.rotate(tb.getRotate(), center.x, center.y);
}
public WptPt addCenterPoint(int position) {
public WptPt addCenterPoint() {
RotatedTileBox tb = view.getCurrentRotatedTileBox();
LatLon l = tb.getLatLonFromPixel(tb.getCenterPixelX(), tb.getCenterPixelY());
WptPt pt = new WptPt();
@ -352,22 +360,24 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
pt.lon = l.getLongitude();
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
editingCtx.getPoints().add(position, pt);
editingCtx.addPoint(pt);
return pt;
}
return null;
}
public WptPt addPoint(int position) {
public WptPt addPoint() {
if (pressedPointLatLon != null) {
WptPt pt = new WptPt();
pt.lat = pressedPointLatLon.getLatitude();
pt.lon = pressedPointLatLon.getLongitude();
double lat = pressedPointLatLon.getLatitude();
double lon = pressedPointLatLon.getLongitude();
pt.lat = lat;
pt.lon = lon;
pressedPointLatLon = null;
boolean allowed = editingCtx.getPointsCount() == 0 || !editingCtx.getPoints().get(editingCtx.getPointsCount() - 1).equals(pt);
if (allowed) {
editingCtx.getPoints().add(position, pt);
moveMapToPoint(position);
editingCtx.addPoint(pt);
moveMapToLatLon(lat, lon);
return pt;
}
}
@ -383,6 +393,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
return pt;
}
private void moveMapToLatLon(double lat, double lon) {
view.getAnimatedDraggingThread().startMoving(lat, lon, view.getZoom(), true);
}
public void moveMapToPoint(int pos) {
if (editingCtx.getPointsCount() > 0) {
if (pos >= editingCtx.getPointsCount()) {
@ -391,7 +405,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
pos = 0;
}
WptPt pt = editingCtx.getPoints().get(pos);
view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
moveMapToLatLon(pt.getLatitude(), pt.getLongitude());
}
}

View file

@ -24,9 +24,9 @@ public class AddPointCommand extends MeasurementModeCommand {
@Override
public boolean execute() {
if (center) {
point = measurementLayer.addCenterPoint(position);
point = measurementLayer.addCenterPoint();
} else {
point = measurementLayer.addPoint(position);
point = measurementLayer.addPoint();
}
measurementLayer.refreshMap();
return point != null;
@ -34,13 +34,13 @@ public class AddPointCommand extends MeasurementModeCommand {
@Override
public void undo() {
measurementLayer.getEditingCtx().getPoints().remove(position);
measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.refreshMap();
}
@Override
public void redo() {
measurementLayer.getEditingCtx().getPoints().add(position, point);
measurementLayer.getEditingCtx().addPoint(position, point);
measurementLayer.refreshMap();
measurementLayer.moveMapToPoint(position);
}

View file

@ -25,13 +25,13 @@ public class ClearPointsCommand extends MeasurementModeCommand {
@Override
public void undo() {
measurementLayer.getEditingCtx().getPoints().addAll(points);
measurementLayer.getEditingCtx().addPoints(points);
measurementLayer.refreshMap();
}
@Override
public void redo() {
measurementLayer.getEditingCtx().getPoints().clear();
measurementLayer.getEditingCtx().clearSegments();
measurementLayer.refreshMap();
}

View file

@ -23,15 +23,15 @@ public class MovePointCommand extends MeasurementModeCommand {
@Override
public void undo() {
measurementLayer.getEditingCtx().getPoints().remove(position);
measurementLayer.getEditingCtx().getPoints().add(position, oldPoint);
measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.getEditingCtx().addPoint(position, oldPoint);
measurementLayer.refreshMap();
}
@Override
public void redo() {
measurementLayer.getEditingCtx().getPoints().remove(position);
measurementLayer.getEditingCtx().getPoints().add(position, newPoint);
measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.getEditingCtx().addPoint(position, newPoint);
measurementLayer.refreshMap();
}

View file

@ -15,21 +15,21 @@ public class RemovePointCommand extends MeasurementModeCommand {
@Override
public boolean execute() {
point = measurementLayer.getEditingCtx().getPoints().remove(position);
point = measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.refreshMap();
return true;
}
@Override
public void undo() {
measurementLayer.getEditingCtx().getPoints().add(position, point);
measurementLayer.getEditingCtx().addPoint(position, point);
measurementLayer.refreshMap();
measurementLayer.moveMapToPoint(position);
}
@Override
public void redo() {
measurementLayer.getEditingCtx().getPoints().remove(position);
measurementLayer.getEditingCtx().removePoint(position);
measurementLayer.refreshMap();
}