コード例 #1
0
        private void editor_ParseGCode()
        {
            editor_Parser.Reset();

            string text = editor_textBoxGCode.Text;

            StringBuilder errors = new StringBuilder();

            int lineIndex = 0;
            int lastpos   = 0;
            int position  = 0;

            while (true)
            {
                lineIndex++;

                position = text.IndexOf('\n', position);

                string line;

                if (position >= 0)
                {
                    line = text.Substring(lastpos, position - lastpos);
                }
                else
                {
                    line = text.Substring(lastpos);
                }

                try
                {
                    editor_Parser.ParseLine(line);
                }
                catch (Exception ex)
                {
                    if (errors.Length > 0)
                    {
                        errors.Append('\n');
                    }

                    errors.Append($"{lineIndex}:\t{ex.Message}");
                }

                if (position == -1)
                {
                    break;
                }

                position++;
                lastpos = position;
            }

            previewPath = editor_Parser.ToolPath;

            editor_labelError.Content    = errors.ToString();
            editor_labelError.Visibility = errors.Length > 0 ? Visibility.Visible : Visibility.Collapsed;
        }
コード例 #2
0
        public static GCodeFile FromList(IEnumerable <string> file, ILogger logger = null)
        {
            var parser = new GCodeParser(logger == null ? Services.Logger : logger);

            parser.Reset();
            parser.Parse(file);

            return(new GCodeFile(parser.Commands)
            {
                FileName = "output.nc"
            });
        }
コード例 #3
0
        public static GCodeFile Load(string path, ILogger logger = null)
        {
            var parser = new GCodeParser(logger == null ? Services.Logger : logger);

            parser.Reset();
            parser.ParseFile(path);

            return(new GCodeFile(parser.Commands)
            {
                FileName = path.Substring(path.LastIndexOf('\\') + 1)
            });
        }