Ignore:
Timestamp:
2018-12-14T10:40:49+01:00 (6 years ago)
Author:
gerdp
Message:

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

  • If the actions splits two or more ways of the same relation, we cannot create a SequenceCommand because it would contain multiple change commands refering to the same relation. Work-around is to create multiple commands in this case and show a warning.
  • Show a message when the selection was not usable for the action.
File:
1 edited

Legend:

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

    r34454 r34780  
    99import java.util.Collection;
    1010import java.util.HashMap;
     11import java.util.HashSet;
    1112import java.util.Iterator;
    1213import java.util.List;
    1314import java.util.Map;
     15import java.util.Map.Entry;
     16import java.util.Set;
    1417
    1518import javax.swing.JOptionPane;
     
    2225import org.openstreetmap.josm.data.osm.Node;
    2326import org.openstreetmap.josm.data.osm.OsmPrimitive;
     27import org.openstreetmap.josm.data.osm.Relation;
    2428import org.openstreetmap.josm.data.osm.Way;
    2529import org.openstreetmap.josm.gui.Notification;
     
    3438public class SplitOnIntersectionsAction extends JosmAction {
    3539    private static final String TITLE = tr("Split adjacent ways");
    36 
     40    private static final String TOOL_DESC = tr("Split adjacent ways on T-intersections");
    3741    public SplitOnIntersectionsAction() {
    38         super(TITLE, "dumbutils/splitonintersections", tr("Split adjacent ways on T-intersections"),
    39                 Shortcut.registerShortcut("tools:splitonintersections", tr("Tool: {0}", tr("Split adjacent ways")),
     42        super(TITLE, "dumbutils/splitonintersections", TOOL_DESC,
     43                Shortcut.registerShortcut("tools:splitonintersections", tr("Tool: {0}", TITLE),
    4044                        KeyEvent.VK_P, Shortcut.ALT_CTRL_SHIFT), true);
    4145    }
     
    8488        }
    8589
     90                if (splitWays.isEmpty()) {
     91                        new Notification(tr("The selection cannot be used for action ''{0}''", TOOL_DESC))
     92                                        .setIcon(JOptionPane.WARNING_MESSAGE).show();
     93                        return;
     94                }
     95
     96                // fix #16006: Don't generate SequenceCommand when ways are part of the same relation.
     97        boolean createSequenceCommand = true;
     98        Set<Relation> allWayRefs = new HashSet<>();
    8699        for (Way splitWay : splitWays.keySet()) {
    87             List<List<Node>> wayChunks = SplitWayCommand.buildSplitChunks(splitWay, splitWays.get(splitWay));
    88             if (wayChunks != null) {
    89                 list.add(SplitWayCommand.splitWay(splitWay, wayChunks, new ArrayList<>(selectedWays)));
     100            for (Relation rel : OsmPrimitive.getFilteredList(splitWay.getReferrers(), Relation.class)) {
     101                createSequenceCommand &= allWayRefs.add(rel);
    90102            }
     103        }
     104        for (Entry<Way, List<Node>> entry : splitWays.entrySet()) {
     105                SplitWayCommand cmd = SplitWayCommand.split(entry.getKey(), entry.getValue(), selectedWays);
     106                if (!createSequenceCommand) {
     107                        UndoRedoHandler.getInstance().add(cmd);
     108                }
     109                list.add(cmd);
    91110        }
    92111
    93112        if (!list.isEmpty()) {
    94             UndoRedoHandler.getInstance().add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list));
     113            if (createSequenceCommand) {
     114                UndoRedoHandler.getInstance().add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list));
     115            } else {
     116                                new Notification(
     117                                                tr("Affected ways are members of the same relation. {0} actions were created for this split.",
     118                                                                list.size())).setIcon(JOptionPane.WARNING_MESSAGE).show();
     119                        }
    95120            getLayerManager().getEditDataSet().clearSelection();
    96121        }
Note: See TracChangeset for help on using the changeset viewer.