- Timestamp:
- 2019-01-10T07:51:29+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r14654 r14670 16 16 import java.util.Collection; 17 17 import java.util.Collections; 18 import java.util.HashSet; 18 19 import java.util.LinkedList; 19 20 import java.util.List; 20 import java.util. stream.Collectors;21 import java.util.Set; 21 22 22 23 import javax.swing.JOptionPane; … … 423 424 424 425 if (ctrl && !alt && candidateSegment != null) { 425 // Adding a new node to the highlighted segment 426 // Important: If there are other ways containing the same 427 // segment, a node must added to all of that ways. 428 Collection<Command> virtualCmds = new LinkedList<>(); 429 430 // Creating a new node 431 Node virtualNode = new Node(mv.getEastNorth(mousePos.x, 432 mousePos.y)); 433 virtualCmds.add(new AddCommand(ds, virtualNode)); 434 435 // Looking for candidateSegment copies in ways that are referenced by candidateSegment nodes 436 List<Way> firstNodeWays = candidateSegment.getFirstNode().referrers(Way.class).collect(Collectors.toList()); 437 List<Way> secondNodeWays = candidateSegment.getFirstNode().referrers(Way.class).collect(Collectors.toList()); 438 426 // Add a new node to the highlighted segment. 439 427 Collection<WaySegment> virtualSegments = new LinkedList<>(); 440 for (Way w : firstNodeWays) { 441 List<Pair<Node, Node>> wpps = w.getNodePairs(true); 442 for (Way w2 : secondNodeWays) { 443 if (!w.equals(w2)) { 444 continue; 445 } 446 // A way is referenced in both nodes. 447 // Checking if there is such segment 448 int i = -1; 449 for (Pair<Node, Node> wpp : wpps) { 450 ++i; 451 boolean ab = wpp.a.equals(candidateSegment.getFirstNode()) 452 && wpp.b.equals(candidateSegment.getSecondNode()); 453 boolean ba = wpp.b.equals(candidateSegment.getFirstNode()) 454 && wpp.a.equals(candidateSegment.getSecondNode()); 455 if (ab || ba) { 456 virtualSegments.add(new WaySegment(w, i)); 457 } 428 429 // Check if other ways have the same segment. 430 // We have to make sure that we add the new node to all of them. 431 Set<Way> commonParentWays = new HashSet<>(candidateSegment.getFirstNode().getParentWays()); 432 commonParentWays.retainAll(candidateSegment.getSecondNode().getParentWays()); 433 for (Way w : commonParentWays) { 434 for (int i = 0; i < w.getNodesCount() - 1; i++) { 435 WaySegment testWS = new WaySegment(w, i); 436 if (testWS.isSimilar(candidateSegment)) { 437 virtualSegments.add(testWS); 458 438 } 459 439 } 460 440 } 441 442 Collection<Command> virtualCmds = new LinkedList<>(); 443 // Create the new node 444 Node virtualNode = new Node(mv.getEastNorth(mousePos.x, mousePos.y)); 445 virtualCmds.add(new AddCommand(ds, virtualNode)); 461 446 462 447 // Adding the node to all segments found
Note:
See TracChangeset
for help on using the changeset viewer.