Package org.openstreetmap.josm.actions
Class OrthogonalizeAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.openstreetmap.josm.actions.JosmAction
-
- org.openstreetmap.josm.actions.OrthogonalizeAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
,Destroyable
public final class OrthogonalizeAction extends JosmAction
Tools / OrthogonalizeAlign edges of a way so all angles are angles of 90 or 180 degrees. See USAGE String below.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
OrthogonalizeAction.Direction
(package private) static class
OrthogonalizeAction.EN
Class contains some auxiliary functionsstatic class
OrthogonalizeAction.InvalidUserInputException
Exception: unsuited user inputprotected static class
OrthogonalizeAction.RejectedAngleException
Exception: angle cannot be recognized as 0, 90, 180 or 270 degreesstatic class
OrthogonalizeAction.Undo
Undo the previous orthogonalization for certain nodes.private static class
OrthogonalizeAction.WayData
Class contains everything we need to know about a single way.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.actions.JosmAction
JosmAction.ActiveLayerChangeAdapter, JosmAction.LayerChangeAdapter, JosmAction.SelectionChangeAdapter
-
-
Field Summary
Fields Modifier and Type Field Description private static double
EPSILON
private static java.util.Map<Node,EastNorth>
rememberMovements
Remember movements, so the user can later undo it for certain nodesprivate static double
TOLERANCE1
excepted deviation from an angle of 0, 90, 180, 360 degrees maximum value: 45 degreesprivate static double
TOLERANCE2
private static java.lang.String
USAGE
-
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
-
-
Constructor Summary
Constructors Constructor Description OrthogonalizeAction()
Constructs a newOrthogonalizeAction
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
private static int
angleToDirectionChange(double a, double deltaMax)
Recognize angle to be approximately 0, 90, 180 or 270 degrees.private static java.util.List<java.util.List<OrthogonalizeAction.WayData>>
buildGroups(java.util.List<OrthogonalizeAction.WayData> wayDataList)
Collect groups of ways with common nodes in order to orthogonalize each group separately.private static void
extendGroupRec(java.util.List<OrthogonalizeAction.WayData> group, OrthogonalizeAction.WayData newGroupMember, java.util.List<OrthogonalizeAction.WayData> remaining)
static SequenceCommand
orthogonalize(java.lang.Iterable<OsmPrimitive> selection)
Rectifies the selectionprivate static java.util.Collection<Command>
orthogonalize(java.util.List<OrthogonalizeAction.WayData> wayDataList, java.util.List<Node> headingNodes)
Outline: 1.private static Command
orthogonalize(java.util.List<OrthogonalizeAction.WayData> wayDataList, Node singleNode)
Try to orthogonalize the given ways by moving only a single given nodeprivate static double
standardAngle0to2PI(double a)
Make sure angle (up to 2*Pi) is in interval [ 0, 2*Pi ).private static double
standardAngleMPItoPI(double a)
Make sure angle (up to 2*Pi) is in interval ( -Pi, Pi ].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.-
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
-
-
-
-
Field Detail
-
USAGE
private static final java.lang.String USAGE
-
EPSILON
private static final double EPSILON
- See Also:
- Constant Field Values
-
TOLERANCE1
private static final double TOLERANCE1
excepted deviation from an angle of 0, 90, 180, 360 degrees maximum value: 45 degreesCurrent policy is to except just everything, no matter how strange the result would be.
-
TOLERANCE2
private static final double TOLERANCE2
-
rememberMovements
private static final java.util.Map<Node,EastNorth> rememberMovements
Remember movements, so the user can later undo it for certain nodes
-
-
Constructor Detail
-
OrthogonalizeAction
public OrthogonalizeAction()
Constructs a newOrthogonalizeAction
.
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
-
orthogonalize
public static SequenceCommand orthogonalize(java.lang.Iterable<OsmPrimitive> selection) throws OrthogonalizeAction.InvalidUserInputException
Rectifies the selection- Parameters:
selection
- the selection which should be rectified- Returns:
- a rectifying command
- Throws:
OrthogonalizeAction.InvalidUserInputException
- if the selection is invalid- Since:
- 13670
-
buildGroups
private static java.util.List<java.util.List<OrthogonalizeAction.WayData>> buildGroups(java.util.List<OrthogonalizeAction.WayData> wayDataList)
Collect groups of ways with common nodes in order to orthogonalize each group separately.- Parameters:
wayDataList
- list of ways- Returns:
- groups of ways with common nodes
-
extendGroupRec
private static void extendGroupRec(java.util.List<OrthogonalizeAction.WayData> group, OrthogonalizeAction.WayData newGroupMember, java.util.List<OrthogonalizeAction.WayData> remaining)
-
orthogonalize
private static Command orthogonalize(java.util.List<OrthogonalizeAction.WayData> wayDataList, Node singleNode) throws OrthogonalizeAction.InvalidUserInputException
Try to orthogonalize the given ways by moving only a single given node- Parameters:
wayDataList
- list of wayssingleNode
- common node to ways to orthogonalize. Only this one will be moved- Returns:
- the command to move the node
- Throws:
OrthogonalizeAction.InvalidUserInputException
- if the command cannot be computed
-
orthogonalize
private static java.util.Collection<Command> orthogonalize(java.util.List<OrthogonalizeAction.WayData> wayDataList, java.util.List<Node> headingNodes) throws OrthogonalizeAction.InvalidUserInputException
Outline: 1. Find direction of all segments - direction = 0..3 (right,up,left,down) - right is not really right, you may have to turn your screen 2. Find average heading of all segments - heading = angle of a vector in polar coordinates - sum up horizontal segments (those with direction 0 or 2) - sum up vertical segments - turn the vertical sum by 90 degrees and add it to the horizontal sum - get the average heading from this total sum 3. Rotate all nodes by the average heading so that right is really right and all segments are approximately NS or EW. 4. If nodes are connected by a horizontal segment: Replace their y-Coordinate by the mean value of their y-Coordinates. - The same for vertical segments. 5. Rotate back.- Parameters:
wayDataList
- list of waysheadingNodes
- list of heading nodes- Returns:
- list of commands to perform
- Throws:
OrthogonalizeAction.InvalidUserInputException
- if selected ways have an angle different from 90 or 180 degrees
-
standardAngle0to2PI
private static double standardAngle0to2PI(double a)
Make sure angle (up to 2*Pi) is in interval [ 0, 2*Pi ).- Parameters:
a
- angle- Returns:
- correct angle
-
standardAngleMPItoPI
private static double standardAngleMPItoPI(double a)
Make sure angle (up to 2*Pi) is in interval ( -Pi, Pi ].- Parameters:
a
- angle- Returns:
- correct angle
-
angleToDirectionChange
private static int angleToDirectionChange(double a, double deltaMax) throws OrthogonalizeAction.RejectedAngleException
Recognize angle to be approximately 0, 90, 180 or 270 degrees. returns an integral value, corresponding to a counter clockwise turn.- Parameters:
a
- angle, in radiansdeltaMax
- maximum tolerance, in radians- Returns:
- an integral value, corresponding to a counter clockwise turn
- Throws:
OrthogonalizeAction.RejectedAngleException
- in case of invalid angle
-
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()
-
-