Changeset 369 in josm
- Timestamp:
- 2007-10-12T15:35:51+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r343 r369 77 77 o.add(osm); 78 78 return o; 79 } 80 81 public void addPrimitive(OsmPrimitive osm) { 82 if (osm instanceof Node) { 83 nodes.add((Node) osm); 84 } else if (osm instanceof Way) { 85 ways.add((Way) osm); 86 } else if (osm instanceof Relation) { 87 relations.add((Relation) osm); 88 } 79 89 } 80 90 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r367 r369 235 235 timestamp = osm.timestamp; 236 236 tagged = osm.tagged; 237 incomplete = osm.incomplete; 237 238 } 238 239 … … 244 245 public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) { 245 246 return 246 id == osm.id && 247 id == osm.id && 248 incomplete == osm.incomplete && 247 249 (semanticOnly || (modified == osm.modified)) && 248 250 deleted == osm.deleted && -
trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java
r343 r369 33 33 } 34 34 35 @Override public String toString() { 36 return '"' + role + "\"=" + member; 37 } 35 38 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r366 r369 26 26 /** 27 27 * Map from primitives in the database to visited primitives. (Attention: The other way 28 * round than merged Prims)28 * round than merged) 29 29 */ 30 30 public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>(); … … 38 38 * in ds.nodes instead. 39 39 */ 40 private final Map<OsmPrimitive, OsmPrimitive> merged Prims40 private final Map<OsmPrimitive, OsmPrimitive> merged 41 41 = new HashMap<OsmPrimitive, OsmPrimitive>(); 42 42 … … 51 51 */ 52 52 public void visit(Node other) { 53 if (mergeAfterId( mergedPrims,ds.nodes, other))53 if (mergeAfterId(ds.nodes, other)) 54 54 return; 55 55 … … 64 64 ds.nodes.add(other); 65 65 else { 66 merged Prims.put(other, my);66 merged.put(other, my); 67 67 mergeCommon(my, other); 68 68 if (my.modified && !other.modified) … … 77 77 78 78 private <T extends OsmPrimitive> void cloneFromExceptIncomplete(T myOsm, T otherOsm) { 79 if (!otherOsm.incomplete) { 79 if (myOsm instanceof Way) { 80 Way my = (Way)myOsm; 81 Way other = (Way)otherOsm; 82 HashMap<Long, Node> copy = new HashMap<Long, Node>(); 83 for (Node n : my.nodes) 84 copy.put(n.id, n); 85 my.cloneFrom(other); 86 my.nodes.clear(); 87 for (Node n : other.nodes) { 88 Node myN = copy.get(n.id); 89 if (n.incomplete && myN != null && !myN.incomplete) { 90 merged.put(n, myN); 91 my.nodes.add(myN); 92 } else 93 my.nodes.add(n); 94 } 95 } else if (myOsm instanceof Relation) { 96 Relation my = (Relation)myOsm; 97 Relation other = (Relation)otherOsm; 98 99 HashMap<Long, OsmPrimitive>[] copy = 100 (HashMap<Long, OsmPrimitive>[]) new HashMap[3]; 101 for (int i = 0; i < 3; i++) copy[i] = new HashMap<Long, OsmPrimitive>(); 102 103 for (RelationMember m : my.members) { 104 int i; 105 if (m.member instanceof Node) i = 0; else 106 if (m.member instanceof Way) i = 1; else 107 if (m.member instanceof Relation) i = 2; else i = 3; 108 copy[i].put(m.member.id, m.member); 109 } 110 111 my.cloneFrom(other); 112 my.members.clear(); 113 for (RelationMember m : other.members) { 114 int i; 115 if (m.member instanceof Node) i = 0; else 116 if (m.member instanceof Way) i = 1; else 117 if (m.member instanceof Relation) i = 2; else i = 3; 118 OsmPrimitive myP = copy[i].get(m.member.id); 119 if (m.member.incomplete && myP != null && !myP.incomplete) { 120 RelationMember mnew = new RelationMember(m); 121 mnew.member = myP; 122 my.members.add(mnew); 123 merged.put(m.member, mnew.member); 124 } else { 125 my.members.add(m); 126 } 127 } 128 } else { 80 129 myOsm.cloneFrom(otherOsm); 81 130 } … … 87 136 */ 88 137 public void visit(Way other) { 89 if (mergeAfterId(mergedPrims, ds.ways, other)) 138 fixWay(other); 139 if (mergeAfterId(ds.ways, other)) 90 140 return; 91 141 … … 99 149 if (my == null) { 100 150 ds.ways.add(other); 151 } else if (my.incomplete && !other.incomplete) { 152 merged.put(other, my); 153 my.cloneFrom(other); 154 } else if (other.incomplete && !my.incomplete) { 155 merged.put(other, my); 101 156 } else { 102 merged Prims.put(other, my);157 merged.put(other, my); 103 158 mergeCommon(my, other); 104 159 if (my.modified && !other.modified) … … 123 178 */ 124 179 public void visit(Relation other) { 125 if (mergeAfterId(null, ds.relations, other)) 180 fixRelation(other); 181 if (mergeAfterId(ds.relations, other)) 126 182 return; 127 183 … … 133 189 } 134 190 } 135 191 136 192 if (my == null) { 137 193 // Add the relation and replace any incomplete segments that we already have 138 194 ds.relations.add(other); 139 // FIXME unclear! 140 /* 141 for (RelationMember em : other.getMembers()) { 195 /*for (RelationMember em : other.members) { 142 196 if (em.member.incomplete) { 143 for (Segment ourSegment : ds.segments) { 144 if (ourSegment.id == s.id) { 145 mergedSegments.put(s, ourSegment); 146 break; 197 if (em.member instanceof Node) { 198 for (Node ourN : ds.nodes) { 199 if (ourN.id == em.member.id) { 200 merged.put(em.member, ourN); 201 break; 202 } 203 } 204 } else if (em.member instanceof Way) { 205 for (Way ourW : ds.ways) { 206 if (ourW.id == em.member.id) { 207 merged.put(em.member, ourW); 208 break; 209 } 210 } 211 } else if (em.member instanceof Relation) { 212 for (Relation ourR : ds.relations) { 213 if (ourR.id == em.member.id) { 214 merged.put(em.member, ourR); 215 break; 216 } 147 217 } 148 218 } … … 150 220 }*/ 151 221 } else { 152 merged Prims.put(other, my);222 merged.put(other, my); 153 223 mergeCommon(my, other); 154 224 if (my.modified && !other.modified) … … 165 235 } 166 236 } 167 // FIXME Unclear168 /*169 237 if (!same) { 170 HashMap<Long, Segment> copy = new HashMap<Long, Segment>(); 171 for (Segment s : my.segments) 172 copy.put(s.id, s); 173 my.segments.clear(); 174 for (Segment s : other.segments) { 175 Segment myS = copy.get(s.id); 176 if (s.incomplete && myS != null && !myS.incomplete) { 177 mergedSegments.put(s, myS); 178 my.segments.add(myS); 179 } else 180 my.segments.add(s); 181 } 238 /*HashMap<Long, OsmPrimitive>[] copy = 239 (HashMap<Long, OsmPrimitive>[]) new HashMap[3]; 240 for (int i = 0; i < 3; i++) copy[i] = new HashMap<Long, OsmPrimitive>(); 241 242 for (RelationMember m : my.members) { 243 int i; 244 if (m.member instanceof Node) i = 0; else 245 if (m.member instanceof Way) i = 1; else 246 if (m.member instanceof Relation) i = 2; else i = 3; 247 copy[i].put(m.member.id, m.member); 248 } 249 250 my.cloneFrom(other); 251 my.members.clear(); 252 for (RelationMember m : other.members) { 253 int i; 254 if (m.member instanceof Node) i = 0; else 255 if (m.member instanceof Way) i = 1; else 256 if (m.member instanceof Relation) i = 2; else i = 3; 257 OsmPrimitive myP = copy[i].get(m.member.id); 258 if (m.member.incomplete && myP != null && !myP.incomplete) { 259 RelationMember mnew = new RelationMember(m); 260 mnew.member = myP; 261 my.members.add(mnew); 262 merged.put(m.member, mnew.member); 263 } else { 264 my.members.add(m); 265 } 266 }*/ 182 267 my.modified = other.modified; 183 268 } 184 */185 269 } 186 270 } … … 204 288 LinkedList<Node> newNodes = new LinkedList<Node>(); 205 289 for (Node n : w.nodes) { 206 Node otherN = (Node) merged Prims.get(n);290 Node otherN = (Node) merged.get(n); 207 291 newNodes.add(otherN == null ? n : otherN); 208 292 if (otherN != null) … … 219 303 LinkedList<RelationMember> newMembers = new LinkedList<RelationMember>(); 220 304 for (RelationMember m : r.members) { 221 OsmPrimitive otherP = merged Prims.get(m.member);305 OsmPrimitive otherP = merged.get(m.member); 222 306 if (otherP == null) { 223 307 newMembers.add(m); … … 308 392 * @return <code>true</code>, if no merge is needed or merge is performed already. 309 393 */ 310 private <P extends OsmPrimitive> boolean mergeAfterId( Map<OsmPrimitive,OsmPrimitive> merged,Collection<P> primitives, P other) {394 private <P extends OsmPrimitive> boolean mergeAfterId(Collection<P> primitives, P other) { 311 395 for (P my : primitives) { 312 396 Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp(); 313 397 Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp(); 314 398 if (my.realEqual(other, false)) { 315 if (merged != null) 316 merged.put(other, my); 399 merged.put(other, my); 317 400 return true; // no merge needed. 318 401 } 319 402 if (my.realEqual(other, true)) { 320 403 // they differ in modified/timestamp combination only. Auto-resolve it. 321 if (merged != null) 322 merged.put(other, my); 404 merged.put(other, my); 323 405 if (myd.before(otherd)) { 324 406 my.modified = other.modified; … … 328 410 } 329 411 if (my.id == other.id && my.id != 0) { 330 if (my.incomplete) { 331 return false; 412 if (my.incomplete || other.incomplete) { 413 if (my.incomplete) { 414 my.cloneFrom(other); 415 } 416 merged.put(other, my); 332 417 } else if (my.modified && other.modified) { 333 418 conflicts.put(my, other); 419 merged.put(other, my); 334 420 } else if (!my.modified && !other.modified) { 335 421 if (myd.before(otherd)) { 336 422 cloneFromExceptIncomplete(my, other); 423 merged.put(other, my); 337 424 } 338 425 } else if (other.modified) { 339 426 if (myd.after(otherd)) { 340 427 conflicts.put(my, other); 428 merged.put(other, my); 341 429 } else { 342 430 cloneFromExceptIncomplete(my, other); 431 merged.put(other, my); 343 432 } 344 433 } else if (my.modified) { 345 434 if (myd.before(otherd)) { 346 435 conflicts.put(my, other); 347 } 348 } 349 if (merged != null) 350 merged.put(other, my); 436 merged.put(other, my); 437 } 438 } 351 439 return true; 352 440 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r348 r369 174 174 osm.visit(visitor); 175 175 visitor.fixReferences(); 176 177 for (Way w : data.ways) { 178 System.out.println("way after merge: " + w.incomplete + " " + w); 179 } 176 180 177 181 // copy the merged layer's data source info
Note:
See TracChangeset
for help on using the changeset viewer.