Class SplitWayCommand
- java.lang.Object
-
- org.openstreetmap.josm.command.Command
-
- org.openstreetmap.josm.command.SequenceCommand
-
- org.openstreetmap.josm.command.SplitWayCommand
-
- All Implemented Interfaces:
PseudoCommand
public class SplitWayCommand extends SequenceCommand
Splits a way into multiple ways (all identical except for their node list).Ways are just split at the selected nodes. The nodes remain in their original order. Selected nodes at the end of a way are ignored.
- Since:
- 12828 (
SplitWayActionconverted to aCommand)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSplitWayCommand.Analysis(package private) static classSplitWayCommand.Direction(package private) static classSplitWayCommand.MissingMemberStrategy(package private) static classSplitWayCommand.RelationAnalysisprivate static classSplitWayCommand.RelationInformationstatic interfaceSplitWayCommand.StrategyDetermines which way chunk should reuse the old id and its history(package private) static classSplitWayCommand.WarningTypestatic classSplitWayCommand.WhenRelationOrderUncertainWhat to do when the split way is part of relations, and the order of the new parts in the relation cannot be determined without downloading missing relation members.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.command.Command
Command.OldNodeState
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringDOWNLOAD_MISSING_PREF_KEYprivate java.util.List<? extends PrimitiveId>newSelectionprivate java.util.List<Way>newWaysprivate WayoriginalWayprivate static java.util.Map<java.lang.String,java.lang.String>relationSpecialTypesMap<Restriction type, type to treat it as>private static java.lang.StringRESTRICTIONprivate static java.util.function.Consumer<java.lang.String>warningNotifier-
Fields inherited from class org.openstreetmap.josm.command.SequenceCommand
continueOnError
-
Fields inherited from class org.openstreetmap.josm.command.Command
IS_INCOMPLETE, IS_OK, IS_OUTSIDE
-
-
Constructor Summary
Constructors Constructor Description SplitWayCommand(java.lang.String name, java.util.Collection<Command> commandList, java.util.List<? extends PrimitiveId> newSelection, Way originalWay, java.util.List<Way> newWays)Create a newSplitWayCommand.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddSortedWays(int position, int indexOfWayToKeep, SplitWayCommand.Direction direction, java.util.List<Way> newWays, Relation relation)Add ways in a sorted mannerstatic java.lang.StringaddSpecialRelationType(java.lang.String relationType, java.lang.String treatAs)Add relations that are treated in a specific way.(package private) static SplitWayCommand.AnalysisanalyseSplit(Way way, Way wayToKeep, java.util.List<Way> newWays)static java.util.List<java.util.List<Node>>buildSplitChunks(Way wayToSplit, java.util.List<Node> splitPoints)Splits the nodes ofwayToSplitinto a list of node sequences which are separated at the nodes insplitPoints.static java.util.List<Way>createNewWaysFromChunks(Way way, java.lang.Iterable<java.util.List<Node>> wayChunks)Creates new way objects for the way chunks and transfers the keys from the original way.static java.util.Optional<SplitWayCommand>doSplitWay(Way way, Way wayToKeep, java.util.List<Way> newWays, java.util.List<OsmPrimitive> newSelection, SplitWayCommand.WhenRelationOrderUncertain whenRelationOrderUncertain)Effectively constructs theSplitWayCommand.(package private) static voiddownloadMissingMembers(java.util.Set<OsmPrimitive> incompleteMembers)(package private) static java.util.List<? extends OsmPrimitive>findVias(Relation r, java.lang.String type)java.util.List<? extends PrimitiveId>getNewSelection()Replies the new list of selected primitives idsjava.util.List<Way>getNewWays()Replies the resulting new waysWaygetOriginalWay()Replies the original way being splitstatic java.util.Map<java.lang.String,java.lang.String>getSpecialRelationTypes()Get the types of relations that are treated differentlyprivate static booleanneedToReverseSplit(int position, int indexOfWayToKeep, Relation relation, java.util.List<Way> newWays)This is only strictly necessary when we are splitting a route where it starts to loop back.(package private) static SplitWayCommand.MissingMemberStrategyofferToDownloadMissingMembersIfNeeded(SplitWayCommand.Analysis analysis, int numRelationsNeedingMoreMembers)static voidsetWarningNotifier(java.util.function.Consumer<java.lang.String> notifier)Sets the global warning notifier.static SplitWayCommandsplit(Way way, java.util.List<Node> atNodes, java.util.Collection<? extends OsmPrimitive> selection)Splits the waywayat the nodes inatNodesand replies the result of this process in an instance ofSplitWayCommand.(package private) static SplitWayCommandsplitBasedOnAnalyses(Way way, java.util.List<Way> newWays, java.util.List<OsmPrimitive> newSelection, SplitWayCommand.Analysis analysis, int indexOfWayToKeep)static SplitWayCommandsplitWay(Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection)Splits the waywayinto chunks ofwayChunksand replies the result of this process in an instance ofSplitWayCommand.static SplitWayCommandsplitWay(Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection, SplitWayCommand.Strategy splitStrategy)Splits the waywayinto chunks ofwayChunksand replies the result of this process in an instance ofSplitWayCommand.static java.util.Optional<SplitWayCommand>splitWay(Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection, SplitWayCommand.Strategy splitStrategy, SplitWayCommand.WhenRelationOrderUncertain whenRelationOrderUncertain)Splits the waywayinto chunks ofwayChunksand replies the result of this process in an instance ofSplitWayCommand.private static SplitWayCommand.RelationInformationtreatAsRestriction(Relation r, RelationMember rm, Relation c, java.util.Collection<Way> newWays, Way way, java.util.List<Node> changedWayNodes)-
Methods inherited from class org.openstreetmap.josm.command.SequenceCommand
equals, executeCommand, fillModifiedData, getChildren, getDescriptionIcon, getDescriptionText, getLastCommand, getName, getParticipatingPrimitives, hashCode, setSequence, setSequenceComplete, undoCommand, undoCommands, wrapIfNeeded, wrapIfNeeded
-
Methods inherited from class org.openstreetmap.josm.command.Command
checkOutlyingOrIncompleteOperation, ensurePrimitivesAreInDataset, getAffectedDataSet, getOrig
-
-
-
-
Field Detail
-
warningNotifier
private static volatile java.util.function.Consumer<java.lang.String> warningNotifier
-
DOWNLOAD_MISSING_PREF_KEY
private static final java.lang.String DOWNLOAD_MISSING_PREF_KEY
- See Also:
- Constant Field Values
-
newSelection
private final java.util.List<? extends PrimitiveId> newSelection
-
originalWay
private final Way originalWay
-
RESTRICTION
private static final java.lang.String RESTRICTION
- See Also:
- Constant Field Values
-
relationSpecialTypes
private static final java.util.Map<java.lang.String,java.lang.String> relationSpecialTypes
Map<Restriction type, type to treat it as>
-
-
Constructor Detail
-
SplitWayCommand
public SplitWayCommand(java.lang.String name, java.util.Collection<Command> commandList, java.util.List<? extends PrimitiveId> newSelection, Way originalWay, java.util.List<Way> newWays)
Create a newSplitWayCommand.- Parameters:
name- The description textcommandList- The sequence of commands that should be executed.newSelection- The new list of selected primitives ids (which is saved for later retrieval withgetNewSelection())originalWay- The original way being split (which is saved for later retrieval withgetOriginalWay())newWays- The resulting new ways (which is saved for later retrieval withgetNewWays())
-
-
Method Detail
-
setWarningNotifier
public static void setWarningNotifier(java.util.function.Consumer<java.lang.String> notifier)
Sets the global warning notifier.- Parameters:
notifier- warning notifier in charge of displaying warning message, if any. Must not be null
-
getNewSelection
public java.util.List<? extends PrimitiveId> getNewSelection()
Replies the new list of selected primitives ids- Returns:
- The new list of selected primitives ids
-
getOriginalWay
public Way getOriginalWay()
Replies the original way being split- Returns:
- The original way being split
-
getNewWays
public java.util.List<Way> getNewWays()
Replies the resulting new ways- Returns:
- The resulting new ways
-
buildSplitChunks
public static java.util.List<java.util.List<Node>> buildSplitChunks(Way wayToSplit, java.util.List<Node> splitPoints)
Splits the nodes ofwayToSplitinto a list of node sequences which are separated at the nodes insplitPoints.This method displays warning messages if
wayToSplitand/orsplitPointsaren't consistent.Returns null, if building the split chunks fails.
- Parameters:
wayToSplit- the way to split. Must not be null.splitPoints- the nodes where the way is split. Must not be null.- Returns:
- the list of chunks
-
createNewWaysFromChunks
public static java.util.List<Way> createNewWaysFromChunks(Way way, java.lang.Iterable<java.util.List<Node>> wayChunks)
Creates new way objects for the way chunks and transfers the keys from the original way.- Parameters:
way- the original way whose keys are transferredwayChunks- the way chunks- Returns:
- the new way objects
-
splitWay
public static SplitWayCommand splitWay(Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection)
Splits the waywayinto chunks ofwayChunksand replies the result of this process in an instance ofSplitWayCommand.Note that changes are not applied to the data yet. You have to submit the command first, i.e.
UndoRedoHandler.getInstance().add(result).- Parameters:
way- the way to split. Must not be null.wayChunks- the list of way chunks into the way is split. Must not be null.selection- The list of currently selected primitives- Returns:
- the result from the split operation
-
splitWay
public static SplitWayCommand splitWay(Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection, SplitWayCommand.Strategy splitStrategy)
Splits the waywayinto chunks ofwayChunksand replies the result of this process in an instance ofSplitWayCommand. TheSplitWayCommand.Strategyis used to determine which way chunk should reuse the old id and its history.If the split way is part of relations, and the order of the new parts in these relations cannot be determined due to missing relation members, the user will be asked to consent to downloading these missing members.
Note that changes are not applied to the data yet. You have to submit the command first, i.e.
UndoRedoHandler.getInstance().add(result).- Parameters:
way- the way to split. Must not be null.wayChunks- the list of way chunks into the way is split. Must not be null.selection- The list of currently selected primitivessplitStrategy- The strategy used to determine which way chunk should reuse the old id and its history- Returns:
- the result from the split operation
-
splitWay
public static java.util.Optional<SplitWayCommand> splitWay(Way way, java.util.List<java.util.List<Node>> wayChunks, java.util.Collection<? extends OsmPrimitive> selection, SplitWayCommand.Strategy splitStrategy, SplitWayCommand.WhenRelationOrderUncertain whenRelationOrderUncertain)
Splits the waywayinto chunks ofwayChunksand replies the result of this process in an instance ofSplitWayCommand. TheSplitWayCommand.Strategyis used to determine which way chunk should reuse the old id and its history.Note that changes are not applied to the data yet. You have to submit the command first, i.e.
UndoRedoHandler.getInstance().add(result).- Parameters:
way- the way to split. Must not be null.wayChunks- the list of way chunks into the way is split. Must not be null.selection- The list of currently selected primitivessplitStrategy- The strategy used to determine which way chunk should reuse the old id and its historywhenRelationOrderUncertain- What to do when the split way is part of relations, and the order of the new parts in the relation cannot be determined without downloading missing relation members.- Returns:
- The result from the split operation, may be an empty
Optionalif the operation is aborted.
-
doSplitWay
public static java.util.Optional<SplitWayCommand> doSplitWay(Way way, Way wayToKeep, java.util.List<Way> newWays, java.util.List<OsmPrimitive> newSelection, SplitWayCommand.WhenRelationOrderUncertain whenRelationOrderUncertain)
Effectively constructs theSplitWayCommand. This method is only public forSplitWayAction.- Parameters:
way- the way to split. Must not be null.wayToKeep- way chunk which should reuse the old id and its historynewWays- potential new waysnewSelection- new selection list to update (optional: can be null)whenRelationOrderUncertain- Action to perform when the order of the new parts in relations the way is member of could not be reliably determined. SeeSplitWayCommand.WhenRelationOrderUncertain.- Returns:
- the
SplitWayCommand
-
analyseSplit
static SplitWayCommand.Analysis analyseSplit(Way way, Way wayToKeep, java.util.List<Way> newWays)
-
offerToDownloadMissingMembersIfNeeded
static SplitWayCommand.MissingMemberStrategy offerToDownloadMissingMembersIfNeeded(SplitWayCommand.Analysis analysis, int numRelationsNeedingMoreMembers)
-
downloadMissingMembers
static void downloadMissingMembers(java.util.Set<OsmPrimitive> incompleteMembers) throws OsmTransferException
- Throws:
OsmTransferException
-
splitBasedOnAnalyses
static SplitWayCommand splitBasedOnAnalyses(Way way, java.util.List<Way> newWays, java.util.List<OsmPrimitive> newSelection, SplitWayCommand.Analysis analysis, int indexOfWayToKeep)
-
addSortedWays
private static void addSortedWays(int position, int indexOfWayToKeep, SplitWayCommand.Direction direction, java.util.List<Way> newWays, Relation relation)
Add ways in a sorted manner- Parameters:
position- The position of the relation member we are operating onindexOfWayToKeep- The index of the way that is keeping history if it were innewWaysdirection- The direction of the waysnewWays- The ways that are being added to the relationrelation- The relation we are operating on
-
needToReverseSplit
private static boolean needToReverseSplit(int position, int indexOfWayToKeep, Relation relation, java.util.List<Way> newWays)
This is only strictly necessary when we are splitting a route where it starts to loop back. Example: way1 → way2 → way2 → way1- Parameters:
position- The position of the original way in the relationindexOfWayToKeep- The index of the way to keep in relation tonewWaysrelation- The relation we are working onnewWays- The ways that are being added- Returns:
trueif we need to reverse the direction of the ways
-
treatAsRestriction
private static SplitWayCommand.RelationInformation treatAsRestriction(Relation r, RelationMember rm, Relation c, java.util.Collection<Way> newWays, Way way, java.util.List<Node> changedWayNodes)
-
findVias
static java.util.List<? extends OsmPrimitive> findVias(Relation r, java.lang.String type)
-
split
public static SplitWayCommand split(Way way, java.util.List<Node> atNodes, java.util.Collection<? extends OsmPrimitive> selection)
Splits the waywayat the nodes inatNodesand replies the result of this process in an instance ofSplitWayCommand.Note that changes are not applied to the data yet. You have to submit the command first, i.e.
UndoRedoHandler.getInstance().add(result).Replies null if the way couldn't be split at the given nodes.
- Parameters:
way- the way to split. Must not be null.atNodes- the list of nodes where the way is split. Must not be null.selection- The list of currently selected primitives- Returns:
- the result from the split operation
-
addSpecialRelationType
public static java.lang.String addSpecialRelationType(java.lang.String relationType, java.lang.String treatAs)
Add relations that are treated in a specific way.- Parameters:
relationType- The value in thetypekeytreatAs- The type of relation to treat therelationTypeas. Currently only supports relations that can be handled like "restriction" relations.- Returns:
- the previous value associated with relationType, or null if there was no mapping
- Since:
- 15078
-
getSpecialRelationTypes
public static java.util.Map<java.lang.String,java.lang.String> getSpecialRelationTypes()
Get the types of relations that are treated differently- Returns:
Map<Relation Type, Type of Relation it is to be treated as>- Since:
- 15078
-
-