Class JoinAreasAction

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, Destroyable

    public class JoinAreasAction
    extends JosmAction
    Join Areas (i.e. closed ways and multipolygons).
    Since:
    2575
    See Also:
    Serialized Form
    • Constructor Detail

      • JoinAreasAction

        public JoinAreasAction()
        Constructs a new JoinAreasAction.
      • JoinAreasAction

        public JoinAreasAction​(boolean addShortcutToolbarAdapters)
        Constructs a new JoinAreasAction with optional shortcut and adapters.
        Parameters:
        addShortcutToolbarAdapters - controls whether the shortcut should be registered or not, as for toolbar registration, adapters creation and undo/redo integration
        Since:
        11611
    • Method Detail

      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        Gets called whenever the shortcut is pressed or the menu entry is selected. Checks whether the selected objects are suitable to join and joins them if so.
      • join

        public void join​(java.util.Collection<Way> ways)
        Joins the given ways.
        Parameters:
        ways - Ways to join
        Since:
        7534
      • testJoin

        private boolean testJoin​(java.util.List<JoinAreasAction.Multipolygon> areas)
        Tests if the areas have some intersections to join.
        Parameters:
        areas - Areas to test
        Returns:
        true if areas are joinable
      • keepOlder

        private Way keepOlder​(Way way,
                              java.util.Map<Node,​Way> oldestWayMap,
                              java.util.List<Way> discardedWays)
        Create copy of given way using an older id so that we don't create a new way instead of a modified old one.
        Parameters:
        way - the way to check
        oldestWayMap - nodes from old ways
        discardedWays - collection of ways which will be deleted (modified)
        Returns:
        a copy of the way with an older id or the way itself
      • resolveTagConflicts

        private boolean resolveTagConflicts​(java.util.List<JoinAreasAction.Multipolygon> polygons)
        Checks if tags of two given ways differ, and presents the user a dialog to solve conflicts
        Parameters:
        polygons - ways to check
        Returns:
        true if all conflicts are resolved, false if conflicts remain.
      • removeDuplicateNodes

        private boolean removeDuplicateNodes​(java.util.List<Way> ways)
        This method removes duplicate points (if any) from the input ways.
        Parameters:
        ways - the ways to process
        Returns:
        true if any changes where made
      • commitCommands

        private void commitCommands​(java.lang.String description)
        Commits the command list with a description
        Parameters:
        description - The description of what the commands do
      • commitExecuted

        private void commitExecuted()
        Add all executed commands as one command to the undo stack without executing them again.
      • markWayInsideSide

        private static java.util.List<JoinAreasAction.WayInPolygonmarkWayInsideSide​(java.util.List<Way> parts,
                                                                                      boolean isInner)
        This method analyzes the way and assigns each part what direction polygon "inside" is.
        Parameters:
        parts - the split parts of the way
        isInner - - if true, reverts the direction (for multipolygon islands)
        Returns:
        list of parts, marked with the inside orientation.
        Throws:
        java.lang.IllegalArgumentException - if parts is empty or not circular
      • revertDuplicateTwoNodeWays

        private static void revertDuplicateTwoNodeWays​(java.util.List<JoinAreasAction.WayInPolygon> parts)
        Correct possible error in markWayInsideSide result when splitting a self-intersecting way. If we have two ways with the same two nodes and the same direction there must be a self intersection. Change the direction flag for the latter of the two ways. The result is that difference between the number of ways with insideToTheRight = true and those with insideToTheRight = false differs by 0 or 1, not more.

        See #10511

        Parameters:
        parts - the parts of a single closed way
      • buildNodeChunks

        private static java.util.List<java.util.List<Node>> buildNodeChunks​(Way way,
                                                                            java.util.Collection<Node> splitNodes)
        Simple chunking version. Does not care about circular ways and result being proper, we will glue it all back together later on.
        Parameters:
        way - the way to chunk
        splitNodes - the places where to cut.
        Returns:
        list of node paths to produce.
      • findBoundaryPolygons

        public static java.util.List<JoinAreasAction.AssembledPolygonfindBoundaryPolygons​(java.util.Collection<JoinAreasAction.WayInPolygon> multigonWays,
                                                                                            java.util.List<Way> discardedResult)
        Finds all ways that form inner or outer boundaries.
        Parameters:
        multigonWays - A list of (splitted) ways that form a multigon and share common end nodes on intersections.
        discardedResult - this list is filled with ways that are to be discarded
        Returns:
        A list of ways that form the outer and inner boundaries of the multigon.
      • collectMultipolygons

        public static java.util.List<JoinAreasAction.MultipolygoncollectMultipolygons​(java.util.Collection<Way> selectedWays)
        This method analyzes multipolygon relationships of given ways and collects addition inner ways to consider.
        Parameters:
        selectedWays - the selected ways
        Returns:
        list of polygons, or null if too complex relation encountered.
      • addOwnMultipolygonRelation

        private JoinAreasAction.RelationRole addOwnMultipolygonRelation​(java.util.Collection<Way> inner)
        Will add own multipolygon relation to the "previously existing" relations. Fixup is done by fixRelations
        Parameters:
        inner - List of already closed inner ways
        Returns:
        The list of relation with roles to add own relation to
      • fixRelations

        private void fixRelations​(java.util.List<JoinAreasAction.RelationRole> rels,
                                  Way outer,
                                  JoinAreasAction.RelationRole ownMultipol,
                                  java.util.Set<Relation> relationsToDelete)
        Adds the previously removed relations again to the outer way. If there are multiple multipolygon relations where the joined areas were in "outer" role a new relation is created instead with all members of both. This function depends on multigon relations to be valid already, it won't fix them.
        Parameters:
        rels - List of relations with roles the (original) ways were part of
        outer - The newly created outer area/way
        ownMultipol - elements to directly add as outer
        relationsToDelete - set of relations to delete.
      • stripTags

        private void stripTags​(java.util.Collection<Way> ways)
        Remove all tags from the all the way
        Parameters:
        ways - The List of Ways to remove all tags from