diameter control is working cancel scale is working

This commit is contained in:
LarsBrubaker 2021-05-01 22:06:43 -07:00
parent 75dd3834ab
commit ec41a2b6aa
17 changed files with 524 additions and 33 deletions

View file

@ -44,6 +44,16 @@ namespace MatterHackers.Plugins.EditorTools
private IObject3DControlContext context;
private Func<double> getDiameter;
private Action<double> setDiameter;
public ScaleController(Func<double> getDiameter = null, Action<double> setDiameter = null)
{
this.getDiameter = getDiameter;
this.setDiameter = setDiameter;
}
public bool HasChange
{
get
@ -76,7 +86,21 @@ namespace MatterHackers.Plugins.EditorTools
widthDepthItem.Depth = InitialState.Depth;
}
if (selectedItem is IObjectWithHeight heightItem)
{
heightItem.Height= InitialState.Height;
}
if (setDiameter != null)
{
setDiameter?.Invoke(InitialState.Diameter);
}
selectedItem.Rebuild();
selectedItem.Matrix = InitialState.Matrix;
selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
}
public void EditComplete()
@ -101,6 +125,18 @@ namespace MatterHackers.Plugins.EditorTools
SetItem(selectedItem, FinalState);
}
public void ScaleDiameter(double newSize)
{
FinalState = InitialState;
FinalState.Diameter = newSize;
if (context.GuiSurface.ModifierKeys == Keys.Shift)
{
ScaleProportional(newSize / InitialState.Diameter);
}
SetItem(selectedItem, FinalState);
}
public void ScaleHeight(double newHeight)
{
FinalState = InitialState;
@ -140,6 +176,11 @@ namespace MatterHackers.Plugins.EditorTools
InitialState.Height = heightItem.Height;
}
if (getDiameter != null)
{
InitialState.Diameter = getDiameter.Invoke();
}
InitialState.Matrix = selectedItem.Matrix;
}
@ -184,6 +225,7 @@ namespace MatterHackers.Plugins.EditorTools
FinalState.Width = InitialState.Width * scale;
FinalState.Depth = InitialState.Depth * scale;
FinalState.Height = InitialState.Height * scale;
FinalState.Diameter = InitialState.Diameter * scale;
}
private void SetItem(IObject3D item, ScaleStates states)
@ -199,9 +241,11 @@ namespace MatterHackers.Plugins.EditorTools
heightItem.Height = states.Height;
}
setDiameter?.Invoke(states.Diameter);
item.Matrix = states.Matrix;
selectedItem.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
item.Invalidate(new InvalidateArgs(item, InvalidateType.DisplayValues));
}
public struct ScaleStates
@ -212,6 +256,8 @@ namespace MatterHackers.Plugins.EditorTools
public double Width;
public double Diameter { get; internal set; }
public Matrix4X4 Matrix { get; set; }
}
}