org.openstreetmap.josm.actions
Class OrthogonalizeAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.openstreetmap.josm.actions.JosmAction
          extended by 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 / Orthogonalize Align 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
private static class OrthogonalizeAction.Direction
           
private static class OrthogonalizeAction.EN
          Class contains some auxiliary functions
private static class OrthogonalizeAction.InvalidUserInputException
          Exception: unsuited user input
private static class OrthogonalizeAction.RejectedAngleException
          Exception: angle cannot be recognized as 0, 90, 180 or 270 degrees
static class OrthogonalizeAction.Undo
          Undo the previous orthogonalization for certain nodes.
private static class OrthogonalizeAction.WayData
          Class contains everything we need to know about a singe way.
 
Field Summary
private static java.util.HashMap<Node,EastNorth> rememberMovements
          Remember movements, so the user can later undo it for certain nodes
private static double TOLERANCE1
          excepted deviation from an angle of 0, 90, 180, 360 degrees maximum value: 45 degrees Current policy is to except just everything, no matter how strange the result would be.
private static double TOLERANCE2
           
private  java.lang.String USAGE
           
 
Fields inherited from class org.openstreetmap.josm.actions.JosmAction
sc
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields 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
OrthogonalizeAction()
           
 
Method Summary
 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.ArrayList<OrthogonalizeAction.WayData>> buildGroups(java.util.ArrayList<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)
           
private static java.util.Collection<Command> orthogonalize(java.util.ArrayList<OrthogonalizeAction.WayData> wayDataList, java.util.ArrayList<Node> headingNodes)
          Outline: 1.
private static double standard_angle_0_to_2PI(double a)
          Make sure angle (up to 2*Pi) is in interval [ 0, 2*Pi ).
private static double standard_angle_mPI_to_PI(double a)
          Make sure angle (up to 2*Pi) is in interval ( -Pi, Pi ].
protected  void updateEnabledState()
          Don't check, if the current selection is suited for orthogonalization.
 
Methods inherited from class org.openstreetmap.josm.actions.JosmAction
destroy, getCurrentDataSet, getEditLayer, getShortcut, initEnabledState, installAdapters, setTooltip, updateEnabledState
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USAGE

private java.lang.String USAGE

TOLERANCE1

private static final double TOLERANCE1
excepted deviation from an angle of 0, 90, 180, 360 degrees maximum value: 45 degrees Current 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.HashMap<Node,EastNorth> rememberMovements
Remember movements, so the user can later undo it for certain nodes

Constructor Detail

OrthogonalizeAction

public OrthogonalizeAction()
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)

buildGroups

private static java.util.List<java.util.ArrayList<OrthogonalizeAction.WayData>> buildGroups(java.util.ArrayList<OrthogonalizeAction.WayData> wayDataList)
Collect groups of ways with common nodes in order to orthogonalize each group separately.


extendGroupRec

private static void extendGroupRec(java.util.List<OrthogonalizeAction.WayData> group,
                                   OrthogonalizeAction.WayData newGroupMember,
                                   java.util.List<OrthogonalizeAction.WayData> remaining)

orthogonalize

private static java.util.Collection<Command> orthogonalize(java.util.ArrayList<OrthogonalizeAction.WayData> wayDataList,
                                                           java.util.ArrayList<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.

Throws:
OrthogonalizeAction.InvalidUserInputException

standard_angle_0_to_2PI

private static double standard_angle_0_to_2PI(double a)
Make sure angle (up to 2*Pi) is in interval [ 0, 2*Pi ).


standard_angle_mPI_to_PI

private static double standard_angle_mPI_to_PI(double a)
Make sure angle (up to 2*Pi) is in interval ( -Pi, Pi ].


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:

Throws:
OrthogonalizeAction.RejectedAngleException

updateEnabledState

protected void updateEnabledState()
Don't check, if the current selection is suited for orthogonalization. Instead, show a usage dialog, that explains, why it cannot be done.

Overrides:
updateEnabledState in class JosmAction
See Also:
JosmAction.updateEnabledState(Collection), JosmAction.initEnabledState()


JOSM