Ticket #14833: josm_keep_ids.patch
| File josm_keep_ids.patch, 9.0 KB (added by , 9 years ago) |
|---|
-
src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
48 48 49 49 private static final AtomicLong idCounter = new AtomicLong(0); 50 50 51 /** 52 * Generates a new primitive unique id. 53 * @return new primitive unique (negative) id 54 */ 51 55 static long generateUniqueId() { 52 56 return idCounter.decrementAndGet(); 53 57 } 54 58 55 59 /** 60 * Returns the current primitive unique id. 61 * @return the current primitive unique (negative) id (last generated) 62 * @since xxx 63 */ 64 public static long currentUniqueId() { 65 return idCounter.get(); 66 } 67 68 /** 69 * Advances the current primitive unique id to skip a range of values. 70 * @param newId new unique id 71 * @throws IllegalArgumentException if newId is greater than current unique id 72 * @since xxx 73 */ 74 public static void advanceUniqueId(long newId) { 75 if (newId > currentUniqueId()) { 76 throw new IllegalArgumentException("Cannot modify the id counter backwards"); 77 } 78 idCounter.set(newId); 79 } 80 81 /** 56 82 * This flag shows, that the properties have been changed by the user 57 83 * and on upload the object will be send to the server. 58 84 */ -
src/org/openstreetmap/josm/data/osm/DataSet.java
233 233 // and then get the cloned members 234 234 Collection<Relation> relations = copyFrom.getRelations(); 235 235 for (Relation r : relations) { 236 Relation newRelation = new Relation(r , r.isNew());236 Relation newRelation = new Relation(r); 237 237 newRelation.setMembers(null); 238 238 primMap.put(r, newRelation); 239 239 addPrimitive(newRelation); … … 250 250 dataSources.add(new DataSource(source)); 251 251 } 252 252 version = copyFrom.version; 253 uploadPolicy = copyFrom.uploadPolicy; 253 254 } finally { 254 255 copyFrom.getReadLock().unlock(); 255 256 } -
src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
42 42 import org.openstreetmap.josm.data.preferences.Setting; 43 43 import org.openstreetmap.josm.data.preferences.StringSetting; 44 44 import org.openstreetmap.josm.gui.dialogs.LogShowDialog; 45 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 45 46 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; 46 47 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 47 48 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; … … 50 51 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 51 52 import org.openstreetmap.josm.gui.widgets.JosmTextField; 52 53 import org.openstreetmap.josm.tools.GBC; 54 import org.openstreetmap.josm.tools.Territories; 53 55 import org.openstreetmap.josm.tools.Utils; 54 56 55 57 /** … … 322 324 } 323 325 324 326 menu.addSeparator(); 327 menu.add(new AbstractAction(tr("Edit boundaries database")) { 328 @Override 329 public void actionPerformed(ActionEvent ae) { 330 Main.getLayerManager().addLayer( 331 new OsmDataLayer(Territories.getDataSet(), Territories.FILENAME, null)); 332 } 333 }); 334 menu.addSeparator(); 325 335 menu.add(getProfileMenu()); 326 336 menu.addSeparator(); 327 337 menu.add(new AbstractAction(tr("Reset preferences")) { -
src/org/openstreetmap/josm/io/OsmReader.java
11 11 import java.util.Collection; 12 12 import java.util.List; 13 13 import java.util.Objects; 14 import java.util.OptionalLong; 14 15 import java.util.regex.Matcher; 15 16 import java.util.regex.Pattern; 16 17 … … 30 31 import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy; 31 32 import org.openstreetmap.josm.data.osm.Node; 32 33 import org.openstreetmap.josm.data.osm.NodeData; 34 import org.openstreetmap.josm.data.osm.OsmPrimitive; 33 35 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 34 36 import org.openstreetmap.josm.data.osm.PrimitiveData; 35 37 import org.openstreetmap.josm.data.osm.Relation; … … 213 215 jumpToEnd(); 214 216 } 215 217 218 @SuppressWarnings("unchecked") 219 protected <T extends OsmPrimitive> T buildPrimitive(PrimitiveData pd) throws XMLStreamException { 220 readCommon(pd); 221 OsmPrimitive p; 222 if (pd.getUniqueId() < AbstractPrimitive.currentUniqueId()) { 223 p = pd.getType().newInstance(pd.getUniqueId(), true); 224 } else { 225 p = pd.getType().newVersionedInstance(pd.getId(), pd.getVersion()); 226 } 227 p.setVisible(pd.isVisible()); 228 p.load(pd); 229 externalIdMap.put(pd.getPrimitiveId(), p); 230 return (T) p; 231 } 232 216 233 protected Node parseNode() throws XMLStreamException { 217 NodeData nd = new NodeData( );234 NodeData nd = new NodeData(0); 218 235 String lat = parser.getAttributeValue(null, "lat"); 219 236 String lon = parser.getAttributeValue(null, "lon"); 220 237 LatLon ll = null; … … 226 243 Main.trace(e); 227 244 } 228 245 } 229 readCommon(nd);246 Node n = buildPrimitive(nd); 230 247 if (lat != null && lon != null && (ll == null || !ll.isValid())) { 231 248 throwException(tr("Illegal value for attributes ''lat'', ''lon'' on node with ID {0}. Got ''{1}'', ''{2}''.", 232 249 Long.toString(nd.getId()), lat, lon)); 233 250 } 234 Node n = new Node(nd.getId(), nd.getVersion());235 n.setVisible(nd.isVisible());236 n.load(nd);237 externalIdMap.put(nd.getPrimitiveId(), n);238 251 while (true) { 239 252 int event = parser.next(); 240 253 if (event == XMLStreamConstants.START_ELEMENT) { … … 249 262 } 250 263 251 264 protected Way parseWay() throws XMLStreamException { 252 WayData wd = new WayData(); 253 readCommon(wd); 254 Way w = new Way(wd.getId(), wd.getVersion()); 255 w.setVisible(wd.isVisible()); 256 w.load(wd); 257 externalIdMap.put(wd.getPrimitiveId(), w); 258 265 WayData wd = new WayData(0); 266 Way w = buildPrimitive(wd); 259 267 Collection<Long> nodeIds = new ArrayList<>(); 260 268 while (true) { 261 269 int event = parser.next(); … … 299 307 } 300 308 301 309 protected Relation parseRelation() throws XMLStreamException { 302 RelationData rd = new RelationData(); 303 readCommon(rd); 304 Relation r = new Relation(rd.getId(), rd.getVersion()); 305 r.setVisible(rd.isVisible()); 306 r.load(rd); 307 externalIdMap.put(rd.getPrimitiveId(), r); 308 310 RelationData rd = new RelationData(0); 311 Relation r = buildPrimitive(rd); 309 312 Collection<RelationMemberData> members = new ArrayList<>(); 310 313 while (true) { 311 314 int event = parser.next(); … … 647 650 } catch (IOException e) { 648 651 throw new IllegalDataException(e); 649 652 } finally { 653 OptionalLong minId = externalIdMap.values().stream().mapToLong(AbstractPrimitive::getUniqueId).min(); 654 if (minId.isPresent() && minId.getAsLong() < AbstractPrimitive.currentUniqueId()) { 655 AbstractPrimitive.advanceUniqueId(minId.getAsLong()); 656 } 650 657 progressMonitor.finishTask(); 651 658 progressMonitor.removeCancelListener(cancelListener); 652 659 } -
src/org/openstreetmap/josm/tools/Territories.java
27 27 */ 28 28 public final class Territories { 29 29 30 /** Internal OSM filename */ 31 public static final String FILENAME = "boundaries.osm"; 32 30 33 private static final String ISO3166_1 = "ISO3166-1:alpha2"; 31 34 private static final String ISO3166_2 = "ISO3166-2"; 32 35 … … 78 81 */ 79 82 public static synchronized void initialize() { 80 83 iso3166Cache = new HashMap<>(); 81 try (CachedFile cf = new CachedFile("resource://data/ boundaries.osm");84 try (CachedFile cf = new CachedFile("resource://data/" + FILENAME); 82 85 InputStream is = cf.getInputStream()) { 83 86 dataSet = OsmReader.parseDataSet(is, null); 84 87 Collection<OsmPrimitive> candidates = new ArrayList<>(dataSet.getWays());
