Changeset 34848 in osm for applications/editors/josm/plugins
- Timestamp:
- 2019-01-21T09:26:11+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/pbf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfReader.java
r34826 r34848 29 29 import org.openstreetmap.josm.io.AbstractReader; 30 30 import org.openstreetmap.josm.io.IllegalDataException; 31 import org.openstreetmap.josm.io.ImportCancelException; 31 32 import org.openstreetmap.josm.tools.CheckParameterUtil; 32 33 import org.openstreetmap.josm.tools.Logging; … … 108 109 @Override 109 110 public boolean skipBlock(FileBlockPosition block) { 110 return exception != null ;111 return exception != null || cancel; 111 112 } 112 113 … … 146 147 for (int i = 0; i < nodes.getIdCount(); i++) { 147 148 // Id (delta) and version (normal) 148 NodeData nd = new NodeData(nodeId += nodes.getId(i)); 149 nodeId += nodes.getId(i); 150 NodeData nd = new NodeData(nodeId); 149 151 nd.setVersion(nodes.hasDenseinfo() ? nodes.getDenseinfo().getVersion(i) : 1); 150 152 // Lat/Lon (delta) 151 nd.setCoor(new LatLon(parseLat(nodeLat += nodes.getLat(i)), 152 parseLon(nodeLon += nodes.getLon(i))).getRoundedToOsmPrecision()); 153 nodeLat += nodes.getLat(i); 154 nodeLon += nodes.getLon(i); 155 nd.setCoor(new LatLon(parseLat(nodeLat), parseLon(nodeLon)).getRoundedToOsmPrecision()); 153 156 checkCoordinates(nd.getCoor()); 154 157 if (nodes.hasDenseinfo()) { … … 156 159 // Changeset (delta) 157 160 if (info.getChangesetCount() > i) { 158 checkChangesetId(changesetId += info.getChangeset(i)); 161 changesetId += info.getChangeset(i); 162 checkChangesetId(changesetId); 159 163 nd.setChangesetId((int) changesetId); 160 164 } 161 165 // User (delta) 162 166 if (info.getUidCount() > i && info.getUserSidCount() > i) { 163 nd.setUser(User.createOsmUser(uid += info.getUid(i), 164 getStringById(suid += info.getUserSid(i)))); 167 uid += info.getUid(i); 168 suid += info.getUserSid(i); 169 nd.setUser(User.createOsmUser(uid, getStringById(suid))); 165 170 } 166 171 // Timestamp (delta) 167 172 if (info.getTimestampCount() > i) { 168 checkTimestamp(timestamp += info.getTimestamp(i)); 173 timestamp += info.getTimestamp(i); 174 checkTimestamp(timestamp); 169 175 nd.setTimestamp(new Date(date_granularity * timestamp)); 170 176 } … … 235 241 } 236 242 wd.setKeys(keys); 237 long previousId = 0; // Node ids are delta coded243 long id = 0; // Node ids are delta coded 238 244 Collection<Long> nodeIds = new ArrayList<>(); 239 for (Long id : w.getRefsList()) { 240 nodeIds.add(previousId += id); 245 for (Long idDelta : w.getRefsList()) { 246 id += idDelta; 247 nodeIds.add(id); 241 248 } 242 249 ways.put(wd.getUniqueId(), nodeIds); … … 265 272 } 266 273 rd.setKeys(keys); 267 long previousId = 0; // Member ids are delta coded274 long memId = 0; // Member ids are delta coded 268 275 Collection<RelationMemberData> members = new ArrayList<>(); 269 276 for (int i = 0; i < r.getMemidsCount(); i++) { 277 memId += r.getMemids(i); 270 278 members.add(new RelationMemberData( 271 279 getStringById(r.getRolesSid(i)), 272 280 mapOsmType(r.getTypes(i)), 273 previousId += r.getMemids(i)));281 memId)); 274 282 } 275 283 relations.put(rd.getUniqueId(), members); … … 325 333 protected DataSet doParseDataSet(InputStream source, ProgressMonitor monitor) 326 334 throws IllegalDataException { 335 ProgressMonitor.CancelListener cancelListener = () -> { 336 cancel = true; 337 monitor.indeterminateSubTask(tr("Canceled: Waiting for reader to react")); 338 }; 339 monitor.addCancelListener(cancelListener); 340 327 341 try { 328 monitor.beginTask(tr("Prepare OSM data..." , 2));342 monitor.beginTask(tr("Prepare OSM data..."), 3); 329 343 monitor.indeterminateSubTask(tr("Reading OSM data...")); 330 344 331 345 parse(source); 332 346 monitor.worked(1); 333 347 if (cancel) { 348 throw new ParsingCancelException(tr("Import was canceled")); 349 } 334 350 monitor.indeterminateSubTask(tr("Preparing data set...")); 335 351 prepareDataSet(); 352 if (cancel) { 353 throw new ParsingCancelException(tr("Import was canceled")); 354 } 336 355 monitor.worked(1); 337 356 return getDataSet(); … … 341 360 throw new IllegalDataException(e); 342 361 } finally { 343 monitor. finishTask();362 monitor.removeCancelListener(cancelListener); 344 363 } 345 364 } … … 351 370 } 352 371 } 372 373 /** 374 * Exception thrown after user cancellation. 375 */ 376 private static final class ParsingCancelException extends Exception implements ImportCancelException { 377 private static final long serialVersionUID = 1L; 378 379 ParsingCancelException(String msg) { 380 super(msg); 381 } 382 } 383 353 384 } -
applications/editors/josm/plugins/pbf/src/org/openstreetmap/josm/plugins/pbf/io/PbfServerReader.java
r32859 r34848 28 28 throws OsmTransferException { 29 29 try { 30 progressMonitor.beginTask(tr("Contacting Server..." , 10));30 progressMonitor.beginTask(tr("Contacting Server...")); 31 31 return new PbfImporter().parseDataSet(url); 32 32 } catch (Exception e) { -
applications/editors/josm/plugins/pbf/test/unit/org/openstreetmap/josm/plugins/pbf/io/PbfImporterTest.java
r34826 r34848 80 80 assertEquals(97, ds.getRelations().size()); 81 81 } 82 82 83 83 /** 84 84 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/14545">Ticket #14545</a>. … … 94 94 } 95 95 96 97 96 }
Note:
See TracChangeset
for help on using the changeset viewer.