예제 #1
0
        /// <summary>
        /// Get the gcode instructions for center drilling using a list of contour elements
        /// </summary>
        /// <param name="contours">list of contour elements</param>
        /// <param name="z">z height lower / raise</param>
        /// <param name="rapidFeed">feedrate to use for rapid moves</param>
        /// <param name="plungeFeed">feedrate to use for plunge moves (Z)</param>
        /// <param name="safeHeight">z height to raise after each contour action</param>
        /// <returns>the gcode instructions for center drilling using a list of contour elements</returns>
        public static string GetGCodeCenter(IEnumerable <IEnumerable <PointF> > contours, float z, float rapidFeed, float plungeFeed, float safeHeight)
        {
            var sb             = new StringBuilder();
            int contourCounter = 0;

            // find min and max
            var points = GetPoints(contours);

            if (points.Count() == 0)
            {
                return(null);
            }

            // Assuming these points come from a SVG
            // we need to shift the Y pos since
            // the SVG origin is upper left, while on
            // this GCode setup it is assumed to be lower left.
            float minX = points.Min(point => point.X);
            //float maxX = points.Max(point => point.X);
            //float minY = points.Min(point => point.Y);
            float maxY = points.Max(point => point.Y);

            // Enumerate each contour in the document
            foreach (var contour in contours)
            {
                contourCounter++;
                var center = Transformation.Center(contour);
                sb.AppendFormat(CultureInfo.InvariantCulture, "G0 X{0:0.##} Y{1:0.##}\n", (center.X - minX), (maxY - center.Y));
                sb.AppendFormat(CultureInfo.InvariantCulture, "G1 Z{0:0.##} F{1:0.##}\n", z, plungeFeed);
                sb.AppendFormat(CultureInfo.InvariantCulture, "G0 Z{0:0.##}\n", safeHeight);
            }
            return(sb.ToString());
        }