From a22301101d539609eedff4f1afa4848c678f2cee Mon Sep 17 00:00:00 2001 From: MatterHackers Date: Wed, 29 Nov 2023 08:32:46 -0800 Subject: [PATCH] Cleaning up --- .../ApplicationView/SceneOperations.cs | 18 +++++++++--------- .../Operations/Image/ImageToPathObject3D.cs | 4 +++- .../Operations/Object3DExtensions.cs | 16 ++++++++++------ .../DesignTools/Primitives/BaseObject3D.cs | 6 ++++-- .../DesignTools/Primitives/TextObject3D.cs | 9 ++++++--- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/MatterControlLib/ApplicationView/SceneOperations.cs b/MatterControlLib/ApplicationView/SceneOperations.cs index 7625cf208..e597eb0f1 100644 --- a/MatterControlLib/ApplicationView/SceneOperations.cs +++ b/MatterControlLib/ApplicationView/SceneOperations.cs @@ -888,9 +888,9 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Combine".Localize(), Action = (sceneContext) => { - if (sceneContext.Scene.SelectedItem.VisiblePaths().Count() > 1) - { - new MergePathObject3D("Combine".Localize(), ClipperLib.ClipType.ctUnion).WrapSelectedItemAndSelect(sceneContext.Scene); + if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathEditorDraw)) + { + new MergePathObject3D("Combine".Localize(), ClipperLib.ClipType.ctUnion).WrapSelectedItemAndSelect(sceneContext.Scene); } else { @@ -1055,9 +1055,9 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Intersect".Localize(), Action = (sceneContext) => { - if (sceneContext.Scene.SelectedItem.VisiblePaths().Count() > 1) - { - new MergePathObject3D("Intersect".Localize(), ClipperLib.ClipType.ctIntersection).WrapSelectedItemAndSelect(sceneContext.Scene); + if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathEditorDraw)) + { + new MergePathObject3D("Intersect".Localize(), ClipperLib.ClipType.ctIntersection).WrapSelectedItemAndSelect(sceneContext.Scene); } else { @@ -1356,9 +1356,9 @@ namespace MatterHackers.MatterControl TitleGetter = () => "Subtract".Localize(), Action = (sceneContext) => { - if (sceneContext.Scene.SelectedItem.VisiblePaths().Count() > 1) - { - new SubtractPathObject3D().WrapSelectedItemAndSelect(sceneContext.Scene); + if (sceneContext.Scene.SelectedItem.VisibleMeshes().All(o => o is IPathEditorDraw)) + { + new SubtractPathObject3D().WrapSelectedItemAndSelect(sceneContext.Scene); } else { diff --git a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs index 658a75ab1..8e0a06444 100644 --- a/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/Image/ImageToPathObject3D.cs @@ -55,7 +55,7 @@ using Polygons = System.Collections.Generic.List true; + public override bool MeshIsSolidObject => false; + public override void Apply(UndoBuffer undoBuffer) { this.FlattenToPathObject(undoBuffer); diff --git a/MatterControlLib/DesignTools/Operations/Object3DExtensions.cs b/MatterControlLib/DesignTools/Operations/Object3DExtensions.cs index 40e49c00b..509e8086e 100644 --- a/MatterControlLib/DesignTools/Operations/Object3DExtensions.cs +++ b/MatterControlLib/DesignTools/Operations/Object3DExtensions.cs @@ -182,12 +182,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public static void FlattenToPathObject(this IObject3D item, UndoBuffer undoBuffer) { - if (item.GetVertexSource() != null) + var pathItem = item as IPathObject3D; + if (pathItem?.GetVertexSource() != null) { using (item.RebuildLock()) { var newPathObject = new PathObject3D(); - newPathObject.VertexStorage = new VertexStorage(item.GetVertexSource()); + newPathObject.VertexStorage = new VertexStorage(pathItem.GetVertexSource()); // and replace us with the children var replaceCommand = new ReplaceCommand(new[] { item }, new[] { newPathObject }); @@ -208,14 +209,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public static void DrawPath(this IObject3D item) { - if (item.GetVertexSource() != null) + var pathItem = item as IPathObject3D; + if (pathItem?.GetVertexSource() != null) { bool first = true; var lastPosition = Vector2.Zero; var maxXYZ = item.GetAxisAlignedBoundingBox().MaxXYZ; maxXYZ = maxXYZ.Transform(item.Matrix.Inverted); var firstMove = Vector2.Zero; - foreach (var vertex in item.GetVertexSource().Vertices()) + foreach (var vertex in pathItem.GetVertexSource().Vertices()) { var position = vertex.Position; if (first) @@ -264,13 +266,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { AxisAlignedBoundingBox box = AxisAlignedBoundingBox.Empty(); - if (item.GetVertexSource() != null) + var pathItem = item as IPathObject3D; + + if (pathItem?.GetVertexSource() != null) { var lastPosition = Vector2.Zero; var maxXYZ = item.GetAxisAlignedBoundingBox().MaxXYZ; maxXYZ = maxXYZ.Transform(item.Matrix.Inverted); - foreach (var vertex in item.GetVertexSource().Vertices()) + foreach (var vertex in pathItem.GetVertexSource().Vertices()) { var position = vertex.Position; diff --git a/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs b/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs index 2e01d5616..3dd6410c8 100644 --- a/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs @@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.DesignTools Outline } - public class BaseObject3D : Object3D, IPropertyGridModifier, IEditorDraw + public class BaseObject3D : PathObject3D, IPropertyGridModifier, IEditorDraw { public enum CenteringTypes { @@ -113,7 +113,9 @@ namespace MatterHackers.MatterControl.DesignTools [EnumDisplay(Mode = EnumDisplayAttribute.PresentationMode.Buttons)] public CenteringTypes Centering { get; set; } = CenteringTypes.Weighted; - public override void Cancel(UndoBuffer undoBuffer) + public override bool MeshIsSolidObject => true; + + public override void Cancel(UndoBuffer undoBuffer) { using (RebuildLock()) { diff --git a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs index 7ae8f6259..eba9322db 100644 --- a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs @@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.DesignTools } [HideChildrenFromTreeView] - public class TextObject3D : Object3D, IPropertyGridModifier, IEditorDraw, IPrimaryOperationsSpecifier + public class TextObject3D : PathObject3D, IPropertyGridModifier, IEditorDraw, IPrimaryOperationsSpecifier { private bool refreshToolBar; @@ -129,7 +129,9 @@ namespace MatterHackers.MatterControl.DesignTools public override bool CanApply => true; - public override IVertexSource GetVertexSource() + public override bool MeshIsSolidObject => Output == OutputDimensions.Output3D; + + public override IVertexSource GetVertexSource() { if (Output == OutputDimensions.Output2D) { @@ -282,7 +284,8 @@ namespace MatterHackers.MatterControl.DesignTools }; if (Output == OutputDimensions.Output2D) { - letterObject.VertexStorage = new VertexStorage( + var pathObject = this as PathObject3D; + pathObject.VertexStorage = new VertexStorage( new VertexSourceApplyTransform( new VertexStorage(scaledLetterPrinter), Affine.NewTranslation(offset.X, offset.Y))); }