Ignore:
Timestamp:
2017-08-17T11:56:02+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm15088 - applying the fix

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r33502 r33503  
    458458                || testError.getCode() == ERROR_CODE_SORTING
    459459                || testError.getCode() == ERROR_CODE_PARTIAL_SORTING
     460                || testError.getCode() == ERROR_CODE_TRIVIAL_FIX
    460461                || testError.getCode() == ERROR_CODE_END_STOP
    461462                || testError.getCode() == ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) {
     
    492493                || testError.getCode() == ERROR_CODE_END_STOP) {
    493494            commands.add(WayChecker.fixErrorByZooming(testError));
     495        }
     496
     497        if (testError.getCode() == ERROR_CODE_TRIVIAL_FIX) {
     498            commands.add(RouteChecker.fixTrivialError(testError));
    494499        }
    495500
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java

    r33502 r33503  
    110110                        Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_TRIVIAL_FIX);
    111111                        builder.message(tr("PT: Route gap can be closed by adding a single way"));
    112                         builder.primitives(relation, before, after, fix);
     112                        builder.primitives(relation, before, fix, after);
    113113                        TestError e = builder.build();
    114114                        this.errors.add(e);
     
    372372    }
    373373
     374    //the trivial fix simply adds the right way (the one found during the
     375    //detection phase) in the gap in order to close it
     376    protected static Command fixTrivialError(TestError testError) {
     377
     378        if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_TRIVIAL_FIX) {
     379            return null;
     380        }
     381
     382        List<OsmPrimitive> primitives = new ArrayList<>(testError.getPrimitives());
     383        Relation originalRelation = (Relation) primitives.get(0);
     384        Way before = (Way) primitives.get(1);
     385        Way fix = (Way) primitives.get(2);
     386
     387        int index = 0;
     388        List<RelationMember> members = originalRelation.getMembers();
     389        for (index = 0; index < members.size(); index++) {
     390            if (members.get(index).getMember().equals(before)) {
     391                break;
     392            }
     393        }
     394
     395        Relation fixedRelation = new Relation(originalRelation);
     396        fixedRelation.addMember(index + 1, new RelationMember(null, fix));
     397
     398        return new ChangeCommand(originalRelation, fixedRelation);
     399    }
     400
    374401    public PTRouteDataManager getManager() {
    375402        return manager;
Note: See TracChangeset for help on using the changeset viewer.