From 4f3a241e866b575ed90c468bad4898f5b2a0dc7e Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 29 May 2021 22:21:50 -0700 Subject: [PATCH] The beginning of variable support --- .../ScaleControls/ScaleController.cs | 24 +++--- .../ScaleControls/ScaleDiameterControl.cs | 4 +- .../ScaleControls/ScaleHeightControl.cs | 23 +++--- .../ScaleWidthDepthCornerControl.cs | 9 ++- .../ScaleWidthDepthEdgeControl.cs | 9 ++- .../Operations/FitToBoundsObject3D_3.cs | 2 +- .../DesignTools/Operations/ScaleObject3D_2.cs | 2 +- .../DesignTools/Operations/ScaleObject3D_3.cs | 2 +- .../DesignTools/Primitives/ConeObject3D.cs | 8 +- .../DesignTools/Primitives/CubeObject3D.cs | 78 ++++++++++++++++--- .../Primitives/CylinderObject3D.cs | 10 ++- .../Primitives/HalfCylinderObject3D.cs | 2 +- .../Primitives/HalfSphereObject3D.cs | 2 + .../Primitives/HalfWedgeObject3D.cs | 2 +- .../DesignTools/Primitives/PyramidObject3D.cs | 2 +- .../DesignTools/Primitives/RingObject3D.cs | 10 ++- .../DesignTools/Primitives/SphereObject3D.cs | 2 + .../DesignTools/Primitives/TextObject3D.cs | 2 +- .../DesignTools/Primitives/TorusObject3D.cs | 4 + .../DesignTools/Primitives/WedgeObject3D.cs | 2 +- .../DesignTools/PublicPropertyEditor.cs | 23 ++++++ .../View3D/Object3DControlsLayer.cs | 50 ++++-------- 22 files changed, 187 insertions(+), 85 deletions(-) diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs index d935043eb..36884d221 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleController.cs @@ -49,12 +49,20 @@ namespace MatterHackers.Plugins.EditorTools private List> getDiameters; private List> setDiameters; + private Func getHeight; + private Action setHeight; - public ScaleController(List> getDiameters = null, List> setDiameters = null) + public ScaleController(Func getHeight, + Action setHeight, + List> getDiameters = null, + List> setDiameters = null) { this.getDiameters = getDiameters; this.setDiameters = setDiameters; + this.getHeight = getHeight; + this.setHeight = setHeight; + if (getDiameters != null) { for (int i = 0; i < getDiameters.Count; i++) @@ -96,10 +104,7 @@ namespace MatterHackers.Plugins.EditorTools widthDepthItem.Depth = InitialState.Depth; } - if (selectedItem is IObjectWithHeight heightItem) - { - heightItem.Height= InitialState.Height; - } + setHeight?.Invoke(InitialState.Height); if (setDiameters != null) { @@ -187,9 +192,9 @@ namespace MatterHackers.Plugins.EditorTools InitialState.Depth = widthDepthItem.Depth; } - if (selectedItem is IObjectWithHeight heightItem) + if (getHeight != null) { - InitialState.Height = heightItem.Height; + InitialState.Height = getHeight(); } if (getDiameters != null) @@ -287,10 +292,7 @@ namespace MatterHackers.Plugins.EditorTools widthDepthItem.Depth = states.Depth; } - if (item is IObjectWithHeight heightItem) - { - heightItem.Height = states.Height; - } + setHeight?.Invoke(states.Height); if (setDiameters != null) { diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs index 81a3e1fb6..0f77b37b9 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs @@ -72,6 +72,8 @@ namespace MatterHackers.Plugins.EditorTools private readonly double angleOffset; public ScaleDiameterControl(IObject3DControlContext context, + Func getHeight, + Action setHeight, List> getDiameters, List> setDiameters, int diameterIndex, @@ -87,7 +89,7 @@ namespace MatterHackers.Plugins.EditorTools this.angleOffset = angleOffset; theme = MatterControl.AppContext.Theme; - scaleController = new ScaleController(getDiameters, setDiameters); + scaleController = new ScaleController(getHeight, setHeight, getDiameters, setDiameters); diameterValueDisplayInfo = new InlineEditControl() { diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs index f6b353d07..87e900cf2 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs @@ -66,14 +66,20 @@ namespace MatterHackers.Plugins.EditorTools private Vector3 originalPointToMove; private ScaleController scaleController; + private readonly Func getHeight; - public ScaleHeightControl(IObject3DControlContext context, List> getDiameters = null, List> setDiameters = null) + public ScaleHeightControl(IObject3DControlContext context, + Func getHeight, + Action setHeight, + List> getDiameters = null, + List> setDiameters = null) : base(context) { theme = MatterControl.AppContext.Theme; - scaleController = new ScaleController(getDiameters, setDiameters); - + scaleController = new ScaleController(getHeight, setHeight, getDiameters, setDiameters); + this.getHeight = getHeight; + heightValueDisplayInfo = new InlineEditControl() { ForceHide = () => @@ -335,11 +341,7 @@ namespace MatterHackers.Plugins.EditorTools { if (MouseDownOnControl) { - if (activeSelectedItem is IObjectWithHeight heightObject - && heightObject.Height != scaleController.InitialState.Height) - { - scaleController.EditComplete(); - } + scaleController.EditComplete(); Object3DControlContext.Scene.ShowSelectionShadow = true; } @@ -405,10 +407,7 @@ namespace MatterHackers.Plugins.EditorTools int j = 0; Vector2 heightDisplayCenter = (((lines[j] + lines[j + 1]) / 2) + ((lines[j + 2] + lines[j + 3]) / 2)) / 2; - if (activeSelectedItem is IObjectWithHeight heightObject) - { - heightValueDisplayInfo.Value = heightObject.Height; - } + heightValueDisplayInfo.Value = getHeight(); heightValueDisplayInfo.OriginRelativeParent = heightDisplayCenter + new Vector2(10, -heightValueDisplayInfo.LocalBounds.Center.Y); } diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs index 650b22c63..cd02998e0 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs @@ -67,13 +67,18 @@ namespace MatterHackers.Plugins.EditorTools private Vector3 initialHitPosition; - private ScaleController scaleController = new ScaleController(); + private ScaleController scaleController; - public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, int quadrant) + public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, + Func getHeight, + Action setHeight, + int quadrant) : base(object3DControlContext) { theme = MatterControl.AppContext.Theme; + scaleController = new ScaleController(getHeight, setHeight); + xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs index dadcc1988..c7e828752 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs @@ -67,13 +67,18 @@ namespace MatterHackers.Plugins.EditorTools private Vector3 initialHitPosition; - private ScaleController scaleController = new ScaleController(); + private ScaleController scaleController; - public ScaleWidthDepthEdgeControl(IObject3DControlContext context, int edgeIndex) + public ScaleWidthDepthEdgeControl(IObject3DControlContext context, + Func getHeight, + Action setHeight, + int edgeIndex) : base(context) { theme = MatterControl.AppContext.Theme; + scaleController = new ScaleController(getHeight, setHeight); + xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, diff --git a/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_3.cs b/MatterControlLib/DesignTools/Operations/FitToBoundsObject3D_3.cs index 2c719cf77..8385181ee 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, IObjectWithHeight + public class FitToBoundsObject3D_3 : TransformWrapperObject3D, ISelectedEditorDraw, IObjectWithWidthAndDepth { private Vector3 boundsSize; private InvalidateType additonalInvalidate; diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs index 5d8049e28..f59e73283 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D_2.cs @@ -45,7 +45,7 @@ using Newtonsoft.Json; namespace MatterHackers.MatterControl.DesignTools.Operations { [Obsolete("Use ScaleObject3D_3 instead", false)] - public class ScaleObject3D_2 : TransformWrapperObject3D, IObjectWithHeight, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker + public class ScaleObject3D_2 : TransformWrapperObject3D, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker { public enum ScaleTypes { diff --git a/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs b/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs index 96df20fe1..7b95125e3 100644 --- a/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs +++ b/MatterControlLib/DesignTools/Operations/ScaleObject3D_3.cs @@ -56,7 +56,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations void ScaledProportionally(); } - public class ScaleObject3D_3 : TransformWrapperObject3D, IObjectWithHeight, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker + public class ScaleObject3D_3 : TransformWrapperObject3D, IObjectWithWidthAndDepth, IPropertyGridModifier, IScaleLocker { public enum ScaleTypes { diff --git a/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs b/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs index 353acaa22..23f416470 100644 --- a/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/ConeObject3D.cs @@ -39,7 +39,7 @@ using MatterHackers.Plugins.EditorTools; namespace MatterHackers.MatterControl.DesignTools { - public class ConeObject3D : PrimitiveObject3D, IObjectWithHeight, IObject3DControlsProvider + public class ConeObject3D : PrimitiveObject3D, IObject3DControlsProvider { public ConeObject3D() { @@ -105,13 +105,19 @@ namespace MatterHackers.MatterControl.DesignTools public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer) { + double getHeight() => Height; + void setHeight(double height) => Height = height; var getDiameters = new List>() { () => Diameter }; var setDiameters = new List>() { (diameter) => Diameter = diameter }; object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters, 0)); object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters)); object3DControlsLayer.AddControls(ControlTypes.MoveInZ); diff --git a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs index f499543f7..4e1c65497 100644 --- a/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CubeObject3D.cs @@ -27,14 +27,63 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; +using System.ComponentModel; +using System.Text.Json.Serialization; using System.Threading.Tasks; using MatterHackers.DataConverters3D; using MatterHackers.Localizations; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.Plugins.EditorTools; using MatterHackers.PolygonMesh; namespace MatterHackers.MatterControl.DesignTools { - public class CubeObject3D : PrimitiveObject3D, IObjectWithHeight, IObjectWithWidthAndDepth + [TypeConverter(typeof(DoubleExpresion))] + public class DoubleExpresion + { + public string Expresion { get; set; } + + public double Value(IObject3D owner) + { + if (double.TryParse(Expresion, out double result)) + { + return result; + } + + return SheetObject3D.FindTableAndValue(owner, Expresion); + } + + public DoubleExpresion(double value) + { + Expresion = value.ToString(); + } + + public DoubleExpresion(string value) + { + Expresion = value; + } + + public static implicit operator DoubleExpresion(double value) + { + return new DoubleExpresion(value); + } + + public static implicit operator DoubleExpresion(string value) + { + return new DoubleExpresion(value); + } + } + + public class SheetObject3D : Object3D + { + public static T FindTableAndValue(IObject3D owner, string expresion) + { + throw new NotImplementedException(); + } + } + + public class CubeObject3D : PrimitiveObject3D, IObject3DControlsProvider { public CubeObject3D() { @@ -44,14 +93,17 @@ namespace MatterHackers.MatterControl.DesignTools public override string ThumbnailName => "Cube"; + /// + /// This is the actual serialized with that can use expressions + /// [MaxDecimalPlaces(2)] - public double Width { get; set; } = 20; + public DoubleExpresion Width { get; set; } = 20; [MaxDecimalPlaces(2)] - public double Depth { get; set; } = 20; + public DoubleExpresion Depth { get; set; } = 20; [MaxDecimalPlaces(2)] - public double Height { get; set; } = 20; + public DoubleExpresion Height { get; set; } = 20; public static async Task Create() { @@ -73,6 +125,17 @@ namespace MatterHackers.MatterControl.DesignTools return item; } + 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); + } + public override async void OnInvalidate(InvalidateArgs invalidateType) { if (invalidateType.InvalidateType.HasFlag(InvalidateType.Properties) @@ -94,7 +157,7 @@ namespace MatterHackers.MatterControl.DesignTools { using (new CenterAndHeightMaintainer(this)) { - Mesh = PlatonicSolids.CreateCube(Width, Depth, Height); + Mesh = PlatonicSolids.CreateCube(Width.Value(this), Depth.Value(this), Height.Value(this)); } } @@ -103,11 +166,6 @@ namespace MatterHackers.MatterControl.DesignTools } } - public interface IObjectWithHeight - { - double Height { get; set; } - } - public interface IObjectWithWidthAndDepth { double Width { get; set; } diff --git a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs index c915e3c70..5f7a1776e 100644 --- a/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/CylinderObject3D.cs @@ -43,7 +43,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools { - public class CylinderObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithHeight, IObject3DControlsProvider + public class CylinderObject3D : PrimitiveObject3D, IPropertyGridModifier, IObject3DControlsProvider { public CylinderObject3D() { @@ -225,20 +225,28 @@ namespace MatterHackers.MatterControl.DesignTools public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer) { + double getHeight() => Height; + void setHeight(double height) => Height = height; var getDiameters = new List>() { () => Diameter, () => DiameterTop }; var setDiameters = new List>() { (diameter) => Diameter = diameter, (diameter) => DiameterTop = diameter }; object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters, 0, controlVisible: () => true)); object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters, 1, ObjectSpace.Placement.Top, controlVisible: () => Advanced)); object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters)); object3DControlsLayer.AddControls(ControlTypes.MoveInZ); diff --git a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs index e0815dc75..faab801ab 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfCylinderObject3D.cs @@ -114,7 +114,7 @@ namespace MatterHackers.MatterControl.DesignTools public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer) { - object3DControlsLayer.AddControls(ControlTypes.ScaleWidthDepth); + object3DControlsLayer.AddWidthDepthControls(null, null); object3DControlsLayer.AddControls(ControlTypes.MoveInZ); object3DControlsLayer.AddControls(ControlTypes.RotateXYZ); } diff --git a/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs index e40467ddd..b507e6843 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfSphereObject3D.cs @@ -135,6 +135,8 @@ namespace MatterHackers.MatterControl.DesignTools public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer) { object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + null, + null, new List>() { () => Diameter }, new List>() { (diameter) => Diameter = diameter }, 0)); diff --git a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs index 55aa2a797..8ce9c8e30 100644 --- a/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/HalfWedgeObject3D.cs @@ -35,7 +35,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools { - public class HalfWedgeObject3D : PrimitiveObject3D, IObjectWithHeight, IObjectWithWidthAndDepth + public class HalfWedgeObject3D : PrimitiveObject3D, IObjectWithWidthAndDepth { public HalfWedgeObject3D() { diff --git a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs index 42ade25a1..dbad5aa02 100644 --- a/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/PyramidObject3D.cs @@ -36,7 +36,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools { - public class PyramidObject3D : PrimitiveObject3D, IObjectWithHeight, IObjectWithWidthAndDepth + public class PyramidObject3D : PrimitiveObject3D, IObjectWithWidthAndDepth { public PyramidObject3D() { diff --git a/MatterControlLib/DesignTools/Primitives/RingObject3D.cs b/MatterControlLib/DesignTools/Primitives/RingObject3D.cs index 530373d9d..cf8d793d9 100644 --- a/MatterControlLib/DesignTools/Primitives/RingObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/RingObject3D.cs @@ -41,7 +41,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools { - public class RingObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithHeight, IObject3DControlsProvider + public class RingObject3D : PrimitiveObject3D, IPropertyGridModifier, IObject3DControlsProvider { public RingObject3D() { @@ -160,18 +160,26 @@ namespace MatterHackers.MatterControl.DesignTools public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer) { + double getHeight() => Height; + void setHeight(double height) => Height = height; var getDiameters = new List>() { () => OuterDiameter, () => InnerDiameter }; var setDiameters = new List>() { (diameter) => OuterDiameter = diameter, (diameter) => InnerDiameter = diameter }; object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters, 0)); object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters, 1, angleOffset: -MathHelper.Tau / 32)); object3DControlsLayer.Object3DControls.Add(new ScaleHeightControl(object3DControlsLayer, + getHeight, + setHeight, getDiameters, setDiameters)); object3DControlsLayer.AddControls(ControlTypes.MoveInZ); diff --git a/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs b/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs index 02f353552..462157ebc 100644 --- a/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/SphereObject3D.cs @@ -189,6 +189,8 @@ namespace MatterHackers.MatterControl.DesignTools public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer) { object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + null, + null, new List>() { () => Diameter }, new List>() { (diameter) => Diameter = diameter }, 0, diff --git a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs index 67b060b06..126c4c693 100644 --- a/MatterControlLib/DesignTools/Primitives/TextObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TextObject3D.cs @@ -46,7 +46,7 @@ using Newtonsoft.Json.Converters; namespace MatterHackers.MatterControl.DesignTools { [HideChildrenFromTreeView] - public class TextObject3D : Object3D, IObjectWithHeight + public class TextObject3D : Object3D { public TextObject3D() { diff --git a/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs b/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs index 5c5d1b0b1..f5165efee 100644 --- a/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/TorusObject3D.cs @@ -170,11 +170,15 @@ namespace MatterHackers.MatterControl.DesignTools var getDiameters = new List>() { () => OuterDiameter, () => InnerDiameter }; var setDiameters = new List>() { (diameter) => OuterDiameter = diameter, (diameter) => InnerDiameter = diameter }; object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + null, + null, getDiameters, setDiameters, 0, ObjectSpace.Placement.Center)); object3DControlsLayer.Object3DControls.Add(new ScaleDiameterControl(object3DControlsLayer, + null, + null, getDiameters, setDiameters, 1, diff --git a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs index ebf208990..7340cf62d 100644 --- a/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/WedgeObject3D.cs @@ -38,7 +38,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.DesignTools { - public class WedgeObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithHeight, IObjectWithWidthAndDepth + public class WedgeObject3D : PrimitiveObject3D, IPropertyGridModifier, IObjectWithWidthAndDepth { public WedgeObject3D() { diff --git a/MatterControlLib/DesignTools/PublicPropertyEditor.cs b/MatterControlLib/DesignTools/PublicPropertyEditor.cs index e4e411e6a..5697f7ad3 100644 --- a/MatterControlLib/DesignTools/PublicPropertyEditor.cs +++ b/MatterControlLib/DesignTools/PublicPropertyEditor.cs @@ -60,6 +60,7 @@ namespace MatterHackers.MatterControl.DesignTools private static readonly Type[] AllowedTypes = { typeof(double), typeof(int), typeof(char), typeof(string), typeof(bool), + typeof(DoubleExpresion), typeof(Color), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(DirectionVector), typeof(DirectionAxis), @@ -667,6 +668,28 @@ namespace MatterHackers.MatterControl.DesignTools (value) => { return ((bool)value) ? "1" : "0"; }); rowContainer = CreateSettingsRow(property, field, theme); } + else if (propertyValue is DoubleExpresion doubleExpresion) + { + // create a string editor + var field = new TextField(theme); + field.Initialize(0); + field.SetValue(doubleExpresion.Expresion, false); + field.ClearUndoHistory(); + field.Content.HAnchor = HAnchor.Stretch; + RegisterValueChanged(field, + (valueString) => new DoubleExpresion(valueString), + (value) => + { + return ((DoubleExpresion)value).Expresion; + }); + rowContainer = CreateSettingsRow(property, field, theme); + + var label = rowContainer.Children.First(); + + var spacer = rowContainer.Children.OfType().FirstOrDefault(); + spacer.HAnchor = HAnchor.Absolute; + spacer.Width = Math.Max(0, 100 - label.Width); + } else if (propertyValue is string stringValue) { if (readOnly) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs index b3c3ddbb1..24d7d6498 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Object3DControlsLayer.cs @@ -55,11 +55,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow MoveInZ = 1 << 0, RotateXYZ = 1 << 1, RotateZ = 1 << 2, - ScaleWidthDepth = 1 << 3, - ScaleMatrixXY = 1 << 4, - Shadow = 1 << 5, - SnappingIndicators = 1 << 6, - ScaleHeight = 1 << 7, + ScaleMatrixXY = 1 << 3, + Shadow = 1 << 4, + SnappingIndicators = 1 << 5, Standard2D = MoveInZ | Shadow | SnappingIndicators | RotateZ | ScaleMatrixXY } @@ -178,24 +176,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow else { // add default controls - if (selectedItem is IObjectWithHeight heightObject) - { - // When this is ready make the debug behavior the only behavior - Object3DControls.Add(new ScaleHeightControl(this)); - } - else - { - Object3DControls.Add(new ScaleMatrixTopControl(this)); - } + Object3DControls.Add(new ScaleMatrixTopControl(this)); - if (selectedItem is IObjectWithWidthAndDepth widthAndDepth) - { - AddControls(ControlTypes.ScaleWidthDepth); - } - else - { - AddControls(ControlTypes.ScaleMatrixXY); - } + AddControls(ControlTypes.ScaleMatrixXY); AddControls(ControlTypes.RotateXYZ | ControlTypes.MoveInZ @@ -224,6 +207,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow base.OnDraw(graphics2D); } + public void AddWidthDepthControls(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)); + } + } + public void AddControls(ControlTypes controls) { if (controls.HasFlag(ControlTypes.RotateXYZ)) @@ -244,11 +236,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Object3DControls.Add(new MoveInZControl(this)); } - if (controls.HasFlag(ControlTypes.ScaleHeight)) - { - Object3DControls.Add(new ScaleHeightControl(this)); - } - if (controls.HasFlag(ControlTypes.ScaleMatrixXY)) { for (int i = 0; i < 4; i++) @@ -258,15 +245,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - if (controls.HasFlag(ControlTypes.ScaleWidthDepth)) - { - for (int i = 0; i < 4; i++) - { - Object3DControls.Add(new ScaleWidthDepthCornerControl(this, i)); - Object3DControls.Add(new ScaleWidthDepthEdgeControl(this, i)); - } - } - if (controls.HasFlag(ControlTypes.Shadow)) { Object3DControls.Add(new SelectionShadow(this));