Changeset 6575 in josm


Ignore:
Timestamp:
2013-12-31T12:05:47+01:00 (8 years ago)
Author:
simon04
Message:

fix #7196 - Validator: add multipolygon role check

This is done by creating a new multipolygon using the logics from
"Create multipolygon" and see if the roles match.

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r6569 r6575  
    3636import org.openstreetmap.josm.tools.Pair;
    3737import org.openstreetmap.josm.tools.Shortcut;
    38 import org.openstreetmap.josm.tools.Utils;
    3938
    4039/**
     
    147146            // add ways of existing relation to include them in polygon analysis
    148147            selectedWays = new HashSet<Way>(selectedWays);
    149             selectedWays.addAll(Utils.filteredCollection(selectedMultipolygonRelation.getMemberPrimitives(), Way.class));
     148            selectedWays.addAll(selectedMultipolygonRelation.getMemberPrimitives(Way.class));
    150149        }
    151150
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r6564 r6575  
    397397    }
    398398
     399    public <T extends OsmPrimitive> Collection<T> getMemberPrimitives(Class<T> tClass) {
     400        return Utils.filteredCollection(getMemberPrimitives(), tClass);
     401    }
     402
    399403    public List<OsmPrimitive> getMemberPrimitivesList() {
    400404        return Utils.transform(getMembers(), new Utils.Function<RelationMember, OsmPrimitive>() {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r6494 r6575  
    1515
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.actions.CreateMultipolygonAction;
    1718import org.openstreetmap.josm.data.osm.Node;
    1819import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2829import org.openstreetmap.josm.data.validation.Test;
    2930import org.openstreetmap.josm.data.validation.TestError;
     31import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3032import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
    3133import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    3234import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    3335import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     36import org.openstreetmap.josm.tools.Pair;
    3437
    3538/**
     
    176179            }
    177180
    178             for (RelationMember rm : r.getMembers()) {
    179                 if (!rm.getMember().isUsable())
    180                     return; // Rest of checks is only for complete multipolygons
     181            if (r.hasIncompleteMembers()) {
     182                return; // Rest of checks is only for complete multipolygons
     183            }
     184
     185            // Create new multipolygon using the logics from CreateMultipolygonAction and see if roles match.
     186            final Pair<Relation, Relation> newMP = CreateMultipolygonAction.createMultipolygonRelation(
     187                    r.getMemberPrimitives(Way.class), Collections.singleton(new Relation()));
     188            if (newMP != null) {
     189                for (RelationMember member : r.getMembers()) {
     190                    final Collection<RelationMember> memberInNewMP = newMP.b.getMembersFor(Collections.singleton(member.getMember()));
     191                    if (memberInNewMP != null && !memberInNewMP.isEmpty()) {
     192                        final String roleInNewMP = memberInNewMP.iterator().next().getRole();
     193                        if (!member.getRole().equals(roleInNewMP)) {
     194                            addError(r, new TestError(this, Severity.WARNING, tr("Role for ''{0}'' should be ''{1}''",
     195                                    member.getMember().getDisplayName(DefaultNameFormatter.getInstance()), roleInNewMP),
     196                                    WRONG_MEMBER_ROLE, Collections.singleton(r), Collections.singleton(member.getMember())));
     197                        }
     198                    }
     199                }
     200
    181201            }
    182202
Note: See TracChangeset for help on using the changeset viewer.