Changeset 34932 in osm for applications/editors/josm/plugins
- Timestamp:
- 2019-03-24T06:43:16+01:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r34862 r34932 40 40 } 41 41 42 private static <T extends OsmPrimitive> void filteredAdd(Collection<T> collection, T element) { 43 if (!element.isDisabled()) { 44 collection.add(element); 45 } 46 } 47 48 private static <T extends OsmPrimitive> void filteredAddAll(Collection<T> out, Collection<T> in) { 49 for (T element: in) { 50 filteredAdd(out, element); 51 } 52 } 53 42 54 /** 43 55 * Find the neighbours of node n on the way w and put them in given collection … … 56 68 // add previous element 57 69 if (idx > 0) { 58 nodes.add(nodeList.get(idx - 1));70 filteredAdd(nodes, nodeList.get(idx - 1)); 59 71 } 60 72 // add next element 61 73 if (idx < nodeList.size() - 1) { 62 nodes.add(nodeList.get(idx + 1));74 filteredAdd(nodes, nodeList.get(idx + 1)); 63 75 } 64 76 if (w.isClosed()) { 65 77 // cyclic neighbours detection 66 78 if (idx == 0) { 67 nodes.add(nodeList.get(nodeList.size() - 2));79 filteredAdd(nodes, nodeList.get(nodeList.size() - 2)); 68 80 } 69 81 if (idx == nodeList.size() - 1) { 70 nodes.add(nodeList.get(1));82 filteredAdd(nodes, nodeList.get(1)); 71 83 } 72 84 } … … 84 96 boolean flag = ways.contains(w); 85 97 for (Node n: nodes) { 86 ways.addAll(n.getParentWays());98 filteredAddAll(ways, n.getParentWays()); 87 99 } 88 100 if (!flag) ways.remove(w); … … 98 110 static int addWaysConnectedToNode(Node n, Set<Way> ways) { 99 111 int s = ways.size(); 100 ways.addAll(n.getParentWays());112 filteredAddAll(ways, n.getParentWays()); 101 113 return ways.size() - s; 102 114 } … … 107 119 * @param w way to check intersections 108 120 * @param newWays set to place the ways we found 121 * @param excludeWays set of excluded ways 109 122 * @return number of ways possibly added added to newWays 110 123 */ … … 113 126 int count = 0; 114 127 for (Way anyway: ways) { 128 if (anyway.isDisabled()) continue; 115 129 if (Objects.equals(anyway, w)) continue; 116 130 if (newWays.contains(anyway) || excludeWays.contains(anyway)) continue; … … 133 147 134 148 static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays) { 135 List<Pair<Node, Node>> nodePairs = w.getNodePairs(false); 136 int count = 0; 137 for (Way anyway: ways) { 138 if (Objects.equals(anyway, w)) continue; 139 if (newWays.contains(anyway)) continue; 140 List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false); 141 loop: for (Pair<Node, Node> p1 : nodePairs) { 142 for (Pair<Node, Node> p2 : nodePairs2) { 143 if (null != Geometry.getSegmentSegmentIntersection( 144 p1.a.getEastNorth(), p1.b.getEastNorth(), 145 p2.a.getEastNorth(), p2.b.getEastNorth())) { 146 newWays.add(anyway); 147 count++; 148 break loop; 149 } 150 } 151 } 152 } 153 return count; 149 Set<Way> excludeWays = new HashSet<Way>(); 150 return addWaysIntersectingWay(ways, w, newWays, excludeWays); 154 151 } 155 152 … … 162 159 */ 163 160 public static int addWaysIntersectingWays(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { 161 // performance improvement - filter everything ahead of time 162 Set<Way> filteredWays = new HashSet<>(); 163 filteredAddAll(filteredWays, allWays); 164 164 int count = 0; 165 165 for (Way w : initWays) { 166 count += addWaysIntersectingWay( allWays, w, newWays);166 count += addWaysIntersectingWay(filteredWays, w, newWays); 167 167 } 168 168 return count; … … 196 196 newWays.addAll(initWays); 197 197 Set<Way> newFoundWays; 198 // performance improvement - apply filters ahead of time 199 Set<Way> filteredWays = new HashSet<>(); 200 filteredAddAll(filteredWays, allWays); 201 filteredWays.removeAll(initWays); 198 202 199 203 int level = 0, c; … … 202 206 newFoundWays = new HashSet<>(); 203 207 for (Way w : foundWays) { 204 c += addWaysIntersectingWay( allWays, w, newFoundWays, newWays);208 c += addWaysIntersectingWay(filteredWays, w, newFoundWays); 205 209 } 206 210 foundWays = newFoundWays; … … 213 217 return; 214 218 } 215 } while (c > 0 && level < maxLevel); 219 if (level >= maxLevel) { 220 new Notification( 221 tr("Reached max recursion depth: {0}", level) 222 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 223 return; 224 } 225 } while (c > 0); 216 226 } 217 227 … … 233 243 return; 234 244 } 235 } while (c > 0 && level < maxLevel); 245 if (level >= maxLevel) { 246 new Notification( 247 tr("Reached max recursion depth: {0}", level) 248 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 249 return; 250 } 251 } while (c > 0); 236 252 } 237 253 … … 256 272 if ((i2-i1)*2 <= n) { // i1 ... i2 257 273 for (int i = i1+1; i != i2; i++) { 258 newNodes.add(nodes.get(i));274 filteredAdd(newNodes, nodes.get(i)); 259 275 } 260 276 } else { // i2 ... n-1 0 1 ... i1 261 277 for (int i = i2+1; i != i1; i = (i+1) % n) { 262 newNodes.add(nodes.get(i));278 filteredAdd(newNodes, nodes.get(i)); 263 279 } 264 280 } 265 281 } else { 266 282 for (int i = i1+1; i < i2; i++) { 267 newNodes.add(nodes.get(i));283 filteredAdd(newNodes, nodes.get(i)); 268 284 } 269 285 } … … 331 347 //we came to starting way, but not not the right end 332 348 if (Objects.equals(otherEnd, firstWay.firstNode())) return false; 333 newWays.addAll(newestWays);349 filteredAddAll(newWays, newestWays); 334 350 return true; // correct loop found 335 351 } … … 362 378 //if (Geometry.nodeInsidePolygon(n, polyNodes)) { 363 379 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)) { 380 // can't filter nodes here, would prevent selecting ways that have filtered nodes 364 381 newestNodes.add(n); 365 382 } … … 369 386 for (Way w : searchWays) { 370 387 if (newestNodes.containsAll(w.getNodes())) { 371 newestWays.add(w);388 filteredAdd(newestWays, w); 372 389 } 373 390 } … … 377 394 } 378 395 379 newNodes.addAll(newestNodes);380 newWays.addAll(newestWays); 396 filteredAddAll(newNodes, newestNodes); 397 newWays.addAll(newestWays); // already filtered 381 398 } 382 399 … … 392 409 //if (Geometry.nodeInsidePolygon(n, polyNodes)) { 393 410 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)) { 411 // can't filter nodes here, would prevent selecting ways that have filtered nodes 394 412 newestNodes.add(n); 395 413 } … … 399 417 for (Way w : searchWays) { 400 418 if (newestNodes.containsAll(w.getNodes())) { 401 newestWays.add(w);402 } 403 } 404 405 newNodes.addAll(newestNodes);406 newWays.addAll(newestWays); 419 filteredAdd(newestWays, w); 420 } 421 } 422 423 filteredAddAll(newNodes, newestNodes); 424 newWays.addAll(newestWays); // already filtered 407 425 } 408 426 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java
r34812 r34932 65 65 Node node = nodeQueue.remove(); 66 66 for (Way p : node.getParentWays()) { 67 if (! newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)) {67 if (!p.isDisabled() && !newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)) { 68 68 newWays.add(p); 69 69 nodeQueue.add(p.firstNode().equals(node) ? p.lastNode() : p.firstNode()); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java
r34816 r34932 60 60 nodes.clear(); 61 61 for (OsmPrimitive p : pp) { // find all affected ways 62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p); 62 if (p instanceof Node && !p.isDeleted() && !p.isDisabled()) 63 nodes.add((Node) p); 63 64 } 64 65 if (!nodes.isEmpty() && !ds.getSelectedNodes().containsAll(nodes)) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java
r34816 r34932 60 60 for (OsmPrimitive p : pp) { 61 61 // find all affected ways 62 if (p instanceof Way && !p.isDeleted()) ways.add((Way) p); 62 if (p instanceof Way && !p.isDeleted() && !p.isDisabled()) 63 ways.add((Way) p); 63 64 } 64 65 if (!ways.isEmpty() && !ds.getSelectedWays().containsAll(ways)) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectWayNodesAction.java
r32410 r34932 68 68 selectedNodes = new ArrayList<>(); 69 69 } 70 selectedNodes.add(n);70 if (!n.isDisabled()) selectedNodes.add(n); 71 71 } 72 72 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java
r34816 r34932 58 58 newSel.clear(); 59 59 newSel.addAll(histsel); 60 newSel.removeIf(p -> p == null || p.isDeleted() );60 newSel.removeIf(p -> p == null || p.isDeleted() || p.isDisabled()); 61 61 k++; 62 62 if (!newSel.isEmpty()) {
Note:
See TracChangeset
for help on using the changeset viewer.