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:
ActionListener,Serializable,Cloneable,EventListener,Action,Destroyable
Tools / Orthogonalize
Align edges of a way so all angles are angles of 90 or 180 degrees. See USAGE String below.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum(package private) static final classClass contains some auxiliary functionsstatic final classException: unsuited user input(package private) static classException: angle cannot be recognized as 0, 90, 180 or 270 degreesstatic classUndo the previous orthogonalization for certain nodes.private static classClass 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
FieldsModifier and TypeFieldDescriptionprivate static final doubleRemember movements, so the user can later undo it for certain nodesprivate static final doubleexcepted deviation from an angle of 0, 90, 180, 360 degrees maximum value: 45 degreesprivate static final doubleprivate static final StringFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate static intangleToDirectionChange(double a, double deltaMax) Recognize angle to be approximately 0, 90, 180 or 270 degrees.private static List<List<OrthogonalizeAction.WayData>>buildGroups(List<OrthogonalizeAction.WayData> wayDataList) Collect groups of ways with common nodes in order to orthogonalize each group separately.private static voidextendGroupRec(List<OrthogonalizeAction.WayData> group, OrthogonalizeAction.WayData newGroupMember, List<OrthogonalizeAction.WayData> remaining) static SequenceCommandorthogonalize(Iterable<OsmPrimitive> selection) Rectifies the selectionprivate static Collection<Command>orthogonalize(List<OrthogonalizeAction.WayData> wayDataList, List<Node> headingNodes) Outline: 1.private static Commandorthogonalize(List<OrthogonalizeAction.WayData> wayDataList, Node singleNode) Try to orthogonalize the given ways by moving only a single given nodeprivate static doublestandardAngle0to2PI(double a) Make sure angle (up to 2*Pi) is in interval [ 0, 2*Pi ).private static doublestandardAngleMPItoPI(double a) Make sure angle (up to 2*Pi) is in interval ( -Pi, Pi ].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.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, waitFutureMethods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Field Details
-
USAGE
-
EPSILON
- See Also:
-
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
-
rememberMovements
Remember movements, so the user can later undo it for certain nodes
-
-
Constructor Details
-
OrthogonalizeAction
public OrthogonalizeAction()Constructs a newOrthogonalizeAction.
-
-
Method Details
-
actionPerformed
-
orthogonalize
public static SequenceCommand orthogonalize(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 List<List<OrthogonalizeAction.WayData>> buildGroups(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(List<OrthogonalizeAction.WayData> group, OrthogonalizeAction.WayData newGroupMember, List<OrthogonalizeAction.WayData> remaining) -
orthogonalize
private static Command orthogonalize(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 Collection<Command> orthogonalize(List<OrthogonalizeAction.WayData> wayDataList, 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
Make sure angle (up to 2*Pi) is in interval [ 0, 2*Pi ).- Parameters:
a- angle- Returns:
- correct angle
-
standardAngleMPItoPI
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
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:
-