Ejemplo n.º 1
0
        /// <summary>
        /// Add a curve to the input GCodeCollector;
        /// </summary>
        /// <param name="code">input GCodeCollector</param>
        /// <param name="centerX">center X of curve</param>
        /// <param name="centerY">center y of curve</param>
        /// <param name="radius">radius of curve</param>
        /// <param name="startDegree">start degree of curve</param>
        /// <param name="stopDegree">start degree of curve</param>
        /// <param name="speed">The feed-rate per minute of the move between the starting point and ending point</param>
        /// <param name="needExtrude">set true for extruding</param>
        public static void Arc(GCodeCollector code, double centerX, double centerY, double radius, double startDegree, double stopDegree, double?speed = null, bool needExtrude = false, bool isClockwise = true)
        {
            double dist = 0;

            if (isClockwise)
            {
                if (stopDegree < startDegree)
                {
                    dist = startDegree - stopDegree;
                }
                else
                {
                    dist = 360 - stopDegree + startDegree;
                }
            }
            else
            {
                if (stopDegree < startDegree)
                {
                    dist = 360 - startDegree + stopDegree;
                }
                else
                {
                    dist = stopDegree - startDegree;
                }
            }


            //double dist = Math.Abs(stopDegree - startDegree);

            double sign = isClockwise ? -1 : 1;



            var p = Point.PolarToCartesian(radius, startDegree, centerX, centerY);

            code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, code.LastPoint) : (double?)null));

            for (int i = 1; i < dist; i += 5)
            {
                p = Point.PolarToCartesian(radius, startDegree + sign * i, centerX, centerY);
                code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, code.LastPoint) : (double?)null));
            }
            p = Point.PolarToCartesian(radius, stopDegree, centerX, centerY);
            code.addCode(new GCodeLine(x: p.X, y: p.Y, speed: speed, extrude: needExtrude ? GCodeSpecial.ExtrudeLine(p, code.LastPoint) : (double?)null));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Shifts specified g-code collection with the specified value.
        /// </summary>
        /// <param name="x">Added this value to all x positions.</param>
        /// <param name="y">Added this value to all y positions.</param>
        /// <param name="incode">specified g-code collection</param>
        /// <returns></returns>
        public static GCodeCollector codeShift(double x, double y, GCodeCollector incode)
        {
            GCodeCollector backcode = new GCodeCollector(incode.Codes.Count);

            foreach (var c in incode.Codes)
            {
                var l   = c as GCodeLine;
                var els = c as GCodeEllipse;
                if (l != null)
                {
                    if (l.x != null || l.y != null)
                    {
                        double?xk = l.x != null ? l.x + x : null;
                        double?yk = l.y != null ? l.y + y : null;

                        GCodeLine nl = new GCodeLine(xk, yk, l.z, l.f, l.e, l.SpeedMode);
                        backcode.addCode(nl);
                        continue;
                    }
                    backcode.addCode(l);
                }
                else if (els != null)
                {
                    els = (GCodeEllipse)els.Duplicate();
                    foreach (var o in els.Code.Codes)
                    {
                        l = (GCodeLine)o;
                        if (l.x != null || l.y != null)
                        {
                            double?xk = l.x != null ? l.x + x : null;
                            double?yk = l.y != null ? l.y + y : null;
                            l.x = xk;
                            l.y = yk;
                        }
                    }
                    backcode.addCode(els);
                }
                else
                {
                    backcode.addCode(c);
                }
            }

            return(backcode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Return a deep copy of the object.
        /// </summary>
        /// <returns></returns>
        public GCodeCollector Duplicate()
        {
            GCodeCollector collector = new GCodeCollector(Codes.Count);

            foreach (var code in Codes)
            {
                collector.addCode(code.Duplicate());
            }
            return(collector);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Shifts specified g-code collection with the specified value.
        /// </summary>
        /// <param name="z">Added this value to all z positions.</param>
        /// <param name="incode">specified g-code collection</param>
        /// <returns></returns>
        public static GCodeCollector codeShift(double z, GCodeCollector incode)
        {
            GCodeCollector backcode = new GCodeCollector(incode.Codes.Count);

            foreach (var c in incode.Codes)
            {
                var l = c as GCodeLine;
                if (l != null)
                {
                    if (l.z != null)
                    {
                        GCodeLine nl = new GCodeLine(l.x, l.y, l.z + z, l.f, l.e, l.SpeedMode);
                        backcode.addCode(nl);
                        continue;
                    }
                }
                backcode.addCode(c);
            }

            return(backcode);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructs a new GCodeReader from a Stream object of g-code text file.
        /// </summary>
        /// <param name="file">Stream object of g-code text file</param>
        public GCodeReader(Stream file)
        {
            Code = new GCodeCollector();
            string line;


            using (StreamReader text = new StreamReader(file))
            {
                while ((line = text.ReadLine()) != null)
                {
                    IGCode row = Read(line);
                    if (row != null)
                    {
                        Code.addCode(row);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This function shifts to the equivalent position the codes of the object.
        /// </summary>
        /// <param name="code">Input code collection (byRef). The new codes are appended to this collection.</param>
        /// <param name="stagePositon">The position of center of the printing area</param>
        /// <param name="zOff">z offset value</param>
        public void Print(GCodeCollector code, Point stagePositon, double zOff)
        {
            var cc = GCodeTransforms.codeShift(zOff, Code.Duplicate());

            code.addCode(GCodeTransforms.codeShift(stagePositon.X, stagePositon.Y, cc));
        }