Merge pull request #2674 from jlewin/design_tools

Supply new Predicate to drop items outside of the build volume
This commit is contained in:
johnlewin 2017-11-16 22:31:24 -08:00 committed by GitHub
commit 29bbce5063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 19 deletions

View file

@ -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

View file

@ -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<string> SliceFileIfNeeded(ILibraryContentStream libraryContent)
private async Task<string> 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;

View file

@ -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<string>();
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");
});

View file

@ -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
@ -52,32 +53,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<int>(SettingsKey.extruder_count);
int extruderCount = printer.Settings.GetValue<int>(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<bool>("support_material"))
if (printer.Settings.GetValue<bool>("support_material"))
{
if (ActiveSliceSettings.Instance.GetValue<int>("support_material_extruder") != 0)
if (printer.Settings.GetValue<int>("support_material_extruder") != 0)
{
int supportExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count) - 1, ActiveSliceSettings.Instance.GetValue<int>("support_material_extruder") - 1));
int supportExtruder = Math.Max(0, Math.Min(printer.Settings.GetValue<int>(SettingsKey.extruder_count) - 1, printer.Settings.GetValue<int>("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<bool>("create_raft"))
if (printer.Settings.GetValue<bool>("create_raft"))
{
if (ActiveSliceSettings.Instance.GetValue<int>("raft_extruder") != 0)
if (printer.Settings.GetValue<int>("raft_extruder") != 0)
{
int raftExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count) - 1, ActiveSliceSettings.Instance.GetValue<int>("raft_extruder") - 1));
int raftExtruder = Math.Max(0, Math.Min(printer.Settings.GetValue<int>(SettingsKey.extruder_count) - 1, printer.Settings.GetValue<int>("raft_extruder") - 1));
extrudersUsed[raftExtruder] = true;
}
}
@ -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<MeshGroup> meshGroups = new List<MeshGroup> { 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<MeshGroup> { flattenScene };
if (meshGroups != null)
{
List<MeshGroup> extruderMeshGroups = new List<MeshGroup>();
@ -226,25 +233,26 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return filePath;
}
public static async Task SliceFileAsync(string partFilePath, string gcodeFilePath, IProgress<string> progressReporter)
public static async Task SliceFileAsync(string partFilePath, string gcodeFilePath, PrinterConfig printer, IProgress<string> progressReporter)
{
await Task.Run(() => SliceFile(
partFilePath,
gcodeFilePath,
printer,
progressReporter));
}
private static void SliceFile(string sourceFile, string gcodeFilePath, IProgress<string> progressReporter)
private static void SliceFile(string sourceFile, string gcodeFilePath, PrinterConfig printer, IProgress<string> 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))
{

@ -1 +1 @@
Subproject commit 7bf60182fd60260a9087e593f84ad38ad350d343
Subproject commit 26b6613f68e76d8243ee1a221547f5e9d8fd99be