Changeset 23712 in osm for applications/editors/josm/plugins/importvec
- Timestamp:
- 2010-10-19T21:53:39+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/importvec
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/importvec/.classpath
- Property svn:executable deleted
-
applications/editors/josm/plugins/importvec/.project
- Property svn:executable deleted
-
applications/editors/josm/plugins/importvec/src/com/kitfox/svg/SVGElement.java
r23707 r23712 419 419 public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException 420 420 { 421 try 422 { 423 build(); 424 } 425 catch (SVGException se) 426 { 427 throw new SVGParseException(se); 428 } 421 429 } 422 430 -
applications/editors/josm/plugins/importvec/src/com/kitfox/svg/Use.java
r23707 r23712 103 103 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 104 104 105 /*if (getPres(sty.setName("xlink:href")))105 if (getPres(sty.setName("xlink:href"))) 106 106 { 107 107 URI src = sty.getURIValue(getXMLBase()); 108 href = diagram.get Universe().getElement(src);109 } */108 href = diagram.getElement(src.getFragment()); 109 } 110 110 111 111 //Determine use offset/scale -
applications/editors/josm/plugins/importvec/src/org/openstreetmap/josm/plugins/importvec/ImportDialog.java
r23707 r23712 73 73 public int getCurveSteps() { 74 74 try { 75 int result = NumberFormat.getIntegerInstance().parse(ts div.getText()).intValue();75 int result = NumberFormat.getIntegerInstance().parse(tsteps.getText()).intValue(); 76 76 if (result < 1) 77 77 return 1; -
applications/editors/josm/plugins/importvec/src/org/openstreetmap/josm/plugins/importvec/ImportVectorAction.java
r23707 r23712 7 7 import java.awt.geom.PathIterator; 8 8 import java.awt.geom.Point2D; 9 import java.awt.geom.Rectangle2D; 9 10 import java.io.File; 11 import java.io.FileInputStream; 10 12 import java.io.IOException; 11 13 import java.net.URI; … … 17 19 import javax.swing.JFileChooser; 18 20 import javax.swing.filechooser.FileFilter; 19 import javax.xml.parsers.ParserConfigurationException;20 import javax.xml.parsers.SAXParserFactory;21 21 22 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.actions.DiskAccessAction;24 import org.openstreetmap.josm.actions.ExtensionFileFilter;25 23 import org.openstreetmap.josm.actions.JosmAction; 26 24 import org.openstreetmap.josm.command.AddCommand; … … 30 28 import org.openstreetmap.josm.data.coor.LatLon; 31 29 import org.openstreetmap.josm.data.osm.Node; 32 import org.openstreetmap.josm.data.osm.OsmPrimitive;33 30 import org.openstreetmap.josm.data.osm.Way; 34 31 import org.openstreetmap.josm.data.projection.Mercator; … … 37 34 import org.openstreetmap.josm.io.OsmTransferException; 38 35 import org.openstreetmap.josm.tools.Shortcut; 36 import org.xml.sax.InputSource; 39 37 import org.xml.sax.SAXException; 38 import org.xml.sax.XMLReader; 39 import org.xml.sax.helpers.XMLReaderFactory; 40 40 41 41 import com.kitfox.svg.SVGDiagram; 42 import com.kitfox.svg.SVGElement;43 42 import com.kitfox.svg.SVGLoader; 44 import com.kitfox.svg.SVGRoot;45 43 import com.kitfox.svg.ShapeElement; 46 44 … … 69 67 public boolean accept(File f) { 70 68 if (f.isDirectory()) 71 return false;69 return true; 72 70 else { 73 71 String name = f.getName().toLowerCase(); … … 77 75 @Override 78 76 public String getDescription() { 79 return tr("SVG images (*.svg)");77 return tr("SVG Drawings (*.svg)"); 80 78 } 81 79 … … 117 115 if (dlg.getValue() != 1) 118 116 return; 117 dlg.saveSettings(); 119 118 120 119 File[] files = fc.getSelectedFiles(); … … 155 154 if (currentway == null) 156 155 throw new IOException("Shape is started incorectly"); 157 Node nd = new Node(projection.eastNorth2latlon(center.add(x*scale, y*scale))); 156 Node nd = new Node(projection.eastNorth2latlon(center.add(x*scale, -y*scale))); 158 157 if (nd.getCoor().isOutSideWorld()) 159 158 throw new IOException("Shape goes outside the world"); … … 189 188 double t) { 190 189 return new Point2D.Double( 191 cube(1-t)*ax+3*sqr(1-t)*t*bx+3*(1- 5)*t*t*cx+t*t*t*dx,192 cube(1-t)*ay+3*sqr(1-t)*t*by+3*(1- 5)*t*t*cy+t*t*t*dy);190 cube(1-t)*ax+3*sqr(1-t)*t*bx+3*(1-t)*t*t*cx+t*t*t*dx, 191 cube(1-t)*ay+3*sqr(1-t)*t*by+3*(1-t)*t*t*cy+t*t*t*dy); 193 192 } 194 193 … … 201 200 try { 202 201 for (File f : files) { 203 SVGLoader loader = new SVGLoader(new URI("about:blank")); 204 SAXParserFactory.newInstance().newSAXParser().parse(f, loader); 202 SVGLoader loader = new SVGLoader(new URI("about:blank"),true); 203 XMLReader rdr = XMLReaderFactory.createXMLReader(); 204 rdr.setContentHandler(loader); 205 FileInputStream in = new FileInputStream(f); 206 try { 207 rdr.parse(new InputSource(in)); 208 } finally { 209 in.close(); 210 } 205 211 206 212 SVGDiagram diagram = loader.getLoadedDiagram(); 207 SVGRoot root = diagram.getRoot(); 208 for (SVGElement el : root.getChildren(null)) { 209 if (el instanceof ShapeElement) { 210 ShapeElement shape = (ShapeElement)el; 211 PathIterator it = shape.getShape().getPathIterator(null); 212 213 while (!it.isDone()) { 214 double[] coords = new double[6]; 215 switch (it.currentSegment(coords)) { 216 case PathIterator.SEG_MOVETO: 217 currentway = new Way(); 218 ways.add(currentway); 219 appendNode(coords[0],coords[1]); 220 break; 221 case PathIterator.SEG_LINETO: 222 appendNode(coords[0],coords[1]); 223 break; 224 case PathIterator.SEG_CLOSE: 225 currentway.addNode(currentway.firstNode()); 226 break; 227 case PathIterator.SEG_QUADTO: 228 double lastx = lastX; 229 double lasty = lastY; 230 for (int i = 1;i<Settings.getCurveSteps();i++) { 231 appendNode(interpolate_quad(lastx,lasty,coords[0],coords[1],coords[2],coords[3],(double)i/Settings.getCurveSteps())); 232 } 233 appendNode(coords[2],coords[3]); 234 break; 235 case PathIterator.SEG_CUBICTO: 236 lastx = lastX; 237 lasty = lastY; 238 for (int i = 1;i<Settings.getCurveSteps();i++) { 239 appendNode(interpolate_cubic(lastx,lasty,coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],(double)i/Settings.getCurveSteps())); 240 } 241 appendNode(coords[4],coords[5]); 242 break; 243 } 213 ShapeElement shape = diagram.getRoot(); 214 Rectangle2D bbox = shape.getBoundingBox(); 215 this.center = this.center.add(-bbox.getCenterX()*scale, bbox.getCenterY()*scale); 216 PathIterator it = shape.getShape().getPathIterator(null); 217 while (!it.isDone()) { 218 double[] coords = new double[6]; 219 switch (it.currentSegment(coords)) { 220 case PathIterator.SEG_MOVETO: 221 currentway = new Way(); 222 ways.add(currentway); 223 appendNode(coords[0],coords[1]); 224 break; 225 case PathIterator.SEG_LINETO: 226 appendNode(coords[0],coords[1]); 227 break; 228 case PathIterator.SEG_CLOSE: 229 currentway.addNode(currentway.firstNode()); 230 break; 231 case PathIterator.SEG_QUADTO: 232 double lastx = lastX; 233 double lasty = lastY; 234 for (int i = 1;i<Settings.getCurveSteps();i++) { 235 appendNode(interpolate_quad(lastx,lasty,coords[0],coords[1],coords[2],coords[3],(double)i/Settings.getCurveSteps())); 244 236 } 245 246 } 247 237 appendNode(coords[2],coords[3]); 238 break; 239 case PathIterator.SEG_CUBICTO: 240 lastx = lastX; 241 lasty = lastY; 242 for (int i = 1;i<Settings.getCurveSteps();i++) { 243 appendNode(interpolate_cubic(lastx,lasty,coords[0],coords[1],coords[2],coords[3],coords[4],coords[5],(double)i/Settings.getCurveSteps())); 244 } 245 appendNode(coords[4],coords[5]); 246 break; 247 } 248 it.next(); 248 249 } 249 250 if (cancelled) return; 250 251 } 251 } catch(ParserConfigurationException e) { 252 throw new IOException(e.getMessage(), e); 252 } catch(SAXException e) { 253 throw e; 254 } catch(IOException e) { 255 throw e; 253 256 } catch(Exception e) { 254 257 throw new IOException(e);
Note:
See TracChangeset
for help on using the changeset viewer.