Changeset 32747 in osm
- Timestamp:
- 2016-07-31T19:55:45+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java
r32710 r32747 122 122 123 123 /** 124 * Assigns the given way to a PTWay of this route relation. 124 * Assigns the given way to a PTWay of this route relation. If multiple 125 * PTWays contain the same inputWay, the first found PTWay is returned. 125 126 * 126 127 * @param inputWay -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteSegment.java
r32707 r32747 19 19 private PTStop lastStop; 20 20 private List<PTWay> ptways; 21 private List<List<PTWay>> fixVariants; 21 22 22 23 public PTRouteSegment(PTStop firstStop, PTStop lastStop, List<PTWay> ways) { … … 25 26 this.ptways = new ArrayList<>(ways.size()); 26 27 ptways.addAll(ways); 27 } 28 29 public PTRouteSegment(PTStop firstStop, PTStop lastStop) { 30 this.firstStop = firstStop; 31 this.lastStop = lastStop; 32 this.ptways = new ArrayList<>(); 28 fixVariants = new ArrayList<>(); 33 29 } 34 30 35 31 public List<PTWay> getPTWays() { 36 32 return this.ptways; 33 } 34 35 public void setPTWays(List<PTWay> ptwayList) { 36 this.ptways = ptwayList; 37 this.fixVariants.clear(); 37 38 } 38 39 … … 45 46 } 46 47 48 public PTWay getFirstPTWay() { 49 if (ptways.isEmpty()) { 50 return null; 51 } 52 return ptways.get(0); 53 } 47 54 55 public PTWay getLastPTWay() { 56 if (ptways.isEmpty()) { 57 return null; 58 } 59 return ptways.get(ptways.size() - 1); 60 } 48 61 62 public void addFixVariant(List<PTWay> list) { 63 this.fixVariants.add(list); 64 } 65 66 public List<List<PTWay>> getFixVariants() { 67 return this.fixVariants; 68 } 49 69 50 70 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java
r32710 r32747 123 123 List<Way> ways = this.getWays(); 124 124 for (Way way: ways) { 125 if (way. hasTag("junction", "roundabout") && way.firstNode() == way.lastNode()) {125 if (way.firstNode() == way.lastNode()) { 126 126 return true; 127 127 } … … 129 129 return false; 130 130 } 131 132 public boolean startsWithUnsplitRoundabout() { 133 if (this.ways.get(0).firstNode() == this.ways.get(0).lastNode()) { 134 return true; 135 } 136 return false; 137 } 138 139 public boolean endsWithUnsplitRoundabout() { 140 if (this.ways.get(this.ways.size() - 1).firstNode() == this.ways.get(this.ways.size()-1).lastNode()) { 141 return true; 142 } 143 return false; 144 } 131 145 132 146 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32734 r32747 320 320 if (!sortingErrorFound) { 321 321 segmentChecker.performStopByStopTest(); 322 segmentChecker.findFixes(); 322 323 } 323 324 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32743 r32747 6 6 import java.util.HashMap; 7 7 import java.util.List; 8 9 import javax.swing.JOptionPane; 8 10 9 11 import org.openstreetmap.josm.command.ChangeCommand; … … 47 49 private StopToWayAssigner assigner; 48 50 49 /*50 * Stores reference that shows in which direction the segment checker is 51 * moving52 */ 53 private Node firstNodeOfRouteSegmentInDirectionOfTravel;51 private List<PTWay> unusedWays = new ArrayList<>(); 52 53 private HashMap<TestError, PTWay> erroneousPTWays = new HashMap<>(); 54 55 private HashMap<TestError, Node> firstNodeOfErroneousPTWay = new HashMap<>(); 54 56 55 57 public SegmentChecker(Relation relation, Test test) { … … 70 72 71 73 this.assigner = new StopToWayAssigner(manager.getPTWays()); 74 75 unusedWays.addAll(manager.getPTWays()); 72 76 73 77 } … … 241 245 for (int i = 1; i < manager.getPTStopCount(); i++) { 242 246 243 // this.firstNodeOfRouteSegmentInDirectionOfTravel = null;244 245 247 PTStop startStop = manager.getPTStops().get(i - 1); 246 248 PTStop endStop = manager.getPTStops().get(i); … … 254 256 List<PTWay> segmentWays = manager.getPTWaysBetween(startWay, endWay); 255 257 256 Node testNode = findFirstNodeOfRouteSegmentInDirectionOfTravel( 257 segmentWays.get(0)); 258 if (testNode == null) { 258 Node firstNode = findFirstNodeOfRouteSegmentInDirectionOfTravel(segmentWays.get(0)); 259 if (firstNode == null) { 259 260 // check if this error has just been reported: 260 261 if (!this.errors.isEmpty() && this.errors.get(this.errors.size() - 1).getHighlighted().size() == 1 … … 272 273 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays); 273 274 wrongSegments.put(e, routeSegment); 275 erroneousPTWays.put(e, manager.getPTWay(startWay)); 276 firstNodeOfErroneousPTWay.put(e, null); 274 277 } 275 278 continue; 276 279 } 277 280 278 boolean sortingCorrect = existingWaySortingIsCorrect(segmentWays.get(0), 279 testNode,segmentWays.get(segmentWays.size() - 1));281 boolean sortingCorrect = existingWaySortingIsCorrect(segmentWays.get(0), firstNode, 282 segmentWays.get(segmentWays.size() - 1)); 280 283 if (sortingCorrect) { 281 284 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays); 282 285 correctSegments.add(routeSegment); 286 unusedWays.removeAll(segmentWays); 283 287 } else { 284 288 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays); … … 430 434 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 431 435 this.errors.add(e); 436 erroneousPTWays.put(e, current); 432 437 return false; 433 438 } … … 439 444 currentNode = getOppositeEndNode(current, currentNode); 440 445 441 List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current, 442 currentNode); 446 List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current, currentNode); 443 447 444 448 if (!nextWaysInDirectionOfTravel.contains(nextPTWayAccortingToExistingSorting)) { … … 557 561 return true; 558 562 } 559 if (isFixableBySegmentSorting(testError)) { 560 return true; 561 } 562 if (isFixableByRemovingWays()) { 563 if (isFixableBySortingAndRemoval(testError)) { 563 564 return true; 564 565 } … … 587 588 } 588 589 589 private static boolean isFixableByS egmentSorting(TestError testError) {590 private static boolean isFixableBySortingAndRemoval(TestError testError) { 590 591 PTRouteSegment wrongSegment = wrongSegments.get(testError); 591 592 return false; 593 } 594 595 private static boolean isFixableByRemovingWays() { 596 // TODO 592 List<List<PTWay>> fixVariants = wrongSegment.getFixVariants(); 593 if (!fixVariants.isEmpty()) { 594 return true; 595 } 597 596 return false; 598 597 } … … 603 602 } 604 603 604 protected void findFixes() { 605 for (TestError error : wrongSegments.keySet()) { 606 findFix(error); 607 } 608 } 609 610 /** 611 * This method assumes that the first and the second ways of the route 612 * segment are correctly connected. If they are not, the error will be 613 * marked as not fixable. 614 * 615 * @param testError 616 */ 617 private void findFix(TestError testError) { 618 619 PTRouteSegment wrongSegment = wrongSegments.get(testError); 620 PTWay startPTWay = wrongSegment.getFirstPTWay(); 621 PTWay endPTWay = wrongSegment.getLastPTWay(); 622 623 Node previousNode = findFirstNodeOfRouteSegmentInDirectionOfTravel(startPTWay); 624 if (previousNode == null) { 625 // TODO: sort route ways 626 return; 627 } 628 629 List<List<PTWay>> initialFixes = new ArrayList<>(); 630 List<PTWay> initialFix = new ArrayList<>(); 631 initialFix.add(startPTWay); 632 initialFixes.add(initialFix); 633 List<PTWay> fix = findWaysForFix(initialFixes, initialFix, previousNode, endPTWay).get(0); 634 635 if (!fix.isEmpty() && fix.get(fix.size() - 1).equals(endPTWay)) { 636 wrongSegment.addFixVariant(fix); 637 } 638 639 } 640 641 /** 642 * 643 * @param allFixes 644 * @param currentFix 645 * @param previousNode 646 * @param endWay 647 * @return 648 */ 649 private List<List<PTWay>> findWaysForFix (List<List<PTWay>> allFixes, List<PTWay> currentFix, Node previousNode, 650 PTWay endWay) { 651 652 PTWay currentWay = currentFix.get(currentFix.size() - 1); 653 Node nextNode = getOppositeEndNode(currentWay, previousNode); 654 655 List<PTWay> potentialNextWays = this.findNextPTWaysInDirectionOfTravel(currentWay, nextNode); 656 List<PTWay> nextWays = new ArrayList<>(); 657 for (PTWay potentianNextWay : potentialNextWays) { 658 if (unusedWays.contains(potentianNextWay)) { 659 nextWays.add(potentianNextWay); 660 } 661 } 662 663 if (!nextWays.isEmpty()) { 664 currentFix.add(nextWays.get(0)); 665 if (!nextWays.get(0).equals(endWay)) { 666 allFixes = findWaysForFix(allFixes, currentFix, nextNode, endWay); 667 } 668 } 669 670 // if (nextWays.size() > 1) { 671 // for (int i = 1; i < nextWays.size(); i++) { 672 // List<PTWay> newList = new ArrayList<>(); 673 // newList.addAll(currentFix); 674 // newList.add(nextWays.get(i)); 675 // allFixes.add(newList); 676 // // TODO: go on 677 // } 678 // } 679 680 return allFixes; 681 } 682 605 683 protected static Command fixError(TestError testError) { 606 684 607 685 PTRouteSegment wrongSegment = wrongSegments.get(testError); 686 687 // 1) try to fix by using the correct segment: 608 688 PTRouteSegment correctSegment = null; 609 689 // TODO: now just the first correctSegment is taken over. Change that … … 653 733 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 654 734 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 655 // if (waysOfOriginalRelation.get(i) ==656 // wrongSegment.getPTWays().get(0)) {657 735 for (PTWay ptway : correctSegment.getPTWays()) { 658 736 if (ptway.getRole().equals("forward") || ptway.getRole().equals("backward")) { … … 678 756 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 679 757 return changeCommand; 758 759 } else if (!wrongSegment.getFixVariants().isEmpty()) { 760 // 2) try to fix by using the sort & remove method: 761 // TODO: ask user if the change should be undertaken 762 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 763 Relation modifiedRelation = new Relation(originalRelation); 764 List<RelationMember> originalRelationMembers = originalRelation.getMembers(); 765 List<RelationMember> modifiedRelationMembers = new ArrayList<>(); 766 767 // copy stops first: 768 for (RelationMember rm : originalRelationMembers) { 769 if (RouteUtils.isPTStop(rm)) { 770 if (rm.getRole().equals("stop_position")) { 771 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 772 RelationMember newMember = new RelationMember("stop", rm.getNode()); 773 modifiedRelationMembers.add(newMember); 774 } else { // if it is a way: 775 RelationMember newMember = new RelationMember("stop", rm.getWay()); 776 modifiedRelationMembers.add(newMember); 777 } 778 } else { 779 // if the relation member does not have the role 780 // "stop_position": 781 modifiedRelationMembers.add(rm); 782 } 783 } 784 } 785 786 // copy PTWays next: 787 List<RelationMember> waysOfOriginalRelation = new ArrayList<>(); 788 for (RelationMember rm : originalRelation.getMembers()) { 789 if (RouteUtils.isPTWay(rm)) { 790 waysOfOriginalRelation.add(rm); 791 } 792 } 793 794 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 795 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 796 for (PTWay ptway : wrongSegment.getFixVariants().get(0)) { 797 if (ptway.getRole().equals("forward") || ptway.getRole().equals("backward")) { 798 modifiedRelationMembers.add(new RelationMember("", ptway.getMember())); 799 } else { 800 modifiedRelationMembers.add(ptway); 801 } 802 } 803 i = i + wrongSegment.getPTWays().size() - 1; 804 } else { 805 if (waysOfOriginalRelation.get(i).getRole().equals("forward") 806 || waysOfOriginalRelation.get(i).getRole().equals("backward")) { 807 modifiedRelationMembers.add(new RelationMember("", waysOfOriginalRelation.get(i).getMember())); 808 } else { 809 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 810 } 811 } 812 } 813 modifiedRelation.setMembers(modifiedRelationMembers); 814 // TODO: change the data model too 815 wrongSegments.remove(testError); 816 wrongSegment.setPTWays(wrongSegment.getFixVariants().get(0)); 817 correctSegments.add(wrongSegment); 818 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 819 return changeCommand; 820 680 821 } 681 822
Note:
See TracChangeset
for help on using the changeset viewer.