Changeset 30008 in osm for applications/editors/josm/plugins/reverter/src
- Timestamp:
- 2013-10-07T13:20:14+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/DataSetCommandMerger.java
r30000 r30008 4 4 5 5 import java.util.ArrayList; 6 import java.util.Collection; 6 7 import java.util.LinkedList; 7 8 import java.util.List; 8 9 10 import org.openstreetmap.josm.Main; 9 11 import org.openstreetmap.josm.command.ChangeCommand; 10 12 import org.openstreetmap.josm.command.Command; … … 32 34 33 35 private final List<Command> cmds = new LinkedList<Command>(); 34 private final List<OsmPrimitive> undeletedPrimitives = new LinkedList<OsmPrimitive>();36 private final List<OsmPrimitive> nominalRevertedPrimitives = new LinkedList<OsmPrimitive>(); 35 37 36 38 /** … … 43 45 } 44 46 45 private void addChangeCommandIfNotEquals(OsmPrimitive target, OsmPrimitive newTarget ) {47 private void addChangeCommandIfNotEquals(OsmPrimitive target, OsmPrimitive newTarget, boolean nominal) { 46 48 if (!target.hasEqualSemanticAttributes(newTarget)) { 47 49 cmds.add(new ChangeCommand(target,newTarget)); 48 undeletedPrimitives.add(target); 50 if (nominal) { 51 nominalRevertedPrimitives.add(target); 52 } 53 Main.debug("Reverting "+target+" to "+newTarget); 49 54 } 50 55 } … … 77 82 Node newTarget = new Node(target); 78 83 mergePrimitive(source, target, newTarget); 79 addChangeCommandIfNotEquals(target,newTarget );84 addChangeCommandIfNotEquals(target,newTarget,true); 80 85 } 81 86 … … 92 97 if (!source.isVisible()) return; 93 98 Way target = (Way)getMergeTarget(source); 99 100 Collection<Conflict<OsmPrimitive>> localConflicts = new ArrayList<Conflict<OsmPrimitive>>(); 94 101 95 102 List<Node> newNodes = new ArrayList<Node>(source.getNodesCount()); 96 103 for (Node sourceNode : source.getNodes()) { 97 104 Node targetNode = (Node)getMergeTarget(sourceNode); 98 if (!targetNode.isDeleted() || undeletedPrimitives.contains(targetNode)) { 105 // Target node is not deleted or it will be undeleted when running existing commands 106 if (!targetNode.isDeleted() || nominalRevertedPrimitives.contains(targetNode)) { 99 107 newNodes.add(targetNode); 100 } else if (sourceNode.isIncomplete() 101 && !conflicts.hasConflictForMy(targetNode)) { 102 conflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true)); 103 Node undeletedTargetNode = new Node(targetNode); 104 undeletedTargetNode.setDeleted(false); 105 addChangeCommandIfNotEquals(targetNode,undeletedTargetNode); 108 // Target node has been deleted by a more recent changeset -> conflict 109 } else if (sourceNode.isIncomplete() && !conflicts.hasConflictForMy(targetNode)) { 110 localConflicts.add(new Conflict<OsmPrimitive>(targetNode, sourceNode, true)); 111 } else { 112 Main.info("Skipping target node "+targetNode+" for source node "+sourceNode+" while reverting way "+source); 106 113 } 107 114 } … … 109 116 mergePrimitive(source, target, newTarget); 110 117 newTarget.setNodes(newNodes); 111 addChangeCommandIfNotEquals(target,newTarget); 118 if (newNodes.isEmpty()) { 119 Main.error("Unable to revert "+source+" as it produces 0 nodes way "+newTarget); 120 } else { 121 for (Conflict<OsmPrimitive> c : localConflicts) { 122 Main.warn("New conflict: "+c); 123 conflicts.add(c); 124 Node targetNode = (Node)c.getTheir(); 125 Node undeletedTargetNode = new Node(targetNode); 126 undeletedTargetNode.setDeleted(false); 127 addChangeCommandIfNotEquals(targetNode,undeletedTargetNode,false); 128 } 129 addChangeCommandIfNotEquals(target,newTarget,true); 130 } 112 131 } 113 132 … … 137 156 } 138 157 undeletedTargetMember.setDeleted(false); 139 addChangeCommandIfNotEquals(targetMember,undeletedTargetMember );158 addChangeCommandIfNotEquals(targetMember,undeletedTargetMember,false); 140 159 } 141 160 newMembers.add(new RelationMember(sourceMember.getRole(), targetMember)); … … 144 163 mergePrimitive(source, target, newRelation); 145 164 newRelation.setMembers(newMembers); 146 addChangeCommandIfNotEquals(target,newRelation );165 addChangeCommandIfNotEquals(target,newRelation,true); 147 166 } 148 167
Note:
See TracChangeset
for help on using the changeset viewer.