Changeset 7226 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-06-09T13:50:48+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r7223 r7226 55 55 import org.openstreetmap.josm.tools.ImageProvider; 56 56 import org.openstreetmap.josm.tools.Shortcut; 57 import org.openstreetmap.josm.tools.Utils; 57 58 58 59 /** … … 80 81 private boolean ignoreSharedNodes; 81 82 82 private finalboolean keepSegmentDirection;83 83 private boolean keepSegmentDirection; 84 84 85 /** 85 86 * drawing settings for helper lines … … 100 101 * Collection of nodes that is moved 101 102 */ 102 private ArrayList< OsmPrimitive> movingNodeList;103 private ArrayList<Node> movingNodeList; 103 104 104 105 /** … … 150 151 /** The cursor for the 'alwaysCreateNodes' submode. */ 151 152 private final Cursor cursorCreateNodes; 152 153 private boolean ignoreNextKeyRelease;154 153 155 154 private static class ReferenceSegment { … … 179 178 /** Dual alignment reference segments */ 180 179 private ReferenceSegment dualAlignSegment1, dualAlignSegment2; 180 /** {@code true}, if new segment was collapsed */ 181 private boolean dualAlignSegmentCollapsed; 181 182 // Dual alignment UI stuff 182 183 private final DualAlignChangeAction dualAlignChangeAction; … … 184 185 private final Shortcut dualAlignShortcut; 185 186 private boolean useRepeatedShortcut; 187 private boolean ignoreNextKeyRelease; 186 188 187 189 private class DualAlignChangeAction extends JosmAction { … … 219 221 dualAlignShortcut = Shortcut.registerShortcut("mapmode:extrudedualalign", 220 222 tr("Mode: {0}", tr("Extrude Dual alignment")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE); 221 useRepeatedShortcut = Main.pref.getBoolean("extrude.dualalign.toggleOnRepeatedX", true); 222 keepSegmentDirection = Main.pref.getBoolean("extrude.dualalign.keep-segment-direction", true); 223 readPreferences(); // to show prefernces in table before entering the mode 223 224 } 224 225 … … 250 251 rv = new StringBuilder(tr("Drag a way segment to make a rectangle. Ctrl-drag to move a segment along its normal, " + 251 252 "Alt-drag to create a new rectangle, double click to add a new node.")); 252 if (dualAlignEnabled) 253 if (dualAlignEnabled) { 253 254 rv.append(" ").append(tr("Dual alignment active.")); 255 if (dualAlignSegmentCollapsed) { 256 rv.append(" ").append(tr("Segment collapsed due to its direction reversing.")); 257 } 258 } 254 259 } else { 255 260 if (mode == Mode.translate) … … 281 286 Main.map.mapView.addMouseListener(this); 282 287 Main.map.mapView.addMouseMotionListener(this); 288 readPreferences(); 289 ignoreNextKeyRelease = true; 290 Main.map.keyDetector.addKeyListener(this); 291 Main.map.keyDetector.addModifierListener(this); 292 } 293 294 private void readPreferences() { 283 295 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200); 284 296 initialMoveThreshold = Main.pref.getInteger("extrude.initial-move-threshold", 1); … … 295 307 ignoreSharedNodes = Main.pref.getBoolean("extrude.ignore-shared-nodes", true); 296 308 dualAlignCheckboxMenuItem.getAction().setEnabled(true); 297 ignoreNextKeyRelease = true; 298 Main.map.keyDetector.addKeyListener(this); 299 Main.map.keyDetector.addModifierListener(this); 309 useRepeatedShortcut = Main.pref.getBoolean("extrude.dualalign.toggleOnRepeatedX", true); 310 keepSegmentDirection = Main.pref.getBoolean("extrude.dualalign.keep-segment-direction", true); 300 311 } 301 312 … … 392 403 dualAlignActive = true; 393 404 calculatePossibleDirectionsForDualAlign(); 405 dualAlignSegmentCollapsed = false; 394 406 } else { 395 407 dualAlignActive = false; … … 451 463 EastNorth mouseEn = Main.map.mapView.getEastNorth(e.getPoint().x, e.getPoint().y); 452 464 EastNorth bestMovement = calculateBestMovementAndNewNodes(mouseEn); 453 465 454 466 Main.map.mapView.setNewCursor(Cursor.MOVE_CURSOR, this); 455 467 … … 480 492 if (moveCommand == null) { 481 493 //make a new move command 482 moveCommand = new MoveCommand( movingNodeList, bestMovement.getX(), bestMovement.getY());494 moveCommand = new MoveCommand(new ArrayList<OsmPrimitive>(movingNodeList), bestMovement); 483 495 Main.main.undoRedo.add(moveCommand); 484 496 } else { … … 522 534 //Commit translate 523 535 //the move command is already committed in mouseDragged 536 joinNodesIfCollapsed(movingNodeList); 524 537 } 525 538 … … 531 544 moveCommand = null; 532 545 mode = Mode.select; 533 534 546 updateStatusLine(); 535 547 Main.map.mapView.repaint(); … … 589 601 * Does actual extrusion of {@link #selectedSegment}. 590 602 * Uses {@link #initialN1en}, {@link #initialN2en} saved in calculatePossibleDirections* call 591 * Uses {@link #newN1en}, {@link #newN2en} calculated by {@link #calculateBestMovementAndNewNodes} 603 * Uses {@link #newN1en}, {@link #newN2en} calculated by {@link #calculateBestMovementAndNewNodes} 592 604 */ 593 605 private void performExtrusion() { … … 671 683 Command c = new SequenceCommand(tr("Extrude Way"), cmds); 672 684 Main.main.undoRedo.add(c); 685 joinNodesIfCollapsed(changedNodes); 686 } 687 688 private void joinNodesIfCollapsed(List<Node> changedNodes) { 673 689 if (newN1en.distance(newN2en) < 1e-6) { 674 690 // If the dual alignment created moved two nodes to the same point, merge them 675 691 Node targetNode = MergeNodesAction.selectTargetNode(changedNodes); 676 Command mergeCmd = MergeNodesAction.mergeNodes(Main.main.getEditLayer(), changedNodes, targetNode, changedNodes.get(0)); 677 Main.main.undoRedo.add(mergeCmd); 692 Node locNode = MergeNodesAction.selectTargetLocationNode(changedNodes); 693 Command mergeCmd = MergeNodesAction.mergeNodes(Main.main.getEditLayer(), changedNodes, targetNode, locNode); 694 if (mergeCmd!=null) { 695 Main.main.undoRedo.add(mergeCmd); 696 } else { 697 // undo extruding command itself 698 Main.main.undoRedo.undo(); 699 } 678 700 } 679 701 } … … 866 888 ), initialN2en, nextNodeEn, false); 867 889 } 868 890 869 891 /** 870 892 * Calculate newN1en, newN2en best suitable for given mouse coordinates … … 881 903 Main.map.statusLine.setDist(distance); 882 904 updateStatusLine(); 883 905 884 906 if (dualAlignActive) { 885 907 // new positions of selected segment's nodes, without applying dual alignment … … 895 917 newN1en = collapsedSegmentPosition; 896 918 newN2en = collapsedSegmentPosition; 919 dualAlignSegmentCollapsed = true; 920 } else { 921 dualAlignSegmentCollapsed = false; 897 922 } 898 923 } else { … … 1064 1089 return normalUnitVector; 1065 1090 } 1066 1091 1067 1092 /** 1068 1093 * Returns true if from1-to1 and from2-to2 vertors directions are opposite
Note:
See TracChangeset
for help on using the changeset viewer.