Changeset 15397 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-10-01T00:26:14+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/relation/ExportRelationToGpxAction.java
r15121 r15397 166 166 .findFirst() 167 167 .ifPresent(r -> { 168 trkAttr.put("name", r.getName() != null ? r.getName() : r.getId());168 trkAttr.put("name", r.getName() != null ? r.getName() : Long.toString(r.getId())); 169 169 trkAttr.put("desc", tr("based on osm route relation data, timestamps are synthetic")); 170 170 }); 171 GpxData.ensureUniqueName(trkAttr, names );171 GpxData.ensureUniqueName(trkAttr, names, (String) trkAttr.get("name")); 172 172 } 173 173 List<Node> ln = flat.get(i).getWay().getNodes(); -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r15121 r15397 438 438 * @param attrs attributes of/for an gpx track, written to if the name appeared previously in {@code counts}. 439 439 * @param counts a {@code HashMap} of previously seen names, associated with their count. 440 * @param srcLayerName Source layer name 440 441 * @return the unique name for the gpx track. 441 442 * 442 * @since 1 3210443 */ 444 public static String ensureUniqueName(Map<String, Object> attrs, Map<String, Integer> counts ) {445 String name = attrs.getOrDefault("name", "GPX split result").toString();443 * @since 15397 444 */ 445 public static String ensureUniqueName(Map<String, Object> attrs, Map<String, Integer> counts, String srcLayerName) { 446 String name = attrs.getOrDefault("name", srcLayerName).toString().replaceFirst(" #\\d+$", ""); 446 447 Integer count = counts.getOrDefault(name, 0) + 1; 447 448 counts.put(name, count); 448 449 449 attrs.put("name", MessageFormat.format("{0}{1}", name, (count > 1) ? " #"+count : ""));450 attrs.put("name", MessageFormat.format("{0}{1}", name, " #" + count)); 450 451 return attrs.get("name").toString(); 451 452 } … … 455 456 * Each segment will make up one individual track after this operation. 456 457 * 457 * @since 13210 458 */ 459 public synchronized void splitTrackSegmentsToTracks() { 458 * @param srcLayerName Source layer name 459 * 460 * @since 15397 461 */ 462 public synchronized void splitTrackSegmentsToTracks(String srcLayerName) { 460 463 final HashMap<String, Integer> counts = new HashMap<>(); 461 464 … … 463 466 .flatMap(trk -> trk.getSegments().stream().map(seg -> { 464 467 HashMap<String, Object> attrs = new HashMap<>(trk.getAttributes()); 465 ensureUniqueName(attrs, counts );468 ensureUniqueName(attrs, counts, srcLayerName); 466 469 return new ImmutableGpxTrack(Arrays.asList(seg), attrs); 467 470 })) … … 479 482 * is untouched as to preserve potential route or wpt parts. 480 483 * 481 * @since 13210 482 */ 483 public synchronized void splitTracksToLayers() { 484 * @param srcLayerName Source layer name 485 * 486 * @since 15397 487 */ 488 public synchronized void splitTracksToLayers(String srcLayerName) { 484 489 final HashMap<String, Integer> counts = new HashMap<>(); 485 490 … … 490 495 GpxData d = new GpxData(); 491 496 d.addTrack(trk); 492 return new GpxLayer(d, ensureUniqueName(attrs, counts ));497 return new GpxLayer(d, ensureUniqueName(attrs, counts, srcLayerName)); 493 498 }) 494 499 .forEachOrdered(layer -> MainApplication.getLayerManager().addLayer(layer)); … … 707 712 * so we just ingore points from future and from year before 1970 in this method 708 713 * works correctly @since 5815 709 714 * @return minimum and maximum dates in array of 2 elements 710 715 */ 711 716 public synchronized Date[] getMinMaxTimeForAllTracks() { -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r15371 r15397 427 427 @Override 428 428 public void actionPerformed(ActionEvent e) { 429 layer.data.splitTrackSegmentsToTracks( );429 layer.data.splitTrackSegmentsToTracks(!layer.getName().isEmpty() ? layer.getName() : "GPX split result"); 430 430 layer.invalidate(); 431 431 } … … 460 460 @Override 461 461 public void actionPerformed(ActionEvent e) { 462 layer.data.splitTracksToLayers( );462 layer.data.splitTracksToLayers(!layer.getName().isEmpty() ? layer.getName() : "GPX split result"); 463 463 // layer is not modified by this action 464 464 }
Note:
See TracChangeset
for help on using the changeset viewer.