Ignore:
Timestamp:
2017-07-24T22:23:18+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm15042

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

    r33464 r33465  
    4444public class PTAssistantValidatorTest extends Test {
    4545
     46    public static final int ERROR_CODE_FROM_TO_ROUTE_TAG = 3701;
    4647    public static final int ERROR_CODE_SORTING = 3711;
    4748    public static final int ERROR_CODE_PARTIAL_SORTING = 3712;
     
    352353        // Check if the relation is correct, or only has a wrong sorting order:
    353354        RouteChecker routeChecker = new RouteChecker(r, this);
     355        routeChecker.setManager(manager);
     356        routeChecker.setAssigner(assigner);
     357        routeChecker.performFromToTagsTest();
    354358        routeChecker.performSortingTest();
    355359        List<TestError> routeCheckerErrors = routeChecker.getErrors();
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java

    r33432 r33465  
    2121import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
    2222import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionTypeCalculator;
     23import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteDataManager;
     24import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
    2325import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     26import org.openstreetmap.josm.plugins.pt_assistant.utils.StopToWayAssigner;
    2427
    2528/**
     
    3538    List<RelationMember> sortedMembers;
    3639
     40    /* Manager of the PTStops and PTWays of the current route */
     41    private PTRouteDataManager manager;
     42
     43    /* Assigns PTStops to nearest PTWays and stores that correspondence */
     44    private StopToWayAssigner assigner;
     45
    3746    public RouteChecker(Relation relation, Test test) {
    3847
     
    4352    }
    4453
    45    protected void performSortingTest() {
     54    protected void performSortingTest() {
    4655
    4756        final List<RelationMember> waysToCheck = new ArrayList<>();
     
    8291            }
    8392        }
     93    }
     94
     95    protected void performFromToTagsTest() {
     96
     97        String from = relation.get("from");
     98        String to = relation.get("to");
     99        if (from == null || to == null || manager.getPTStopCount() == 0) {
     100            return;
     101        }
     102
     103        PTStop stop = manager.getFirstStop();
     104        OsmPrimitive primitive = checkPTStopName(stop, from);
     105
     106        if (primitive != null) {
     107            Builder builder = TestError.builder(this.test, Severity.WARNING,
     108                    PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
     109            builder.message(tr("PT: The name of the first stop does not match the \"from\" tag of the route relation"));
     110            builder.primitives(primitive);
     111            TestError e = builder.build();
     112            this.errors.add(e);
     113        }
     114
     115        stop = manager.getLastStop();
     116        primitive = checkPTStopName(stop, to);
     117
     118        if (primitive != null) {
     119            Builder builder = TestError.builder(this.test, Severity.WARNING,
     120                    PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
     121            builder.message(tr("PT: The name of the last stop does not match the \"to\" tag of the route relation"));
     122            builder.primitives(primitive);
     123            TestError e = builder.build();
     124            this.errors.add(e);
     125        }
     126    }
     127
     128    //given a PTStop and a name, check whether one of its primitives have a
     129    //different name from the one passed. if so, it returns the primitive.
     130    //it returns null if the names match
     131    private OsmPrimitive checkPTStopName(PTStop stop, String name) {
     132        OsmPrimitive primitive = null;
     133        String toCheck = null;
     134        if (stop.getPlatform() != null) {
     135            toCheck = stop.getPlatform().getName();
     136            primitive = stop.getPlatform();
     137        }
     138        if (toCheck == null && stop.getStopPosition() != null) {
     139            toCheck = stop.getStopPosition().getName();
     140            primitive = stop.getStopPosition();
     141        }
     142
     143        if (toCheck != null && !toCheck.equals(name))
     144            return primitive;
     145
     146        return null;
    84147    }
    85148
     
    185248        return new ChangeCommand(originalRelation, sortedRelation);
    186249    }
     250
     251    public PTRouteDataManager getManager() {
     252        return manager;
     253    }
     254
     255    public void setManager(PTRouteDataManager manager) {
     256        this.manager = manager;
     257    }
     258
     259    public StopToWayAssigner getAssigner() {
     260        return assigner;
     261    }
     262
     263    public void setAssigner(StopToWayAssigner assigner) {
     264        this.assigner = assigner;
     265    }
    187266}
Note: See TracChangeset for help on using the changeset viewer.