Changeset 29509 in osm for applications/editors/josm/plugins/terracer/src
- Timestamp:
- 2013-04-17T23:02:35+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/terracer/src/terracer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
r29035 r29509 27 27 import org.openstreetmap.josm.Main; 28 28 import org.openstreetmap.josm.actions.JosmAction; 29 import org.openstreetmap.josm.corrector.UserCancelException; 29 30 import org.openstreetmap.josm.data.osm.Node; 30 31 import org.openstreetmap.josm.data.osm.Relation; … … 304 305 saveValues(); 305 306 306 terracerAction.terraceBuilding( 307 outline, 308 init, 309 street, 310 associatedStreet, 311 segments(), 312 dialog.lo.getText(), 313 dialog.hi.getText(), 314 stepSize(), 315 housenumbers, 316 streetName(), 317 doHandleRelation(), 318 doDeleteOutline()); 307 try { 308 terracerAction.terraceBuilding( 309 outline, 310 init, 311 street, 312 associatedStreet, 313 segments(), 314 dialog.lo.getText(), 315 dialog.hi.getText(), 316 stepSize(), 317 housenumbers, 318 streetName(), 319 doHandleRelation(), 320 doDeleteOutline()); 321 } catch (UserCancelException ex) { 322 // Ignore 323 } 319 324 320 325 this.dialog.dispose(); -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r29050 r29509 14 14 import java.awt.event.KeyEvent; 15 15 import java.util.ArrayList; 16 import java.util.Arrays; 16 17 import java.util.Collection; 17 18 import java.util.Collections; … … 21 22 import java.util.LinkedList; 22 23 import java.util.List; 23 import java.util.Map.Entry;24 24 import java.util.Set; 25 25 import java.util.regex.Matcher; … … 36 36 import org.openstreetmap.josm.command.DeleteCommand; 37 37 import org.openstreetmap.josm.command.SequenceCommand; 38 import org.openstreetmap.josm.corrector.UserCancelException; 38 39 import org.openstreetmap.josm.data.osm.Node; 39 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 40 41 import org.openstreetmap.josm.data.osm.Relation; 41 42 import org.openstreetmap.josm.data.osm.RelationMember; 43 import org.openstreetmap.josm.data.osm.Tag; 42 44 import org.openstreetmap.josm.data.osm.TagCollection; 43 45 import org.openstreetmap.josm.data.osm.Way; 44 46 import org.openstreetmap.josm.gui.ExtendedDialog; 47 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 45 48 import org.openstreetmap.josm.tools.Pair; 46 49 import org.openstreetmap.josm.tools.Shortcut; … … 216 219 if (housenumbers.size() == 1) { 217 220 // Special case of one outline and one address node. 218 // Don't open the dialogue 219 terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0, housenumbers, streetname, associatedStreet != null, false); 221 // Don't open the dialog 222 try { 223 terraceBuilding(outline, init, street, associatedStreet, 0, null, null, 0, housenumbers, streetname, associatedStreet != null, false); 224 } catch (UserCancelException ex) { 225 // Ignore 226 } finally { 227 this.commands.clear(); 228 this.commands = null; 229 } 220 230 } else { 221 String title = trn("Change {0} object", "Change {0} objects", sel 222 .size(), sel.size()); 231 String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()); 223 232 // show input dialog. 224 233 new HouseNumberInputHandler(this, outline, init, street, streetname, … … 303 312 * existing relation 304 313 * @param deleteOutline If the outline way should be deleted when done 314 * @throws UserCancelException 305 315 */ 306 316 public void terraceBuilding(Way outline, … … 315 325 String streetName, 316 326 boolean handleRelations, 317 boolean deleteOutline) {327 boolean deleteOutline) throws UserCancelException { 318 328 final int nb; 319 329 Integer to = null, from = null; … … 386 396 // add the tags of the outline to each building (e.g. source=*) 387 397 TagCollection.from(outline).applyTo(terr); 388 389 String number = null; 390 Set<Entry<String, String>> additionalKeys = null; 391 if (housenumbers.isEmpty()) { 392 if (from != null) { 393 // only, if the user has specified house numbers 394 number = Integer.toString(from + i * step); 395 } 396 } else { 397 number = housenumbers.get(i).get("addr:housenumber"); 398 additionalKeys = housenumbers.get(i).getKeys().entrySet(); 399 } 400 401 addressBuilding(terr, street, streetName, number, additionalKeys, associatedStreet); 402 403 ways.add(terr); 398 ways.add(addressBuilding(terr, street, streetName, associatedStreet, housenumbers, i, 399 from != null ? Integer.toString(from + i * step) : null)); 400 404 401 this.commands.add(new AddCommand(terr)); 405 402 } … … 420 417 } else { 421 418 // Single building, just add the address details 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, associatedStreet); 432 ways.add(outline); 419 ways.add(addressBuilding(outline, street, streetName, associatedStreet, housenumbers, 0, From)); 433 420 } 434 421 … … 478 465 } 479 466 } 480 467 481 468 /** 482 469 * Adds address details to a single building … … 485 472 * @param street The street, the buildings belong to (may be null) 486 473 * @param streetName the name of a street (may be null). Used if not null and street is null. 487 * @param number The house number488 * @param additionalKeys More keys to be copied onto the new outline489 474 * @param associatedStreet The associated street. Used to determine if addr:street should be set or not. 490 */ 491 private void addressBuilding(Way outline, Way street, String streetName, 492 String number, Set<Entry<String, String>> additionalKeys, Relation associatedStreet) { 493 if (number != null) { 494 // only, if the user has specified house numbers 495 this.commands.add(new ChangePropertyCommand(outline, "addr:housenumber", number)); 496 } 475 * @return {@code outline} 476 * @throws UserCancelException 477 */ 478 private Way addressBuilding(Way outline, Way street, String streetName, Relation associatedStreet, ArrayList<Node> housenumbers, int i, String defaultNumber) throws UserCancelException { 479 Node houseNum = (housenumbers != null && i >= 0 && i < housenumbers.size()) ? housenumbers.get(i) : null; 497 480 boolean buildingAdded = false; 498 if (additionalKeys != null) { 499 for (Entry<String, String> entry : additionalKeys) { 500 String key = entry.getKey(); 501 if ("building".equals(key)) { 502 buildingAdded = true; 503 } 504 this.commands.add(new ChangePropertyCommand(outline, key, entry.getValue())); 505 } 481 boolean numberAdded = false; 482 if (houseNum != null) { 483 Collection<OsmPrimitive> primitives = Arrays.asList(new OsmPrimitive[]{houseNum, outline}); 484 485 TagCollection tagsToCopy = TagCollection.unionOfAllPrimitives(primitives).getTagsFor(houseNum.keySet()); 486 TagCollection tagsInConflict = tagsToCopy.getTagsFor(tagsToCopy.getKeysWithMultipleValues()); 487 tagsToCopy = tagsToCopy.minus(tagsInConflict).minus(TagCollection.from(outline)); 488 489 for (Tag tag : tagsToCopy) { 490 this.commands.add(new ChangePropertyCommand(outline, tag.getKey(), tag.getValue())); 491 } 492 493 this.commands.addAll(CombinePrimitiveResolverDialog.launchIfNecessary( 494 tagsInConflict, primitives, Collections.singleton(outline))); 495 496 buildingAdded = houseNum.hasKey("building"); 497 numberAdded = houseNum.hasKey("addr:housenumber"); 506 498 } 507 499 if (!outline.hasKey("building") && !buildingAdded) { 508 500 this.commands.add(new ChangePropertyCommand(outline, "building", "yes")); 501 } 502 if (defaultNumber != null && !numberAdded) { 503 this.commands.add(new ChangePropertyCommand(outline, "addr:housenumber", defaultNumber)); 509 504 } 510 505 // Only put addr:street if no relation exists or if it has no name … … 516 511 } 517 512 } 513 return outline; 518 514 } 519 515
Note:
See TracChangeset
for help on using the changeset viewer.