From f9378f440508323d0ecd78cc8f0cfd379276bf73 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 12 Dec 2017 12:30:39 -0800 Subject: [PATCH] Adding some progress reporting to subtract Moved ProgressStatus to agg --- ApplicationView/MainApplicationWidget.cs | 6 ---- .../View3D/Actions/PaintMaterialEditor.cs | 2 +- .../View3D/Actions/SubtractEditor.cs | 32 +++++++++++++++++-- .../View3D/SliceProgressReporter.cs | 1 + SettingsManagement/OemSettings.cs | 1 + SetupWizard/SyncingPrintersPage.cs | 1 + Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 8 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 02109e13b..02da910cc 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -85,10 +85,4 @@ namespace MatterHackers.MatterControl } } } - - public class ProgressStatus : EventArgs - { - public string Status { get; set; } - public double Progress0To1 { get; set; } - } } diff --git a/PartPreviewWindow/View3D/Actions/PaintMaterialEditor.cs b/PartPreviewWindow/View3D/Actions/PaintMaterialEditor.cs index c9a2240ad..858fde323 100644 --- a/PartPreviewWindow/View3D/Actions/PaintMaterialEditor.cs +++ b/PartPreviewWindow/View3D/Actions/PaintMaterialEditor.cs @@ -170,7 +170,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D private void ProcessBooleans(IObject3D group) { - // spin up a task to remove holes from the objects in the group + // spin up a task to calculate the paint ApplicationController.Instance.Tasks.Execute((reporter, cancelationToken) => { var progressStatus = new ProgressStatus() diff --git a/PartPreviewWindow/View3D/Actions/SubtractEditor.cs b/PartPreviewWindow/View3D/Actions/SubtractEditor.cs index 1ef1a2135..5fce763d4 100644 --- a/PartPreviewWindow/View3D/Actions/SubtractEditor.cs +++ b/PartPreviewWindow/View3D/Actions/SubtractEditor.cs @@ -147,11 +147,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D tabContainer.AddChild(updateButton); } - private async void ProcessBooleans(IObject3D group) + private void ProcessBooleans(IObject3D group) { // spin up a task to remove holes from the objects in the group - await Task.Run(() => + ApplicationController.Instance.Tasks.Execute((reporter, cancelationToken) => { + var progressStatus = new ProgressStatus() + { + Status = "Processing Booleans" + }; + + reporter.Report(progressStatus); + var participants = group.Descendants().Where(o => o.OwnerID == group.ID).ToList(); var removeObjects = participants.Where((obj) => obj.OutputType == PrintOutputTypes.Hole).ToList(); var keepObjects = participants.Where((obj) => obj.OutputType != PrintOutputTypes.Hole).ToList(); @@ -159,27 +166,46 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D if (removeObjects.Any() && keepObjects.Any()) { + var totalOpperations = removeObjects.Count() * keepObjects.Count(); + double amountPerOperation = 1.0 / totalOpperations; + double percentCompleted = 0; + foreach (var remove in removeObjects) { foreach (var keep in keepObjects) { + progressStatus.Status = "Copy Remove"; + reporter.Report(progressStatus); var transformedRemove = Mesh.Copy(remove.Mesh, CancellationToken.None); transformedRemove.Transform(remove.WorldMatrix()); + progressStatus.Status = "Copy Keep"; + reporter.Report(progressStatus); var transformedKeep = Mesh.Copy(keep.Mesh, CancellationToken.None); transformedKeep.Transform(keep.WorldMatrix()); - transformedKeep = PolygonMesh.Csg.CsgOperations.Subtract(transformedKeep, transformedRemove); + progressStatus.Status = "Do CSG"; + reporter.Report(progressStatus); + transformedKeep = PolygonMesh.Csg.CsgOperations.Subtract(transformedKeep, transformedRemove, (csgStatus) => + { + progressStatus.Status = csgStatus.Status; + reporter.Report(progressStatus); + }, cancelationToken); var inverse = keep.WorldMatrix(); inverse.Invert(); transformedKeep.Transform(inverse); keep.Mesh = transformedKeep; view3DWidget.Invalidate(); + + percentCompleted += amountPerOperation; + progressStatus.Progress0To1 = percentCompleted; + reporter.Report(progressStatus); } remove.Visible = false; } } + return Task.CompletedTask; }); } } diff --git a/PartPreviewWindow/View3D/SliceProgressReporter.cs b/PartPreviewWindow/View3D/SliceProgressReporter.cs index d48cc8bf9..211d1c6da 100644 --- a/PartPreviewWindow/View3D/SliceProgressReporter.cs +++ b/PartPreviewWindow/View3D/SliceProgressReporter.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Diagnostics; using MatterHackers.GCodeVisualizer; +using MatterHackers.Agg; namespace MatterHackers.MatterControl.PartPreviewWindow { diff --git a/SettingsManagement/OemSettings.cs b/SettingsManagement/OemSettings.cs index 30f1bf8cf..734773c9c 100644 --- a/SettingsManagement/OemSettings.cs +++ b/SettingsManagement/OemSettings.cs @@ -33,6 +33,7 @@ using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Threading.Tasks; +using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.MatterControl.SlicerConfiguration; using Newtonsoft.Json; diff --git a/SetupWizard/SyncingPrintersPage.cs b/SetupWizard/SyncingPrintersPage.cs index 71661aec9..8a8951bb7 100644 --- a/SetupWizard/SyncingPrintersPage.cs +++ b/SetupWizard/SyncingPrintersPage.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.Agg; namespace MatterHackers.MatterControl.SetupWizard { diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 8ef196a04..4c6870cd6 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 8ef196a04d1ab2ab8d85d14ce9be1c1926a55666 +Subproject commit 4c6870cd65cafbf5d677ccfbc47044a3df5e88e3 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index c3bf6f29d..f5421fbb0 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit c3bf6f29d625706728891a38ecbf4c2f81996ded +Subproject commit f5421fbb01872b3909e8e3d3d0f5c963dd384109