From 9ae907017c5f3b0d602e29b8f87cce26f838fd98 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 16 Nov 2017 22:01:24 -0800 Subject: [PATCH 1/2] Slicing operations should pass and use printer reference - IssueMatterHackers/MCCentral#2273 Don't send off bed items to slicing. --- ApplicationView/ApplicationController.cs | 2 +- Library/Export/GCodeExport.cs | 9 +++++--- Queue/OptionsMenu/ExportToFolderProcess.cs | 5 ++++- SlicerConfiguration/Slicer.cs | 25 +++++++++++----------- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index e3202ab10..80e3e7e34 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -1269,7 +1269,7 @@ namespace MatterHackers.MatterControl // Slice reporter?.StartReporting(); - await Slicer.SliceFileAsync(partFilePath, gcodeFilePath, reporter); + await Slicer.SliceFileAsync(partFilePath, gcodeFilePath, printer, reporter); reporter?.EndReporting(); // Load diff --git a/Library/Export/GCodeExport.cs b/Library/Export/GCodeExport.cs index 48a87ea9b..fcf6aa4ca 100644 --- a/Library/Export/GCodeExport.cs +++ b/Library/Export/GCodeExport.cs @@ -90,9 +90,12 @@ namespace MatterHackers.MatterControl.Library.Export if (libraryContent != null) { + // TODO: Export operations need to resolve printer context interactively + var printer = ApplicationController.Instance.ActivePrinter; + try { - string newGCodePath = await SliceFileIfNeeded(libraryContent); + string newGCodePath = await SliceFileIfNeeded(libraryContent, printer); if (File.Exists(newGCodePath)) { @@ -110,7 +113,7 @@ namespace MatterHackers.MatterControl.Library.Export } - private async Task SliceFileIfNeeded(ILibraryContentStream libraryContent) + private async Task SliceFileIfNeeded(ILibraryContentStream libraryContent, PrinterConfig printer) { // TODO: How to handle gcode files in library content? //string fileToProcess = partIsGCode ? printItemWrapper.FileLocation : ""; @@ -128,7 +131,7 @@ namespace MatterHackers.MatterControl.Library.Export var context = ApplicationController.Instance.ActivePrinter.Bed.EditContext; // - Slice - await Slicer.SliceFileAsync(context.PartFilePath, context.GCodeFilePath, null); + await Slicer.SliceFileAsync(context.PartFilePath, context.GCodeFilePath, printer, null); // - Return fileToProcess = context.GCodeFilePath; diff --git a/Queue/OptionsMenu/ExportToFolderProcess.cs b/Queue/OptionsMenu/ExportToFolderProcess.cs index 6a5e8ac69..c773b85d7 100644 --- a/Queue/OptionsMenu/ExportToFolderProcess.cs +++ b/Queue/OptionsMenu/ExportToFolderProcess.cs @@ -96,6 +96,9 @@ namespace MatterHackers.MatterControl.PrintQueue { StartingNextPart?.Invoke(this, new StringEventArgs(ItemNameBeingWorkedOn)); + // TODO: Export operations need to resolve printer context interactively + var printer = ApplicationController.Instance.ActivePrinter; + savedGCodeFileNames = new List(); foreach (PrintItem part in allFilesToExport) { @@ -103,7 +106,7 @@ namespace MatterHackers.MatterControl.PrintQueue string extension = Path.GetExtension(printItemWrapper.FileLocation).ToUpper(); if (extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)) { - Slicer.SliceFileAsync(printItemWrapper.FileLocation, printItemWrapper.GetGCodePathAndFileName(), null).ContinueWith((task) => + Slicer.SliceFileAsync(printItemWrapper.FileLocation, printItemWrapper.GetGCodePathAndFileName(), printer, null).ContinueWith((task) => { Console.WriteLine("Part Slicing Completed"); }); diff --git a/SlicerConfiguration/Slicer.cs b/SlicerConfiguration/Slicer.cs index 700694b45..62dd833d6 100644 --- a/SlicerConfiguration/Slicer.cs +++ b/SlicerConfiguration/Slicer.cs @@ -52,32 +52,32 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private static Process slicerProcess = null; - public static string[] GetStlFileLocations(string fileToSlice, ref string mergeRules) + public static string[] GetStlFileLocations(string fileToSlice, ref string mergeRules, PrinterConfig printer) { extrudersUsed.Clear(); - int extruderCount = ActiveSliceSettings.Instance.GetValue(SettingsKey.extruder_count); + int extruderCount = printer.Settings.GetValue(SettingsKey.extruder_count); for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++) { extrudersUsed.Add(false); } // If we have support enabled and are using an extruder other than 0 for it - if (ActiveSliceSettings.Instance.GetValue("support_material")) + if (printer.Settings.GetValue("support_material")) { - if (ActiveSliceSettings.Instance.GetValue("support_material_extruder") != 0) + if (printer.Settings.GetValue("support_material_extruder") != 0) { - int supportExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.GetValue(SettingsKey.extruder_count) - 1, ActiveSliceSettings.Instance.GetValue("support_material_extruder") - 1)); + int supportExtruder = Math.Max(0, Math.Min(printer.Settings.GetValue(SettingsKey.extruder_count) - 1, printer.Settings.GetValue("support_material_extruder") - 1)); extrudersUsed[supportExtruder] = true; } } // If we have raft enabled and are using an extruder other than 0 for it - if (ActiveSliceSettings.Instance.GetValue("create_raft")) + if (printer.Settings.GetValue("create_raft")) { - if (ActiveSliceSettings.Instance.GetValue("raft_extruder") != 0) + if (printer.Settings.GetValue("raft_extruder") != 0) { - int raftExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.GetValue(SettingsKey.extruder_count) - 1, ActiveSliceSettings.Instance.GetValue("raft_extruder") - 1)); + int raftExtruder = Math.Max(0, Math.Min(printer.Settings.GetValue(SettingsKey.extruder_count) - 1, printer.Settings.GetValue("raft_extruder") - 1)); extrudersUsed[raftExtruder] = true; } } @@ -226,25 +226,26 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return filePath; } - public static async Task SliceFileAsync(string partFilePath, string gcodeFilePath, IProgress progressReporter) + public static async Task SliceFileAsync(string partFilePath, string gcodeFilePath, PrinterConfig printer, IProgress progressReporter) { await Task.Run(() => SliceFile( partFilePath, gcodeFilePath, + printer, progressReporter)); } - private static void SliceFile(string sourceFile, string gcodeFilePath, IProgress progressReporter) + private static void SliceFile(string sourceFile, string gcodeFilePath, PrinterConfig printer, IProgress progressReporter) { string mergeRules = ""; - string[] stlFileLocations = GetStlFileLocations(sourceFile, ref mergeRules); + string[] stlFileLocations = GetStlFileLocations(sourceFile, ref mergeRules, printer); string fileToSlice = stlFileLocations[0]; { string configFilePath = Path.Combine( ApplicationDataStorage.Instance.GCodeOutputPath, - string.Format("config_{0}.ini", ActiveSliceSettings.Instance.GetLongHashCode().ToString())); + string.Format("config_{0}.ini", printer.Settings.GetLongHashCode().ToString())); if (!File.Exists(gcodeFilePath)) { From fe4d08f659c9cfb61d747a80141ab2731ef16337 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 16 Nov 2017 22:13:35 -0800 Subject: [PATCH 2/2] Supply new Predicate to drop items outside of the build volume - Issue MatterHackers/MCCentral#2273 Don't send off bed items to slicing --- SlicerConfiguration/Slicer.cs | 9 ++++++++- Submodules/agg-sharp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/SlicerConfiguration/Slicer.cs b/SlicerConfiguration/Slicer.cs index 62dd833d6..87c819e99 100644 --- a/SlicerConfiguration/Slicer.cs +++ b/SlicerConfiguration/Slicer.cs @@ -39,6 +39,7 @@ using MatterHackers.DataConverters3D; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; namespace MatterHackers.MatterControl.SlicerConfiguration @@ -94,7 +95,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration case ".OBJ": // TODO: Once graph parsing is added to MatterSlice we can remove and avoid this flattening meshPrintOutputSettings.Clear(); - List meshGroups = new List { Object3D.Load(fileToSlice, CancellationToken.None).Flatten(meshPrintOutputSettings) }; + + var reloadedItem = Object3D.Load(fileToSlice, CancellationToken.None); + + // Flatten the scene, filtering out items outside of the build volume + var flattenScene = reloadedItem.Flatten(meshPrintOutputSettings, (item) => item.InsideBuildVolume(printer)); + + var meshGroups = new List { flattenScene }; if (meshGroups != null) { List extruderMeshGroups = new List(); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 7bf60182f..26b6613f6 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 7bf60182fd60260a9087e593f84ad38ad350d343 +Subproject commit 26b6613f68e76d8243ee1a221547f5e9d8fd99be