From f39ac55e47886335d8da0e673d32773f3c37db2e Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 9 Jul 2018 16:48:12 -0700 Subject: [PATCH] Make cancel work better on ungroup --- PartPreviewWindow/CreateDiscreteMeshes.cs | 18 +++++++++++++++++- PartPreviewWindow/View3D/SceneActions.cs | 12 ++++++++++++ Submodules/agg-sharp | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/PartPreviewWindow/CreateDiscreteMeshes.cs b/PartPreviewWindow/CreateDiscreteMeshes.cs index 3029f7fd4..cbfbcea43 100644 --- a/PartPreviewWindow/CreateDiscreteMeshes.cs +++ b/PartPreviewWindow/CreateDiscreteMeshes.cs @@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading; using ClipperLib; @@ -50,12 +51,27 @@ namespace MatterHackers.MatterControl { public static List SplitVolumesIntoMeshes(Mesh meshToSplit, CancellationToken cancellationToken, Action reportProgress) { + Stopwatch maxProgressReport = Stopwatch.StartNew(); List discreetVolumes = new List(); HashSet facesThatHaveBeenAdded = new HashSet(); Mesh meshFromCurrentVolume = null; Stack attachedFaces = new Stack(); - for (int faceIndex = 0; faceIndex < meshToSplit.Faces.Count; faceIndex++) + int faceCount = meshToSplit.Faces.Count; + for (int faceIndex = 0; faceIndex < faceCount; faceIndex++) { + if (reportProgress != null) + { + if (maxProgressReport.ElapsedMilliseconds > 200) + { + reportProgress(faceIndex / (double)faceCount, "Merging Mesh Edges"); + maxProgressReport.Restart(); + if (cancellationToken.IsCancellationRequested) + { + return null; + } + } + } + Face currentFace = meshToSplit.Faces[faceIndex]; // If this face as not been added to any volume, create a new volume and add all of the attached faces. if (!facesThatHaveBeenAdded.Contains(currentFace)) diff --git a/PartPreviewWindow/View3D/SceneActions.cs b/PartPreviewWindow/View3D/SceneActions.cs index 2505abb67..e83363c8e 100644 --- a/PartPreviewWindow/View3D/SceneActions.cs +++ b/PartPreviewWindow/View3D/SceneActions.cs @@ -97,6 +97,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow progressStatus.Status = processingState; reporter.Report(progressStatus); }); + if(cancellationToken.IsCancellationRequested) + { + return Task.CompletedTask; + } progressStatus.Status = "Clean".Localize(); reporter.Report(progressStatus); ungroupMesh.CleanAndMergeMesh(cancellationToken, 0, (progress0To1, processingState) => @@ -105,6 +109,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow progressStatus.Status = processingState; reporter.Report(progressStatus); }); + if (cancellationToken.IsCancellationRequested) + { + return Task.CompletedTask; + } using (selectedItem.RebuildLock()) { selectedItem.Mesh = ungroupMesh; @@ -118,6 +126,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow progressStatus.Status = processingState; reporter.Report(progressStatus); }); + if (cancellationToken.IsCancellationRequested) + { + return Task.CompletedTask; + } if (discreetMeshes.Count == 1) { diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 567928b41..3811863d4 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 567928b4170ac786a5db3171edb2db3bc93d62b6 +Subproject commit 3811863d420c25b06784dc0888018b22c8f3fb92