Changeset 32806 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-08-13T04:10:03+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32801 r32806 26 26 import org.openstreetmap.josm.data.validation.TestError; 27 27 import org.openstreetmap.josm.gui.Notification; 28 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 29 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 31 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteDataManager; 29 32 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; … … 565 568 566 569 /*- 567 * When is an error fixable ?570 * When is an error fixable (outdated)? 568 571 * - if there is a correct segment 569 572 * - if it can be fixed by sorting … … 584 587 PTRouteSegment wrongSegment = wrongSegments.get(testError); 585 588 PTRouteSegment correctSegment = null; 586 // TODO: now just the first correctSegment is taken over. Change587 // that the segment is selected.588 589 for (PTRouteSegment segment : correctSegments) { 589 590 if (wrongSegment.getFirstStop().equalsStop(segment.getFirstStop()) … … 606 607 } 607 608 609 /** 610 * Finds fixes using sorting and removal. Modifies the messages in the test 611 * error according to the availability of automatic fixes. 612 */ 608 613 protected void findFixes() { 614 609 615 for (TestError error : wrongSegments.keySet()) { 616 // look for fixes using sorting and removing: 610 617 findFix(error); 611 } 618 619 // change the error code based on the availability of fixes: 620 PTRouteSegment wrongSegment = wrongSegments.get(error); 621 List<PTRouteSegment> correctSegmentsForThisError = new ArrayList<>(); 622 for (PTRouteSegment segment : correctSegments) { 623 if (wrongSegment.getFirstWay().getId() == segment.getFirstWay().getId() 624 && wrongSegment.getLastWay().getId() == segment.getLastWay().getId()) { 625 correctSegmentsForThisError.add(segment); 626 } 627 } 628 629 int numberOfFixes = correctSegmentsForThisError.size(); 630 631 if (numberOfFixes == 0) { 632 numberOfFixes = wrongSegment.getFixVariants().size(); 633 } 634 if (numberOfFixes == 0) { 635 for (PTRouteSegment segment : correctSegments) { 636 if (wrongSegment.getFirstStop().equalsStop(segment.getFirstStop()) 637 && wrongSegment.getLastStop().equalsStop(segment.getLastStop())) { 638 correctSegmentsForThisError.add(segment); 639 } 640 } 641 numberOfFixes = correctSegmentsForThisError.size(); 642 } 643 644 // change the error code: 645 if (numberOfFixes == 0) { 646 error.setMessage(tr("PT: Problem in the route segment with no automatic fix")); 647 } else if (numberOfFixes == 1) { 648 error.setMessage(tr("PT: Problem in the route segment with one automatic fix")); 649 } else { 650 error.setMessage("PT: Problem in the route segment with several automatic fixes"); 651 } 652 } 653 612 654 } 613 655 … … 627 669 Node previousNode = findFirstNodeOfRouteSegmentInDirectionOfTravel(startPTWay); 628 670 if (previousNode == null) { 629 // TODO: sort route ways630 671 return; 631 672 } … … 697 738 // layer, clear them: 698 739 ((PTAssistantValidatorTest) testError.getTester()).clearFixVariants(); 699 740 700 741 PTRouteSegment wrongSegment = wrongSegments.get(testError); 701 742 … … 709 750 } 710 751 711 // if no correct segment found, apply less strict criteria to look for one: 752 // if no correct segment found, apply less strict criteria to look for 753 // one: 712 754 if (correctSegmentsForThisError.isEmpty() && wrongSegment.getFixVariants().isEmpty()) { 713 755 for (PTRouteSegment segment : correctSegments) { … … 863 905 */ 864 906 private static void carryOutSelectedFix(TestError testError, List<PTWay> fix) { 907 // modify the route: 865 908 Relation route = (Relation) testError.getPrimitives().iterator().next(); 866 909 route.setMembers(getModifiedRelationMembers(testError, fix)); … … 869 912 wrongSegment.setPTWays(fix); 870 913 addCorrectSegment(wrongSegment); 914 915 // get ways for the fix: 916 List<Way> primitives = new ArrayList<>(); 917 for (PTWay ptway : fix) { 918 primitives.addAll(ptway.getWays()); 919 } 920 921 // get layer: 922 OsmDataLayer layer = null; 923 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class); 924 for (OsmDataLayer osmDataLayer : listOfLayers) { 925 if (osmDataLayer.data == route.getDataSet()) { 926 layer = osmDataLayer; 927 break; 928 } 929 } 930 931 // create editor: 932 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, route, 933 route.getMembersFor(primitives)); 934 935 // open editor: 936 editor.setVisible(true); 937 871 938 } 872 939
Note:
See TracChangeset
for help on using the changeset viewer.