private void StateDataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { if (e.Row.Index < bs.Count() - 1) { int counter = bs.Count() - 1 - e.Row.Index; for (int x = 0; x < counter; x++) { StateDataGridView.Rows.Remove(StateDataGridView.Rows[bs.Count() - 1]); } } if (StateDataGridView.RowCount == 1) { State state = new State { StartPoint = Tuple.Create(0.00, 0.00), ZPoint = Tuple.Create(10.00, Double.NaN) }; bs.Add(state); StateDataGridView.Refresh(); } else if (StateDataGridView.RowCount > 1) { State state = new State { StartPoint = bs.Last().StartPoint, ZPoint = Tuple.Create(bs.Last().ZPoint.Item2, Double.NaN) }; bs.Add(state); StateDataGridView.Refresh(); } }
private void DotButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = bs.Last().StartPoint; bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); string gcode = "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().EndPoint.Item1 + " Y" + bs.Last().EndPoint.Item2 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 E" + DotSize + " F" + DotSpeed + Environment.NewLine; bs.Last().Operation = "DOT"; bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }
private void CircleButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = Tuple.Create(CoordX, CoordY); bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); double radius = (bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1) / 2; List <double> LineWidthList = new List <double>(); while (radius >= LineWidth) { LineWidthList.Add(LineWidth); radius -= LineWidth; } //LineWidthList.Remove(0); if (radius > 0) { LineWidthList.Add(radius); } string gcode = ""; radius = (bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1) / 2; gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item2 + " F" + TravelSpeed + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; for (int x = 0; x < LineWidthList.Count(); x++) { if (LineWidthList[x] == LineWidth) { gcode = gcode + "G02 I" + (Math.Round(radius, 2)) + " E" + ExtrusionFormatter(2 * Math.PI * radius / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 X" + (LineWidthList[x]) + " F" + TravelSpeed + Environment.NewLine; } else { gcode = gcode + "G01 E" + ExtrusionFormatter(2 * Math.PI * radius / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } radius -= LineWidthList[x]; } bs.Last().Operation = "CIRCLE"; bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }
private void CArcButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = Tuple.Create(CoordX, CoordY); bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); double OffsetX = (bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1) / 2; double OffsetY = (bs.Last().EndPoint.Item2 - bs.Last().StartPoint.Item2) / 2; string gcode = ""; gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item2 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G03 X" + (bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1) + " Y" + (bs.Last().EndPoint.Item2 - bs.Last().StartPoint.Item2); gcode = gcode + " I" + OffsetX + " J" + OffsetY + " E" + ExtrusionFormatter(Math.PI * Math.Abs(OffsetX) / Multiplier) + " F" + PrintSpeed + Environment.NewLine; bs.Last().Operation = "ARC"; bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }
private void LineButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = Tuple.Create(CoordX, CoordY); bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); bs.Last().Operation = "LINE"; double distX = bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1; double distY = bs.Last().EndPoint.Item2 - bs.Last().StartPoint.Item2; string gcode = ""; if (distX == 0 && Math.Abs(distY) > 0) { gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item2 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 X" + distX + " Y" + distY + " E" + ExtrusionFormatter(Math.Abs(distY) / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else if (Math.Abs(distX) > 0 && distY == 0) { gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item2 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 X" + distX + " Y" + distY + " E" + ExtrusionFormatter(Math.Abs(distX) / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else if (distX != 0 && distY != 0) { gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item2 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; double diagonal = Math.Sqrt(Math.Abs(distX) * Math.Abs(distX) + Math.Abs(distY) * Math.Abs(distY)); gcode = gcode + "G01 X" + distX + " Y" + distY + " E" + ExtrusionFormatter(diagonal / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }
private void ZigZagButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = Tuple.Create(CoordX, CoordY); bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); double distX = Math.Abs(bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1); double distY = Math.Abs(bs.Last().EndPoint.Item2 - bs.Last().StartPoint.Item2); string gcode = ""; gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item2 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; Boolean reverse = false; while (distY > 0) { if (distY > LineWidth) { if (reverse) { gcode = gcode + "G01 X-" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; reverse = false; } else { gcode = gcode + "G01 X" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; reverse = true; } if (distY - LineWidth == LineWidth) { distY -= LineWidth; gcode = gcode + "G01 Y" + Math.Round(LineWidth, 2) + " E" + ExtrusionFormatter(LineWidth / Multiplier) + " F" + PrintSpeed + Environment.NewLine; if (reverse) { gcode = gcode + "G01 X-" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; reverse = false; } else { gcode = gcode + "G01 X" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; reverse = true; } } else if (distY - LineWidth < LineWidth) { distY -= LineWidth; gcode = gcode + "G01 Y" + Math.Round(((LineWidth / 2) + distY / 2), 2) + " E" + ExtrusionFormatter(LineWidth / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else { gcode = gcode + "G01 Y" + Math.Round(LineWidth, 2) + " E" + ExtrusionFormatter(LineWidth / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distY -= LineWidth; } } else { if (distY > 0 && distY < LineWidth) { if (reverse) { gcode = gcode + "G01 X-" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; reverse = false; } else { gcode = gcode + "G01 X" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; reverse = true; } } break; } } bs.Last().Operation = "ZIGZAG"; bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }
private void CoilButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = Tuple.Create(CoordX, CoordY); bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); double distX = Math.Abs(bs.Last().EndPoint.Item1 - bs.Last().StartPoint.Item1); double distY = Math.Abs(bs.Last().EndPoint.Item2 - bs.Last().StartPoint.Item2); string gcode = ""; if (distX > LineWidth && distY > LineWidth) { gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().StartPoint.Item1 + " Y" + bs.Last().StartPoint.Item1 + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 X" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 Y" + distY + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 X-" + distX + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distY -= LineWidth; distX -= LineWidth; gcode = gcode + "G01 Y-" + distY + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distY -= LineWidth; while (distX > LineWidth && distY > LineWidth) { gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distX -= LineWidth; gcode = gcode + "G01 Y" + Math.Round(distY, 2) + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distY -= LineWidth; gcode = gcode + "G01 X-" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 Y-" + Math.Round(distY, 2) + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distY -= LineWidth; distX -= LineWidth; } //gcode = gcode + ";distX : " + distX + Environment.NewLine; //gcode = gcode + ";distY : " + distY + Environment.NewLine; if (distX > LineWidth && distY == LineWidth) { //gcode = gcode + ";1" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distX -= LineWidth; gcode = gcode + "G01 Y" + Math.Round(distY, 2) + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 X-" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else if (distX > LineWidth && distY < LineWidth) { if (distY > 0) { //gcode = gcode + ";2" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; distX -= LineWidth; gcode = gcode + "G01 Y" + distY + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 X-" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else { //gcode = gcode + ";2" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } } else if (distX == LineWidth && distY >= LineWidth) { //gcode = gcode + ";3" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 Y" + Math.Round(distY, 2) + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else if (distX == LineWidth && distY < LineWidth) { if (distY > 0) { //gcode = gcode + ";4" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; double y = distY / 2 + LineWidth / 2; gcode = gcode + "G01 Y" + Math.Round(y, 2) + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else { //gcode = gcode + ";4" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } } else if (distX < LineWidth && distY >= LineWidth) { //gcode = gcode + ";5" + Environment.NewLine; gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; gcode = gcode + "G01 Y" + Math.Round(distY, 2) + " E" + ExtrusionFormatter(distY / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } else if (distX < LineWidth && distY < LineWidth) { //gcode = gcode + ";6" + Environment.NewLine; if (distX > 0) { gcode = gcode + "G01 X" + Math.Round(distX, 2) + " E" + ExtrusionFormatter(distX / Multiplier) + " F" + PrintSpeed + Environment.NewLine; } } } bs.Last().Operation = "COIL"; bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }
private void TravelButton_Click(object sender, EventArgs e) { bs.Last().EndPoint = Tuple.Create(CoordX, CoordY); bs.Last().ZPoint = Tuple.Create(bs.Last().ZPoint.Item1, CoordZ); double Z_end = bs.Last().ZPoint.Item2; double Z_start = bs.Last().ZPoint.Item1; //if (bs.Count() == 1) //{ // Z_start = bs.Last().ZPoint.Item1 + ZHeight; //} //else //{ // Z_start = bs.Last().ZPoint.Item1; //} string gcode = ""; if (bs.Count() != 1) { gcode = gcode + "G01 E" + Retract + " F" + RetractSpeed + Environment.NewLine; } if (Z_end > Z_start) { gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 Z" + (ZHeight + Z_end - Z_start) + " F" + TravelSpeed + Environment.NewLine; //if (bs.Count() == 1) //{ // gcode = gcode + "G01 Z" + (ZHeight * 2 + Z_end - Z_start) + " F" + TravelSpeed + Environment.NewLine; //} //else //{ // gcode = gcode + "G01 Z" + (ZHeight + Z_end - Z_start) + " F" + TravelSpeed + Environment.NewLine; //} gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().EndPoint.Item1 + " Y" + bs.Last().EndPoint.Item2 + " F" + TravelSpeed + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 Z-" + ZHeight + " F" + TravelSpeed + Environment.NewLine; } else if (Z_end < Z_start) { gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 Z" + ZHeight + " F" + TravelSpeed + Environment.NewLine; gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().EndPoint.Item1 + " Y" + bs.Last().EndPoint.Item2 + " F" + TravelSpeed + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 Z-" + (ZHeight + Z_start - Z_end) + " F" + TravelSpeed + Environment.NewLine; } else if (Z_end == Z_start) { gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 Z" + ZHeight + " F" + TravelSpeed + Environment.NewLine; gcode = gcode + "G90" + Environment.NewLine; gcode = gcode + "G01 X" + bs.Last().EndPoint.Item1 + " Y" + bs.Last().EndPoint.Item2 + " F" + TravelSpeed + Environment.NewLine; gcode = gcode + "G91" + Environment.NewLine; gcode = gcode + "G01 Z-" + ZHeight + " F" + TravelSpeed + Environment.NewLine; } gcode = gcode + "G01 E" + PrimeExtrusion + " F" + PrimeSpeed + Environment.NewLine; if (bs.Count() == 1) { gcode = gcode + "G01 E" + PrimeExtrusion2 + " F" + PrimeSpeed2 + Environment.NewLine; gcode = gcode + "G04 P200" + Environment.NewLine; } bs.Last().Operation = "TRAVEL"; gcode = gcode + "G90" + Environment.NewLine; bs.Last().GCode = gcode; ConcatNewPoint(); StateDataGridView.Refresh(); }