Ticket #18501: 18495.patch

File 18495.patch, 3.6 KB (added by GerdP, 4 years ago)
  • src/org/openstreetmap/josm/actions/CombineWayAction.java

     
    1414import java.util.LinkedList;
    1515import java.util.List;
    1616import java.util.Objects;
     17import java.util.Set;
    1718import java.util.stream.Collectors;
    1819
    1920import javax.swing.JOptionPane;
     
    106107     * @throws UserCancelException if the user cancelled a dialog.
    107108     */
    108109    public static Pair<Way, Command> combineWaysWorker(Collection<Way> ways) throws UserCancelException {
     110        return combineWaysWorker(ways, false);
     111    }
    109112
     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
    110123        // prepare and clean the list of ways to combine
    111124        //
    112125        if (ways == null || ways.isEmpty())
     
    116129        // remove duplicates, preserving order
    117130        ways = new LinkedHashSet<>(ways);
    118131        // remove incomplete ways
    119         ways.removeIf(w -> w.isIncomplete() || w.isOutsideDownloadArea());
     132        ways.removeIf(OsmPrimitive::isIncomplete);
    120133        // we need at least two ways
    121134        if (ways.size() < 2)
    122135            return null;
     
    132145            warnCombiningImpossible();
    133146            return null;
    134147        }
     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
    135169        // check whether any ways have been reversed in the process
    136170        // and build the collection of tags used by the ways to combine
    137171        //
     
    283317        // combine and update gui
    284318        Pair<Way, Command> combineResult;
    285319        try {
    286             combineResult = combineWaysWorker(selectedWays);
     320            combineResult = combineWaysWorker(selectedWays, true);
    287321        } catch (UserCancelException ex) {
    288322            Logging.trace(ex);
    289323            return;
     
    325359        int numWays = 0;
    326360        if (OsmUtils.isOsmCollectionEditable(selection)) {
    327361            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) {
    330363                    break;
    331364                }
    332365            }