Changeset 426 in josm


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

Allow to combine ways with different memberships.

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

Legend:

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

    r425 r426  
    7676                Collection<OsmPrimitive> selection = Main.ds.getSelected(); 
    7777                LinkedList<Way> selectedWays = new LinkedList<Way>(); 
    78                  
     78 
    7979                for (OsmPrimitive osm : selection) 
    8080                        if (osm instanceof Way) 
     
    8585                        return; 
    8686                } 
    87                  
    88                 // Check whether all ways have identical relationship membership. More  
     87 
     88                // Check whether all ways have identical relationship membership. More 
    8989                // specifically: If one of the selected ways is a member of relation X 
    9090                // in role Y, then all selected ways must be members of X in role Y. 
    91                  
    92                 // FIXME: In a later revision, we should display some sort of conflict  
     91 
     92                // FIXME: In a later revision, we should display some sort of conflict 
    9393                // dialog like we do for tags, to let the user choose which relations 
    9494                // should be kept. 
    95                  
     95 
    9696                // Step 1, iterate over all relations and figure out which of our 
    9797                // selected ways are members of a relation. 
     
    122122                        } 
    123123                } 
    124                  
    125                 // Step 2, all values of the backlinks HashMap must now equal the size 
    126                 // of the selection. 
     124 
     125                // Complain to the user if the ways don't have equal memberships. 
    127126                for (HashSet<Way> waylinks : backlinks.values()) { 
    128                         if (!selectedWays.equals(waylinks)) { 
    129                                 JOptionPane.showMessageDialog(Main.parent, tr("The selected ways cannot be combined as they have differing relation memberships.")); 
    130                                 return; 
     127                        if (!waylinks.containsAll(selectedWays)) { 
     128                                int option = JOptionPane.showConfirmDialog(Main.parent, 
     129                                        tr("The selected ways have differing relation memberships.  " 
     130                                                + "Do you still want to combine them?"), 
     131                                        tr("Combine ways with different memberships?"), 
     132                                        JOptionPane.YES_NO_OPTION); 
     133                                if (option == JOptionPane.YES_OPTION) { 
     134                                        break; 
     135                                } else { 
     136                                        return; 
     137                                } 
    131138                        } 
    132139                } 
     
    166173                newWay.nodes.clear(); 
    167174                newWay.nodes.addAll(nodeList); 
    168                  
     175 
    169176                // display conflict dialog 
    170177                Map<String, JComboBox> components = new HashMap<String, JComboBox>(); 
     
    181188                                newWay.put(e.getKey(), e.getValue().iterator().next()); 
    182189                } 
    183                  
     190 
    184191                if (!components.isEmpty()) { 
    185192                        int answer = JOptionPane.showConfirmDialog(Main.parent, p, tr("Enter values for all conflicts."), JOptionPane.OK_CANCEL_OPTION); 
     
    193200                cmds.add(new DeleteCommand(selectedWays.subList(1, selectedWays.size()))); 
    194201                cmds.add(new ChangeCommand(selectedWays.peek(), newWay)); 
    195                  
     202 
    196203                // modify all relations containing the now-deleted ways 
    197204                for (Relation r : relationsUsingWays) { 
    198205                        Relation newRel = new Relation(r); 
    199206                        newRel.members.clear(); 
     207                        HashSet<String> rolesToReAdd = new HashSet<String>(); 
    200208                        for (RelationMember rm : r.members) { 
    201                                 // only copy member if it is either the first of all the selected 
    202                                 // ways (indexOf==0) or not one if the selected ways (indexOf==-1) 
    203                                 if (selectedWays.indexOf(rm.member) < 1) { 
    204                                         newRel.members.add(new RelationMember(rm)); 
    205                                 } 
     209                                // Don't copy the member if it to one of our ways, just keep a 
     210                                // note to re-add it later on. 
     211                                if (selectedWays.contains(rm.member)) { 
     212                                        rolesToReAdd.add(rm.role); 
     213                                } else { 
     214                                        newRel.members.add(rm); 
     215                                } 
     216                        } 
     217                        for (String role : rolesToReAdd) { 
     218                                newRel.members.add(new RelationMember(role, selectedWays.peek())); 
    206219                        } 
    207220                        cmds.add(new ChangeCommand(r, newRel)); 
     
    224237                //     complain to the user. 
    225238                //  4. Profit! 
    226                  
     239 
    227240                HashSet<NodePair> chunkSet = new HashSet<NodePair>(); 
    228241                for (Way w : ways) { 
     
    278291                        return tr("Could not combine ways " 
    279292                                + "(They could not be merged into a single string of nodes)"); 
    280                 }  
    281                  
     293                } 
     294 
    282295                return nodeList; 
    283296        } 
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r369 r426  
    1717         */ 
    1818        public RelationMember() { }; 
     19 
     20        public RelationMember(String role, OsmPrimitive member) { 
     21                this.role = role; 
     22                this.member = member; 
     23        } 
    1924         
    2025        /** 
Note: See TracChangeset for help on using the changeset viewer.