Changeset 2596 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-12-09T17:11:51+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r2512 r2596 11 11 import java.util.Arrays; 12 12 import java.util.Collection; 13 import java.util.Collections; 13 14 import java.util.HashMap; 14 15 import java.util.HashSet; … … 151 152 } 152 153 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 160 193 throw new InvalidUserInputException("usage"); 161 }162 194 } 163 195 } catch (InvalidUserInputException ex) { … … 199 231 * 200 232 **/ 201 private static voidorthogonalize(ArrayList<WayData> wayDataList, ArrayList<Node> headingNodes)233 private static Collection<Command> orthogonalize(ArrayList<WayData> wayDataList, ArrayList<Node> headingNodes) 202 234 throws InvalidUserInputException 203 235 { … … 247 279 final HashMap<Node, Double> nY = new HashMap<Node, Double>(); 248 280 249 // cal uclate the centroid of all nodes281 // calculate the centroid of all nodes 250 282 // it is used as rotation center 251 283 EastNorth pivot = new EastNorth(0., 0.); … … 325 357 // rotate back and log the change 326 358 final Collection<Command> commands = new LinkedList<Command>(); 327 OrthogonalizeAction.rememberMovements.clear(); 359 // OrthogonalizeAction.rememberMovements.clear(); 328 360 for (Node n: allNodes) { 329 361 EastNorth tmp = new EastNorth(nX.get(n), nY.get(n)); … … 343 375 } 344 376 } 345 Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands)); 346 Main.map.repaint(); 377 return commands; 347 378 } 348 379
Note:
See TracChangeset
for help on using the changeset viewer.