Changeset 3703 in josm for trunk/src/org
- Timestamp:
- 2010-12-07T10:00:08+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r3660 r3703 11 11 import javax.swing.JLabel; 12 12 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.data.osm.Node; 14 15 import org.openstreetmap.josm.data.osm.NodeData; … … 17 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 19 20 /** 21 * Add primitives to a data layer. 22 * 23 */ 19 24 public class AddPrimitivesCommand extends Command { 20 25 21 private final List<PrimitiveData> data = new ArrayList<PrimitiveData>(); 26 private List<PrimitiveData> data = new ArrayList<PrimitiveData>(); 27 28 // only filled on undo 29 private List<OsmPrimitive> createdPrimitives = null; 22 30 23 31 public AddPrimitivesCommand(List<PrimitiveData> data) { … … 32 40 @SuppressWarnings("null") 33 41 @Override public boolean executeCommand() { 42 List<OsmPrimitive> newPrimitives; 43 if (createdPrimitives == null) { // first time execution 44 newPrimitives = new ArrayList<OsmPrimitive>(data.size()); 34 45 35 List<OsmPrimitive> createdPrimitives = new ArrayList<OsmPrimitive>(data.size()); 46 for (PrimitiveData pd : data) { 47 OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd); 48 boolean created = primitive == null; 49 if (created) { 50 primitive = pd.getType().newInstance(pd.getUniqueId(), true); 51 } 52 if (pd instanceof NodeData) { // Load nodes immediately because they can't be added to dataset without coordinates 53 primitive.load(pd); 54 } 55 if (created) { 56 getLayer().data.addPrimitive(primitive); 57 } 58 newPrimitives.add(primitive); 59 } 36 60 37 for (PrimitiveData pd:data) {38 OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd);39 boolean created = primitive == null;40 if (created) {41 primitive = pd.getType().newInstance(pd.getUniqueId(), true);61 //Then load ways and relations 62 for (int i=0; i<newPrimitives.size(); i++) { 63 if (!(newPrimitives.get(i) instanceof Node)) { 64 newPrimitives.get(i).load(data.get(i)); 65 } 42 66 } 43 if (pd instanceof NodeData) { // Load nodes immediately because they can't be added to dataset without coordinates 44 primitive.load(pd); 67 } else { // redo 68 // When redoing this command, we have to add the same objects, otherwise 69 // a subsequent command (e.g. MoveCommand) cannot be redone. 70 for (OsmPrimitive osm : createdPrimitives) { 71 getLayer().data.addPrimitive(osm); 45 72 } 46 if (created) { 47 getLayer().data.addPrimitive(primitive); 48 } 49 createdPrimitives.add(primitive); 73 newPrimitives = createdPrimitives; 50 74 } 51 75 52 //Then load ways and relations 53 for (int i=0; i<createdPrimitives.size(); i++) { 54 if (!(createdPrimitives.get(i) instanceof Node)) { 55 createdPrimitives.get(i).load(data.get(i)); 56 } 57 } 58 59 getLayer().data.setSelected(createdPrimitives); 76 getLayer().data.setSelected(newPrimitives); 60 77 return true; 61 78 } 62 79 63 80 @Override public void undoCommand() { 64 for (PrimitiveData p:data) { 65 getLayer().data.removePrimitive(p); 81 DataSet ds = getLayer().data; 82 83 if (createdPrimitives == null) { 84 createdPrimitives = new ArrayList<OsmPrimitive>(data.size()); 85 86 for (PrimitiveData p : data) { 87 createdPrimitives.add(ds.getPrimitiveById(p)); 88 } 89 createdPrimitives = PurgeCommand.topoSort(createdPrimitives); 90 91 for (PrimitiveData p : data) { 92 ds.removePrimitive(p); 93 } 94 data = null; 95 96 } else { 97 for (OsmPrimitive osm : createdPrimitives) { 98 ds.removePrimitive(osm); 99 } 66 100 } 67 101 } 68 102 69 103 @Override public JLabel getDescription() { 70 return new JLabel(trn("Added {0} object", "Added {0} objects", data.size(), data.size()), null, 104 int size = data != null ? data.size() : createdPrimitives.size(); 105 return new JLabel(trn("Added {0} object", "Added {0} objects", size, size), null, 71 106 JLabel.HORIZONTAL 72 107 ); … … 81 116 @Override 82 117 public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 118 if (createdPrimitives != null) 119 return createdPrimitives; 120 83 121 Collection<OsmPrimitive> prims = new HashSet<OsmPrimitive>(); 84 122 for (PrimitiveData d : data) { -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
r3699 r3703 100 100 if ("turning_circle".equals(en.get("highway")) 101 101 || "bus_stop".equals(en.get("highway")) 102 || "buffer_stop".equals(en.get("railway")) 102 103 || OsmUtils.isTrue(en.get("noexit")) 103 104 || en.hasKey("barrier")) {
Note:
See TracChangeset
for help on using the changeset viewer.