Changeset 30872 in osm
- Timestamp:
- 2014-12-21T13:55:57+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/terracer/src/terracer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java
r30737 r30872 55 55 final static String DEFAULT_SEGMENTS = "plugins.terracer.segments"; 56 56 final static String HANDLE_RELATION = "plugins.terracer.handle_relation"; 57 final static String DELETE_OUTLINE = "plugins.terracer.delete_outline";57 final static String KEEP_OUTLINE = "plugins.terracer.keep_outline"; 58 58 final static String INTERPOLATION = "plugins.terracer.interpolation"; 59 59 … … 83 83 Choice interpolation; 84 84 JCheckBox handleRelationCheckBox; 85 JCheckBox deleteOutlineCheckBox;85 JCheckBox keepOutlineCheckBox; 86 86 87 87 HouseNumberInputHandler inputHandler; … … 182 182 183 183 handleRelationCheckBox = new JCheckBox(txt, relationExists ? Main.pref.getBoolean(HANDLE_RELATION, true) : false); 184 deleteOutlineCheckBox = new JCheckBox(tr("delete outline way"), Main.pref.getBoolean(DELETE_OUTLINE, true));184 keepOutlineCheckBox = new JCheckBox(tr("keep outline way"), Main.pref.getBoolean(KEEP_OUTLINE, false)); 185 185 186 186 inputPanel = new JPanel(); … … 209 209 inputPanel.add(getBuilding(), GBC.eol().insets(5,3,0,0)); 210 210 inputPanel.add(handleRelationCheckBox, GBC.eol().insets(3,3,0,0)); 211 inputPanel.add( deleteOutlineCheckBox, GBC.eol().insets(3,3,0,0));212 211 inputPanel.add(keepOutlineCheckBox, GBC.eol().insets(3,3,0,0)); 212 213 213 if (numbers.isVisible()) { 214 214 loLabel.setVisible(false); … … 261 261 return hi; 262 262 } 263 263 264 264 /** 265 265 * This method initializes numbers … … 270 270 if (numbers == null) { 271 271 numbers = new JTextField(); 272 272 273 273 Iterator<Node> it = housenumbers.iterator(); 274 274 StringBuilder s = new StringBuilder(256); … … 282 282 numbers.setVisible(false); 283 283 } 284 284 285 285 numbers.setText(s.toString()); 286 286 numbers.setEditable(false); … … 306 306 return streetComboBox; 307 307 } 308 308 309 309 /** 310 310 * This method initializes building -
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
r30643 r30872 304 304 streetName(), 305 305 doHandleRelation(), 306 do DeleteOutline(), buildingType());306 doKeepOutline(), buildingType()); 307 307 } catch (UserCancelException ex) { 308 308 // Ignore … … 380 380 return getItemText(dialog.streetComboBox); 381 381 } 382 382 383 383 /** 384 384 * Gets the building type. … … 389 389 return getItemText(dialog.buildingComboBox); 390 390 } 391 391 392 392 private static String getItemText(AutoCompletingComboBox box) { 393 393 Object selected = box.getSelectedItem(); … … 430 430 431 431 /** 432 * Whether the user likes to deletethe outline way.433 */ 434 public boolean do DeleteOutline() {435 return dialog. deleteOutlineCheckBox.isSelected();432 * Whether the user likes to keep the outline way. 433 */ 434 public boolean doKeepOutline() { 435 return dialog.keepOutlineCheckBox.isSelected(); 436 436 } 437 437 … … 454 454 public void saveValues() { 455 455 Main.pref.put(HouseNumberInputDialog.HANDLE_RELATION, doHandleRelation()); 456 Main.pref.put(HouseNumberInputDialog. DELETE_OUTLINE, doDeleteOutline());456 Main.pref.put(HouseNumberInputDialog.KEEP_OUTLINE, doKeepOutline()); 457 457 Main.pref.put(HouseNumberInputDialog.INTERPOLATION, stepSize().toString()); 458 458 } -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r30737 r30872 69 69 70 70 Collection<Command> commands; 71 71 72 72 private Collection<OsmPrimitive> primitives; 73 73 private TagCollection tagsInConflict; … … 96 96 return result; 97 97 } 98 98 99 99 private static final class InvalidUserInputException extends Exception { 100 100 InvalidUserInputException(String message) { … … 182 182 if (outline == null || !outline.isClosed() || outline.getNodesCount() < 5) 183 183 throw new InvalidUserInputException("wrong or missing outline"); 184 184 185 185 } catch (InvalidUserInputException ex) { 186 186 Main.warn("Terracer: "+ex.getMessage()); … … 202 202 candidates.add(street); 203 203 } 204 204 205 205 Set<Relation> associatedStreets = findAssociatedStreets(candidates); 206 206 207 207 if (!associatedStreets.isEmpty()) { 208 208 associatedStreet = associatedStreets.iterator().next(); … … 212 212 } 213 213 } 214 214 215 215 if (streetname == null && associatedStreet != null && associatedStreet.hasKey("name")) { 216 216 streetname = associatedStreet.get("name"); … … 297 297 * @param associatedStreet 298 298 * @param segments The number of segments to generate 299 * @param FromStarting housenumber300 * @param ToEnding housenumber299 * @param start Starting housenumber 300 * @param end Ending housenumber 301 301 * @param step The step width to use 302 302 * @param housenumbers List of housenumbers to use. From and To are ignored … … 306 306 * @param handleRelations If the user likes to add a relation or extend an 307 307 * existing relation 308 * @param deleteOutline If the outline way should be deleted when done308 * @param keepOutline If the outline way should be kept 309 309 * @param buildingValue The value for {@code building} key to add 310 * @throws UserCancelException 311 */ 312 public void terraceBuilding(final Way outline, 313 Node init, 314 Way street, 315 Relation associatedStreet, 316 Integer segments, 317 String From, 318 String To, 319 int step, 320 ArrayList<Node> housenumbers, 321 String streetName, 322 boolean handleRelations, 323 boolean deleteOutline, String buildingValue) throws UserCancelException { 310 * @throws UserCancelException 311 */ 312 public void terraceBuilding(final Way outline, Node init, Way street, Relation associatedStreet, Integer segments, 313 String start, String end, int step, List<Node> housenumbers, String streetName, boolean handleRelations, 314 boolean keepOutline, String buildingValue) throws UserCancelException { 324 315 final int nb; 325 316 Integer to = null, from = null; 326 317 if (housenumbers == null || housenumbers.isEmpty()) { 327 to = getNumber( To);328 from = getNumber( From);318 to = getNumber(end); 319 from = getNumber(start); 329 320 if (to != null && from != null) { 330 321 nb = 1 + (to.intValue() - from.intValue()) / step; … … 336 327 "Could not determine segments from parameters, this is a bug. " 337 328 + "Parameters were: segments " + segments 338 + " from " + from + " to " + to + " step " 339 + step); 329 + " from " + from + " to " + to + " step " + step); 340 330 } 341 331 } else { … … 346 336 Pair<Way, Way> interp = findFrontAndBack(outline); 347 337 348 boolean swap = false; 349 if (init != null) { 350 if (interp.a.lastNode().equals(init) || interp.b.lastNode().equals(init)) { 351 swap = true; 352 } 353 } 338 final boolean swap = init != null && (interp.a.lastNode().equals(init) || interp.b.lastNode().equals(init)); 354 339 355 340 final double frontLength = wayLength(interp.a); … … 357 342 358 343 // new nodes array to hold all intermediate nodes 359 // This set will contain at least 4 existing nodes from the original outline (those, which coordinates match coordinates of outline nodes) 360 Node[][] new_nodes = new Node[2][nb + 1]; 344 // This set will contain at least 4 existing nodes from the original outline 345 // (those, which coordinates match coordinates of outline nodes) 346 Node[][] newNodes = new Node[2][nb + 1]; 361 347 // This list will contain nodes of the outline that are used in new lines. 362 348 // These nodes will not be deleted with the outline (if deleting was prompted). 363 ArrayList<Node> reused_nodes = new ArrayList<>();349 List<Node> reusedNodes = new ArrayList<>(); 364 350 365 351 this.commands = new LinkedList<>(); … … 367 353 368 354 if (nb > 1) { 355 // add required new nodes and build list of nodes to reuse 369 356 for (int i = 0; i <= nb; ++i) { 370 int i _dir = swap ? nb - i : i;371 new _nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb);372 new _nodes[1][i] = interpolateAlong(interp.b, backLength * i_dir / nb);373 if (!outline.containsNode(new _nodes[0][i]))374 this.commands.add(new AddCommand(new _nodes[0][i]));357 int iDir = swap ? nb - i : i; 358 newNodes[0][i] = interpolateAlong(interp.a, frontLength * iDir / nb); 359 newNodes[1][i] = interpolateAlong(interp.b, backLength * iDir / nb); 360 if (!outline.containsNode(newNodes[0][i])) 361 this.commands.add(new AddCommand(newNodes[0][i])); 375 362 else 376 reused _nodes.add(new_nodes[0][i]);377 if (!outline.containsNode(new _nodes[1][i]))378 this.commands.add(new AddCommand(new _nodes[1][i]));363 reusedNodes.add(newNodes[0][i]); 364 if (!outline.containsNode(newNodes[1][i])) 365 this.commands.add(new AddCommand(newNodes[1][i])); 379 366 else 380 reused _nodes.add(new_nodes[1][i]);367 reusedNodes.add(newNodes[1][i]); 381 368 } 382 369 383 370 // assemble new quadrilateral, closed ways 384 371 for (int i = 0; i < nb; ++i) { 385 Way terr = new Way(); 386 terr.addNode(new_nodes[0][i]); 387 terr.addNode(new_nodes[0][i + 1]); 388 terr.addNode(new_nodes[1][i + 1]); 389 terr.addNode(new_nodes[1][i]); 390 terr.addNode(new_nodes[0][i]); 391 392 // add the tags of the outline to each building (e.g. source=*) 393 TagCollection.from(outline).applyTo(terr); 394 ways.add(addressBuilding(terr, street, streetName, associatedStreet, housenumbers, i, 372 final Way terr; 373 if (i > 0 || keepOutline) { 374 terr = new Way(); 375 // add the tags of the outline to each building (e.g. source=*) 376 TagCollection.from(outline).applyTo(terr); 377 } else { 378 terr = new Way(outline); 379 terr.setNodes(null); 380 } 381 382 terr.addNode(newNodes[0][i]); 383 terr.addNode(newNodes[0][i + 1]); 384 terr.addNode(newNodes[1][i + 1]); 385 terr.addNode(newNodes[1][i]); 386 terr.addNode(newNodes[0][i]); 387 388 ways.add(addressBuilding(terr, street, streetName, associatedStreet, housenumbers, i, 395 389 from != null ? Integer.toString(from + i * step) : null, buildingValue)); 396 397 this.commands.add(new AddCommand(terr)); 398 } 399 400 if (deleteOutline) { 390 391 if (i > 0 || keepOutline) { 392 this.commands.add(new AddCommand(terr)); 393 } else { 394 this.commands.add(new ChangeCommand(outline, terr)); 395 } 396 } 397 398 if (!keepOutline) { 401 399 // Delete outline nodes having no tags and referrers but the outline itself 402 400 List<Node> nodes = outline.getNodes(); 403 401 ArrayList<Node> nodesToDelete = new ArrayList<>(); 404 402 for (Node n : nodes) 405 if (!n.hasKeys() && n.getReferrers().size() == 1 && !reused _nodes.contains(n))403 if (!n.hasKeys() && n.getReferrers().size() == 1 && !reusedNodes.contains(n)) 406 404 nodesToDelete.add(n); 407 if ( nodesToDelete.size() > 0)405 if (!nodesToDelete.isEmpty()) 408 406 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), nodesToDelete)); 409 // Delete the way itself without nodes410 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), false, true));411 412 407 } 413 408 } else { 414 409 // Single building, just add the address details 415 ways.add(addressBuilding(outline, street, streetName, associatedStreet, housenumbers, 0, From, buildingValue)); 416 } 417 418 // Remove the address nodes since their tags have been incorporated into 419 // the terraces. 410 ways.add(addressBuilding(outline, street, streetName, associatedStreet, housenumbers, 0, start, buildingValue)); 411 } 412 413 // Remove the address nodes since their tags have been incorporated into the terraces. 420 414 // Or should removing them also be an option? 421 415 if (!housenumbers.isEmpty()) { … … 426 420 if (handleRelations) { // create a new relation or merge with existing 427 421 if (associatedStreet == null) { // create a new relation 428 associatedStreet = new Relation(); 429 associatedStreet.put("type", "associatedStreet"); 430 if (street != null) { // a street was part of the selection 431 associatedStreet.put("name", street.get("name")); 432 associatedStreet.addMember(new RelationMember("street", street)); 433 } else { 434 associatedStreet.put("name", streetName); 435 } 436 for (Way w : ways) { 437 associatedStreet.addMember(new RelationMember("house", w)); 438 } 439 this.commands.add(new AddCommand(associatedStreet)); 422 addNewAssociatedStreetRelation(street, streetName, ways); 440 423 } else { // relation exists already - add new members 441 Relation newAssociatedStreet = new Relation(associatedStreet); 442 // remove housenumbers as they have been deleted 443 newAssociatedStreet.removeMembersFor(housenumbers); 444 for (Way w : ways) { 445 newAssociatedStreet.addMember(new RelationMember("house", w)); 446 } 447 if (deleteOutline) { 448 newAssociatedStreet.removeMembersFor(outline); 449 } 450 this.commands.add(new ChangeCommand(associatedStreet, newAssociatedStreet)); 451 } 452 } 453 454 Main.main.undoRedo.add(new SequenceCommand(tr("Terrace"), commands) { 424 updateAssociatedStreetRelation(associatedStreet, housenumbers, ways); 425 } 426 } 427 428 Main.main.undoRedo.add(createTerracingCommand(outline)); 429 if (nb <= 1 && street != null) { 430 // Select the way (for quick selection of a new house (with the same way)) 431 Main.main.getCurrentDataSet().setSelected(street); 432 } else { 433 // Select the new building outlines (for quick reversing) 434 Main.main.getCurrentDataSet().setSelected(ways); 435 } 436 } 437 438 private void updateAssociatedStreetRelation(Relation associatedStreet, List<Node> housenumbers, Collection<Way> ways) { 439 Relation newAssociatedStreet = new Relation(associatedStreet); 440 // remove housenumbers as they have been deleted 441 newAssociatedStreet.removeMembersFor(housenumbers); 442 for (Way w : ways) { 443 newAssociatedStreet.addMember(new RelationMember("house", w)); 444 } 445 /*if (!keepOutline) { 446 newAssociatedStreet.removeMembersFor(outline); 447 }*/ 448 this.commands.add(new ChangeCommand(associatedStreet, newAssociatedStreet)); 449 } 450 451 private void addNewAssociatedStreetRelation(Way street, String streetName, Collection<Way> ways) { 452 Relation associatedStreet = new Relation(); 453 associatedStreet.put("type", "associatedStreet"); 454 if (street != null) { // a street was part of the selection 455 associatedStreet.put("name", street.get("name")); 456 associatedStreet.addMember(new RelationMember("street", street)); 457 } else { 458 associatedStreet.put("name", streetName); 459 } 460 for (Way w : ways) { 461 associatedStreet.addMember(new RelationMember("house", w)); 462 } 463 this.commands.add(new AddCommand(associatedStreet)); 464 } 465 466 private Command createTerracingCommand(final Way outline) { 467 return new SequenceCommand(tr("Terrace"), commands) { 455 468 @Override 456 469 public boolean executeCommand() { … … 481 494 return result; 482 495 } 483 }); 484 if (nb <= 1 && street != null) { 485 // Select the way (for quick selection of a new house (with the same way)) 486 Main.main.getCurrentDataSet().setSelected(street); 487 } else { 488 // Select the new building outlines (for quick reversing) 489 Main.main.getCurrentDataSet().setSelected(ways); 490 } 491 } 492 496 }; 497 } 498 493 499 /** 494 500 * Adds address details to a single building … … 500 506 * @param buildingValue The value for {@code building} key to add 501 507 * @return {@code outline} 502 * @throws UserCancelException 503 */ 504 private Way addressBuilding(Way outline, Way street, String streetName, Relation associatedStreet, ArrayList<Node> housenumbers, int i, String defaultNumber, String buildingValue) throws UserCancelException { 508 * @throws UserCancelException 509 */ 510 private Way addressBuilding(Way outline, Way street, String streetName, Relation associatedStreet, 511 List<Node> housenumbers, int i, String defaultNumber, String buildingValue) throws UserCancelException { 505 512 Node houseNum = (housenumbers != null && i >= 0 && i < housenumbers.size()) ? housenumbers.get(i) : null; 506 513 boolean buildingAdded = false; … … 508 515 if (houseNum != null) { 509 516 primitives = Arrays.asList(new OsmPrimitive[]{houseNum, outline}); 510 517 511 518 TagCollection tagsToCopy = TagCollection.unionOfAllPrimitives(primitives).getTagsFor(houseNum.keySet()); 512 519 tagsInConflict = tagsToCopy.getTagsFor(tagsToCopy.getKeysWithMultipleValues()); 513 520 tagsToCopy = tagsToCopy.minus(tagsInConflict).minus(TagCollection.from(outline)); 514 521 515 522 for (Tag tag : tagsToCopy) { 516 523 this.commands.add(new ChangePropertyCommand(outline, tag.getKey(), tag.getValue())); 517 524 } 518 525 519 526 buildingAdded = houseNum.hasKey("building"); 520 527 numberAdded = houseNum.hasKey("addr:housenumber");
Note:
See TracChangeset
for help on using the changeset viewer.