All the corner and edge controls are working
This commit is contained in:
parent
b13b3ed056
commit
fa80380c26
12 changed files with 162 additions and 86 deletions
|
|
@ -340,10 +340,14 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
if (activeSelectedItem is IObjectWithHeight heightObject
|
||||
&& heightObject.Height != heightOnMouseDown)
|
||||
if (MouseDownOnControl)
|
||||
{
|
||||
SetHeightUndo(heightObject.Height, heightOnMouseDown);
|
||||
if (activeSelectedItem is IObjectWithHeight heightObject
|
||||
&& heightObject.Height != heightOnMouseDown)
|
||||
{
|
||||
SetHeightUndo(heightObject.Height, heightOnMouseDown);
|
||||
}
|
||||
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
private double LineLength => 35 * GuiWidget.DeviceScale;
|
||||
|
||||
private readonly List<Vector2> lines = new List<Vector2>();
|
||||
private Vector3 originalPointToMove;
|
||||
private readonly int quadrantIndex;
|
||||
private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale;
|
||||
|
|
@ -194,11 +193,69 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}
|
||||
}
|
||||
|
||||
if (MouseIsOver || MouseDownOnControl)
|
||||
{
|
||||
DrawMeasureLines(e, quadrantIndex);
|
||||
DrawMeasureLines(e, quadrantIndex + 1);
|
||||
}
|
||||
|
||||
base.Draw(e);
|
||||
}
|
||||
|
||||
private (Vector3 start0, Vector3 end0, Vector3 start1, Vector3 end1) GetMeasureLine(int quadrant)
|
||||
{
|
||||
var selectedItem = RootSelection;
|
||||
var corner = new Vector3[4];
|
||||
var screen = new Vector3[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
corner[i] = GetCornerPosition(selectedItem, quadrant + i);
|
||||
screen[i] = Object3DControlContext.World.GetScreenSpace(corner[i]);
|
||||
}
|
||||
|
||||
var start = corner[0];
|
||||
var direction = (start - corner[1]).GetNormal();
|
||||
var end = corner[3];
|
||||
// find out which side we should render on (the one closer to the screen)
|
||||
if (screen[0].Z > screen[1].Z)
|
||||
{
|
||||
start = corner[1];
|
||||
end = corner[2];
|
||||
direction = (start - corner[0]).GetNormal();
|
||||
}
|
||||
|
||||
var startScale = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(start);
|
||||
var endScale = Object3DControlContext.World.GetWorldUnitsPerScreenPixelAtPosition(end);
|
||||
var offset = .3;
|
||||
var start0 = start + direction * LineLength * offset * startScale;
|
||||
var end0 = start + direction * LineLength * (1 + offset) * endScale;
|
||||
var start1 = end + direction * LineLength * offset * endScale;
|
||||
var end1 = end + direction * LineLength * (1 + offset) * endScale;
|
||||
return (start0, end0, start1, end1);
|
||||
}
|
||||
|
||||
private void DrawMeasureLines(DrawGlContentEventArgs e, int quadrant)
|
||||
{
|
||||
var (start0, end0, start1, end1) = GetMeasureLine(quadrant);
|
||||
|
||||
var color = theme.TextColor.WithAlpha(e.Alpha0to255);
|
||||
if (!e.ZBuffered)
|
||||
{
|
||||
theme.TextColor.WithAlpha(Constants.LineAlpha);
|
||||
}
|
||||
|
||||
Frustum clippingFrustum = Object3DControlContext.World.GetClippingFrustum();
|
||||
|
||||
Object3DControlContext.World.Render3DLine(clippingFrustum, start0, end0, color, e.ZBuffered, GuiWidget.DeviceScale);
|
||||
Object3DControlContext.World.Render3DLine(clippingFrustum, start1, end1, color, e.ZBuffered, GuiWidget.DeviceScale);
|
||||
var start = (start0 + end0) / 2;
|
||||
var end = (start1 + end1) / 2;
|
||||
Object3DControlContext.World.Render3DLine(clippingFrustum, start, end, color, e.ZBuffered, GuiWidget.DeviceScale * 1.2, true, true);
|
||||
}
|
||||
|
||||
public Vector3 GetCornerPosition(IObject3D item, int quadrantIndex)
|
||||
{
|
||||
quadrantIndex %= 4;
|
||||
AxisAlignedBoundingBox originalSelectedBounds = item.GetAxisAlignedBoundingBox();
|
||||
Vector3 cornerPosition = originalSelectedBounds.GetBottomCorner(quadrantIndex);
|
||||
|
||||
|
|
@ -359,24 +416,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
var centerMatrix = Matrix4X4.CreateTranslation(boxCenter);
|
||||
centerMatrix = Matrix4X4.CreateScale(distBetweenPixelsWorldSpace) * centerMatrix;
|
||||
TotalTransform = centerMatrix;
|
||||
|
||||
var xOtherSide = new Vector3(cornerPosition.X + otherSideDelta.X, cornerPosition.Y, cornerPosition.Z);
|
||||
var yOtherSide = new Vector3(cornerPosition.X, cornerPosition.Y + otherSideDelta.Y, cornerPosition.Z);
|
||||
|
||||
lines.Clear();
|
||||
// left lines
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(cornerPosition - new Vector3(xSign * DistToStart * distBetweenPixelsWorldSpace, 0, 0)));
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(cornerPosition - new Vector3(xSign * (DistToStart + LineLength) * distBetweenPixelsWorldSpace, 0, 0)));
|
||||
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(yOtherSide - new Vector3(xSign * DistToStart * distBetweenPixelsWorldSpace, 0, 0)));
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(yOtherSide - new Vector3(xSign * (DistToStart + LineLength) * distBetweenPixelsWorldSpace, 0, 0)));
|
||||
|
||||
// bottom lines
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(cornerPosition - new Vector3(0, ySign * DistToStart * distBetweenPixelsWorldSpace, 0)));
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(cornerPosition - new Vector3(0, ySign * (DistToStart + LineLength) * distBetweenPixelsWorldSpace, 0)));
|
||||
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(xOtherSide - new Vector3(0, ySign * DistToStart * distBetweenPixelsWorldSpace, 0)));
|
||||
lines.Add(Object3DControlContext.World.GetScreenPosition(xOtherSide - new Vector3(0, ySign * (DistToStart + LineLength) * distBetweenPixelsWorldSpace, 0)));
|
||||
}
|
||||
|
||||
public static Vector3 GetScalingConsideringShiftKey(AxisAlignedBoundingBox originalSelectedBounds,
|
||||
|
|
@ -487,36 +526,32 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
if (MouseIsOver || MouseDownOnControl)
|
||||
{
|
||||
for (int i = 0; i < lines.Count; i += 2)
|
||||
{
|
||||
// draw the line that is on the ground
|
||||
drawEvent.Graphics2D.Line(lines[i], lines[i + 1], theme.TextColor);
|
||||
}
|
||||
|
||||
for (int i = 0; i < lines.Count; i += 4)
|
||||
{
|
||||
drawEvent.Graphics2D.DrawMeasureLine((lines[i] + lines[i + 1]) / 2,
|
||||
(lines[i + 2] + lines[i + 3]) / 2,
|
||||
LineArrows.Both,
|
||||
theme);
|
||||
}
|
||||
|
||||
int j = 4;
|
||||
|
||||
AxisAlignedBoundingBox selectedBounds = selectedItem.GetAxisAlignedBoundingBox();
|
||||
|
||||
Vector2 widthDisplayCenter = (((lines[j] + lines[j + 1]) / 2) + ((lines[j + 2] + lines[j + 3]) / 2)) / 2;
|
||||
xValueDisplayInfo.Value = selectedBounds.XSize;
|
||||
xValueDisplayInfo.OriginRelativeParent = widthDisplayCenter - xValueDisplayInfo.LocalBounds.Center;
|
||||
|
||||
j = 0;
|
||||
Vector2 heightDisplayCenter = (((lines[j] + lines[j + 1]) / 2) + ((lines[j + 2] + lines[j + 3]) / 2)) / 2;
|
||||
yValueDisplayInfo.Value = selectedBounds.YSize;
|
||||
yValueDisplayInfo.OriginRelativeParent = heightDisplayCenter - yValueDisplayInfo.LocalBounds.Center;
|
||||
UpdateNumberControl(quadrantIndex);
|
||||
UpdateNumberControl(quadrantIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateNumberControl(int quadrant)
|
||||
{
|
||||
var (start0, end0, start1, end1) = GetMeasureLine(quadrant);
|
||||
var start = (start0 + end0) / 2;
|
||||
var end = (start1 + end1) / 2;
|
||||
var screenStart = Object3DControlContext.World.GetScreenPosition(start);
|
||||
var screenEnd = Object3DControlContext.World.GetScreenPosition(end);
|
||||
|
||||
if (quadrant % 2 == 1)
|
||||
{
|
||||
xValueDisplayInfo.Value = (start - end).Length;
|
||||
xValueDisplayInfo.OriginRelativeParent = (screenStart + screenEnd) / 2 - xValueDisplayInfo.LocalBounds.Center;
|
||||
}
|
||||
else
|
||||
{
|
||||
yValueDisplayInfo.Value = (start - end).Length;
|
||||
yValueDisplayInfo.OriginRelativeParent = (screenStart + screenEnd) / 2 - yValueDisplayInfo.LocalBounds.Center;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
xValueDisplayInfo.Close();
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
bool shouldDrawScaleControls = true;
|
||||
if (Object3DControlContext.SelectedObject3DControl != null
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleMatrixEdgeControl == null)
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleMatrixCornerControl == null)
|
||||
{
|
||||
shouldDrawScaleControls = false;
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}
|
||||
else
|
||||
{
|
||||
GLHelper.Render(minXminYMesh, theme.TextColor.Blend(theme.BackgroundColor, .35).WithAlpha(e.Alpha0to255), TotalTransform, RenderTypes.Shaded);
|
||||
GLHelper.Render(minXminYMesh, theme.TextColor.WithAlpha(e.Alpha0to255), TotalTransform, RenderTypes.Shaded);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,16 +334,18 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
if (hadClickOnControl
|
||||
&& RootSelection is IObjectWithWidthAndDepth widthDepthItem
|
||||
&& (widthDepthItem.Width != sizeOnMouseDown.X || widthDepthItem.Depth != sizeOnMouseDown.Y))
|
||||
if (hadClickOnControl)
|
||||
{
|
||||
SetWidthDepthUndo(RootSelection,
|
||||
Object3DControlContext.Scene.UndoBuffer,
|
||||
new Vector2(widthDepthItem.Width,widthDepthItem.Depth),
|
||||
RootSelection.Matrix,
|
||||
sizeOnMouseDown,
|
||||
matrixOnMouseDown);
|
||||
if (RootSelection is IObjectWithWidthAndDepth widthDepthItem
|
||||
&& (widthDepthItem.Width != sizeOnMouseDown.X || widthDepthItem.Depth != sizeOnMouseDown.Y))
|
||||
{
|
||||
SetWidthDepthUndo(RootSelection,
|
||||
Object3DControlContext.Scene.UndoBuffer,
|
||||
new Vector2(widthDepthItem.Width, widthDepthItem.Depth),
|
||||
RootSelection.Matrix,
|
||||
sizeOnMouseDown,
|
||||
matrixOnMouseDown);
|
||||
}
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -325,16 +325,18 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D)
|
||||
{
|
||||
if (hadClickOnControl
|
||||
&& RootSelection is IObjectWithWidthAndDepth widthDepthItem
|
||||
&& (widthDepthItem.Width != sizeOnMouseDown.X || widthDepthItem.Depth != sizeOnMouseDown.Y))
|
||||
if (hadClickOnControl)
|
||||
{
|
||||
ScaleWidthDepthCornerControl.SetWidthDepthUndo(RootSelection,
|
||||
Object3DControlContext.Scene.UndoBuffer,
|
||||
new Vector2(widthDepthItem.Width, widthDepthItem.Depth),
|
||||
RootSelection.Matrix,
|
||||
sizeOnMouseDown,
|
||||
matrixOnMouseDown);
|
||||
if (RootSelection is IObjectWithWidthAndDepth widthDepthItem
|
||||
&& (widthDepthItem.Width != sizeOnMouseDown.X || widthDepthItem.Depth != sizeOnMouseDown.Y))
|
||||
{
|
||||
ScaleWidthDepthCornerControl.SetWidthDepthUndo(RootSelection,
|
||||
Object3DControlContext.Scene.UndoBuffer,
|
||||
new Vector2(widthDepthItem.Width, widthDepthItem.Depth),
|
||||
RootSelection.Matrix,
|
||||
sizeOnMouseDown,
|
||||
matrixOnMouseDown);
|
||||
}
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
public double Diameter { get; set; } = 20;
|
||||
//[DisplayName("Top")]
|
||||
//public double TopDiameter { get; set; } = 0;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Height { get; set; } = 20;
|
||||
|
||||
public int Sides { get; set; } = 40;
|
||||
|
||||
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
||||
|
|
|
|||
|
|
@ -44,10 +44,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public override string ThumbnailName => "Cube";
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Width { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Depth { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Height { get; set; } = 20;
|
||||
|
||||
public static async Task<CubeObject3D> Create()
|
||||
|
|
|
|||
|
|
@ -33,11 +33,12 @@ using MatterHackers.Agg;
|
|||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools
|
||||
{
|
||||
public class HalfCylinderObject3D : PrimitiveObject3D
|
||||
public class HalfCylinderObject3D : PrimitiveObject3D, IObject3DControlsProvider, IObjectWithWidthAndDepth
|
||||
{
|
||||
public HalfCylinderObject3D()
|
||||
{
|
||||
|
|
@ -55,8 +56,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return item;
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Width { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Depth { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public int Sides { get; set; } = 20;
|
||||
|
||||
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
||||
|
|
@ -105,5 +111,10 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
||||
{
|
||||
object3DControlsLayer.AddControls(ControlTypes.ScaleWidthDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,8 +53,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return item;
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Width { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Depth { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Height { get; set; } = 10;
|
||||
|
||||
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return item;
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Width { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Depth { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Height { get; set; } = 20;
|
||||
|
||||
public override async void OnInvalidate(InvalidateArgs invalidateType)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public double PointSize { get; set; } = 24;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Height { get; set; } = 5;
|
||||
|
||||
[Sortable]
|
||||
|
|
|
|||
|
|
@ -56,10 +56,13 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
return item;
|
||||
}
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Width { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Depth { get; set; } = 20;
|
||||
|
||||
[MaxDecimalPlaces(2)]
|
||||
public double Height { get; set; } = 20;
|
||||
|
||||
public bool Round { get; set; } = false;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
MoveInZ = 1,
|
||||
RotateXYZ = 2,
|
||||
RotateZ = 4,
|
||||
ScaleCornersXY = 8,
|
||||
ScaleWidthDepth = 8,
|
||||
ScaleMatrixXY = 16,
|
||||
Shadow = 32,
|
||||
SnappingIndicators = 64,
|
||||
|
|
@ -190,11 +190,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
if (selectedItem is IObjectWithWidthAndDepth widthAndDepth)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Object3DControls.Add(new ScaleWidthDepthCornerControl(this, i));
|
||||
Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, i));
|
||||
}
|
||||
AddControls(ControlTypes.ScaleWidthDepth);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -213,9 +209,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
if (controls.HasFlag(ControlTypes.RotateXYZ))
|
||||
{
|
||||
Object3DControls.Add(new RotateCornerControl(this, 0));
|
||||
Object3DControls.Add(new RotateCornerControl(this, 1));
|
||||
Object3DControls.Add(new RotateCornerControl(this, 2));
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Object3DControls.Add(new RotateCornerControl(this, i));
|
||||
}
|
||||
}
|
||||
|
||||
if (controls.HasFlag(ControlTypes.RotateZ))
|
||||
|
|
@ -235,15 +232,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
if (controls.HasFlag(ControlTypes.ScaleMatrixXY))
|
||||
{
|
||||
Object3DControls.Add(new ScaleMatrixCornerControl(this, 0));
|
||||
Object3DControls.Add(new ScaleMatrixCornerControl(this, 1));
|
||||
Object3DControls.Add(new ScaleMatrixCornerControl(this, 2));
|
||||
Object3DControls.Add(new ScaleMatrixCornerControl(this, 3));
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Object3DControls.Add(new ScaleMatrixCornerControl(this, i));
|
||||
Object3DControls.Add(new ScaleMatrixEdgeControl(this, i));
|
||||
}
|
||||
}
|
||||
|
||||
Object3DControls.Add(new ScaleMatrixEdgeControl(this, 0));
|
||||
Object3DControls.Add(new ScaleMatrixEdgeControl(this, 1));
|
||||
Object3DControls.Add(new ScaleMatrixEdgeControl(this, 2));
|
||||
Object3DControls.Add(new ScaleMatrixEdgeControl(this, 3));
|
||||
if (controls.HasFlag(ControlTypes.ScaleWidthDepth))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Object3DControls.Add(new ScaleWidthDepthCornerControl(this, i));
|
||||
Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, i));
|
||||
}
|
||||
}
|
||||
|
||||
if (controls.HasFlag(ControlTypes.Shadow))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue