Changeset 29047 in osm for applications/editors/josm
- Timestamp:
- 2012-12-05T23:27:19+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/terracer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/build.xml
r29035 r29047 2 2 <project name="terracer" default="dist" basedir="."> 3 3 <property name="commit.message" value="applied #j5760 (patch by robome) - Order of housenumbers not correct"/> 4 <property name="plugin.main.version" value=" 4980"/>4 <property name="plugin.main.version" value="5613"/> 5 5 6 6 <property name="plugin.author" value="Matt Amos"/> -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r29037 r29047 17 17 import java.util.Collections; 18 18 import java.util.Comparator; 19 import java.util.HashSet; 19 20 import java.util.Iterator; 20 21 import java.util.LinkedList; … … 75 76 } 76 77 78 protected static final Set<Relation> findAssociatedStreets(Collection<OsmPrimitive> objects) { 79 Set<Relation> result = new HashSet<Relation>(); 80 if (objects != null) { 81 for (OsmPrimitive c : objects) { 82 if (c != null) { 83 for (OsmPrimitive p : c.getReferrers()) { 84 if (p instanceof Relation && "associatedStreet".equals(p.get("type"))) { 85 result.add((Relation) p); 86 } 87 } 88 } 89 } 90 } 91 return result; 92 } 93 77 94 /** 78 95 * Checks that the selection is OK. If not, displays error message. If so … … 176 193 Relation associatedStreet = null; 177 194 178 // Try to find an associatedStreet relation that could be reused from outline. 179 for (OsmPrimitive p : outline.getReferrers()) { 180 if (p instanceof Relation) { 181 Relation rel = (Relation) p; 182 if ("associatedStreet".equals(rel.get("type"))) { 183 associatedStreet = rel; 184 break; 185 } 186 } 195 // Try to find an associatedStreet relation that could be reused from housenumbers, outline and street. 196 Set<OsmPrimitive> candidates = new HashSet<OsmPrimitive>(housenumbers); 197 candidates.add(outline); 198 if (street != null) { 199 candidates.add(street); 187 200 } 188 201 189 // If we have a street, try to find an associatedStreet relation that could be reused. 190 if (associatedStreet == null && street != null) { 191 outer:for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) { 192 if (!(osm instanceof Relation)) continue; 193 Relation rel = (Relation) osm; 194 if ("associatedStreet".equals(rel.get("type")) && street.get("name").equals(rel.get("name"))) { 195 List<RelationMember> members = rel.getMembers(); 196 for (RelationMember m : members) { 197 if ("street".equals(m.getRole()) && m.isWay() && m.getMember().equals(street)) { 198 associatedStreet = rel; 199 break outer; 200 } 201 } 202 } 203 } 202 Set<Relation> associatedStreets = findAssociatedStreets(candidates); 203 204 if (!associatedStreets.isEmpty()) { 205 associatedStreet = associatedStreets.iterator().next(); 206 if (associatedStreets.size() > 1) { 207 // TODO: Deal with multiple associated Streets 208 System.out.println("Terracer warning: Found "+associatedStreets.size()+" associatedStreet relations. Considering the first one only."); 209 } 210 } 211 212 if (streetname == null && associatedStreet != null && associatedStreet.hasKey("name")) { 213 streetname = associatedStreet.get("name"); 204 214 } 205 215 206 216 if (housenumbers.size() == 1) { 207 217 // Special case of one outline and one address node. 208 // Don't open the dialogue, just copy the node keys 209 // to the outline, set building just in case it isn't there 210 // and remove the node. 211 Collection<Command> commands = new LinkedList<Command>(); 212 Way newOutline = new Way(outline); 213 for (Entry<String, String> entry : housenumbers.get(0).getKeys() 214 .entrySet()) { 215 newOutline.put(entry.getKey(), entry.getValue()); 216 } 217 newOutline.put("building", "yes"); 218 commands.add(new ChangeCommand(outline, newOutline)); 219 commands.add(DeleteCommand.delete(Main.main.getEditLayer(), 220 housenumbers, true, true)); 221 Main.main.undoRedo 222 .add(new SequenceCommand(tr("Terrace"), commands)); 223 Main.main.getCurrentDataSet().setSelected(newOutline); 218 // Don't open the dialogue 219 terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0, housenumbers, streetname, associatedStreet != null, false); 224 220 } else { 225 221 String title = trn("Change {0} object", "Change {0} objects", sel … … 322 318 final int nb; 323 319 Integer to = null, from = null; 324 if (housenumbers .isEmpty()) {320 if (housenumbers == null || housenumbers.isEmpty()) { 325 321 to = getNumber(To); 326 322 from = getNumber(From); … … 403 399 } 404 400 405 terr = addressBuilding(terr, street, streetName, number, 406 additionalKeys); 401 addressBuilding(terr, street, streetName, number, additionalKeys); 407 402 408 403 ways.add(terr); … … 425 420 } else { 426 421 // Single building, just add the address details 427 Way newOutline; 428 newOutline = addressBuilding(outline, street, streetName, From, null); 429 ways.add(newOutline); 430 this.commands.add(new ChangeCommand(outline, newOutline)); 422 String number = null; 423 if (housenumbers == null || housenumbers.isEmpty()) { 424 number = From; 425 } else { 426 Node firstHouseNum = housenumbers.iterator().next(); 427 if (firstHouseNum != null) { 428 number = firstHouseNum.get("addr:housenumber"); 429 } 430 } 431 addressBuilding(outline, street, streetName, number, null); 432 ways.add(outline); 433 } 434 435 // Remove the address nodes since their tags have been incorporated into 436 // the terraces. 437 // Or should removing them also be an option? 438 if (!housenumbers.isEmpty()) { 439 commands.add(DeleteCommand.delete(Main.main.getEditLayer(), 440 housenumbers, true, true)); 431 441 } 432 442 … … 447 457 } else { // relation exists already - add new members 448 458 Relation newAssociatedStreet = new Relation(associatedStreet); 459 // remove housenumbers as they have been deleted 460 newAssociatedStreet.removeMembersFor(housenumbers); 449 461 for (Way w : ways) { 450 462 newAssociatedStreet.addMember(new RelationMember("house", w)); … … 457 469 } 458 470 459 // Remove the address node since their tags have been incorporated into460 // the terraces.461 // Or should removing them also be an option?462 if (!housenumbers.isEmpty())463 commands.add(DeleteCommand.delete(Main.main.getEditLayer(),464 housenumbers, true, true));465 466 471 Main.main.undoRedo.add(new SequenceCommand(tr("Terrace"), commands)); 467 if (nb > 1) { 472 if (nb <= 1 && street != null) { 473 // Select the way (for quick selection of a new house (with the same way)) 474 Main.main.getCurrentDataSet().setSelected(street); 475 } else { 468 476 // Select the new building outlines (for quick reversing) 469 477 Main.main.getCurrentDataSet().setSelected(ways); 470 } else if (street != null) {471 // Select the way (for quick selection of a new house (with the same way))472 Main.main.getCurrentDataSet().setSelected(street);473 478 } 474 479 } … … 482 487 * @param number The house number 483 488 * @param additionalKeys More keys to be copied onto the new outline 484 * @return the way with added address details 485 */ 486 private Way addressBuilding(Way outline, Way street, String streetName, 489 */ 490 private void addressBuilding(Way outline, Way street, String streetName, 487 491 String number, Set<Entry<String, String>> additionalKeys) { 488 Way changedOutline = outline;489 492 if (number != null) { 490 493 // only, if the user has specified house numbers 491 this.commands.add(new ChangePropertyCommand(changedOutline, "addr:housenumber", number)); 492 } 494 this.commands.add(new ChangePropertyCommand(outline, "addr:housenumber", number)); 495 } 496 boolean buildingAdded = false; 493 497 if (additionalKeys != null) { 494 498 for (Entry<String, String> entry : additionalKeys) { 495 this.commands.add(new ChangePropertyCommand(changedOutline, 496 entry.getKey(), entry.getValue())); 497 } 498 } 499 changedOutline.put("building", "yes"); 499 String key = entry.getKey(); 500 if ("building".equals(key)) { 501 buildingAdded = true; 502 } 503 this.commands.add(new ChangePropertyCommand(outline, key, entry.getValue())); 504 } 505 } 506 if (!outline.hasKey("building") && !buildingAdded) { 507 this.commands.add(new ChangePropertyCommand(outline, "building", "yes")); 508 } 500 509 if (street != null) { 501 this.commands.add(new ChangePropertyCommand(changedOutline, "addr:street", street.get("name"))); 502 } else if (streetName != null) { 503 this.commands.add(new ChangePropertyCommand(changedOutline, "addr:street", streetName)); 504 } 505 return changedOutline; 510 this.commands.add(new ChangePropertyCommand(outline, "addr:street", street.get("name"))); 511 } else if (streetName != null && !streetName.trim().isEmpty()) { 512 this.commands.add(new ChangePropertyCommand(outline, "addr:street", streetName.trim())); 513 } 506 514 } 507 515
Note:
See TracChangeset
for help on using the changeset viewer.