Changeset 4671 in josm
- Timestamp:
- 2011-12-20T22:28:46+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 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 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r4431 r4671 8 8 import java.util.List; 9 9 import java.util.Set; 10 import java.util.HashSet; 10 11 11 12 import org.openstreetmap.josm.Main; … … 139 140 } 140 141 142 /** 143 * Return nodes adjacent to <code>node</code> 144 * 145 * @param node the node. May be null. 146 * @return Set of nodes adjacent to <code>node</code> 147 * @since 4666 148 */ 149 public Set<Node> getNeighbours(Node node) { 150 HashSet<Node> neigh = new HashSet<Node>(); 151 152 if (node == null) return neigh; 153 154 Node[] nodes = this.nodes; 155 for (int i=0; i<nodes.length; i++) { 156 if (nodes[i].equals(node)) { 157 if (i > 0) 158 neigh.add(nodes[i-1]); 159 if (i < nodes.length-1) 160 neigh.add(nodes[i+1]); 161 } 162 } 163 return neigh; 164 } 165 141 166 public List<Pair<Node,Node>> getNodePairs(boolean sort) { 142 167 List<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>();
Note:
See TracChangeset
for help on using the changeset viewer.