virtual protected bool parse_value_param(string token, int split, int skip, ref GCodeParam param) { param.identifier = token.Substring(0, split); string value = token.Substring(split + skip, token.Length - (split + skip)); try { GCodeUtil.NumberType numType = GCodeUtil.GetNumberType(value); if (numType == GCodeUtil.NumberType.Decimal) { param.type = GCodeParam.PType.DoubleValue; param.doubleValue = double.Parse(value); return(true); } else if (numType == GCodeUtil.NumberType.Integer) { param.type = GCodeParam.PType.IntegerValue; param.intValue = int.Parse(value); return(true); } } catch { // just continue on and do generic string param } param.type = GCodeParam.PType.TextValue; param.textValue = value; return(true); }
/// <summary> /// Append a label-only parameter to the current line (eg like G162 X Y) /// </summary> /// <param name="identifier">Identifier.</param> public virtual GCodeBuilder AppendL(string identifier) { GCodeParam p = GCodeParam.NoValue(identifier); next_params.Add(p); return(this); }
/// <summary> /// Add a text-value parameter to the current line /// (these are used in Biesse gcode...can also use this to string-format values yourself) /// </summary> public virtual GCodeBuilder AppendS(string identifier, string value) { GCodeParam p = GCodeParam.Text(value, identifier); next_params.Add(p); return(this); }
/// <summary> /// Add a float-value parameter to the current line /// </summary> public virtual GCodeBuilder AppendF(string identifier, double value) { GCodeParam p = GCodeParam.Double(value, identifier); next_params.Add(p); return(this); }
/// <summary> /// Add an integer-value parameter to the current line /// </summary> public virtual GCodeBuilder AppendI(string identifier, int value) { GCodeParam p = GCodeParam.Integer(value, identifier); next_params.Add(p); return(this); }
/// <summary> /// Append a label-only parameter to the current line (eg like G162 X Y) /// </summary> /// <param name="identifier">Identifier.</param> public virtual GCodeBuilder AppendL(string identifier) { GCodeParam p = new GCodeParam() { type = GCodeParam.PType.NoValue, identifier = identifier }; next_params.Add(p); return(this); }
/// <summary> /// Add a text-value parameter to the current line /// (these are used in Biesse gcode...can also use this to string-format values yourself) /// </summary> public virtual GCodeBuilder AppendS(string identifier, string value) { GCodeParam p = new GCodeParam() { type = GCodeParam.PType.TextValue, identifier = identifier, textValue = value }; next_params.Add(p); return(this); }
/// <summary> /// Add an integer-value parameter to the current line /// </summary> public virtual GCodeBuilder AppendI(string identifier, int value) { GCodeParam p = new GCodeParam() { type = GCodeParam.PType.IntegerValue, identifier = identifier, intValue = value }; next_params.Add(p); return(this); }
virtual protected bool parse_noequals_num_parameter(string token, ref GCodeParam param) { int i = is_num_parameter(token); if (i >= 0) { return(parse_value_param(token, i, 0, ref param)); } return(false); }
virtual protected bool parse_code_parameter(string token, ref GCodeParam param) { param.type = GCodeParam.PType.Code; param.identifier = token.Substring(0, 1); string value = token.Substring(1); GCodeUtil.NumberType numType = GCodeUtil.GetNumberType(value); if (numType == GCodeUtil.NumberType.Integer) { param.intValue = int.Parse(value); } return(true); }
virtual protected GCodeParam[] parse_parameters(string[] tokens, int iStart, int iEnd = -1) { if (iEnd == -1) { iEnd = tokens.Length; } int N = iEnd - iStart; GCodeParam[] paramList = new GCodeParam[N]; for (int ti = iStart; ti < iEnd; ++ti) { int pi = ti - iStart; bool bHandled = false; if (tokens[ti].Contains('=')) { parse_equals_parameter(tokens[ti], ref paramList[pi]); bHandled = true; } else if (tokens[ti][0] == 'G' || tokens[ti][0] == 'M') { parse_code_parameter(tokens[ti], ref paramList[pi]); bHandled = true; } else if (is_num_parameter(tokens[ti]) > 0) { parse_noequals_num_parameter(tokens[ti], ref paramList[pi]); bHandled = true; } else if (tokens[ti].Length == 1) { paramList[pi].type = GCodeParam.PType.NoValue; paramList[pi].identifier = tokens[ti]; bHandled = true; } if (!bHandled) { paramList[pi].type = GCodeParam.PType.TextValue; paramList[pi].textValue = tokens[ti]; } } return(paramList); }
virtual protected bool parse_code_parameter(string token, ref GCodeParam param) { string identifier = token.Substring(0, 1); string value = token.Substring(1); switch (GCodeUtil.GetNumberType(value)) { case GCodeUtil.NumberType.Integer: param = GCodeParam.Integer(int.Parse(value), identifier); break; case GCodeUtil.NumberType.Decimal: param = GCodeParam.Double(double.Parse(value), identifier); break; default: case GCodeUtil.NumberType.NotANumber: param = GCodeParam.Text(value, identifier); break; } return(true); }
virtual protected bool parse_equals_parameter(string token, ref GCodeParam param) { int i = token.IndexOf('='); return(parse_value_param(token, i, 1, ref param)); }