From 23e7263da516ab107e02b973ef583b7daf4f33f7 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sun, 9 Aug 2020 08:23:22 -0700 Subject: [PATCH] Print recovery test working for dual extruder no probe --- .../WizardPages/SelectMaterialPage.cs | 3 +- .../Widgets/ListView/LibraryListView.cs | 29 ++------ .../PartPreviewWindow/ItemMaterialButton.cs | 5 +- .../PartPreviewWindow/MaterialControls.cs | 7 +- .../PrinterBar/ValidationErrorsPanel.cs | 3 +- Submodules/agg-sharp | 2 +- .../PrintingTests.cs | 68 ++++++++++++------- .../ReSliceTests.cs | 2 +- .../SliceSettingsTests.cs | 8 +-- .../MatterControl/MatterControlUtilities.cs | 63 ++++++++++++++--- 10 files changed, 121 insertions(+), 69 deletions(-) diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs index 97a2ccfda..ff7ce15de 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/SelectMaterialPage.cs @@ -60,7 +60,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling loadFilamentButton.Click += (s, e) => { base.setupWizard.MoveNext(); - if(base.setupWizard.Current is WizardPage wizardPage) + + if (base.setupWizard.Current is WizardPage wizardPage) { this.DialogWindow.ChangeToPage(wizardPage); } diff --git a/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs b/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs index 52b4dece9..36c33eb9b 100644 --- a/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs +++ b/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs @@ -35,6 +35,7 @@ using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; +using MatterHackers.Localizations; using MatterHackers.MatterControl.Library; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrintQueue; @@ -51,8 +52,6 @@ namespace MatterHackers.MatterControl.CustomWidgets private ThemeConfig theme; private ILibraryContext LibraryContext; - private int scrollAmount = -1; - private GuiWidget stashedContentView; private ILibraryContainerLink loadingContainerLink; @@ -133,8 +132,7 @@ namespace MatterHackers.MatterControl.CustomWidgets } // If the current view doesn't match the view requested by the container, construct and switch to the requested view - var targetView = Activator.CreateInstance(targetType) as GuiWidget; - if (targetView != null) + if (Activator.CreateInstance(targetType) is GuiWidget targetView) { this.ListContentView = targetView; } @@ -264,10 +262,11 @@ namespace MatterHackers.MatterControl.CustomWidgets using (contentView.LayoutLock()) { - IEnumerable containerItems = from item in sourceContainer.ChildContainers - where item.IsVisible && this.ContainerFilter(item) - && this.ContainsActiveFilter(item) - select item; + var containerItems = sourceContainer.ChildContainers + .Where(item => item.IsVisible + && this.ContainerFilter(item) + && this.ContainsActiveFilter(item)) + .Select(item => item); // Folder items foreach (var childContainer in this.SortItems(containerItems)) @@ -369,8 +368,6 @@ namespace MatterHackers.MatterControl.CustomWidgets { if (value is IListContentView) { - scrollAmount = -1; - if (contentView != null && contentView != value) { @@ -580,18 +577,6 @@ namespace MatterHackers.MatterControl.CustomWidgets this.Reload().ConfigureAwait(false); } - public override void OnMouseWheel(MouseEventArgs mouseEvent) - { - if (scrollAmount == -1) - { - scrollAmount = (int)(this.contentView.Children.FirstOrDefault()?.Height ?? 20); - } - - int direction = (mouseEvent.WheelDelta > 0) ? -1 : 1; - - ScrollPosition += new Vector2(0, scrollAmount * direction); - } - public override void OnClosed(EventArgs e) { if (this.LibraryContext != null) diff --git a/MatterControlLib/PartPreviewWindow/ItemMaterialButton.cs b/MatterControlLib/PartPreviewWindow/ItemMaterialButton.cs index 82cf1e0da..3cac75d70 100644 --- a/MatterControlLib/PartPreviewWindow/ItemMaterialButton.cs +++ b/MatterControlLib/PartPreviewWindow/ItemMaterialButton.cs @@ -43,7 +43,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private ColorButton materialColorButton; public event EventHandler MaterialChanged; - int currentIndex; + + private int currentIndex; public ItemMaterialButton(ThemeConfig theme, int initialMaterialIndex) { @@ -56,6 +57,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var menuTheme = AppContext.MenuTheme; + this.Name = "ItemMaterialButton"; + this.DynamicPopupContent = () => { var materialControl = new MaterialControls(menuTheme, currentIndex) diff --git a/MatterControlLib/PartPreviewWindow/MaterialControls.cs b/MatterControlLib/PartPreviewWindow/MaterialControls.cs index 3c046e21e..dc249c6e8 100644 --- a/MatterControlLib/PartPreviewWindow/MaterialControls.cs +++ b/MatterControlLib/PartPreviewWindow/MaterialControls.cs @@ -54,8 +54,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow int extruderCount = 4; for (int extruderIndex = -1; extruderIndex < extruderCount; extruderIndex++) { - var name = $"{"Material".Localize()} {extruderIndex +1}"; - if(extruderIndex == -1) + var name = $"{"Material".Localize()} {extruderIndex + 1}"; + if (extruderIndex == -1) { name = "Default".Localize(); } @@ -93,7 +93,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow HAnchor = HAnchor.Fit, VAnchor = VAnchor.Fit, TextColor = theme.TextColor, - Checked = extruderIndex == initialMaterialIndex + Checked = extruderIndex == initialMaterialIndex, + Name = name + " Button" }; materialButtons.Add(radioButton); this.AddChild(radioButton); diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/ValidationErrorsPanel.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/ValidationErrorsPanel.cs index 3031b617f..2960df5a5 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/ValidationErrorsPanel.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/ValidationErrorsPanel.cs @@ -89,7 +89,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { VAnchor = VAnchor.Center, Margin = new BorderDouble(right: 8), - Enabled = action.IsEnabled == null || action.IsEnabled() + Enabled = action.IsEnabled == null || action.IsEnabled(), + Name = action.Title + " Button" }; if (!string.IsNullOrEmpty(action.ID)) diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index ee46a8013..d0ee73eb2 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit ee46a80139064a3c661b25f0bc99b09b4b5ba581 +Subproject commit d0ee73eb25acad88fb93259364b4ddb860385971 diff --git a/Tests/MatterControl.AutomationTests/PrintingTests.cs b/Tests/MatterControl.AutomationTests/PrintingTests.cs index 2029baefd..335097a24 100644 --- a/Tests/MatterControl.AutomationTests/PrintingTests.cs +++ b/Tests/MatterControl.AutomationTests/PrintingTests.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.Tests.Automation // Shorten the delay so the test runs in a reasonable time printer.Connection.TimeToHoldTemperature = 5; - testRunner.StartPrint(); + testRunner.StartPrint(printer); // Wait for print to finish testRunner.WaitForPrintFinished(printer); @@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl.Tests.Automation Assert.Less(printer.Connection.ActualBedTemperature, 10); // Make sure we can run this whole thing again - testRunner.StartPrint(); + testRunner.StartPrint(printer); // Wait for print to finish testRunner.WaitForPrintFinished(printer); @@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.Tests.Automation currentSettings.SetValue(SettingsKey.pause_gcode, ""); currentSettings.SetValue(SettingsKey.resume_gcode, ""); - testRunner.StartPrint(pauseAtLayers: "2"); + testRunner.StartPrint(printer, pauseAtLayers: "2"); testRunner.WaitForName("Yes Button", 20); // the yes button is 'Resume' @@ -125,7 +125,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.Complete9StepLeveling(2); - testRunner.StartPrint(pauseAtLayers: "2"); + testRunner.StartPrint(printer, pauseAtLayers: "2"); testRunner.WaitForName("Yes Button", 20); // the yes button is 'Resume' @@ -154,7 +154,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Cancel Wizard Button"); - testRunner.StartPrint(pauseAtLayers: "2"); + testRunner.StartPrint(printer, pauseAtLayers: "2"); testRunner.WaitForName("Yes Button", 20); // the yes button is 'Resume' @@ -291,7 +291,7 @@ namespace MatterHackers.MatterControl.Tests.Automation // print a part testRunner.AddItemToBedplate(); - testRunner.StartPrint(pauseAtLayers: "2;6"); + testRunner.StartPrint(testRunner.FirstPrinter(), pauseAtLayers: "2;6"); // turn on line error simulation emulator.SimulateLineErrors = true; @@ -329,7 +329,7 @@ namespace MatterHackers.MatterControl.Tests.Automation // print a part testRunner.AddItemToBedplate(); - testRunner.StartPrint(pauseAtLayers: "2"); + testRunner.StartPrint(printer, pauseAtLayers: "2"); ProfileManager.DebugPrinterDelete = true; // Wait for pause dialog @@ -360,7 +360,7 @@ namespace MatterHackers.MatterControl.Tests.Automation // print a part testRunner.AddItemToBedplate() - .StartPrint(pauseAtLayers: "2;4;6") + .StartPrint(printer, pauseAtLayers: "2;4;6") .ClickResumeButton(printer, true, 1) // Resume .ClickResumeButton(printer, false, 3) // close the pause dialog pop-up do not resume .ClickByName("Disconnect from printer button") @@ -381,33 +381,48 @@ namespace MatterHackers.MatterControl.Tests.Automation } [Test, Category("Emulator")] - public async Task ExtruderT1RecoveryTest() + public async Task RecoveryT1NoProbe() + { + await ExtruderT1RecoveryTest("Airwolf 3D", "HD"); + } + + [Test, Category("Emulator")] + public async Task RecoveryT1WithProbe() + { + await ExtruderT1RecoveryTest("Pulse", "S-500"); + } + + public async Task ExtruderT1RecoveryTest(string make, string model) { await MatterControlUtilities.RunTest((testRunner) => { - using (var emulator = testRunner.LaunchAndConnectToPrinterEmulator("Pulse", "S-500")) + using (var emulator = testRunner.LaunchAndConnectToPrinterEmulator(make, model)) { Assert.AreEqual(1, ApplicationController.Instance.ActivePrinters.Count(), "One printer should exist after add"); var printer = testRunner.FirstPrinter(); - printer.Settings.SetValue(SettingsKey.recover_is_enabled, "1"); - printer.Settings.SetValue(SettingsKey.extruder_count, "2"); - printer.Settings.SetValue(SettingsKey.has_hardware_leveling, "0"); + testRunner.ChangeSettings( + new (string, string)[] + { + (SettingsKey.recover_is_enabled, "1"), + (SettingsKey.extruder_count, "2"), + (SettingsKey.has_hardware_leveling, "0"), + }, printer); Assert.IsTrue(printer.Connection.RecoveryIsEnabled); // print a part testRunner.AddItemToBedplate() .ClickByName("ItemMaterialButton") - .ClickByName("Material 2 Button"); - testRunner.StartPrint(pauseAtLayers: "2;4;6"); + .ClickByName("Material 2 Button") + .StartPrint(printer, pauseAtLayers: "2;3;4;5"); testRunner.ClickResumeButton(printer, true, 1); // Resume // make sure we are printing with extruder 2 (T1) Assert.AreEqual(0, printer.Connection.GetTargetHotendTemperature(0)); Assert.Greater(printer.Connection.GetTargetHotendTemperature(1), 0); - testRunner.ClickResumeButton(printer, false, 3) // close the pause dialog pop-up do not resume + testRunner.ClickResumeButton(printer, false, 2) // close the pause dialog pop-up do not resume .ClickByName("Disconnect from printer button") .ClickByName("Connect to printer button") // Reconnect .WaitFor(() => printer.Connection.CommunicationState == CommunicationStates.Connected); @@ -418,12 +433,13 @@ namespace MatterHackers.MatterControl.Tests.Automation // Recover the print testRunner.ClickButton("Yes Button", "Recover Print"); - testRunner.ClickResumeButton(printer, true, 5); // The first pause that we get after recovery should be layer 6. - emulator.RunSlow = true; + // The first pause that we get after recovery should be layer 4 (index 3). + testRunner.ClickResumeButton(printer, true, 3); // make sure we are printing with extruder 2 (T1) Assert.AreEqual(0, printer.Connection.GetTargetHotendTemperature(0)); Assert.Greater(printer.Connection.GetTargetHotendTemperature(1), 0); - emulator.RunSlow = false; + + testRunner.ClickResumeButton(printer, true, 4); testRunner.WaitForPrintFinished(printer); } @@ -459,7 +475,7 @@ namespace MatterHackers.MatterControl.Tests.Automation printFinishedResetEvent.Set(); }; - testRunner.StartPrint() + testRunner.StartPrint(printer) .ScrollIntoView("Extrusion Multiplier NumberEdit") .ScrollIntoView("Feed Rate NumberEdit"); @@ -489,7 +505,7 @@ namespace MatterHackers.MatterControl.Tests.Automation ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate, "After print finished"); testRunner.WaitForPrintFinished(printer) - .StartPrint() // Restart the print + .StartPrint(printer) // Restart the print .Delay(1); // Values should match entered values @@ -537,7 +553,7 @@ namespace MatterHackers.MatterControl.Tests.Automation var printFinishedResetEvent = new AutoResetEvent(false); printer.Connection.PrintFinished += (s, e) => printFinishedResetEvent.Set(); - testRunner.StartPrint(); + testRunner.StartPrint(printer); var container = testRunner.GetWidgetByName("ManualPrinterControls.ControlsContainer", out _, 5); @@ -581,7 +597,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.WaitForPrintFinished(printer); // Values should match entered values - testRunner.StartPrint(); + testRunner.StartPrint(printer); testRunner.WaitFor(() => printer.Connection.CommunicationState == CommunicationStates.Printing, 15); // Values should match entered values @@ -655,7 +671,9 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.AddItemToBedplate(); - testRunner.StartPrint(); + var printer = testRunner.FirstPrinter(); + + testRunner.StartPrint(printer); int fanChangedCount = 0; emulator.FanSpeedChanged += (s, e) => @@ -663,8 +681,6 @@ namespace MatterHackers.MatterControl.Tests.Automation fanChangedCount++; }; - var printer = testRunner.FirstPrinter(); - emulator.WaitForLayer(printer.Settings, 2); emulator.RunSlow = true; diff --git a/Tests/MatterControl.AutomationTests/ReSliceTests.cs b/Tests/MatterControl.AutomationTests/ReSliceTests.cs index bdf1a97c4..f6ae3734a 100644 --- a/Tests/MatterControl.AutomationTests/ReSliceTests.cs +++ b/Tests/MatterControl.AutomationTests/ReSliceTests.cs @@ -94,7 +94,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.ClickByName("Add to Bed Menu Item"); // start the print - testRunner.StartPrint(pauseAtLayers: "50;60"); + testRunner.StartPrint(printer, pauseAtLayers: "50;60"); // Wait for pause testRunner.WaitForName("No Button", 80); // the yes button is 'Resume' diff --git a/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs b/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs index 5a540c4ad..c7c12e978 100644 --- a/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs +++ b/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs @@ -52,11 +52,11 @@ namespace MatterHackers.MatterControl.Tests.Automation using (var emulator = testRunner.LaunchAndConnectToPrinterEmulator()) { - testRunner.AddItemToBedplate(); - testRunner.StartPrint(pauseAtLayers: "4;2;a;not;6"); - var printer = testRunner.FirstPrinter(); + testRunner.AddItemToBedplate(); + testRunner.StartPrint(printer, pauseAtLayers: "4;2;a;not;6"); + WaitForLayerAndResume(testRunner, printer, 2); WaitForLayerAndResume(testRunner, printer, 4); WaitForLayerAndResume(testRunner, printer, 6); @@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.AddItemToBedplate(); - testRunner.StartPrint(pauseAtLayers: "2"); + testRunner.StartPrint(printer, pauseAtLayers: "2"); // Wait for the Ok button testRunner.WaitForName("Yes Button", 30); diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 8fa32ec40..904992531 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -114,6 +114,41 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.Delay(.5); } + public static void ChangeSettings(this AutomationRunner testRunner, + IEnumerable<(string key, string value)> settings, + PrinterConfig printer) + { + bool needReload = false; + + foreach (var setting in settings) + { + if (printer.Settings.GetValue(setting.key) != setting.value + && PrinterSettings.SettingsData[setting.key].ReloadUiWhenChanged) + { + needReload = true; + break; + } + } + + if (needReload) + { + testRunner.WaitForReloadAll(() => + { + foreach (var setting in settings) + { + printer.Settings.SetValue(setting.key, setting.value); + } + }); + } + else + { + foreach (var setting in settings) + { + printer.Settings.SetValue(setting.key, setting.value); + } + } + } + public static void WaitForReloadAll(this AutomationRunner testRunner, Action reloadAllAction) { // Wire up a block and release mechanism to wait until the sign in process has completed @@ -380,8 +415,6 @@ namespace MatterHackers.MatterControl.Tests.Automation return widget.TreeLoaded; }); - testRunner.Delay(1000); - // Apply filter testRunner.ClickByName("Search") .Type(model) @@ -470,7 +503,7 @@ namespace MatterHackers.MatterControl.Tests.Automation { File.WriteAllText(mcpPath, JsonConvert.SerializeObject(new ManifestFile() { - ProjectFiles = new System.Collections.Generic.List() + ProjectFiles = new List() }, Formatting.Indented)); } @@ -919,8 +952,10 @@ namespace MatterHackers.MatterControl.Tests.Automation /// /// The AutomationRunner we are using. /// The string to write into the pause field in the print menu. - /// - public static AutomationRunner StartPrint(this AutomationRunner testRunner, string pauseAtLayers = null) + /// The automation runner to allow fluid design + public static AutomationRunner StartPrint(this AutomationRunner testRunner, + PrinterConfig printer, + string pauseAtLayers = null) { // Open popup testRunner.OpenPrintPopupMenu(); @@ -935,10 +970,20 @@ namespace MatterHackers.MatterControl.Tests.Automation if (testRunner.NameExists("SetupPrinter")) { - testRunner.ClickByName("SetupPrinter") - .ClickByName("Already Loaded Button") - .ClickByName("Cancel Wizard Button") - .OpenPrintPopupMenu(); + if (printer.Settings.GetValue(SettingsKey.use_z_probe)) + { + testRunner.ClickByName("SetupPrinter") + .ClickByName("Already Loaded Button") + .ClickByName("Cancel Wizard Button") + .OpenPrintPopupMenu(); + } + else + { + testRunner.ClickByName("SetupPrinter") + .ClickByName("Already Loaded Button") + .ClickByName("Cancel Wizard Button") + .OpenPrintPopupMenu(); + } } testRunner.ClickByName("Start Print Button");