From 98392156039405abfc6fb0032600f232a68ce71c Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 28 Apr 2022 14:08:30 -0700 Subject: [PATCH] Combine can subtract holes --- .../ApplicationView/SceneOperations.cs | 32 +++-------------- .../DesignTools/Operations/GroupObject3D.cs | 35 ++++++++++++++++++- .../Primitives/ComponentObject3D.cs | 2 +- .../View3D/Actions/SubtractObject3D_2.cs | 2 +- StaticData/Translations/Master.txt | 3 ++ 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/MatterControlLib/ApplicationView/SceneOperations.cs b/MatterControlLib/ApplicationView/SceneOperations.cs index 1f614bad3..6f02c4b5e 100644 --- a/MatterControlLib/ApplicationView/SceneOperations.cs +++ b/MatterControlLib/ApplicationView/SceneOperations.cs @@ -1073,37 +1073,12 @@ namespace MatterHackers.MatterControl return new SceneOperation("Group") { OperationType = typeof(SelectionGroupObject3D), - ResultType = typeof(GroupObject3D), + ResultType = typeof(GroupHolesAppliedObject3D), TitleGetter = () => "Group".Localize(), Action = (sceneContext) => { - var scene = sceneContext.Scene; - var selectedItem = scene.SelectedItem; - scene.SelectedItem = null; - - var newGroup = new GroupObject3D(); - // When grouping items, move them to be centered on their bounding box - newGroup.Children.Modify((gChildren) => - { - selectedItem.Clone().Children.Modify((sChildren) => - { - var center = selectedItem.GetAxisAlignedBoundingBox().Center; - - foreach (var child in sChildren) - { - child.Translate(-center.X, -center.Y, 0); - gChildren.Add(child); - } - - newGroup.Translate(center.X, center.Y, 0); - }); - }); - - scene.UndoBuffer.AddAndDo(new ReplaceCommand(selectedItem.Children.ToList(), new[] { newGroup })); - - newGroup.MakeNameNonColliding(); - - scene.SelectedItem = newGroup; + var group = new GroupHolesAppliedObject3D(); + group.WrapSelectedItemAndSelect(sceneContext.Scene); }, HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(), IsEnabled = (sceneContext) => sceneContext.Scene is InteractiveScene scene @@ -1534,6 +1509,7 @@ namespace MatterHackers.MatterControl if (selectedItem != null) { return selectedItem is GroupObject3D + || selectedItem is GroupHolesAppliedObject3D || selectedItem.GetType() == typeof(Object3D) || selectedItem.CanApply; } diff --git a/MatterControlLib/DesignTools/Operations/GroupObject3D.cs b/MatterControlLib/DesignTools/Operations/GroupObject3D.cs index d2a875e0f..690f014e4 100644 --- a/MatterControlLib/DesignTools/Operations/GroupObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/GroupObject3D.cs @@ -29,10 +29,14 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.DataConverters3D; using MatterHackers.Localizations; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using System; +using System.Linq; +using System.Text.Json.Serialization; namespace MatterHackers.MatterControl.DesignTools.Operations { - public class GroupObject3D : Object3D + public class GroupObject3D : Object3D { public override bool CanApply => true; @@ -41,4 +45,33 @@ namespace MatterHackers.MatterControl.DesignTools.Operations Name = "Group".Localize(); } } + + [ShowUpdateButton(Show = false)] + public class GroupHolesAppliedObject3D : SubtractObject3D_2 + { + public GroupHolesAppliedObject3D() + { + Name = "Group".Localize(); + } + + public override SelectedChildren SelectedChildren + { + get + { + var selections = new SelectedChildren(); + + foreach(var child in SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf().Children.Where(i => i.WorldOutputType(this) == PrintOutputTypes.Hole)) + { + selections.Add(child.ID); + } + + return selections; + } + + set + { + + } + } + } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs b/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs index b7362bed1..39f91107e 100644 --- a/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ComponentObject3D.cs @@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.DesignTools if (newChildren.Count > 1) { - var group = new GroupObject3D + var group = new GroupHolesAppliedObject3D { Name = this.Name }; diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs index 01b7aab02..b55df7c58 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SubtractObject3D_2.cs @@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D } [DisplayName("Part(s) to Subtract")] - public SelectedChildren SelectedChildren { get; set; } = new SelectedChildren(); + public virtual SelectedChildren SelectedChildren { get; set; } = new SelectedChildren(); #if DEBUG public ProcessingModes Processing { get; set; } = ProcessingModes.Polygons; diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 11b153341..ad48a10c9 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -4339,6 +4339,9 @@ Translated:Select this option only if your printer does not appear in the list English:Select What to Import Translated:Select What to Import +English:Selected Children +Translated:Selected Children + English:Selected Material and Bed Surface are Incompatable Translated:Selected Material and Bed Surface are Incompatable