Improving Rotate operation and DirectionAxis editor
This commit is contained in:
parent
4f8d8e61cf
commit
7ee2b211cf
3 changed files with 65 additions and 26 deletions
|
|
@ -112,13 +112,25 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
using (this.RebuildLock())
|
||||
{
|
||||
this.DebugDepth("Rebuild");
|
||||
var aabb = this.GetAxisAlignedBoundingBox();
|
||||
|
||||
// check if we have initialized the Axis
|
||||
if (Axis.Origin.X == double.NegativeInfinity)
|
||||
{
|
||||
// make it something reasonable (just to the left of the aabb of the object)
|
||||
var aabb = this.GetAxisAlignedBoundingBox();
|
||||
Axis.Origin = aabb.Center - new Vector3(30, 0, 0);
|
||||
Axis.Origin = aabb.Center - new Vector3(-30, 0, 0);
|
||||
}
|
||||
|
||||
// make sure our length is in the right axis
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (Axis.Normal[i] != 0 && Axis.Origin[i] == 0)
|
||||
{
|
||||
var newOrigin = Vector3.Zero;
|
||||
newOrigin[i] = Math.Max(aabb.Center[0] - Axis.Origin[0],
|
||||
Math.Max(aabb.Center[1] - Axis.Origin[1],
|
||||
aabb.Center[2] - Axis.Origin[2]));
|
||||
}
|
||||
}
|
||||
|
||||
var sourceContainer = OperationSourceObject3D.GetOrCreateSourceContainer(this);
|
||||
|
|
@ -141,8 +153,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
if (!RotatePart)
|
||||
{
|
||||
var aabb = next.GetAxisAlignedBoundingBox();
|
||||
next.Rotate(aabb.Center, normal, -angleRadians);
|
||||
var nextAabb = next.GetAxisAlignedBoundingBox();
|
||||
next.Rotate(nextAabb.Center, normal, -angleRadians);
|
||||
}
|
||||
|
||||
list.Add(next);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
{
|
||||
public class RotateObject3D_2 : TransformWrapperObject3D, IEditorDraw
|
||||
{
|
||||
public DirectionAxis Axis { get; set; } = new DirectionAxis() { Origin = Vector3.NegativeInfinity, Normal = Vector3.UnitZ };
|
||||
public DirectionAxis RotateAbout { get; set; } = new DirectionAxis() { Origin = Vector3.NegativeInfinity, Normal = Vector3.UnitZ };
|
||||
[DisplayName("Angle")]
|
||||
public double AngleDegrees { get; set; } = 0;
|
||||
|
||||
|
|
@ -71,9 +71,9 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
get
|
||||
{
|
||||
var angleRadians = MathHelper.DegreesToRadians(AngleDegrees);
|
||||
var rotation = Matrix4X4.CreateTranslation(-Axis.Origin)
|
||||
* Matrix4X4.CreateRotation(Axis.Normal, angleRadians)
|
||||
* Matrix4X4.CreateTranslation(Axis.Origin);
|
||||
var rotation = Matrix4X4.CreateTranslation(-RotateAbout.Origin)
|
||||
* Matrix4X4.CreateRotation(RotateAbout.Normal, angleRadians)
|
||||
* Matrix4X4.CreateTranslation(RotateAbout.Origin);
|
||||
|
||||
return rotation;
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
&& layer.Scene.SelectedItem != null
|
||||
&& layer.Scene.SelectedItem.DescendantsAndSelf().Where((i) => i == this).Any())
|
||||
{
|
||||
layer.World.RenderDirectionAxis(Axis, this.WorldMatrix(), 30);
|
||||
layer.World.RenderDirectionAxis(RotateAbout, this.WorldMatrix(), 30);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
var rotate = new RotateObject3D_2();
|
||||
var aabb = itemToRotate.GetAxisAlignedBoundingBox();
|
||||
|
||||
rotate.Axis.Origin = aabb.Center;
|
||||
rotate.RotateAbout.Origin = aabb.Center;
|
||||
|
||||
var rotateItem = new Object3D();
|
||||
rotate.Children.Add(rotateItem);
|
||||
|
|
|
|||
|
|
@ -323,35 +323,62 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
else if (propertyValue is DirectionAxis directionAxis)
|
||||
{
|
||||
rowContainer = CreateSettingsColumn(property);
|
||||
var newDirectionVector = new DirectionVector()
|
||||
{
|
||||
Normal = directionAxis.Normal
|
||||
};
|
||||
var row1 = CreateSettingsRow("Axis".Localize());
|
||||
var field1 = new DirectionVectorField();
|
||||
field1.Initialize(0);
|
||||
field1.SetValue(newDirectionVector);
|
||||
row1.AddChild(field1.Content);
|
||||
|
||||
rowContainer.AddChild(row1);
|
||||
|
||||
// the direction axis
|
||||
// the distance from the center of the part
|
||||
// create a double editor
|
||||
var field = new DoubleField();
|
||||
field.Initialize(0);
|
||||
field.DoubleValue = directionAxis.Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
||||
field.ValueChanged += (s, e) =>
|
||||
{
|
||||
property.SetValue(
|
||||
new DirectionAxis()
|
||||
{
|
||||
Normal = Vector3.UnitZ, Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field.DoubleValue, 0, 0)
|
||||
});
|
||||
object3D?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
||||
propertyGridModifier?.UpdateControls(context);
|
||||
};
|
||||
var field2 = new DoubleField();
|
||||
var row2 = CreateSettingsRow("Offset");
|
||||
field2.Initialize(0);
|
||||
field2.DoubleValue = directionAxis.Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
||||
|
||||
// update this when changed
|
||||
EventHandler<InvalidateArgs> updateData = (s, e) =>
|
||||
{
|
||||
field.DoubleValue = ((DirectionAxis)property.Value).Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
||||
field2.DoubleValue = ((DirectionAxis)property.Value).Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
||||
};
|
||||
property.Item.Invalidated += updateData;
|
||||
field.Content.Closed += (s, e) =>
|
||||
field2.Content.Closed += (s, e) =>
|
||||
{
|
||||
property.Item.Invalidated -= updateData;
|
||||
};
|
||||
|
||||
rowContainer = CreateSettingsRow(property, field);
|
||||
// update functions
|
||||
field1.ValueChanged += (s, e) =>
|
||||
{
|
||||
property.SetValue(new DirectionAxis()
|
||||
{
|
||||
Normal = field1.DirectionVector.Normal,
|
||||
Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field2.DoubleValue, 0, 0)
|
||||
});
|
||||
object3D?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
||||
propertyGridModifier?.UpdateControls(context);
|
||||
};
|
||||
field2.ValueChanged += (s, e) =>
|
||||
{
|
||||
property.SetValue(new DirectionAxis()
|
||||
{
|
||||
Normal = field1.DirectionVector.Normal,
|
||||
Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field2.DoubleValue, 0, 0)
|
||||
});
|
||||
object3D?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
||||
propertyGridModifier?.UpdateControls(context);
|
||||
};
|
||||
|
||||
row2.AddChild(field2.Content);
|
||||
rowContainer.AddChild(row2);
|
||||
}
|
||||
else if (propertyValue is ChildrenSelector childSelector)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue