Changeset 12562 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-08-03T19:57:36+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r12527 r12562 170 170 return; 171 171 172 DataSet ds = getLayerManager().getEditDataSet();173 List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes());174 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays());175 selectedWays.removeIf(OsmPrimitive::isIncomplete);176 177 172 try { 178 Command cmd; 179 // Decide what to align based on selection: 180 181 if (selectedNodes.isEmpty() && !selectedWays.isEmpty()) { 182 // Only ways selected -> For each way align their nodes taking care of intersection 183 cmd = alignMultiWay(selectedWays); 184 } else if (selectedNodes.size() == 1) { 185 // Only 1 node selected -> align this node relative to referers way 186 Node selectedNode = selectedNodes.get(0); 187 List<Way> involvedWays; 188 if (selectedWays.isEmpty()) 189 // No selected way, all way containing this node are used 190 involvedWays = selectedNode.getParentWays(); 191 else 192 // Selected way, use only these ways 193 involvedWays = selectedWays; 194 List<Line> lines = getInvolvedLines(selectedNode, involvedWays); 195 if (lines.size() > 2 || lines.isEmpty()) 196 throw new InvalidSelection(); 197 cmd = alignSingleNode(selectedNodes.get(0), lines); 198 } else if (selectedNodes.size() >= 3) { 199 // More than 3 nodes and way(s) selected -> align selected nodes. Don't care of way(s). 200 cmd = alignOnlyNodes(selectedNodes); 201 } else { 202 // All others cases are invalid 203 throw new InvalidSelection(); 204 } 205 206 // Do it! 207 Main.main.undoRedo.add(cmd); 208 173 Main.main.undoRedo.add(buildCommand()); 209 174 } catch (InvalidSelection except) { 210 175 Main.debug(except); … … 212 177 .setIcon(JOptionPane.INFORMATION_MESSAGE) 213 178 .show(); 179 } 180 } 181 182 /** 183 * Builds "align in line" command depending on the selected objects. 184 * @return the resulting command to execute to perform action 185 * @throws InvalidSelection if a polygon is selected, or if a node is used by 3 or more ways 186 * @since 12562 187 */ 188 public Command buildCommand() throws InvalidSelection { 189 DataSet ds = getLayerManager().getEditDataSet(); 190 List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes()); 191 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays()); 192 selectedWays.removeIf(OsmPrimitive::isIncomplete); 193 194 // Decide what to align based on selection: 195 if (selectedNodes.isEmpty() && !selectedWays.isEmpty()) { 196 // Only ways selected -> For each way align their nodes taking care of intersection 197 return alignMultiWay(selectedWays); 198 } else if (selectedNodes.size() == 1) { 199 // Only 1 node selected -> align this node relative to referers way 200 Node selectedNode = selectedNodes.get(0); 201 List<Way> involvedWays; 202 if (selectedWays.isEmpty()) 203 // No selected way, all way containing this node are used 204 involvedWays = selectedNode.getParentWays(); 205 else 206 // Selected way, use only these ways 207 involvedWays = selectedWays; 208 List<Line> lines = getInvolvedLines(selectedNode, involvedWays); 209 if (lines.size() > 2 || lines.isEmpty()) 210 throw new InvalidSelection(); 211 return alignSingleNode(selectedNodes.get(0), lines); 212 } else if (selectedNodes.size() >= 3) { 213 // More than 3 nodes and way(s) selected -> align selected nodes. Don't care of way(s). 214 return alignOnlyNodes(selectedNodes); 215 } else { 216 // All others cases are invalid 217 throw new InvalidSelection(); 214 218 } 215 219 }
Note:
See TracChangeset
for help on using the changeset viewer.