From c01afb5542c214929fd8e02b19b866b42111e16d Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sun, 6 Jun 2021 09:07:18 -0700 Subject: [PATCH] Added UiHints to controls --- .../EditorTools/RotateControls/PathControl.cs | 3 +- .../RotateControls/RotateCornerControl.cs | 4 ++ .../ScaleControls/ScaleDiameterControl.cs | 3 ++ .../ScaleControls/ScaleHeightControl.cs | 4 ++ .../ScaleControls/ScaleMatrixCornerControl.cs | 7 +-- .../ScaleControls/ScaleMatrixEdgeControl.cs | 4 ++ .../ScaleControls/ScaleMatrixTopControl.cs | 4 ++ .../ScaleWidthDepthCornerControl.cs | 4 ++ .../ScaleWidthDepthEdgeControl.cs | 4 ++ .../DesignTools/Primitives/BaseObject3D.cs | 32 +++++++------ .../TracedPositionObject3DControl.cs | 37 +++++++-------- .../DesignTools/PublicPropertyEditor.cs | 17 +++++++ .../DesignTools/Sheets/SheetObject3D.cs | 19 ++++++++ .../View3D/Gui3D/MoveInZControl.cs | 5 +++ .../View3D/Interaction/IObject3DControl.cs | 2 + .../View3D/Interaction/Object3DControl.cs | 23 +++++++++- .../DesignTools/PrimitveTests.cs | 45 +++++++++++++++++++ 17 files changed, 177 insertions(+), 40 deletions(-) create mode 100644 Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs diff --git a/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs b/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs index ec83cef63..4c5e88253 100644 --- a/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/RotateControls/PathControl.cs @@ -115,9 +115,10 @@ namespace MatterHackers.Plugins.EditorTools public bool DrawOnTop => false; + public string UiHint => ""; + public void CancelOperation() { - throw new NotImplementedException(); } public void Draw(DrawGlContentEventArgs e) diff --git a/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs index f8ab922b4..a0618b9cb 100644 --- a/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs @@ -67,6 +67,8 @@ namespace MatterHackers.Plugins.EditorTools private double rotationTransformScale = 1; private Vector3 selectCubeSize = new Vector3(30, 30, .1) * GuiWidget.DeviceScale; + public override string UiHint => "Hold 'Shift' to lock to 45°, Type 'Esc' to cancel"; + public RotateCornerControl(IObject3DControlContext context, int axisIndex) : base(context) { @@ -451,6 +453,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo) diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs index c86891e8f..c65cfa540 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleDiameterControl.cs @@ -73,6 +73,7 @@ namespace MatterHackers.Plugins.EditorTools private readonly ObjectSpace.Placement placement; private readonly int diameterIndex; private readonly double angleOffset; + public override string UiHint => ScallingHint; public ScaleDiameterControl(IObject3DControlContext context, Func getHeight, @@ -160,6 +161,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void Dispose() diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs index 580fbb676..f5af3648f 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleHeightControl.cs @@ -74,6 +74,8 @@ namespace MatterHackers.Plugins.EditorTools private readonly List> getDiameters; private readonly List> setDiameters; + public override string UiHint => ScallingHint; + public ScaleHeightControl(IObject3DControlContext context, Func getWidth, Action setWidth, @@ -182,6 +184,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void Dispose() diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs index 48abee454..0693bf261 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixCornerControl.cs @@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.Collections.Generic; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; @@ -56,8 +55,6 @@ namespace MatterHackers.Plugins.EditorTools private Matrix4X4 transformOnMouseDown = Matrix4X4.Identity; private Matrix4X4 transformAppliedByThis = Matrix4X4.Identity; - private double DistToStart => 10 * GuiWidget.DeviceScale; - private double LineLength => 35 * GuiWidget.DeviceScale; private Vector3 originalPointToMove; @@ -68,6 +65,8 @@ namespace MatterHackers.Plugins.EditorTools private readonly InlineEditControl yValueDisplayInfo; private bool hadClickOnControl; + public override string UiHint => ScallingHint; + public ScaleMatrixCornerControl(IObject3DControlContext context, int cornerIndex) : base(context) { @@ -396,6 +395,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo) diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixEdgeControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixEdgeControl.cs index 8a9eae28b..cacb31699 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixEdgeControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixEdgeControl.cs @@ -72,6 +72,8 @@ namespace MatterHackers.Plugins.EditorTools private readonly InlineEditControl yValueDisplayInfo; private bool hadClickOnControl; + public override string UiHint => ScallingHint; + public ScaleMatrixEdgeControl(IObject3DControlContext context, int edgeIndex) : base(context) { @@ -365,6 +367,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo) diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixTopControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixTopControl.cs index cb96a08a2..567e61dc8 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixTopControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleMatrixTopControl.cs @@ -64,6 +64,8 @@ namespace MatterHackers.Plugins.EditorTools private readonly InlineEditControl zValueDisplayInfo; private bool hadClickOnControl; + public override string UiHint => ScallingHint; + public ScaleMatrixTopControl(IObject3DControlContext context) : base(context) { @@ -313,6 +315,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo) diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs index dd4e04905..be791dc77 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthCornerControl.cs @@ -74,6 +74,8 @@ namespace MatterHackers.Plugins.EditorTools private ScaleController scaleController; + public override string UiHint => ScallingHint; + public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, Func getWidth, Action setWidth, @@ -157,6 +159,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void Dispose() diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs index 1dee3e13b..96078fc58 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleWidthDepthEdgeControl.cs @@ -74,6 +74,8 @@ namespace MatterHackers.Plugins.EditorTools private ScaleController scaleController; + public override string UiHint => ScallingHint; + public ScaleWidthDepthEdgeControl(IObject3DControlContext context, Func getWidth, Action setWidth, @@ -164,6 +166,8 @@ namespace MatterHackers.Plugins.EditorTools Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void Dispose() diff --git a/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs b/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs index 459a2834c..2ee568a76 100644 --- a/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs +++ b/MatterControlLib/DesignTools/Primitives/BaseObject3D.cs @@ -80,15 +80,15 @@ namespace MatterHackers.MatterControl.DesignTools public BaseTypes BaseType { get; set; } = BaseTypes.Circle; [Description("The height the base will be derived from (starting at the bottom).")] - public double CalculationHeight { get; set; } = .1; + public DoubleOrExpression CalculationHeight { get; set; } = .1; [DisplayName("Expand")] - public double BaseSize { get; set; } = 3; + public DoubleOrExpression BaseSize { get; set; } = 3; - public double InfillAmount { get; set; } = 3; + public DoubleOrExpression InfillAmount { get; set; } = 3; [DisplayName("Height")] - public double ExtrusionHeight { get; set; } = 5; + public DoubleOrExpression ExtrusionHeight { get; set; } = 5; [ReadOnly(true)] public string NoBaseMessage { get; set; } = "No base is added under your part. Switch to a different base option to create a base."; @@ -159,12 +159,13 @@ namespace MatterHackers.MatterControl.DesignTools { if (OutlineIsFromMesh) { - if (meshVertexCache.vertexSource == null || meshVertexCache.height != CalculationHeight) + var calculationHeight = CalculationHeight.Value(this); + if (meshVertexCache.vertexSource == null || meshVertexCache.height != calculationHeight) { var aabb = this.GetAxisAlignedBoundingBox(); - var cutPlane = new Plane(Vector3.UnitZ, new Vector3(0, 0, aabb.MinXYZ.Z + CalculationHeight)); + var cutPlane = new Plane(Vector3.UnitZ, new Vector3(0, 0, aabb.MinXYZ.Z + calculationHeight)); meshVertexCache.vertexSource = GetSlicePaths(this, cutPlane); - meshVertexCache.height = CalculationHeight; + meshVertexCache.height = calculationHeight; } return meshVertexCache.vertexSource; @@ -396,15 +397,18 @@ namespace MatterHackers.MatterControl.DesignTools { Polygons basePolygons; + var infillAmount = InfillAmount.Value(this); + var baseSize = BaseSize.Value(this); + var extrusionHeight = ExtrusionHeight.Value(this); if (BaseType == BaseTypes.Outline - && InfillAmount > 0) + && infillAmount > 0) { - basePolygons = polysToOffset.Offset((BaseSize + InfillAmount) * scalingForClipper); - basePolygons = basePolygons.Offset(-InfillAmount * scalingForClipper); + basePolygons = polysToOffset.Offset((baseSize + infillAmount) * scalingForClipper); + basePolygons = basePolygons.Offset(-infillAmount * scalingForClipper); } else { - basePolygons = polysToOffset.Offset(BaseSize * scalingForClipper); + basePolygons = polysToOffset.Offset(baseSize * scalingForClipper); } basePolygons = ClipperLib.Clipper.CleanPolygons(basePolygons, 10); @@ -412,8 +416,8 @@ namespace MatterHackers.MatterControl.DesignTools VertexStorage rawVectorShape = basePolygons.PolygonToPathStorage(); var vectorShape = new VertexSourceApplyTransform(rawVectorShape, Affine.NewScaling(1.0 / scalingForClipper)); - var mesh = VertexSourceToMesh.Extrude(vectorShape, zHeightTop: ExtrusionHeight); - mesh.Translate(new Vector3(0, 0, -ExtrusionHeight + bottomWithoutBase)); + var mesh = VertexSourceToMesh.Extrude(vectorShape, zHeightTop: extrusionHeight); + mesh.Translate(new Vector3(0, 0, -extrusionHeight + bottomWithoutBase)); var baseObject = new Object3D() { @@ -467,7 +471,7 @@ namespace MatterHackers.MatterControl.DesignTools { var aabb = this.GetAxisAlignedBoundingBox(this.WorldMatrix()); // ExtrusionHeight - layer.World.RenderPathOutline(this.WorldMatrix() * Matrix4X4.CreateTranslation(0, 0, CalculationHeight - aabb.MinXYZ.Z + ExtrusionHeight), VertexSource, Agg.Color.Red, 5); + layer.World.RenderPathOutline(this.WorldMatrix() * Matrix4X4.CreateTranslation(0, 0, CalculationHeight.Value(this) - aabb.MinXYZ.Z + ExtrusionHeight.Value(this)), VertexSource, Agg.Color.Red, 5); // turn the lighting back on GL.Enable(EnableCap.Lighting); diff --git a/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs b/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs index ecd16e41d..75c47f5d7 100644 --- a/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs +++ b/MatterControlLib/DesignTools/Primitives/TracedPositionObject3DControl.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; +using MatterHackers.Localizations; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; @@ -54,8 +55,6 @@ namespace MatterHackers.MatterControl.DesignTools private Func getPosition; - private IObject3D owner; - private Action setPosition; private Action editComplete; @@ -83,20 +82,6 @@ namespace MatterHackers.MatterControl.DesignTools this.shape = PlatonicSolids.CreateCube(); this.shape = SphereObject3D.CreateSphere(1, 15, 10); collisionVolume = shape.CreateBVHData(); - this.owner = owner; - - Keyboard.StateChanged += Keyboard_StateChanged; - } - - private void Keyboard_StateChanged(object sender, EventArgs e) - { - if (DownOnControl - && Keyboard.IsKeyDown(Keys.Escape)) - { - DownOnControl = false; - setPosition(mouseDownPosition); - return; - } } public bool DrawOnTop => true; @@ -105,13 +90,17 @@ namespace MatterHackers.MatterControl.DesignTools public bool Visible { get; set; } + public string UiHint => "Type 'Esc' to cancel".Localize(); + public void CancelOperation() { - } - - public void Dispose() - { - Keyboard.StateChanged -= Keyboard_StateChanged; + if (DownOnControl) + { + ApplicationController.Instance.UiHint = ""; + DownOnControl = false; + setPosition(mouseDownPosition); + ApplicationController.Instance.UiHint = ""; + } } public void Draw(DrawGlContentEventArgs e) @@ -150,6 +139,7 @@ namespace MatterHackers.MatterControl.DesignTools public void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { DownOnControl = true; + ApplicationController.Instance.UiHint = UiHint; mouseDownPosition = getPosition(); // Make sure we always get a new hit plane ResetHitPlane(); @@ -224,6 +214,7 @@ namespace MatterHackers.MatterControl.DesignTools { DownOnControl = false; editComplete(mouseDownPosition); + ApplicationController.Instance.UiHint = ""; } } @@ -235,5 +226,9 @@ namespace MatterHackers.MatterControl.DesignTools { UpdatePosition(screenPosition); } + + public void Dispose() + { + } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/PublicPropertyEditor.cs b/MatterControlLib/DesignTools/PublicPropertyEditor.cs index 0660a1e25..e04adf07e 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(StringOrExpression), typeof(DoubleOrExpression), typeof(IntOrExpression), typeof(Color), @@ -830,6 +831,22 @@ namespace MatterHackers.MatterControl.DesignTools } } } + else if (propertyValue is StringOrExpression stringOrExpression) + { + // create a string editor + var field = new TextField(theme); + field.Initialize(0); + field.SetValue(stringOrExpression.Expression, false); + field.ClearUndoHistory(); + field.Content.HAnchor = HAnchor.Stretch; + RegisterValueChanged(field, + (valueString) => new StringOrExpression(valueString), + (value) => + { + return ((StringOrExpression)value).Expression; + }); + rowContainer = CreateSettingsRow(property, field, theme, rows); + } else if (propertyValue is char charValue) { // create a char editor diff --git a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs index 9306b542d..df736aba8 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs @@ -130,6 +130,11 @@ namespace MatterHackers.MatterControl.DesignTools // check if the expression is not an equation (does not start with "=") if (inputExpression.Length > 0 && inputExpression[0] != '=') { + if (typeof(T) == typeof(string)) + { + return (T)(object)inputExpression; + } + // not an equation so try to parse it directly if (double.TryParse(inputExpression, out var result)) { @@ -170,9 +175,23 @@ namespace MatterHackers.MatterControl.DesignTools if (sibling != owner && sibling is SheetObject3D sheet) { + // try to manage the cell into the correct data type string value = sheet.SheetData.EvaluateExpression(inputExpression); + if (typeof(T) == typeof(string)) + { + // if parsing the equation resulted in NaN as the output + if (value == "NaN") + { + // return the actual expression + return (T)(object)inputExpression; + } + + // get the value of the cell + return (T)(object)value; + } + if (typeof(T) == typeof(double)) { if (double.TryParse(value, out double doubleValue) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs index 2454e47b0..ecf15cc31 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs @@ -35,6 +35,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; +using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MeshVisualizer; using MatterHackers.PolygonMesh; @@ -62,6 +63,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private bool hadClickOnControl; private readonly ThemeConfig theme; + public override string UiHint => "Type 'Esc' to cancel".Localize(); + public MoveInZControl(IObject3DControlContext context) : base(context) { @@ -283,6 +286,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Object3DControlContext.Scene.DrawSelection = true; Object3DControlContext.Scene.ShowSelectionShadow = true; } + + base.CancelOperation(); } public override void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Interaction/IObject3DControl.cs b/MatterControlLib/PartPreviewWindow/View3D/Interaction/IObject3DControl.cs index 4e4391466..99874df8a 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Interaction/IObject3DControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Interaction/IObject3DControl.cs @@ -41,6 +41,8 @@ namespace MatterHackers.MeshVisualizer { string Name { get; } + string UiHint { get; } + void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo); /// diff --git a/MatterControlLib/PartPreviewWindow/View3D/Interaction/Object3DControl.cs b/MatterControlLib/PartPreviewWindow/View3D/Interaction/Object3DControl.cs index c939c199d..056369658 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Interaction/Object3DControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Interaction/Object3DControl.cs @@ -29,6 +29,8 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; +using MatterHackers.Localizations; +using MatterHackers.MatterControl; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.RayTracer; using MatterHackers.RayTracer.Traceable; @@ -38,6 +40,8 @@ namespace MatterHackers.MeshVisualizer { public abstract class Object3DControl : IObject3DControl { + public static string ScallingHint => "Hold 'Shift' to scale proportionally, Type 'Esc' to cancel".Localize(); + private bool _mouseIsOver = false; public Matrix4X4 TotalTransform { get; set; } = Matrix4X4.Identity; @@ -53,6 +57,8 @@ namespace MatterHackers.MeshVisualizer public virtual bool Visible { get; set; } + public virtual string UiHint { get; } + protected bool MouseDownOnControl { get; set; } public abstract void Dispose(); @@ -110,7 +116,13 @@ namespace MatterHackers.MeshVisualizer Object3DControlContext.GuiSurface.Invalidate(); } - public abstract void CancelOperation(); + public virtual void CancelOperation() + { + if (!string.IsNullOrEmpty(UiHint)) + { + ApplicationController.Instance.UiHint = ""; + } + } public virtual void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { @@ -118,6 +130,10 @@ namespace MatterHackers.MeshVisualizer { MouseDownOnControl = true; this.Object3DControlContext.GuiSurface.Invalidate(); + if (!string.IsNullOrEmpty(UiHint)) + { + ApplicationController.Instance.UiHint = UiHint; + } } } @@ -129,6 +145,11 @@ namespace MatterHackers.MeshVisualizer public virtual void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { MouseDownOnControl = false; + + if (!string.IsNullOrEmpty(UiHint)) + { + ApplicationController.Instance.UiHint = ""; + } } public virtual void SetPosition(IObject3D selectedItem, MeshSelectInfo selectInfo) diff --git a/Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs b/Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs new file mode 100644 index 000000000..5ab23518d --- /dev/null +++ b/Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs @@ -0,0 +1,45 @@ +using System.Threading; +using System.Threading.Tasks; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PrintQueue; +using NUnit.Framework; + +namespace MatterHackers.MatterControl.Tests.Automation +{ + [TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)] + public class PrimitiveAndSheetsTests + { + [Test] + public async Task DimensionsWorkWithSheets() + { + await MatterControlUtilities.RunTest((testRunner) => + { + testRunner.OpenEmptyPartTab(); + + testRunner.AddItemToBedplate(); + + // Get View3DWidget + View3DWidget view3D = testRunner.GetWidgetByName("View3DWidget", out _, 3) as View3DWidget; + var scene = view3D.Object3DControlLayer.Scene; + + testRunner.WaitForName("Calibration - Box.stl"); + Assert.AreEqual(1, scene.Children.Count, "Should have 1 part before copy"); + + // Select scene object + testRunner.Select3DPart("Calibration - Box.stl"); + + // Click Copy button and count Scene.Children + testRunner.ClickByName("Duplicate Button"); + testRunner.WaitFor(() => scene.Children.Count == 2); + Assert.AreEqual(2, scene.Children.Count, "Should have 2 parts after copy"); + + // Click Copy button a second time and count Scene.Children + testRunner.ClickByName("Duplicate Button"); + testRunner.WaitFor(() => scene.Children.Count > 2); + Assert.AreEqual(3, scene.Children.Count, "Should have 3 parts after 2nd copy"); + + return Task.CompletedTask; + }, overrideWidth: 1300, maxTimeToRun: 60); + } + } +}