diff --git a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs index 9b94228c1..3199bfff2 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayAdvancedObject3D.cs @@ -45,15 +45,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public override bool CanFlatten => true; - public override int Count { get; set; } = 3; + public override IntOrExpression Count { get; set; } = 3; public Vector3 Offset { get; set; } = new Vector3(30, 0, 0); - public double Rotate { get; set; } = -15; + public DoubleOrExpression Rotate { get; set; } = -15; public bool RotatePart { get; set; } = true; - public double Scale { get; set; } = .9; + public DoubleOrExpression Scale { get; set; } = .9; public bool ScaleOffset { get; set; } = true; @@ -76,12 +76,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations var lastChild = sourceContainer.Children.First(); list.Add(lastChild.Clone()); var offset = Offset; - for (int i = 1; i < Count; i++) + var count = Count.Value(this); + var rotate = Rotate.Value(this); + var scale = Scale.Value(this); + for (int i = 1; i < count; i++) { - var rotateRadians = MathHelper.DegreesToRadians(Rotate); + var rotateRadians = MathHelper.DegreesToRadians(rotate); if (ScaleOffset) { - offset *= Scale; + offset *= scale; } var next = lastChild.Clone(); @@ -93,7 +96,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateRotationZ(rotateRadians)); } - next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateScale(Scale)); + next.Matrix = next.ApplyAtBoundsCenter(Matrix4X4.CreateScale(scale)); list.Add(next); lastChild = next; } diff --git a/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs index ff49c8008..f158ab59f 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayLinearObject3D.cs @@ -49,52 +49,57 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public override bool CanFlatten => true; - public override int Count { get; set; } = 3; + public override IntOrExpression Count { get; set; } = 3; public DirectionVector Direction { get; set; } = new DirectionVector { Normal = new Vector3(1, 0, 0) }; - public double Distance { get; set; } = 30; + public DoubleOrExpression Distance { get; set; } = 30; public override async Task Rebuild() { var rebuildLock = this.RebuildLock(); SourceContainer.Visible = true; - await ApplicationController.Instance.Tasks.Execute( - "Linear Array".Localize(), - null, - (reporter, cancellationToken) => - { - this.DebugDepth("Rebuild"); + using (new CenterAndHeightMaintainer(this, CenterAndHeightMaintainer.MaintainFlags.Height)) + { + await ApplicationController.Instance.Tasks.Execute( + "Linear Array".Localize(), + null, + (reporter, cancellationToken) => + { + this.DebugDepth("Rebuild"); - var newChildren = new List(); + var newChildren = new List(); - newChildren.Add(SourceContainer); + newChildren.Add(SourceContainer); - var arrayItem = SourceContainer.Children.First(); + var arrayItem = SourceContainer.Children.First(); + var distance = Distance.Value(this); + var count = Count.Value(this); // add in all the array items - for (int i = 0; i < Math.Max(Count, 1); i++) - { - var next = arrayItem.Clone(); - next.Matrix = arrayItem.Matrix * Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * Distance * i); - newChildren.Add(next); - } + for (int i = 0; i < Math.Max(count, 1); i++) + { + var next = arrayItem.Clone(); + next.Matrix = arrayItem.Matrix * Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * distance * i); + newChildren.Add(next); + } - Children.Modify(list => - { - list.Clear(); - list.AddRange(newChildren); - }); + Children.Modify(list => + { + list.Clear(); + list.AddRange(newChildren); + }); - SourceContainer.Visible = false; - UiThread.RunOnIdle(() => - { - rebuildLock.Dispose(); - Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); + SourceContainer.Visible = false; + UiThread.RunOnIdle(() => + { + rebuildLock.Dispose(); + Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); + }); + return Task.CompletedTask; }); - return Task.CompletedTask; - }); + } } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs index 22d66d63b..999d607cf 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayObject3D.cs @@ -40,6 +40,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { public abstract class ArrayObject3D : OperationSourceContainerObject3D { - public abstract int Count { get; set; } + public abstract IntOrExpression Count { get; set; } } } \ No newline at end of file diff --git a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs index 8235e8524..d99128972 100644 --- a/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs +++ b/MatterControlLib/DesignTools/Operations/ArrayRadialObject3D.cs @@ -54,13 +54,13 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public override bool CanFlatten => true; - public override int Count { get; set; } = 3; + public override IntOrExpression Count { get; set; } = 3; [Description("Rotate the part to the same angle as the array.")] public bool RotatePart { get; set; } = true; // make this public when within angle works - private double Angle { get; set; } = 360; + private DoubleOrExpression Angle { get; set; } = 360; // make this public when it works [DisplayName("Keep Within Angle")] @@ -109,12 +109,14 @@ namespace MatterHackers.MatterControl.DesignTools.Operations var sourceItem = sourceContainer.Children.First(); var offset = Vector3.Zero; - for (int i = 0; i < Math.Max(Count, 1); i++) + var count = Count.Value(this); + var angle = Angle.Value(this); + for (int i = 0; i < Math.Max(count, 1); i++) { var next = sourceItem.Clone(); var normal = Axis.Normal.GetNormal(); - var angleRadians = MathHelper.DegreesToRadians(Angle) / Count * i; + var angleRadians = MathHelper.DegreesToRadians(angle) / count * i; next.Rotate(Axis.Origin, normal, angleRadians); if (!RotatePart) diff --git a/MatterControlLib/DesignTools/Sheets/SheetData.cs b/MatterControlLib/DesignTools/Sheets/SheetData.cs index 9d64a6224..77affc43b 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetData.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetData.cs @@ -31,12 +31,16 @@ using System.Collections.Generic; using org.mariuszgromada.math.mxparser; using Newtonsoft.Json; using System.Linq; +using System; namespace MatterHackers.MatterControl.DesignTools { public class SheetData { private object locker = new object(); + + public event EventHandler Recalculated; + public SheetData() { } @@ -274,6 +278,8 @@ namespace MatterHackers.MatterControl.DesignTools tabelCalculated = true; } + + Recalculated?.Invoke(this, null); } private void AddConstants(Expression evaluator) diff --git a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs index 6c3b50748..bad37e1a3 100644 --- a/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs +++ b/MatterControlLib/DesignTools/Sheets/SheetObject3D.cs @@ -51,7 +51,25 @@ namespace MatterHackers.MatterControl.DesignTools [MarkDownDescription("[BETA] - Experimental support for variables and equations with a sheets like interface.")] public class SheetObject3D : Object3D, IObject3DControlsProvider { - public SheetData SheetData { get; set; } + private SheetData _sheetData; + public SheetData SheetData + { + get => _sheetData; + + set + { + if (_sheetData != value) + { + if (_sheetData != null) + { + _sheetData.Recalculated -= SendInvalidateToAll; + } + + _sheetData = value; + _sheetData.Recalculated += SendInvalidateToAll; + } + } + } public static async Task Create() { @@ -111,31 +129,13 @@ namespace MatterHackers.MatterControl.DesignTools public override bool Persistable => false; - public override void OnInvalidate(InvalidateArgs invalidateType) - { - if (invalidateType.InvalidateType.HasFlag(InvalidateType.SheetUpdated) && invalidateType.Source == this) - { - using (RebuildLock()) - { - // update the table info - SheetData.Recalculate(); - // send a message to all our siblings and their children - SendInvalidateToAll(); - } - } - else - { - base.OnInvalidate(invalidateType); - } - } - internal class UpdateItem { internal int depth; internal IObject3D item; internal RebuildLock rebuildLock; } - private void SendInvalidateToAll() + private void SendInvalidateToAll(object s, EventArgs e) { var updateItems = new List(); foreach (var sibling in this.Parent.Children) diff --git a/MatterControlLib/Library/Providers/Zip/ZipMemoryContainer.cs b/MatterControlLib/Library/Providers/Zip/ZipMemoryContainer.cs index d1034eb0c..72025c77b 100644 --- a/MatterControlLib/Library/Providers/Zip/ZipMemoryContainer.cs +++ b/MatterControlLib/Library/Providers/Zip/ZipMemoryContainer.cs @@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.Library CurrentDirectory = RelativeDirectory.Length == 0 ? d : $"{RelativeDirectory}{pathSeparator}{d}" })); - this.Items = new SafeList(items.Select(kvp => new ZipMemoryItem(this.Path, RelativeDirectory.Length == 0 ? kvp.Key : $"{RelativeDirectory}{pathSeparator}{kvp.Key}", kvp.Value))); + this.Items = new SafeList(items.Select(kvp => new ZipMemoryItem(this, this.Path, RelativeDirectory.Length == 0 ? kvp.Key : $"{RelativeDirectory}{pathSeparator}{kvp.Key}", kvp.Value))); } } } \ No newline at end of file diff --git a/MatterControlLib/Library/Providers/Zip/ZipMemoryItem.cs b/MatterControlLib/Library/Providers/Zip/ZipMemoryItem.cs index acce86b2f..a8455b078 100644 --- a/MatterControlLib/Library/Providers/Zip/ZipMemoryItem.cs +++ b/MatterControlLib/Library/Providers/Zip/ZipMemoryItem.cs @@ -38,9 +38,10 @@ namespace MatterHackers.MatterControl.Library { public class ZipMemoryItem : FileSystemItem, ILibraryAssetStream { - public ZipMemoryItem(string filePath, string relativePath, long fileSize) + public ZipMemoryItem(ZipMemoryContainer containingZip, string filePath, string relativePath, long fileSize) : base(filePath) { + this.ContainingZip = containingZip; this.RelativePath = relativePath; this.Name = System.IO.Path.GetFileName(relativePath); this.FileSize = fileSize; @@ -59,6 +60,7 @@ namespace MatterHackers.MatterControl.Library public override string ID => agg_basics.GetLongHashCode($"{this.Path}/{this.RelativePath}").ToString(); + public ZipMemoryContainer ContainingZip { get; } public string RelativePath { get; set; } public async Task GetStream(Action reportProgress) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Actions/SheetEditor.cs b/MatterControlLib/PartPreviewWindow/View3D/Actions/SheetEditor.cs index 5fada982b..bd0daab49 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Actions/SheetEditor.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Actions/SheetEditor.cs @@ -37,181 +37,179 @@ using MatterHackers.Localizations; namespace MatterHackers.MatterControl.DesignTools { - public class SheetEditor : IObject3DEditor + public class SheetEditorWidget : FlowLayoutWidget { - public class SheetEditorWidget : FlowLayoutWidget + private SheetData sheetData; + Point2D selectedCell = new Point2D(-1, -1); + Dictionary<(int, int), GuiWidget> CellWidgetsByLocation = new Dictionary<(int, int), GuiWidget>(); + private ThemeConfig theme; + private MHTextEditWidget editSelectedName; + private MHTextEditWidget editSelectedExpression; + + public SheetEditorWidget(SheetData sheetData, UndoBuffer undoBuffer, ThemeConfig theme) + : base(FlowDirection.TopToBottom) { - private SheetObject3D sheetObject; - private SheetData sheetData; - Point2D selectedCell = new Point2D(-1, -1); - Dictionary<(int, int), GuiWidget> CellWidgetsByLocation = new Dictionary<(int, int), GuiWidget>(); - private ThemeConfig theme; - private MHTextEditWidget editSelectedName; - private MHTextEditWidget editSelectedExpression; + this.theme = theme; + HAnchor = HAnchor.MaxFitOrStretch; - public SheetEditorWidget(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme) - : base(FlowDirection.TopToBottom) + this.sheetData = sheetData; + var countWidth = 10 * GuiWidget.DeviceScale; + var cellWidth = 50 * GuiWidget.DeviceScale; + + // put in the edit row + var editSelectionGroup = this.AddChild(new FlowLayoutWidget() { - this.theme = theme; - HAnchor = HAnchor.MaxFitOrStretch; + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit, + }); - sheetObject = item as SheetObject3D; - sheetData = sheetObject.SheetData; - var countWidth = 10 * GuiWidget.DeviceScale; - var cellWidth = 50 * GuiWidget.DeviceScale; + editSelectedName = new MHTextEditWidget("", theme, cellWidth, messageWhenEmptyAndNotSelected: "Name".Localize()) + { + HAnchor = HAnchor.Absolute, + SelectAllOnFocus = true, + }; + editSelectedName.ActualTextEditWidget.EditComplete += SelectedName_EditComplete; + editSelectionGroup.AddChild(editSelectedName); + editSelectedExpression = new MHTextEditWidget("", theme, messageWhenEmptyAndNotSelected: "Select cell to edit".Localize()) + { + HAnchor = HAnchor.Stretch, + SelectAllOnFocus = true, + }; + editSelectionGroup.AddChild(editSelectedExpression); + editSelectedExpression.ActualTextEditWidget.EditComplete += ActualTextEditWidget_EditComplete1; - // put in the edit row - var editSelectionGroup = this.AddChild(new FlowLayoutWidget() + // put in the header row + var topRow = this.AddChild(new FlowLayoutWidget() + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit, + }); + + + topRow.AddChild(new GuiWidget(cellWidth, 1)); + for (int x = 0; x < sheetData.Width; x++) + { + topRow.AddChild(new TextWidget(((char)('A' + x)).ToString()) + { + HAnchor = HAnchor.Stretch, + TextColor = theme.TextColor + }); + } + + for (int y = 0; y < sheetData.Height; y++) + { + var row = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, + }; + this.AddChild(row); + + // add row count + row.AddChild(new TextWidget((y + 1).ToString()) + { + TextColor = theme.TextColor, }); - editSelectedName = new MHTextEditWidget("", theme, cellWidth, messageWhenEmptyAndNotSelected: "Name".Localize()) - { - HAnchor = HAnchor.Absolute, - SelectAllOnFocus = true, - }; - editSelectedName.ActualTextEditWidget.EditComplete += SelectedName_EditComplete; - editSelectionGroup.AddChild(editSelectedName); - editSelectedExpression = new MHTextEditWidget("", theme, messageWhenEmptyAndNotSelected: "Select cell to edit".Localize()) - { - HAnchor = HAnchor.Stretch, - SelectAllOnFocus = true, - }; - editSelectionGroup.AddChild(editSelectedExpression); - editSelectedExpression.ActualTextEditWidget.EditComplete += ActualTextEditWidget_EditComplete1; - - // put in the header row - var topRow = this.AddChild(new FlowLayoutWidget() - { - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit, - }); - - - topRow.AddChild(new GuiWidget(cellWidth, 1)); for (int x = 0; x < sheetData.Width; x++) { - topRow.AddChild(new TextWidget(((char)('A' + x)).ToString()) - { - HAnchor = HAnchor.Stretch, - TextColor = theme.TextColor - }); - } + var capturedX = x; + var capturedY = y; - for (int y = 0; y < sheetData.Height; y++) - { - var row = new FlowLayoutWidget() + var edit = new MHTextEditWidget(sheetData[x, y].Expression, theme) { HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit, + SelectAllOnFocus = true, }; - this.AddChild(row); - // add row count - row.AddChild(new TextWidget((y + 1).ToString()) + CellWidgetsByLocation.Add((capturedX, capturedY), edit); + + edit.MouseDown += (s, e) => SelectCell(capturedX, capturedY); + + row.AddChild(edit); + edit.ActualTextEditWidget.EditComplete += (s, e) => { - TextColor = theme.TextColor, - }); - - for (int x = 0; x < sheetData.Width; x++) - { - var capturedX = x; - var capturedY = y; - - var edit = new MHTextEditWidget(sheetData[x, y].Expression, theme) - { - HAnchor = HAnchor.Stretch, - SelectAllOnFocus = true, - }; - - CellWidgetsByLocation.Add((capturedX, capturedY), edit); - - edit.MouseDown += (s, e) => SelectCell(capturedX, capturedY); - - row.AddChild(edit); - edit.ActualTextEditWidget.EditComplete += (s, e) => - { - editSelectedExpression.Text = edit.Text; - sheetData[capturedX, capturedY].Expression = edit.Text; - Recalculate(); - }; - } + editSelectedExpression.Text = edit.Text; + sheetData[capturedX, capturedY].Expression = edit.Text; + sheetData.Recalculate(); + }; } } - - private void ActualTextEditWidget_EditComplete1(object sender, EventArgs e) - { - if (selectedCell.x == -1) - { - return; - } - - sheetData[selectedCell.x, selectedCell.y].Expression = editSelectedExpression.Text; - CellWidgetsByLocation[(selectedCell.x, selectedCell.y)].Text = editSelectedExpression.Text; - } - - private void SelectedName_EditComplete(object sender, EventArgs e) - { - if (selectedCell.x == -1) - { - return; - } - - var existingNames = new HashSet(); - for (int y = 0; y < sheetData.Height; y++) - { - for (int x = 0; x < sheetData.Width; x++) - { - if (x != selectedCell.x || y != selectedCell.y) - { - var currentName = sheetData[x, y].Name; - if (!string.IsNullOrEmpty(currentName)) - { - existingNames.Add(currentName); - } - } - } - } - - var name = agg_basics.GetNonCollidingName(editSelectedName.Text, existingNames); - editSelectedName.Text = name; - sheetData[selectedCell.x, selectedCell.y].Name = name; - } - private void SelectCell(int x, int y) - { - if (selectedCell.x != -1) - { - CellWidgetsByLocation[(selectedCell.x, selectedCell.y)].BorderColor = Color.Transparent; - } - selectedCell.x = x; - selectedCell.y = y; - CellWidgetsByLocation[(selectedCell.x, selectedCell.y)].BorderColor = theme.PrimaryAccentColor; - editSelectedExpression.Text = sheetData[x, y].Expression; - if (string.IsNullOrEmpty(sheetData[x, y].Name)) - { - editSelectedName.Text = $"{(char)('A' + x)}{y + 1}"; - } - else - { - editSelectedName.Text = sheetData[x, y].Name; - } - } - - private void Recalculate() - { - sheetObject.Invalidate(InvalidateType.SheetUpdated); - } } + private void ActualTextEditWidget_EditComplete1(object sender, EventArgs e) + { + if (selectedCell.x == -1) + { + return; + } + + sheetData[selectedCell.x, selectedCell.y].Expression = editSelectedExpression.Text; + CellWidgetsByLocation[(selectedCell.x, selectedCell.y)].Text = editSelectedExpression.Text; + } + + private void SelectedName_EditComplete(object sender, EventArgs e) + { + if (selectedCell.x == -1) + { + return; + } + + var existingNames = new HashSet(); + for (int y = 0; y < sheetData.Height; y++) + { + for (int x = 0; x < sheetData.Width; x++) + { + if (x != selectedCell.x || y != selectedCell.y) + { + var currentName = sheetData[x, y].Name; + if (!string.IsNullOrEmpty(currentName)) + { + existingNames.Add(currentName); + } + } + } + } + + var name = agg_basics.GetNonCollidingName(editSelectedName.Text, existingNames); + editSelectedName.Text = name; + sheetData[selectedCell.x, selectedCell.y].Name = name; + } + private void SelectCell(int x, int y) + { + if (selectedCell.x != -1) + { + CellWidgetsByLocation[(selectedCell.x, selectedCell.y)].BorderColor = Color.Transparent; + } + selectedCell.x = x; + selectedCell.y = y; + CellWidgetsByLocation[(selectedCell.x, selectedCell.y)].BorderColor = theme.PrimaryAccentColor; + editSelectedExpression.Text = sheetData[x, y].Expression; + if (string.IsNullOrEmpty(sheetData[x, y].Name)) + { + editSelectedName.Text = $"{(char)('A' + x)}{y + 1}"; + } + else + { + editSelectedName.Text = sheetData[x, y].Name; + } + } + } + + public class SheetEditor : IObject3DEditor + { string IObject3DEditor.Name => "Sheet Editor"; IEnumerable IObject3DEditor.SupportedTypes() => new[] { typeof(SheetObject3D) }; public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme) { - return new SheetEditorWidget(item, undoBuffer, theme); + if (item is SheetObject3D sheetObject) + { + return new SheetEditorWidget(sheetObject.SheetData, undoBuffer, theme); + } + + return null; } } } diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index a9e52a7bf..845f98133 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit a9e52a7bfccee5385a25b71d8ca33a92353597b7 +Subproject commit 845f9813383ab1098112cabfb62c3151d129b40e diff --git a/Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs b/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs similarity index 80% rename from Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs rename to Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs index 3f25ee917..b153c56fd 100644 --- a/Tests/MatterControl.AutomationTests/DesignTools/PrimitveTests.cs +++ b/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs @@ -1,11 +1,13 @@ using System.Threading; using System.Threading.Tasks; using MatterHackers.Agg; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; +using MatterHackers.GuiAutomation; using MatterHackers.MatterControl.DesignTools; using MatterHackers.MatterControl.DesignTools.Operations; using MatterHackers.MatterControl.PartPreviewWindow; -using MatterHackers.MatterControl.PrintQueue; using MatterHackers.VectorMath; using NUnit.Framework; @@ -14,6 +16,37 @@ namespace MatterHackers.MatterControl.Tests.Automation [TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)] public class PrimitiveAndSheetsTests { + [Test] + public void SheetEditorLayoutAndNavigation() + { + StaticData.RootPath = TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"); + MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4)); + + var systemWindow = new SystemWindow(800, 600) + { + Name = "Main Window", + }; + + Application.AddTextWidgetRightClickMenu(); + + AutomationRunner.TimeToMoveMouse = .1; + + var sheetData = new SheetData(5, 5); + var undoBuffer = new UndoBuffer(); + var theme = ApplicationController.Instance.Theme; + var sheetEditor = new SheetEditorWidget(sheetData, undoBuffer, theme); + + systemWindow.AddChild(sheetEditor); + + AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testRunner => + { + testRunner.Delay(100); + + return Task.CompletedTask; + }, + 2000); + } + [Test] public async Task DimensionsWorkWhenNoSheet() { diff --git a/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj b/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj index e24bb95f0..fa1e23b1a 100644 --- a/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj +++ b/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj @@ -52,7 +52,7 @@ MatterControlUtilities.cs - + diff --git a/Tests/MatterControl.Tests/MatterControl/MeshRebuildTests.cs b/Tests/MatterControl.Tests/MatterControl/MeshRebuildTests.cs index 73b832306..1589c5992 100644 --- a/Tests/MatterControl.Tests/MatterControl/MeshRebuildTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/MeshRebuildTests.cs @@ -50,9 +50,9 @@ namespace MatterHackers.PolygonMesh.UnitTests // 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(platformFeaturesProvider); - MatterControl.AppContext.Platform.InitPluginFinder(); - MatterControl.AppContext.Platform.ProcessCommandline(); + AppContext.Platform = AggContext.CreateInstanceFrom(platformFeaturesProvider); + AppContext.Platform.InitPluginFinder(); + AppContext.Platform.ProcessCommandline(); } [Test] @@ -81,9 +81,9 @@ namespace MatterHackers.PolygonMesh.UnitTests // 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(platformFeaturesProvider); - MatterControl.AppContext.Platform.InitPluginFinder(); - MatterControl.AppContext.Platform.ProcessCommandline(); + AppContext.Platform = AggContext.CreateInstanceFrom(platformFeaturesProvider); + AppContext.Platform.InitPluginFinder(); + AppContext.Platform.ProcessCommandline(); } [Test] diff --git a/Tests/MatterControl.Tests/MatterControl/SliceSettingsFieldTests.cs b/Tests/MatterControl.Tests/MatterControl/SliceSettingsFieldTests.cs index 959f9e978..4e015303b 100644 --- a/Tests/MatterControl.Tests/MatterControl/SliceSettingsFieldTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/SliceSettingsFieldTests.cs @@ -438,6 +438,8 @@ namespace MatterControl.Tests.MatterControl .ClickByName("Paste Menu Item"); Assert.AreEqual(pastText, textWidget.Text, "Pasted everything"); + // make sure we lose selection if we click off the menu + // cut works testRunner.RightClickByName(GetSliceSettingsField(setting)) .ClickByName("Select All Menu Item")