Changeset 9923 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r9446 r9923 146 146 } 147 147 148 final List<Node> nodeList = new ArrayList<>();149 final List<WayData> wayDataList = new ArrayList<>();150 148 final Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 151 149 152 150 try { 153 // collect nodes and ways from the selection 154 for (OsmPrimitive p : sel) { 155 if (p instanceof Node) { 156 nodeList.add((Node) p); 157 } else if (p instanceof Way) { 158 wayDataList.add(new WayData((Way) p)); 159 } else 160 throw new InvalidUserInputException(tr("Selection must consist only of ways and nodes.")); 161 } 162 if (wayDataList.isEmpty()) 163 throw new InvalidUserInputException("usage"); 164 else { 165 if (nodeList.size() == 2 || nodeList.isEmpty()) { 166 OrthogonalizeAction.rememberMovements.clear(); 167 final Collection<Command> commands = new LinkedList<>(); 168 169 if (nodeList.size() == 2) { // fixed direction 170 commands.addAll(orthogonalize(wayDataList, nodeList)); 171 } else if (nodeList.isEmpty()) { 172 List<List<WayData>> groups = buildGroups(wayDataList); 173 for (List<WayData> g: groups) { 174 commands.addAll(orthogonalize(g, nodeList)); 175 } 176 } else 177 throw new IllegalStateException(); 178 179 Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands)); 180 Main.map.repaint(); 181 182 } else 183 throw new InvalidUserInputException("usage"); 184 } 151 final SequenceCommand command = orthogonalize(sel); 152 Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), command)); 153 Main.map.repaint(); 185 154 } catch (InvalidUserInputException ex) { 186 155 String msg; … … 194 163 .setDuration(Notification.TIME_DEFAULT) 195 164 .show(); 165 } 166 } 167 168 /** 169 * Rectifies the selection 170 * @param selection the selection which should be rectified 171 * @return a rectifying command 172 * @throws InvalidUserInputException if the selection is invalid 173 */ 174 static SequenceCommand orthogonalize(Iterable<OsmPrimitive> selection) throws InvalidUserInputException { 175 final List<Node> nodeList = new ArrayList<>(); 176 final List<WayData> wayDataList = new ArrayList<>(); 177 // collect nodes and ways from the selection 178 for (OsmPrimitive p : selection) { 179 if (p instanceof Node) { 180 nodeList.add((Node) p); 181 } else if (p instanceof Way) { 182 wayDataList.add(new WayData((Way) p)); 183 } else 184 throw new InvalidUserInputException(tr("Selection must consist only of ways and nodes.")); 185 } 186 if (wayDataList.isEmpty()) { 187 throw new InvalidUserInputException("usage"); 188 } else { 189 if (nodeList.size() == 2 || nodeList.isEmpty()) { 190 OrthogonalizeAction.rememberMovements.clear(); 191 final Collection<Command> commands = new LinkedList<>(); 192 193 if (nodeList.size() == 2) { // fixed direction 194 commands.addAll(orthogonalize(wayDataList, nodeList)); 195 } else if (nodeList.isEmpty()) { 196 List<List<WayData>> groups = buildGroups(wayDataList); 197 for (List<WayData> g: groups) { 198 commands.addAll(orthogonalize(g, nodeList)); 199 } 200 } else { 201 throw new IllegalStateException(); 202 } 203 204 return new SequenceCommand(tr("Orthogonalize"), commands); 205 206 } else { 207 throw new InvalidUserInputException("usage"); 208 } 196 209 } 197 210 } … … 580 593 * Exception: unsuited user input 581 594 */ 582 pr ivatestatic class InvalidUserInputException extends Exception {595 protected static class InvalidUserInputException extends Exception { 583 596 InvalidUserInputException(String message) { 584 597 super(message); … … 593 606 * Exception: angle cannot be recognized as 0, 90, 180 or 270 degrees 594 607 */ 595 pr ivatestatic class RejectedAngleException extends Exception {608 protected static class RejectedAngleException extends Exception { 596 609 RejectedAngleException() { 597 610 super();
Note:
See TracChangeset
for help on using the changeset viewer.