Make cancel work better on ungroup

This commit is contained in:
Lars Brubaker 2018-07-09 16:48:12 -07:00
parent d9842b8b7e
commit f39ac55e47
3 changed files with 30 additions and 2 deletions

View file

@ -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<Mesh> SplitVolumesIntoMeshes(Mesh meshToSplit, CancellationToken cancellationToken, Action<double, string> reportProgress)
{
Stopwatch maxProgressReport = Stopwatch.StartNew();
List<Mesh> discreetVolumes = new List<Mesh>();
HashSet<Face> facesThatHaveBeenAdded = new HashSet<Face>();
Mesh meshFromCurrentVolume = null;
Stack<Face> attachedFaces = new Stack<Face>();
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))

View file

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

@ -1 +1 @@
Subproject commit 567928b4170ac786a5db3171edb2db3bc93d62b6
Subproject commit 3811863d420c25b06784dc0888018b22c8f3fb92