Ignore:
Timestamp:
2017-07-24T23:24:26+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm15042 - first last stop way test

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

    r33465 r33467  
    4545
    4646    public static final int ERROR_CODE_FROM_TO_ROUTE_TAG = 3701;
     47    public static final int ERROR_CODE_FIRST_LAST_STOP_WAY_TAG = 3702;
    4748    public static final int ERROR_CODE_SORTING = 3711;
    4849    public static final int ERROR_CODE_PARTIAL_SORTING = 3712;
     
    355356        routeChecker.setManager(manager);
    356357        routeChecker.setAssigner(assigner);
    357         routeChecker.performFromToTagsTest();
     358        if (!routeChecker.performFromToTagsTest()) {
     359            routeChecker.performFirstLastWayStopTest();
     360        }
    358361        routeChecker.performSortingTest();
    359362        List<TestError> routeCheckerErrors = routeChecker.getErrors();
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java

    r33465 r33467  
    55
    66import java.util.ArrayList;
     7import java.util.Arrays;
    78import java.util.Collection;
    89import java.util.List;
     
    1415import org.openstreetmap.josm.data.osm.Relation;
    1516import org.openstreetmap.josm.data.osm.RelationMember;
     17import org.openstreetmap.josm.data.osm.Way;
    1618import org.openstreetmap.josm.data.validation.Severity;
    1719import org.openstreetmap.josm.data.validation.Test;
     
    5254    }
    5355
     56    //checks if sorting the members of the current relation could make it
     57    //continuous or it could reduce the number of gaps. if one of the previous
     58    //is true raises a warning
    5459    protected void performSortingTest() {
    5560
     
    9398    }
    9499
    95     protected void performFromToTagsTest() {
     100    //checks if the from and to tags of the route match the names of the first
     101    //and last stops
     102    protected boolean performFromToTagsTest() {
    96103
    97104        String from = relation.get("from");
    98105        String to = relation.get("to");
    99106        if (from == null || to == null || manager.getPTStopCount() == 0) {
    100             return;
    101         }
    102 
     107            return false;
     108        }
     109
     110        boolean foundError = false;
    103111        PTStop stop = manager.getFirstStop();
    104112        OsmPrimitive primitive = checkPTStopName(stop, from);
     
    108116                    PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
    109117            builder.message(tr("PT: The name of the first stop does not match the \"from\" tag of the route relation"));
    110             builder.primitives(primitive);
     118            builder.primitives(primitive, relation);
    111119            TestError e = builder.build();
    112120            this.errors.add(e);
     121            foundError = true;
    113122        }
    114123
     
    120129                    PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
    121130            builder.message(tr("PT: The name of the last stop does not match the \"to\" tag of the route relation"));
    122             builder.primitives(primitive);
     131            builder.primitives(primitive, relation);
     132            TestError e = builder.build();
     133            this.errors.add(e);
     134            foundError = true;
     135        }
     136
     137        return foundError;
     138    }
     139
     140    //checks if the first and last stop are assigned to the first and last way
     141    protected void performFirstLastWayStopTest() {
     142
     143        if (manager.getPTStopCount() == 0 || manager.getPTWayCount() == 0) {
     144            return;
     145        }
     146
     147        PTStop stop = manager.getFirstStop();
     148        Way way = manager.getFirstWay();
     149        if (!way.equals(assigner.get(stop))) {
     150            Builder builder = TestError.builder(this.test, Severity.WARNING,
     151                    PTAssistantValidatorTest.ERROR_CODE_FIRST_LAST_STOP_WAY_TAG);
     152            builder.message(tr("PT: The first stop of the route does not match the first way"));
     153            List<OsmPrimitive> prims = new ArrayList<>(Arrays.asList(way, relation));
     154            if (stop.getPlatform() != null)
     155                prims.add(stop.getPlatform());
     156            if (stop.getStopPosition() != null)
     157                prims.add(stop.getStopPosition());
     158            builder.primitives(prims);
     159            TestError e = builder.build();
     160            this.errors.add(e);
     161        }
     162
     163        stop = manager.getLastStop();
     164        way = manager.getLastWay();
     165        if (!way.equals(assigner.get(stop))) {
     166            Builder builder = TestError.builder(this.test, Severity.WARNING,
     167                    PTAssistantValidatorTest.ERROR_CODE_FIRST_LAST_STOP_WAY_TAG);
     168            builder.message(tr("PT: The last stop of the route does not match the last way"));
     169            List<OsmPrimitive> prims = new ArrayList<>(Arrays.asList(way, relation));
     170            if (stop.getPlatform() != null)
     171                prims.add(stop.getPlatform());
     172            if (stop.getStopPosition() != null)
     173                prims.add(stop.getStopPosition());
     174            builder.primitives(prims);
    123175            TestError e = builder.build();
    124176            this.errors.add(e);
     
    147199    }
    148200
     201    /**
     202     * Checks whether there is at least one gap in the given list of ways.
     203     *
     204     * @param waysToCheck ways to check
     205     * @return true if has gap (in the sense of continuity of ways in the
     206     *         Relation Editor), false otherwise
     207     */
    149208    public boolean hasGaps(List<RelationMember> waysToCheck) {
    150209        return countGaps(waysToCheck) > 0;
     
    157216     *
    158217     * @param waysToCheck ways to check
    159      * @return true if has gap (in the sense of continuity of ways in the
    160      *         Relation Editor), false otherwise
     218     * @return number of gaps
    161219     */
    162220    private int countGaps(List<RelationMember> waysToCheck) {
Note: See TracChangeset for help on using the changeset viewer.