示例#1
0
        public static GCode ParseLine(string line)
        {
            var code = new GCode();

            var parts = line.Split(' ').ToList();

            code.Cmd = parts.First();
            parts.RemoveAt(0);

            foreach (var part in parts)
            {
                var cmd = new Regex("([A-Za-z]*)").Match(part);
                switch (cmd.Captures[0].Value)
                {
                case "X":
                    code.X = double.Parse(part.Substring(1));
                    break;

                case "Y":
                    code.Y = double.Parse(part.Substring(1));
                    break;

                case "Z":
                    code.Z = double.Parse(part.Substring(1));
                    break;

                case "E":
                    code.E = double.Parse(part.Substring(1));
                    break;

                case "F":
                    code.F = int.Parse(part.Substring(1));
                    break;

                case "S":
                    code.S = int.Parse(part.Substring(1));
                    break;

                case "T":
                    code.T = int.Parse(part.Substring(1));
                    break;

                default:
                    break;
                }
            }

            return(code);
        }
示例#2
0
        public override string ToString()
        {
            switch (LineType)
            {
            case GCodeLineType.Comment:
                return(Comment);

            case GCodeLineType.S3DSetting:
                return(S3DSetting.ToString());

            case GCodeLineType.Gcode:
                return(GCode.ToString());

            case GCodeLineType.FeatureComment:
                return(S3DFeature.ToString());
            }

            return(string.Empty);
        }
示例#3
0
        private static GCodeLine ParseLine(string line)
        {
            var gcodeLine = new GCodeLine {
                Raw = line
            };

            if (line.StartsWith(";"))
            {
                line = line.Substring(2);
                if (line.StartsWith("feature"))
                {
                    gcodeLine.LineType   = GCodeLineType.FeatureComment;
                    gcodeLine.S3DFeature = new S3DFeatureComment {
                        Name = line.Substring("feature".Length)
                    };
                }
                else if (line.StartsWith("  "))
                {
                    // double space indicates an S3D setting
                    gcodeLine.LineType = GCodeLineType.S3DSetting;
                    line = line.Substring(2);
                    var parts = line.Split(',');

                    gcodeLine.S3DSetting = new S3DSetting {
                        Key = parts[0]
                    };

                    if (parts.Count() > 1)
                    {
                        var valueArray = parts[1]?.Split('|');
                        // more restrictive to less
                        // S3D settings are a mess
                        // they use both comma and pipe separated lists, and a mixture of both
                        // I'm only interested in the pipe separated lists for now, so that's what I'm using
                        // SETTING DATA WILL BE LOST
                        if (int.TryParse(valueArray[0], out var i))
                        {
                            gcodeLine.S3DSetting.SettingType = S3DSettingType.Integer;
                            gcodeLine.S3DSetting.IntValues.Add(i);
                        }
                        else if (double.TryParse(valueArray[0], out var d))
                        {
                            gcodeLine.S3DSetting.SettingType = S3DSettingType.Double;
                            gcodeLine.S3DSetting.DoubleValues.Add(d);
                        }
                        else
                        {
                            gcodeLine.S3DSetting.SettingType = S3DSettingType.Text;
                            gcodeLine.S3DSetting.Text        = string.Join("|", valueArray);
                        }
                    }
                    else
                    {
                        gcodeLine.S3DSetting.SettingType = S3DSettingType.Empty;
                    }
                }
            }
            else if (GCode.IsGcodeLine(line))
            {
                gcodeLine.GCode = GCode.ParseLine(line);
            }
            else
            {
                gcodeLine.LineType = GCodeLineType.Unknown;
            }

            return(gcodeLine);
        }