diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index f25914884..acafea501 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -139,9 +139,9 @@ namespace MatterHackers.MatterControl } } - public void LoadGCode(string filePath, ReportProgressRatio<(double,string)> progressReporter) + public void LoadGCode(string filePath, CancellationToken cancellationToken, ReportProgressRatio<(double,string)> progressReporter) { - this.LoadedGCode = GCodeMemoryFile.Load(filePath, progressReporter); + this.LoadedGCode = GCodeMemoryFile.Load(filePath, cancellationToken, progressReporter); this.GCodeRenderer = new GCodeRenderer(loadedGCode); if (ActiveSliceSettings.Instance.PrinterSelected) diff --git a/CustomWidgets/ExportPrintItemWindow.cs b/CustomWidgets/ExportPrintItemWindow.cs index c639868a3..6a0b28d17 100644 --- a/CustomWidgets/ExportPrintItemWindow.cs +++ b/CustomWidgets/ExportPrintItemWindow.cs @@ -20,6 +20,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Threading.Tasks; +using System.Threading; namespace MatterHackers.MatterControl { @@ -339,7 +340,7 @@ namespace MatterHackers.MatterControl { try { - GCodeFileStream gCodeFileStream = new GCodeFileStream(GCodeFile.Load(gcodeFilename)); + GCodeFileStream gCodeFileStream = new GCodeFileStream(GCodeFile.Load(gcodeFilename, CancellationToken.None)); bool addLevelingStream = ActiveSliceSettings.Instance.GetValue(SettingsKey.print_leveling_enabled) && applyLeveling.Checked; var queueStream = new QueuedCommandsStream(gCodeFileStream); @@ -445,7 +446,7 @@ namespace MatterHackers.MatterControl } else { - IObject3D item = Object3D.Load(printItemWrapper.FileLocation); + IObject3D item = Object3D.Load(printItemWrapper.FileLocation, CancellationToken.None); MeshFileIo.Save(item, filePathToSave); } ShowFileIfRequested(filePathToSave); @@ -500,7 +501,7 @@ namespace MatterHackers.MatterControl } else { - IObject3D loadedItem = Object3D.Load(printItemWrapper.FileLocation); + IObject3D loadedItem = Object3D.Load(printItemWrapper.FileLocation, CancellationToken.None); if (!MeshFileIo.Save(new List { loadedItem.Flatten() }, filePathToSave)) { diff --git a/Library/ContentProviders/MeshContentProvider.cs b/Library/ContentProviders/MeshContentProvider.cs index 422e940c0..072a3558e 100644 --- a/Library/ContentProviders/MeshContentProvider.cs +++ b/Library/ContentProviders/MeshContentProvider.cs @@ -33,6 +33,7 @@ namespace MatterHackers.MatterControl { using System; using System.IO; + using System.Threading; using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.PlatformAbstract; @@ -82,7 +83,7 @@ namespace MatterHackers.MatterControl if (contentStream != null) { // TODO: Wire up caching - loadedItem = Object3D.Load(contentStream.Stream, Path.GetExtension(streamInterface.FileName), null /*itemCache*/, progressReporter); + loadedItem = Object3D.Load(contentStream.Stream, Path.GetExtension(streamInterface.FileName), CancellationToken.None, null /*itemCache*/, progressReporter); } } } diff --git a/Library/Providers/MatterControl/SqliteLibraryContainer.cs b/Library/Providers/MatterControl/SqliteLibraryContainer.cs index 3ca875927..fcd6fcadb 100644 --- a/Library/Providers/MatterControl/SqliteLibraryContainer.cs +++ b/Library/Providers/MatterControl/SqliteLibraryContainer.cs @@ -31,6 +31,7 @@ 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.UI; @@ -269,7 +270,7 @@ namespace MatterHackers.MatterControl.Library try { // Load mesh - IObject3D loadedItem = MeshFileIo.Load(stream, extension); + IObject3D loadedItem = MeshFileIo.Load(stream, extension, CancellationToken.None); // Create a new PrintItemWrapper if (!printItem.FileLocation.Contains(ApplicationDataStorage.Instance.ApplicationLibraryDataPath)) diff --git a/Library/Widgets/ListView/ListViewItem.cs b/Library/Widgets/ListView/ListViewItem.cs index 9e07fac38..02f5c9abd 100644 --- a/Library/Widgets/ListView/ListViewItem.cs +++ b/Library/Widgets/ListView/ListViewItem.cs @@ -48,7 +48,7 @@ namespace MatterHackers.MatterControl.CustomWidgets ProgressControl processingProgressControl; - internal void ProgressReporter((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) + internal void ProgressReporter((double progress0To1, string processingState) progress) { if (processingProgressControl == null) { diff --git a/MatterControl.Printing/GCode/GCodeFile.cs b/MatterControl.Printing/GCode/GCodeFile.cs index e08ff0e72..6471d72b2 100644 --- a/MatterControl.Printing/GCode/GCodeFile.cs +++ b/MatterControl.Printing/GCode/GCodeFile.cs @@ -33,6 +33,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading.Tasks; +using System.Threading; namespace MatterHackers.GCodeVisualizer { @@ -175,7 +176,7 @@ namespace MatterHackers.GCodeVisualizer return false; } - public static GCodeFile Load(string fileName) + public static GCodeFile Load(string fileName, CancellationToken cancellationToken) { if (FileTooBigToLoad(fileName)) { @@ -183,7 +184,7 @@ namespace MatterHackers.GCodeVisualizer } else { - return new GCodeMemoryFile(fileName); + return new GCodeMemoryFile(fileName, cancellationToken); } } diff --git a/MatterControl.Printing/GCode/GCodeMemoryFile.cs b/MatterControl.Printing/GCode/GCodeMemoryFile.cs index 1bde9541c..8ef4b3fbb 100644 --- a/MatterControl.Printing/GCode/GCodeMemoryFile.cs +++ b/MatterControl.Printing/GCode/GCodeMemoryFile.cs @@ -61,11 +61,11 @@ namespace MatterHackers.GCodeVisualizer this.gcodeHasExplicitLayerChangeInfo = gcodeHasExplicitLayerChangeInfo; } - public GCodeMemoryFile(string pathAndFileName, bool gcodeHasExplicitLayerChangeInfo = false) + public GCodeMemoryFile(string pathAndFileName, CancellationToken cancellationToken, bool gcodeHasExplicitLayerChangeInfo = false) { this.gcodeHasExplicitLayerChangeInfo = gcodeHasExplicitLayerChangeInfo; - var loadedFile = GCodeMemoryFile.Load(pathAndFileName, null); + var loadedFile = GCodeMemoryFile.Load(pathAndFileName, cancellationToken, null); if (loadedFile != null) { this.indexOfChangeInZ = loadedFile.indexOfChangeInZ; @@ -108,18 +108,18 @@ namespace MatterHackers.GCodeVisualizer GCodeCommandQueue.Insert(insertIndex, printerMachineInstruction); } - public static GCodeFile ParseGCodeString(string gcodeContents) + public static GCodeFile ParseGCodeString(string gcodeContents, CancellationToken cancellationToken) { - return ParseFileContents(gcodeContents, null); + return ParseFileContents(gcodeContents, cancellationToken, null); } - public static GCodeMemoryFile Load(Stream fileStream, ReportProgressRatio<(double ratio, string state)> progressReporter = null) + public static GCodeMemoryFile Load(Stream fileStream, CancellationToken cancellationToken, ReportProgressRatio<(double ratio, string state)> progressReporter = null) { try { using (var reader = new StreamReader(fileStream)) { - return ParseFileContents(reader.ReadToEnd(), progressReporter); + return ParseFileContents(reader.ReadToEnd(), cancellationToken, progressReporter); } } catch (Exception e) @@ -130,7 +130,7 @@ namespace MatterHackers.GCodeVisualizer return null; } - public static GCodeMemoryFile Load(string filePath, ReportProgressRatio<(double ratio, string state)> progressReporter) + public static GCodeMemoryFile Load(string filePath, CancellationToken cancellationToken, ReportProgressRatio<(double ratio, string state)> progressReporter) { if (Path.GetExtension(filePath).ToUpper() == ".GCODE") { @@ -138,7 +138,7 @@ namespace MatterHackers.GCodeVisualizer { using (var stream = File.OpenRead(filePath)) { - return Load(stream, progressReporter); + return Load(stream, cancellationToken, progressReporter); } } catch (Exception e) @@ -180,7 +180,7 @@ namespace MatterHackers.GCodeVisualizer return crCount + 1; } - public static GCodeMemoryFile ParseFileContents(string gCodeString, ReportProgressRatio<(double ratio, string state)> progressReporter) + public static GCodeMemoryFile ParseFileContents(string gCodeString, CancellationToken cancellationToken, ReportProgressRatio<(double ratio, string state)> progressReporter) { if (gCodeString == null) { @@ -259,9 +259,9 @@ namespace MatterHackers.GCodeVisualizer if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200) { - var continueProcessing = new CancellationTokenSource(); - progressReporter(((double)lineIndex / crCount / 2, ""), continueProcessing); - if (continueProcessing.IsCancellationRequested) + progressReporter(((double)lineIndex / crCount / 2, "")); + + if (cancellationToken.IsCancellationRequested) { return null; } @@ -272,7 +272,7 @@ namespace MatterHackers.GCodeVisualizer lineIndex++; } - loadedGCodeFile.AnalyzeGCodeLines(progressReporter); + loadedGCodeFile.AnalyzeGCodeLines(cancellationToken, progressReporter); loadTime.Stop(); Console.WriteLine("Time To Load Seconds: {0:0.00}".FormatWith(loadTime.Elapsed.TotalSeconds)); @@ -280,7 +280,7 @@ namespace MatterHackers.GCodeVisualizer return loadedGCodeFile; } - private void AnalyzeGCodeLines(ReportProgressRatio<(double ratio, string state)> progressReporter) + private void AnalyzeGCodeLines(CancellationToken cancellationToken, ReportProgressRatio<(double ratio, string state)> progressReporter) { double feedRateMmPerMin = 0; Vector3 lastPrinterPosition = new Vector3(); @@ -334,9 +334,8 @@ namespace MatterHackers.GCodeVisualizer if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200) { - var continueProcessing = new CancellationTokenSource(); - progressReporter((((double) lineIndex / GCodeCommandQueue.Count / 2) + .5, ""), continueProcessing); - if (continueProcessing.IsCancellationRequested) + progressReporter((((double) lineIndex / GCodeCommandQueue.Count / 2) + .5, "")); + if (cancellationToken.IsCancellationRequested) { return; } diff --git a/PartPreviewWindow/CreateDiscreteMeshes.cs b/PartPreviewWindow/CreateDiscreteMeshes.cs index afda75f5a..7cc98b5c6 100644 --- a/PartPreviewWindow/CreateDiscreteMeshes.cs +++ b/PartPreviewWindow/CreateDiscreteMeshes.cs @@ -47,19 +47,19 @@ namespace MatterHackers.MatterControl public static class CreateDiscreteMeshes { - public static List SplitConnectedIntoMeshes(MeshGroup meshGroupToSplit, ReportProgressRatio<(double ratio, string state)> reportProgress) + public static List SplitConnectedIntoMeshes(MeshGroup meshGroupToSplit, CancellationToken cancellationToken, ReportProgressRatio<(double ratio, string state)> reportProgress) { List discreteMeshes = new List(); double ratioPerDiscreetMesh = 1.0 / meshGroupToSplit.Meshes.Count; double currentRatioDone = 0; foreach (Mesh mesh in meshGroupToSplit.Meshes) { - List discreteVolumes = SplitVolumesIntoMeshes(mesh, ((double progress0To1, string processingState) progressIn, CancellationTokenSource continueProcessing) => + List discreteVolumes = SplitVolumesIntoMeshes(mesh, cancellationToken, ((double progress0To1, string processingState) progressIn) => { if (reportProgress != null) { double progress = (currentRatioDone + ratioPerDiscreetMesh * progressIn.progress0To1); - reportProgress((progress, "Split Into Meshes"), continueProcessing); + reportProgress.Invoke((progress, "Split Into Meshes")); } }); discreteMeshes.AddRange(discreteVolumes); @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl return discreteMeshes; } - public static List SplitVolumesIntoMeshes(Mesh meshToSplit, ReportProgressRatio<(double ratio, string state)> reportProgress) + public static List SplitVolumesIntoMeshes(Mesh meshToSplit, CancellationToken cancellationToken, ReportProgressRatio<(double ratio, string state)> reportProgress) { List discreetVolumes = new List(); HashSet facesThatHaveBeenAdded = new HashSet(); @@ -117,15 +117,15 @@ namespace MatterHackers.MatterControl } } - meshFromCurrentVolume.CleanAndMergMesh(); + meshFromCurrentVolume.CleanAndMergMesh(cancellationToken); discreetVolumes.Add(meshFromCurrentVolume); meshFromCurrentVolume = null; } + if (reportProgress != null) { double progress = faceIndex / (double)meshToSplit.Faces.Count; - var continueProcessing = new CancellationTokenSource(); - reportProgress((progress, "Split Into Meshes"), continueProcessing); + reportProgress((progress, "Split Into Meshes")); } } @@ -150,11 +150,7 @@ namespace MatterHackers.MatterControl PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partPlate.NewGraphics2D(), meshToSplit, renderOffset, scaleFactor, RGBA_Bytes.White); - var continueProcessin = new CancellationTokenSource(); - if (reportProgress != null) - { - reportProgress((.2, ""), continueProcessin); - } + reportProgress?.Invoke((.2, "")); //ImageIO.SaveImageData("test part plate 0.png", partPlate); // expand the bounds a bit so that we can collect all the vertices and polygons within each bound @@ -191,10 +187,9 @@ namespace MatterHackers.MatterControl { graphics2D.Render(PlatingHelper.PolygonToPathStorage(polygon), new RGBA_Bytes(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))); } - if (reportProgress != null) - { - reportProgress((.5, ""), continueProcessin); - } + + reportProgress?.Invoke((.5, "")); + //ImageIO.SaveImageData("test part plate 2.png", partPlate); // add each of the separate bounds polygons to new meshes @@ -238,10 +233,7 @@ namespace MatterHackers.MatterControl } } - if (reportProgress != null) - { - reportProgress((.8, ""), continueProcessin); - } + reportProgress?.Invoke((.8, "")); for (int i = 0; i < discreteMeshes.Count(); i++) { diff --git a/PartPreviewWindow/View3D/DragDropLoadProgress.cs b/PartPreviewWindow/View3D/DragDropLoadProgress.cs index 0f597c3b4..7d9422e9a 100644 --- a/PartPreviewWindow/View3D/DragDropLoadProgress.cs +++ b/PartPreviewWindow/View3D/DragDropLoadProgress.cs @@ -70,7 +70,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - public void ProgressReporter((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) + public void ProgressReporter((double progress0To1, string processingState) progress) { progressBar.RatioComplete = progress.progress0To1; view3DWidget?.Invalidate(); diff --git a/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs b/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs index ee8c9f5b1..b7ed8b40d 100644 --- a/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs +++ b/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using System.IO; +using System.Threading; using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.PlatformAbstract; @@ -139,7 +140,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow string arrowFile = Path.Combine("Icons", "3D Icons", "up_pointer.stl"); using (Stream arrowStream = StaticData.Instance.OpenSteam(arrowFile)) { - upArrowMesh = MeshFileIo.Load(arrowStream, Path.GetExtension(arrowFile)).Mesh; + upArrowMesh = MeshFileIo.Load(arrowStream, Path.GetExtension(arrowFile), CancellationToken.None).Mesh; } CollisionVolume = upArrowMesh.CreateTraceData(); diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index 5e3dd7072..b2c1df9b9 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -418,14 +418,18 @@ namespace MatterHackers.MeshVisualizer public bool SuppressUiVolumes { get; set; } = false; + private CancellationTokenSource fileLoadCancellationTokenSource; + public async Task LoadItemIntoScene(string itemPath, Vector2 bedCenter = new Vector2(), string itemName = null) { if (File.Exists(itemPath)) { BeginProgressReporting("Loading Mesh"); + fileLoadCancellationTokenSource = new CancellationTokenSource(); + // TODO: How to we handle mesh load errors? How do we report success? - IObject3D loadedItem = await Task.Run(() => Object3D.Load(itemPath, progress: ReportProgress0to100)); + IObject3D loadedItem = await Task.Run(() => Object3D.Load(itemPath, fileLoadCancellationTokenSource.Token, progress: ReportProgress0to100)); if (loadedItem != null) { if (itemName != null) @@ -463,6 +467,14 @@ namespace MatterHackers.MeshVisualizer { partProcessingInfo.centeredInfoText.Text = string.Format("{0}\n'{1}'", "File not found on disk.", Path.GetFileName(itemPath)); } + + fileLoadCancellationTokenSource = null; + } + + public override void OnClosed(ClosedEventArgs e) + { + fileLoadCancellationTokenSource?.Cancel(); + base.OnClosed(e); } public override void OnDraw(Graphics2D graphics2D) @@ -581,13 +593,8 @@ namespace MatterHackers.MeshVisualizer partProcessingInfo.Visible = false; } - public void ReportProgress0to100((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) + public void ReportProgress0to100((double progress0To1, string processingState) progress) { - if (this.HasBeenClosed) - { - continueProcessing.Cancel(); - } - UiThread.RunOnIdle(() => { int percentComplete = (int)(progress.progress0To1 * 100); diff --git a/PartPreviewWindow/View3D/PrinterActionsBar.cs b/PartPreviewWindow/View3D/PrinterActionsBar.cs index 7f5d3cf81..463657772 100644 --- a/PartPreviewWindow/View3D/PrinterActionsBar.cs +++ b/PartPreviewWindow/View3D/PrinterActionsBar.cs @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ using System; +using System.Threading; using MatterHackers.Agg; using MatterHackers.Agg.PlatformAbstract; using MatterHackers.Agg.UI; @@ -51,6 +52,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private SliceProgressReporter sliceProgressReporter; + private CancellationTokenSource gcodeLoadCancellationTokenSource; + public class SliceProgressReporter : IProgress { private MeshViewerWidget meshViewer; @@ -120,7 +123,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow await SlicingQueue.SliceFileAsync(printItem, sliceProgressReporter); - ApplicationController.Instance.Printer.BedPlate.LoadGCode(printItem.GetGCodePathAndFileName(), printerTabPage.modelViewer.gcodeViewer.LoadProgress_Changed); + gcodeLoadCancellationTokenSource = new CancellationTokenSource(); + + ApplicationController.Instance.Printer.BedPlate.LoadGCode(printItem.GetGCodePathAndFileName(), gcodeLoadCancellationTokenSource.Token, printerTabPage.modelViewer.gcodeViewer.LoadProgress_Changed); sliceProgressReporter.EndReporting(); printerTabPage.ViewMode = PartViewMode.Layers3D; @@ -215,6 +220,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.AddChild(overflowDropdown); } + public override void OnClosed(ClosedEventArgs e) + { + gcodeLoadCancellationTokenSource?.Cancel(); + base.OnClosed(e); + } + private GuiWidget GeneratePrinterOverflowMenu() { var widgetToPop = new FlowLayoutWidget() diff --git a/PartPreviewWindow/View3D/SceneActions.cs b/PartPreviewWindow/View3D/SceneActions.cs index 091a93991..de12743a2 100644 --- a/PartPreviewWindow/View3D/SceneActions.cs +++ b/PartPreviewWindow/View3D/SceneActions.cs @@ -62,9 +62,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow && !selectedItem.HasChildren && selectedItem.Mesh != null) { - var discreetMeshes = CreateDiscreteMeshes.SplitVolumesIntoMeshes(Scene.SelectedItem.Mesh, ((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) => + var discreetMeshes = CreateDiscreteMeshes.SplitVolumesIntoMeshes(Scene.SelectedItem.Mesh, CancellationToken.None, ((double progress0To1, string processingState) progress) => { - view3DWidget.ReportProgressChanged(progress.progress0To1 * .5, progress.processingState, continueProcessing); + view3DWidget.ReportProgressChanged(progress.progress0To1 * .5, progress.processingState); }); if (discreetMeshes.Count == 1) diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index f0fa47585..76ae10c4e 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -651,7 +651,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow boxB.Transform(transformB); Mesh meshToAdd = meshOpperation(boxA, boxB); - meshToAdd.CleanAndMergMesh(); + meshToAdd.CleanAndMergMesh(CancellationToken.None); if (aabbOpperation != null) { @@ -872,7 +872,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } else { - return Object3D.Load(dragDropItem.MeshPath, progress: new DragDropLoadProgress(this, dragDropItem).ProgressReporter); + return Object3D.Load(dragDropItem.MeshPath, CancellationToken.None, progress: new DragDropLoadProgress(this, dragDropItem).ProgressReporter); } } else if (DragSourceModel != null) @@ -890,17 +890,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { sourceListItem.StartProgress(); - contentResult = DragSourceModel.CreateContent(((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) => + contentResult = DragSourceModel.CreateContent(((double progress0To1, string processingState) progress) => { - sourceListItem.ProgressReporter(progress, continueProcessing); - loadProgress.ProgressReporter(progress, continueProcessing); + sourceListItem.ProgressReporter(progress); + loadProgress.ProgressReporter(progress); }); await contentResult.MeshLoaded; sourceListItem.EndProgress(); - loadProgress.ProgressReporter((1, ""), new CancellationTokenSource()); + loadProgress.ProgressReporter((1, "")); } return contentResult?.Object3D; @@ -1587,13 +1587,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - private void ReportProgressChanged(double progress0To1, string processingState) - { - var continueProcessing = new CancellationTokenSource(); - ReportProgressChanged(progress0To1, processingState, continueProcessing); - } - - internal void ReportProgressChanged(double progress0To1, string processingState, CancellationTokenSource continueProcessing) + internal void ReportProgressChanged(double progress0To1, string processingState) { if (!timeSinceReported.IsRunning || timeSinceReported.ElapsedMilliseconds > 100 || processingState != processingProgressControl.ProgressMessage) @@ -1848,11 +1842,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { var libraryItem = new FileSystemFileItem(filePath); - var contentResult = libraryItem.CreateContent(((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) => + var contentResult = libraryItem.CreateContent(((double progress0To1, string processingState) progress) => { double ratioAvailable = (ratioPerFile * .5); double currentRatio = currentRatioDone + progress.progress0To1 * ratioAvailable; - ReportProgressChanged(currentRatio, progressMessage, continueProcessing); + + ReportProgressChanged(currentRatio, progressMessage); }); contentResult?.MeshLoaded.ContinueWith((task) => diff --git a/PartPreviewWindow/ViewGcodeBasic.cs b/PartPreviewWindow/ViewGcodeBasic.cs index 95b6ccb84..e51c55200 100644 --- a/PartPreviewWindow/ViewGcodeBasic.cs +++ b/PartPreviewWindow/ViewGcodeBasic.cs @@ -174,13 +174,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - internal void LoadProgress_Changed((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) + internal void LoadProgress_Changed((double progress0To1, string processingState) progress) { SetProcessingMessage(string.Format("{0} {1:0}%...", gcodeLoading, progress.progress0To1 * 100)); - if(this.HasBeenClosed) - { - continueProcessing.Cancel(); - } } private void SetProcessingMessage(string message) diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index 0c4144e99..e91e4e69f 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -2312,7 +2312,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication GCodeStream firstStream = null; if (gcodeFilename != null) { - loadedGCode = GCodeFile.Load(gcodeFilename); + loadedGCode = GCodeFile.Load(gcodeFilename, CancellationToken.None); gCodeFileStream0 = new GCodeFileStream(loadedGCode); if (ActiveSliceSettings.Instance.GetValue(SettingsKey.recover_is_enabled) diff --git a/Queue/OptionsMenu/ExportToFolderProcess.cs b/Queue/OptionsMenu/ExportToFolderProcess.cs index 3c5aaab1d..1a77c0edb 100644 --- a/Queue/OptionsMenu/ExportToFolderProcess.cs +++ b/Queue/OptionsMenu/ExportToFolderProcess.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using System.IO; +using System.Threading; using MatterHackers.Agg; using MatterHackers.DataConverters3D; using MatterHackers.GCodeVisualizer; @@ -190,7 +191,7 @@ namespace MatterHackers.MatterControl.PrintQueue if (ActiveSliceSettings.Instance.GetValue(SettingsKey.print_leveling_enabled)) { - GCodeMemoryFile unleveledGCode = new GCodeMemoryFile(savedGcodeFileName); + GCodeMemoryFile unleveledGCode = new GCodeMemoryFile(savedGcodeFileName, CancellationToken.None); for (int j = 0; j < unleveledGCode.LineCount; j++) { diff --git a/SlicerConfiguration/SlicingQueue.cs b/SlicerConfiguration/SlicingQueue.cs index 961e6d00d..3c6264af9 100644 --- a/SlicerConfiguration/SlicingQueue.cs +++ b/SlicerConfiguration/SlicingQueue.cs @@ -151,7 +151,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration case ".AMF": case ".OBJ": // TODO: Once graph parsing is added to MatterSlice we can remove and avoid this flattening - List meshGroups = new List { Object3D.Load(fileToSlice).Flatten() }; + List meshGroups = new List { Object3D.Load(fileToSlice, CancellationToken.None).Flatten() }; if (meshGroups != null) { List extruderMeshGroups = new List(); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index f865fe5d7..d77505eac 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit f865fe5d782de19ab393f772f39bd387cccb26af +Subproject commit d77505eacee3d4d89a399288f75935a9b98756fa diff --git a/Tests/MatterControl.Tests/MatterControl/Slicing/SliceLayersTests.cs b/Tests/MatterControl.Tests/MatterControl/Slicing/SliceLayersTests.cs index 3cc383798..d96c9fc1b 100644 --- a/Tests/MatterControl.Tests/MatterControl/Slicing/SliceLayersTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/Slicing/SliceLayersTests.cs @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System.Threading; using MatterHackers.Agg.PlatformAbstract; #if !__ANDROID__ using MatterHackers.MatterControl.Tests.Automation; @@ -52,7 +53,7 @@ namespace MatterHackers.MatterControl.Slicing.Tests } string meshFileName = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestMeshes", "SliceLayers", "Box20x20x10.stl"); - Mesh cubeMesh = StlProcessing.Load(meshFileName); + Mesh cubeMesh = StlProcessing.Load(meshFileName, CancellationToken.None); AxisAlignedBoundingBox bounds = cubeMesh.GetAxisAlignedBoundingBox(); Assert.IsTrue(bounds.ZSize == 10); diff --git a/Tests/MatterControl.Tests/SceneTests.cs b/Tests/MatterControl.Tests/SceneTests.cs index 19f59a2f1..637205f0d 100644 --- a/Tests/MatterControl.Tests/SceneTests.cs +++ b/Tests/MatterControl.Tests/SceneTests.cs @@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project. using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.Agg.PlatformAbstract; @@ -61,7 +62,7 @@ namespace MatterHackers.PolygonMesh.UnitTests Assert.IsTrue(File.Exists(filePath)); - IObject3D loadedItem = Object3D.Load(filePath); + IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None); Assert.IsTrue(loadedItem.Children.Count == 1); } @@ -84,7 +85,7 @@ namespace MatterHackers.PolygonMesh.UnitTests Assert.IsTrue(File.Exists(filePath)); - IObject3D loadedItem = Object3D.Load(filePath); + IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None); Assert.IsTrue(loadedItem.Children.Count == 1); IObject3D meshItem = loadedItem.Children.First(); @@ -140,7 +141,7 @@ namespace MatterHackers.PolygonMesh.UnitTests var originalFiles = Directory.GetFiles(tempPath).ToArray(); ; - IObject3D loadedItem = Object3D.Load(filePath); + IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None); Assert.IsTrue(loadedItem.Children.Count == 1); await view3DWidget.ClearBedAndLoadPrintItemWrapper(