diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 3a2bc47a2..733183adb 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -2186,7 +2186,7 @@ namespace MatterHackers.MatterControl object3D, gcodeFilePath, printer, - new SliceProgressReporter(reporter, printer), + reporter, cancellationToken); }); diff --git a/CustomWidgets/ExportPrintItemPage.cs b/CustomWidgets/ExportPrintItemPage.cs index 0ed42de9e..3e668b31c 100644 --- a/CustomWidgets/ExportPrintItemPage.cs +++ b/CustomWidgets/ExportPrintItemPage.cs @@ -162,13 +162,19 @@ namespace MatterHackers.MatterControl ActionButtonLabel = "Export".Localize(), Title = ApplicationController.Instance.ProductName + " - " + "Select A Folder".Localize() }, - async (openParams) => + (openParams) => { - string path = openParams.FolderPath; - if (!string.IsNullOrEmpty(path)) - { - await activePlugin.Generate(libraryItems, path); - } + ApplicationController.Instance.Tasks.Execute( + "Saving".Localize() + "...", + async (reporter, cancellationToken) => + { + + string path = openParams.FolderPath; + if (!string.IsNullOrEmpty(path)) + { + await activePlugin.Generate(libraryItems, path, reporter, cancellationToken); + } + }); }); }); @@ -192,33 +198,35 @@ namespace MatterHackers.MatterControl if (!string.IsNullOrEmpty(savePath)) { - Task.Run(async () => - { - string extension = Path.GetExtension(savePath); - if (extension != targetExtension) + ApplicationController.Instance.Tasks.Execute( + "Exporting".Localize() + "...", + async (reporter, cancellationToken) => { - savePath += targetExtension; - } - - bool succeeded = false; - - if (activePlugin != null) - { - succeeded = await activePlugin.Generate(libraryItems, savePath); - } - - if (succeeded) - { - ShowFileIfRequested(savePath); - } - else - { - UiThread.RunOnIdle(() => + string extension = Path.GetExtension(savePath); + if (extension != targetExtension) { - StyledMessageBox.ShowMessageBox("Export failed".Localize(), title); - }); - } - }); + savePath += targetExtension; + } + + bool succeeded = false; + + if (activePlugin != null) + { + succeeded = await activePlugin.Generate(libraryItems, savePath, reporter, cancellationToken); + } + + if (succeeded) + { + ShowFileIfRequested(savePath); + } + else + { + UiThread.RunOnIdle(() => + { + StyledMessageBox.ShowMessageBox("Export failed".Localize(), title); + }); + } + }); } }); }); diff --git a/Library/Export/FolderExport.cs b/Library/Export/FolderExport.cs index 6dbd50bd7..4a65f67c6 100644 --- a/Library/Export/FolderExport.cs +++ b/Library/Export/FolderExport.cs @@ -31,7 +31,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -57,7 +59,7 @@ namespace MatterHackers.MatterControl.Library.Export public bool ExportPossible(ILibraryAsset libraryItem) => true; - public async Task Generate(IEnumerable libraryItems, string outputPath) + public async Task Generate(IEnumerable libraryItems, string outputPath, IProgress progress, CancellationToken cancellationToken) { var streamItems = libraryItems.OfType(); if (streamItems.Any()) diff --git a/Library/Export/GCodeExport.cs b/Library/Export/GCodeExport.cs index ef442a636..3186c8002 100644 --- a/Library/Export/GCodeExport.cs +++ b/Library/Export/GCodeExport.cs @@ -114,7 +114,7 @@ namespace MatterHackers.MatterControl.Library.Export return container; } - public async Task Generate(IEnumerable libraryItems, string outputPath) + public async Task Generate(IEnumerable libraryItems, string outputPath, IProgress progress, CancellationToken cancellationToken) { var firstItem = libraryItems.OfType().FirstOrDefault(); if (firstItem != null) @@ -144,7 +144,17 @@ namespace MatterHackers.MatterControl.Library.Export } else if (firstItem is ILibraryObject3D object3DItem) { + var status = new ProgressStatus() + { + Status = "Saving Asset".Localize() + }; + loadedItem = await object3DItem.CreateContent(null); + await loadedItem.PersistAssets((percentComplete, text) => + { + status.Progress0To1 = percentComplete; + progress.Report(status); + }, publishAssets: false); } else if (assetStream != null) { @@ -189,10 +199,12 @@ namespace MatterHackers.MatterControl.Library.Export printer.Settings.SetValue(SettingsKey.spiral_vase, "1"); } - await ApplicationController.Instance.Tasks.Execute("Slicing Item".Localize() + " " + loadedItem.Name, (reporter, cancellationToken) => - { - return Slicer.SliceItem(loadedItem, gcodePath, printer, reporter, cancellationToken); - }); + await ApplicationController.Instance.Tasks.Execute( + "Slicing Item".Localize() + " " + loadedItem.Name, + (reporter, cancellationToken2) => + { + return Slicer.SliceItem(loadedItem, gcodePath, printer, reporter, cancellationToken2); + }); } finally { diff --git a/Library/Export/IExportPlugin.cs b/Library/Export/IExportPlugin.cs index 095360fef..2a22b035a 100644 --- a/Library/Export/IExportPlugin.cs +++ b/Library/Export/IExportPlugin.cs @@ -26,8 +26,11 @@ The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; using MatterHackers.MatterControl.Library; @@ -43,7 +46,7 @@ namespace MatterHackers.MatterControl void Initialize(PrinterConfig printer); - Task Generate(IEnumerable libraryItems, string outputPath); + Task Generate(IEnumerable libraryItems, string outputPath, IProgress progress, CancellationToken cancellationToken); bool Enabled { get; } diff --git a/Library/Export/StlExport.cs b/Library/Export/StlExport.cs index 5bb30e2b8..550e62009 100644 --- a/Library/Export/StlExport.cs +++ b/Library/Export/StlExport.cs @@ -27,10 +27,13 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -56,7 +59,7 @@ namespace MatterHackers.MatterControl.Library.Export public bool ExportPossible(ILibraryAsset libraryItem) => true; - public Task Generate(IEnumerable libraryItems, string outputPath) + public Task Generate(IEnumerable libraryItems, string outputPath, IProgress progress, CancellationToken cancellationToken) { if (libraryItems.OfType().FirstOrDefault() is ILibraryAsset libraryItem) { diff --git a/Library/Export/ZipExport.cs b/Library/Export/ZipExport.cs index 7899d92d9..7e3ddf93e 100644 --- a/Library/Export/ZipExport.cs +++ b/Library/Export/ZipExport.cs @@ -32,7 +32,9 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; +using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -58,7 +60,7 @@ namespace MatterHackers.MatterControl.Library.Export public bool ExportPossible(ILibraryAsset libraryItem) => true; - public async Task Generate(IEnumerable libraryItems, string outputPath) + public async Task Generate(IEnumerable libraryItems, string outputPath, IProgress progress, CancellationToken cancellationToken) { var streamItems = libraryItems.OfType(); if (streamItems.Any()) diff --git a/PrinterCommunication/Drivers/X3G/X3GExport.cs b/PrinterCommunication/Drivers/X3G/X3GExport.cs index 81f16f5ec..69eccb02b 100644 --- a/PrinterCommunication/Drivers/X3G/X3GExport.cs +++ b/PrinterCommunication/Drivers/X3G/X3GExport.cs @@ -31,7 +31,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.Platform; using MatterHackers.MatterControl.Library; @@ -65,7 +67,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver public bool ExportPossible(ILibraryAsset libraryItem) => true; - public async Task Generate(IEnumerable libraryItems, string outputPath) + public async Task Generate(IEnumerable libraryItems, string outputPath, IProgress progress, CancellationToken cancellationToken) { ILibraryAssetStream libraryContent = libraryItems.OfType().FirstOrDefault(); diff --git a/SlicerConfiguration/Slicer.cs b/SlicerConfiguration/Slicer.cs index 7e6312ece..54e2f4233 100644 --- a/SlicerConfiguration/Slicer.cs +++ b/SlicerConfiguration/Slicer.cs @@ -39,6 +39,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.DataConverters3D; using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.SettingsManagement; using MatterHackers.MeshVisualizer; @@ -235,8 +236,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return SliceItem(stlFileLocations, mergeRules, gcodeFilePath, printer, progressReporter, cancellationToken); } - public static Task SliceItem(List<(Matrix4X4 matrix, string fileName)> stlFileLocations, string mergeRules, string gcodeFilePath, PrinterConfig printer, IProgress progressReporter, CancellationToken cancellationToken) + public static Task SliceItem(List<(Matrix4X4 matrix, string fileName)> stlFileLocations, string mergeRules, string gcodeFilePath, PrinterConfig printer, IProgress reporter, CancellationToken cancellationToken) { + // Wrap the reporter with a specialized MatterSlice string parser for percent from string results + var sliceProgressReporter = new SliceProgressReporter(reporter, printer); + bool slicingSucceeded = true; if(stlFileLocations.Count > 0) @@ -245,14 +249,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration { Status = "Generating Config" }; - progressReporter.Report(progressStatus); + sliceProgressReporter.Report(progressStatus); string configFilePath = Path.Combine( ApplicationDataStorage.Instance.GCodeOutputPath, string.Format("config_{0}.ini", printer.Settings.GetLongHashCode().ToString())); progressStatus.Status = "Starting slicer"; - progressReporter.Report(progressStatus); + sliceProgressReporter.Report(progressStatus); if (!File.Exists(gcodeFilePath) || !HasCompletedSuccessfully(gcodeFilePath)) @@ -301,7 +305,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } if (s is string stringValue) { - progressReporter?.Report(new ProgressStatus() + + + + sliceProgressReporter?.Report(new ProgressStatus() { Status = stringValue }); @@ -350,7 +357,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } message += "..."; - progressReporter?.Report(new ProgressStatus() + sliceProgressReporter?.Report(new ProgressStatus() { Status = message });