diff --git a/Library/ContentProviders/GCodeContentProvider.cs b/Library/ContentProviders/GCodeContentProvider.cs index bf74cb283..d4f9f4cfb 100644 --- a/Library/ContentProviders/GCodeContentProvider.cs +++ b/Library/ContentProviders/GCodeContentProvider.cs @@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl thumbnailImage = thumbIcon; } - public ContentResult CreateItem(ILibraryItem item, ReportProgressRatio reporter) + public ContentResult CreateItem(ILibraryItem item, ReportProgressRatio<(double ratio, string state)> reporter) { System.Diagnostics.Debugger.Break(); return null; diff --git a/Library/ContentProviders/IContentProvider.cs b/Library/ContentProviders/IContentProvider.cs index 056a89968..72966243b 100644 --- a/Library/ContentProviders/IContentProvider.cs +++ b/Library/ContentProviders/IContentProvider.cs @@ -47,7 +47,7 @@ namespace MatterHackers.MatterControl.Library public interface ISceneContentProvider : IContentProvider { // TODO: Needs to take a progress reporter that is used in the background task which creates the actual IObject3D mesh and children - ContentResult CreateItem(ILibraryItem item, ReportProgressRatio reporter); + ContentResult CreateItem(ILibraryItem item, ReportProgressRatio<(double ratio, string state)> reporter); } public interface IPrintableContentProvider : IContentProvider diff --git a/Library/ContentProviders/MeshContentProvider.cs b/Library/ContentProviders/MeshContentProvider.cs index 78898e235..422e940c0 100644 --- a/Library/ContentProviders/MeshContentProvider.cs +++ b/Library/ContentProviders/MeshContentProvider.cs @@ -56,7 +56,7 @@ namespace MatterHackers.MatterControl private static readonly int MaxFileSize = (OsInformation.OperatingSystem == OSType.Android) ? tooBigAndroid : tooBigDesktop; private static readonly Point2D BigRenderSize = new Point2D(460, 460); - public ContentResult CreateItem(ILibraryItem item, ReportProgressRatio progressReporter) + public ContentResult CreateItem(ILibraryItem item, ReportProgressRatio<(double ratio, string state)> progressReporter) { var sceneItem = new Object3D() { diff --git a/Library/ExtensionMethods.cs b/Library/ExtensionMethods.cs index 05e78b603..a8c784881 100644 --- a/Library/ExtensionMethods.cs +++ b/Library/ExtensionMethods.cs @@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl.Library } } - public static ContentResult CreateContent(this ILibraryContentStream item, ReportProgressRatio reporter = null) + public static ContentResult CreateContent(this ILibraryContentStream item, ReportProgressRatio<(double ratio, string state)> reporter = null) { var contentProvider = ApplicationController.Instance.Library.GetContentProvider(item) as ISceneContentProvider; return contentProvider?.CreateItem(item, reporter); diff --git a/Library/Interfaces/ILibraryContainerLink.cs b/Library/Interfaces/ILibraryContainerLink.cs index 9269374f5..7cad58def 100644 --- a/Library/Interfaces/ILibraryContainerLink.cs +++ b/Library/Interfaces/ILibraryContainerLink.cs @@ -34,6 +34,6 @@ namespace MatterHackers.MatterControl.Library { public interface ILibraryContainerLink : ILibraryItem { - Task GetContainer(ReportProgressRatio reportProgress); + Task GetContainer(ReportProgressRatio<(double ratio, string state)> reportProgress); } } diff --git a/Library/Interfaces/ILibraryItem.cs b/Library/Interfaces/ILibraryItem.cs index efc601371..cdacfcd26 100644 --- a/Library/Interfaces/ILibraryItem.cs +++ b/Library/Interfaces/ILibraryItem.cs @@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.Library { string ContentType { get; } string Category { get; } - Task GetContent(ReportProgressRatio reportProgress); + Task GetContent(ReportProgressRatio<(double ratio, string state)> reportProgress); void SetContent(IObject3D item); } @@ -58,6 +58,6 @@ namespace MatterHackers.MatterControl.Library string ContentType { get; } string FileName { get; } string AssetPath { get; } - Task GetContentStream(ReportProgressRatio reportProgress); + Task GetContentStream(ReportProgressRatio<(double ratio, string state)> reportProgress); } } diff --git a/Library/Providers/DynamicContainerLink.cs b/Library/Providers/DynamicContainerLink.cs index 999acd780..a0a56b378 100644 --- a/Library/Providers/DynamicContainerLink.cs +++ b/Library/Providers/DynamicContainerLink.cs @@ -56,7 +56,7 @@ namespace MatterHackers.MatterControl.Library public bool IsVisible => this.visibilityResolver(); - public Task GetContainer(ReportProgressRatio reportProgress) + public Task GetContainer(ReportProgressRatio<(double ratio, string state)> reportProgress) { return Task.FromResult(this.containerCreator()); } diff --git a/Library/Providers/FileSystem/FileSystemContainer.cs b/Library/Providers/FileSystem/FileSystemContainer.cs index fdeb0cb61..0c1bfb6bd 100644 --- a/Library/Providers/FileSystem/FileSystemContainer.cs +++ b/Library/Providers/FileSystem/FileSystemContainer.cs @@ -385,7 +385,7 @@ namespace MatterHackers.MatterControl.Library public bool UseIncrementedNameDuringTypeChange { get; set; } - public Task GetContainer(ReportProgressRatio reportProgress) + public Task GetContainer(ReportProgressRatio<(double ratio, string state)> reportProgress) { return Task.FromResult( new FileSystemContainer(this.Path) diff --git a/Library/Providers/FileSystem/FileSystemFileItem.cs b/Library/Providers/FileSystem/FileSystemFileItem.cs index 51549af25..d33d5a804 100644 --- a/Library/Providers/FileSystem/FileSystemFileItem.cs +++ b/Library/Providers/FileSystem/FileSystemFileItem.cs @@ -57,7 +57,7 @@ namespace MatterHackers.MatterControl.Library } } - public Task GetContentStream(ReportProgressRatio reportProgress) + public Task GetContentStream(ReportProgressRatio<(double ratio, string state)> reportProgress) { if (ApplicationController.Instance.IsLoadableFile(this.Path) && File.Exists(this.Path)) @@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl.Library return Task.FromResult(null); } - public Task GetContent(ReportProgressRatio reportProgress) + public Task GetContent(ReportProgressRatio<(double ratio, string state)> reportProgress) { throw new NotImplementedException(); } diff --git a/Library/Providers/GeneratorItem.cs b/Library/Providers/GeneratorItem.cs index fc41d40e1..4a0ef43f5 100644 --- a/Library/Providers/GeneratorItem.cs +++ b/Library/Providers/GeneratorItem.cs @@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.Library /// public Func Collector { get; } - public Task GetContent(ReportProgressRatio reportProgress) => Task.FromResult(Collector?.Invoke()); + public Task GetContent(ReportProgressRatio<(double ratio, string state)> reportProgress) => Task.FromResult(Collector?.Invoke()); public void SetContent(IObject3D item) { diff --git a/Library/Providers/MatterControl/HistoryContainer.cs b/Library/Providers/MatterControl/HistoryContainer.cs index e5bfa0d21..87d1ee66f 100644 --- a/Library/Providers/MatterControl/HistoryContainer.cs +++ b/Library/Providers/MatterControl/HistoryContainer.cs @@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.Library public bool IsVisible => true; - public Task GetContentStream(ReportProgressRatio reportProgress) + public Task GetContentStream(ReportProgressRatio<(double ratio, string state)> reportProgress) { throw new NotImplementedException(); } diff --git a/Library/Providers/MatterControl/SqliteLibraryContainer.cs b/Library/Providers/MatterControl/SqliteLibraryContainer.cs index 4e494a8a0..875f21e13 100644 --- a/Library/Providers/MatterControl/SqliteLibraryContainer.cs +++ b/Library/Providers/MatterControl/SqliteLibraryContainer.cs @@ -342,7 +342,7 @@ namespace MatterHackers.MatterControl.Library public bool IsVisible { get; set; } = true; - public Task GetContainer(ReportProgressRatio reportProgress) + public Task GetContainer(ReportProgressRatio<(double ratio, string state)> reportProgress) { return Task.FromResult( new SqliteLibraryContainer(this.ContainerID) diff --git a/Library/Providers/Zip/LocalZipContainerLink.cs b/Library/Providers/Zip/LocalZipContainerLink.cs index b5bc8f05d..c8c9d6e43 100644 --- a/Library/Providers/Zip/LocalZipContainerLink.cs +++ b/Library/Providers/Zip/LocalZipContainerLink.cs @@ -67,7 +67,7 @@ namespace MatterHackers.MatterControl.Library } } - public Task GetContainer(ReportProgressRatio reportProgress) + public Task GetContainer(ReportProgressRatio<(double ratio, string state)> reportProgress) { return Task.FromResult(new ZipMemoryContainer(this.currentDirectory, this.Path)); } diff --git a/Library/Providers/Zip/ZipMemoryItem.cs b/Library/Providers/Zip/ZipMemoryItem.cs index 41494a17e..27afbe639 100644 --- a/Library/Providers/Zip/ZipMemoryItem.cs +++ b/Library/Providers/Zip/ZipMemoryItem.cs @@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.Library /// public long FileSize { get; private set; } - public async Task GetContentStream(ReportProgressRatio reportProgress) + public async Task GetContentStream(ReportProgressRatio<(double ratio, string state)> reportProgress) { var memStream = await Task.Run(() => { @@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.Library } /* - public async Task GetContent(ReportProgressRatio reportProgress) + public async Task GetContent(ReportProgressRatio<(double ratio, string state)> reportProgress) { var streamAndLength = await GetContentStream(null); IObject3D object3D = Object3D.Load(streamAndLength.Stream, System.IO.Path.GetExtension(Name)); diff --git a/Library/Widgets/ListView/ListViewItem.cs b/Library/Widgets/ListView/ListViewItem.cs index 356f85845..9e07fac38 100644 --- a/Library/Widgets/ListView/ListViewItem.cs +++ b/Library/Widgets/ListView/ListViewItem.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Threading; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; @@ -47,20 +48,18 @@ namespace MatterHackers.MatterControl.CustomWidgets ProgressControl processingProgressControl; - internal void ProgressReporter(double progress0To1, string processingState, out bool continueProcessing) + internal void ProgressReporter((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) { - continueProcessing = true; - if (processingProgressControl == null) { return; } - processingProgressControl.Visible = progress0To1 != 0; - processingProgressControl.RatioComplete = progress0To1; - processingProgressControl.ProcessType = processingState; + processingProgressControl.Visible = progress.progress0To1 != 0; + processingProgressControl.RatioComplete = progress.progress0To1; + processingProgressControl.ProcessType = progress.processingState; - if (progress0To1 == 1) + if (progress.progress0To1 == 1) { EndProgress(); } diff --git a/MatterControl.Printing/GCode/GCodeMemoryFile.cs b/MatterControl.Printing/GCode/GCodeMemoryFile.cs index 4c5dd5d1f..400476a59 100644 --- a/MatterControl.Printing/GCode/GCodeMemoryFile.cs +++ b/MatterControl.Printing/GCode/GCodeMemoryFile.cs @@ -33,6 +33,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Threading; using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.VectorMath; @@ -125,7 +126,7 @@ namespace MatterHackers.GCodeVisualizer return loadedGCode; } - public static async Task LoadInBackground(string fileName, ReportProgressRatio progressReporter) + public static async Task LoadInBackground(string fileName, ReportProgressRatio<(double ratio, string state)> progressReporter) { if (Path.GetExtension(fileName).ToUpper() == ".GCODE") { @@ -198,7 +199,7 @@ namespace MatterHackers.GCodeVisualizer return crCount + 1; } - public static GCodeMemoryFile ParseFileContents(string gCodeString, ReportProgressRatio progressReporter) + public static GCodeMemoryFile ParseFileContents(string gCodeString, ReportProgressRatio<(double ratio, string state)> progressReporter) { if (gCodeString == null) { @@ -277,8 +278,9 @@ namespace MatterHackers.GCodeVisualizer if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200) { - progressReporter((double)lineIndex / crCount / 2, "", out bool continueProcessing); - if (!continueProcessing) + var continueProcessing = new CancellationTokenSource(); + progressReporter(((double)lineIndex / crCount / 2, ""), continueProcessing); + if (continueProcessing.IsCancellationRequested) { return null; } @@ -297,7 +299,7 @@ namespace MatterHackers.GCodeVisualizer return loadedGCodeFile; } - private void AnalyzeGCodeLines(ReportProgressRatio progressReporter) + private void AnalyzeGCodeLines(ReportProgressRatio<(double ratio, string state)> progressReporter) { double feedRateMmPerMin = 0; Vector3 lastPrinterPosition = new Vector3(); @@ -351,8 +353,9 @@ namespace MatterHackers.GCodeVisualizer if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200) { - progressReporter(((double) lineIndex / GCodeCommandQueue.Count / 2) + .5, "", out bool continueProcessing); - if (!continueProcessing) + var continueProcessing = new CancellationTokenSource(); + progressReporter((((double) lineIndex / GCodeCommandQueue.Count / 2) + .5, ""), continueProcessing); + if (continueProcessing.IsCancellationRequested) { return; } diff --git a/MatterControl.Printing/MatterControl.Printing.csproj b/MatterControl.Printing/MatterControl.Printing.csproj index c439ebf8a..4f2beb013 100644 --- a/MatterControl.Printing/MatterControl.Printing.csproj +++ b/MatterControl.Printing/MatterControl.Printing.csproj @@ -34,6 +34,9 @@ + + ..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll + @@ -58,5 +61,8 @@ VectorMath + + + \ No newline at end of file diff --git a/MatterControl.Printing/packages.config b/MatterControl.Printing/packages.config new file mode 100644 index 000000000..9958f16fb --- /dev/null +++ b/MatterControl.Printing/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/MatterControl.csproj b/MatterControl.csproj index beacf83ca..a2ff6ce78 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -427,8 +427,8 @@ - - packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll + + packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll diff --git a/PartPreviewWindow/CreateDiscreteMeshes.cs b/PartPreviewWindow/CreateDiscreteMeshes.cs index 324bfbf4b..173443bb3 100644 --- a/PartPreviewWindow/CreateDiscreteMeshes.cs +++ b/PartPreviewWindow/CreateDiscreteMeshes.cs @@ -37,6 +37,7 @@ using MatterHackers.VectorMath; using System; using System.Collections.Generic; using System.Linq; +using System.Threading; namespace MatterHackers.MatterControl { @@ -46,23 +47,19 @@ namespace MatterHackers.MatterControl public static class CreateDiscreteMeshes { - public static List SplitConnectedIntoMeshes(MeshGroup meshGroupToSplit, ReportProgressRatio reportProgress) + public static List SplitConnectedIntoMeshes(MeshGroup meshGroupToSplit, 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, out bool continueProcessing) => + List discreteVolumes = SplitVolumesIntoMeshes(mesh, ((double progress0To1, string processingState) progressIn, CancellationTokenSource continueProcessing) => { if (reportProgress != null) { - double progress = (currentRatioDone + ratioPerDiscreetMesh * progress0To1); - reportProgress(progress, "Split Into Meshes", out continueProcessing); - } - else - { - continueProcessing = true; + double progress = (currentRatioDone + ratioPerDiscreetMesh * progressIn.progress0To1); + reportProgress((progress, "Split Into Meshes"), continueProcessing); } }); discreteMeshes.AddRange(discreteVolumes); @@ -73,7 +70,7 @@ namespace MatterHackers.MatterControl return discreteMeshes; } - public static List SplitVolumesIntoMeshes(Mesh meshToSplit, ReportProgressRatio reportProgress) + public static List SplitVolumesIntoMeshes(Mesh meshToSplit, ReportProgressRatio<(double ratio, string state)> reportProgress) { List discreetVolumes = new List(); HashSet facesThatHaveBeenAdded = new HashSet(); @@ -127,15 +124,15 @@ namespace MatterHackers.MatterControl if (reportProgress != null) { double progress = faceIndex / (double)meshToSplit.Faces.Count; - bool continueProcessing; - reportProgress(progress, "Split Into Meshes", out continueProcessing); + var continueProcessing = new CancellationTokenSource(); + reportProgress((progress, "Split Into Meshes"), continueProcessing); } } return discreetVolumes; } - public static Mesh[] SplitIntoMeshesOnOrthographicZ(Mesh meshToSplit, Vector3 buildVolume, ReportProgressRatio reportProgress) + public static Mesh[] SplitIntoMeshesOnOrthographicZ(Mesh meshToSplit, Vector3 buildVolume, ReportProgressRatio<(double ratio, string state)> reportProgress) { // check if the part is bigger than the build plate (if it is we need to use that as our size) AxisAlignedBoundingBox partBounds = meshToSplit.GetAxisAlignedBoundingBox(); @@ -153,10 +150,10 @@ namespace MatterHackers.MatterControl PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partPlate.NewGraphics2D(), meshToSplit, renderOffset, scaleFactor, RGBA_Bytes.White); - bool continueProcessin = true; + var continueProcessin = new CancellationTokenSource(); if (reportProgress != null) { - reportProgress(.2, "", out continueProcessin); + reportProgress((.2, ""), continueProcessin); } //ImageIO.SaveImageData("test part plate 0.png", partPlate); @@ -196,7 +193,7 @@ namespace MatterHackers.MatterControl } if (reportProgress != null) { - reportProgress(.5, "", out continueProcessin); + reportProgress((.5, ""), continueProcessin); } //ImageIO.SaveImageData("test part plate 2.png", partPlate); @@ -243,7 +240,7 @@ namespace MatterHackers.MatterControl if (reportProgress != null) { - reportProgress(.8, "", out continueProcessin); + reportProgress((.8, ""), continueProcessin); } for (int i = 0; i < discreteMeshes.Count(); i++) diff --git a/PartPreviewWindow/GCode2DWidget.cs b/PartPreviewWindow/GCode2DWidget.cs index f2e41bc44..d99c8b72e 100644 --- a/PartPreviewWindow/GCode2DWidget.cs +++ b/PartPreviewWindow/GCode2DWidget.cs @@ -86,12 +86,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private GCodeFile loadedGCode => printer.BedPlate.LoadedGCode; - private ReportProgressRatio progressReporter; + private ReportProgressRatio<(double ratio, string state)> progressReporter; private View3DConfig options; private PrinterConfig printer; - public GCode2DWidget(Vector2 gridSizeMm, Vector2 gridCenterMm, ReportProgressRatio progressReporter) + public GCode2DWidget(Vector2 gridSizeMm, Vector2 gridCenterMm, ReportProgressRatio<(double ratio, string state)> progressReporter) { options = ApplicationController.Instance.Options.View3D; diff --git a/PartPreviewWindow/PlatingHelper.cs b/PartPreviewWindow/PlatingHelper.cs index d15ada7c7..03e4073f7 100644 --- a/PartPreviewWindow/PlatingHelper.cs +++ b/PartPreviewWindow/PlatingHelper.cs @@ -327,7 +327,7 @@ namespace MatterHackers.MatterControl } /* - public static void CreateITraceableForMeshGroup(List perMeshGroupInfo, List meshGroups, int meshGroupIndex, ReportProgressRatio reportProgress) + public static void CreateITraceableForMeshGroup(List perMeshGroupInfo, List meshGroups, int meshGroupIndex, ReportProgressRatio<(double ratio, string state)> reportProgress) { if (meshGroups != null) { @@ -348,8 +348,8 @@ namespace MatterHackers.MatterControl needUpdateTitle = true; if (reportProgress != null) { - bool continueProcessing; - reportProgress(currentAction / (double)totalActionCount, "Creating Trace Group", out continueProcessing); + var continueProcessing = new CancellationTokenSource(); + reportProgress(currentAction / (double)totalActionCount, "Creating Trace Group", continueProcessing); } // only allow limited recursion to speed this up building this data @@ -367,9 +367,9 @@ namespace MatterHackers.MatterControl return BoundingVolumeHierarchy.CreateNewHierachy(allPolys); } - private static List AddTraceDataForMesh(Mesh mesh, int totalActionCount, ref int currentAction, ref bool needToUpdateProgressReport, ReportProgressRatio reportProgress) + private static List AddTraceDataForMesh(Mesh mesh, int totalActionCount, ref int currentAction, ref bool needToUpdateProgressReport, ReportProgressRatio<(double ratio, string state)> reportProgress) { - bool continueProcessing; + var continueProcessing = new CancellationTokenSource(); List allPolys = new List(); List positions = new List(); @@ -403,7 +403,7 @@ namespace MatterHackers.MatterControl { if ((currentAction % 256) == 0 || needToUpdateProgressReport) { - reportProgress(currentAction / (double)totalActionCount, "Creating Trace Polygons", out continueProcessing); + reportProgress(currentAction / (double)totalActionCount, "Creating Trace Polygons", continueProcessing); needToUpdateProgressReport = false; } currentAction++; diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index dcf9b0271..3fab7d04d 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -48,6 +48,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using System.Xml.Linq; +using System.Threading; namespace MatterHackers.MeshVisualizer { @@ -751,27 +752,23 @@ namespace MatterHackers.MeshVisualizer partProcessingInfo.Visible = false; } - public void ReportProgress0to100(double progress0To1, string processingState, out bool continueProcessing) + public void ReportProgress0to100((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) { if (this.HasBeenClosed) { - continueProcessing = false; - } - else - { - continueProcessing = true; + continueProcessing.Cancel(); } UiThread.RunOnIdle(() => { - int percentComplete = (int)(progress0To1 * 100); + int percentComplete = (int)(progress.progress0To1 * 100); partProcessingInfo.centeredInfoText.Text = "{0} {1}%...".FormatWith(progressReportingPrimaryTask, percentComplete); partProcessingInfo.progressControl.PercentComplete = percentComplete; // Only assign to textbox if value passed through - if (processingState != null) + if (progress.processingState != null) { - partProcessingInfo.centeredInfoDescription.Text = processingState; + partProcessingInfo.centeredInfoDescription.Text = progress.processingState; } }); } diff --git a/PartPreviewWindow/View3D/SceneActions.cs b/PartPreviewWindow/View3D/SceneActions.cs index c57b2c0e6..85fd4bea7 100644 --- a/PartPreviewWindow/View3D/SceneActions.cs +++ b/PartPreviewWindow/View3D/SceneActions.cs @@ -32,6 +32,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; using MatterHackers.Localizations; @@ -61,9 +62,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow && !selectedItem.HasChildren && selectedItem.Mesh != null) { - var discreetMeshes = CreateDiscreteMeshes.SplitVolumesIntoMeshes(Scene.SelectedItem.Mesh, (double progress0To1, string processingState, out bool continueProcessing) => + var discreetMeshes = CreateDiscreteMeshes.SplitVolumesIntoMeshes(Scene.SelectedItem.Mesh, ((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) => { - view3DWidget.ReportProgressChanged(progress0To1 * .5, processingState, out continueProcessing); + view3DWidget.ReportProgressChanged(progress.progress0To1 * .5, progress.processingState, continueProcessing); }); if (discreetMeshes.Count == 1) @@ -194,9 +195,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow for (int i = 0; i < MeshGroups.Count; i++) { // create the selection info - PlatingHelper.CreateITraceableForMeshGroup(MeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) => + PlatingHelper.CreateITraceableForMeshGroup(MeshGroups, i, (double progress0To1, string processingState, CancellationTokenSource continueProcessing) => { - ReportProgressChanged(progress0To1, processingState, out continueProcessing); + ReportProgressChanged(progress0To1, processingState, continueProcessing); }); currentRatioDone += ratioPerMeshGroup; diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index a144caf98..a8e905dd8 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -145,11 +145,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - public void ProgressReporter(double progress0To1, string processingState, out bool continueProcessing) + public void ProgressReporter((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) { - continueProcessing = true; - progressBar.RatioComplete = progress0To1; - if (progress0To1 == 1) + progressBar.RatioComplete = progress.progress0To1; + if (progress.progress0To1 == 1) { if (view3DWidget != null) { @@ -988,17 +987,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { sourceListItem.StartProgress(); - contentResult = DragSourceModel.CreateContent((double progress0To1, string processingState, out bool continueProcessing) => + contentResult = DragSourceModel.CreateContent(((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) => { - sourceListItem.ProgressReporter(progress0To1, processingState, out continueProcessing); - loadProgress.ProgressReporter(progress0To1, processingState, out continueProcessing); + sourceListItem.ProgressReporter(progress, continueProcessing); + loadProgress.ProgressReporter(progress, continueProcessing); }); await contentResult.MeshLoaded; sourceListItem.EndProgress(); - loadProgress.ProgressReporter(1, "", out bool continuex); + loadProgress.ProgressReporter((1, ""), new CancellationTokenSource()); } return contentResult?.Object3D; @@ -1679,11 +1678,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private void ReportProgressChanged(double progress0To1, string processingState) { - bool continueProcessing; - ReportProgressChanged(progress0To1, processingState, out continueProcessing); + var continueProcessing = new CancellationTokenSource(); + ReportProgressChanged(progress0To1, processingState, continueProcessing); } - internal void ReportProgressChanged(double progress0To1, string processingState, out bool continueProcessing) + internal void ReportProgressChanged(double progress0To1, string processingState, CancellationTokenSource continueProcessing) { if (!timeSinceReported.IsRunning || timeSinceReported.ElapsedMilliseconds > 100 || processingState != processingProgressControl.ProgressMessage) @@ -1695,7 +1694,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }); timeSinceReported.Restart(); } - continueProcessing = true; } public async Task ClearBedAndLoadPrintItemWrapper(PrintItemWrapper newPrintItem, bool switchToEditingMode = false) @@ -1933,11 +1931,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { var libraryItem = new FileSystemFileItem(filePath); - var contentResult = libraryItem.CreateContent((double progress0To1, string processingState, out bool continueProcessing) => + var contentResult = libraryItem.CreateContent(((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) => { double ratioAvailable = (ratioPerFile * .5); - double currentRatio = currentRatioDone + progress0To1 * ratioAvailable; - ReportProgressChanged(currentRatio, progressMessage, out continueProcessing); + double currentRatio = currentRatioDone + progress.progress0To1 * ratioAvailable; + ReportProgressChanged(currentRatio, progressMessage, continueProcessing); }); contentResult?.MeshLoaded.ContinueWith((task) => @@ -2321,7 +2319,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // TODO: Why were we recreating GLData on edit? //bool continueProcessing2; - //ReportProgressChanged(1, "Creating GL Data", out continueProcessing2); + //ReportProgressChanged(1, "Creating GL Data", continueProcessing2); //meshViewerWidget.CreateGlDataForMeshes(Scene.Children); }); diff --git a/PartPreviewWindow/ViewGcodeBasic.cs b/PartPreviewWindow/ViewGcodeBasic.cs index 47ad3a511..ed46ef4b1 100644 --- a/PartPreviewWindow/ViewGcodeBasic.cs +++ b/PartPreviewWindow/ViewGcodeBasic.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.IO; using System.Linq; +using System.Threading; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.GCodeVisualizer; @@ -594,10 +595,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow SetSyncToPrintVisibility(); } - private void LoadProgress_Changed(double progress0To1, string processingState, out bool continueProcessing) + private void LoadProgress_Changed((double progress0To1, string processingState) progress, CancellationTokenSource continueProcessing) { - SetProcessingMessage(string.Format("{0} {1:0}%...", gcodeLoading, progress0To1 * 100)); - continueProcessing = !this.HasBeenClosed; + SetProcessingMessage(string.Format("{0} {1:0}%...", gcodeLoading, progress.progress0To1 * 100)); + if(this.HasBeenClosed) + { + continueProcessing.Cancel(); + } } private GuiWidget CreateGCodeViewWidget(string pathAndFileName) diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index c8047868b..88107bb81 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit c8047868bac1cc6fecf77aaf871c241a48481789 +Subproject commit 88107bb816ab25de37b338cb6a0b24511f51f56c diff --git a/Tests/MatterControl.Tests/MatterControl.Tests.csproj b/Tests/MatterControl.Tests/MatterControl.Tests.csproj index ea11d77b9..10a4483f4 100644 --- a/Tests/MatterControl.Tests/MatterControl.Tests.csproj +++ b/Tests/MatterControl.Tests/MatterControl.Tests.csproj @@ -47,6 +47,9 @@ True + + ..\..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll + diff --git a/Tests/MatterControl.Tests/packages.config b/Tests/MatterControl.Tests/packages.config index 0a0385b79..e5c276158 100644 --- a/Tests/MatterControl.Tests/packages.config +++ b/Tests/MatterControl.Tests/packages.config @@ -4,4 +4,5 @@ + \ No newline at end of file diff --git a/packages.config b/packages.config index 650026cd6..ca03e4eb9 100644 --- a/packages.config +++ b/packages.config @@ -2,5 +2,5 @@ - + \ No newline at end of file