Changeset 2978 in josm
- Timestamp:
- 2010-02-14T12:00:24+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitor.java
r2845 r2978 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.osm.visitor; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.util.ArrayList; … … 11 9 import org.openstreetmap.josm.data.osm.Node; 12 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.data.osm.PrimitiveData; 13 12 import org.openstreetmap.josm.data.osm.Relation; 13 import org.openstreetmap.josm.data.osm.RelationData; 14 14 import org.openstreetmap.josm.data.osm.RelationMember; 15 import org.openstreetmap.josm.data.osm.RelationMemberData; 15 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.data.osm.WayData; 16 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 17 19 … … 30 32 private DataSet selectionBase; 31 33 private DataSet hull; 32 private HashMap<OsmPrimitive, OsmPrimitive> mappedPrimitives;34 private HashMap<OsmPrimitive, PrimitiveData> mappedPrimitives; 33 35 34 36 /** … … 45 47 this.selectionBase = selectionBase; 46 48 this.hull = new DataSet(); 47 this.mappedPrimitives = new HashMap<OsmPrimitive, OsmPrimitive>();49 this.mappedPrimitives = new HashMap<OsmPrimitive, PrimitiveData>(); 48 50 } 49 51 … … 64 66 if (isAlreadyRemembered(n)) 65 67 return; 66 Node clone = new Node(n); 67 mappedPrimitives.put(n, clone); 68 mappedPrimitives.put(n, n.save()); 68 69 } 69 70 … … 76 77 if (isAlreadyRemembered(w)) 77 78 return; 78 Way clone = new Way(w);79 List< Node> newNodes = new ArrayList<Node>(w.getNodesCount());79 WayData clone = w.save(); 80 List<Long> newNodes = new ArrayList<Long>(w.getNodesCount()); 80 81 for (Node n: w.getNodes()) { 81 newNodes.add( (Node)mappedPrimitives.get(n));82 newNodes.add(mappedPrimitives.get(n).getUniqueId()); 82 83 } 83 84 clone.setNodes(newNodes); … … 91 92 */ 92 93 protected void rememberRelation(Relation r) { 93 Relation clone;94 RelationData clone; 94 95 if (isAlreadyRemembered(r)) { 95 clone = (Relation)mappedPrimitives.get(r); 96 clone.cloneFrom(r); 96 clone = (RelationData)mappedPrimitives.get(r); 97 97 } else { 98 clone = new Relation(r); 98 clone = r.save(); 99 mappedPrimitives.put(r, clone); 99 100 } 100 101 101 List<RelationMember > newMembers = new ArrayList<RelationMember>();102 List<RelationMemberData> newMembers = new ArrayList<RelationMemberData>(); 102 103 for (RelationMember member: r.getMembers()) { 103 104 newMembers.add( 104 new RelationMember (member.getRole(), mappedPrimitives.get(member.getMember())));105 new RelationMemberData(member.getRole(), mappedPrimitives.get(member.getMember()))); 105 106 106 107 } 107 108 clone.setMembers(newMembers); 108 109 if (!isAlreadyRemembered(r)) {110 mappedPrimitives.put(r, clone);111 }112 109 } 113 110 … … 115 112 if (isAlreadyRemembered(r)) 116 113 return; 117 Relation clone = new Relation(r);118 clone. setMembers(null);114 RelationData clone = r.save(); 115 clone.getMembers().clear(); 119 116 mappedPrimitives.put(r, clone); 120 117 } … … 123 120 if (isAlreadyRemembered(primitive)) 124 121 return; 125 OsmPrimitive clone = null; 126 if (primitive instanceof Node) { 127 clone = new Node(primitive.getId()); 128 } else if (primitive instanceof Way) { 129 clone = new Way(primitive.getId()); 130 } else if (primitive instanceof Relation) { 131 clone = new Relation(primitive.getId()); 132 } 122 PrimitiveData clone = primitive.save(); 123 clone.setIncomplete(true); 133 124 mappedPrimitives.put(primitive, clone); 134 }135 136 protected void rememberNodeIncomplete(Node n) {137 if (!isAlreadyRemembered(n)) {138 mappedPrimitives.put(n, new Node(n.getId()));139 }140 }141 142 protected void rememberWayIncomplete(Way w) {143 if (!isAlreadyRemembered(w)) {144 mappedPrimitives.put(w, new Way(w.getId()));145 }146 }147 148 protected void rememberRelationIncomplete(Relation r) {149 if (!isAlreadyRemembered(r)) {150 mappedPrimitives.put(r, new Relation(r.getId()));151 }152 125 } 153 126 … … 177 150 continue; 178 151 } 179 if (member.isNode()) { 180 Node node = member.getNode(); 181 if (isInSelectionBase(node)) { 182 rememberNode(node); 183 } else if (node.isNew()) { 184 rememberNode(node); 185 } else { 186 rememberNodeIncomplete(node); 187 } 188 } else if (member.isWay()) { 189 Way way = member.getWay(); 190 if (isInSelectionBase(way)) { 191 way.visit(this); 192 } else if (way.isNew()) { 193 way.visit(this); 194 } else { 195 rememberWayIncomplete(way); 196 } 197 } else if (member.isRelation()) { 198 Relation relation = member.getRelation(); 199 if (isInSelectionBase(member.getMember())) { 200 relation.visit(this); 201 } else if (relation.isNew()) { 202 relation.visit(this); 203 } else { 204 rememberRelationIncomplete(relation); 205 } 152 if (isInSelectionBase(member.getMember()) || member.getMember().isNew()) { 153 member.getMember().visit(this); 154 } else { 155 rememberIncomplete(member.getMember()); 206 156 } 207 157 } … … 210 160 211 161 protected void buildHull() { 212 for (OsmPrimitive primitive : mappedPrimitives.keySet()) { 213 OsmPrimitive clone = mappedPrimitives.get(primitive); 214 hull.addPrimitive(clone); 162 // Create all primitives first 163 for (PrimitiveData primitive: mappedPrimitives.values()) { 164 hull.getPrimitiveById(primitive, true); 165 } 166 // Then fill them with data 167 for (PrimitiveData primitive : mappedPrimitives.values()) { 168 if (!primitive.isIncomplete()) { 169 hull.getPrimitiveById(primitive).load(primitive); 170 } 215 171 } 216 172 }
Note:
See TracChangeset
for help on using the changeset viewer.