writing tests for sheets

This commit is contained in:
Lars Brubaker 2021-06-02 14:30:29 -07:00
parent 3d068ef868
commit 0dcb08e1cc
6 changed files with 74 additions and 19 deletions

View file

@ -147,7 +147,6 @@ namespace MatterHackers.Plugins.EditorTools
public void ScaleDepth(double newDepth)
{
FinalState = new ScaleStates(InitialState);
FinalState.Depth = newDepth;
if (context.GuiSurface.ModifierKeys == Keys.Shift || selectedItem is IScaleLocker)
{
@ -159,7 +158,6 @@ namespace MatterHackers.Plugins.EditorTools
public void ScaleDiameter(double newSize, int index)
{
FinalState = new ScaleStates(InitialState);
FinalState.Diameters[index] = newSize;
if (context.GuiSurface.ModifierKeys == Keys.Shift)
{
@ -171,7 +169,6 @@ namespace MatterHackers.Plugins.EditorTools
public void ScaleHeight(double newHeight)
{
FinalState = new ScaleStates(InitialState);
FinalState.Height = newHeight;
if (context.GuiSurface.ModifierKeys == Keys.Shift || selectedItem is IScaleLocker)
{
@ -183,7 +180,6 @@ namespace MatterHackers.Plugins.EditorTools
public void ScaleWidth(double newWidth)
{
FinalState = new ScaleStates(InitialState);
FinalState.Width = newWidth;
if (context.GuiSurface.ModifierKeys == Keys.Shift || selectedItem is IScaleLocker)
{
@ -221,11 +217,12 @@ namespace MatterHackers.Plugins.EditorTools
}
InitialState.Matrix = selectedItem.Matrix;
FinalState = new ScaleStates(InitialState);
}
internal void ScaleWidthDepth(double newWidth, double newDepth)
{
FinalState = new ScaleStates(InitialState);
FinalState.Width = newWidth;
FinalState.Depth = newDepth;
if (context.GuiSurface.ModifierKeys == Keys.Shift || selectedItem is IScaleLocker)

View file

@ -84,6 +84,8 @@ namespace MatterHackers.MatterControl.DesignTools
{
using (RebuildLock())
{
// update the table info
SheetData.Recalculate();
// send a message to all our siblings and their children
SendInvalidateToAll();
}
@ -143,6 +145,11 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
}
if (inputExpression.Length > 0 && inputExpression[0] == '=')
{
inputExpression = inputExpression.Substring(1);
}
// look through all the parents
foreach (var parent in owner.Parents())

View file

@ -183,7 +183,6 @@ namespace MatterHackers.MatterControl.DesignTools
private void Recalculate()
{
sheetData.Recalculate();
sheetObject.Invalidate(InvalidateType.SheetUpdated);
}
}

View file

@ -213,8 +213,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Action<double> setWidth = (newWidth) => width.Expression = newWidth.ToString();
Func<double> getDepth = () => depth.Value(item);
Action<double> setDepth = (newDepth) => depth.Expression = newDepth.ToString();
Func<double> getHeight = () => height.Value(item);
Action<double> setHeight = (newHeight) => height.Expression = newHeight.ToString();
Func<double> getHeight = null;
Action<double> setHeight = null;
if (height != null)
{
getHeight = () => height.Value(item);
setHeight = (newHeight) => height.Expression = newHeight.ToString();
}
if (width != null
&& !width.IsEquation

View file

@ -424,9 +424,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
renderRoundedGroup(.3, .25);
renderRoundedGroup(.1, .5 + .1);
// render the perspective and turntable group background
// renderRoundedGroup(.1, 1 - .1); // when we have both ortho and turntable
renderRoundedGroup(.001, 1 - .127); // when we only have turntable
void renderRoundedLine(double lineWidth, double heightBelowCenter)
{
@ -480,12 +480,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
ToolTipText = "Turntable Mode".Localize(),
Margin = theme.ButtonSpacing,
Padding = 2,
ToggleButton = true,
SiblingRadioButtonList = new List<GuiWidget>(),
Checked = turntableEnabled,
BorderColor = hudStrokeColor,
};
// AddRoundButton(turnTableButton, RotatedMargin(turnTableButton, -MathHelper.Tau * .4)); // 2 button position
AddRoundButton(turnTableButton, RotatedMargin(turnTableButton, -MathHelper.Tau * .375));
AddRoundButton(turnTableButton, RotatedMargin(turnTableButton, -MathHelper.Tau * .30));
turnTableButton.CheckedStateChanged += (s, e) =>
{
UserSettings.Instance.set(UserSettingsKey.TurntableMode, turnTableButton.Checked.ToString());

View file

@ -28,9 +28,8 @@ either expressed or implied, of the FreeBSD Project.
*/
#define DEBUG_INTO_TGAS
using System;
using System.Linq;
using MatterHackers.Agg;
using System.Threading.Tasks;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
@ -44,8 +43,7 @@ namespace MatterHackers.PolygonMesh.UnitTests
[TestFixture, Category("Agg.PolygonMesh.Rebuild")]
public class MeshRebuildTests
{
[Test]
public void PinchChangesMesh()
public void SetupEvnironment()
{
StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
@ -55,13 +53,12 @@ namespace MatterHackers.PolygonMesh.UnitTests
MatterControl.AppContext.Platform = AggContext.CreateInstanceFrom<INativePlatformFeatures>(platformFeaturesProvider);
MatterControl.AppContext.Platform.InitPluginFinder();
MatterControl.AppContext.Platform.ProcessCommandline();
RunTest();
}
private async void RunTest()
[Test]
public async Task PinchChangesMesh()
{
StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
SetupEvnironment();
var root = new Object3D();
@ -73,4 +70,51 @@ namespace MatterHackers.PolygonMesh.UnitTests
Assert.AreEqual(3, root.Descendants().Count());
}
}
[TestFixture, Category("Agg.Scene.Rebuild")]
public class SceenSheetTests
{
public void SetupEvnironment()
{
StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData");
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
// Automation runner must do as much as program.cs to spin up platform
string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";
MatterControl.AppContext.Platform = AggContext.CreateInstanceFrom<INativePlatformFeatures>(platformFeaturesProvider);
MatterControl.AppContext.Platform.InitPluginFinder();
MatterControl.AppContext.Platform.ProcessCommandline();
}
[Test]
public async Task TestSheetFunctions()
{
SetupEvnironment();
var root = new Object3D();
// Create the scene (a cube and a sheet)
var cube1 = new CubeObject3D();
root.Children.Add(cube1);
var sheet = await SheetObject3D.Create();
root.Children.Add(sheet);
// set the sheet A1 to 33
sheet.SheetData[0, 0].Expression = "=33";
// rebuild cube without a reference to sheet
cube1.Invalidate(InvalidateType.Properties);
Assert.AreEqual(20, cube1.Width.Value(cube1), "cube1 should be the default 20mm");
// set the cube width to the sheet value, but with a bad description (needs an equals to work)
cube1.Width = "A1";
cube1.Invalidate(InvalidateType.Properties);
Assert.AreEqual(0, cube1.Width.Value(cube1), "Should be 0 as the reference is bad");
// now fix the reference
cube1.Width = "=A1";
cube1.Invalidate(InvalidateType.Properties);
Assert.AreEqual(33, cube1.Width.Value(cube1), "Should now be the value ad A1");
// Change the sheet value
sheet.SheetData[0, 0].Expression = "=43";
// and rebuild the references
sheet.Invalidate(InvalidateType.SheetUpdated);
Assert.AreEqual(43, cube1.Width.Value(cube1));
}
}
}