Package org.openstreetmap.josm.actions
Class JoinAreasAction
java.lang.Object
javax.swing.AbstractAction
org.openstreetmap.josm.actions.JosmAction
org.openstreetmap.josm.actions.JoinAreasAction
- All Implemented Interfaces:
ActionListener,Serializable,Cloneable,EventListener,Action,Destroyable
Join Areas (i.e. closed ways and multipolygons).
- Since:
- 2575
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA multipolygon with a list of inner ways and an assembled polygon for the outer waystatic classThis helper class describes a polygon, assembled from several ways.private static classstatic classThis helper class describes join areas action result.static classA record class to store how a multipolygon is constructed(package private) static classHelper storage class for finding findOuterWaysprivate static classstatic classHelperClass - saves a way and the "inside" side.private static classThis helper class implements algorithm traversing through connected ways.Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate final LinkedList<Command>private DataSetprivate final LinkedList<Command>Fields inherited from class org.openstreetmap.josm.actions.JosmAction
scFields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newJoinAreasAction.JoinAreasAction(boolean addShortcutToolbarAdapters) Constructs a newJoinAreasActionwith optional shortcut and adapters. -
Method Summary
Modifier and TypeMethodDescriptionvoidGets called whenever the shortcut is pressed or the menu entry is selected.private JoinAreasAction.RelationRoleaddOwnMultipolygonRelation(Collection<Way> inner) Will add own multipolygon relation to the "previously existing" relations.buildNodeChunks(Way way, Collection<Node> splitNodes) Simple chunking version.private voidstatic List<JoinAreasAction.Multipolygon>collectMultipolygons(Collection<Way> selectedWays) This method analyzes multipolygon relationships of given ways and collects addition inner ways to consider.private voidprivate voidcommitCommands(String description) Commits the command list with a descriptionprivate voidAdd all executed commands as one command to the undo stack without executing them again.static List<JoinAreasAction.AssembledPolygon>findBoundaryPolygons(Collection<JoinAreasAction.WayInPolygon> multigonWays, List<Way> discardedResult) Finds all ways that form inner or outer boundaries.private static List<JoinAreasAction.PolygonLevel>findOuterWaysImpl(int level, Collection<JoinAreasAction.AssembledPolygon> boundaryWays) Collects outer way and corresponding inner ways from all boundaries.private static List<JoinAreasAction.AssembledMultipolygon>findPolygons(Collection<JoinAreasAction.AssembledPolygon> boundaries) This method finds which ways are outer and which are inner.private voidfixRelations(List<JoinAreasAction.RelationRole> rels, Way outer, JoinAreasAction.RelationRole ownMultipol, Set<Relation> relationsToDelete) Adds the previously removed relations again to the outer way.static List<JoinAreasAction.AssembledPolygon>This method checks if polygons have several touching parts and splits them in several polygons.voidjoin(Collection<Way> ways) Joins the given ways.private JoinAreasAction.JoinAreasResultWill join two or more overlapping areasprivate WayJoins a list of ways (using CombineWayAction and ReverseWayAction as specified in WayInPath)private JoinAreasAction.MultipolygonJoins the lists of ways.private WayJoins the outer ways and deletes all short ways that can't be part of a multipolygon anyway.private WayCreate copy of given way using an older id so that we don't create a new way instead of a modified old one.private static List<JoinAreasAction.WayInPolygon>markWayInsideSide(List<Way> parts, boolean isInner) This method analyzes the way and assigns each part what direction polygon "inside" is.private booleanremoveDuplicateNodes(List<Way> ways) This method removes duplicate points (if any) from the input ways.private List<JoinAreasAction.RelationRole>Removes a given OsmPrimitive from all relations.private booleanresolveTagConflicts(List<JoinAreasAction.Multipolygon> polygons) Checks if tags of two given ways differ, and presents the user a dialog to solve conflictsprivate static voidCorrect possible error in markWayInsideSide result when splitting a self-intersecting way.This is a method that splits way into smaller parts, using the prepared nodes list as split points.private voidstripTags(Collection<Way> ways) Remove all tags from the all the wayprivate booleantestJoin(List<JoinAreasAction.Multipolygon> areas) Tests if the areas have some intersections to join.private voidtryUndo()protected voidOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.protected voidupdateEnabledState(Collection<? extends OsmPrimitive> selection) Override in subclasses to update the enabled state of the action if the collection of selected primitives changes.static booleanwayInsideWay(JoinAreasAction.AssembledPolygon inside, JoinAreasAction.AssembledPolygon outside) Tests if way is inside other wayMethods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFutureMethods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Field Details
-
executedCmds
-
cmds
-
ds
-
addedRelations
-
addUndoRedo
-
-
Constructor Details
-
JoinAreasAction
public JoinAreasAction()Constructs a newJoinAreasAction. -
JoinAreasAction
Constructs a newJoinAreasActionwith 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 Details
-
actionPerformed
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. -
clearFields
-
join
Joins the given ways.- Parameters:
ways- Ways to join- Since:
- 7534
-
tryUndo
-
testJoin
Tests if the areas have some intersections to join.- Parameters:
areas- Areas to test- Returns:
trueif areas are joinable
-
joinAreas
private JoinAreasAction.JoinAreasResult joinAreas(List<JoinAreasAction.Multipolygon> areas) throws UserCancelException Will join two or more overlapping areas- Parameters:
areas- list of areas to join- Returns:
- new area formed.
- Throws:
UserCancelException- if user cancels the operation- Since:
- 15852 : visibility changed from public to private
-
keepOlder
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 checkoldestWayMap- nodes from old waysdiscardedWays- collection of ways which will be deleted (modified)- Returns:
- a copy of the way with an older id or the way itself
-
resolveTagConflicts
Checks if tags of two given ways differ, and presents the user a dialog to solve conflicts- Parameters:
polygons- ways to check- Returns:
trueif all conflicts are resolved,falseif conflicts remain.
-
removeDuplicateNodes
This method removes duplicate points (if any) from the input ways.- Parameters:
ways- the ways to process- Returns:
trueif any changes where made
-
commitCommands
Commits the command list with a description- Parameters:
description- The description of what the commands do
-
commitCommand
-
commitExecuted
Add all executed commands as one command to the undo stack without executing them again. -
markWayInsideSide
private static List<JoinAreasAction.WayInPolygon> markWayInsideSide(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 wayisInner- - if true, reverts the direction (for multipolygon islands)- Returns:
- list of parts, marked with the inside orientation.
- Throws:
IllegalArgumentException- if parts is empty or not circular
-
revertDuplicateTwoNodeWays
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 =trueand those with insideToTheRight =falsediffers by 0 or 1, not more.See #10511
- Parameters:
parts- the parts of a single closed way
-
splitWayOnNodes
This is a method that splits way into smaller parts, using the prepared nodes list as split points. UsesSplitWayCommand.splitWay(org.openstreetmap.josm.data.osm.Way, java.util.List<java.util.List<org.openstreetmap.josm.data.osm.Node>>, java.util.Collection<? extends org.openstreetmap.josm.data.osm.OsmPrimitive>)for the heavy lifting.- Parameters:
way- way to splitnodes- split pointsoldestWayMap- nodes from old ways (modified here)- Returns:
- list of split ways (or original way if no splitting is done).
-
buildNodeChunks
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 chunksplitNodes- the places where to cut.- Returns:
- list of node paths to produce.
-
findPolygons
private static List<JoinAreasAction.AssembledMultipolygon> findPolygons(Collection<JoinAreasAction.AssembledPolygon> boundaries) This method finds which ways are outer and which are inner.- Parameters:
boundaries- list of joined boundaries to search in- Returns:
- outer ways
-
findOuterWaysImpl
private static List<JoinAreasAction.PolygonLevel> findOuterWaysImpl(int level, Collection<JoinAreasAction.AssembledPolygon> boundaryWays) Collects outer way and corresponding inner ways from all boundaries.- Parameters:
level- depth levelboundaryWays- list of joined boundaries to search in- Returns:
- the outermost Way.
-
findBoundaryPolygons
public static List<JoinAreasAction.AssembledPolygon> findBoundaryPolygons(Collection<JoinAreasAction.WayInPolygon> multigonWays, 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.
-
fixTouchingPolygons
public static List<JoinAreasAction.AssembledPolygon> fixTouchingPolygons(List<JoinAreasAction.AssembledPolygon> polygons) This method checks if polygons have several touching parts and splits them in several polygons.- Parameters:
polygons- the polygons to process.- Returns:
- the resulting list of polygons
-
wayInsideWay
public static boolean wayInsideWay(JoinAreasAction.AssembledPolygon inside, JoinAreasAction.AssembledPolygon outside) Tests if way is inside other way- Parameters:
outside- outer polygon descriptioninside- inner polygon description- Returns:
trueif inner is inside outer
-
joinPolygon
private JoinAreasAction.Multipolygon joinPolygon(JoinAreasAction.AssembledMultipolygon polygon) throws UserCancelException Joins the lists of ways.- Parameters:
polygon- The list of outer ways that belong to that multipolygon.- Returns:
- The newly created outer way
- Throws:
UserCancelException- if user cancels the operation
-
joinWays
Joins the outer ways and deletes all short ways that can't be part of a multipolygon anyway.- Parameters:
ways- The list of outer ways that belong to that multigon.- Returns:
- The newly created outer way
- Throws:
UserCancelException- if user cancels the operation
-
joinOrientedWays
Joins a list of ways (using CombineWayAction and ReverseWayAction as specified in WayInPath)- Parameters:
ways- The list of ways to join and reverse- Returns:
- The newly created way
- Throws:
UserCancelException- if user cancels the operation
-
collectMultipolygons
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
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
-
removeFromAllRelations
Removes a given OsmPrimitive from all relations.- Parameters:
osm- Element to remove from all relations- Returns:
- List of relations with roles the primitives was part of
-
fixRelations
private void fixRelations(List<JoinAreasAction.RelationRole> rels, Way outer, JoinAreasAction.RelationRole ownMultipol, 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 ofouter- The newly created outer area/wayownMultipol- elements to directly add as outerrelationsToDelete- set of relations to delete.
-
stripTags
Remove all tags from the all the way- Parameters:
ways- The List of Ways to remove all tags from
-
updateEnabledState
Description copied from class:JosmActionOverride in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e. when a layer is removed or added. SeeJosmAction.updateEnabledState(Collection)to respond to changes in the collection of selected primitives. Default behavior is empty.- Overrides:
updateEnabledStatein classJosmAction- See Also:
-
updateEnabledState
Description copied from class:JosmActionOverride in subclasses to update the enabled state of the action if the collection of selected primitives changes. This method is called with the new selection.- Overrides:
updateEnabledStatein classJosmAction- Parameters:
selection- the collection of selected primitives; may be empty, but not null- See Also:
-