diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 8ba06472b..e00418c81 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -348,7 +348,7 @@ namespace MatterHackers.MatterControl // PrinterConnection.IsPrinterConnected, that could should be updated to iterate ActiverPrinters, checking each one and acting on each as it would // have for the single case [Obsolete("ActivePrinter references should be migrated to logic than supports multi-printer mode")] - public PrinterConfig ActivePrinter { get; private set; } = PrinterConfig.EmptyPrinter; + public PrinterConfig ActivePrinter => this.ActivePrinters.FirstOrDefault() ?? PrinterConfig.EmptyPrinter; public Action RedeemDesignCode; public Action EnterShareCode; diff --git a/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs b/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs index 972d8de9c..37c628154 100644 --- a/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs +++ b/MatterControlLib/ApplicationView/Themes/ThemeConfig.cs @@ -44,9 +44,9 @@ namespace MatterHackers.MatterControl public class ThemeConfig { - private static ImageBuffer restoreNormal; - private static ImageBuffer restoreHover; - private static ImageBuffer restorePressed; + private ImageBuffer restoreNormal; + private ImageBuffer restoreHover; + private ImageBuffer restorePressed; public int FontSize7 { get; } = 7; public int FontSize8 { get; } = 8; @@ -421,14 +421,9 @@ namespace MatterHackers.MatterControl return imageBuffer; } - public Button CreateSmallResetButton() + public GuiWidget CreateSmallResetButton() { - return new Button( - new ButtonViewStates( - new ImageWidget(restoreNormal), - new ImageWidget(restoreHover), - new ImageWidget(restorePressed), - new ImageWidget(restoreNormal))) + return new HoverImageWidget(restoreNormal, restoreHover) { VAnchor = VAnchor.Center, Margin = new BorderDouble(0, 0, 5, 0) diff --git a/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs b/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs index 468001e76..b3e88d5ec 100644 --- a/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs @@ -515,7 +515,7 @@ namespace MatterHackers.MatterControl.PrintLibrary public class SearchInputBox : GuiWidget { internal MHTextEditWidget searchInput; - public Button ResetButton { get; } + public GuiWidget ResetButton { get; } public SearchInputBox(ThemeConfig theme, string emptyText = null) { diff --git a/MatterControlLib/PrinterControls/ControlWidgets/MovementControls.cs b/MatterControlLib/PrinterControls/ControlWidgets/MovementControls.cs index c238dda76..53ae50da2 100644 --- a/MatterControlLib/PrinterControls/ControlWidgets/MovementControls.cs +++ b/MatterControlLib/PrinterControls/ControlWidgets/MovementControls.cs @@ -248,7 +248,7 @@ namespace MatterHackers.MatterControl.PrinterControls public class ZTuningWidget : GuiWidget { private TextWidget zOffsetStreamDisplay; - private Button clearZOffsetButton; + private GuiWidget clearZOffsetButton; private FlowLayoutWidget zOffsetStreamContainer; private bool allowRemoveButton; diff --git a/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs b/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs index 78db1e5f3..fc0b9b42e 100644 --- a/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs +++ b/MatterControlLib/SlicerConfiguration/SliceSettingsRow.cs @@ -46,7 +46,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private GuiWidget dataArea; private GuiWidget unitsArea; private GuiWidget restoreArea; - private Button restoreButton = null; + private GuiWidget restoreButton = null; public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, ThemeConfig theme, bool fullRowSelect = false) : base (settingData.PresentationName.Localize(), settingData.HelpText.Localize(), theme, fullRowSelect: fullRowSelect) diff --git a/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs b/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs index 7e8cdeccd..187dcb4db 100644 --- a/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs +++ b/Tests/MatterControl.AutomationTests/SliceSettingsTests.cs @@ -6,6 +6,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.GuiAutomation; +using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; using NUnit.Framework; @@ -498,7 +499,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.AddAndSelectPrinter("Airwolf 3D", "HD"); testRunner.SwitchToSliceSettings(); - var printer = ApplicationController.Instance.ActivePrinter; + var printer = ApplicationController.Instance.ActivePrinters.First(); testRunner.SelectSliceSettingsField("Advanced", "layer_height"); testRunner.Type(".5"); @@ -515,17 +516,24 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.WaitFor(() => printer.Settings.GetValue(SettingsKey.layer_height) == 0.1); Assert.AreEqual(printer.Settings.GetValue(SettingsKey.layer_height).ToString(), "0.1", "Layer height is the fine override"); + // Close Airwolf + CloseFirstPrinterTab(testRunner); + testRunner.AddAndSelectPrinter("BCN", "Sigma"); // Check Guest printer count - Assert.AreEqual(2, ProfileManager.Instance.ActiveProfiles.Count(), "ProfileManager has 2 Profiles"); + Assert.AreEqual(2, ProfileManager.Instance.ActiveProfiles.Count(), "ProfileManager has 2 profiles"); + Assert.AreEqual(1, ProfileManager.Instance.OpenPrinterIDs.Count(), "ProfileManager has 1 open profiles"); - // Check if Guest printer names exists in dropdown + // Close BCN + CloseFirstPrinterTab(testRunner); + + // Reopen Airwolf testRunner.SwitchToHardwareTab(); testRunner.DoubleClickByName("Airwolf 3D HD Node"); testRunner.Delay(0.2); - printer = ApplicationController.Instance.ActivePrinter; + printer = ApplicationController.Instance.ActivePrinters.First(); testRunner.WaitFor(() => printer.Settings.GetValue(SettingsKey.layer_height) == 0.1); Assert.AreEqual(printer.Settings.GetValue(SettingsKey.layer_height).ToString(), "0.1", "Layer height is the fine override"); @@ -542,5 +550,30 @@ namespace MatterHackers.MatterControl.Tests.Automation return Task.CompletedTask; }, maxTimeToRun: 120); } + + private void CloseFirstPrinterTab(AutomationRunner testRunner) + { + // Close all printer tabs + var mainViewWidget = testRunner.GetWidgetByName("PartPreviewContent", out _) as MainViewWidget; + if (mainViewWidget.TabControl.AllTabs.First(t => t.TabContent is PrinterTabPage) is GuiWidget widget) + { + var closeWidget = widget.Descendants().First(); + closeWidget.InvokeClick(); + } + } + + private void CloseAllPrinterTabs(AutomationRunner testRunner) + { + // Close all printer tabs + var mainViewWidget = testRunner.GetWidgetByName("PartPreviewContent", out _) as MainViewWidget; + foreach (var tab in mainViewWidget.TabControl.AllTabs.Where(t => t.TabContent is PrinterTabPage).ToList()) + { + if (tab is GuiWidget widget) + { + var closeWidget = widget.Descendants().First(); + closeWidget.InvokeClick(); + } + } + } } } diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 6b5ecdf7b..f181973c2 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -240,7 +240,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.WaitForName("Disconnect from printer button"); testRunner.Delay(); - if (testRunner.NameExists("Already Loaded Button")) + if (testRunner.NamedWidgetExists("Already Loaded Button")) { testRunner.ClickByName("Already Loaded Button"); } @@ -773,7 +773,7 @@ namespace MatterHackers.MatterControl.Tests.Automation /// public static void OpenPrintPopupMenu(this AutomationRunner testRunner) { - var printerConnection = ApplicationController.Instance.ActivePrinter.Connection; + var printerConnection = ApplicationController.Instance.DragDropData.View3DWidget.Printer.Connection; if (printerConnection.CommunicationState != CommunicationStates.Connected && printerConnection.CommunicationState != CommunicationStates.FinishedPrint) @@ -782,6 +782,12 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.WaitFor(() => printerConnection.CommunicationState == CommunicationStates.Connected); } + if (testRunner.NamedWidgetExists("Finish Setup Button")) + { + testRunner.ClickByName("Finish Setup Button"); + testRunner.ClickByName("Already Loaded Button"); + } + // Wait for button to become enabled var printerPopup = testRunner.GetWidgetByName("PrintPopupMenu", out _); testRunner.WaitFor(() => printerPopup.Enabled);