Changeset 4671 in josm for trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java
- Timestamp:
- 2011-12-20T22:28:46+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java
r4214 r4671 9 9 import java.util.Iterator; 10 10 import java.util.List; 11 import java.util.Set; 11 12 12 13 import org.openstreetmap.josm.Main; … … 72 73 return; 73 74 Way follower = selectedLines.iterator().next(); 75 if (follower.isClosed()) /* Don't loop until OOM */ 76 return; 74 77 Node prev = follower.getNode(1); 75 78 boolean reversed = true; … … 81 84 if (referrers.size() < 2) return; // There's nothing to follow 82 85 86 Node newPoint = null; 83 87 Iterator<OsmPrimitive> i = referrers.iterator(); 84 88 while (i.hasNext()) { … … 91 95 continue; 92 96 } 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)) 97 99 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); 98 116 } 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 }; 130 126 } 131 127 }
Note:
See TracChangeset
for help on using the changeset viewer.