From 76345be5768d8b1836a88cbd7e99db18f70a8754 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 22 Sep 2018 18:59:42 -0700 Subject: [PATCH] fixing modify opperations on selection groups issue: MatterHackers/MCCentral#4005 Scale duplicates objects --- .../ApplicationView/ApplicationController.cs | 46 +++++++++++++++---- .../Operations/RotateObject3D_2.cs | 5 -- .../DesignTools/Operations/ScaleObject3D.cs | 2 +- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 3f01a613b..e5372a4f4 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -756,6 +756,28 @@ namespace MatterHackers.MatterControl () => new RootHistoryContainer())); } + public static IObject3D SelectionAsSingleClone(IObject3D selection) + { + IEnumerable items = new[] { selection }; + + // If SelectionGroup, operate on Children instead + if (selection is SelectionGroupObject3D) + { + items = selection.Children; + + var group = new GroupObject3D(); + + group.Children.Modify(children => + { + children.AddRange(items.Select(o => o.Clone())); + }); + + return group; + } + + return selection.Clone(); + } + public ApplicationController() { // Initialize the AppContext theme object which will sync its content with Agg ActiveTheme changes @@ -829,12 +851,14 @@ namespace MatterHackers.MatterControl (sceneItem, scene) => { var selectedItem = scene.SelectedItem; + var replaceItems = (selectedItem is SelectionGroupObject3D) ? selectedItem.Children.ToList() : new List { selectedItem }; scene.SelectedItem = null; - var translate = TranslateObject3D.Create(selectedItem.Clone()); - translate.MakeNameNonColliding(); + var selectedClone = SelectionAsSingleClone(selectedItem); + var tranlate = TranslateObject3D.Create(selectedClone); + tranlate.MakeNameNonColliding(); - scene.UndoBuffer.AddAndDo(new ReplaceCommand(new List { selectedItem }, new List { translate })); - scene.SelectedItem = translate; + scene.UndoBuffer.AddAndDo(new ReplaceCommand(replaceItems, new List { tranlate })); + scene.SelectedItem = tranlate; return Task.CompletedTask; }, @@ -847,11 +871,13 @@ namespace MatterHackers.MatterControl (sceneItem, scene) => { var selectedItem = scene.SelectedItem; + var replaceItems = (selectedItem is SelectionGroupObject3D) ? selectedItem.Children.ToList() : new List { selectedItem }; scene.SelectedItem = null; - var rotate = RotateObject3D_2.Create(selectedItem.Clone()); + var selectedClone = SelectionAsSingleClone(selectedItem); + var rotate = new RotateObject3D_2(selectedClone); rotate.MakeNameNonColliding(); - scene.UndoBuffer.AddAndDo(new ReplaceCommand(new List { selectedItem }, new List { rotate })); + scene.UndoBuffer.AddAndDo(new ReplaceCommand(replaceItems, new List { rotate })); scene.SelectedItem = rotate; return Task.CompletedTask; @@ -937,13 +963,13 @@ namespace MatterHackers.MatterControl (sceneItem, scene) => { var selectedItem = scene.SelectedItem; + var replaceItems = (selectedItem is SelectionGroupObject3D) ? selectedItem.Children.ToList() : new List { selectedItem }; scene.SelectedItem = null; - - var scale = new ScaleObject3D(selectedItem.Clone(), Vector3.One); - + var selectedClone = SelectionAsSingleClone(selectedItem); + var scale = new ScaleObject3D(selectedClone); scale.MakeNameNonColliding(); - scene.UndoBuffer.AddAndDo(new ReplaceCommand(new List { selectedItem }, new List { scale })); + scene.UndoBuffer.AddAndDo(new ReplaceCommand(replaceItems, new List { scale })); scene.SelectedItem = scale; return Task.CompletedTask; diff --git a/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs b/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs index a1d4b04b3..638175291 100644 --- a/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/RotateObject3D_2.cs @@ -88,11 +88,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations } } - public static RotateObject3D_2 Create(IObject3D itemToRotate) - { - return new RotateObject3D_2(itemToRotate); - } - public void DrawEditor(object sender, DrawEventArgs e) { if (sender is InteractionLayer layer diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs index 96b7190bc..401c25218 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations Name = "Scale".Localize(); } - public ScaleObject3D(IObject3D item, double x = 0, double y = 0, double z = 0) + public ScaleObject3D(IObject3D item, double x = 1, double y = 1, double z = 1) : this(item, new Vector3(x, y, z)) { }