Class AlignInCircleAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.AlignInCircleAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
public final class AlignInCircleAction extends JosmAction
Aligns all selected nodes within a circle. (Useful for roundabouts)- Since:
- 146
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AlignInCircleAction.InvalidSelection
InvalidSelection exception has to be raised when action can't be performed-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description AlignInCircleAction()
Constructs a newAlignInCircleAction
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Perform AlignInCircle action.static void
addMoveCommandIfNeeded(Node n, PolarCoor coor, java.util.List<Command> cmds)
Add aMoveCommand
to move a node to a PolarCoor if there is a significant move.static Command
buildCommand(DataSet ds)
Builds "align in circle" command depending on the selected objects.private static java.util.List<Node>
collectNodesAnticlockwise(java.util.List<Way> ways)
Assuming all ways can be joined into polygon, create an ordered list of node.private static java.util.List<Node>
collectNodesWithExternReferrers(java.util.List<Way> ways)
Collect all nodes with more than one referrer.static Command
moveNodesCommand(java.util.List<Node> nodes, java.util.Set<Node> fixNodes, EastNorth center, double radius)
Move each node of the list of nodes to be arranged in a circle.private static java.util.List<Node>
sortByAngle(java.util.List<Node> nodes)
protected void
updateEnabledState()
Override in subclasses to update the enabled state of the action when something in the JOSM state changes, i.e.protected void
updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Override in subclasses to update the enabled state of the action if the collection of selected primitives changes.private static boolean
validateGeometry(java.util.List<Node> nodes)
-
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
buildActiveLayerChangeAdapter, buildLayerChangeAdapter, checkAndConfirmOutlyingOperation, destroy, getLayerManager, getShortcut, initEnabledState, installAdapters, listenToLayerChange, listenToSelectionChange, setHelpId, setToolbarId, setTooltip, updateEnabledStateOnCurrentSelection, updateEnabledStateOnCurrentSelection, updateEnabledStateOnModifiableSelection, waitFuture
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Constructor Detail
-
AlignInCircleAction
public AlignInCircleAction()
Constructs a newAlignInCircleAction
.
-
-
Method Detail
-
addMoveCommandIfNeeded
public static void addMoveCommandIfNeeded(Node n, PolarCoor coor, java.util.List<Command> cmds)
Add aMoveCommand
to move a node to a PolarCoor if there is a significant move.- Parameters:
n
- Node to movecoor
- polar coordinate where to move the nodecmds
- list of commands- Since:
- 17386
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Perform AlignInCircle action.
-
buildCommand
public static Command buildCommand(DataSet ds) throws AlignInCircleAction.InvalidSelection
Builds "align in circle" command depending on the selected objects. A fixed node is a node for which it is forbidden to change the angle relative to center of the circle. All other nodes are uniformly distributed.Case 1: One unclosed way. → allow action, and align selected way nodes If nodes contained by this way are selected, there are fix. If nodes outside from the way are selected there are ignored.
Case 2: One or more ways are selected and can be joined into a polygon → allow action, and align selected ways nodes If 1 node outside of way is selected, it became center If 1 node outside and 1 node inside are selected there define center and radius If no outside node and 2 inside nodes are selected those 2 nodes define diameter In all other cases outside nodes are ignored In all cases, selected nodes are fix, nodes with more than one referrers are fix (first referrer is the selected way)
Case 3: Only nodes are selected → Align these nodes, all are fix
Case 4: Circularize selected ways → Circularize each way of the selection.
- Parameters:
ds
- data set in which the command operates- Returns:
- the resulting command to execute to perform action, or null if nothing was changed
- Throws:
AlignInCircleAction.InvalidSelection
- if selection cannot be used- Since:
- 17386
-
moveNodesCommand
public static Command moveNodesCommand(java.util.List<Node> nodes, java.util.Set<Node> fixNodes, EastNorth center, double radius)
Move each node of the list of nodes to be arranged in a circle.- Parameters:
nodes
- The list of nodes to be moved.fixNodes
- The list of nodes that must not be moved.center
- A center of the circle formed by the nodes.radius
- A radius of the circle formed by the nodes.- Returns:
- the command that arranges the nodes in a circle.
- Since:
- 18615
-
sortByAngle
private static java.util.List<Node> sortByAngle(java.util.List<Node> nodes)
-
validateGeometry
private static boolean validateGeometry(java.util.List<Node> nodes)
-
collectNodesWithExternReferrers
private static java.util.List<Node> collectNodesWithExternReferrers(java.util.List<Way> ways)
Collect all nodes with more than one referrer.- Parameters:
ways
- Ways from witch nodes are selected- Returns:
- List of nodes with more than one referrer
-
collectNodesAnticlockwise
private static java.util.List<Node> collectNodesAnticlockwise(java.util.List<Way> ways) throws AlignInCircleAction.InvalidSelection
Assuming all ways can be joined into polygon, create an ordered list of node.- Parameters:
ways
- List of ways to be joined- Returns:
- Nodes anticlockwise ordered
- Throws:
AlignInCircleAction.InvalidSelection
- if selection cannot be used
-
updateEnabledState
protected void updateEnabledState()
Description copied from class:JosmAction
Override 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:
updateEnabledState
in classJosmAction
- See Also:
JosmAction.updateEnabledState(Collection)
,JosmAction.initEnabledState()
,JosmAction.listenToLayerChange()
-
updateEnabledState
protected void updateEnabledState(java.util.Collection<? extends OsmPrimitive> selection)
Description copied from class:JosmAction
Override 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:
updateEnabledState
in classJosmAction
- Parameters:
selection
- the collection of selected primitives; may be empty, but not null- See Also:
JosmAction.updateEnabledState()
,JosmAction.initEnabledState()
,JosmAction.listenToSelectionChange()
-
-