Ticket #16988: 16988.patch
File 16988.patch, 3.7 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/plugins/importvec/Settings.java
14 14 } 15 15 public static void setCurveSteps(long value) { 16 16 if (value < 1) 17 throw new IllegalArgumentException("Curve steps cannot less than 1");17 throw new IllegalArgumentException("Curve steps cannot be less than 1"); 18 18 Config.getPref().putLong("importvec.curvesteps", value); 19 19 } 20 20 -
src/org/openstreetmap/josm/plugins/importvec/SvgImportTask.java
12 12 import java.io.File; 13 13 import java.io.IOException; 14 14 import java.util.ArrayList; 15 import java.util.HashMap; 16 import java.util.LinkedHashMap; 15 17 import java.util.LinkedList; 16 18 import java.util.List; 17 19 … … 44 46 * @author ak 45 47 */ 46 48 public class SvgImportTask extends PleaseWaitRunnable { 47 LinkedList<Node> nodes = new LinkedList<>();49 HashMap<LatLon, Node> nodes = new LinkedHashMap<>(); 48 50 LinkedList<Way> ways = new LinkedList<>(); 49 51 private List<File> files; 50 52 private boolean canceled; … … 73 75 if (currentway == null) { 74 76 throw new IOException("Shape is started incorectly"); 75 77 } 76 78 Node nd = new Node(projection.eastNorth2latlon(center.add(x * scale, -y * scale))); 77 79 if (nd.getCoor().isOutSideWorld()) { 78 80 throw new IOException("Shape goes outside the world"); 79 81 } 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 } 80 94 currentway.addNode(nd); 81 nodes.add(nd);82 95 lastX = x; 83 96 lastY = y; 84 97 } … … 135 148 appendNode(coords[0], coords[1]); 136 149 break; 137 150 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 } 142 154 break; 143 155 case PathIterator.SEG_QUADTO: 144 156 double lastx = lastX; … … 191 203 } 192 204 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 193 205 List<Command> cmds = new ArrayList<>(); 194 for (Node n : nodes ) {206 for (Node n : nodes.values()) { 195 207 cmds.add(new AddCommand(ds, n)); 196 208 } 197 209 for (Way w : ways) { 198 cmds.add(new AddCommand(ds, w)); 210 if (w.getNodesCount() > 0) { 211 cmds.add(new AddCommand(ds, w)); 212 } 199 213 } 200 214 UndoRedoHandler.getInstance().add(new SequenceCommand("Import primitives", cmds)); 201 215 }