Changeset 7129 in josm for trunk


Ignore:
Timestamp:
2014-05-14T23:03:49+02:00 (6 years ago)
Author:
simon04
Message:

see #10018 - Avoid broken relations after combining ways

Location:
trunk/src/org/openstreetmap/josm/gui/conflict/tags
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

    r7005 r7129  
    1818import java.beans.PropertyChangeListener;
    1919import java.util.Collection;
    20 import java.util.HashSet;
     20import java.util.Collections;
     21import java.util.HashMap;
    2122import java.util.LinkedList;
    2223import java.util.List;
     24import java.util.Map;
    2325import java.util.Set;
    2426
     
    4951import org.openstreetmap.josm.tools.CheckParameterUtil;
    5052import org.openstreetmap.josm.tools.ImageProvider;
     53import org.openstreetmap.josm.tools.MultiMap;
     54import org.openstreetmap.josm.tools.Predicates;
    5155import org.openstreetmap.josm.tools.Utils;
    5256import org.openstreetmap.josm.tools.Utils.Function;
     
    297301
    298302    protected void prepareDefaultRelationDecisions() {
    299         RelationMemberConflictResolverModel model = getRelationMemberConflictResolverModel();
    300         Set<Relation> relations = new HashSet<>();
     303        final RelationMemberConflictResolverModel model = getRelationMemberConflictResolverModel();
     304        final Map<Relation, Integer> numberOfKeepResolutions = new HashMap<>();
     305        final MultiMap<OsmPrimitive, Relation> resolvedRelationsPerPrimitive = new MultiMap<>();
     306
    301307        for (int i = 0; i < model.getNumDecisions(); i++) {
    302             RelationMemberConflictDecision decision = model.getDecision(i);
    303             if (!relations.contains(decision.getRelation())) {
     308            final RelationMemberConflictDecision decision = model.getDecision(i);
     309            final Relation r = decision.getRelation();
     310            final OsmPrimitive p = decision.getOriginalPrimitive();
     311            if (!numberOfKeepResolutions.containsKey(r)) {
    304312                decision.decide(RelationMemberConflictDecisionType.KEEP);
    305                 relations.add(decision.getRelation());
     313                numberOfKeepResolutions.put(r, 1);
     314                resolvedRelationsPerPrimitive.put(p, r);
     315                continue;
     316            }
     317
     318            final Integer keepResolutions = numberOfKeepResolutions.get(r);
     319            final Collection<Relation> resolvedRelations = Utils.firstNonNull(resolvedRelationsPerPrimitive.get(p), Collections.<Relation>emptyList());
     320            if (keepResolutions <= Utils.filter(resolvedRelations, Predicates.equalTo(r)).size()) {
     321                // old relation contains one primitive more often than the current resolution => keep the current member
     322                decision.decide(RelationMemberConflictDecisionType.KEEP);
     323                numberOfKeepResolutions.put(r, keepResolutions + 1);
     324                resolvedRelationsPerPrimitive.put(p, r);
    306325            } else {
    307326                decision.decide(RelationMemberConflictDecisionType.REMOVE);
     327                resolvedRelationsPerPrimitive.put(p, r);
    308328            }
    309329        }
     
    552572        /* I18n: object count < 2 is not possible */
    553573        String msg = trn("You are about to combine {1} object, "
    554                 + "which are part of {0} relation:<br/>{2}"
     574                + "which is part of {0} relation:<br/>{2}"
    555575                + "Combining these objects may break this relation. If you are unsure, please cancel this operation.<br/>"
    556576                + "If you want to continue, you are shown a dialog to decide how to adapt the relation.<br/><br/>"
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java

    r7005 r7129  
    230230
    231231    protected Command buildResolveCommand(Relation relation, OsmPrimitive newPrimitive) {
    232         Relation modifiedRelation = new Relation(relation);
     232        final Relation modifiedRelation = new Relation(relation);
    233233        modifiedRelation.setMembers(null);
    234234        boolean isChanged = false;
    235235        for (int i=0; i < relation.getMembersCount(); i++) {
    236             RelationMember rm = relation.getMember(i);
    237             RelationMember rmNew;
     236            final RelationMember member = relation.getMember(i);
    238237            RelationMemberConflictDecision decision = getDecision(relation, i);
    239238            if (decision == null) {
    240                 modifiedRelation.addMember(rm);
     239                modifiedRelation.addMember(member);
    241240            } else {
    242241                switch(decision.getDecision()) {
    243242                case KEEP:
    244                     rmNew = new RelationMember(decision.getRole(),newPrimitive);
    245                     modifiedRelation.addMember(rmNew);
    246                     isChanged |= ! rm.equals(rmNew);
     243                    final RelationMember newMember = new RelationMember(decision.getRole(),newPrimitive);
     244                    modifiedRelation.addMember(newMember);
     245                    isChanged |= ! member.equals(newMember);
    247246                    break;
    248247                case REMOVE:
Note: See TracChangeset for help on using the changeset viewer.