Changeset 26029 in osm


Ignore:
Timestamp:
2011-05-21T18:54:25+02:00 (13 years ago)
Author:
kachkaev
Message:

JOSM terracer plugin: Fixed several bugs.

  1. If the building was in the middle of the sequence of buildings, common nodes were not used in the result (new nodes were created instead causing duplicates).

This issue was described in http://josm.openstreetmap.de/ticket/6339

  1. NullPointerException was thrown in some cases when validating dialog input.
  1. ListIndexOutOfBounds exception was sometimes thrown during findFrontAndBack() method execution.
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  
    2222
    2323import javax.swing.JButton;
     24import javax.swing.JOptionPane;
    2425import javax.swing.JTextField;
    25 import javax.swing.JOptionPane;
    2626
    2727import 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;
    3128import org.openstreetmap.josm.actions.JosmAction;
    3229import org.openstreetmap.josm.data.osm.Node;
     30import org.openstreetmap.josm.data.osm.Relation;
     31import org.openstreetmap.josm.data.osm.Way;
    3332import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    3433
     
    4443 */
    4544public 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;
    5251    public HouseNumberInputDialog dialog;
    5352
     
    127126        // Allow non numeric characters for the low number as long as there is
    128127        // 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)) {
    130129            isOk = isOk
    131130                    && checkNumberStringField(dialog.lo, tr("Lowest number"),
     
    281280    /*
    282281     * (non-Javadoc)
    283      * 
     282     *
    284283     * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
    285284     * Called when the user selects from a pulldown selection
    286285     */
     286    @Override
    287287    public void itemStateChanged(ItemEvent e) {
    288288        validateInput();
     
    291291    /*
    292292     * (non-Javadoc)
    293      * 
     293     *
    294294     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
    295295     */
     296    @Override
    296297    public void actionPerformed(final ActionEvent e) {
    297298        // OK or Cancel button-actions
     
    391392        } else {
    392393            String name;
    393             if (selected instanceof AutoCompletionListItem) 
     394            if (selected instanceof AutoCompletionListItem)
    394395            {
    395396               name = ((AutoCompletionListItem)selected).getValue();
     
    436437     * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
    437438     */
     439    @Override
    438440    public void focusGained(FocusEvent e) {
    439441        // Empty, but placeholder is required
     
    445447     * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
    446448     */
     449    @Override
    447450    public void focusLost(FocusEvent e) {
    448451        if (e.getOppositeComponent() == null)
  • applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java

    r24889 r26029  
    2020import java.util.LinkedList;
    2121import java.util.List;
    22 import java.util.Map;
     22import java.util.Map.Entry;
    2323import java.util.Set;
    24 import java.util.Map.Entry;
    2524import java.util.regex.Matcher;
    2625import java.util.regex.Pattern;
     
    3130import org.openstreetmap.josm.actions.JosmAction;
    3231import org.openstreetmap.josm.command.AddCommand;
     32import org.openstreetmap.josm.command.ChangeCommand;
    3333import org.openstreetmap.josm.command.ChangePropertyCommand;
    34 import org.openstreetmap.josm.command.ChangeCommand;
    3534import org.openstreetmap.josm.command.Command;
    3635import org.openstreetmap.josm.command.DeleteCommand;
    3736import org.openstreetmap.josm.command.SequenceCommand;
    38 import org.openstreetmap.josm.data.osm.DataSet;
    3937import org.openstreetmap.josm.data.osm.Node;
    4038import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    8078     * calls to terraceBuilding(), which does all the real work.
    8179     */
     80    @Override
    8281    public void actionPerformed(ActionEvent e) {
    8382        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
     
    229228    /**
    230229     * Sorts the house number nodes according their numbers only
    231      * 
     230     *
    232231     * @param house
    233232     *            number nodes
     
    238237        /*
    239238         * (non-Javadoc)
    240          * 
     239         *
    241240         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
    242241         */
     
    343342
    344343        // 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)
    345345        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>();
    346349
    347350        this.commands = new LinkedList<Command>();
     
    353356                new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb);
    354357                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]);
    357366            }
    358367
     
    389398
    390399            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
    392411            }
    393412        } else {
     
    532551        // if side2 is contiguous with side1 then look further down the
    533552        // 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.
    536554        if (indexDistance(side1, side2, indexes.length) < 2) {
    537555            side2 = indexes[2];
     
    547565        // same for all sides.
    548566        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);
    551569            side2 = (side2 + 1) % (w.getNodesCount() - 1);
    552570        }
     
    628646            }
    629647
     648            @Override
    630649            public int compareTo(SortWithIndex o) {
    631650                return Double.compare(x, o.x);
     
    686705     * nodes. Interpolates linearly in projected coordinates.
    687706     *
     707     * If new node coordinate matches a or b coordinates, a or b is returned.
     708     *
    688709     * @param a First node, at which f=0.
    689710     * @param b Last node, at which f=1.
    690711     * @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).
    692713     */
    693714    private Node interpolateNode(Node a, Node b, double f) {
    694715        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;
    695720        return n;
    696721    }
Note: See TracChangeset for help on using the changeset viewer.