Package com.willwinder.universalgcodesender.types

Examples of com.willwinder.universalgcodesender.types.PointSegment


    // Resets the current state.
    final public void reset() {
        this.currentPoint = new Point3d();
        this.points = new ArrayList<PointSegment>();
        // The unspoken home location.
        this.points.add(new PointSegment(this.currentPoint, -1));
    }
View Full Code Here


    /**
     * Expands the last point in the list if it is an arc according to the
     * the parsers settings.
     */
    public List<PointSegment> expandArc() {
        PointSegment startSegment = this.points.get(this.points.size() - 2);
        PointSegment lastSegment = this.points.get(this.points.size() - 1);

        // Can only expand arcs.
        if (!lastSegment.isArc()) {
            return null;
        }
       
        // Get precalculated stuff.
        Point3d start     = startSegment.point();
        Point3d end       = lastSegment.point();
        Point3d center    = lastSegment.center();
        double radius     = lastSegment.getRadius();
        boolean clockwise = lastSegment.isClockwise();

        //
        // Start expansion.
        //
        List<Point3d> expandedPoints =
                GcodePreprocessorUtils.generatePointsAlongArcBDring(
                        start, end, center, clockwise, radius,
                        smallArcThreshold, smallArcSegmentLength);
       
        // Validate output of expansion.
        if (expandedPoints == null) {
            return null;
        }
       
        // Remove the last point now that we're about to expand it.
        this.points.remove(this.points.size() - 1);
        commandNumber--;       
               
        // Initialize return value
        List<PointSegment> psl = new ArrayList<PointSegment>();

        // Create line segments from points.
        PointSegment temp;
        // skip first element.
        Iterator<Point3d> psi = expandedPoints.listIterator(1);
        while (psi.hasNext()) {
            temp = new PointSegment(psi.next(), commandNumber++);
            temp.setIsMetric(lastSegment.isMetric());

            // Add new points.
            this.points.add(temp);
            psl.add(temp);
        }
View Full Code Here

        return this.points;
    }

    private PointSegment processCommand(List<String> args) {
        List<String> gCodes;
        PointSegment ps = null;
       
        // handle M codes.
        //codes = GcodePreprocessorUtils.parseCodes(args, 'M');
        //handleMCode(for each codes);
       
View Full Code Here

       
        return ps;
    }

    private PointSegment addLinearPointSegment(Point3d nextPoint, boolean fastTraverse) {
        PointSegment ps = new PointSegment(nextPoint, commandNumber++);

        boolean zOnly = false;

        // Check for z-only
        if ((this.currentPoint.x == nextPoint.x) &&
                (this.currentPoint.y == nextPoint.y) &&
                (this.currentPoint.z != nextPoint.z)) {
            zOnly = true;
        }

        ps.setIsMetric(this.isMetric);
        ps.setIsZMovement(zOnly);
        ps.setIsFastTraverse(fastTraverse);
        this.points.add(ps);

        // Save off the endpoint.
        this.currentPoint = nextPoint;
        return ps;
View Full Code Here

        this.currentPoint = nextPoint;
        return ps;
    }

    private PointSegment addArcPointSegment(Point3d nextPoint, boolean clockwise, List<String> args) {
        PointSegment ps = new PointSegment(nextPoint, commandNumber++);

        Point3d center =
                GcodePreprocessorUtils.updateCenterWithCommand(
                        args, this.currentPoint, nextPoint, this.inAbsoluteIJKMode, clockwise);

        double radius = GcodePreprocessorUtils.parseCoord(args, 'R');

        // Calculate radius if necessary.
        if (Double.isNaN(radius)) {
            radius = Math.sqrt(
                    Math.pow(this.currentPoint.x - center.x, 2.0)
                            + Math.pow(this.currentPoint.y - center.y, 2.0));
        }

        ps.setIsMetric(this.isMetric);
        ps.setArcCenter(center);
        ps.setIsArc(true);
        ps.setRadius(radius);
        ps.setIsClockwise(clockwise);
        this.points.add(ps);

        // Save off the endpoint.
        this.currentPoint = nextPoint;
        return ps;
View Full Code Here

        this.currentPoint = nextPoint;
        return ps;
    }

    private PointSegment handleGCode(String code, List<String> args) {
        PointSegment ps = null;
        Point3d nextPoint =
            GcodePreprocessorUtils.updatePointWithCommand(
            args, this.currentPoint, this.inAbsoluteMode);

        if (code.length() > 1 && code.startsWith("0"))
View Full Code Here

        List<String> result = null;

        // Save off the start of the arc for later.
        Point3d start = new Point3d(this.currentPoint);

        PointSegment ps = addCommand(command);

        if (ps == null || !ps.isArc()) {
            return result;
        }

        List<PointSegment> psl = expandArc();
View Full Code Here

        Point3d start = null;
        Point3d end = null;
        LineSegment ls;
        int num = 0;
        for (PointSegment segment : psl) {
            PointSegment ps = segment;
            ps.convertToMetric();
           
            end = ps.point();

            // start is null for the first iteration.
            if (start != null) {
                // Expand arc for graphics.
                if (ps.isArc()) {
                    List<Point3d> points =
                        GcodePreprocessorUtils.generatePointsAlongArcBDring(
                        start, end, ps.center(), ps.isClockwise(), ps.getRadius(), minArcLength, arcSegmentLength);
                    // Create line segments from points.
                    if (points != null) {
                        Point3d startPoint = start;
                        for (Point3d nextPoint : points) {
                            ls = new LineSegment(startPoint, nextPoint, num);
                            ls.setIsArc(ps.isArc());
                            ls.setIsFastTraverse(ps.isFastTraverse());
                            ls.setIsZMovement(ps.isZMovement());
                            this.testExtremes(nextPoint);
                            lines.add(ls);
                            startPoint = nextPoint;
                        }
                    }
                // Line
                } else {
                    ls = new LineSegment(start, end, num++);
                    ls.setIsArc(ps.isArc());
                    ls.setIsFastTraverse(ps.isFastTraverse());
                    ls.setIsZMovement(ps.isZMovement());
                    this.testExtremes(end);
                    lines.add(ls);
                }
            }
            start = end;
View Full Code Here

TOP

Related Classes of com.willwinder.universalgcodesender.types.PointSegment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.