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);
}
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;
}
}
Aggregations