Class 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 (SplitWayAction converted to a Command)
    • 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 new SplitWayCommand.
        Parameters:
        name - The description text
        commandList - The sequence of commands that should be executed.
        newSelection - The new list of selected primitives ids (which is saved for later retrieval with getNewSelection())
        originalWay - The original way being split (which is saved for later retrieval with getOriginalWay())
        newWays - The resulting new ways (which is saved for later retrieval with getNewWays())
    • 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 PrimitiveIdgetNewSelection()
        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<WaygetNewWays()
        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 of wayToSplit into a list of node sequences which are separated at the nodes in splitPoints.

        This method displays warning messages if wayToSplit and/or splitPoints aren'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<WaycreateNewWaysFromChunks​(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 transferred
        wayChunks - 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 way way into chunks of wayChunks and replies the result of this process in an instance of SplitWayCommand.

        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 way way into chunks of wayChunks and replies the result of this process in an instance of SplitWayCommand. The SplitWayCommand.Strategy is 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 primitives
        splitStrategy - 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<SplitWayCommandsplitWay​(Way way,
                                                                   java.util.List<java.util.List<Node>> wayChunks,
                                                                   java.util.Collection<? extends OsmPrimitive> selection,
                                                                   SplitWayCommand.Strategy splitStrategy,
                                                                   SplitWayCommand.WhenRelationOrderUncertain whenRelationOrderUncertain)
        Splits the way way into chunks of wayChunks and replies the result of this process in an instance of SplitWayCommand. The SplitWayCommand.Strategy is 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 primitives
        splitStrategy - The strategy used to determine which way chunk should reuse the old id and its history
        whenRelationOrderUncertain - 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 Optional if the operation is aborted.
      • doSplitWay

        public static java.util.Optional<SplitWayCommanddoSplitWay​(Way way,
                                                                     Way wayToKeep,
                                                                     java.util.List<Way> newWays,
                                                                     java.util.List<OsmPrimitive> newSelection,
                                                                     SplitWayCommand.WhenRelationOrderUncertain whenRelationOrderUncertain)
        Effectively constructs the SplitWayCommand. This method is only public for SplitWayAction.
        Parameters:
        way - the way to split. Must not be null.
        wayToKeep - way chunk which should reuse the old id and its history
        newWays - potential new ways
        newSelection - 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. See SplitWayCommand.WhenRelationOrderUncertain.
        Returns:
        the SplitWayCommand
      • 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 on
        indexOfWayToKeep - The index of the way that is keeping history if it were in newWays
        direction - The direction of the ways
        newWays - The ways that are being added to the relation
        relation - 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 relation
        indexOfWayToKeep - The index of the way to keep in relation to newWays
        relation - The relation we are working on
        newWays - The ways that are being added
        Returns:
        true if we need to reverse the direction of the ways
      • split

        public static SplitWayCommand split​(Way way,
                                            java.util.List<Node> atNodes,
                                            java.util.Collection<? extends OsmPrimitive> selection)
        Splits the way way at the nodes in atNodes and replies the result of this process in an instance of SplitWayCommand.

        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 the type key
        treatAs - The type of relation to treat the relationType as. 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