Center on bounding box

When grouping items, move them to be centered on their bounding box
This commit is contained in:
John Lewin 2018-03-28 17:14:46 -07:00
parent 6998440a51
commit 4e6d0d7f08

View file

@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MeshVisualizer;
namespace MatterHackers.MatterControl.PartPreviewWindow
@ -56,18 +57,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
Name = "Group".Localize()
};
// When grouping items, move them to be centered on their bounding box
newGroup.Children.Modify((gChildren) =>
{
selectedItem.Children.Modify((sChildren) =>
{
foreach(var child in 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);
sChildren.Clear();
});
});
scene.Children.Add(newGroup);
scene.SelectedItem = null;
item = newGroup;