Changeset 27624 in osm
- Timestamp:
- 2012-01-26T05:32:40+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryAction.java
r27623 r27624 10 10 import org.openstreetmap.josm.actions.JosmAction; 11 11 import org.openstreetmap.josm.command.*; 12 import org.openstreetmap.josm.data.coor.LatLon;13 12 import org.openstreetmap.josm.data.osm.Node; 14 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 14 import org.openstreetmap.josm.data.osm.Relation; 15 import org.openstreetmap.josm.data.osm.RelationToChildReference; 16 import org.openstreetmap.josm.data.osm.TagCollection; 16 17 import org.openstreetmap.josm.data.osm.Way; 17 18 import org.openstreetmap.josm.gui.DefaultNameFormatter; 19 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 20 import org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil; 18 21 import static org.openstreetmap.josm.tools.I18n.tr; 19 22 import org.openstreetmap.josm.tools.Shortcut; … … 81 84 AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) node.getKeys(); 82 85 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 83 94 // replace sacrificial node in way with node that is being upgraded 84 95 if (nodeToReplace != null) { … … 104 115 // no node to replace, so just delete the original node 105 116 commands.add(new DeleteCommand(node)); 106 }107 108 // Copy tags from node109 // TODO: use merge tag conflict dialog instead110 for (String key : nodeTags.keySet()) {111 commands.add(new ChangePropertyCommand(way, key, nodeTags.get(key)));112 117 } 113 118 … … 164 169 } 165 170 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 166 181 // Prepare a list of nodes that are not used anywhere except in the way 167 182 Collection<Node> nodePool = getUnimportantNodes(way); … … 199 214 200 215 // Now do the replacement 201 List<Command> commands = new ArrayList<Command>();202 216 commands.add(new ChangeNodesCommand(way, geometryNodes)); 203 217 … … 205 219 for( Node node : nodeAssoc.keySet() ) 206 220 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)));211 221 212 222 // Remove geometry way from selection … … 296 306 } 297 307 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 298 347 /** 299 348 * 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.