Changeset 3055 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-02-27T16:31:10+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r2844 r3055 2 2 package org.openstreetmap.josm.command; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trn; 6 import static org.openstreetmap.josm.tools.I18n.marktr;7 7 8 8 import java.awt.GridBagLayout; … … 11 11 import java.util.Collection; 12 12 import java.util.Collections; 13 import java.util.HashMap; 13 14 import java.util.HashSet; 14 15 import java.util.Iterator; 15 16 import java.util.LinkedList; 16 17 import java.util.List; 18 import java.util.Map; 17 19 import java.util.Set; 20 import java.util.Map.Entry; 18 21 19 22 import javax.swing.JLabel; … … 28 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 32 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 import org.openstreetmap.josm.data.osm.PrimitiveData; 30 34 import org.openstreetmap.josm.data.osm.Relation; 31 35 import org.openstreetmap.josm.data.osm.RelationToChildReference; … … 48 52 */ 49 53 private final Collection<? extends OsmPrimitive> toDelete; 54 private final Map<OsmPrimitive, PrimitiveData> clonedPrimitives = new HashMap<OsmPrimitive, PrimitiveData>(); 50 55 51 56 /** … … 107 112 } 108 113 109 protected void removeNewNodesFromDeletedWay(Way w) {110 // #2707: ways to be deleted can include new nodes (with node.id == 0).111 // Remove them from the way before the way is deleted. Otherwise the112 // deleted way is saved (or sent to the API) with a dangling reference to a node113 // Example:114 // <node id='2' action='delete' visible='true' version='1' ... />115 // <node id='1' action='delete' visible='true' version='1' ... />116 // <!-- missing node with id -1 because new deleted nodes are not persisted -->117 // <way id='3' action='delete' visible='true' version='1'>118 // <nd ref='1' />119 // <nd ref='-1' /> <!-- here's the problem -->120 // <nd ref='2' />121 // </way>122 if (w.isNew())123 return; // process existing ways only124 List<Node> nodesToKeep = new ArrayList<Node>();125 // lookup new nodes which have been added to the set of deleted126 // nodes ...127 Iterator<Node> it = nodesToKeep.iterator();128 while(it.hasNext()) {129 Node n = it.next();130 if (n.isNew()) {131 it.remove();132 }133 }134 w.setNodes(nodesToKeep);135 }136 137 114 @Override 138 115 public boolean executeCommand() { 139 super.executeCommand(); 140 for (OsmPrimitive osm : toDelete) { 116 // Make copy and remove all references (to prevent inconsistent dataset (delete referenced) while command is executed) 117 for (OsmPrimitive osm: toDelete) { 118 if (osm.isDeleted()) 119 throw new IllegalArgumentException(osm.toString() + " is already deleted"); 120 clonedPrimitives.put(osm, osm.save()); 121 122 if (osm instanceof Way) { 123 ((Way) osm).setNodes(null); 124 } else if (osm instanceof Relation) { 125 ((Relation) osm).setMembers(null); 126 } 127 } 128 129 for (OsmPrimitive osm: toDelete) { 141 130 osm.setDeleted(true); 142 if (osm instanceof Way) { 143 removeNewNodesFromDeletedWay((Way)osm); 144 } 145 } 131 } 132 146 133 return true; 134 } 135 136 @Override 137 public void undoCommand() { 138 for (OsmPrimitive osm: toDelete) { 139 osm.setDeleted(false); 140 } 141 142 for (Entry<OsmPrimitive, PrimitiveData> entry: clonedPrimitives.entrySet()) { 143 entry.getKey().load(entry.getValue()); 144 } 147 145 } 148 146
Note:
See TracChangeset
for help on using the changeset viewer.