- Timestamp:
- 2015-10-27T18:31:03+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r8931 r8955 942 942 943 943 if (chunks.size() > 1) { 944 SplitWayResult split = SplitWayAction.splitWay(getEditLayer(), way, chunks, Collections.<OsmPrimitive>emptyList()); 944 SplitWayResult split = SplitWayAction.splitWay(getEditLayer(), way, chunks, 945 Collections.<OsmPrimitive>emptyList(), SplitWayAction.Strategy.keepFirstChunk()); 945 946 946 947 //execute the command, we need the results -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r8931 r8955 197 197 198 198 final List<Way> newWays = createNewWaysFromChunks(selectedWay, wayChunks); 199 final Way wayToKeep = determineWayToKeep(newWays);199 final Way wayToKeep = Strategy.keepLongestChunk().determineWayToKeep(newWays); 200 200 201 201 if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) { … … 297 297 298 298 /** 299 * Determines which way chunk should reuse the old id and its history. Selects the one with the highest node count. 300 * @param wayChunks the way chunks 301 * @return the way to keep 302 */ 303 protected static Way determineWayToKeep(Iterable<Way> wayChunks) { 304 Way wayToKeep = null; 305 for (Way i : wayChunks) { 306 if (wayToKeep == null || i.getNodesCount() > wayToKeep.getNodesCount()) { 307 wayToKeep = i; 308 } 309 } 310 return wayToKeep; 311 } 299 * Determines which way chunk should reuse the old id and its history 300 * 301 * @since 8954 302 */ 303 public static abstract class Strategy { 304 305 /** 306 * Determines which way chunk should reuse the old id and its history. 307 * 308 * @param wayChunks the way chunks 309 * @return the way to keep 310 */ 311 public abstract Way determineWayToKeep(Iterable<Way> wayChunks); 312 313 /** 314 * Returns a strategy which selects the way chunk with the highest node count to keep. 315 */ 316 public static Strategy keepLongestChunk() { 317 return new Strategy() { 318 @Override 319 public Way determineWayToKeep(Iterable<Way> wayChunks) { 320 Way wayToKeep = null; 321 for (Way i : wayChunks) { 322 if (wayToKeep == null || i.getNodesCount() > wayToKeep.getNodesCount()) { 323 wayToKeep = i; 324 } 325 } 326 return wayToKeep; 327 } 328 }; 329 } 330 331 /** 332 * Returns a strategy which selects the first way chunk. 333 */ 334 public static Strategy keepFirstChunk() { 335 return new Strategy() { 336 @Override 337 public Way determineWayToKeep(Iterable<Way> wayChunks) { 338 return wayChunks.iterator().next(); 339 } 340 }; 341 } 342 } 343 312 344 313 345 /** … … 483 515 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, 484 516 Collection<? extends OsmPrimitive> selection) { 517 return splitWay(layer, way, wayChunks, selection, Strategy.keepLongestChunk()); 518 } 519 520 /** 521 * Splits the way {@code way} into chunks of {@code wayChunks} and replies 522 * the result of this process in an instance of {@link SplitWayResult}. 523 * The {@link org.openstreetmap.josm.actions.SplitWayAction.Strategy} is used to determine which 524 * way chunk should reuse the old id and its history. 525 * 526 * Note that changes are not applied to the data yet. You have to 527 * submit the command in {@link SplitWayResult#getCommand()} first, 528 * i.e. {@code Main.main.undoredo.add(result.getCommand())}. 529 * 530 * @param layer the layer which the way belongs to. Must not be null. 531 * @param way the way to split. Must not be null. 532 * @param wayChunks the list of way chunks into the way is split. Must not be null. 533 * @param selection The list of currently selected primitives 534 * @param splitStrategy The strategy used to determine which way chunk should reuse the old id and its history 535 * @return the result from the split operation 536 * @since 8954 537 */ 538 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, 539 Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) { 485 540 // build a list of commands, and also a new selection list 486 541 final List<OsmPrimitive> newSelection = new ArrayList<>(selection.size() + wayChunks.size()); … … 491 546 492 547 // Determine which part reuses the existing way 493 final Way wayToKeep = determineWayToKeep(newWays);548 final Way wayToKeep = splitStrategy.determineWayToKeep(newWays); 494 549 495 550 return doSplitWay(layer, way, wayToKeep, newWays, newSelection);
Note:
See TracChangeset
for help on using the changeset viewer.