Search in sources :

Example 1 with Path

use of com.willwinder.ugs.nbp.designer.entities.cuttable.Path in project Universal-G-Code-Sender by winder.

the class SvgReader method parsePath.

private AbstractEntity parsePath(ExtendedGeneralPath shape) {
    ExtendedPathIterator extendedPathIterator = shape.getExtendedPathIterator();
    double[] coords = new double[8];
    double[] lastMoveTo = new double[2];
    double[] lastPoint = new double[2];
    Path line = new Path();
    while (!extendedPathIterator.isDone()) {
        int i = extendedPathIterator.currentSegment();
        switch(i) {
            case ExtendedPathIterator.SEG_MOVETO:
                extendedPathIterator.currentSegment(coords);
                line.moveTo(coords[0], coords[1]);
                lastMoveTo[0] = coords[0];
                lastMoveTo[1] = coords[1];
                lastPoint[0] = coords[0];
                lastPoint[1] = coords[1];
                break;
            case ExtendedPathIterator.SEG_LINETO:
                extendedPathIterator.currentSegment(coords);
                line.lineTo(coords[0], coords[1]);
                lastPoint[0] = coords[0];
                lastPoint[1] = coords[1];
                break;
            case ExtendedPathIterator.SEG_QUADTO:
                extendedPathIterator.currentSegment(coords);
                line.quadTo(coords[0], coords[1], coords[2], coords[3]);
                lastPoint[0] = coords[2];
                lastPoint[1] = coords[3];
                break;
            /*
                 *  The segment type constant for an elliptical arc.  This consists of
                 *  Seven values [rx, ry, angle, largeArcFlag, sweepFlag, x, y].
                 *  rx, ry are the radius of the ellipse.
                 *  angle is angle of the x axis of the ellipse.
                 *  largeArcFlag is zero if the smaller of the two arcs are to be used.
                 *  sweepFlag is zero if the 'left' branch is taken one otherwise.
                 *  x and y are the destination for the ellipse.
                 */
            case ExtendedPathIterator.SEG_ARCTO:
                extendedPathIterator.currentSegment(coords);
                double rx = coords[0];
                double ry = coords[1];
                double angle = coords[2];
                boolean largeArcFlag = coords[3] >= 1;
                boolean sweepFlag = coords[4] >= 1;
                double x = coords[5];
                double y = coords[6];
                // If the radius is zero, just make a line
                if (rx == 0 || ry == 0) {
                    line.lineTo(x, y);
                    break;
                }
                // Get the current coordinates of the path
                double x0 = lastPoint[0];
                double y0 = lastPoint[1];
                // If the endpoints (x, y) and (x0, y0) are identical, then this is not an arc
                if (x0 == x && y0 == y) {
                    break;
                }
                Arc2D arc = ExtendedGeneralPath.computeArc(x0, y0, rx, ry, angle, largeArcFlag, sweepFlag, x, y);
                line.append(arc);
                lastPoint[0] = coords[5];
                lastPoint[1] = coords[6];
                break;
            case PathIterator.SEG_CUBICTO:
                extendedPathIterator.currentSegment(coords);
                line.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
                lastPoint[0] = coords[4];
                lastPoint[1] = coords[5];
                break;
            case PathIterator.SEG_CLOSE:
                extendedPathIterator.currentSegment(coords);
                line.lineTo(lastMoveTo[0], lastMoveTo[1]);
                lastPoint[0] = lastMoveTo[0];
                lastPoint[1] = lastMoveTo[1];
                line.close();
                break;
            default:
                LOGGER.warning("Missing handler for path segment: " + i);
        }
        extendedPathIterator.next();
    }
    return line;
}
Also used : Path(com.willwinder.ugs.nbp.designer.entities.cuttable.Path) ExtendedGeneralPath(org.apache.batik.ext.awt.geom.ExtendedGeneralPath) ExtendedPathIterator(org.apache.batik.ext.awt.geom.ExtendedPathIterator)

Example 2 with Path

use of com.willwinder.ugs.nbp.designer.entities.cuttable.Path in project Universal-G-Code-Sender by winder.

the class BreakApartAction method onSelectionEvent.

@Override
public void onSelectionEvent(SelectionEvent selectionEvent) {
    SelectionManager selectionManager = controller.getSelectionManager();
    boolean isSingleEntity = selectionManager.getSelection().size() == 1;
    if (!isSingleEntity) {
        setEnabled(false);
        return;
    }
    boolean isCompoundPath = false;
    Entity entity = selectionManager.getSelection().get(0);
    if (entity instanceof Path) {
        isCompoundPath = ((Path) entity).isCompoundPath();
    }
    setEnabled(isCompoundPath);
}
Also used : Path(com.willwinder.ugs.nbp.designer.entities.cuttable.Path) SelectionManager(com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager) Entity(com.willwinder.ugs.nbp.designer.entities.Entity)

Example 3 with Path

use of com.willwinder.ugs.nbp.designer.entities.cuttable.Path in project Universal-G-Code-Sender by winder.

the class DxfReader method parseLines.

private void parseLines(DXFLayer layer, Group linesGroup) {
    List<DXFLine> lines = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_LINE);
    if (lines != null) {
        Path path = new Path();
        Point lastPoint = null;
        for (DXFLine line : lines) {
            if (lastPoint != null && !lastPoint.equals(line.getStartPoint())) {
                linesGroup.addChild(path);
                path = new Path();
                lastPoint = null;
            }
            if (lastPoint == null) {
                path.moveTo(line.getStartPoint().getX() * MILLIMETERS_PER_INCH, line.getStartPoint().getY() * MILLIMETERS_PER_INCH);
            }
            path.lineTo(line.getEndPoint().getX() * MILLIMETERS_PER_INCH, line.getEndPoint().getY() * MILLIMETERS_PER_INCH);
            lastPoint = line.getEndPoint();
        }
        linesGroup.addChild(path);
    }
}
Also used : Path(com.willwinder.ugs.nbp.designer.entities.cuttable.Path) Point(org.kabeja.dxf.helpers.Point)

Example 4 with Path

use of com.willwinder.ugs.nbp.designer.entities.cuttable.Path in project Universal-G-Code-Sender by winder.

the class FontClipart method getCuttable.

@Override
public Cuttable getCuttable() {
    BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = img.createGraphics();
    GlyphVector glyphVector = font.createGlyphVector(g2.getFontRenderContext(), text);
    AffineTransform transform = AffineTransform.getScaleInstance(1, -1);
    Shape shape = transform.createTransformedShape(glyphVector.getOutline(0, 0));
    Path path = new Path();
    path.append(shape);
    return path;
}
Also used : Path(com.willwinder.ugs.nbp.designer.entities.cuttable.Path) GlyphVector(java.awt.font.GlyphVector) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage)

Example 5 with Path

use of com.willwinder.ugs.nbp.designer.entities.cuttable.Path in project Universal-G-Code-Sender by winder.

the class EntityPathV1 method toInternal.

@Override
public Entity toInternal() {
    Path path = new Path();
    final Point2D latestMoveTo = new Point2D.Double();
    getSegments().forEach(segment -> {
        switch(segment.getType()) {
            case MOVE_TO:
                path.moveTo(segment.getCoordinates().get(0)[0], segment.getCoordinates().get(0)[1]);
                latestMoveTo.setLocation(new Point2D.Double(segment.getCoordinates().get(0)[0], segment.getCoordinates().get(0)[1]));
                break;
            case LINE_TO:
                path.lineTo(segment.getCoordinates().get(0)[0], segment.getCoordinates().get(0)[1]);
                break;
            case QUAD_TO:
                path.quadTo(segment.getCoordinates().get(0)[0], segment.getCoordinates().get(0)[1], segment.getCoordinates().get(1)[0], segment.getCoordinates().get(1)[1]);
                break;
            case CUBIC_TO:
                path.curveTo(segment.getCoordinates().get(0)[0], segment.getCoordinates().get(0)[1], segment.getCoordinates().get(1)[0], segment.getCoordinates().get(1)[1], segment.getCoordinates().get(2)[0], segment.getCoordinates().get(2)[1]);
                break;
            case CLOSE:
                path.lineTo(latestMoveTo.getX(), latestMoveTo.getY());
                path.close();
        }
    });
    applyCommonAttributes(path);
    return path;
}
Also used : Path(com.willwinder.ugs.nbp.designer.entities.cuttable.Path) Point2D(java.awt.geom.Point2D)

Aggregations

Path (com.willwinder.ugs.nbp.designer.entities.cuttable.Path)5 Entity (com.willwinder.ugs.nbp.designer.entities.Entity)1 SelectionManager (com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager)1 GlyphVector (java.awt.font.GlyphVector)1 AffineTransform (java.awt.geom.AffineTransform)1 Point2D (java.awt.geom.Point2D)1 BufferedImage (java.awt.image.BufferedImage)1 ExtendedGeneralPath (org.apache.batik.ext.awt.geom.ExtendedGeneralPath)1 ExtendedPathIterator (org.apache.batik.ext.awt.geom.ExtendedPathIterator)1 Point (org.kabeja.dxf.helpers.Point)1