private void ConvertGcode(string gcodeInString, int layerNr) { GcodeLine thisGcode = new GcodeLine(gcodeInString) { LayerNr = layerNr }; if (thisGcode.LineType == GcodeLine.LType.Gcode) { gcodeInLayer.Add(thisGcode); } }
} // get the value of coordinate X and Y in current gcode line public static List <GcodeLine> ConvertFormart(int layerNr, List <string> gcodeStringSet) { List <GcodeLine> gcodeConverted = new List <GcodeLine> { }; foreach (string thisLine in gcodeStringSet) { GcodeLine thisGcode = new GcodeLine(thisLine) { LayerNr = layerNr }; if (thisGcode.LineType == GcodeLine.LType.Gcode) { gcodeConverted.Add(thisGcode); } } return(gcodeConverted); }
private List <string> GetGcodeText() { gcodeText.Clear(); string currentLine; bool switch_keep_discard = true; while ((currentLine = file.ReadLine()) != null) { if (GcodeLine.GetLineType(currentLine) == GcodeLine.LType.Comment) { switch (GcodeLine.GetCommentType(currentLine)) { case GcodeLine.CType.Unknown: { switch_keep_discard = false; break; } default: { switch_keep_discard = true; gcodeText.Add(currentLine); lineCount++; break; } } } else if ((GcodeLine.GetLineType(currentLine) == GcodeLine.LType.Gcode) && switch_keep_discard) { gcodeText.Add(currentLine); lineCount++; //Console.WriteLine("L{0}: {1}\n", lineCount, line); } } //Console.WriteLine("line count: {0} lines", lineCount); return(gcodeText); }
private void GetLayerContour() { List <GcodeLine> gcodeInLayer = GcodeLine.ConvertFormart(layerNr, gcodeStringInLayer); int gcodeLineNr = gcodeInLayer.Count - 1; for (int c = 0; c < gcodeLineNr; c++) { // current line contains E -> need current point // next line contains E -> current point is not the last point of current curve // next line doesn't contain E -> current point is the last point of current curve // current line doesn't contains E -> must check the next point // next line contains E -> current point is the first point of current curve // next line doesn't contain E -> current point can be skipped. if (gcodeInLayer[c].EnableE) // exists extrude(E) in current gcode line { _Point currentPoint = new _Point { PointID = pointCounter, X = gcodeInLayer[c].X, Y = gcodeInLayer[c].Y, Z = z }; points.Add(currentPoint); if (pointCounter == 0) { //Console.WriteLine("\n\tCurve " + curveCounter + "\t--------------------------------------------------"); } //Console.WriteLine("\t\tP" + pointCounter + "\tX = " + points[pointCounter].X + "\t Y = " + points[pointCounter].Y + "\t Z = " + points[pointCounter].Z); if (gcodeInLayer[c + 1].EnableE) // check the next line { pointCounter++; } else { _Curve currentCurve = new _Curve { CurveID = curveCounter, Points = points }; curves.Add(currentCurve); pointCounter = 0; points = new List <_Point>(); curveCounter++; } } else if (gcodeInLayer[c + 1].EnableE) { _Point currentPoint = new _Point { PointID = pointCounter, X = gcodeInLayer[c].X, Y = gcodeInLayer[c].Y, Z = z }; points.Add(currentPoint); if (pointCounter == 0) { //Console.WriteLine("\n\tCurve " + curveCounter + "\t--------------------------------------------------"); } //Console.WriteLine("\t\tP" + pointCounter + "\tX = " + points[pointCounter].X + "\t Y = " + points[pointCounter].Y + "\t Z = " + points[pointCounter].Z); pointCounter++; } } if (gcodeInLayer[gcodeLineNr].EnableE) // check the last line { _Point currentPoint = new _Point { PointID = pointCounter, X = gcodeInLayer[gcodeLineNr].X, Y = gcodeInLayer[gcodeLineNr].Y, Z = z }; points.Add(currentPoint); if (pointCounter == 0) { //Console.WriteLine("\n\tCurve " + curveCounter + "\t--------------------------------------------------"); } //Console.WriteLine("\t\tP" + pointCounter + "\tX = " + points[pointCounter].X + "\t Y = " + points[pointCounter].Y + "\t Z = " + points[pointCounter].Z); _Curve currentCurve = new _Curve { CurveID = curveCounter, Points = points }; curves.Add(currentCurve); } myContour.LayerID = layerNr; myContour.Curves = curves; }