Ticket #19136: 19136.4.patch

File 19136.4.patch, 8.3 KB (added by GerdP, 4 years ago)
  • src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

     
    7373    public static final int RINGS_SHARE_NODES = 1617;
    7474    /** Incomplete multipolygon was modified */
    7575    public static final int MODIFIED_INCOMPLETE = 1618;
     76    /** No further tags for multipolygon */
     77    public static final int NO_TAGS = 1619;
     78    /** No area tag for multipolygon */
     79    public static final int NO_AREA_TAG = 1620;
    7680
    7781    private static final int FOUND_INSIDE = 1;
    7882    private static final int FOUND_OUTSIDE = 2;
     
    9397    @Override
    9498    public void visit(Relation r) {
    9599        if (r.isMultipolygon() && !r.isEmpty()) {
     100            tagTest(r);
    96101            List<TestError> tmpErrors = new ArrayList<>(30);
    97102            boolean hasUnexpectedWayRoles = checkMembersAndRoles(r, tmpErrors);
    98103            boolean hasRepeatedMembers = checkRepeatedWayMembers(r);
     
    119124    }
    120125
    121126    /**
     127     * Check if there is any useful tag on a multipolygon relation.
     128     * @param r relation
     129     */
     130    private void tagTest(Relation r) {
     131        if (!r.isBoundary()) {
     132            if (r.getInterestingTags().size() <= 1) {
     133                errors.add(TestError.builder(this, Severity.ERROR, NO_TAGS)
     134                        .message(tr("No further tags for multipolygon"))
     135                        .primitives(r)
     136                        .build());
     137            } else if (!r.concernsArea()) {
     138                errors.add(TestError.builder(this, Severity.WARNING, NO_AREA_TAG)
     139                        .message(tr("No area tag for multipolygon"))
     140                        .primitives(r)
     141                        .build());
     142            }
     143        }
     144    }
     145
     146    /**
    122147     * Various style-related checks:<ul>
     148     * <li>{@link #NO_STYLE}: No area style for multipolygon</li>
    123149     * <li>{@link #INNER_STYLE_MISMATCH}: With the currently used mappaint style the style for inner way equals the multipolygon style</li>
    124      * <li>{@link #OUTER_STYLE_MISMATCH}: Style for outer way mismatches</li>
     150     * <li>{@link #OUTER_STYLE_MISMATCH}: With the currently used mappaint style the style for outer way mismatches the area style</li>
    125151     * <li>{@link #OUTER_STYLE}: Area style on outer way</li>
    126152     * </ul>
    127153     * @param r relation
     
    128154     * @param polygon multipolygon
    129155     */
    130156    private void checkStyleConsistency(Relation r, Multipolygon polygon) {
    131         ElemStyles styles = MapPaintStyles.getStyles();
    132         if (styles != null && !r.isBoundary()) {
     157        if (MapPaintStyles.getStyles() != null && !r.isBoundary()) {
    133158            AreaElement area = ElemStyles.getAreaElemStyle(r, false);
    134             boolean areaStyle = area != null;
    135             // If area style was not found for relation then use style of ways
    136159            if (area == null) {
    137                 for (Way w : polygon.getOuterWays()) {
    138                     area = ElemStyles.getAreaElemStyle(w, true);
    139                     if (area != null) {
    140                         break;
    141                     }
    142                 }
    143                 if (area == null) {
    144                     errors.add(TestError.builder(this, Severity.OTHER, NO_STYLE)
    145                             .message(tr("No area style for multipolygon"))
    146                             .primitives(r)
    147                             .build());
    148                 }
    149             }
    150 
    151             if (area != null) {
     160                errors.add(TestError.builder(this, Severity.OTHER, NO_STYLE)
     161                        .message(tr("No area style for multipolygon"))
     162                        .primitives(r)
     163                        .build());
     164            } else {
    152165                for (Way wInner : polygon.getInnerWays()) {
    153                     if (area.equals(ElemStyles.getAreaElemStyle(wInner, false))) {
     166                    if (wInner.isClosed() && area.equals(ElemStyles.getAreaElemStyle(wInner, false))) {
    154167                        errors.add(TestError.builder(this, Severity.OTHER, INNER_STYLE_MISMATCH)
    155168                                .message(tr("With the currently used mappaint style the style for inner way equals the multipolygon style"))
    156169                                .primitives(Arrays.asList(r, wInner))
     
    159172                    }
    160173                }
    161174                for (Way wOuter : polygon.getOuterWays()) {
     175                    if (!wOuter.isArea())
     176                        continue;
    162177                    AreaElement areaOuter = ElemStyles.getAreaElemStyle(wOuter, false);
    163178                    if (areaOuter != null) {
    164179                        if (!area.equals(areaOuter)) {
    165                             String message = !areaStyle ? tr("Style for outer way mismatches")
    166                                     : tr("With the currently used mappaint style the style for outer way mismatches the area style");
    167180                            errors.add(TestError.builder(this, Severity.OTHER, OUTER_STYLE_MISMATCH)
    168                                     .message(message)
     181                                    .message(tr("With the currently used mappaint style the style for outer way mismatches the area style"))
    169182                                    .primitives(Arrays.asList(r, wOuter))
    170183                                    .highlight(wOuter)
    171184                                    .build());
    172                         } else if (areaStyle) { /* style on outer way of multipolygon, but equal to polygon */
     185                        } else { /* style on outer way of multipolygon, but equal to polygon */
    173186                            errors.add(TestError.builder(this, Severity.WARNING, OUTER_STYLE)
    174187                                    .message(tr("Area style on outer way"))
    175188                                    .primitives(Arrays.asList(r, wOuter))
     
    913926            boolean hasRepeatedMembers = checkRepeatedWayMembers(r);
    914927            if (!hasRepeatedMembers) {
    915928                polygon = new Multipolygon(r);
    916                 // don't check style consistency here
     929                // don't check style tags or consistency here
    917930                checkGeometryAndRoles(r, polygon);
    918931            }
    919932            createdRelation = null; // makes sure that repeatCheck is only set once
  • src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java

     
    99import java.util.HashSet;
    1010import java.util.Set;
    1111
    12 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1312import org.openstreetmap.josm.data.osm.OsmUtils;
    14 import org.openstreetmap.josm.data.osm.Relation;
    1513import org.openstreetmap.josm.data.osm.Way;
    1614import org.openstreetmap.josm.data.validation.Severity;
    1715import org.openstreetmap.josm.data.validation.Test;
     
    179177        if (!w.isUsable() || w.isArea())
    180178            return;
    181179
    182         for (OsmPrimitive parent: w.getReferrers()) {
    183             if (parent instanceof Relation && ((Relation) parent).isMultipolygon())
    184                 return;
    185         }
    186 
    187180        for (UnclosedWaysCheck c : checks) {
    188181            TestError error = c.getTestError(w, this);
    189182            if (error != null) {
  • test/unit/org/openstreetmap/josm/data/validation/tests/UnclosedWaysTest.java

     
    7878    }
    7979
    8080    /**
    81      * Test to make sure the multipolygon ways are ignored
     81     * Test to make sure the multipolygon ways are not ignored
     82     * See #19136
    8283     * @throws Exception if an exception occurs
    8384     */
    8485    @Test
     
    9596        ds.addPrimitive(r);
    9697        uwTest.visit(w);
    9798        assertTrue(ElemStyles.hasAreaElemStyle(w, false));
    98         assertEquals(0, uwTest.getErrors().size());
     99        assertEquals(1, uwTest.getErrors().size());
    99100
    100101        uwTest.endTest();
    101102    }