Ticket #24695: 24695.patch
| File 24695.patch, 7.4 KB (added by , 44 hours ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
792 792 return ds.update(() -> { 793 793 if (mode == Mode.ROTATE) { 794 794 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) { 795 ((RotateCommand) c).handleEvent(currentEN); 795 if (didMouseDrag) { 796 ((RotateCommand) c).handleEvent(currentEN); 797 } else { 798 ((RotateCommand) c).handleUpdate(currentEN); 799 } 796 800 } else { 797 801 UndoRedoHandler.getInstance().add(new RotateCommand(selection, currentEN)); 798 802 } 799 803 } else if (mode == Mode.SCALE) { 800 804 if (c instanceof ScaleCommand && affectedNodes.equals(((ScaleCommand) c).getTransformedNodes())) { 801 ((ScaleCommand) c).handleEvent(currentEN); 805 if (didMouseDrag) { 806 ((ScaleCommand) c).handleEvent(currentEN); 807 } else { 808 ((ScaleCommand) c).handleUpdate(currentEN); 809 } 802 810 } else { 803 811 UndoRedoHandler.getInstance().add(new ScaleCommand(selection, currentEN)); 804 812 } … … 821 829 } 822 830 } 823 831 832 private boolean movesOutside() { 833 DataSet ds = getLayerManager().getEditDataSet(); 834 if (ds.getDataSourceBounds().isEmpty()) 835 return false; 836 final Collection<Node> elementsToTest = new HashSet<>(ds.getSelectedNodes()); 837 for (Way osm : ds.getSelectedWays()) { 838 elementsToTest.addAll(osm.getNodes()); 839 } 840 for (Node n : elementsToTest) { 841 if (n.isOutsideDownloadArea()) 842 return true; 843 } 844 return false; 845 } 846 824 847 private static boolean doesImpactStatusLine(Collection<Node> affectedNodes, Collection<Way> selectedWays) { 825 848 return selectedWays.stream() 826 849 .flatMap(w -> w.getNodes().stream()) … … 870 893 * @param e the mouse event causing the action (mouse released) 871 894 */ 872 895 private void confirmOrUndoMovement(MouseEvent e) { 896 final Command lastCommand = UndoRedoHandler.getInstance().getLastCommand(); 897 if (lastCommand == null) { 898 Logging.warn("No command found in undo/redo history, skipping confirmOrUndoMovement"); 899 return; 900 } 901 873 902 if (movesHiddenWay()) { 874 903 final ConfirmMoveDialog ed = new ConfirmMoveDialog(); 875 904 ed.setContent(tr("Are you sure that you want to move elements with attached ways that are hidden by filters?")); … … 876 905 ed.toggleEnable("movedHiddenElements"); 877 906 showConfirmMoveDialog(ed); 878 907 } 908 // check if move was cancelled 909 if (UndoRedoHandler.getInstance().getLastCommand() != lastCommand) 910 return; 879 911 880 final Command lastCommand = UndoRedoHandler.getInstance().getLastCommand(); 881 if (lastCommand == null) { 882 Logging.warn("No command found in undo/redo history, skipping confirmOrUndoMovement"); 912 if (movesOutside()) { 913 final ConfirmMoveDialog ed = new ConfirmMoveDialog(); 914 ed.setContent(tr("Are you sure that you want to move nodes outside the downloaded area?")); 915 ed.toggleEnable("movedOutsideNodes"); 916 showConfirmMoveDialog(ed); 917 } 918 // check if move was cancelled 919 if (UndoRedoHandler.getInstance().getLastCommand() != lastCommand) 883 920 return; 884 }885 921 886 922 SelectAction.checkCommandForLargeDistance(lastCommand); 887 923 -
src/org/openstreetmap/josm/command/RotateCommand.java
25 25 /** 26 26 * angle of rotation starting click to pivot 27 27 */ 28 private finaldouble startAngle;28 private double startAngle; 29 29 30 30 /** 31 31 * computed rotation angle between starting click and current mouse pos … … 32 32 */ 33 33 private double rotationAngle; 34 34 35 private double deltaAngle; 36 35 37 /** 36 38 * Creates a RotateCommand. 37 39 * Assign the initial object set, compute pivot point and initial rotation angle. … … 65 67 @Override 66 68 public final void handleEvent(EastNorth currentEN) { 67 69 double currentAngle = getAngle(currentEN); 68 rotationAngle = currentAngle - startAngle ;70 rotationAngle = currentAngle - startAngle + deltaAngle; 69 71 transformNodes(); 70 72 } 71 73 72 74 /** 75 * Handle a repeated rotation action where the mouse was moved to a different position 76 * see #24695 77 * @param startEN start cursor position of a repeated rotation 78 */ 79 public void handleUpdate(EastNorth startEN) { 80 deltaAngle = rotationAngle; 81 startAngle = getAngle(startEN); 82 } 83 84 /** 73 85 * Set the rotation angle. 74 86 * @param rotationAngle The rotate angle 75 87 */ -
src/org/openstreetmap/josm/command/ScaleCommand.java
26 26 private double scalingFactor; 27 27 28 28 /** 29 * scaling factor applied previously 30 */ 31 private double deltaScalingFactor; 32 33 /** 29 34 * World position of the mouse when the user started the command. 30 35 */ 31 private finalEastNorth startEN;36 private EastNorth startEN; 32 37 33 38 /** 34 39 * Creates a ScaleCommand. … … 57 62 */ 58 63 @Override 59 64 public final void handleEvent(EastNorth currentEN) { 60 double startAngle = Math.atan2(startEN.east()-pivot.east(), startEN.north()-pivot.north()); 61 double endAngle = Math.atan2(currentEN.east()-pivot.east(), currentEN.north()-pivot.north()); 65 setScalingFactor(deltaScalingFactor + calcScalingFactor(currentEN)); 66 transformNodes(); 67 } 68 69 /** 70 * Handle a repeated scaling action where the mouse was moved to a different position 71 * see #24695 72 * @param newStartEN start cursor position of a repeated scaling 73 */ 74 public void handleUpdate(EastNorth newStartEN) { 75 startEN = newStartEN; 76 deltaScalingFactor = scalingFactor - calcScalingFactor(newStartEN); 77 } 78 79 private double calcScalingFactor(EastNorth currentEN) { 80 double startAngle = Math.atan2(startEN.east() - pivot.east(), startEN.north() - pivot.north()); 81 double endAngle = Math.atan2(currentEN.east() - pivot.east(), currentEN.north() - pivot.north()); 62 82 double startDistance = pivot.distance(startEN); 63 83 double currentDistance = pivot.distance(currentEN); 64 setScalingFactor(Math.cos(startAngle-endAngle) * currentDistance / startDistance); 65 transformNodes(); 84 return Math.cos(startAngle - endAngle) * currentDistance / startDistance; 66 85 } 67 86 68 87 /**
