Ignore:
Timestamp:
2010-10-19T21:53:39+02:00 (14 years ago)
Author:
upliner
Message:

importvec bugfixes, first working version

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  
    419419    public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException
    420420    {
     421        try
     422        {
     423            build();
     424        }
     425        catch (SVGException se)
     426        {
     427            throw new SVGParseException(se);
     428        }
    421429    }
    422430   
  • applications/editors/josm/plugins/importvec/src/com/kitfox/svg/Use.java

    r23707 r23712  
    103103        if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
    104104
    105         /*if (getPres(sty.setName("xlink:href")))
     105        if (getPres(sty.setName("xlink:href")))
    106106        {
    107107            URI src = sty.getURIValue(getXMLBase());
    108             href = diagram.getUniverse().getElement(src);
    109         }*/
     108            href = diagram.getElement(src.getFragment());
     109        }
    110110       
    111111        //Determine use offset/scale
  • applications/editors/josm/plugins/importvec/src/org/openstreetmap/josm/plugins/importvec/ImportDialog.java

    r23707 r23712  
    7373    public int getCurveSteps() {
    7474        try {
    75             int result = NumberFormat.getIntegerInstance().parse(tsdiv.getText()).intValue();
     75            int result = NumberFormat.getIntegerInstance().parse(tsteps.getText()).intValue();
    7676            if (result < 1)
    7777                return 1;
  • applications/editors/josm/plugins/importvec/src/org/openstreetmap/josm/plugins/importvec/ImportVectorAction.java

    r23707 r23712  
    77import java.awt.geom.PathIterator;
    88import java.awt.geom.Point2D;
     9import java.awt.geom.Rectangle2D;
    910import java.io.File;
     11import java.io.FileInputStream;
    1012import java.io.IOException;
    1113import java.net.URI;
     
    1719import javax.swing.JFileChooser;
    1820import javax.swing.filechooser.FileFilter;
    19 import javax.xml.parsers.ParserConfigurationException;
    20 import javax.xml.parsers.SAXParserFactory;
    2121
    2222import org.openstreetmap.josm.Main;
    23 import org.openstreetmap.josm.actions.DiskAccessAction;
    24 import org.openstreetmap.josm.actions.ExtensionFileFilter;
    2523import org.openstreetmap.josm.actions.JosmAction;
    2624import org.openstreetmap.josm.command.AddCommand;
     
    3028import org.openstreetmap.josm.data.coor.LatLon;
    3129import org.openstreetmap.josm.data.osm.Node;
    32 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3330import org.openstreetmap.josm.data.osm.Way;
    3431import org.openstreetmap.josm.data.projection.Mercator;
     
    3734import org.openstreetmap.josm.io.OsmTransferException;
    3835import org.openstreetmap.josm.tools.Shortcut;
     36import org.xml.sax.InputSource;
    3937import org.xml.sax.SAXException;
     38import org.xml.sax.XMLReader;
     39import org.xml.sax.helpers.XMLReaderFactory;
    4040
    4141import com.kitfox.svg.SVGDiagram;
    42 import com.kitfox.svg.SVGElement;
    4342import com.kitfox.svg.SVGLoader;
    44 import com.kitfox.svg.SVGRoot;
    4543import com.kitfox.svg.ShapeElement;
    4644
     
    6967            public boolean accept(File f) {
    7068                if (f.isDirectory())
    71                     return false;
     69                    return true;
    7270                else {
    7371                    String name = f.getName().toLowerCase();
     
    7775            @Override
    7876            public String getDescription() {
    79                 return tr("SVG images (*.svg)");
     77                return tr("SVG Drawings (*.svg)");
    8078            }
    8179
     
    117115        if (dlg.getValue() != 1)
    118116            return;
     117        dlg.saveSettings();
    119118
    120119        File[] files = fc.getSelectedFiles();
     
    155154            if (currentway == null)
    156155                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)));
    158157            if (nd.getCoor().isOutSideWorld())
    159158                throw new IOException("Shape goes outside the world");
     
    189188                double t) {
    190189            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);
    193192        }
    194193
     
    201200            try {
    202201                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                    }
    205211               
    206212                    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()));
    244236                            }
    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();
    248249                    }
    249250                    if (cancelled) return;
    250251                }
    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;
    253256            } catch(Exception e) {
    254257                throw new IOException(e);
Note: See TracChangeset for help on using the changeset viewer.