Ticket #7513: 7513_bugfix.patch

File 7513_bugfix.patch, 6.8 KB (added by simon04, 14 years ago)
  • src/org/openstreetmap/josm/actions/MergeNodesAction.java

    diff --git a/src/org/openstreetmap/josm/actions/MergeNodesAction.java b/src/org/openstreetmap/josm/actions/MergeNodesAction.java
    index 4a99848..1d1ecdb 100644
    a b import org.openstreetmap.josm.data.coor.EastNorth;  
    2727import org.openstreetmap.josm.data.coor.LatLon;
    2828import org.openstreetmap.josm.data.osm.Node;
    2929import org.openstreetmap.josm.data.osm.OsmPrimitive;
     30import org.openstreetmap.josm.data.osm.Relation;
    3031import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3132import org.openstreetmap.josm.data.osm.TagCollection;
    3233import org.openstreetmap.josm.data.osm.Way;
    public class MergeNodesAction extends JosmAction {  
    260261            return null;
    261262        }
    262263
    263         Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(nodes);
     264        final Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(nodes);
     265        final Set<Relation> relationsWithReferences = new HashSet<Relation>();
     266        for (RelationToChildReference i : relationToNodeReferences) {
     267            relationsWithReferences.add(i.getParent());
     268        }
    264269
    265270        try {
    266271            TagCollection nodeTags = TagCollection.unionOfAllPrimitives(nodes);
    267             List<Command> resultion = CombinePrimitiveResolverDialog.launchIfNecessary(nodeTags, nodes, Collections.singleton(targetNode));
     272            List<Command> resolution = CombinePrimitiveResolverDialog.launchIfNecessary(
     273                    nodeTags, nodes, Collections.singleton(targetNode), relationsWithReferences,
     274                    1 /* safe to merge nodes being part of at most 1 relation */);
    268275            LinkedList<Command> cmds = new LinkedList<Command>();
    269276
    270277            // the nodes we will have to delete
    public class MergeNodesAction extends JosmAction {  
    290297                newTargetNode.setCoor(targetLocationNode.getCoor());
    291298                cmds.add(new ChangeCommand(targetNode, newTargetNode));
    292299            }
    293             cmds.addAll(resultion);
     300            cmds.addAll(resolution);
    294301            if (!nodesToDelete.isEmpty()) {
    295302                cmds.add(new DeleteCommand(nodesToDelete));
    296303            }
  • src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java b/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
    index 1ef4418..7bdc315 100644
    a b public class CombinePrimitiveResolverDialog extends JDialog {  
    439439            final TagCollection tagsOfPrimitives,
    440440            final Collection<? extends OsmPrimitive> primitives,
    441441            final Collection<? extends OsmPrimitive> targetPrimitives) throws UserCancelException {
     442        return launchIfNecessary(tagsOfPrimitives, primitives, targetPrimitives, OsmPrimitive.getParentRelations(primitives), 0);
     443    }
    442444
    443         final TagCollection completeWayTags = new TagCollection(tagsOfPrimitives);
    444         TagConflictResolutionUtil.combineTigerTags(completeWayTags);
    445         TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(completeWayTags, primitives);
    446         final TagCollection tagsToEdit = new TagCollection(completeWayTags);
     445    public static List<Command> launchIfNecessary(
     446            final TagCollection tagsOfPrimitives,
     447            final Collection<? extends OsmPrimitive> primitives,
     448            final Collection<? extends OsmPrimitive> targetPrimitives,
     449            final Collection<Relation> parentRelations,
     450            final int parentRelationsThreshold) throws UserCancelException {
     451
     452        final TagCollection normalizedTags = new TagCollection(tagsOfPrimitives);
     453        TagConflictResolutionUtil.combineTigerTags(normalizedTags);
     454        TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(normalizedTags, primitives);
     455        final TagCollection tagsToEdit = new TagCollection(normalizedTags);
    447456        TagConflictResolutionUtil.completeTagCollectionForEditing(tagsToEdit);
    448457
    449458        final CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance();
    450459
    451         dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues());
     460        dialog.getTagConflictResolverModel().populate(tagsToEdit, normalizedTags.getKeysWithMultipleValues());
    452461
    453         final Set<Relation> parentRelations = OsmPrimitive.getParentRelations(primitives);
    454462        dialog.getRelationMemberConflictResolverModel().populate(parentRelations, primitives);
    455463        dialog.prepareDefaultDecisions();
    456464
    457465        // show information dialog to non-experts
    458         if (!completeWayTags.isApplicableToPrimitive() && !ExpertToggleAction.isExpert()) {
    459             String conflicts = Utils.joinAsHtmlUnorderedList(Utils.transform(completeWayTags.getKeysWithMultipleValues(), new Function<String, String>() {
     466        if (!normalizedTags.isApplicableToPrimitive() && !ExpertToggleAction.isExpert()) {
     467            String conflicts = Utils.joinAsHtmlUnorderedList(Utils.transform(normalizedTags.getKeysWithMultipleValues(), new Function<String, String>() {
    460468
    461469                @Override
    462470                public String apply(String key) {
    463                     return tr("{0} ({1})", key, Utils.join(tr(", "), Utils.transform(completeWayTags.getValues(key), new Function<String, String>() {
     471                    return tr("{0} ({1})", key, Utils.join(tr(", "), Utils.transform(normalizedTags.getValues(key), new Function<String, String>() {
    464472
    465473                        @Override
    466474                        public String apply(String x) {
    public class CombinePrimitiveResolverDialog extends JDialog {  
    487495            }
    488496        }
    489497
    490         if (!parentRelations.isEmpty() && !ExpertToggleAction.isExpert()) {
     498        if (parentRelations.size() > parentRelationsThreshold && !ExpertToggleAction.isExpert()) {
    491499            String msg = trn("You are about to combine {1} objects, "
    492500                    + "which are part of {0} relation:<br/>{2}"
    493501                    + "Combining these objects may break this relation. If you are unsure, please cancel this operation.<br/>"
    public class CombinePrimitiveResolverDialog extends JDialog {  
    513521        }
    514522
    515523        // resolve tag conflicts if necessary
    516         if (!completeWayTags.isApplicableToPrimitive() || !parentRelations.isEmpty()) {
     524        if (!normalizedTags.isApplicableToPrimitive() || parentRelations.size() > parentRelationsThreshold) {
    517525            dialog.setVisible(true);
    518526            if (dialog.isCanceled()) {
    519527                throw new UserCancelException();