Made width depth scale controls work with variables

This commit is contained in:
LarsBrubaker 2021-05-31 16:12:07 -07:00
parent 8d386825d0
commit abe5d17012
17 changed files with 300 additions and 123 deletions

View file

@ -49,20 +49,34 @@ namespace MatterHackers.Plugins.EditorTools
private List<Func<double>> getDiameters;
private List<Action<double>> setDiameters;
private Func<double> getWidth;
private Action<double> setWidth;
private Func<double> getDepth;
private Action<double> setDepth;
private Func<double> getHeight;
private Action<double> setHeight;
public ScaleController(Func<double> getHeight,
public ScaleController(Func<double> getWidth,
Action<double> setWidth,
Func<double> getDepth,
Action<double> setDepth,
Func<double> getHeight,
Action<double> setHeight,
List<Func<double>> getDiameters = null,
List<Action<double>> setDiameters = null)
{
this.getDiameters = getDiameters;
this.setDiameters = setDiameters;
this.getWidth = getWidth;
this.setWidth = setWidth;
this.getDepth = getDepth;
this.setDepth = setDepth;
this.getHeight = getHeight;
this.setHeight = setHeight;
this.getDiameters = getDiameters;
this.setDiameters = setDiameters;
if (getDiameters != null)
{
for (int i = 0; i < getDiameters.Count; i++)
@ -76,8 +90,8 @@ namespace MatterHackers.Plugins.EditorTools
{
get
{
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem
&& (widthDepthItem.Width != InitialState.Width || widthDepthItem.Depth != InitialState.Depth))
if (getWidth != null
&& (getWidth() != InitialState.Width || getDepth() != InitialState.Depth))
{
return true;
}
@ -98,11 +112,8 @@ namespace MatterHackers.Plugins.EditorTools
public void Cancel()
{
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem)
{
widthDepthItem.Width = InitialState.Width;
widthDepthItem.Depth = InitialState.Depth;
}
setWidth?.Invoke(InitialState.Width);
setDepth?.Invoke(InitialState.Depth);
setHeight?.Invoke(InitialState.Height);
@ -186,10 +197,10 @@ namespace MatterHackers.Plugins.EditorTools
{
this.context = context;
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem)
if (getWidth != null)
{
InitialState.Width = widthDepthItem.Width;
InitialState.Depth = widthDepthItem.Depth;
InitialState.Width = getWidth();
InitialState.Depth = getDepth();
}
if (getHeight != null)
@ -286,11 +297,8 @@ namespace MatterHackers.Plugins.EditorTools
private void SetItem(IObject3D item, ScaleStates states)
{
if (item is IObjectWithWidthAndDepth widthDepthItem)
{
widthDepthItem.Width = states.Width;
widthDepthItem.Depth = states.Depth;
}
setWidth?.Invoke(states.Width);
setDepth?.Invoke(states.Depth);
setHeight?.Invoke(states.Height);

View file

@ -89,7 +89,7 @@ namespace MatterHackers.Plugins.EditorTools
this.angleOffset = angleOffset;
theme = MatterControl.AppContext.Theme;
scaleController = new ScaleController(getHeight, setHeight, getDiameters, setDiameters);
scaleController = new ScaleController(null, null, null, null, getHeight, setHeight, getDiameters, setDiameters);
diameterValueDisplayInfo = new InlineEditControl()
{

View file

@ -69,6 +69,10 @@ namespace MatterHackers.Plugins.EditorTools
private readonly Func<double> getHeight;
public ScaleHeightControl(IObject3DControlContext context,
Func<double> getWidth,
Action<double> setWidth,
Func<double> getDepth,
Action<double> setDepth,
Func<double> getHeight,
Action<double> setHeight,
List<Func<double>> getDiameters = null,
@ -77,7 +81,7 @@ namespace MatterHackers.Plugins.EditorTools
{
theme = MatterControl.AppContext.Theme;
scaleController = new ScaleController(getHeight, setHeight, getDiameters, setDiameters);
scaleController = new ScaleController(getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters);
this.getHeight = getHeight;
heightValueDisplayInfo = new InlineEditControl()

View file

@ -56,6 +56,10 @@ namespace MatterHackers.Plugins.EditorTools
private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale;
private readonly ThemeConfig theme;
private readonly Func<double> getWidth;
private readonly Action<double> setWidth;
private readonly Func<double> getDepth;
private readonly Action<double> setDepth;
private readonly InlineEditControl xValueDisplayInfo;
@ -70,14 +74,21 @@ namespace MatterHackers.Plugins.EditorTools
private ScaleController scaleController;
public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext,
Func<double> getWidth,
Action<double> setWidth,
Func<double> getDepth,
Action<double> setDepth,
Func<double> getHeight,
Action<double> setHeight,
int quadrant)
: base(object3DControlContext)
{
theme = MatterControl.AppContext.Theme;
scaleController = new ScaleController(getHeight, setHeight);
this.getWidth = getWidth;
this.setWidth = setWidth;
this.getDepth = getDepth;
this.setDepth = setDepth;
scaleController = new ScaleController(getWidth, setWidth, getDepth, setDepth, getHeight, setHeight);
xValueDisplayInfo = new InlineEditControl()
{
@ -321,9 +332,8 @@ namespace MatterHackers.Plugins.EditorTools
{
if (hadClickOnControl)
{
if (RootSelection is IObjectWithWidthAndDepth widthDepthItem
&& (widthDepthItem.Width != scaleController.InitialState.Width
|| widthDepthItem.Depth != scaleController.InitialState.Depth))
if (getWidth() != scaleController.InitialState.Width
|| getDepth() != scaleController.InitialState.Depth)
{
scaleController.EditComplete();
}
@ -504,27 +514,24 @@ namespace MatterHackers.Plugins.EditorTools
}
}
public static void SetWidthDepthUndo(IObject3D selectedItem, UndoBuffer undoBuffer, Vector2 doWidthDepth, Matrix4X4 doMatrix, Vector2 undoWidthDepth, Matrix4X4 undoMatrix)
{
if (selectedItem is IObjectWithWidthAndDepth widthDepthItem)
public void SetWidthDepthUndo(IObject3D selectedItem, UndoBuffer undoBuffer, Vector2 doWidthDepth, Matrix4X4 doMatrix, Vector2 undoWidthDepth, Matrix4X4 undoMatrix)
{
undoBuffer.AddAndDo(new UndoRedoActions(async () =>
{
widthDepthItem.Width = undoWidthDepth.X;
widthDepthItem.Depth = undoWidthDepth.Y;
setWidth(undoWidthDepth.X);
setDepth(undoWidthDepth.Y);
await selectedItem.Rebuild();
selectedItem.Matrix = undoMatrix;
selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
},
async () =>
{
widthDepthItem.Width = doWidthDepth.X;
widthDepthItem.Depth = doWidthDepth.Y;
setWidth(doWidthDepth.X);
setDepth(doWidthDepth.Y);
await selectedItem.Rebuild();
selectedItem.Matrix = doMatrix;
selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues));
}));
}
}
}
}

View file

@ -56,7 +56,8 @@ namespace MatterHackers.Plugins.EditorTools
private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale;
private readonly ThemeConfig theme;
private readonly Func<double> getWidth;
private readonly Func<double> getDepth;
private readonly InlineEditControl xValueDisplayInfo;
private readonly InlineEditControl yValueDisplayInfo;
@ -70,6 +71,10 @@ namespace MatterHackers.Plugins.EditorTools
private ScaleController scaleController;
public ScaleWidthDepthEdgeControl(IObject3DControlContext context,
Func<double> getWidth,
Action<double> setWidth,
Func<double> getDepth,
Action<double> setDepth,
Func<double> getHeight,
Action<double> setHeight,
int edgeIndex)
@ -77,7 +82,9 @@ namespace MatterHackers.Plugins.EditorTools
{
theme = MatterControl.AppContext.Theme;
scaleController = new ScaleController(getHeight, setHeight);
this.getWidth = getWidth;
this.getDepth = getDepth;
scaleController = new ScaleController(getWidth, setWidth, getDepth, setDepth, getHeight, setHeight);
xValueDisplayInfo = new InlineEditControl()
{
@ -320,9 +327,8 @@ namespace MatterHackers.Plugins.EditorTools
{
if (hadClickOnControl)
{
if (RootSelection is IObjectWithWidthAndDepth widthDepthItem
&& (widthDepthItem.Width != scaleController.InitialState.Width
|| widthDepthItem.Depth != scaleController.InitialState.Depth))
if (getWidth() != scaleController.InitialState.Width
|| getDepth() != scaleController.InitialState.Depth)
{
scaleController.EditComplete();
}

View file

@ -43,7 +43,7 @@ using System.Threading.Tasks;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
public class FitToBoundsObject3D_3 : TransformWrapperObject3D, ISelectedEditorDraw, IObjectWithWidthAndDepth
public class FitToBoundsObject3D_3 : TransformWrapperObject3D, ISelectedEditorDraw
{
private Vector3 boundsSize;
private InvalidateType additonalInvalidate;

View file

@ -39,13 +39,15 @@ using System.Threading.Tasks;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.Plugins.EditorTools;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
namespace MatterHackers.MatterControl.DesignTools.Operations
{
[Obsolete("Use ScaleObject3D_3 instead", false)]
public class ScaleObject3D_2 : TransformWrapperObject3D, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker
public class ScaleObject3D_2 : TransformWrapperObject3D, IObject3DControlsProvider, IPropertyGridModifier, IScaleLocker
{
public enum ScaleTypes
{
@ -356,5 +358,27 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public void ScaledProportionally()
{
}
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
var controls = object3DControlsLayer.Object3DControls;
controls.Add(new ScaleHeightControl(object3DControlsLayer,
() => Width,
(width) => Width = width,
() => Depth,
(depth) => Depth = depth,
() => Height,
(height) => Height = height));
object3DControlsLayer.AddWidthDepthControls(() => Width,
(width) => Width = width,
() => Depth,
(depth) => Depth = depth,
() => Height,
(height) => Height = height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
}
}

View file

@ -34,6 +34,8 @@ using System.Threading.Tasks;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.Plugins.EditorTools;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
@ -56,7 +58,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
void ScaledProportionally();
}
public class ScaleObject3D_3 : TransformWrapperObject3D, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker
public class ScaleObject3D_3 : TransformWrapperObject3D, IObject3DControlsProvider, IPropertyGridModifier, IScaleLocker
{
public enum ScaleTypes
{
@ -131,7 +133,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
[MaxDecimalPlaces(3)]
[JsonIgnore]
public double Width
public DoubleConstantOrReference Width
{
get
{
@ -148,14 +150,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
var children = UntransformedChildren;
if (children != null)
{
FixIfLockedProportions(0, value / UntransformedChildren.GetAxisAlignedBoundingBox().XSize);
FixIfLockedProportions(0, value.Value(this) / UntransformedChildren.GetAxisAlignedBoundingBox().XSize);
}
}
}
[MaxDecimalPlaces(3)]
[JsonIgnore]
public double Depth
public DoubleConstantOrReference Depth
{
get
{
@ -172,14 +174,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
var children = UntransformedChildren;
if (children != null)
{
FixIfLockedProportions(1, value / children.GetAxisAlignedBoundingBox().YSize);
FixIfLockedProportions(1, value.Value(this) / children.GetAxisAlignedBoundingBox().YSize);
}
}
}
[MaxDecimalPlaces(3)]
[JsonIgnore]
public double Height
public DoubleConstantOrReference Height
{
get
{
@ -196,7 +198,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
var children = UntransformedChildren;
if (children != null)
{
FixIfLockedProportions(2, value / children.GetAxisAlignedBoundingBox().ZSize);
FixIfLockedProportions(2, value.Value(this) / children.GetAxisAlignedBoundingBox().ZSize);
}
}
}
@ -456,5 +458,27 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
this.UpdateControls(new PublicPropertyChange(change.Context, "Rebuild_On_Scale"));
}
}
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
var controls = object3DControlsLayer.Object3DControls;
controls.Add(new ScaleHeightControl(object3DControlsLayer,
() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
}
}

View file

@ -116,6 +116,10 @@ namespace MatterHackers.MatterControl.DesignTools
setDiameters,
0));
object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer,
null,
null,
null,
null,
getHeight,
setHeight,
getDiameters,

View file

@ -27,7 +27,6 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
@ -81,13 +80,24 @@ namespace MatterHackers.MatterControl.DesignTools
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
double getHeight() => Height.Value(this);
void setHeight(double height) => Height = height;
var controls = object3DControlsLayer.Object3DControls;
controls.Add(new ScaleHeightControl(object3DControlsLayer, getHeight, setHeight));
object3DControlsLayer.AddWidthDepthControls(getHeight, setHeight);
controls.Add(new ScaleHeightControl(object3DControlsLayer,
() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
public override async void OnInvalidate(InvalidateArgs invalidateType)
@ -119,10 +129,4 @@ namespace MatterHackers.MatterControl.DesignTools
return Task.CompletedTask;
}
}
public interface IObjectWithWidthAndDepth
{
double Width { get; set; }
double Depth { get; set; }
}
}

View file

@ -120,10 +120,10 @@ namespace MatterHackers.MatterControl.DesignTools
[MaxDecimalPlaces(2)]
[Description("The width from one side to the opposite side.")]
public double Diameter { get; set; } = 20;
public DoubleConstantOrReference Diameter { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Height { get; set; } = 20;
public DoubleConstantOrReference Height { get; set; } = 20;
[Description("The number of segments around the perimeter.")]
public int Sides { get; set; } = 40;
@ -135,18 +135,18 @@ namespace MatterHackers.MatterControl.DesignTools
public string EasyModeMessage { get; set; } = "You can switch to Advanced mode to get more cylinder options.";
[MaxDecimalPlaces(2)]
public double StartingAngle { get; set; } = 0;
public DoubleConstantOrReference StartingAngle { get; set; } = 0;
[MaxDecimalPlaces(2)]
public double EndingAngle { get; set; } = 360;
public DoubleConstantOrReference EndingAngle { get; set; } = 360;
[MaxDecimalPlaces(2)]
public double DiameterTop { get; set; } = 20;
public DoubleConstantOrReference DiameterTop { get; set; } = 20;
public override async void OnInvalidate(InvalidateArgs invalidateType)
{
if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties)
&& invalidateType.Source == this)
if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateType.Source == this)
|| invalidateType.InvalidateType.HasFlag(InvalidateType.SheetUpdated))
{
await Rebuild();
}
@ -161,11 +161,14 @@ namespace MatterHackers.MatterControl.DesignTools
this.DebugDepth("Rebuild");
bool valuesChanged = false;
var height = Height.Value(this);
var diameter = Diameter.Value(this);
var diameterTop = DiameterTop.Value(this);
Sides = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
Height = agg_basics.Clamp(Height, .01, 1000000, ref valuesChanged);
Diameter = agg_basics.Clamp(Diameter, .01, 1000000, ref valuesChanged);
StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
EndingAngle = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);
height = agg_basics.Clamp(height, .01, 1000000, ref valuesChanged);
diameter = agg_basics.Clamp(diameter, .01, 1000000, ref valuesChanged);
var startingAngle = agg_basics.Clamp(StartingAngle.Value(this), 0, 360 - .01, ref valuesChanged);
var endingAngle = agg_basics.Clamp(EndingAngle.Value(this), StartingAngle.Value(this) + .01, 360, ref valuesChanged);
if (valuesChanged)
{
@ -179,22 +182,22 @@ namespace MatterHackers.MatterControl.DesignTools
if (!Advanced)
{
var path = new VertexStorage();
path.MoveTo(0, -Height / 2);
path.LineTo(Diameter / 2, -Height / 2);
path.LineTo(Diameter / 2, Height / 2);
path.LineTo(0, Height / 2);
path.MoveTo(0, -height / 2);
path.LineTo(diameter / 2, -height / 2);
path.LineTo(diameter / 2, height / 2);
path.LineTo(0, height / 2);
Mesh = VertexSourceToMesh.Revolve(path, Sides);
}
else
{
var path = new VertexStorage();
path.MoveTo(0, -Height / 2);
path.LineTo(Diameter / 2, -Height / 2);
path.LineTo(DiameterTop / 2, Height / 2);
path.LineTo(0, Height / 2);
path.MoveTo(0, -height / 2);
path.LineTo(diameter / 2, -height / 2);
path.LineTo(diameterTop / 2, height / 2);
path.LineTo(0, height / 2);
Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(StartingAngle), MathHelper.DegreesToRadians(EndingAngle));
Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(startingAngle), MathHelper.DegreesToRadians(endingAngle));
}
}
}
@ -225,9 +228,9 @@ namespace MatterHackers.MatterControl.DesignTools
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
double getHeight() => Height;
double getHeight() => Height.Value(this);
void setHeight(double height) => Height = height;
var getDiameters = new List<Func<double>>() { () => Diameter, () => DiameterTop };
var getDiameters = new List<Func<double>>() { () => Diameter.Value(this), () => DiameterTop.Value(this) };
var setDiameters = new List<Action<double>>() { (diameter) => Diameter = diameter, (diameter) => DiameterTop = diameter };
object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer,
getHeight,
@ -245,6 +248,10 @@ namespace MatterHackers.MatterControl.DesignTools
ObjectSpace.Placement.Top,
controlVisible: () => Advanced));
object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer,
null,
null,
null,
null,
getHeight,
setHeight,
getDiameters,

View file

@ -38,7 +38,7 @@ using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class HalfCylinderObject3D : PrimitiveObject3D, IObject3DControlsProvider, IObjectWithWidthAndDepth
public class HalfCylinderObject3D : PrimitiveObject3D, IObject3DControlsProvider
{
public HalfCylinderObject3D()
{
@ -57,10 +57,10 @@ namespace MatterHackers.MatterControl.DesignTools
}
[MaxDecimalPlaces(2)]
public double Width { get; set; } = 20;
public DoubleConstantOrReference Width { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Depth { get; set; } = 20;
public DoubleConstantOrReference Depth { get; set; } = 20;
[MaxDecimalPlaces(2)]
public int Sides { get; set; } = 20;
@ -89,15 +89,15 @@ namespace MatterHackers.MatterControl.DesignTools
using (new CenterAndHeightMaintainer(this))
{
var path = new VertexStorage();
path.MoveTo(Width / 2, 0);
path.MoveTo(Width.Value(this) / 2, 0);
for (int i = 1; i < Sides; i++)
{
var angle = MathHelper.Tau * i / 2 / (Sides - 1);
path.LineTo(Math.Cos(angle) * Width / 2, Math.Sin(angle) * Width / 2);
path.LineTo(Math.Cos(angle) * Width.Value(this) / 2, Math.Sin(angle) * Width.Value(this) / 2);
}
var mesh = VertexSourceToMesh.Extrude(path, Depth);
var mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
Mesh = mesh;
}
@ -114,7 +114,15 @@ namespace MatterHackers.MatterControl.DesignTools
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
object3DControlsLayer.AddWidthDepthControls(null, null);
var controls = object3DControlsLayer.Object3DControls;
object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
null,
null);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}

View file

@ -31,11 +31,13 @@ using System.Threading.Tasks;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.Plugins.EditorTools;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class HalfWedgeObject3D : PrimitiveObject3D, IObjectWithWidthAndDepth
public class HalfWedgeObject3D : PrimitiveObject3D, IObject3DControlsProvider
{
public HalfWedgeObject3D()
{
@ -54,13 +56,13 @@ namespace MatterHackers.MatterControl.DesignTools
}
[MaxDecimalPlaces(2)]
public double Width { get; set; } = 20;
public DoubleConstantOrReference Width { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Depth { get; set; } = 20;
public DoubleConstantOrReference Depth { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Height { get; set; } = 10;
public DoubleConstantOrReference Height { get; set; } = 10;
public override async void OnInvalidate(InvalidateArgs invalidateType)
{
@ -84,10 +86,10 @@ namespace MatterHackers.MatterControl.DesignTools
{
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Width, 0);
path.LineTo(Width / 2, Height);
path.LineTo(Width.Value(this), 0);
path.LineTo(Width.Value(this) / 2, Height.Value(this));
var mesh = VertexSourceToMesh.Extrude(path, Depth);
var mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
Mesh = mesh;
}
@ -96,5 +98,27 @@ namespace MatterHackers.MatterControl.DesignTools
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
return Task.CompletedTask;
}
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
var controls = object3DControlsLayer.Object3DControls;
controls.Add(new ScaleHeightControl(object3DControlsLayer,
() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
}
}

View file

@ -32,11 +32,13 @@ using System.Threading.Tasks;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.Plugins.EditorTools;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class PyramidObject3D : PrimitiveObject3D, IObjectWithWidthAndDepth
public class PyramidObject3D : PrimitiveObject3D, IObject3DControlsProvider
{
public PyramidObject3D()
{
@ -55,13 +57,13 @@ namespace MatterHackers.MatterControl.DesignTools
}
[MaxDecimalPlaces(2)]
public double Width { get; set; } = 20;
public DoubleConstantOrReference Width { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Depth { get; set; } = 20;
public DoubleConstantOrReference Depth { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Height { get; set; } = 20;
public DoubleConstantOrReference Height { get; set; } = 20;
public override async void OnInvalidate(InvalidateArgs invalidateType)
{
@ -86,10 +88,10 @@ namespace MatterHackers.MatterControl.DesignTools
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Math.Sqrt(2) * 100, 0);
path.LineTo(0, Height * 100);
path.LineTo(0, Height.Value(this) * 100);
var mesh = VertexSourceToMesh.Revolve(path, 4);
mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2 / 100.0, Depth / 2 / 100.0, 1 / 100.0));
mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width.Value(this) / 2 / 100.0, Depth.Value(this) / 2 / 100.0, 1 / 100.0));
Mesh = mesh;
}
}
@ -97,5 +99,27 @@ namespace MatterHackers.MatterControl.DesignTools
Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
return Task.CompletedTask;
}
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
var controls = object3DControlsLayer.Object3DControls;
controls.Add(new ScaleHeightControl(object3DControlsLayer,
() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
}
}

View file

@ -178,6 +178,10 @@ namespace MatterHackers.MatterControl.DesignTools
1,
angleOffset: -MathHelper.Tau / 32));
object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer,
null,
null,
null,
null,
getHeight,
setHeight,
getDiameters,

View file

@ -34,11 +34,13 @@ using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.Plugins.EditorTools;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.DesignTools
{
public class WedgeObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithWidthAndDepth
public class WedgeObject3D : PrimitiveObject3D, IPropertyGridModifier, IObject3DControlsProvider
{
public WedgeObject3D()
{
@ -57,13 +59,13 @@ namespace MatterHackers.MatterControl.DesignTools
}
[MaxDecimalPlaces(2)]
public double Width { get; set; } = 20;
public DoubleConstantOrReference Width { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Depth { get; set; } = 20;
public DoubleConstantOrReference Depth { get; set; } = 20;
[MaxDecimalPlaces(2)]
public double Height { get; set; } = 20;
public DoubleConstantOrReference Height { get; set; } = 20;
public bool Round { get; set; } = false;
@ -100,7 +102,7 @@ namespace MatterHackers.MatterControl.DesignTools
{
var path = new VertexStorage();
path.MoveTo(0, 0);
path.LineTo(Width, 0);
path.LineTo(Width.Value(this), 0);
if (Round)
{
@ -109,13 +111,13 @@ namespace MatterHackers.MatterControl.DesignTools
{
var angle = range / (RoundSegments - 1) * i;
var rad = MathHelper.DegreesToRadians(angle);
path.LineTo(Width - Math.Sin(rad) * Width, Height - Math.Cos(rad) * Height);
path.LineTo(Width.Value(this) - Math.Sin(rad) * Width.Value(this), Height.Value(this) - Math.Cos(rad) * Height.Value(this));
}
}
path.LineTo(0, Height);
path.LineTo(0, Height.Value(this));
Mesh = VertexSourceToMesh.Extrude(path, Depth);
Mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this));
Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4));
}
}
@ -132,5 +134,27 @@ namespace MatterHackers.MatterControl.DesignTools
segmentsWidget.Visible = Round;
}
}
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
{
var controls = object3DControlsLayer.Object3DControls;
controls.Add(new ScaleHeightControl(object3DControlsLayer,
() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height));
object3DControlsLayer.AddWidthDepthControls(() => Width.Value(this),
(width) => Width = width,
() => Depth.Value(this),
(depth) => Depth = depth,
() => Height.Value(this),
(height) => Height = height);
object3DControlsLayer.AddControls(ControlTypes.MoveInZ);
object3DControlsLayer.AddControls(ControlTypes.RotateXYZ);
}
}
}

View file

@ -207,12 +207,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnDraw(graphics2D);
}
public void AddWidthDepthControls(Func<double> getHeight, Action<double> setHeight)
public void AddWidthDepthControls(Func<double> getWidth,
Action<double> setWidth,
Func<double> getDepth,
Action<double> setDepth,
Func<double> getHeight,
Action<double> setHeight)
{
for (int i = 0; i < 4; i++)
{
Object3DControls.Add(new ScaleWidthDepthCornerControl(this, getHeight, setHeight, i));
Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, getHeight, setHeight, i));
Object3DControls.Add(new ScaleWidthDepthCornerControl(this, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, i));
Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, i));
}
}