Changeset 34238 in osm for applications/editors/josm/plugins
- Timestamp:
- 2018-06-03T11:29:51+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java
r34236 r34238 17 17 import java.util.ArrayList; 18 18 import java.util.Arrays; 19 import java.util.Collection; 19 20 import java.util.Collections; 20 21 import java.util.HashSet; 21 22 import java.util.List; 23 import java.util.Objects; 22 24 import java.util.Set; 23 25 … … 35 37 import org.openstreetmap.josm.command.Command; 36 38 import org.openstreetmap.josm.command.SequenceCommand; 37 //import org.openstreetmap.josm.command.Command;38 39 import org.openstreetmap.josm.command.SplitWayCommand; 39 40 import org.openstreetmap.josm.data.Bounds; … … 54 55 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 55 56 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 56 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;57 57 import org.openstreetmap.josm.tools.CheckParameterUtil; 58 58 import org.openstreetmap.josm.tools.GBC; 59 import org.openstreetmap.josm.tools.Geometry; 59 60 import org.openstreetmap.josm.tools.ImageProvider; 61 import org.openstreetmap.josm.tools.Pair; 60 62 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; 61 63 … … 599 601 } 600 602 603 // to find if there is any highway, railway, waterway crossing the way 604 private void findIntersection(Set<Way> newWays) { 605 try { 606 DataSet ds = getLayerManager().getEditDataSet(); 607 addWaysIntersectingWays(ds.getWays(), Arrays.asList(previousAffectedWay, affected), newWays); 608 Node n1 = previousAffectedWay.firstNode(); 609 Node n2 = previousAffectedWay.lastNode(); 610 Node n3 = affected.firstNode(); 611 Node n4 = affected.lastNode(); 612 List<Way> waysToBeRemoved = new ArrayList<>(); 613 for (Way way : newWays) { 614 int count = 0; 615 if (way.containsNode(n1)) 616 count++; 617 if (way.containsNode(n2)) 618 count++; 619 if (!previousAffectedWay.equals(affected)) { 620 if (way.containsNode(n3)) 621 count++; 622 if (way.containsNode(n4)) 623 count++; 624 } 625 if (count == 1) { 626 waysToBeRemoved.add(way); 627 } else { 628 if (!way.hasKey("highway") && !way.hasKey("waterway") && !way.hasKey("railway")) { 629 waysToBeRemoved.add(way); 630 } 631 } 632 } 633 newWays.removeAll(waysToBeRemoved); 634 } catch (Exception e) { 635 e.printStackTrace(); 636 } 637 } 638 639 int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays) { 640 List<Pair<Node, Node>> nodePairs = w.getNodePairs(false); 641 int count = 0; 642 for (Way anyway: ways) { 643 if (Objects.equals(anyway, w)) continue; 644 if (newWays.contains(anyway)) continue; 645 List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false); 646 loop: for (Pair<Node, Node> p1 : nodePairs) { 647 for (Pair<Node, Node> p2 : nodePairs2) { 648 if (null != Geometry.getSegmentSegmentIntersection( 649 p1.a.getEastNorth(), p1.b.getEastNorth(), 650 p2.a.getEastNorth(), p2.b.getEastNorth())) { 651 newWays.add(anyway); 652 count++; 653 break loop; 654 } 655 } 656 } 657 } 658 return count; 659 } 660 661 int addWaysIntersectingWays(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { 662 int count = 0; 663 for (Way w : initWays) { 664 count += addWaysIntersectingWay(allWays, w, newWays); 665 } 666 return count; 667 } 668 601 669 @Override 602 670 public void mouseMoved(MouseEvent e) { … … 654 722 // to be highlighted now 655 723 private void updateHighlights() { 724 if (oldHighlights == null && newHighlights == null) { 725 return; 726 } 727 656 728 if (oldHighlights.isEmpty() && newHighlights.isEmpty()) { 657 729 return; … … 741 813 if (previousAffectedWay.hasKey("waterway") || affected.hasKey("waterway")) { 742 814 setOptionsWithTunnel(); 743 } else if (newWays.size() != 0) { 815 } else if (newWays != null && newWays.size() != 0) { 744 816 setOptionsWithBridge(); 745 817 } else { … … 847 919 } 848 920 849 private void findIntersection(Set<Way> newWays) {850 DataSet ds = getLayerManager().getEditDataSet();851 NodeWayUtils.addWaysIntersectingWays(ds.getWays(), Arrays.asList(previousAffectedWay, affected), newWays);852 Node n1 = previousAffectedWay.firstNode();853 Node n2 = previousAffectedWay.lastNode();854 Node n3 = affected.firstNode();855 Node n4 = affected.lastNode();856 List<Way> waysToBeRemoved = new ArrayList<>();857 for (Way way : newWays) {858 int count = 0;859 if (way.containsNode(n1))860 count++;861 if (way.containsNode(n2))862 count++;863 if (!previousAffectedWay.equals(affected)) {864 if (way.containsNode(n3))865 count++;866 if (way.containsNode(n4))867 count++;868 }869 if (count == 1) {870 waysToBeRemoved.add(way);871 } else {872 if (!way.hasKey("highway") && !way.hasKey("waterway") && !way.hasKey("railway")) {873 waysToBeRemoved.add(way);874 }875 }876 }877 newWays.removeAll(waysToBeRemoved);878 }879 880 921 @Override 881 922 protected void buttonAction(int buttonIndex, ActionEvent evt) {
Note:
See TracChangeset
for help on using the changeset viewer.