Changeset 7742 in josm for trunk/src/org


Ignore:
Timestamp:
2014-11-23T22:25:29+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #10778 - fix automatic member role assignment when relation matches several presets

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r7005 r7742  
    1919import org.openstreetmap.josm.tools.ImageProvider;
    2020
    21 
     21/**
     22 * Add all objects selected in the current dataset after the last member of relation(s).
     23 * @since 5799
     24 */
    2225public class AddSelectionToRelations extends AbstractRelationAction implements SelectionChangedListener {
    2326    /**
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r7601 r7742  
    737737    }
    738738
     739    /**
     740     * Adds primitives to a given relation.
     741     * @param orig The relation to modify
     742     * @param primitivesToAdd The primitives to add as relation members
     743     * @return The resulting command
     744     * @throws IllegalArgumentException if orig is null
     745     */
    739746    public static Command addPrimitivesToRelation(final Relation orig, Collection<? extends OsmPrimitive> primitivesToAdd)
    740747            throws IllegalArgumentException {
     
    753760                    continue;
    754761                }
    755                 final String role = presets.isEmpty() ? null : presets.iterator().next().suggestRoleForOsmPrimitive(p);
    756                 relation.addMember(new RelationMember(role == null ? "" : role, p));
     762                final Set<String> roles = findSuggestedRoles(presets, p);
     763                relation.addMember(new RelationMember(roles.size() == 1 ? roles.iterator().next() : "", p));
    757764                modified = true;
    758765            }
     
    761768            return null;
    762769        }
     770    }
     771
     772    protected static Set<String> findSuggestedRoles(final Collection<TaggingPreset> presets, OsmPrimitive p) {
     773        final Set<String> roles = new HashSet<>();
     774        for (TaggingPreset preset : presets) {
     775            String role = preset.suggestRoleForOsmPrimitive(p);
     776            if (role != null && !role.isEmpty()) {
     777                roles.add(role);
     778            }
     779        }
     780        return roles;
    763781    }
    764782
Note: See TracChangeset for help on using the changeset viewer.