Changeset 2982 in josm
- Timestamp:
- 2010-02-14T15:01:00+01:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/BBox.java
r2500 r2982 67 67 ymax = Math.max(ymax, y); 68 68 sanity(); 69 } 70 71 public void add(BBox box) { 72 add(box.getTopLeft()); 73 add(box.getBottomRight()); 69 74 } 70 75 … … 139 144 140 145 @Override 146 public int hashCode() { 147 return (int)(ymin * xmin); 148 } 149 150 @Override 151 public boolean equals(Object o) { 152 if (o instanceof BBox) { 153 BBox b = (BBox)o; 154 return b.xmax == xmax && b.ymax == ymax && b.xmin == xmin && b.ymin == ymin; 155 } else 156 return false; 157 } 158 159 @Override 141 160 public String toString() { 142 161 return "[ x: " + xmin + " -> " + xmax + -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2944 r2982 136 136 } 137 137 138 public List<Relation> searchRelations(BBox bbox) { 139 // QuadBuckets might be useful here (don't forget to do reindexing after some of rm is changed) 140 List<Relation> result = new ArrayList<Relation>(); 141 for (Relation r: relations) { 142 if (r.getBBox().intersects(bbox)) { 143 result.add(r); 144 } 145 } 146 return result; 147 } 148 138 149 /** 139 150 * All data sources of this DataSet. … … 200 211 * Adds a primitive to the dataset 201 212 * 202 * @param primitive the primitive. Ignored if null.213 * @param primitive the primitive. 203 214 */ 204 215 public void addPrimitive(OsmPrimitive primitive) { … … 779 790 } 780 791 781 /**782 * Reindex all nodes and ways after their coordinates were changed. This is a temporary solution, reindexing should783 * be automatic in the future784 * @deprecated Reindexing should be automatic785 */786 @Deprecated787 public void reindexAll() {788 List<Node> ntmp = new ArrayList<Node>(nodes);789 nodes.clear();790 nodes.addAll(ntmp);791 List<Way> wtmp = new ArrayList<Way>(ways);792 ways.clear();793 ways.addAll(wtmp);794 }795 796 792 private void reindexNode(Node node) { 797 793 nodes.remove(node); 798 794 nodes.add(node); 799 for (Way way:OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) { 800 ways.remove(way); 801 way.updatePosition(); 802 ways.add(way); 795 for (OsmPrimitive primitive: node.getReferrers()) { 796 if (primitive instanceof Way) { 797 reindexWay((Way)primitive); 798 } else { 799 reindexRelation((Relation) primitive); 800 } 803 801 } 804 802 } 805 803 806 804 private void reindexWay(Way way) { 805 BBox before = way.getBBox(); 807 806 ways.remove(way); 808 807 way.updatePosition(); 809 808 ways.add(way); 809 if (!way.getBBox().equals(before)) { 810 for (OsmPrimitive primitive: way.getReferrers()) { 811 reindexRelation((Relation)primitive); 812 } 813 } 814 } 815 816 private void reindexRelation(Relation relation) { 817 BBox before = relation.getBBox(); 818 relation.updatePosition(); 819 if (!before.equals(relation.getBBox())) { 820 for (OsmPrimitive primitive: relation.getReferrers()) { 821 reindexRelation((Relation) primitive); 822 } 823 } 810 824 } 811 825 … … 874 888 875 889 void fireRelationMembersChanged(Relation r) { 890 reindexRelation(r); 876 891 fireEvent(new RelationMembersChangedEvent(this, r)); 877 892 } -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r2970 r2982 23 23 */ 24 24 private final List<RelationMember> members = new ArrayList<RelationMember>(); 25 26 private BBox bbox; 25 27 26 28 /** … … 336 338 @Override 337 339 public BBox getBBox() { 338 return new BBox(0, 0, 0, 0); 340 if (bbox == null) { 341 calculateBBox(new HashSet<PrimitiveId>()); 342 if (bbox == null) { 343 bbox = new BBox(0, 0, 0, 0); // No members 344 } 345 } 346 return bbox; 347 } 348 349 private BBox calculateBBox(Set<PrimitiveId> visitedRelations) { 350 if (visitedRelations.contains(this)) 351 return null; 352 visitedRelations.add(this); 353 if (members.isEmpty()) 354 return null; 355 else { 356 BBox result = null; 357 for (RelationMember rm:members) { 358 BBox box = rm.isRelation()?rm.getRelation().calculateBBox(visitedRelations):rm.getMember().getBBox(); 359 if (box != null) { 360 if (result == null) { 361 result = box; 362 } else { 363 result.add(box); 364 } 365 } 366 } 367 return result; 368 } 339 369 } 340 370 341 371 @Override 342 372 public void updatePosition() { 343 // Do nothing for now373 bbox = calculateBBox(new HashSet<PrimitiveId>()); 344 374 } 345 375 … … 355 385 for (RelationMember rm: members) { 356 386 if (rm.getMember().getDataSet() != dataSet) 357 throw new DataIntegrityProblemException( "Relation member must be part of the same dataset as relation");387 throw new DataIntegrityProblemException(String.format("Relation member must be part of the same dataset as relation(%s, %s)", getPrimitiveId(), rm.getMember().getPrimitiveId())); 358 388 } 359 389 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r2954 r2982 244 244 245 245 public void drawRestriction(Relation r) { 246 246 247 Way fromWay = null; 247 248 Way toWay = null; … … 674 675 675 676 /*** RELATIONS ***/ 676 for (final Relation osm: data. getRelations()) {677 for (final Relation osm: data.searchRelations(bbox)) { 677 678 if (osm.isDrawable()) { 678 679 paintUnselectedRelation(osm); … … 699 700 700 701 /*** RELATIONS ***/ 701 for (final Relation osm: data. getRelations()) {702 for (final Relation osm: data.searchRelations(bbox)) { 702 703 if (osm.isDrawable()) { 703 704 paintUnselectedRelation(osm); -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMerger.java
r2945 r2982 641 641 ImageIcon icon = ImageProvider.get("dialogs/conflict", "useallleft.png"); 642 642 putValue(Action.SMALL_ICON, icon); 643 putValue(Action.SHORT_DESCRIPTION, tr("Use all m ineelements"));643 putValue(Action.SHORT_DESCRIPTION, tr("Use all my elements")); 644 644 } 645 645 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r2907 r2982 397 397 protected PurgePrimitivesCommand buildPurgeCommand() { 398 398 ArrayList<OsmPrimitive> toPurge = new ArrayList<OsmPrimitive>(); 399 conflictLoop: for (Conflict<?> c: conflicts) { 400 if (c.getMy().isDeleted() && !c.getTheir().isVisible()) { 401 // Local and server version of the primitive are deleted. We 402 // can purge it from the local dataset. 403 // 404 toPurge.add(c.getMy()); 405 } else if (!c.getMy().isModified() && ! c.getTheir().isVisible()) { 406 // We purge deleted *ways* and *relations* automatically if they are 407 // deleted on the server and if they aren't modified in the local 408 // dataset. 409 // 410 if (c.getMy() instanceof Way || c.getMy() instanceof Relation) { 399 conflictLoop: 400 for (Conflict<?> c: conflicts) { 401 if (c.getMy().isDeleted() && !c.getTheir().isVisible()) { 402 // Local and server version of the primitive are deleted. We 403 // can purge it from the local dataset. 404 // 411 405 toPurge.add(c.getMy()); 412 continue conflictLoop; 413 } 414 // We only purge nodes if they aren't part of a modified way. 415 // Otherwise the number of nodes of a modified way could drop 416 // below 2 and we would lose the modified data when the way 417 // gets purged. 418 // 419 for (OsmPrimitive parent: c.getMy().getReferrers()) { 420 if (parent.isModified() && parent instanceof Way) { 406 } else if (!c.getMy().isModified() && ! c.getTheir().isVisible()) { 407 // We purge deleted *ways* and *relations* automatically if they are 408 // deleted on the server and if they aren't modified in the local 409 // dataset. 410 // 411 if (c.getMy() instanceof Way || c.getMy() instanceof Relation) { 412 toPurge.add(c.getMy()); 421 413 continue conflictLoop; 422 414 } 415 // We only purge nodes if they aren't part of a modified way. 416 // Otherwise the number of nodes of a modified way could drop 417 // below 2 and we would lose the modified data when the way 418 // gets purged. 419 // 420 for (OsmPrimitive parent: c.getMy().getReferrers()) { 421 if (parent.isModified() && parent instanceof Way) { 422 continue conflictLoop; 423 } 424 } 425 toPurge.add(c.getMy()); 423 426 } 424 toPurge.add(c.getMy()); 425 } 426 } 427 } 427 428 if (toPurge.isEmpty()) return null; 428 429 PurgePrimitivesCommand cmd = new PurgePrimitivesCommand(this, toPurge); -
trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java
r1806 r2982 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static org.junit.Assert.assertFalse; 5 6 import org.junit.Assert; 4 7 import org.junit.Test; 5 6 import static org.junit.Assert.*; 8 import org.openstreetmap.josm.data.coor.LatLon; 7 9 8 10 public class RelationTest { 11 9 12 @Test(expected=NullPointerException.class) 10 13 public void createNewRelation() { … … 18 21 } 19 22 23 @Test 24 public void testBBox() { 25 DataSet ds = new DataSet(); 26 27 Node n1 = new Node(new LatLon(10, 10)); 28 Node n2 = new Node(new LatLon(20, 20)); 29 Node n3 = new Node(new LatLon(30, 30)); 30 Way w1 = new Way(); 31 w1.addNode(n1); 32 w1.addNode(n2); 33 Relation r1 = new Relation(); 34 Relation r2 = new Relation(); 35 ds.addPrimitive(r1); 36 ds.addPrimitive(r2); 37 ds.addPrimitive(n1); 38 ds.addPrimitive(n2); 39 ds.addPrimitive(n3); 40 ds.addPrimitive(w1); 41 r1.addMember(new RelationMember("", n1)); 42 r1.addMember(new RelationMember("", w1)); 43 r1.addMember(new RelationMember("", r1)); 44 r1.addMember(new RelationMember("", r2)); 45 r2.addMember(new RelationMember("", r1)); 46 r2.addMember(new RelationMember("", n3)); 47 48 BBox bbox = new BBox(w1); 49 bbox.add(n3.getBBox()); 50 Assert.assertEquals(bbox, r1.getBBox()); 51 Assert.assertEquals(bbox, r2.getBBox()); 52 53 n3.setCoor(new LatLon(40, 40)); 54 bbox.add(n3.getBBox()); 55 Assert.assertEquals(bbox, r1.getBBox()); 56 Assert.assertEquals(bbox, r2.getBBox()); 57 58 r1.removeMembersFor(r2); 59 Assert.assertEquals(w1.getBBox(), r1.getBBox()); 60 Assert.assertEquals(bbox, r2.getBBox()); 61 62 w1.addNode(n3); 63 Assert.assertEquals(w1.getBBox(), r1.getBBox()); 64 Assert.assertEquals(w1.getBBox(), r2.getBBox()); 65 } 66 20 67 }
Note:
See TracChangeset
for help on using the changeset viewer.