Ticket #16988: 16988.patch

File 16988.patch, 3.7 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/plugins/importvec/Settings.java

     
    1414    }
    1515    public static void setCurveSteps(long value) {
    1616        if (value < 1)
    17             throw new IllegalArgumentException("Curve steps cannot less than 1");
     17            throw new IllegalArgumentException("Curve steps cannot be less than 1");
    1818        Config.getPref().putLong("importvec.curvesteps", value);
    1919    }
    2020   
  • src/org/openstreetmap/josm/plugins/importvec/SvgImportTask.java

     
    1212import java.io.File;
    1313import java.io.IOException;
    1414import java.util.ArrayList;
     15import java.util.HashMap;
     16import java.util.LinkedHashMap;
    1517import java.util.LinkedList;
    1618import java.util.List;
    1719
     
    4446 * @author ak
    4547 */
    4648public class SvgImportTask extends PleaseWaitRunnable {
    47     LinkedList<Node> nodes = new LinkedList<>();
     49    HashMap<LatLon, Node> nodes = new LinkedHashMap<>();
    4850    LinkedList<Way> ways = new LinkedList<>();
    4951    private List<File> files;
    5052    private boolean canceled;
     
    7375        if (currentway == null) {
    7476            throw new IOException("Shape is started incorectly");
    7577        }
    76         Node nd = new Node(projection.eastNorth2latlon(center.add(x * scale, -y * scale)));
     78        Node nd = new Node(projection.eastNorth2latlon(center.add(x * scale, -y * scale)));
    7779        if (nd.getCoor().isOutSideWorld()) {
    7880            throw new IOException("Shape goes outside the world");
    7981        }
     82        if (currentway.getNodesCount() > 0 &&  nd.getCoor().equalsEpsilon(currentway.lastNode().getCoor())) {
     83                // don't add node that will be saved at the same location as the previous one
     84                return;
     85        }
     86        LatLon rounded = nd.getCoor().getRoundedToOsmPrecision();
     87        Node old = nodes.get(rounded);
     88        boolean isNewNode = old == null;
     89        if (isNewNode) {
     90                nodes.put(rounded, nd);
     91        } else {
     92                nd = old;
     93        }
    8094        currentway.addNode(nd);
    81         nodes.add(nd);
    8295        lastX = x;
    8396        lastY = y;
    8497    }
     
    135148                        appendNode(coords[0], coords[1]);
    136149                        break;
    137150                    case PathIterator.SEG_CLOSE:
    138                         if (currentway.firstNode().getCoor().equalsEpsilon(nodes.getLast().getCoor())) {
    139                             currentway.removeNode(nodes.removeLast());
    140                         }
    141                         currentway.addNode(currentway.firstNode());
     151                        if (currentway.lastNode() != currentway.firstNode()) {
     152                                currentway.addNode(currentway.firstNode());
     153                        }
    142154                        break;
    143155                    case PathIterator.SEG_QUADTO:
    144156                        double lastx = lastX;
     
    191203        }
    192204        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    193205        List<Command> cmds = new ArrayList<>();
    194         for (Node n : nodes) {
     206        for (Node n : nodes.values()) {
    195207            cmds.add(new AddCommand(ds, n));
    196208        }
    197209        for (Way w : ways) {
    198             cmds.add(new AddCommand(ds, w));
     210                if (w.getNodesCount() > 0) {
     211                        cmds.add(new AddCommand(ds, w));
     212                }
    199213        }
    200214        UndoRedoHandler.getInstance().add(new SequenceCommand("Import primitives", cmds));
    201215    }