Changeset 23724 in osm for applications/editors
- Timestamp:
- 2010-10-20T10:36:48+02:00 (14 years ago)
- Location:
- applications/editors/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/importvec/src/org/openstreetmap/josm/plugins/importvec/ImportVectorAction.java
r23715 r23724 41 41 import org.xml.sax.helpers.XMLReaderFactory; 42 42 43 import com.kitfox.svg.Group; 43 44 import com.kitfox.svg.SVGDiagram; 45 import com.kitfox.svg.SVGElement; 44 46 import com.kitfox.svg.SVGLoader; 45 47 import com.kitfox.svg.ShapeElement; … … 193 195 cube(1-t)*ay+3*sqr(1-t)*t*by+3*(1-t)*t*t*cy+t*t*t*dy); 194 196 } 195 197 198 private void processElement(SVGElement el) throws IOException { 199 if (el instanceof Group) { 200 for (SVGElement child : ((Group)el).getChildren(null)) { 201 processElement(child); 202 } 203 } else if (el instanceof ShapeElement) { 204 PathIterator it = ((ShapeElement)el).getShape().getPathIterator(null); 205 while (!it.isDone()) { 206 double[] coords = new double[6]; 207 switch (it.currentSegment(coords)) { 208 case PathIterator.SEG_MOVETO: 209 currentway = new Way(); 210 ways.add(currentway); 211 appendNode(coords[0],coords[1]); 212 break; 213 case PathIterator.SEG_LINETO: 214 appendNode(coords[0],coords[1]); 215 break; 216 case PathIterator.SEG_CLOSE: 217 if (currentway.firstNode().getCoor().equals(nodes.getLast().getCoor())) { 218 currentway.removeNode(nodes.removeLast()); 219 } 220 currentway.addNode(currentway.firstNode()); 221 break; 222 case PathIterator.SEG_QUADTO: 223 double lastx = lastX; 224 double lasty = lastY; 225 for (int i = 1;i<Settings.getCurveSteps();i++) { 226 appendNode(interpolate_quad(lastx,lasty,coords[0],coords[1],coords[2],coords[3],(double)i/Settings.getCurveSteps())); 227 } 228 appendNode(coords[2],coords[3]); 229 break; 230 case PathIterator.SEG_CUBICTO: 231 lastx = lastX; 232 lasty = lastY; 233 for (int i = 1;i<Settings.getCurveSteps();i++) { 234 appendNode(interpolate_cubic(lastx,lasty,coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],(double)i/Settings.getCurveSteps())); 235 } 236 appendNode(coords[4],coords[5]); 237 break; 238 } 239 it.next(); 240 } 241 } 242 } 196 243 @Override 197 244 protected void realRun() throws SAXException, IOException, OsmTransferException { … … 202 249 try { 203 250 for (File f : files) { 251 if (cancelled) return; 204 252 SVGLoader loader = new SVGLoader(new URI("about:blank"),true); 205 253 XMLReader rdr = XMLReaderFactory.createXMLReader(); … … 219 267 220 268 SVGDiagram diagram = loader.getLoadedDiagram(); 221 ShapeElement shape = diagram.getRoot(); 222 Rectangle2D bbox = shape.getBoundingBox(); 269 ShapeElement root = diagram.getRoot(); 270 if (root == null) throw new IOException("Can't find root SVG element"); 271 Rectangle2D bbox = root.getBoundingBox(); 223 272 this.center = this.center.add(-bbox.getCenterX()*scale, bbox.getCenterY()*scale); 224 PathIterator it = shape.getShape().getPathIterator(null); 225 while (!it.isDone()) { 226 double[] coords = new double[6]; 227 switch (it.currentSegment(coords)) { 228 case PathIterator.SEG_MOVETO: 229 currentway = new Way(); 230 ways.add(currentway); 231 appendNode(coords[0],coords[1]); 232 break; 233 case PathIterator.SEG_LINETO: 234 appendNode(coords[0],coords[1]); 235 break; 236 case PathIterator.SEG_CLOSE: 237 currentway.addNode(currentway.firstNode()); 238 break; 239 case PathIterator.SEG_QUADTO: 240 double lastx = lastX; 241 double lasty = lastY; 242 for (int i = 1;i<Settings.getCurveSteps();i++) { 243 appendNode(interpolate_quad(lastx,lasty,coords[0],coords[1],coords[2],coords[3],(double)i/Settings.getCurveSteps())); 244 } 245 appendNode(coords[2],coords[3]); 246 break; 247 case PathIterator.SEG_CUBICTO: 248 lastx = lastX; 249 lasty = lastY; 250 for (int i = 1;i<Settings.getCurveSteps();i++) { 251 appendNode(interpolate_cubic(lastx,lasty,coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],(double)i/Settings.getCurveSteps())); 252 } 253 appendNode(coords[4],coords[5]); 254 break; 255 } 256 it.next(); 257 } 258 if (cancelled) return; 273 274 processElement(root); 259 275 } 260 276 } catch(SAXException e) {
Note:
See TracChangeset
for help on using the changeset viewer.