From 5db2bfae478067eb50f02883bb3b69cba11a31a4 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 1 Dec 2023 09:43:23 -0800 Subject: [PATCH] New path understanding is working --- .../ApplicationView/SceneOperations.cs | 25 +++---------------- .../Operations/Path/MergePathObject3D.cs | 4 ++- .../View3D/Actions/SubtractPathObject3D.cs | 19 +++++++++++--- Submodules/agg-sharp | 2 +- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/MatterControlLib/ApplicationView/SceneOperations.cs b/MatterControlLib/ApplicationView/SceneOperations.cs index e597eb0f1..830fb6408 100644 --- a/MatterControlLib/ApplicationView/SceneOperations.cs +++ b/MatterControlLib/ApplicationView/SceneOperations.cs @@ -888,7 +888,7 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Combine".Localize(), Action = (sceneContext) => { - if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathEditorDraw)) + if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathObject3D)) { new MergePathObject3D("Combine".Localize(), ClipperLib.ClipType.ctUnion).WrapSelectedItemAndSelect(sceneContext.Scene); } @@ -1055,7 +1055,7 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Intersect".Localize(), Action = (sceneContext) => { - if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathEditorDraw)) + if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathObject3D)) { new MergePathObject3D("Intersect".Localize(), ClipperLib.ClipType.ctIntersection).WrapSelectedItemAndSelect(sceneContext.Scene); } @@ -1081,10 +1081,7 @@ namespace MatterHackers.MatterControl if (item is IPathObject3D pathObject) { - if (!pathObject.MeshIsSolidObject) - { - return false; - } + return pathObject.MeshIsSolidObject; } return true; @@ -1093,20 +1090,6 @@ namespace MatterHackers.MatterControl return false; } - private static bool IsPathObject(IObject3D item) - { - if (item != null) - { - if (item is IPathObject3D pathObject - && !pathObject.MeshIsSolidObject) - { - return true; - } - } - - return false; - } - private static SceneOperation LayFlatOperation() { return new SceneOperation("Lay Flat") @@ -1356,7 +1339,7 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Subtract".Localize(), Action = (sceneContext) => { - if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathEditorDraw)) + if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathObject3D)) { new SubtractPathObject3D().WrapSelectedItemAndSelect(sceneContext.Scene); } diff --git a/MatterControlLib/DesignTools/Operations/Path/MergePathObject3D.cs b/MatterControlLib/DesignTools/Operations/Path/MergePathObject3D.cs index 4cfebca7f..e66f596be 100644 --- a/MatterControlLib/DesignTools/Operations/Path/MergePathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Path/MergePathObject3D.cs @@ -117,7 +117,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations SourceContainer.Visible = true; RemoveAllButSource(); - var participants = SourceContainer.VisiblePaths2(); + var participants = SourceContainer.VisiblePaths(); var first = participants.First(); var firstObject3D = first as Object3D; if (participants.Count() < 2) @@ -148,6 +148,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations var itemObject3D = item as Object3D; var itemVertexSource = item.GetVertexSource().Transform(itemObject3D.WorldMatrix(this)); + this.CopyProperties(firstObject3D, Object3DPropertyFlags.Color); + resultsVertexSource = resultsVertexSource.MergePaths(itemVertexSource, clipType); ratioCompleted += amountPerOperation; diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractPathObject3D.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractPathObject3D.cs index cfb95015a..96ab5673f 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractPathObject3D.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractPathObject3D.cs @@ -45,7 +45,7 @@ using System.Threading.Tasks; namespace MatterHackers.MatterControl.PartPreviewWindow.View3D { - public class SubtractPathObject3D : OperationSourceContainerObject3D, IEditorDraw, IObject3DControlsProvider, IPrimaryOperationsSpecifier + public class SubtractPathObject3D : OperationSourceContainerObject3D, IEditorDraw, IObject3DControlsProvider, IPrimaryOperationsSpecifier, IPathObject3D { public SubtractPathObject3D() { @@ -93,6 +93,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D public override bool CanApply => true; + public bool MeshIsSolidObject => false; + + public VertexStorage VertexStorage { get; set; } + public override void Apply(UndoBuffer undoBuffer) { this.FlattenToPathObject(undoBuffer); @@ -189,11 +193,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D bool first = true; foreach (var keep in keepVisibleItems) { - var resultsVertexSource = keep.GetVertexSource().Transform(keep.Matrix); + var keepObject3D = keep as Object3D; + var resultsVertexSource = keep.GetVertexSource().Transform(keepObject3D.Matrix); foreach (var remove in removeVisibleItems) { - resultsVertexSource = resultsVertexSource.MergePaths(remove.GetVertexSource().Transform(remove.Matrix), ClipperLib.ClipType.ctDifference); + var removeObject3D = remove as Object3D; + resultsVertexSource = resultsVertexSource.MergePaths(remove.GetVertexSource().Transform(removeObject3D.Matrix), ClipperLib.ClipType.ctDifference); // report our progress ratioCompleted += amountPerOperation; @@ -203,6 +209,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D if (first) { this.VertexStorage = new VertexStorage(resultsVertexSource); + this.CopyProperties(keepObject3D, Object3DPropertyFlags.Color); + first = false; } else @@ -251,5 +259,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D { return PathContainerObject3D.GetOperations(this.GetType()); } + + public IVertexSource GetVertexSource() + { + return VertexStorage; + } } } \ No newline at end of file diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 461e797ff..2ba5e9779 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 461e797ff7e25df7e9b4a6031d396937d7ea6c30 +Subproject commit 2ba5e9779639090ffa4b632aeb014e4b59256ae6