Changeset 5820 in josm for trunk


Ignore:
Timestamp:
2013-04-01T22:12:50+02:00 (7 years ago)
Author:
akks
Message:

Angle indicator and angle snapping worked incorrect when line was continued from the start (no from the end)
Allow angle snapping for Alt-drawing (creating new way aligned to previous one)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r5768 r5820  
    873873        currentBaseNode = null;
    874874        previousNode = null;
    875 
     875       
     876        // Try to find an open way to measure angle from it. The way is not to be continued!
     877        // warning: may result in changes of currentBaseNode and previousNode
     878        // please remove if bugs arise
     879        if (selectedWay == null && selectedNode != null) {
     880            for (OsmPrimitive p: selectedNode.getReferrers()) {
     881                if (p.isUsable() && p instanceof Way && ((Way) p).isFirstLastNode(selectedNode)) {
     882                    if (selectedWay!=null) { // two uncontinued ways, nothing to take as reference
     883                        selectedWay=null;
     884                        break;
     885                    } else {
     886                        // set us ~continue this way (measure angle from it)
     887                        selectedWay = (Way) p;
     888                    }
     889                }
     890            }
     891        }
     892       
    876893        if (selectedNode == null) {
    877894            if (selectedWay == null)
    878895                return;
    879             if (selectedWay.isFirstLastNode(lastUsedNode)) {
    880                 currentBaseNode = lastUsedNode;
    881                 if (lastUsedNode == selectedWay.getNode(selectedWay.getNodesCount()-1) && selectedWay.getNodesCount() > 1) {
    882                     previousNode = selectedWay.getNode(selectedWay.getNodesCount()-2);
    883                 }
    884             }
     896            continueWayFromNode(selectedWay, lastUsedNode);
    885897        } else if (selectedWay == null) {
    886898            currentBaseNode = selectedNode;
    887899        } else if (!selectedWay.isDeleted()) { // fix #7118
    888             if (selectedNode == selectedWay.getNode(0)){
    889                 currentBaseNode = selectedNode;
    890                 if (selectedWay.getNodesCount()>1) {
    891                     previousNode = selectedWay.getNode(1);
    892                 }
    893             }
    894             if (selectedNode == selectedWay.lastNode()) {
    895                 currentBaseNode = selectedNode;
    896                 if (selectedWay.getNodesCount()>1) {
    897                     previousNode = selectedWay.getNode(selectedWay.getNodesCount()-2);
    898                 }
    899             }
    900         }
    901     }
    902 
     900            continueWayFromNode(selectedWay, selectedNode);
     901        }
     902    }
     903   
     904    /**
     905     * if one of the ends of @param way is given @param node ,
     906     * then set  currentBaseNode = node and previousNode = adjacent node of way
     907     */
     908    private void continueWayFromNode(Way way, Node node) {
     909        int n = way.getNodesCount();
     910        if (node == way.firstNode()){
     911            currentBaseNode = node;
     912            if (n>1) previousNode = way.getNode(1);
     913        } else if (node == way.lastNode()) {
     914            currentBaseNode = node;
     915            if (n>1) previousNode = way.getNode(n-2);
     916        }
     917    }
    903918
    904919    /**
Note: See TracChangeset for help on using the changeset viewer.