From abe5d17012a90537dd2b7c095fd12bb3f98ecb99 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Mon, 31 May 2021 16:12:07 -0700 Subject: [PATCH] Made width depth scale controls work with variables --- .../ScaleControls/ScaleController.cs | 44 +++++++++------ .../ScaleControls/ScaleDiameterControl.cs | 2 +- .../ScaleControls/ScaleHeightControl.cs | 6 +- .../ScaleWidthDepthCornerControl.cs | 55 +++++++++++-------- .../ScaleWidthDepthEdgeControl.cs | 16 ++++-- .../Operations/FitToBoundsObject3D_3.cs | 2 +- .../DesignTools/Operations/ScaleObject3D_2.cs | 26 ++++++++- .../DesignTools/Operations/ScaleObject3D_3.cs | 38 ++++++++++--- .../DesignTools/Primitives/ConeObject3D.cs | 4 ++ .../DesignTools/Primitives/CubeObject3D.cs | 28 ++++++---- .../Primitives/CylinderObject3D.cs | 51 +++++++++-------- .../Primitives/HalfCylinderObject3D.cs | 22 +++++--- .../Primitives/HalfWedgeObject3D.cs | 38 ++++++++++--- .../DesignTools/Primitives/PyramidObject3D.cs | 36 ++++++++++-- .../DesignTools/Primitives/RingObject3D.cs | 4 ++ .../DesignTools/Primitives/WedgeObject3D.cs | 40 +++++++++++--- .../View3D/Object3DControlsLayer.cs | 11 +++- 17 files changed, 300 insertions(+), 123 deletions(-) diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs index 36884d221..da6895559 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs @@ -49,20 +49,34 @@ namespace MatterHackers.Plugins.EditorTools private List> getDiameters; private List> setDiameters; + private Func getWidth; + private Action setWidth; + private Func getDepth; + private Action setDepth; private Func getHeight; private Action setHeight; - public ScaleController(Func getHeight, + public ScaleController(Func getWidth, + Action setWidth, + Func getDepth, + Action setDepth, + Func getHeight, Action setHeight, List> getDiameters = null, List> 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); diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs index 0f77b37b9..f6e7a776a 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs @@ -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() { diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs index 87e900cf2..d08cd742c 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs @@ -69,6 +69,10 @@ namespace MatterHackers.Plugins.EditorTools private readonly Func getHeight; public ScaleHeightControl(IObject3DControlContext context, + Func getWidth, + Action setWidth, + Func getDepth, + Action setDepth, Func getHeight, Action setHeight, List> 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() diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs index cd02998e0..8cee63763 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs @@ -56,6 +56,10 @@ namespace MatterHackers.Plugins.EditorTools private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale; private readonly ThemeConfig theme; + private readonly Func getWidth; + private readonly Action setWidth; + private readonly Func getDepth; + private readonly Action setDepth; private readonly InlineEditControl xValueDisplayInfo; @@ -70,14 +74,21 @@ namespace MatterHackers.Plugins.EditorTools private ScaleController scaleController; public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, + Func getWidth, + Action setWidth, + Func getDepth, + Action setDepth, Func getHeight, Action 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) + public void SetWidthDepthUndo(IObject3D selectedItem, UndoBuffer undoBuffer, Vector2 doWidthDepth, Matrix4X4 doMatrix, Vector2 undoWidthDepth, Matrix4X4 undoMatrix) { - if (selectedItem is IObjectWithWidthAndDepth widthDepthItem) + undoBuffer.AddAndDo(new UndoRedoActions(async () => { - undoBuffer.AddAndDo(new UndoRedoActions(async () => - { - widthDepthItem.Width = undoWidthDepth.X; - widthDepthItem.Depth = undoWidthDepth.Y; - await selectedItem.Rebuild(); - selectedItem.Matrix = undoMatrix; - selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues)); - }, - async () => - { - widthDepthItem.Width = doWidthDepth.X; - widthDepthItem.Depth = doWidthDepth.Y; - await selectedItem.Rebuild(); - selectedItem.Matrix = doMatrix; - selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues)); - })); - } + setWidth(undoWidthDepth.X); + setDepth(undoWidthDepth.Y); + await selectedItem.Rebuild(); + selectedItem.Matrix = undoMatrix; + selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues)); + }, + async () => + { + setWidth(doWidthDepth.X); + setDepth(doWidthDepth.Y); + await selectedItem.Rebuild(); + selectedItem.Matrix = doMatrix; + selectedItem?.Invalidate(new InvalidateArgs(selectedItem, InvalidateType.DisplayValues)); + })); } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs index c7e828752..fa191a57f 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs @@ -56,7 +56,8 @@ namespace MatterHackers.Plugins.EditorTools private readonly double selectCubeSize = 7 * GuiWidget.DeviceScale; private readonly ThemeConfig theme; - + private readonly Func getWidth; + private readonly Func 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 getWidth, + Action setWidth, + Func getDepth, + Action setDepth, Func getHeight, Action 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(); } diff --git a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_3.cs b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_3.cs index 8385181ee..bf2fa6373 100644 --- a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_3.cs +++ b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_3.cs @@ -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; diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs index f59e73283..9802d65ee 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs @@ -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); + } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs index 7b95125e3..5255ea102 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs @@ -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); + } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs b/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs index 23f416470..21b55d34a 100644 --- a/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs @@ -116,6 +116,10 @@ namespace MatterHackers.MatterControl.DesignTools setDiameters, 0)); object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer, + null, + null, + null, + null, getHeight, setHeight, getDiameters, diff --git a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs index cdcc1c664..d5e77f11e 100644 --- a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs @@ -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; } - } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs index 5f7a1776e..a03ef3c27 100644 --- a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs @@ -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>() { () => Diameter, () => DiameterTop }; + var getDiameters = new List>() { () => Diameter.Value(this), () => DiameterTop.Value(this) }; var setDiameters = new List>() { (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, diff --git a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs index faab801ab..672ddd490 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs @@ -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); } diff --git a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs index 8ce9c8e30..6d22ed7c6 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs @@ -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); + } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs index dbad5aa02..e3eefde44 100644 --- a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs @@ -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); + } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Primitives/RingObject3D.cs b/MatterControlLib/DesignTools/Primitives/RingObject3D.cs index cf8d793d9..66dc411b4 100644 --- a/MatterControlLib/DesignTools/Primitives/RingObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/RingObject3D.cs @@ -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, diff --git a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs index 7340cf62d..7842fd567 100644 --- a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs @@ -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); + } } } \ No newline at end of file diff --git a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs index 24d7d6498..a1a21c547 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs @@ -207,12 +207,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow base.OnDraw(graphics2D); } - public void AddWidthDepthControls(Func getHeight, Action setHeight) + public void AddWidthDepthControls(Func getWidth, + Action setWidth, + Func getDepth, + Action setDepth, + Func getHeight, + Action 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)); } }