コード例 #1
0
        // :IF, :ENDIF, :ELSE
        virtual protected GCodeLine make_control_line(string line, string[] tokens, int nLineNum)
        {
            // figure out command type
            string command = tokens[0].Substring(1);

            GCodeLine.LType eType = GCodeLine.LType.UnknownControl;
            if (command.Equals("if", StringComparison.OrdinalIgnoreCase))
            {
                eType = GCodeLine.LType.If;
            }
            else if (command.Equals("else", StringComparison.OrdinalIgnoreCase))
            {
                eType = GCodeLine.LType.Else;
            }
            else if (command.Equals("endif", StringComparison.OrdinalIgnoreCase))
            {
                eType = GCodeLine.LType.EndIf;
            }

            GCodeLine l = new GCodeLine(nLineNum, eType);

            l.orig_string = line;

            if (tokens.Length > 1)
            {
                l.parameters = parse_parameters(tokens, 1);
            }

            return(l);
        }
コード例 #2
0
        public IEnumerable <GCodeLine> AllLinesOfType(GCodeLine.LType eType)
        {
            int N = lines.Count;

            for (int i = 0; i < N; ++i)
            {
                if (lines[i].type == eType)
                {
                    yield return(lines[i]);
                }
            }
        }
コード例 #3
0
        protected virtual void begin_new_line(GCodeLine.LType type)
        {
            if (next_line != null)
            {
                close_current_line();
            }

            next_line = new GCodeLine(next_line_number(), type);
            if (next_params == null || next_params.Count > 0)
            {
                next_params = new List <GCodeParam>();
            }
        }
コード例 #4
0
        // G### and M### code lines
        virtual protected GCodeLine make_GM_code_line(string line, string[] tokens, int nLineNum)
        {
            GCodeLine.LType eType = GCodeLine.LType.UnknownCode;
            if (tokens[0][0] == 'G')
            {
                eType = GCodeLine.LType.GCode;
            }
            else if (tokens[0][0] == 'M')
            {
                eType = GCodeLine.LType.MCode;
            }

            GCodeLine l = new GCodeLine(nLineNum, eType);

            l.orig_string = line;

            // [TODO] comments

            if (eType == GCodeLine.LType.UnknownCode)
            {
                l.N = int.Parse(tokens[0].Substring(1));
                if (tokens.Length > 1)
                {
                    l.parameters = parse_parameters(tokens, 1);
                }
            }
            else
            {
                var subcodePos = tokens[0].IndexOf('.');
                if (subcodePos == -1)
                {
                    l.code = int.Parse(tokens[0].Substring(1));
                }
                else
                {
                    l.code    = int.Parse(tokens[0].Substring(1, subcodePos - 1));
                    l.subcode = int.Parse(tokens[0].Substring(subcodePos + 1));
                }
                l.N = l.code;
                if (tokens.Length > 1)
                {
                    l.parameters = parse_parameters(tokens, 1);
                }
            }

            return(l);
        }
コード例 #5
0
        // N### lines
        virtual protected GCodeLine make_N_code_line(string line, string[] tokens, int nLineNum)
        {
            GCodeLine.LType eType = GCodeLine.LType.UnknownCode;
            if (tokens[1][0] == 'G')
            {
                eType = GCodeLine.LType.GCode;
            }
            else if (tokens[1][0] == 'M')
            {
                eType = GCodeLine.LType.MCode;
            }

            GCodeLine l = new GCodeLine(nLineNum, eType);

            l.orig_string = line;

            l.N = int.Parse(tokens[0].Substring(1));

            // [TODO] comments

            if (eType == GCodeLine.LType.UnknownCode)
            {
                if (tokens.Length > 1)
                {
                    l.parameters = parse_parameters(tokens, 1);
                }
            }
            else
            {
                l.code = int.Parse(tokens[1].Substring(1));
                if (tokens.Length > 2)
                {
                    l.parameters = parse_parameters(tokens, 2);
                }
            }

            return(l);
        }