public GCodeArc(GCodeArc old)                         // Copy
 {
     moveTo     = new Point(old.moveTo.X, old.moveTo.Y);
     center     = new Point(old.center.X, old.center.Y);
     depth      = old.depth;
     angle      = old.angle;
     angleStart = old.angleStart;
     iscw       = old.iscw;
 }
            public void AddArc(Point tmp, Point centerIJ, bool isCW, double z, double angStart, double angEnd)
            {
                GCodeMotion motion;

                motion = new GCodeArc(tmp, centerIJ, isCW, z, angStart, angEnd);
                dimension.setDimensionArc(new xyPoint(end), new xyPoint(tmp), centerIJ.X, centerIJ.Y, isCW);
                path.Add(motion);

                ArcProperties arcMove;
                Point         p1 = Round(end);
                Point         p2 = Round(tmp);

                arcMove     = gcodeMath.getArcMoveProperties(p1, p2, centerIJ, isCW);
                pathLength += Math.Abs(arcMove.radius * arcMove.angleDiff);           // distance from last to current point
                end         = tmp;
            }
Exemple #3
0
//convert graphic to gcode ##################################################################
        private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInformation graphicInfo)
        {
            if (logDetailed)
            {
                Logger.Trace("ProcessPathObject start");
            }
            figureEnable = graphicInfo.FigureEnable;
            float origZ = gcode.gcodeZDown;

/* Create Dot */
            if (pathObject is ItemDot)
            {
                ItemDot DotData = (ItemDot)pathObject;
                if (DotData.UseZ)
                {
                    double setZ = calculateZFromRange(graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.Z);//-Math.Abs(DotData.Z);      // be sure for right sign
                    if (logEnable)
                    {
                        Logger.Trace("---Dot DotData.UseZ: RangeMin:{0:0.00}  RangeMax:{1:0.00}  DotData.Z:{2:0.00}  -> setZ:{3:0.00}", graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.Z, setZ);
                    }
                    setZ = Math.Max(origZ, setZ);    // don't go deeper than set Z
                    if (logCoordinates)
                    {
                        Logger.Trace("  PenDownWithZ z:{0:0.00}  setZ:{1:0.00}  gcodeZDown:{2:0.00}", DotData.Z, setZ, origZ);
                    }
                    gcode.gcodeZDown = (float)setZ;
                    penIsDown        = false;
                }

                else if (graphicInfo.OptionZFromWidth)
                {
                    double newZ = calculateZFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.Z);
                    if (logEnable)
                    {
                        Logger.Trace("---Dot OptionZFromWidth: RangeMin:{0:0.00}  RangeMax:{1:0.00}  DotData.Z:{2:0.00}  -> setZ:{3:0.00}", graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.Z, newZ);
                    }
                    newZ             = Math.Max(origZ, newZ); // don't go deeper than set Z
                    gcode.gcodeZDown = (float)newZ;
                    penIsDown        = false;
                }

                pathObject.FigureId = StartPath(DotData);
                PenDown();
                StopPath();
                gcode.gcodeZDown = origZ;
            }
            else
            {
                if (graphicInfo.OptionZFromWidth)
                {
                    gcode.gcodeZDown = 0;
                }

                ItemPath PathData = (ItemPath)pathObject;
                if (logDetailed)
                {
                    Logger.Trace(" {0}  cnt:{1}", PathData.Info.List(), PathData.path.Count);
                }

                if (PathData.path.Count == 0)
                {
                    if (logEnable)
                    {
                        Logger.Trace("--ProcessPathObject: Empty path ID:{0}", PathData.Info.id);
                    }
                    return;
                }
                pathObject.FigureId = StartPath(PathData);
                PathDashArray       = PathData.dashArray;

                double newZ = gcode.gcodeZDown;                           // default

                for (int index = 1; index < PathData.path.Count; index++) // 0 was already processed in StartPath
                {
                    GCodeMotion entity = PathData.path[index];
                    if (graphicInfo.OptionZFromWidth)
                    {
                        newZ             = calculateZFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, entity.Depth);
                        newZ             = Math.Max(origZ, newZ); // don't go deeper than set Z
                        gcode.gcodeZDown = (float)newZ;
                        if (!Properties.Settings.Default.importDepthFromWidthRamp)
                        {
                            penIsDown = false;
                        }
                        if (logEnable)
                        {
                            Logger.Trace("--ProcessPathObject: penWidth:{0:0.00}  -> setZ:{1:0.00}", entity.Depth, newZ);
                        }
                    }

/* Create Line */
                    if (entity is GCodeLine)
                    {
                        MoveTo(entity.MoveTo, newZ, entity.Angle, "");
                    }
                    else if (entity is GCodeArc)
                    {
/* Create Arc */
                        GCodeArc ArcData = (GCodeArc)entity;
                        Arc(ArcData.IsCW, ArcData.MoveTo, ArcData.CenterIJ, newZ, ArcData.AngleStart, ArcData.Angle, "");                        // entity.comment);
                    }
                }
                StopPath("");
            }
            gcode.gcodeZDown = origZ;
            if (logDetailed)
            {
                Logger.Trace("ProcessPathObject end");
            }
        }
            public void AddArc(Point tmp, Point centerIJ, double z, bool isCW, bool convertToLine)
            {
                GCodeMotion motion;

                if (!convertToLine)
                {
                    motion = new GCodeArc(tmp, centerIJ, isCW, z);
                    dimension.setDimensionArc(new xyPoint(end), new xyPoint(tmp), centerIJ.X, centerIJ.Y, isCW);
                    path.Add(motion);

                    ArcProperties arcMove;
                    Point         p1 = Round(end);
                    Point         p2 = Round(tmp);
                    arcMove     = gcodeMath.getArcMoveProperties(p1, p2, centerIJ, isCW);
                    pathLength += Math.Abs(arcMove.radius * arcMove.angleDiff);           // distance from last to current point
                    end         = tmp;
                }
                else
                {
                    ArcProperties arcMove;
                    Point         p1 = Round(end);
                    Point         p2 = Round(tmp);
                    double        x = 0, y = 0;
                    arcMove = gcodeMath.getArcMoveProperties(p1, p2, centerIJ, isCW);
                    double stepwidth = (double)Properties.Settings.Default.importGCSegment;

                    if (stepwidth > arcMove.radius / 2)
                    {
                        stepwidth = arcMove.radius / 5;
                    }
                    double step = Math.Asin(stepwidth / arcMove.radius);     // in RAD
                                                                             //                    double step = Math.Asin((double)Properties.Settings.Default.importGCSegment / arcMove.radius);     // in RAD
                    if (step > Math.Abs(arcMove.angleDiff))
                    {
                        step = Math.Abs(arcMove.angleDiff / 2);
                    }

                    if (arcMove.angleDiff > 0)   //(da > 0)                                             // if delta >0 go counter clock wise
                    {
                        for (double angle = (arcMove.angleStart + step); angle < (arcMove.angleStart + arcMove.angleDiff); angle += step)
                        {
                            x      = arcMove.center.X + arcMove.radius * Math.Cos(angle);
                            y      = arcMove.center.Y + arcMove.radius * Math.Sin(angle);
                            motion = new GCodeLine(new Point(x, y), z);
                            dimension.setDimensionXY(x, y);
                            path.Add(motion);
                            pathLength += PointDistance(end, tmp);    // distance from last to current point
                            end         = tmp;
                        }
                    }
                    else                                                       // else go clock wise
                    {
                        for (double angle = (arcMove.angleStart - step); angle > (arcMove.angleStart + arcMove.angleDiff); angle -= step)
                        {
                            x      = arcMove.center.X + arcMove.radius * Math.Cos(angle);
                            y      = arcMove.center.Y + arcMove.radius * Math.Sin(angle);
                            motion = new GCodeLine(new Point(x, y), z);
                            dimension.setDimensionXY(x, y);
                            path.Add(motion);
                            pathLength += PointDistance(end, tmp);    // distance from last to current point
                            end         = tmp;
                        }
                    }
                    motion = new GCodeLine(new Point(tmp.X, tmp.Y), z);
                    dimension.setDimensionXY(tmp.X, tmp.Y);
                    path.Add(motion);
                    pathLength += PointDistance(end, tmp);    // distance from last to current point
                    end         = tmp;
                }
                if (start == end)
                {
                    isClosed = true;
                }
            }
 public void AddArc(GCodeArc arc, double z, double angStart, double angEnd)
 {
     AddArc(arc.MoveTo, arc.CenterIJ, arc.IsCW, z, angStart, angEnd);
 }
Exemple #6
0
        public GCodeArc ParseArc(List <Word> words, double motionMode, Vector3 EndPos, double UnitMultiplier)
        {
            double U, V;

            bool IJKused = false;

            switch (State.Plane)
            {
            default:
                U = State.Position.X;
                V = State.Position.Y;
                break;

            case ArcPlane.YZ:
                U = State.Position.Y;
                V = State.Position.Z;
                break;

            case ArcPlane.ZX:
                U = State.Position.Z;
                V = State.Position.X;
                break;
            }

            int ArcIncremental = (State.ArcDistanceMode == ParseDistanceMode.Relative) ? 1 : 0;

            for (int i = 0; i < words.Count; i++)
            {
                if (words[i].Command != 'I')
                {
                    continue;
                }

                switch (State.Plane)
                {
                case ArcPlane.XY:
                    U = words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.X;
                    break;

                case ArcPlane.YZ:
                    throw new Exception("Current Plane is YZ, I word is invalid");

                case ArcPlane.ZX:
                    V = words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.X;
                    break;
                }

                IJKused = true;
                words.RemoveAt(i);
                break;
            }

            for (int i = 0; i < words.Count; i++)
            {
                if (words[i].Command != 'J')
                {
                    continue;
                }

                switch (State.Plane)
                {
                case ArcPlane.XY:
                    V = words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Y;
                    break;

                case ArcPlane.YZ:
                    U = words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Y;
                    break;

                case ArcPlane.ZX:
                    throw new Exception("Current Plane is ZX, J word is invalid");
                }

                IJKused = true;
                words.RemoveAt(i);
                break;
            }

            for (int i = 0; i < words.Count; i++)
            {
                if (words[i].Command != 'K')
                {
                    continue;
                }

                switch (State.Plane)
                {
                case ArcPlane.XY:
                    throw new Exception("Current Plane is XY, K word is invalid");

                case ArcPlane.YZ:
                    V = words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Z;
                    break;

                case ArcPlane.ZX:
                    U = words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Z;
                    break;
                }

                IJKused = true;
                words.RemoveAt(i);
                break;
            }

            for (int i = 0; i < words.Count; i++)
            {
                if (words[i].Command != 'R')
                {
                    continue;
                }

                if (IJKused)
                {
                    throw new Exception("Both IJK and R notation used");
                }

                if (State.Position == EndPos)
                {
                    throw new Exception("arcs in R-notation must have non-coincident start and end points");
                }

                double Radius = words[i].Parameter * UnitMultiplier;

                if (Radius == 0)
                {
                    throw new Exception("Radius can't be zero");
                }

                double A, B;

                switch (State.Plane)
                {
                default:
                    A = EndPos.X;
                    B = EndPos.Y;
                    break;

                case ArcPlane.YZ:
                    A = EndPos.Y;
                    B = EndPos.Z;
                    break;

                case ArcPlane.ZX:
                    A = EndPos.Z;
                    B = EndPos.X;
                    break;
                }

                A -= U;     //(AB) = vector from start to end of arc along the axes of the current plane
                B -= V;

                var C = Math.Round(A, 4) == Math.Round(B, 4) ? A : -A;
                var D = Math.Round(A, 4) == Math.Round(B, 4) ? -B : B;

                {   //normalize perpendicular vector
                    double perpLength = Math.Sqrt(C * C + D * D);
                    C /= perpLength;
                    D /= perpLength;
                }

                var PerpSquare = (Radius * Radius) - ((A * A + B * B) / 4);

                if (PerpSquare < 0)
                {
                    throw new Exception("arc radius too small to reach both ends");
                }

                double PerpLength = Math.Sqrt(PerpSquare);

                if (motionMode == 3 ^ Radius < 0)
                {
                    PerpLength = -PerpLength;
                }

                U += (A / 2) + (C * PerpLength);
                V += (B / 2) + (D * PerpLength);

                words.RemoveAt(i);
                break;
            }

            var arc = new GCodeArc();

            arc.Start     = State.Position;
            arc.End       = EndPos;
            arc.Direction = (motionMode == 2) ? ArcDirection.CW : ArcDirection.CCW;
            arc.U         = U;
            arc.V         = V;
            arc.Plane     = State.Plane;

            return(arc);
        }