Ignore:
Timestamp:
2011-12-20T22:28:46+01:00 (12 years ago)
Author:
stoecker
Message:

fix #7164 - patch by ij - bugs fixes and improvements for FollowLine function

File:
1 edited

Legend:

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

    r4214 r4671  
    99import java.util.Iterator;
    1010import java.util.List;
     11import java.util.Set;
    1112
    1213import org.openstreetmap.josm.Main;
     
    7273            return;
    7374        Way follower = selectedLines.iterator().next();
     75        if (follower.isClosed())    /* Don't loop until OOM */
     76            return;
    7477        Node prev = follower.getNode(1);
    7578        boolean reversed = true;
     
    8184        if (referrers.size() < 2) return; // There's nothing to follow
    8285       
     86        Node newPoint = null;       
    8387        Iterator<OsmPrimitive> i = referrers.iterator();
    8488        while (i.hasNext()) {
     
    9195                continue;
    9296            }
    93             List<Node> points = toFollow.getNodes();
    94             int indexOfLast = points.indexOf(last);
    95             int indexOfPrev = points.indexOf(prev);
    96             if ((indexOfLast == -1) || (indexOfPrev == -1)) { // Both points must belong to both lines
     97            Set<Node> points = toFollow.getNeighbours(last);
     98            if (!points.remove(prev) || (points.size() == 0))
    9799                continue;
     100            if (points.size() > 1)    // Ambiguous junction?
     101                return;
     102
     103            Node newPointCandidate = points.iterator().next();
     104
     105            if ((newPoint != null) && (newPoint != newPointCandidate))
     106                return;         // Ambiguous junction, force to select next
     107
     108            newPoint = newPointCandidate;
     109        }
     110        if (newPoint != null) {
     111            Way newFollower = new Way(follower);
     112            if (reversed) {
     113                newFollower.addNode(0, newPoint);
     114            } else {
     115                newFollower.addNode(newPoint);
    98116            }
    99             if (Math.abs(indexOfPrev - indexOfLast) != 1) {  // ...and be consecutive
    100                 continue;
    101             }
    102             Node newPoint = null;
    103             if (indexOfPrev == (indexOfLast - 1)) {
    104                 if ((indexOfLast + 1) < points.size()) {
    105                     newPoint = points.get(indexOfLast + 1);
    106                 }
    107             } else {
    108                 if ((indexOfLast - 1) >= 0) {
    109                     newPoint = points.get(indexOfLast - 1);
    110                 }
    111             }
    112             if (newPoint != null) {
    113                 Way newFollower = new Way(follower);
    114                 if (reversed) {
    115                     newFollower.addNode(0, newPoint);
    116                 } else {
    117                     newFollower.addNode(newPoint);
    118                 }
    119                 Main.main.undoRedo.add(new ChangeCommand(follower, newFollower));
    120                 osmLayer.data.clearSelection();
    121                 osmLayer.data.addSelected(newFollower);
    122                 osmLayer.data.addSelected(newPoint);
    123                 // "viewport following" mode for tracing long features
    124                 // from aerial imagery or GPS tracks.
    125                 if (Main.map.mapView.viewportFollowing) {
    126                     Main.map.mapView.smoothScrollTo(newPoint.getEastNorth());
    127                 };
    128                 return;
    129             }
     117            Main.main.undoRedo.add(new ChangeCommand(follower, newFollower));
     118            osmLayer.data.clearSelection();
     119            osmLayer.data.addSelected(newFollower);
     120            osmLayer.data.addSelected(newPoint);
     121            // "viewport following" mode for tracing long features
     122            // from aerial imagery or GPS tracks.
     123            if (Main.map.mapView.viewportFollowing) {
     124                Main.map.mapView.smoothScrollTo(newPoint.getEastNorth());
     125            };
    130126        }
    131127    }
Note: See TracChangeset for help on using the changeset viewer.