private void Machine_FileChanged() { try { ToolPath = GCodeFile.FromList(machine.File); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); // prevents considerable increase in memory usage } catch (Exception ex) { MessageBox.Show("Could not parse GCode File, no preview/editing available\nrun this file at your own risk\n" + ex.Message); } if (Properties.Settings.Default.EnableCodePreview) { ToolPath.GetModel(ModelLine, ModelRapid, ModelArc); } LabelFileLength.Content = machine.File.Count; int digits = (int)Math.Ceiling(Math.Log10(machine.File.Count)); string format = "D" + digits; int i = 1; ListViewFile.Items.Clear(); foreach (string line in machine.File) { ListViewFile.Items.Add(new TextBlock() { Text = $"{i++.ToString(format)} : {line}" }); } }
private void Machine_FileChanged() { try { ToolPath = GCodeFile.FromList(machine.File); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); // prevents considerable increase in memory usage } catch (Exception ex) { MessageBox.Show("Could not parse GCode File, no preview/editing available\nrun this file at your own risk\n" + ex.Message + "\n\n\ninternal:\n" + ex.StackTrace); } if (ToolPath.Warnings.Count > 0) { WarningWindow ww = new WarningWindow(@"Warning! Parsing this file resulted in some warnings! Do not use OpenCNCPilot's edit functions unless you are sure that these warnings can be ignored! If you use edit functions, check the output file for errors before running the gcode! Be aware that the affected lines will likely move when using edit functions." + "\n\n", ToolPath.Warnings); ww.ShowDialog(); } if (Properties.Settings.Default.EnableCodePreview) { ToolPath.GetModel(ModelLine, ModelRapid, ModelArc); } RunFileLength.Text = machine.File.Count.ToString(); FileRunTime = TimeSpan.Zero; RunFileDuration.Text = ToolPath.TotalTime.ToString(@"hh\:mm\:ss"); RunFileRunTime.Text = "00:00:00"; int digits = (int)Math.Ceiling(Math.Log10(machine.File.Count)); string format = "D" + digits; ListViewFile.Items.Clear(); for (int line = 0; line < machine.File.Count; line++) { TextBlock tb = new TextBlock() { Text = $"{(line + 1).ToString(format)} : {machine.File[line]}" }; if (machine.PauseLines[line]) { tb.Background = Brushes.YellowGreen; } ListViewFile.Items.Add(tb); } TextBlock tbFinal = new TextBlock() { Text = "-- FILE END --" }; ListViewFile.Items.Add(tbFinal); if (ToolPath.ContainsMotion) { ModelFileBoundary.Points.Clear(); Point3DCollection boundary = new Point3DCollection(); Vector3 MinPoint = ToolPath.MinFeed; Vector3 MaxPoint = ToolPath.MaxFeed; for (int ax = 0; ax < 3; ax++) { for (int mask = 0; mask < 4; mask++) { Vector3 point = MinPoint; for (int i = 0; i < 2; i++) { // binary integer logic? hell yeah! if (((mask >> i) & 0x01) == 1) { point[(ax + i + 1) % 3] = MaxPoint[(ax + i + 1) % 3]; } } boundary.Add(point.ToPoint3D()); point[ax] = MaxPoint[ax]; boundary.Add(point.ToPoint3D()); } } ModelFileBoundary.Points = boundary; ModelTextMinPoint.Text = string.Format(Constants.DecimalOutputFormat, "({0:0.###}, {1:0.###}, {2:0.###})", MinPoint.X, MinPoint.Y, MinPoint.Z); ModelTextMaxPoint.Text = string.Format(Constants.DecimalOutputFormat, "({0:0.###}, {1:0.###}, {2:0.###})", MaxPoint.X, MaxPoint.Y, MaxPoint.Z); ModelTextMinPoint.Position = MinPoint.ToPoint3D(); ModelTextMaxPoint.Position = MaxPoint.ToPoint3D(); ModelFileBoundaryPoints.Points.Clear(); ModelFileBoundaryPoints.Points.Add(MinPoint.ToPoint3D()); ModelFileBoundaryPoints.Points.Add(MaxPoint.ToPoint3D()); } else { ModelFileBoundary.Points.Clear(); ModelFileBoundaryPoints.Points.Clear(); ModelTextMinPoint.Text = ""; ModelTextMaxPoint.Text = ""; } }
private void Machine_FileChanged() { try { ToolPath = GCodeFile.FromList(machine.File); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); // prevents considerable increase in memory usage } catch (Exception ex) { MessageBox.Show("Could not parse GCode File, no preview/editing available\nrun this file at your own risk\n" + ex.Message); } if (Properties.Settings.Default.EnableCodePreview) { ToolPath.GetModel(ModelLine, ModelRapid, ModelArc); } RunFileLength.Text = machine.File.Count.ToString(); RunFileDuration.Text = ToolPath.TotalTime.ToString(@"hh\:mm\:ss"); FileRunTime = TimeSpan.Zero; int digits = (int)Math.Ceiling(Math.Log10(machine.File.Count)); string format = "D" + digits; ListViewFile.Items.Clear(); for (int line = 0; line < machine.File.Count; line++) { TextBlock tb = new TextBlock() { Text = $"{(line + 1).ToString(format)} : {machine.File[line]}" }; if (machine.PauseLines[line]) { tb.Background = Brushes.YellowGreen; } ListViewFile.Items.Add(tb); } TextBlock tbFinal = new TextBlock() { Text = "-- FILE END --" }; ListViewFile.Items.Add(tbFinal); if (ToolPath.ContainsMotion) { ModelFileBoundary.Points.Clear(); Point3DCollection boundary = new Point3DCollection(); Vector3 MinPoint = ToolPath.MinFeed; Vector3 MaxPoint = ToolPath.MaxFeed; for (int ax = 0; ax < 3; ax++) { for (int mask = 0; mask < 4; mask++) { Vector3 point = MinPoint; for (int i = 0; i < 2; i++) { // binary integer logic? hell yeah! if (((mask >> i) & 0x01) == 1) { point[(ax + i + 1) % 3] = MaxPoint[(ax + i + 1) % 3]; } } boundary.Add(point.ToPoint3D()); point[ax] = MaxPoint[ax]; boundary.Add(point.ToPoint3D()); } } ModelFileBoundary.Points = boundary; ModelTextMinPoint.Text = string.Format(Constants.DecimalOutputFormat, "({0:0.###}, {1:0.###}, {2:0.###})", MinPoint.X, MinPoint.Y, MinPoint.Z); ModelTextMaxPoint.Text = string.Format(Constants.DecimalOutputFormat, "({0:0.###}, {1:0.###}, {2:0.###})", MaxPoint.X, MaxPoint.Y, MaxPoint.Z); ModelTextMinPoint.Position = MinPoint.ToPoint3D(); ModelTextMaxPoint.Position = MaxPoint.ToPoint3D(); ModelFileBoundaryPoints.Points.Clear(); ModelFileBoundaryPoints.Points.Add(MinPoint.ToPoint3D()); ModelFileBoundaryPoints.Points.Add(MaxPoint.ToPoint3D()); } else { ModelFileBoundary.Points.Clear(); ModelFileBoundaryPoints.Points.Clear(); ModelTextMinPoint.Text = ""; ModelTextMaxPoint.Text = ""; } }
private void Machine_FileChanged() { try { ToolPath = GCodeFile.FromList(machine.File); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); // prevents considerable increase in memory usage } catch (Exception ex) { MessageBox.Show("Could not parse GCode File, no preview/editing available\nrun this file at your own risk\n" + ex.Message); } if (Properties.Settings.Default.EnableCodePreview) { ToolPath.GetModel(ModelLine, ModelRapid, ModelArc); } LabelFileLength.Content = machine.File.Count; int digits = (int)Math.Ceiling(Math.Log10(machine.File.Count)); string format = "D" + digits; int lineNo = 1; ListViewFile.Items.Clear(); foreach (string line in machine.File) { ListViewFile.Items.Add(new TextBlock() { Text = $"{lineNo++.ToString(format)} : {line}" }); } if (ToolPath.Toolpath.Count > 0) { ModelFileBoundary.Points.Clear(); Point3DCollection boundary = new Point3DCollection(); Vector3 MinPoint = ToolPath.Min; Vector3 MaxPoint = ToolPath.Max; for (int ax = 0; ax < 3; ax++) { for (int mask = 0; mask < 4; mask++) { Vector3 point = MinPoint; for (int i = 0; i < 2; i++) { // binary integer logic? hell yeah! if (((mask >> i) & 0x01) == 1) { point[(ax + i + 1) % 3] = MaxPoint[(ax + i + 1) % 3]; } } boundary.Add(point.ToPoint3D()); point[ax] = MaxPoint[ax]; boundary.Add(point.ToPoint3D()); } } ModelFileBoundary.Points = boundary; ModelTextMinPoint.Text = string.Format(Constants.DecimalOutputFormat, "({0}, {1}, {2})", MinPoint.X, MinPoint.Y, MinPoint.Z); ModelTextMaxPoint.Text = string.Format(Constants.DecimalOutputFormat, "({0}, {1}, {2})", MaxPoint.X, MaxPoint.Y, MaxPoint.Z); ModelTextMinPoint.Position = MinPoint.ToPoint3D(); ModelTextMaxPoint.Position = MaxPoint.ToPoint3D(); ModelFileBoundaryPoints.Points.Clear(); ModelFileBoundaryPoints.Points.Add(MinPoint.ToPoint3D()); ModelFileBoundaryPoints.Points.Add(MaxPoint.ToPoint3D()); } else { ModelFileBoundary.Points.Clear(); ModelFileBoundaryPoints.Points.Clear(); ModelTextMinPoint.Text = ""; ModelTextMaxPoint.Text = ""; } }