Changeset 27624 in osm


Ignore:
Timestamp:
2012-01-26T05:32:40+01:00 (13 years ago)
Author:
joshdoe
Message:

utilsplugin2: Show conflict dialog with "Replace Geometry" when tags or memberships conflict (fixes #7278)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryAction.java

    r27623 r27624  
    1010import org.openstreetmap.josm.actions.JosmAction;
    1111import org.openstreetmap.josm.command.*;
    12 import org.openstreetmap.josm.data.coor.LatLon;
    1312import org.openstreetmap.josm.data.osm.Node;
    1413import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1514import org.openstreetmap.josm.data.osm.Relation;
     15import org.openstreetmap.josm.data.osm.RelationToChildReference;
     16import org.openstreetmap.josm.data.osm.TagCollection;
    1617import org.openstreetmap.josm.data.osm.Way;
    1718import org.openstreetmap.josm.gui.DefaultNameFormatter;
     19import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog;
     20import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil;
    1821import static org.openstreetmap.josm.tools.I18n.tr;
    1922import org.openstreetmap.josm.tools.Shortcut;
     
    8184        AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) node.getKeys();
    8285
     86        // merge tags
     87        Collection<Command> tagResolutionCommands = getTagConflictResolutionCommands(node, way);
     88        if (tagResolutionCommands == null) {
     89            // user canceled tag merge dialog
     90            return;
     91        }
     92        commands.addAll(tagResolutionCommands);
     93       
    8394        // replace sacrificial node in way with node that is being upgraded
    8495        if (nodeToReplace != null) {
     
    104115            // no node to replace, so just delete the original node
    105116            commands.add(new DeleteCommand(node));
    106         }
    107 
    108         // Copy tags from node
    109         // TODO: use merge tag conflict dialog instead
    110         for (String key : nodeTags.keySet()) {
    111             commands.add(new ChangePropertyCommand(way, key, nodeTags.get(key)));
    112117        }
    113118
     
    164169        }
    165170
     171        List<Command> commands = new ArrayList<Command>();
     172               
     173        // merge tags
     174        Collection<Command> tagResolutionCommands = getTagConflictResolutionCommands(geometry, way);
     175        if (tagResolutionCommands == null) {
     176            // user canceled tag merge dialog
     177            return;
     178        }
     179        commands.addAll(tagResolutionCommands);
     180       
    166181        // Prepare a list of nodes that are not used anywhere except in the way
    167182        Collection<Node> nodePool = getUnimportantNodes(way);
     
    199214
    200215        // Now do the replacement
    201         List<Command> commands = new ArrayList<Command>();
    202216        commands.add(new ChangeNodesCommand(way, geometryNodes));
    203217
     
    205219        for( Node node : nodeAssoc.keySet() )
    206220            commands.add(new MoveCommand(nodeAssoc.get(node), node.getCoor()));
    207 
    208         // Copy tags from temporary way (source etc.)
    209         for( String key : geometry.keySet() )
    210             commands.add(new ChangePropertyCommand(way, key, geometry.get(key)));
    211221
    212222        // Remove geometry way from selection
     
    296306    }
    297307   
     308     /**
     309     * Merge tags from source to target object, showing resolution dialog if
     310     * needed.
     311     *
     312     * @param source
     313     * @param target
     314     * @return
     315     */
     316    public List<Command> getTagConflictResolutionCommands(OsmPrimitive source, OsmPrimitive target) {
     317        Collection<OsmPrimitive> primitives = Arrays.asList(source, target);
     318       
     319        Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(primitives);
     320
     321        // build the tag collection
     322        TagCollection tags = TagCollection.unionOfAllPrimitives(primitives);
     323        TagConflictResolutionUtil.combineTigerTags(tags);
     324        TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing(tags, primitives);
     325        TagCollection tagsToEdit = new TagCollection(tags);
     326        TagConflictResolutionUtil.completeTagCollectionForEditing(tagsToEdit);
     327
     328        // launch a conflict resolution dialog, if necessary
     329        CombinePrimitiveResolverDialog dialog = CombinePrimitiveResolverDialog.getInstance();
     330        dialog.getTagConflictResolverModel().populate(tagsToEdit, tags.getKeysWithMultipleValues());
     331        dialog.getRelationMemberConflictResolverModel().populate(relationToNodeReferences);
     332        dialog.setTargetPrimitive(target);
     333        dialog.prepareDefaultDecisions();
     334
     335        // conflict resolution is necessary if there are conflicts in the merged tags
     336        // or if at least one of the merged nodes is referred to by a relation
     337        if (!tags.isApplicableToPrimitive() || relationToNodeReferences.size() > 1) {
     338            dialog.setVisible(true);
     339            if (dialog.isCanceled()) {
     340                return null;
     341            }
     342        }
     343        return dialog.buildResolutionCommands();
     344    }
     345
     346   
    298347    /**
    299348     * Find node from the collection which is nearest to <tt>node</tt>. Max distance is taken in consideration.
Note: See TracChangeset for help on using the changeset viewer.