Changeset 2564 in josm for trunk


Ignore:
Timestamp:
2009-12-03T19:51:27+01:00 (15 years ago)
Author:
Gubaer
Message:

Removed code not necessary any more because we have referrer support in OsmPrimitive

File:
1 edited

Legend:

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

    r2512 r2564  
    33
    44import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    65import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing;
    76import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing;
     7import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    88import static org.openstreetmap.josm.tools.I18n.tr;
    99
     
    1717import java.util.LinkedList;
    1818import java.util.List;
    19 import java.util.Map;
    2019import java.util.Set;
    2120import java.util.Stack;
     
    2928import org.openstreetmap.josm.command.DeleteCommand;
    3029import org.openstreetmap.josm.command.SequenceCommand;
    31 import org.openstreetmap.josm.data.osm.DataSet;
    3230import org.openstreetmap.josm.data.osm.Node;
    3331import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3432import org.openstreetmap.josm.data.osm.Relation;
    35 import org.openstreetmap.josm.data.osm.RelationMember;
    3633import org.openstreetmap.josm.data.osm.TagCollection;
    3734import org.openstreetmap.josm.data.osm.Way;
     
    9087    }
    9188
     89    /**
     90     * Replies the set of referring relations
     91     *
     92     * @return the set of referring relations
     93     */
     94    protected Set<Relation> getParentRelations(Collection<Way> ways) {
     95        HashSet<Relation> ret = new HashSet<Relation>();
     96        for (Way w: ways) {
     97            ret.addAll(OsmPrimitive.getFilteredList(w.getReferrers(), Relation.class));
     98        }
     99        return ret;
     100    }
     101
    92102    public void combineWays(Collection<Way> ways) {
    93103
     
    98108        ways.remove(null); // just in case -  remove all null ways from the collection
    99109        ways = new HashSet<Way>(ways); // remove duplicates
    100 
    101         // build the list of relations referring to the ways to combine
    102         //
    103         WayReferringRelations referringRelations = new WayReferringRelations(ways);
    104         referringRelations.build(getCurrentDataSet());
    105110
    106111        // build the collection of tags used by the ways to combine
     
    140145        dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues());
    141146        dialog.setTargetPrimitive(targetWay);
     147        Set<Relation> parentRelations = getParentRelations(ways);
    142148        dialog.getRelationMemberConflictResolverModel().populate(
    143                 referringRelations.getRelations(),
    144                 referringRelations.getWays()
     149                parentRelations,
     150                ways
    145151        );
    146152        dialog.prepareDefaultDecisions();
     
    148154        // resolve tag conflicts if necessary
    149155        //
    150         if (!completeWayTags.isApplicableToPrimitive() || !referringRelations.getRelations().isEmpty()) {
     156        if (!completeWayTags.isApplicableToPrimitive() || !parentRelations.isEmpty()) {
    151157            dialog.setVisible(true);
    152158            if (dialog.isCancelled())
     
    213219            }
    214220        setEnabled(numWays >= 2);
    215     }
    216 
    217     /**
    218      * This is a collection of relations referring to at least one out of a set of
    219      * ways.
    220      *
    221      *
    222      */
    223     static private class WayReferringRelations {
    224         /**
    225          * the map references between relations and ways. The key is a ways, the value is a
    226          * set of relations referring to that way.
    227          */
    228         private Map<Way, Set<Relation>> wayRelationMap;
    229 
    230         /**
    231          *
    232          * @param ways  a collection of ways
    233          */
    234         public WayReferringRelations(Collection<Way> ways) {
    235             wayRelationMap = new HashMap<Way, Set<Relation>>();
    236             if (ways == null) return;
    237             ways.remove(null); // just in case - remove null values
    238             for (Way way: ways) {
    239                 if (!wayRelationMap.containsKey(way)) {
    240                     wayRelationMap.put(way, new HashSet<Relation>());
    241                 }
    242             }
    243         }
    244 
    245         /**
    246          * build the sets of referring relations from the relations in the dataset <code>ds</code>
    247          *
    248          * @param ds the data set
    249          */
    250         public void build(DataSet ds) {
    251             for (Relation r : ds.getRelations()) {
    252                 if (!r.isUsable()) {
    253                     continue;
    254                 }
    255                 Set<Way> referringWays = OsmPrimitive.getFilteredSet(r.getMemberPrimitives(), Way.class);
    256                 for (Way w : wayRelationMap.keySet()) {
    257                     if (referringWays.contains(w)) {
    258                         wayRelationMap.get(w).add(r);
    259                     }
    260                 }
    261             }
    262         }
    263 
    264         /**
    265          * Replies the ways
    266          * @return the ways
    267          */
    268         public Set<Way> getWays() {
    269             return wayRelationMap.keySet();
    270         }
    271 
    272         /**
    273          * Replies the set of referring relations
    274          *
    275          * @return the set of referring relations
    276          */
    277         public Set<Relation> getRelations() {
    278             HashSet<Relation> ret = new HashSet<Relation>();
    279             for (Way w: wayRelationMap.keySet()) {
    280                 ret.addAll(wayRelationMap.get(w));
    281             }
    282             return ret;
    283         }
    284 
    285         /**
    286          * Replies the set of referring relations for a specific way
    287          *
    288          * @return the set of referring relations
    289          */
    290         public Set<Relation> getRelations(Way way) {
    291             return wayRelationMap.get(way);
    292         }
    293 
    294         protected Command buildRelationUpdateCommand(Relation relation, Collection<Way> ways, Way targetWay) {
    295             List<RelationMember> newMembers = new ArrayList<RelationMember>();
    296             for (RelationMember rm : relation.getMembers()) {
    297                 if (ways.contains(rm.getMember())) {
    298                     RelationMember newMember = new RelationMember(rm.getRole(),targetWay);
    299                     newMembers.add(newMember);
    300                 } else {
    301                     newMembers.add(rm);
    302                 }
    303             }
    304             Relation newRelation = new Relation(relation);
    305             newRelation.setMembers(newMembers);
    306             return new ChangeCommand(relation, newRelation);
    307         }
    308 
    309         public List<Command> buildRelationUpdateCommands(Way targetWay) {
    310             Collection<Way> toRemove = getWays();
    311             toRemove.remove(targetWay);
    312             ArrayList<Command> cmds = new ArrayList<Command>();
    313             for (Relation r : getRelations()) {
    314                 Command cmd = buildRelationUpdateCommand(r, toRemove, targetWay);
    315                 cmds.add(cmd);
    316             }
    317             return cmds;
    318         }
    319221    }
    320222
Note: See TracChangeset for help on using the changeset viewer.