Changeset 26029 in osm for applications/editors/josm/plugins/terracer/src
- Timestamp:
- 2011-05-21T18:54:25+02:00 (14 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
r24956 r26029 22 22 23 23 import javax.swing.JButton; 24 import javax.swing.JOptionPane; 24 25 import javax.swing.JTextField; 25 import javax.swing.JOptionPane;26 26 27 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.data.osm.Node;29 import org.openstreetmap.josm.data.osm.Way;30 import org.openstreetmap.josm.data.osm.Relation;31 28 import org.openstreetmap.josm.actions.JosmAction; 32 29 import org.openstreetmap.josm.data.osm.Node; 30 import org.openstreetmap.josm.data.osm.Relation; 31 import org.openstreetmap.josm.data.osm.Way; 33 32 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 34 33 … … 44 43 */ 45 44 public class HouseNumberInputHandler extends JosmAction implements ActionListener, FocusListener, ItemListener { 46 private TerracerAction terracerAction; 47 private Way outline, street; 48 private String streetName; 49 private Node init; 50 private Relation associatedStreet; 51 private ArrayList<Node> housenumbers; 45 private final TerracerAction terracerAction; 46 private final Way outline, street; 47 private final String streetName; 48 private final Node init; 49 private final Relation associatedStreet; 50 private final ArrayList<Node> housenumbers; 52 51 public HouseNumberInputDialog dialog; 53 52 … … 127 126 // Allow non numeric characters for the low number as long as there is 128 127 // no high number of the segmentcount is 1 129 if (dialog.hi.getText().length() > 0 | segments() > 1) {128 if (dialog.hi.getText().length() > 0 && (segments()!= null || segments() < 1)) { 130 129 isOk = isOk 131 130 && checkNumberStringField(dialog.lo, tr("Lowest number"), … … 281 280 /* 282 281 * (non-Javadoc) 283 * 282 * 284 283 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) 285 284 * Called when the user selects from a pulldown selection 286 285 */ 286 @Override 287 287 public void itemStateChanged(ItemEvent e) { 288 288 validateInput(); … … 291 291 /* 292 292 * (non-Javadoc) 293 * 293 * 294 294 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 295 295 */ 296 @Override 296 297 public void actionPerformed(final ActionEvent e) { 297 298 // OK or Cancel button-actions … … 391 392 } else { 392 393 String name; 393 if (selected instanceof AutoCompletionListItem) 394 if (selected instanceof AutoCompletionListItem) 394 395 { 395 396 name = ((AutoCompletionListItem)selected).getValue(); … … 436 437 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) 437 438 */ 439 @Override 438 440 public void focusGained(FocusEvent e) { 439 441 // Empty, but placeholder is required … … 445 447 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent) 446 448 */ 449 @Override 447 450 public void focusLost(FocusEvent e) { 448 451 if (e.getOppositeComponent() == null) -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r24889 r26029 20 20 import java.util.LinkedList; 21 21 import java.util.List; 22 import java.util.Map; 22 import java.util.Map.Entry; 23 23 import java.util.Set; 24 import java.util.Map.Entry;25 24 import java.util.regex.Matcher; 26 25 import java.util.regex.Pattern; … … 31 30 import org.openstreetmap.josm.actions.JosmAction; 32 31 import org.openstreetmap.josm.command.AddCommand; 32 import org.openstreetmap.josm.command.ChangeCommand; 33 33 import org.openstreetmap.josm.command.ChangePropertyCommand; 34 import org.openstreetmap.josm.command.ChangeCommand;35 34 import org.openstreetmap.josm.command.Command; 36 35 import org.openstreetmap.josm.command.DeleteCommand; 37 36 import org.openstreetmap.josm.command.SequenceCommand; 38 import org.openstreetmap.josm.data.osm.DataSet;39 37 import org.openstreetmap.josm.data.osm.Node; 40 38 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 80 78 * calls to terraceBuilding(), which does all the real work. 81 79 */ 80 @Override 82 81 public void actionPerformed(ActionEvent e) { 83 82 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); … … 229 228 /** 230 229 * Sorts the house number nodes according their numbers only 231 * 230 * 232 231 * @param house 233 232 * number nodes … … 238 237 /* 239 238 * (non-Javadoc) 240 * 239 * 241 240 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 242 241 */ … … 343 342 344 343 // new nodes array to hold all intermediate nodes 344 // This set will contain at least 4 existing nodes from the original outline (those, which coordinates match coordinates of outline nodes) 345 345 Node[][] new_nodes = new Node[2][nb + 1]; 346 // This list will contain nodes of the outline that are used in new lines. 347 // These nodes will not be deleted with the outline (if deleting was prompted). 348 ArrayList<Node> reused_nodes = new ArrayList<Node>(); 346 349 347 350 this.commands = new LinkedList<Command>(); … … 353 356 new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb); 354 357 new_nodes[1][i] = interpolateAlong(interp.b, backLength * i_dir / nb); 355 this.commands.add(new AddCommand(new_nodes[0][i])); 356 this.commands.add(new AddCommand(new_nodes[1][i])); 358 if (!outline.containsNode(new_nodes[0][i])) 359 this.commands.add(new AddCommand(new_nodes[0][i])); 360 else 361 reused_nodes.add(new_nodes[0][i]); 362 if (!outline.containsNode(new_nodes[1][i])) 363 this.commands.add(new AddCommand(new_nodes[1][i])); 364 else 365 reused_nodes.add(new_nodes[1][i]); 357 366 } 358 367 … … 389 398 390 399 if (deleteOutline) { 391 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), true, true)); 400 // Delete outline nodes having no tags and referrers but the outline itself 401 List<Node> nodes = outline.getNodes(); 402 ArrayList<Node> nodesToDelete = new ArrayList<Node>(); 403 for (Node n : nodes) 404 if (!n.hasKeys() && n.getReferrers().size() == 1 && !reused_nodes.contains(n)) 405 nodesToDelete.add(n); 406 if (nodesToDelete.size() > 0) 407 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), nodesToDelete)); 408 // Delete the way itself without nodes 409 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), false, true)); 410 392 411 } 393 412 } else { … … 532 551 // if side2 is contiguous with side1 then look further down the 533 552 // list. we know there are at least 4 sides, as anything smaller 534 // than a quadrilateral would have been rejected at an earlier 535 // stage. 553 // than a quadrilateral would have been rejected at an earlier stage. 536 554 if (indexDistance(side1, side2, indexes.length) < 2) { 537 555 side2 = indexes[2]; … … 547 565 // same for all sides. 548 566 if (sideLength(w, side1) > sideLength(w, side1 + 1) 549 && Math.abs(sideness[side1] - sideness[side1 + 1]) < 0.001) { 550 side1 = side1 + 1; 567 && Math.abs(sideness[side1] - sideness[(side1 + 1) % (w.getNodesCount() - 1)]) < 0.001) { 568 side1 = (side1 + 1) % (w.getNodesCount() - 1); 551 569 side2 = (side2 + 1) % (w.getNodesCount() - 1); 552 570 } … … 628 646 } 629 647 648 @Override 630 649 public int compareTo(SortWithIndex o) { 631 650 return Double.compare(x, o.x); … … 686 705 * nodes. Interpolates linearly in projected coordinates. 687 706 * 707 * If new node coordinate matches a or b coordinates, a or b is returned. 708 * 688 709 * @param a First node, at which f=0. 689 710 * @param b Last node, at which f=1. 690 711 * @param f Fractional position between first and last nodes. 691 * @return A new node at the interpolated position. 712 * @return A new node at the interpolated position (or a or b in case if f ≈ 0 or f ≈ 1). 692 713 */ 693 714 private Node interpolateNode(Node a, Node b, double f) { 694 715 Node n = new Node(a.getEastNorth().interpolate(b.getEastNorth(), f)); 716 if (n.getCoor().equalsEpsilon(a.getCoor())) 717 return a; 718 if (n.getCoor().equalsEpsilon(b.getCoor())) 719 return b; 695 720 return n; 696 721 }
Note:
See TracChangeset
for help on using the changeset viewer.