Scale height control can scale proportional
This commit is contained in:
parent
ee65c180c2
commit
100ddf2bfa
4 changed files with 65 additions and 75 deletions
|
|
@ -79,16 +79,14 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
selectedItem.Matrix = InitialState.Matrix;
|
||||
}
|
||||
|
||||
public void ScaleWidth(double newWidth)
|
||||
public void EditComplete()
|
||||
{
|
||||
FinalState = InitialState;
|
||||
FinalState.Width = newWidth;
|
||||
if (context.GuiSurface.ModifierKeys == Keys.Shift)
|
||||
{
|
||||
ScaleProportional(newWidth / InitialState.Width);
|
||||
}
|
||||
var doState = FinalState;
|
||||
doState.Matrix = selectedItem.Matrix;
|
||||
|
||||
SetItem(selectedItem, FinalState);
|
||||
var undoState = InitialState;
|
||||
|
||||
EditComplete(undoState, doState);
|
||||
}
|
||||
|
||||
public void ScaleDepth(double newDepth)
|
||||
|
|
@ -103,27 +101,28 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
SetItem(selectedItem, FinalState);
|
||||
}
|
||||
|
||||
private void ScaleProportional(double scale)
|
||||
public void ScaleHeight(double newHeight)
|
||||
{
|
||||
FinalState.Width = InitialState.Width * scale;
|
||||
FinalState.Depth = InitialState.Depth * scale;
|
||||
FinalState.Height = InitialState.Height * scale;
|
||||
FinalState = InitialState;
|
||||
FinalState.Height = newHeight;
|
||||
if (context.GuiSurface.ModifierKeys == Keys.Shift)
|
||||
{
|
||||
ScaleProportional(newHeight / InitialState.Height);
|
||||
}
|
||||
|
||||
SetItem(selectedItem, FinalState);
|
||||
}
|
||||
|
||||
private void SetItem(IObject3D item, ScaleStates states)
|
||||
public void ScaleWidth(double newWidth)
|
||||
{
|
||||
if (item is IObjectWithWidthAndDepth widthDepthItem)
|
||||
FinalState = InitialState;
|
||||
FinalState.Width = newWidth;
|
||||
if (context.GuiSurface.ModifierKeys == Keys.Shift)
|
||||
{
|
||||
widthDepthItem.Width = states.Width;
|
||||
widthDepthItem.Depth = states.Depth;
|
||||
ScaleProportional(newWidth / InitialState.Width);
|
||||
}
|
||||
|
||||
if (item is IObjectWithHeight heightItem)
|
||||
{
|
||||
heightItem.Height = states.Height;
|
||||
}
|
||||
|
||||
item.Matrix = states.Matrix;
|
||||
SetItem(selectedItem, FinalState);
|
||||
}
|
||||
|
||||
public void SetInitialState(IObject3DControlContext context)
|
||||
|
|
@ -144,16 +143,6 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
InitialState.Matrix = selectedItem.Matrix;
|
||||
}
|
||||
|
||||
public void WidthDepthEditComplete()
|
||||
{
|
||||
var doState = FinalState;
|
||||
doState.Matrix = selectedItem.Matrix;
|
||||
|
||||
var undoState = InitialState;
|
||||
|
||||
EditComplete(undoState, doState);
|
||||
}
|
||||
|
||||
private void EditComplete(ScaleStates undoState, ScaleStates doState)
|
||||
{
|
||||
var undoBuffer = context.Scene.UndoBuffer;
|
||||
|
|
@ -177,6 +166,29 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}));
|
||||
}
|
||||
|
||||
private void ScaleProportional(double scale)
|
||||
{
|
||||
FinalState.Width = InitialState.Width * scale;
|
||||
FinalState.Depth = InitialState.Depth * scale;
|
||||
FinalState.Height = InitialState.Height * scale;
|
||||
}
|
||||
|
||||
private void SetItem(IObject3D item, ScaleStates states)
|
||||
{
|
||||
if (item is IObjectWithWidthAndDepth widthDepthItem)
|
||||
{
|
||||
widthDepthItem.Width = states.Width;
|
||||
widthDepthItem.Depth = states.Depth;
|
||||
}
|
||||
|
||||
if (item is IObjectWithHeight heightItem)
|
||||
{
|
||||
heightItem.Height = states.Height;
|
||||
}
|
||||
|
||||
item.Matrix = states.Matrix;
|
||||
}
|
||||
|
||||
public struct ScaleStates
|
||||
{
|
||||
public double Depth;
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
private bool hadClickOnControl;
|
||||
|
||||
private double heightOnMouseDown = 0;
|
||||
|
||||
private PlaneShape hitPlane;
|
||||
|
||||
private Vector3 initialHitPosition;
|
||||
|
||||
private Vector3 originalPointToMove;
|
||||
|
||||
private ScaleController scaleController = new ScaleController();
|
||||
|
||||
public ScaleHeightControl(IObject3DControlContext context)
|
||||
: base(context)
|
||||
{
|
||||
|
|
@ -118,7 +118,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
|
||||
Invalidate();
|
||||
|
||||
SetHeightUndo(heightValueDisplayInfo.Value, heightObject.Height);
|
||||
scaleController.EditComplete();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -143,10 +143,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
if (selectedItem != null
|
||||
&& MouseDownOnControl)
|
||||
{
|
||||
if (activeSelectedItem is IObjectWithHeight heightObject)
|
||||
{
|
||||
heightObject.Height = heightOnMouseDown;
|
||||
}
|
||||
scaleController.Cancel();
|
||||
|
||||
MouseDownOnControl = false;
|
||||
MouseIsOver = false;
|
||||
|
|
@ -262,10 +259,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
hitPlane = new PlaneShape(new Plane(planeNormal, mouseEvent3D.info.HitPosition), null);
|
||||
|
||||
initialHitPosition = mouseEvent3D.info.HitPosition;
|
||||
if (selectedItem is IObjectWithHeight heightObject)
|
||||
{
|
||||
heightOnMouseDown = heightObject.Height;
|
||||
}
|
||||
scaleController.SetInitialState(Object3DControlContext);
|
||||
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = false;
|
||||
}
|
||||
|
|
@ -318,12 +312,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
newSize = ((int)((newSize / snapGridDistance) + .5)) * snapGridDistance;
|
||||
}
|
||||
|
||||
if (selectedItem is IObjectWithHeight heightObject)
|
||||
{
|
||||
heightObject.Height = newSize;
|
||||
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
}
|
||||
|
||||
scaleController.ScaleHeight(newSize);
|
||||
|
||||
await selectedItem.Rebuild();
|
||||
|
||||
|
|
@ -343,9 +332,9 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
if (MouseDownOnControl)
|
||||
{
|
||||
if (activeSelectedItem is IObjectWithHeight heightObject
|
||||
&& heightObject.Height != heightOnMouseDown)
|
||||
&& heightObject.Height != scaleController.InitialState.Height)
|
||||
{
|
||||
SetHeightUndo(heightObject.Height, heightOnMouseDown);
|
||||
scaleController.EditComplete();
|
||||
}
|
||||
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
|
|
@ -421,23 +410,5 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetHeightUndo(double doHeight, double undoHeight)
|
||||
{
|
||||
if (activeSelectedItem is IObjectWithHeight heightObject)
|
||||
{
|
||||
var undoBuffer = Object3DControlContext.Scene.UndoBuffer;
|
||||
undoBuffer.AddAndDo(new UndoRedoActions(() =>
|
||||
{
|
||||
heightObject.Height = undoHeight;
|
||||
activeSelectedItem?.Invalidate(new InvalidateArgs(activeSelectedItem, InvalidateType.Properties));
|
||||
},
|
||||
() =>
|
||||
{
|
||||
heightObject.Height = doHeight;
|
||||
activeSelectedItem?.Invalidate(new InvalidateArgs(activeSelectedItem, InvalidateType.Properties));
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
bool shouldDrawScaleControls = true;
|
||||
if (Object3DControlContext.SelectedObject3DControl != null
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleMatrixCornerControl == null)
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleWidthDepthCornerControl == null)
|
||||
{
|
||||
shouldDrawScaleControls = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
{
|
||||
bool shouldDrawScaleControls = true;
|
||||
if (Object3DControlContext.SelectedObject3DControl != null
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleMatrixEdgeControl == null)
|
||||
&& Object3DControlContext.SelectedObject3DControl as ScaleWidthDepthEdgeControl == null)
|
||||
{
|
||||
shouldDrawScaleControls = false;
|
||||
}
|
||||
|
|
@ -282,15 +282,22 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
if (edgeIndex % 2 == 1)
|
||||
{
|
||||
newSize.X = ((int)((newSize.X / snapGridDistance) + .5)) * snapGridDistance;
|
||||
scaleController.ScaleWidth(newSize.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
newSize.Y = ((int)((newSize.Y / snapGridDistance) + .5)) * snapGridDistance;
|
||||
scaleController.ScaleDepth(newSize.Y);
|
||||
}
|
||||
}
|
||||
|
||||
if (edgeIndex % 2 == 1)
|
||||
{
|
||||
scaleController.ScaleWidth(newSize.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
scaleController.ScaleDepth(newSize.Y);
|
||||
}
|
||||
|
||||
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
|
||||
|
||||
await selectedItem.Rebuild();
|
||||
|
|
@ -315,7 +322,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
&& (widthDepthItem.Width != scaleController.InitialState.Width
|
||||
|| widthDepthItem.Depth != scaleController.InitialState.Depth))
|
||||
{
|
||||
scaleController.WidthDepthEditComplete();
|
||||
scaleController.EditComplete();
|
||||
}
|
||||
Object3DControlContext.Scene.ShowSelectionShadow = true;
|
||||
}
|
||||
|
|
@ -388,7 +395,7 @@ namespace MatterHackers.Plugins.EditorTools
|
|||
newSize.X = xValueDisplayInfo.Value != 0 ? xValueDisplayInfo.Value : widthDepthItem.Width;
|
||||
newSize.Y = yValueDisplayInfo.Value != 0 ? yValueDisplayInfo.Value : widthDepthItem.Depth;
|
||||
|
||||
scaleController.WidthDepthEditComplete();
|
||||
scaleController.EditComplete();
|
||||
|
||||
// and keep the locked edge in place
|
||||
Vector3 newLockedEdge = ObjectSpace.GetEdgePosition(ActiveSelectedItem, edgeIndex + 2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue