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