Proportional scale for height and corner controls
This commit is contained in:
parent
100ddf2bfa
commit
75dd3834ab
4 changed files with 58 additions and 71 deletions
|
|
@ -143,6 +143,19 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
InitialState.Matrix = selectedItem.Matrix;
|
||||
}
|
||||
|
||||
internal void ScaleWidthDepth(double newWidth, double newDepth)
|
||||
{
|
||||
FinalState = InitialState;
|
||||
FinalState.Width = newWidth;
|
||||
FinalState.Depth = newDepth;
|
||||
if (context.GuiSurface.ModifierKeys == Keys.Shift)
|
||||
{
|
||||
ScaleProportional(newWidth / InitialState.Width);
|
||||
}
|
||||
|
||||
SetItem(selectedItem, FinalState);
|
||||
}
|
||||
|
||||
private void EditComplete(ScaleStates undoState, ScaleStates doState)
|
||||
{
|
||||
var undoBuffer = context.Scene.UndoBuffer;
|
||||
|
|
@ -187,6 +200,8 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}
|
||||
|
||||
item.Matrix = states.Matrix;
|
||||
|
||||
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
}
|
||||
|
||||
public struct ScaleStates
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ using MatterHackers.PolygonMesh;
|
|||
using MatterHackers.RayTracer;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MatterHackers.Plugins.EditorTools
|
||||
|
|
@ -69,7 +70,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
public ScaleHeightControl(IObject3DControlContext context)
|
||||
: base(context)
|
||||
{
|
||||
theme = AppContext.Theme;
|
||||
theme = MatterControl.AppContext.Theme;
|
||||
|
||||
heightValueDisplayInfo = new InlineEditControl()
|
||||
{
|
||||
|
|
@ -116,6 +117,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
await selectedItem.Rebuild();
|
||||
|
||||
throw new NotImplementedException("Need to have the object set by the time we edit complete for undo to be right");
|
||||
Invalidate();
|
||||
|
||||
scaleController.EditComplete();
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
private Vector3 initialHitPosition;
|
||||
|
||||
private Vector2 sizeOnMouseDown;
|
||||
private Matrix4X4 matrixOnMouseDown;
|
||||
private ScaleController scaleController = new ScaleController();
|
||||
|
||||
public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, int quadrant)
|
||||
: base(object3DControlContext)
|
||||
|
|
@ -130,13 +129,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
if (selectedItem != null
|
||||
&& MouseDownOnControl)
|
||||
{
|
||||
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem)
|
||||
{
|
||||
widthDepthItem.Width = sizeOnMouseDown.X;
|
||||
widthDepthItem.Depth = sizeOnMouseDown.Y;
|
||||
}
|
||||
|
||||
selectedItem.Matrix = matrixOnMouseDown;
|
||||
scaleController.Cancel();
|
||||
|
||||
MouseDownOnControl = false;
|
||||
MouseIsOver = false;
|
||||
|
|
@ -231,12 +224,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
hitPlane = new PlaneShape(new Plane(planeNormal, edge0), null);
|
||||
|
||||
initialHitPosition = mouseEvent3D.info.HitPosition;
|
||||
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem)
|
||||
{
|
||||
sizeOnMouseDown = new Vector2(widthDepthItem.Width, widthDepthItem.Depth);
|
||||
}
|
||||
|
||||
matrixOnMouseDown = selectedItem.Matrix;
|
||||
scaleController.SetInitialState(Object3DControlContext);
|
||||
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = false;
|
||||
}
|
||||
|
|
@ -254,9 +242,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
xValueDisplayInfo.Visible = true;
|
||||
yValueDisplayInfo.Visible = true;
|
||||
}
|
||||
else if (!hadClickOnControl
|
||||
|| (selectedItem is IObjectWithWidthAndDepth widthDepthItem
|
||||
&& (widthDepthItem.Width != sizeOnMouseDown.X || widthDepthItem.Depth != sizeOnMouseDown.Y)))
|
||||
else if (!hadClickOnControl || scaleController.HasChange)
|
||||
{
|
||||
xValueDisplayInfo.Visible = false;
|
||||
yValueDisplayInfo.Visible = false;
|
||||
|
|
@ -283,40 +269,35 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
var deltaAlong03 = direction03.Dot(delta);
|
||||
|
||||
// scale it
|
||||
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem)
|
||||
var newSize = new Vector2(scaleController.InitialState.Width, scaleController.InitialState.Depth);
|
||||
if (quadrantIndex % 2 == 0)
|
||||
{
|
||||
var newSize = new Vector3(widthDepthItem.Width, widthDepthItem.Depth, 0);
|
||||
if (quadrantIndex % 2 == 0)
|
||||
{
|
||||
newSize.X = sizeOnMouseDown.X + deltaAlong01;
|
||||
newSize.X = Math.Max(Math.Max(newSize.X, .001), Object3DControlContext.SnapGridDistance);
|
||||
newSize.X += deltaAlong01;
|
||||
newSize.X = Math.Max(Math.Max(newSize.X, .001), Object3DControlContext.SnapGridDistance);
|
||||
|
||||
newSize.Y = sizeOnMouseDown.Y + deltaAlong03;
|
||||
newSize.Y = Math.Max(Math.Max(newSize.Y, .001), Object3DControlContext.SnapGridDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
newSize.X = sizeOnMouseDown.X + deltaAlong03;
|
||||
newSize.X = Math.Max(Math.Max(newSize.X, .001), Object3DControlContext.SnapGridDistance);
|
||||
|
||||
newSize.Y = sizeOnMouseDown.Y + deltaAlong01;
|
||||
newSize.Y = Math.Max(Math.Max(newSize.Y, .001), Object3DControlContext.SnapGridDistance);
|
||||
}
|
||||
|
||||
if (Object3DControlContext.SnapGridDistance > 0)
|
||||
{
|
||||
// snap this position to the grid
|
||||
double snapGridDistance = Object3DControlContext.SnapGridDistance;
|
||||
|
||||
// snap this position to the grid
|
||||
newSize.X = ((int)((newSize.X / snapGridDistance) + .5)) * snapGridDistance;
|
||||
newSize.Y = ((int)((newSize.Y / snapGridDistance) + .5)) * snapGridDistance;
|
||||
}
|
||||
|
||||
widthDepthItem.Width = newSize.X;
|
||||
widthDepthItem.Depth = newSize.Y;
|
||||
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
newSize.Y += deltaAlong03;
|
||||
newSize.Y = Math.Max(Math.Max(newSize.Y, .001), Object3DControlContext.SnapGridDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
newSize.X += deltaAlong03;
|
||||
newSize.X = Math.Max(Math.Max(newSize.X, .001), Object3DControlContext.SnapGridDistance);
|
||||
|
||||
newSize.Y += deltaAlong01;
|
||||
newSize.Y = Math.Max(Math.Max(newSize.Y, .001), Object3DControlContext.SnapGridDistance);
|
||||
}
|
||||
|
||||
if (Object3DControlContext.SnapGridDistance > 0)
|
||||
{
|
||||
// snap this position to the grid
|
||||
double snapGridDistance = Object3DControlContext.SnapGridDistance;
|
||||
|
||||
// snap this position to the grid
|
||||
newSize.X = ((int)((newSize.X / snapGridDistance) + .5)) * snapGridDistance;
|
||||
newSize.Y = ((int)((newSize.Y / snapGridDistance) + .5)) * snapGridDistance;
|
||||
}
|
||||
|
||||
scaleController.ScaleWidthDepth(newSize.X, newSize.Y);
|
||||
|
||||
await selectedItem.Rebuild();
|
||||
|
||||
|
|
@ -337,14 +318,10 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
if (hadClickOnControl)
|
||||
{
|
||||
if (RootSelection is IObjectWithWidthAndDepth widthDepthItem
|
||||
&& (widthDepthItem.Width != sizeOnMouseDown.X || widthDepthItem.Depth != sizeOnMouseDown.Y))
|
||||
&& (widthDepthItem.Width != scaleController.InitialState.Width
|
||||
|| widthDepthItem.Depth != scaleController.InitialState.Depth))
|
||||
{
|
||||
SetWidthDepthUndo(RootSelection,
|
||||
Object3DControlContext.Scene.UndoBuffer,
|
||||
new Vector2(widthDepthItem.Width, widthDepthItem.Depth),
|
||||
RootSelection.Matrix,
|
||||
sizeOnMouseDown,
|
||||
matrixOnMouseDown);
|
||||
scaleController.EditComplete();
|
||||
}
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
|
@ -417,16 +394,11 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
Vector3 lockedEdge = ObjectSpace.GetCornerPosition(ActiveSelectedItem, quadrantIndex + 2);
|
||||
|
||||
Vector3 newSize = Vector3.Zero;
|
||||
newSize.X = xValueDisplayInfo.Value != 0 ? xValueDisplayInfo.Value : widthDepthItem.Width;
|
||||
newSize.Y = yValueDisplayInfo.Value != 0 ? yValueDisplayInfo.Value : widthDepthItem.Depth;
|
||||
scaleController.FinalState.Width = xValueDisplayInfo.Value != 0 ? xValueDisplayInfo.Value : widthDepthItem.Width;
|
||||
scaleController.FinalState.Height = yValueDisplayInfo.Value != 0 ? yValueDisplayInfo.Value : widthDepthItem.Depth;
|
||||
|
||||
SetWidthDepthUndo(RootSelection,
|
||||
Object3DControlContext.Scene.UndoBuffer,
|
||||
new Vector2(newSize),
|
||||
RootSelection.Matrix,
|
||||
sizeOnMouseDown,
|
||||
matrixOnMouseDown);
|
||||
throw new NotImplementedException("Need to have the matrix set by the time we edit complete for undo to be right");
|
||||
scaleController.EditComplete();
|
||||
|
||||
// and keep the locked edge in place
|
||||
Vector3 newLockedEdge = ObjectSpace.GetCornerPosition(ActiveSelectedItem, quadrantIndex + 2);
|
||||
|
|
|
|||
|
|
@ -298,8 +298,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
scaleController.ScaleDepth(newSize.Y);
|
||||
}
|
||||
|
||||
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
|
||||
await selectedItem.Rebuild();
|
||||
|
||||
// and keep the locked edge in place
|
||||
|
|
@ -391,10 +389,10 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
Vector3 lockedEdge = ObjectSpace.GetEdgePosition(ActiveSelectedItem, edgeIndex + 2);
|
||||
|
||||
Vector3 newSize = Vector3.Zero;
|
||||
newSize.X = xValueDisplayInfo.Value != 0 ? xValueDisplayInfo.Value : widthDepthItem.Width;
|
||||
newSize.Y = yValueDisplayInfo.Value != 0 ? yValueDisplayInfo.Value : widthDepthItem.Depth;
|
||||
scaleController.FinalState.Width = xValueDisplayInfo.Value != 0 ? xValueDisplayInfo.Value : widthDepthItem.Width;
|
||||
scaleController.FinalState.Height = yValueDisplayInfo.Value != 0 ? yValueDisplayInfo.Value : widthDepthItem.Depth;
|
||||
|
||||
throw new NotImplementedException("Need to have the matrix set by the time we edit complete for undo to be right");
|
||||
scaleController.EditComplete();
|
||||
|
||||
// and keep the locked edge in place
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue