Changeset 16585 in josm


Ignore:
Timestamp:
2020-06-09T15:29:05+02:00 (2 months ago)
Author:
GerdP
Message:

fix #14228: Order the members when creating boundaries and multipolygons

  • Members are sorted by connectivity
  • When the selected ways build a valid multipolygon use the calculated roles
  • If the selected ways do not build a valid multipolygon user will see a popup message and roles are empty
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r16453 r16585  
    1616import java.util.Collections;
    1717import java.util.EnumSet;
    18 import java.util.HashSet;
     18import java.util.LinkedHashSet;
    1919import java.util.LinkedList;
    2020import java.util.List;
     
    3636
    3737import org.openstreetmap.josm.actions.AdaptableAction;
     38import org.openstreetmap.josm.actions.CreateMultipolygonAction;
    3839import org.openstreetmap.josm.command.ChangePropertyCommand;
    3940import org.openstreetmap.josm.command.Command;
     
    4849import org.openstreetmap.josm.data.osm.RelationMember;
    4950import org.openstreetmap.josm.data.osm.Tag;
     51import org.openstreetmap.josm.data.osm.Way;
    5052import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    5153import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
     
    5557import org.openstreetmap.josm.gui.Notification;
    5658import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
     59import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
    5760import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    5861import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
     
    7073import org.openstreetmap.josm.tools.ImageResource;
    7174import org.openstreetmap.josm.tools.Logging;
     75import org.openstreetmap.josm.tools.Pair;
    7276import org.openstreetmap.josm.tools.StreamUtils;
    7377import org.openstreetmap.josm.tools.Utils;
     
    401405            }
    402406        } else if (answer == DIALOG_ANSWER_NEW_RELATION) {
    403             final Relation r = new Relation();
    404             final Collection<RelationMember> members = new HashSet<>();
     407            Relation calculated = null;
     408            if (getChangedTags().stream().anyMatch(t -> "boundary".equals(t.get("type")) || "multipolygon".equals(t.get("type")))) {
     409                Pair<Relation, Relation> res = CreateMultipolygonAction.createMultipolygonRelation(ds.getSelectedWays(), true);
     410                if (res != null) {
     411                    calculated = res.b;
     412                }
     413            }
     414            final Relation r = calculated != null ? calculated : new Relation();
     415            final Collection<RelationMember> members = new LinkedHashSet<>();
     416            members.addAll(r.getMembers());
    405417            for (Tag t : getChangedTags()) {
    406418                r.put(t.getKey(), t.getValue());
    407419            }
    408420            for (OsmPrimitive osm : ds.getSelected()) {
     421                if (r == calculated && osm instanceof Way)
     422                    continue;
    409423                String role = suggestRoleForOsmPrimitive(osm);
    410424                RelationMember rm = new RelationMember(role == null ? "" : role, osm);
    411425                r.addMember(rm);
    412426                members.add(rm);
     427            }
     428            if (r.isMultipolygon() && r != calculated) {
     429                r.setMembers(RelationSorter.sortMembersByConnectivity(r.getMembers()));
    413430            }
    414431            SwingUtilities.invokeLater(() -> RelationEditor.getEditor(
Note: See TracChangeset for help on using the changeset viewer.