Changeset 406 in josm
- Timestamp:
- 2007-10-19T12:38:34+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r343 r406 34 34 import org.openstreetmap.josm.data.osm.DataSet; 35 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 36 import org.openstreetmap.josm.data.osm.Relation; 37 import org.openstreetmap.josm.data.osm.RelationMember; 36 38 import org.openstreetmap.josm.data.osm.Way; 37 39 import org.openstreetmap.josm.data.osm.Node; … … 62 64 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least two ways to combine.")); 63 65 return; 66 } 67 68 // Check whether all ways have identical relationship membership. More 69 // specifically: If one of the selected ways is a member of relation X 70 // in role Y, then all selected ways must be members of X in role Y. 71 72 // FIXME: In a later revision, we should display some sort of conflict 73 // dialog like we do for tags, to let the user choose which relations 74 // should be kept. 75 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>(); 80 HashSet<Relation> relationsUsingWays = new HashSet<Relation>(); 81 for (Relation r : Main.ds.relations) { 82 if (r.deleted) continue; 83 for (RelationMember rm : r.members) { 84 if (rm.member instanceof Way) { 85 for(Way w : selectedWays) { 86 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)); 91 } else { 92 backlinks.put(hash, 1); 93 } 94 // this is just a cache for later use 95 relationsUsingWays.add(r); 96 } 97 } 98 } 99 } 100 } 101 102 // Step 2, all values of the backlinks HashMap must now equal the size 103 // of the selection. 104 for (Integer i : backlinks.values()) { 105 if (i.intValue() != selectedWays.size()) { 106 JOptionPane.showMessageDialog(Main.parent, tr("The selected ways cannot be combined as they have differing relation memberships.")); 107 return; 108 } 64 109 } 65 110 … … 113 158 newWay.put(e.getKey(), e.getValue().iterator().next()); 114 159 } 160 115 161 if (!components.isEmpty()) { 116 162 int answer = JOptionPane.showConfirmDialog(Main.parent, p, tr("Enter values for all conflicts."), JOptionPane.OK_CANCEL_OPTION); … … 124 170 cmds.add(new DeleteCommand(selectedWays.subList(1, selectedWays.size()))); 125 171 cmds.add(new ChangeCommand(selectedWays.peek(), newWay)); 172 173 // modify all relations containing the now-deleted ways 174 for (Relation r : relationsUsingWays) { 175 Relation newRel = new Relation(r); 176 newRel.members.clear(); 177 for (RelationMember rm : r.members) { 178 // only copy member if it is either the first of all the selected 179 // ways (indexOf==0) or not one if the selected ways (indexOf==-1) 180 if (selectedWays.indexOf(rm.member) < 1) { 181 newRel.members.add(new RelationMember(rm)); 182 } 183 } 184 cmds.add(new ChangeCommand(r, newRel)); 185 } 126 186 Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds)); 127 187 Main.ds.setSelected(selectedWays.peek()); … … 195 255 return tr("Could not combine ways " 196 256 + "(They could not be merged into a single string of nodes)"); 197 } else {198 return nodeList;199 }257 } 258 259 return nodeList; 200 260 } 201 261
Note:
See TracChangeset
for help on using the changeset viewer.