Search in sources :

Example 1 with SplineKnot

use of org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot in project poi by apache.

the class SplineCollector method addToPath.

public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
    // ok, we have the start, and all knots... do something with this
    Point2D last = path.getCurrentPoint();
    // create a control path and knots
    ControlPath controlPath = new ControlPath();
    ValueVector knots = new ValueVector(_knots.size() + 3);
    double firstKnot = _start.getB();
    double lastKnot = _start.getC();
    int degree = _start.getD();
    // first/second knot
    knots.add(firstKnot);
    knots.add(_start.getA());
    // first/second control point
    controlPath.addPoint(PointFactory.create(last.getX(), last.getY()));
    controlPath.addPoint(PointFactory.create(_start.getX(), _start.getY()));
    // middle knots/control points
    for (SplineKnot knot : _knots) {
        knots.add(knot.getA());
        controlPath.addPoint(PointFactory.create(knot.getX(), knot.getY()));
    }
    // last knot
    knots.add(lastKnot);
    ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, null, degree);
    path.append(shape, true);
}
Also used : ValueVector(com.graphbuilder.curve.ValueVector) Point2D(java.awt.geom.Point2D) ShapeMultiPath(com.graphbuilder.curve.ShapeMultiPath) ControlPath(com.graphbuilder.curve.ControlPath) SplineKnot(org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot)

Example 2 with SplineKnot

use of org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot in project poi by apache.

the class GeometrySection method getPath.

public Path2D.Double getPath(XDGFShape parent) {
    Iterator<GeometryRow> rows = getCombinedRows().iterator();
    // special cases
    GeometryRow first = rows.next();
    if (first instanceof Ellipse) {
        return ((Ellipse) first).getPath();
    } else if (first instanceof InfiniteLine) {
        return ((InfiniteLine) first).getPath();
    } else if (first instanceof SplineStart) {
        throw new POIXMLException("SplineStart must be preceded by another type");
    } else {
        // everything else is a path
        Path2D.Double path = new Path2D.Double();
        // dealing with splines makes this more complex
        SplineCollector renderer = null;
        GeometryRow row;
        while (true) {
            if (first != null) {
                row = first;
                first = null;
            } else {
                if (!rows.hasNext())
                    break;
                row = rows.next();
            }
            if (row instanceof SplineStart) {
                if (renderer != null)
                    throw new POIXMLException("SplineStart found multiple times!");
                renderer = new SplineCollector((SplineStart) row);
            } else if (row instanceof SplineKnot) {
                if (renderer == null)
                    throw new POIXMLException("SplineKnot found without SplineStart!");
                renderer.addKnot((SplineKnot) row);
            } else {
                if (renderer != null) {
                    renderer.addToPath(path, parent);
                    renderer = null;
                }
                row.addToPath(path, parent);
            }
        }
        // just in case we end iteration
        if (renderer != null)
            renderer.addToPath(path, parent);
        return path;
    }
}
Also used : GeometryRow(org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow) SplineStart(org.apache.poi.xdgf.usermodel.section.geometry.SplineStart) Ellipse(org.apache.poi.xdgf.usermodel.section.geometry.Ellipse) Path2D(java.awt.geom.Path2D) POIXMLException(org.apache.poi.POIXMLException) SplineKnot(org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot) InfiniteLine(org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine) SplineCollector(org.apache.poi.xdgf.geom.SplineCollector)

Aggregations

SplineKnot (org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot)2 ControlPath (com.graphbuilder.curve.ControlPath)1 ShapeMultiPath (com.graphbuilder.curve.ShapeMultiPath)1 ValueVector (com.graphbuilder.curve.ValueVector)1 Path2D (java.awt.geom.Path2D)1 Point2D (java.awt.geom.Point2D)1 POIXMLException (org.apache.poi.POIXMLException)1 SplineCollector (org.apache.poi.xdgf.geom.SplineCollector)1 Ellipse (org.apache.poi.xdgf.usermodel.section.geometry.Ellipse)1 GeometryRow (org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow)1 InfiniteLine (org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine)1 SplineStart (org.apache.poi.xdgf.usermodel.section.geometry.SplineStart)1