Changeset 34790 in osm for applications/editors/josm


Ignore:
Timestamp:
2018-12-23T08:23:59+01:00 (6 years ago)
Author:
gerdp
Message:

fix #16006: Using 'split adjacent ways' on multipolygons is unpredictable.

When multiple ways are split, make sure that relations are updated after each split.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitOnIntersectionsAction.java

    r34785 r34790  
    99import java.util.Collection;
    1010import java.util.HashMap;
    11 import java.util.HashSet;
    1211import java.util.Iterator;
    1312import java.util.List;
    1413import java.util.Map;
    1514import java.util.Map.Entry;
    16 import java.util.Set;
    1715
    1816import javax.swing.JOptionPane;
     
    2523import org.openstreetmap.josm.data.osm.Node;
    2624import org.openstreetmap.josm.data.osm.OsmPrimitive;
    27 import org.openstreetmap.josm.data.osm.Relation;
    2825import org.openstreetmap.josm.data.osm.Way;
    2926import org.openstreetmap.josm.gui.Notification;
     
    9592        }
    9693
    97         // fix #16006: Don't generate SequenceCommand when ways are part of the same relation.
    98         boolean createSequenceCommand = true;
    99         Set<Relation> allWayRefs = new HashSet<>();
    100         for (Way splitWay : splitWays.keySet()) {
    101             for (Relation rel : OsmPrimitive.getFilteredList(splitWay.getReferrers(), Relation.class)) {
    102                 createSequenceCommand &= allWayRefs.add(rel);
     94        for (Entry<Way, List<Node>> entry : splitWays.entrySet()) {
     95            SplitWayCommand split = SplitWayCommand.split(entry.getKey(), entry.getValue(), selectedWays);
     96            if (split != null) {
     97                // execute, we need the result, see also #16006
     98                UndoRedoHandler.getInstance().add(split);
     99                selectedWays.remove(split.getOriginalWay());
     100                selectedWays.addAll(split.getNewWays());
     101                list.add(split);
    103102            }
    104         }
    105         for (Entry<Way, List<Node>> entry : splitWays.entrySet()) {
    106             SplitWayCommand cmd = SplitWayCommand.split(entry.getKey(), entry.getValue(), selectedWays);
    107             if (!createSequenceCommand) {
    108                 UndoRedoHandler.getInstance().add(cmd);
    109             }
    110             list.add(cmd);
    111103        }
    112104
    113105        if (!list.isEmpty()) {
    114             if (createSequenceCommand) {
    115                 UndoRedoHandler.getInstance().add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list));
    116             } else {
    117                 new Notification(
    118                         tr("Affected ways are members of the same relation. {0} actions were created for this split.",
    119                                 list.size())).setIcon(JOptionPane.WARNING_MESSAGE).show();
     106                if (list.size() > 1) {
     107                        // create a single command for the previously executed commands
     108                        SequenceCommand seq = new SequenceCommand(TITLE, list);
     109                        for (int i = 0; i < list.size(); i++) {
     110                                UndoRedoHandler.getInstance().undo();
     111                        }
     112                        UndoRedoHandler.getInstance().add(seq);
    120113            }
    121114            getLayerManager().getEditDataSet().clearSelection();
Note: See TracChangeset for help on using the changeset viewer.