Changeset 15137 in josm for trunk/src


Ignore:
Timestamp:
2019-05-29T09:21:54+02:00 (5 years ago)
Author:
GerdP
Message:

fix #17767: "Update multipolygon" may change route relation to multipolygon
If no relation is selected but at least one way: Collect the multipolygon relations which have the selected way(s) as members. If the collection contains exactly one relation the action is enabled.
The implementation stops early when more than one multipolygon relation is found.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r14654 r15137  
    179179    }
    180180
    181     private Relation getSelectedMultipolygonRelation() {
    182         DataSet ds = getLayerManager().getEditDataSet();
    183         return getSelectedMultipolygonRelation(ds.getSelectedWays(), ds.getSelectedRelations());
    184     }
    185 
    186181    private static Relation getSelectedMultipolygonRelation(Collection<Way> selectedWays, Collection<Relation> selectedRelations) {
    187         if (selectedRelations.size() == 1 && "multipolygon".equals(selectedRelations.iterator().next().get("type"))) {
    188             return selectedRelations.iterator().next();
    189         } else {
    190             final Set<Relation> relatedRelations = new HashSet<>();
     182        Relation candidate = null;
     183        if (selectedRelations.size() == 1) {
     184            candidate = selectedRelations.iterator().next();
     185            if (!candidate.hasTag("type", "multipolygon"))
     186                candidate = null;
     187        } else if (!selectedWays.isEmpty()) {
    191188            for (final Way w : selectedWays) {
    192                 w.referrers(Relation.class).forEach(relatedRelations::add);
    193             }
    194             return relatedRelations.size() == 1 ? relatedRelations.iterator().next() : null;
    195         }
     189                for (OsmPrimitive r : w.getReferrers()) {
     190                    if (r != candidate && r instanceof Relation && r.hasTag("type", "multipolygon")) {
     191                        if (candidate != null)
     192                            return null; // found another multipolygon relation
     193                        candidate = (Relation) r;
     194                    }
     195                }
     196            }
     197        }
     198        return candidate;
    196199    }
    197200
     
    271274      * Enable this action only if something is selected
    272275      *
    273       * @param selection the current selection, gets tested for emptyness
     276      * @param selection the current selection, gets tested for emptiness
    274277      */
    275278    @Override
    276279    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    277280        DataSet ds = getLayerManager().getEditDataSet();
    278         if (ds == null) {
     281        if (ds == null || selection.isEmpty()) {
    279282            setEnabled(false);
    280283        } else if (update) {
    281             setEnabled(getSelectedMultipolygonRelation() != null);
     284            setEnabled(getSelectedMultipolygonRelation(ds.getSelectedWays(), ds.getSelectedRelations()) != null);
    282285        } else {
    283             setEnabled(!getLayerManager().getEditDataSet().getSelectedWays().isEmpty());
     286            setEnabled(!ds.getSelectedWays().isEmpty());
    284287        }
    285288    }
Note: See TracChangeset for help on using the changeset viewer.