Changeset 2596 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-12-09T17:11:51+01:00 (15 years ago)
Author:
bastiK
Message:

fixed #4120 (patch by mjulius) - orthogonalize tool: Do not assume all selected areas are facing in the same direction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r2512 r2596  
    1111import java.util.Arrays;
    1212import java.util.Collection;
     13import java.util.Collections;
    1314import java.util.HashMap;
    1415import java.util.HashSet;
     
    151152            }
    152153            else  {
    153                 if (nodeList.size() == 2) {
    154                     orthogonalize(wayDataList, nodeList);
    155                 }
    156                 else if (nodeList.isEmpty()) {
    157                     orthogonalize(wayDataList, nodeList);
    158                 }
    159                 else {
     154                if (nodeList.size() == 2 || nodeList.isEmpty()) {
     155                    OrthogonalizeAction.rememberMovements.clear();
     156                    final Collection<Command> commands = new LinkedList<Command>();
     157
     158                    if (nodeList.size() == 2) {  // fixed direction
     159                        commands.addAll(orthogonalize(wayDataList, nodeList));
     160                    }
     161                    else if (nodeList.isEmpty()) {
     162                        // collect groups of ways with common nodes and orthogonalize each group separately.
     163                        ArrayList<ArrayList<WayData>> groups = new ArrayList<ArrayList<WayData>>();
     164                        for (WayData w: wayDataList) {
     165                            boolean add = false;
     166                            for (ArrayList<WayData> g: groups) {
     167                                for (WayData groupedWay: g) {
     168                                    if (!Collections.disjoint(w.way.getNodes(), groupedWay.way.getNodes())) {
     169                                        add = true;
     170                                        break;
     171                                    }
     172                                }
     173                                if (add) {
     174                                    g.add(w);
     175                                }
     176                            }
     177                            if (!add) {
     178                                ArrayList<WayData> newGroup = new ArrayList<WayData>();
     179                                newGroup.add(w);
     180                                groups.add(newGroup);
     181                            }
     182                        }
     183                        for (ArrayList<WayData> g: groups) {
     184                            commands.addAll(orthogonalize(g, nodeList));
     185                        }
     186                    } else
     187                        throw new IllegalStateException();
     188                   
     189                    Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands));
     190                    Main.map.repaint();
     191                   
     192                } else
    160193                    throw new InvalidUserInputException("usage");
    161                 }
    162194            }
    163195        } catch (InvalidUserInputException ex) {
     
    199231     *
    200232     **/
    201     private static void orthogonalize(ArrayList<WayData> wayDataList, ArrayList<Node> headingNodes)
     233    private static Collection<Command> orthogonalize(ArrayList<WayData> wayDataList, ArrayList<Node> headingNodes)
    202234        throws InvalidUserInputException
    203235    {
     
    247279        final HashMap<Node, Double> nY = new HashMap<Node, Double>();
    248280
    249         // caluclate the centroid of all nodes
     281        // calculate the centroid of all nodes
    250282        // it is used as rotation center
    251283        EastNorth pivot = new EastNorth(0., 0.);
     
    325357        // rotate back and log the change
    326358        final Collection<Command> commands = new LinkedList<Command>();
    327         OrthogonalizeAction.rememberMovements.clear();
     359//        OrthogonalizeAction.rememberMovements.clear();
    328360        for (Node n: allNodes) {
    329361            EastNorth tmp = new EastNorth(nX.get(n), nY.get(n));
     
    343375            }
    344376        }
    345         Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands));
    346         Main.map.repaint();
     377        return commands;
    347378    }
    348379
Note: See TracChangeset for help on using the changeset viewer.