Changeset 425 in josm


Ignore:
Timestamp:
Oct 26, 2007 9:14:14 AM (6 years ago)
Author:
gebner
Message:

Fix combining of ways that are members of not-yet-uploaded relations.

File:
1 edited

Legend:

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

    r407 r425  
    5353        } 
    5454 
     55        private static class RelationRolePair { 
     56                public Relation rel; 
     57                public String role; 
     58 
     59                public RelationRolePair(Relation rel, String role) { 
     60                        this.rel = rel; 
     61                        this.role = role; 
     62                } 
     63 
     64                @Override public boolean equals(Object o) { 
     65                        return o instanceof RelationRolePair 
     66                                && rel == ((RelationRolePair) o).rel 
     67                                && role.equals(((RelationRolePair) o).role); 
     68                } 
     69 
     70                @Override public int hashCode() { 
     71                        return rel.hashCode() ^ role.hashCode(); 
     72                } 
     73        } 
     74 
    5575        public void actionPerformed(ActionEvent event) { 
    5676                Collection<OsmPrimitive> selection = Main.ds.getSelected(); 
     
    7494                // should be kept. 
    7595                 
    76                 // Step 1, iterate over all relations and create counters indicating 
    77                 // how many of the selected ways are part of relation X in role Y 
    78                 // (hashMap backlinks contains keys formed like X@Y) 
    79                 HashMap<String, Integer> backlinks = new HashMap<String, Integer>(); 
     96                // Step 1, iterate over all relations and figure out which of our 
     97                // selected ways are members of a relation. 
     98                HashMap<RelationRolePair, HashSet<Way>> backlinks = 
     99                        new HashMap<RelationRolePair, HashSet<Way>>(); 
    80100                HashSet<Relation> relationsUsingWays = new HashSet<Relation>(); 
    81101                for (Relation r : Main.ds.relations) { 
     
    85105                                        for(Way w : selectedWays) { 
    86106                                                if (rm.member == w) { 
    87                                                         String hash = Long.toString(r.id) + "@" + rm.role; 
    88                                                         System.out.println(hash); 
    89                                                         if (backlinks.containsKey(hash)) { 
    90                                                                 backlinks.put(hash, new Integer(backlinks.get(hash)+1)); 
     107                                                        RelationRolePair pair = new RelationRolePair(r, rm.role); 
     108                                                        HashSet<Way> waylinks = new HashSet<Way>(); 
     109                                                        if (backlinks.containsKey(pair)) { 
     110                                                                waylinks = backlinks.get(pair); 
    91111                                                        } else { 
    92                                                                 backlinks.put(hash, 1); 
     112                                                                waylinks = new HashSet<Way>(); 
     113                                                                backlinks.put(pair, waylinks); 
    93114                                                        } 
     115                                                        waylinks.add(w); 
     116 
    94117                                                        // this is just a cache for later use 
    95118                                                        relationsUsingWays.add(r); 
     
    102125                // Step 2, all values of the backlinks HashMap must now equal the size 
    103126                // of the selection. 
    104                 for (Integer i : backlinks.values()) { 
    105                         if (i.intValue() != selectedWays.size()) { 
     127                for (HashSet<Way> waylinks : backlinks.values()) { 
     128                        if (!selectedWays.equals(waylinks)) { 
    106129                                JOptionPane.showMessageDialog(Main.parent, tr("The selected ways cannot be combined as they have differing relation memberships.")); 
    107                                 return;                          
     130                                return; 
    108131                        } 
    109132                } 
Note: See TracChangeset for help on using the changeset viewer.