Ticket #18495: 18495.patch
File 18495.patch, 3.6 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/actions/CombineWayAction.java
14 14 import java.util.LinkedList; 15 15 import java.util.List; 16 16 import java.util.Objects; 17 import java.util.Set; 17 18 import java.util.stream.Collectors; 18 19 19 20 import javax.swing.JOptionPane; … … 106 107 * @throws UserCancelException if the user cancelled a dialog. 107 108 */ 108 109 public static Pair<Way, Command> combineWaysWorker(Collection<Way> ways) throws UserCancelException { 110 return combineWaysWorker(ways, false); 111 } 109 112 113 /** 114 * Combine multiple ways into one. 115 * @param ways the way to combine to one way 116 * @param checkOutsideNodes if true, don't allow combination at nodes outside the download area 117 * @return null if ways cannot be combined. Otherwise returns the combined ways and the commands to combine 118 * @throws UserCancelException if the user cancelled a dialog. 119 * @since xxx 120 */ 121 public static Pair<Way, Command> combineWaysWorker(Collection<Way> ways, boolean checkOutsideNodes) throws UserCancelException { 122 110 123 // prepare and clean the list of ways to combine 111 124 // 112 125 if (ways == null || ways.isEmpty()) … … 116 129 // remove duplicates, preserving order 117 130 ways = new LinkedHashSet<>(ways); 118 131 // remove incomplete ways 119 ways.removeIf( w -> w.isIncomplete() || w.isOutsideDownloadArea());132 ways.removeIf(OsmPrimitive::isIncomplete); 120 133 // we need at least two ways 121 134 if (ways.size() < 2) 122 135 return null; … … 132 145 warnCombiningImpossible(); 133 146 return null; 134 147 } 148 if (checkOutsideNodes) { 149 for (Node n : path) { 150 if (n.isOutsideDownloadArea() && !n.isNew()) { 151 int count = 0; 152 Set<Way> parentWays = n.referrers(Way.class).collect(Collectors.toSet()); 153 for (Way w : ways) { 154 if (parentWays.contains(w)) 155 count++; 156 } 157 if (count > 1) { 158 String msg = tr("Could not combine ways<br>" 159 + "(A shared node is outside of download area)"); 160 new Notification(msg) 161 .setIcon(JOptionPane.INFORMATION_MESSAGE) 162 .show(); 163 return null; 164 } 165 } 166 } 167 } 168 135 169 // check whether any ways have been reversed in the process 136 170 // and build the collection of tags used by the ways to combine 137 171 // … … 283 317 // combine and update gui 284 318 Pair<Way, Command> combineResult; 285 319 try { 286 combineResult = combineWaysWorker(selectedWays );320 combineResult = combineWaysWorker(selectedWays, true); 287 321 } catch (UserCancelException ex) { 288 322 Logging.trace(ex); 289 323 return; … … 325 359 int numWays = 0; 326 360 if (OsmUtils.isOsmCollectionEditable(selection)) { 327 361 for (OsmPrimitive osm : selection) { 328 if (osm instanceof Way && !osm.isIncomplete() && !((Way) osm).isOutsideDownloadArea() 329 && ++numWays >= 2) { 362 if (osm instanceof Way && !osm.isIncomplete() && ++numWays >= 2) { 330 363 break; 331 364 } 332 365 }