Adding ability to cancel rebuilding
This commit is contained in:
parent
aa795f1d3b
commit
dd3912a504
86 changed files with 257 additions and 67 deletions
|
|
@ -43,9 +43,11 @@ using MatterHackers.VectorMath;
|
|||
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
||||
{
|
||||
[ShowUpdateButton(false)]
|
||||
public class CombineObject3D_2 : OperationSourceContainerObject3D, IPropertyGridModifier
|
||||
public class CombineObject3D_2 : OperationSourceContainerObject3D, IPropertyGridModifier, IBuildsOnThread
|
||||
{
|
||||
public CombineObject3D_2()
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
public CombineObject3D_2()
|
||||
{
|
||||
Name = "Combine";
|
||||
}
|
||||
|
|
@ -67,6 +69,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
private IplicitSurfaceMethod MeshAnalysis { get; set; }
|
||||
private ProcessingResolution InputResolution { get; set; } = ProcessingResolution._64;
|
||||
#endif
|
||||
public bool IsBuilding => this.cancellationToken != null;
|
||||
|
||||
public override Task Rebuild()
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
|
|
@ -76,22 +80,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
return ApplicationController.Instance.Tasks.Execute(
|
||||
"Combine".Localize(),
|
||||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
(reporter, cancellationTokenSource) =>
|
||||
{
|
||||
this.cancellationToken = cancellationTokenSource as CancellationTokenSource;
|
||||
var progressStatus = new ProgressStatus();
|
||||
reporter.Report(progressStatus);
|
||||
|
||||
try
|
||||
{
|
||||
Combine(cancellationToken, reporter);
|
||||
Combine(cancellationTokenSource.Token, reporter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
|
|
@ -197,5 +204,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
change.SetRowVisible(nameof(MeshAnalysis), () => Processing != ProcessingModes.Polygons);
|
||||
change.SetRowVisible(nameof(InputResolution), () => Processing != ProcessingModes.Polygons && MeshAnalysis == IplicitSurfaceMethod.Grid);
|
||||
}
|
||||
}
|
||||
|
||||
public void CancelBuild()
|
||||
{
|
||||
var threadSafe = this.cancellationToken;
|
||||
if(threadSafe != null)
|
||||
{
|
||||
threadSafe.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,19 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
private ProcessingResolution InputResolution { get; set; } = ProcessingResolution._64;
|
||||
#endif
|
||||
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
public bool IsBuilding => this.cancellationToken != null;
|
||||
|
||||
public void CancelBuild()
|
||||
{
|
||||
var threadSafe = this.cancellationToken;
|
||||
if (threadSafe != null)
|
||||
{
|
||||
threadSafe.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public override Task Rebuild()
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
|
|
@ -77,22 +90,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
return ApplicationController.Instance.Tasks.Execute(
|
||||
"Intersection".Localize(),
|
||||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
(reporter, cancellationTokenSource) =>
|
||||
{
|
||||
this.cancellationToken = cancellationTokenSource as CancellationTokenSource;
|
||||
var progressStatus = new ProgressStatus();
|
||||
reporter.Report(progressStatus);
|
||||
|
||||
try
|
||||
{
|
||||
Intersect(cancellationToken, reporter);
|
||||
Intersect(cancellationTokenSource.Token, reporter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -202,11 +202,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
var rebuildLocks = this.RebuilLockAll();
|
||||
|
||||
// spin up a task to calculate the paint
|
||||
return ApplicationController.Instance.Tasks.Execute("Replacing".Localize(), null, (reporter, cancellationToken) =>
|
||||
return ApplicationController.Instance.Tasks.Execute("Replacing".Localize(), null, (reporter, cancellationTokenSource) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
SubtractAndReplace(cancellationToken, reporter);
|
||||
SubtractAndReplace(cancellationTokenSource.Token, reporter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -215,6 +215,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -129,16 +129,32 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
}
|
||||
}
|
||||
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
public bool IsBuilding => this.cancellationToken != null;
|
||||
|
||||
public void CancelBuild()
|
||||
{
|
||||
var threadSafe = this.cancellationToken;
|
||||
if (threadSafe != null)
|
||||
{
|
||||
threadSafe.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public override Task Rebuild()
|
||||
{
|
||||
var rebuildLocks = this.RebuilLockAll();
|
||||
|
||||
// spin up a task to calculate the paint
|
||||
return ApplicationController.Instance.Tasks.Execute("Replacing".Localize(), null, (reporter, cancellationToken) =>
|
||||
return ApplicationController.Instance.Tasks.Execute("Replacing".Localize(),
|
||||
null,
|
||||
(reporter, cancellationTokenSource) =>
|
||||
{
|
||||
this.cancellationToken = cancellationTokenSource as CancellationTokenSource;
|
||||
try
|
||||
{
|
||||
SubtractAndReplace(cancellationToken, reporter);
|
||||
SubtractAndReplace(cancellationTokenSource.Token, reporter);
|
||||
var newComputedChildren = new SelectedChildren();
|
||||
|
||||
foreach (var id in SelectedChildren)
|
||||
|
|
@ -152,9 +168,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
{
|
||||
}
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -85,14 +85,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
return ApplicationController.Instance.Tasks.Execute(
|
||||
"Subtract".Localize(),
|
||||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
(reporter, cancellationTokenSource) =>
|
||||
{
|
||||
var progressStatus = new ProgressStatus();
|
||||
reporter.Report(progressStatus);
|
||||
|
||||
try
|
||||
{
|
||||
Subtract(cancellationToken, reporter);
|
||||
Subtract(cancellationTokenSource.Token, reporter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -101,6 +101,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ using MatterHackers.VectorMath;
|
|||
namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
||||
{
|
||||
[ShowUpdateButton(false)]
|
||||
public class SubtractObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, ICustomEditorDraw, IPropertyGridModifier
|
||||
public class SubtractObject3D_2 : OperationSourceContainerObject3D, ISelectableChildContainer, ICustomEditorDraw, IPropertyGridModifier, IBuildsOnThread
|
||||
{
|
||||
public SubtractObject3D_2()
|
||||
{
|
||||
|
|
@ -130,6 +130,19 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
}
|
||||
}
|
||||
|
||||
private CancellationTokenSource cancellationToken;
|
||||
|
||||
public bool IsBuilding => this.cancellationToken != null;
|
||||
|
||||
public void CancelBuild()
|
||||
{
|
||||
var threadSafe = this.cancellationToken;
|
||||
if (threadSafe != null)
|
||||
{
|
||||
threadSafe.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public override Task Rebuild()
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
|
|
@ -139,22 +152,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
return ApplicationController.Instance.Tasks.Execute(
|
||||
"Subtract".Localize(),
|
||||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
(reporter, cancellationTokenSource) =>
|
||||
{
|
||||
this.cancellationToken = cancellationTokenSource as CancellationTokenSource;
|
||||
var progressStatus = new ProgressStatus();
|
||||
reporter.Report(progressStatus);
|
||||
|
||||
try
|
||||
{
|
||||
Subtract(cancellationToken, reporter);
|
||||
Subtract(cancellationTokenSource.Token, reporter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
this.cancellationToken = null;
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -106,14 +106,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
return ApplicationController.Instance.Tasks.Execute(
|
||||
"Subtract".Localize(),
|
||||
null,
|
||||
(reporter, cancellationToken) =>
|
||||
(reporter, cancellationTokenSource) =>
|
||||
{
|
||||
var progressStatus = new ProgressStatus();
|
||||
reporter.Report(progressStatus);
|
||||
|
||||
try
|
||||
{
|
||||
Subtract(cancellationToken, reporter);
|
||||
Subtract(cancellationTokenSource.Token, reporter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -133,6 +133,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
rebuildLocks.Dispose();
|
||||
this.CancelAllParentBuilding();
|
||||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue