- Timestamp:
- 2009-12-03T19:51:27+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r2512 r2564 3 3 4 4 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 5 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing; 7 6 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing; 7 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 8 8 import static org.openstreetmap.josm.tools.I18n.tr; 9 9 … … 17 17 import java.util.LinkedList; 18 18 import java.util.List; 19 import java.util.Map;20 19 import java.util.Set; 21 20 import java.util.Stack; … … 29 28 import org.openstreetmap.josm.command.DeleteCommand; 30 29 import org.openstreetmap.josm.command.SequenceCommand; 31 import org.openstreetmap.josm.data.osm.DataSet;32 30 import org.openstreetmap.josm.data.osm.Node; 33 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 34 32 import org.openstreetmap.josm.data.osm.Relation; 35 import org.openstreetmap.josm.data.osm.RelationMember;36 33 import org.openstreetmap.josm.data.osm.TagCollection; 37 34 import org.openstreetmap.josm.data.osm.Way; … … 90 87 } 91 88 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 92 102 public void combineWays(Collection<Way> ways) { 93 103 … … 98 108 ways.remove(null); // just in case - remove all null ways from the collection 99 109 ways = new HashSet<Way>(ways); // remove duplicates 100 101 // build the list of relations referring to the ways to combine102 //103 WayReferringRelations referringRelations = new WayReferringRelations(ways);104 referringRelations.build(getCurrentDataSet());105 110 106 111 // build the collection of tags used by the ways to combine … … 140 145 dialog.getTagConflictResolverModel().populate(tagsToEdit, completeWayTags.getKeysWithMultipleValues()); 141 146 dialog.setTargetPrimitive(targetWay); 147 Set<Relation> parentRelations = getParentRelations(ways); 142 148 dialog.getRelationMemberConflictResolverModel().populate( 143 referringRelations.getRelations(),144 referringRelations.getWays()149 parentRelations, 150 ways 145 151 ); 146 152 dialog.prepareDefaultDecisions(); … … 148 154 // resolve tag conflicts if necessary 149 155 // 150 if (!completeWayTags.isApplicableToPrimitive() || ! referringRelations.getRelations().isEmpty()) {156 if (!completeWayTags.isApplicableToPrimitive() || !parentRelations.isEmpty()) { 151 157 dialog.setVisible(true); 152 158 if (dialog.isCancelled()) … … 213 219 } 214 220 setEnabled(numWays >= 2); 215 }216 217 /**218 * This is a collection of relations referring to at least one out of a set of219 * 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 a226 * set of relations referring to that way.227 */228 private Map<Way, Set<Relation>> wayRelationMap;229 230 /**231 *232 * @param ways a collection of ways233 */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 values238 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 set249 */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 ways266 * @return the ways267 */268 public Set<Way> getWays() {269 return wayRelationMap.keySet();270 }271 272 /**273 * Replies the set of referring relations274 *275 * @return the set of referring relations276 */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 way287 *288 * @return the set of referring relations289 */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 }319 221 } 320 222
Note:
See TracChangeset
for help on using the changeset viewer.