Changeset 3440 in josm
- Timestamp:
- 2010-08-15T17:31:20+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r3262 r3440 12 12 13 13 import org.openstreetmap.josm.data.osm.Node; 14 import org.openstreetmap.josm.data.osm.NodeData; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 16 import org.openstreetmap.josm.data.osm.PrimitiveData; … … 23 24 } 24 25 26 @SuppressWarnings("null") 25 27 @Override public boolean executeCommand() { 26 28 … … 28 30 29 31 for (PrimitiveData pd:data) { 30 createdPrimitives.add(getLayer().data.getPrimitiveById(pd, true)); 32 OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd); 33 boolean created = primitive == null; 34 if (created) { 35 primitive = pd.getType().newInstance(pd.getUniqueId(), true); 36 } 37 if (pd instanceof NodeData) { // Load nodes immediately because they can't be added to dataset without coordinates 38 primitive.load(pd); 39 } 40 if (created) { 41 getLayer().data.addPrimitive(primitive); 42 } 43 createdPrimitives.add(primitive); 31 44 } 32 45 33 // Load nodes first to prevent ways with null coordinates 34 for (int i=0; i<createdPrimitives.size(); i++) { 35 if (createdPrimitives.get(i) instanceof Node) { 36 createdPrimitives.get(i).load(data.get(i)); 37 } 38 } 39 40 // Now load ways and relations 46 //Then load ways and relations 41 47 for (int i=0; i<createdPrimitives.size(); i++) { 42 48 if (!(createdPrimitives.get(i) instanceof Node)) { … … 57 63 @Override public JLabel getDescription() { 58 64 return new JLabel(trn("Added {0} object", "Added {0} objects", data.size(), data.size()), null, 59 65 JLabel.HORIZONTAL 60 66 ); 61 67 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r3432 r3440 283 283 success = ways.remove((Way) primitive); 284 284 } else if (primitive instanceof Relation) { 285 success = relations.remove( (Relation)primitive);285 success = relations.remove(primitive); 286 286 } 287 287 if (!success) … … 609 609 */ 610 610 public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) { 611 return getPrimitiveById(new SimplePrimitiveId(id, type) , false);611 return getPrimitiveById(new SimplePrimitiveId(id, type)); 612 612 } 613 613 614 614 public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId) { 615 return getPrimitiveById(primitiveId, false); 616 } 617 615 return primitivesMap.get(primitiveId); 616 } 617 618 /** 619 * 620 * @param primitiveId 621 * @param createNew 622 * @return 623 * @deprecated This method can created inconsistent dataset when called for node with id < 0 and createNew=true. That will add 624 * complete node without coordinates to dataset which is not allowed. 625 */ 626 @Deprecated 618 627 public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId, boolean createNew) { 619 628 OsmPrimitive result = primitivesMap.get(primitiveId); … … 734 743 */ 735 744 public boolean isModified() { 736 for (Node n: nodes) { 737 if (n.isModified()) return true; 738 } 739 for (Way w: ways) { 740 if (w.isModified()) return true; 741 } 742 for (Relation r: relations) { 743 if (r.isModified()) return true; 745 for (OsmPrimitive p: allPrimitives) { 746 if (p.isModified()) 747 return true; 744 748 } 745 749 return false; -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
r3083 r3440 72 72 } 73 73 74 public OsmPrimitive newInstance(long uniqueId, boolean allowNegative) { 75 switch (this) { 76 case NODE: 77 return new Node(uniqueId, allowNegative); 78 case WAY: 79 return new Way(uniqueId, allowNegative); 80 case RELATION: 81 return new Relation(uniqueId, allowNegative); 82 default: 83 throw new AssertionError(); 84 } 85 } 86 74 87 @Override 75 88 public String toString() { -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitor.java
r3265 r3440 163 163 // Create all primitives first 164 164 for (PrimitiveData primitive: mappedPrimitives.values()) { 165 hull.getPrimitiveById(primitive, true); 166 } 167 // Then fill nodes with data 168 for (PrimitiveData primitive : mappedPrimitives.values()) { 169 if (primitive instanceof NodeData) { 170 if (!primitive.isIncomplete()) { 171 hull.getPrimitiveById(primitive).load(primitive); 172 } 165 OsmPrimitive newPrimitive = hull.getPrimitiveById(primitive); 166 boolean created = newPrimitive == null; 167 if (created) { 168 newPrimitive = primitive.getType().newInstance(primitive.getUniqueId(), true); 169 } 170 if (newPrimitive instanceof Node && !primitive.isIncomplete()) { 171 newPrimitive.load(primitive); 172 } 173 if (created) { 174 hull.addPrimitive(newPrimitive); 173 175 } 174 176 } 175 177 // Then ways and relations 176 178 for (PrimitiveData primitive : mappedPrimitives.values()) { 177 if (!(primitive instanceof NodeData)) { 178 if (!primitive.isIncomplete()) { 179 hull.getPrimitiveById(primitive).load(primitive); 180 } 179 if (!(primitive instanceof NodeData) && !primitive.isIncomplete()) { 180 hull.getPrimitiveById(primitive).load(primitive); 181 181 } 182 182 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r3384 r3440 1481 1481 toAdd.add(primitiveInDs); 1482 1482 } else if (!primitive.isNew()) { 1483 toAdd.add(ds.getPrimitiveById(primitive, true)); 1483 OsmPrimitive p = primitive.getType().newInstance(primitive.getUniqueId(), true); 1484 ds.addPrimitive(p); 1485 toAdd.add(p); 1484 1486 } else { 1485 1487 hasNewInOtherLayer = true;
Note:
See TracChangeset
for help on using the changeset viewer.