Ticket #6323: extrude-add-point.patch

File extrude-add-point.patch, 3.7 KB (added by olejorgenb, 11 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java b/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
    index 252852c..1e84ad3 100644
    a b import org.openstreetmap.josm.tools.Shortcut; 
    5050 */
    5151public class ExtrudeAction extends MapMode implements MapViewPaintable {
    5252
    53     enum Mode { extrude, translate, select }
     53    enum Mode { extrude, translate, select, add_node }
    5454
    5555    private Mode mode = Mode.select;
    5656
    public class ExtrudeAction extends MapMode implements MapViewPaintable { 
    116116            return tr("Move a segment along its normal, then release the mouse button.");
    117117        else if (mode == Mode.extrude)
    118118            return tr("Draw a rectangle of the desired size, then release the mouse button.");
     119        else if (mode == Mode.add_node)
     120            return tr("Release mouse button to add the node");
    119121        else
    120             return tr("Drag a way segment to make a rectangle. Ctrl-drag to move a segment along its normal.");
     122            return tr("Drag a way segment to make a rectangle. Ctrl-drag to move a segment along its normal. Alt-click to add a node");
    121123    }
    122124
    123125    @Override public boolean layerIsSupported(Layer l) {
    public class ExtrudeAction extends MapMode implements MapViewPaintable { 
    153155
    154156        if (selectedSegment == null) {
    155157            // If nothing gets caught, stay in select mode
     158        } else if ((e.getModifiers() & ActionEvent.ALT_MASK) != 0) {
     159            mode = Mode.add_node;
     160            updateStatusLine();
    156161        } else {
    157162            // Otherwise switch to another mode
    158163
    public class ExtrudeAction extends MapMode implements MapViewPaintable { 
    221226        if (System.currentTimeMillis() - mouseDownTime < initialMoveDelay)
    222227            return;
    223228
    224         if (mode == Mode.select) {
     229        if (mode == Mode.select || mode == Mode.add_node) {
    225230            // Just sit tight and wait for mouse to be released.
    226231        } else {
    227232            //move and extrude mode - move the selected segment
    public class ExtrudeAction extends MapMode implements MapViewPaintable { 
    291296
    292297        if (mode == Mode.select) {
    293298            // Nothing to be done
     299        } else if (mode == Mode.add_node) {
     300            // Should maybe do the same as in DrawAction and fetch all nearby segments?
     301            WaySegment ws = Main.map.mapView.getNearestWaySegment(e.getPoint(), OsmPrimitive.isSelectablePredicate);
     302            if (ws == null) {
     303                mode = Mode.select;
     304                return;
     305            }
     306
     307            Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
     308
     309            EastNorth A = ws.getFirstNode().getEastNorth();
     310            EastNorth B = ws.getSecondNode().getEastNorth();
     311            n.setEastNorth(Geometry.closestPointToSegment(A, B, n.getEastNorth()));
     312
     313            Way wnew = new Way(ws.way);
     314            wnew.addNode(ws.lowerIndex+1, n);
     315
     316            SequenceCommand cmds = new SequenceCommand(tr("Add a new node to an existing way"),
     317                    new AddCommand(n), new ChangeCommand(ws.way, wnew));
     318
     319            Main.main.undoRedo.add(cmds);
     320            mode = Mode.select;
    294321        } else {
    295322            if (mode == Mode.extrude) {
    296323                if (e.getPoint().distance(initialMousePos) > 10 && newN1en != null) {
    public class ExtrudeAction extends MapMode implements MapViewPaintable { 
    355382            moveCommand = null;
    356383            mode = Mode.select;
    357384
    358             updateStatusLine();
    359385            Main.map.mapView.repaint();
    360386        }
     387        updateStatusLine();
    361388    }
    362389
    363390    /**