Changeset 16968 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r16626 r16968 18 18 import java.util.LinkedList; 19 19 import java.util.Optional; 20 import java.util.Set;21 20 22 21 import javax.swing.JOptionPane; … … 30 29 import org.openstreetmap.josm.command.ScaleCommand; 31 30 import org.openstreetmap.josm.command.SequenceCommand; 31 import org.openstreetmap.josm.data.SystemOfMeasurement; 32 32 import org.openstreetmap.josm.data.UndoRedoHandler; 33 33 import org.openstreetmap.josm.data.coor.EastNorth; … … 827 827 showConfirmMoveDialog(ed); 828 828 } 829 Set<Node> nodes = new HashSet<>(); 829 final int moveCount = UndoRedoHandler.getInstance().getLastCommand().getParticipatingPrimitives().size(); 830 if (UndoRedoHandler.getInstance().getLastCommand() instanceof MoveCommand) { 831 final double moveDistance = ((MoveCommand) UndoRedoHandler.getInstance().getLastCommand()).getDistance(n -> !n.isNew()); 832 if (Double.isFinite(moveDistance) && moveDistance > Config.getPref().getInt("warn.move.maxdistance", 200)) { 833 final ConfirmMoveDialog ed = new ConfirmMoveDialog(); 834 ed.setContent(trn( 835 "You moved {0} element by a distance of {1}. " 836 + "Moving elements by a large distance is often an error.\n" + "Really move them?", 837 "You moved {0} elements by a distance of {1}. " 838 + "Moving elements by a large distance is often an error.\n" + "Really move them?", 839 moveCount, moveCount, SystemOfMeasurement.getSystemOfMeasurement().getDistText(moveDistance))); 840 ed.toggleEnable("movedLargeDistance"); 841 showConfirmMoveDialog(ed); 842 } 843 } 830 844 int max = Config.getPref().getInt("warn.move.maxelements", 20); 831 for (OsmPrimitive osm : getLayerManager().getEditDataSet().getSelected()) { 832 if (osm instanceof Way) { 833 nodes.addAll(((Way) osm).getNodes()); 834 } else if (osm instanceof Node) { 835 nodes.add((Node) osm); 836 } 837 if (nodes.size() > max) { 838 break; 839 } 840 } 841 if (nodes.size() > max) { 845 if (moveCount > max) { 842 846 final ConfirmMoveDialog ed = new ConfirmMoveDialog(); 843 847 ed.setContent( -
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r15000 r16968 11 11 import java.util.NoSuchElementException; 12 12 import java.util.Objects; 13 import java.util.function.Predicate; 13 14 14 15 import javax.swing.Icon; … … 300 301 301 302 /** 302 * Gets the offset.303 * @return The current offset.303 * Gets the current move offset. 304 * @return The current move offset. 304 305 */ 305 306 protected EastNorth getOffset() { 306 307 return new EastNorth(x, y); 308 } 309 310 /** 311 * Computes the move distance for one node matching the specified predicate 312 * @param predicate predicate to match 313 * @return distance in metres 314 */ 315 public double getDistance(Predicate<Node> predicate) { 316 return nodes.stream() 317 .filter(predicate) 318 .filter(node -> node.getCoor() != null && node.getEastNorth() != null) 319 .findFirst() 320 .map(node -> { 321 final Node old = new Node(node); 322 old.setEastNorth(old.getEastNorth().add(-x, -y)); 323 return node.getCoor().greatCircleDistance(old.getCoor()); 324 }).orElse(Double.NaN); 307 325 } 308 326 -
trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
r14120 r16968 77 77 assertEquals("east", 1, moveCommand.getOffset().east(), 0.0001); 78 78 assertEquals("north", 2, moveCommand.getOffset().north(), 0.0001); 79 assertEquals("distance", 2.236068, moveCommand.getDistance(n -> true), 0.0001); 79 80 } 80 81 … … 89 90 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 90 91 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 92 assertEquals("distance", 2.236068, command.getDistance(n -> true), 0.0001); 91 93 } 92 94
Note:
See TracChangeset
for help on using the changeset viewer.