- Timestamp:
- 2006-02-21T13:39:40+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r52 r57 1 1 package org.openstreetmap.josm.data.osm.visitor; 2 2 3 import java.util.HashMap; 3 4 import java.util.Iterator; 5 import java.util.LinkedList; 6 import java.util.Map; 4 7 5 8 import org.openstreetmap.josm.data.osm.DataSet; … … 20 23 private final DataSet ds; 21 24 25 /** 26 * A list of all nodes that got replaced with other nodes. 27 * Key is the node in the other's dataset and the value is the one that is now 28 * in ds.nodes instead. 29 */ 30 private final Map<Node, Node> mergedNodes = new HashMap<Node, Node>(); 31 /** 32 * A list of all line segments that got replaced with others. 33 * Key is the segment in the other's dataset and the value is the one that is now 34 * in ds.lineSegments. 35 */ 36 private final Map<LineSegment, LineSegment> mergedLineSegments = new HashMap<LineSegment, LineSegment>(); 37 22 38 public MergeVisitor(DataSet ds) { 23 39 this.ds = ds; … … 39 55 ds.nodes.add(otherNode); 40 56 else { 57 mergedNodes.put(otherNode, myNode); 41 58 mergeCommon(myNode, otherNode); 42 59 if (myNode.modified && !otherNode.modified) … … 64 81 ds.lineSegments.add(otherLs); 65 82 else { 83 mergedLineSegments.put(otherLs, myLs); 66 84 mergeCommon(myLs, otherLs); 67 85 if (myLs.modified && !otherLs.modified) … … 99 117 Iterator<LineSegment> it = otherTrack.segments.iterator(); 100 118 for (LineSegment ls : myTrack.segments) { 101 if (!match(ls, it.next())) {119 if (!match(ls, it.next())) 102 120 same = false; 103 }104 121 } 105 122 if (!same) { … … 113 130 public void visit(Key k) { 114 131 //TODO: Key doesn't really fit the OsmPrimitive concept! 132 } 133 134 /** 135 * Postprocess the dataset and fix all merged references to point to the actual 136 * data. 137 */ 138 public void fixReferences() { 139 for (LineSegment ls : ds.lineSegments) { 140 if (mergedNodes.containsKey(ls.start)) 141 ls.start = mergedNodes.get(ls.start); 142 if (mergedNodes.containsKey(ls.end)) 143 ls.end = mergedNodes.get(ls.end); 144 } 145 for (Track t : ds.tracks) { 146 boolean replacedSomething = false; 147 LinkedList<LineSegment> newSegments = new LinkedList<LineSegment>(); 148 for (LineSegment ls : t.segments) { 149 LineSegment otherLs = mergedLineSegments.get(ls); 150 newSegments.add(otherLs == null ? ls : otherLs); 151 if (otherLs != null) 152 replacedSomething = true; 153 } 154 if (replacedSomething) { 155 t.segments.clear(); 156 t.segments.addAll(newSegments); 157 } 158 for (LineSegment ls : t.segments) { 159 if (mergedNodes.containsKey(ls.start)) 160 ls.start = mergedNodes.get(ls.start); 161 if (mergedNodes.containsKey(ls.end)) 162 ls.end = mergedNodes.get(ls.end); 163 } 164 } 115 165 } 116 166 -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r52 r57 136 136 for (OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) 137 137 osm.visit(visitor); 138 visitor.fixReferences(); 138 139 } 139 140
Note:
See TracChangeset
for help on using the changeset viewer.