From 2d4f3a4784c4a57c20647acb6a2e8c13e5980d3c Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 14 May 2019 13:02:11 -0700 Subject: [PATCH 1/6] Add Calibrate Printer menu item --- .../View3D/PrinterBar/PrinterActionsBar.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs index 2e9a46fca..a367da47f 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs @@ -303,7 +303,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow SetIsActive = (value) => printer.ViewState.ControlsVisible = value }, new NamedBoolAction() - { + { Title = "Show Terminal".Localize(), Action = () => { }, GetIsActive = () => printer.ViewState.TerminalVisible, @@ -343,6 +343,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, theme.InvertIcons), }, new ActionSeparator(), + + new NamedAction() + { + Title = "Calibrate Printer".Localize(), + Action = () => UiThread.RunOnIdle(() => + { + UiThread.RunOnIdle(() => + { + DialogWindow.Show(new PrinterCalibrationWizard(printer, theme)); + }); + }), + Icon = AggContext.StaticData.LoadIcon("fa-cog_16.png", theme.InvertIcons) + }, + new ActionSeparator(), new NamedAction() { Title = "Restore Settings".Localize(), From 670b988281ef5c7c8bfeb3d8535eb1399bbfa5af Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 14 May 2019 13:03:55 -0700 Subject: [PATCH 2/6] Update target framework --- Tests/MatterControl.Tests/MatterControl.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/MatterControl.Tests/MatterControl.Tests.csproj b/Tests/MatterControl.Tests/MatterControl.Tests.csproj index fe2f5e57e..558b0ea5d 100644 --- a/Tests/MatterControl.Tests/MatterControl.Tests.csproj +++ b/Tests/MatterControl.Tests/MatterControl.Tests.csproj @@ -17,7 +17,7 @@ Properties MatterControl.Tests MatterControl.Tests - v4.7.1 + v4.7.2 512 ..\..\ From 27e38d26084c72cb40573b9339bb8237ecfe501a Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 14 May 2019 15:12:30 -0700 Subject: [PATCH 3/6] Extract WaitForPage for reuse --- .../MatterControl/MatterControlUtilities.cs | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 218cf91a4..c13533057 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -132,6 +132,23 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.Delay(.2); } + public static void WaitForPage(this AutomationRunner testRunner, string headerText) + { + // Helper methods + bool HeaderExists(string text) + { + var header = testRunner.GetWidgetByName("HeaderRow", out _); + var textWidget = header.Children().FirstOrDefault(); + + return textWidget?.Text.StartsWith(text) ?? false; + } + + testRunner.WaitFor(() => HeaderExists(headerText)); + + Assert.IsTrue(HeaderExists(headerText), "Expected page not found: " + headerText); + } + + public static string PathToExportGcodeFolder { get => TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "ExportedGcode", runName); @@ -946,24 +963,9 @@ namespace MatterHackers.MatterControl.Tests.Automation public static void Complete9StepLeveling(this AutomationRunner testRunner, int numUpClicks = 1) { - // Helper methods - bool headerExists(string headerText) - { - var header = testRunner.GetWidgetByName("HeaderRow", out _); - var textWidget = header.Children().FirstOrDefault(); - - return textWidget?.Text.StartsWith(headerText) ?? false; - } - - void waitForPage(string headerText) - { - testRunner.WaitFor(() => headerExists(headerText)); - Assert.IsTrue(headerExists(headerText), "Expected page not found: " + headerText); - } - void waitForPageAndAdvance(string headerText) { - waitForPage(headerText); + testRunner.WaitForPage(headerText); testRunner.ClickByName("Next Button"); } @@ -979,20 +981,20 @@ namespace MatterHackers.MatterControl.Tests.Automation { var section = (i * 3) + 1; - waitForPage($"Step {section} of 9"); + testRunner.WaitForPage($"Step {section} of 9"); for (int j = 0; j < numUpClicks; j++) { testRunner.Delay(); testRunner.ClickByName("Move Z positive"); } - waitForPage($"Step {section} of 9"); + testRunner.WaitForPage($"Step {section} of 9"); testRunner.ClickByName("Next Button"); - waitForPage($"Step {section + 1} of 9"); + testRunner.WaitForPage($"Step {section + 1} of 9"); testRunner.ClickByName("Next Button"); - waitForPage($"Step {section + 2} of 9"); + testRunner.WaitForPage($"Step {section + 2} of 9"); testRunner.ClickByName("Next Button"); } From 8d6a2cec598c743ed5926f13ea9b74da78b8adda Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 14 May 2019 15:18:08 -0700 Subject: [PATCH 4/6] New searchable Add Printer Wizard - Issue MatterHackers/MCCentral#5519 Finish new Add Printer wizard - Issue MatterHackers/MCCentral#3439 Improve printer Make / Model selection for Pulse --- .../CustomWidgets/TreeView/TreeNode.cs | 4 +- .../Library/Widgets/AddPrinterWidget.cs | 401 ++++++++++++++++++ .../SetupStepMakeModelName.cs | 202 +-------- 3 files changed, 427 insertions(+), 180 deletions(-) create mode 100644 MatterControlLib/Library/Widgets/AddPrinterWidget.cs diff --git a/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs b/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs index 1cfc93169..2d39662a4 100644 --- a/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs +++ b/MatterControlLib/CustomWidgets/TreeView/TreeNode.cs @@ -49,12 +49,14 @@ namespace MatterHackers.MatterControl.CustomWidgets private ImageWidget imageWidget; private bool isDirty; - public TreeNode(ThemeConfig theme, bool useIcon = true) + public TreeNode(ThemeConfig theme, bool useIcon = true, TreeNode nodeParent = null) : base(FlowDirection.TopToBottom) { this.HAnchor = HAnchor.Fit | HAnchor.Left; this.VAnchor = VAnchor.Fit; + this.NodeParent = nodeParent; + this.TitleBar = new FlowLayoutWidget(); this.TitleBar.Click += (s, e) => { diff --git a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs new file mode 100644 index 000000000..ece305a79 --- /dev/null +++ b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs @@ -0,0 +1,401 @@ +/* +Copyright (c) 2019, John Lewin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; + +using MatterHackers.Agg; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.ImageProcessing; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; + +namespace MatterHackers.MatterControl.PrintLibrary +{ + public class AddPrinterWidget : FlowLayoutWidget + { + private SectionWidget nameSection; + private SearchInputBox searchBox; + + private TreeView treeView; + private FlowLayoutWidget rootColumn; + private MHTextEditWidget printerNameInput; + private bool usingDefaultName = true; + private ThemeConfig theme; + private TextButton nextButton; + + public AddPrinterWidget(ThemeConfig theme, TextButton nextButton) + : base(FlowDirection.TopToBottom) + { + this.theme = theme; + this.nextButton = nextButton; + this.ExistingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name).ToList(); + + var searchIcon = AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16, theme.InvertIcons).AjustAlpha(0.3); + + searchBox = new SearchInputBox(theme) + { + Name = "Search", + HAnchor = HAnchor.Stretch, + Margin = new BorderDouble(bottom: 4), + }; + + searchBox.ResetButton.Visible = false; + + var searchInput = searchBox.searchInput; + + searchInput.BeforeDraw += (s, e) => + { + if (!searchBox.ResetButton.Visible) + { + e.Graphics2D.Render( + searchIcon, + searchInput.Width - searchIcon.Width - 5, + searchInput.LocalBounds.Bottom + searchInput.Height / 2 - searchIcon.Height / 2); + } + }; + + searchBox.ResetButton.Click += (s, e) => + { + this.ClearSearch(); + }; + + searchBox.searchInput.ActualTextEditWidget.TextChanged += (s, e) => + { + if (string.IsNullOrWhiteSpace(searchBox.Text)) + { + this.ClearSearch(); + } + else + { + this.PerformSearch(); + } + }; + + this.AddChild(searchBox); + + var horizontalSplitter = new Splitter() + { + SplitterDistance = Math.Max(UserSettings.Instance.LibraryViewWidth, 20), + SplitterSize = theme.SplitterWidth, + SplitterBackground = theme.SplitterBackground + }; + horizontalSplitter.AnchorAll(); + + horizontalSplitter.DistanceChanged += (s, e) => + { + UserSettings.Instance.LibraryViewWidth = Math.Max(horizontalSplitter.SplitterDistance, 20); + }; + + this.AddChild(horizontalSplitter); + + treeView = new TreeView(theme) + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Stretch, + }; + treeView.AfterSelect += async (s, e) => + { + nameSection.Enabled = treeView.SelectedNode != null; + this.ClearError(); + + this.PrinterNameError.Visible = false; + + if (nameSection.Enabled + && treeView.SelectedNode.Tag != null) + { + UiThread.RunOnIdle(() => + { + if (usingDefaultName + && treeView.SelectedNode != null) + { + string printerName = treeView.SelectedNode.Tag.ToString(); + + printerNameInput.Text = agg_basics.GetNonCollidingName(printerName, this.ExistingPrinterNames); + + SelectedPrinter = treeView.SelectedNode.Tag as MakeModelInfo; + + nextButton.Enabled = treeView.SelectedNode != null + && !string.IsNullOrWhiteSpace(printerNameInput.Text); + } + }); + } + else + { + nextButton.Enabled = false; + } + }; + horizontalSplitter.Panel1.AddChild(treeView); + + rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Fit, + VAnchor = VAnchor.Fit, + Margin = new BorderDouble(left: 2) + }; + treeView.AddChild(rootColumn); + + UiThread.RunOnIdle(() => + { + foreach (var oem in OemSettings.Instance.OemProfiles.OrderBy(o => o.Key)) + { + var rootNode = this.CreateTreeNode(oem); + rootNode.Expandable = true; + rootNode.TreeView = treeView; + rootNode.Load += (s, e) => + { + rootNode.Image = OemSettings.Instance.GetIcon(oem.Key); + + // Push to children + foreach (var child in rootNode.Nodes) + { + child.Image = rootNode.Image; + } + }; + + rootColumn.AddChild(rootNode); + } + }, 1); + + var container = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Stretch, + Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0) + }; + + nameSection = new SectionWidget("New Printer Name".Localize(), container, theme, expandingContent: false) + { + HAnchor = HAnchor.Stretch, + Padding = theme.ToolbarPadding, + Enabled = false + }; + theme.ApplyBoxStyle(nameSection); + + nameSection.BackgroundColor = theme.MinimalShade; + nameSection.Margin = new BorderDouble(top: theme.DefaultContainerPadding); + + horizontalSplitter.Panel2.Padding = theme.DefaultContainerPadding; + + var panel2Column = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Stretch + }; + + panel2Column.AddChild(new TextWidget("Select a printer to continue".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor)); + panel2Column.AddChild(nameSection); + panel2Column.AddChild(PrinterNameError = new TextWidget("", 0, 0, 10) + { + TextColor = Color.Red, + HAnchor = HAnchor.Stretch, + Margin = new BorderDouble(top: 3) + }); + + horizontalSplitter.Panel2.AddChild(panel2Column); + + printerNameInput = new MHTextEditWidget("", theme) + { + HAnchor = HAnchor.Stretch, + }; + printerNameInput.ActualTextEditWidget.EditComplete += (s, e) => + { + this.ValidateControls(); + this.usingDefaultName = false; + }; + + container.AddChild(printerNameInput); + } + + public IReadOnlyList ExistingPrinterNames { get; private set; } + + public TextWidget PrinterNameError { get; private set; } + + + public bool ValidateControls() + { + bool selectionValid = this.SelectedPrinter is AddPrinterWidget.MakeModelInfo selectedPrinter; + + if (!selectionValid) + { + this.SetError("Invalid printer selection".Localize()); + } + + string printerName = this.NewPrinterName; + + bool nameValid = !string.IsNullOrWhiteSpace(printerName); + + if (!nameValid) + { + this.SetError("Printer name cannot be blank".Localize()); + } + + bool nameIsUnique = !this.ExistingPrinterNames.Any(p => p.Equals(printerName, StringComparison.OrdinalIgnoreCase)); + if (!nameIsUnique) + { + this.SetError("Printer name already exists".Localize()); + } + + bool allValid = selectionValid + && nameValid + && nameIsUnique; + + nextButton.Enabled = allValid; + + if (allValid) + { + this.ClearError(); + } + + return allValid; + } + + internal void SetError(string errorMessage) + { + this.PrinterNameError.Text = errorMessage; + this.PrinterNameError.Visible = true; + } + + private void ClearError() + { + this.PrinterNameError.Text = ""; + this.PrinterNameError.Visible = true; + } + + private TreeNode CreateTreeNode(KeyValuePair> make) + { + var treeNode = new TreeNode(theme) + { + Text = make.Key, + }; + + foreach (var printer in make.Value.OrderBy(p => p.Key)) + { + treeNode.Nodes.Add(new TreeNode(theme, nodeParent: treeNode) + { + Text = printer.Key, + Name = $"Node{make.Key}{printer.Key}", + Tag = new MakeModelInfo() + { + Make = make.Key, + Model = printer.Key + } + }); + } + + return treeNode; + } + + private void PerformSearch() + { + var matches = new List(); + + Console.WriteLine("Filter for: " + searchBox.Text); + + foreach (var rootNode in rootColumn.Children.OfType()) + { + FilterTree(rootNode, searchBox.Text, false, matches); + } + + if (matches.Count == 1) + { + treeView.SelectedNode = matches.First(); + } + else + { + treeView.SelectedNode = null; + } + + searchBox.ResetButton.Visible = true; + } + + private void ClearSearch() + { + foreach (var rootNode in rootColumn.Children.OfType()) + { + ResetTree(rootNode); + } + + searchBox.Text = ""; + searchBox.ResetButton.Visible = false; + treeView.SelectedNode = null; + } + + private void FilterTree(TreeNode context, string filter, bool parentVisible, List matches) + { + bool hasFilterText = context.Text.IndexOf(filter, StringComparison.OrdinalIgnoreCase) != -1; + context.Visible = hasFilterText || parentVisible; + + if (context.Visible + && context.NodeParent != null) + { + context.NodeParent.Visible = true; + context.NodeParent.Expanded = true; + } + + if (context.NodeParent != null + && hasFilterText) + { + matches.Add(context); + } + + foreach (var child in context.Nodes) + { + FilterTree(child, filter, hasFilterText, matches); + } + } + + private void ResetTree(TreeNode context) + { + context.Visible = true; + context.Expanded = false; + + foreach (var child in context.Nodes) + { + ResetTree(child); + } + } + + public MakeModelInfo SelectedPrinter { get; private set; } + + public string NewPrinterName => printerNameInput.Text; + + public class MakeModelInfo + { + public string Make { get; set; } + + public string Model { get; set; } + + public override string ToString() => $"{Make} {Model}"; + } + } +} diff --git a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index f7ddc028f..50555d6c3 100644 --- a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -28,12 +28,12 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.Collections.Generic; using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections @@ -41,85 +41,39 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections // Normally step one of the setup process public class SetupStepMakeModelName : DialogPage { - private FlowLayoutWidget printerModelContainer; - private FlowLayoutWidget printerMakeContainer; - - private MHTextEditWidget printerNameInput; - - private TextWidget printerNameError; - - private GuiWidget nextButton; - + private TextButton nextButton; + private AddPrinterWidget printerPanel; private bool usingDefaultName; private static BorderDouble elementMargin = new BorderDouble(top: 3); - private BoundDropList printerManufacturerSelector; - private BoundDropList printerModelSelector; - - private string activeMake; - private string activeModel; - private string activeName; - private RadioButton createPrinterRadioButton = null; + private RadioButton signInRadioButton; public SetupStepMakeModelName() { bool userIsLoggedIn = !ApplicationController.GuestUserActive?.Invoke() ?? false; this.HeaderText = this.WindowTitle = "Printer Setup".Localize(); + this.WindowSize = new VectorMath.Vector2(800, 600); - var addPrinterColumn = new FlowLayoutWidget(FlowDirection.TopToBottom) + contentRow.BackgroundColor = theme.SectionBackgroundColor; + nextButton = theme.CreateDialogButton("Next".Localize()); + + printerPanel = new AddPrinterWidget(theme, nextButton) { HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit, + VAnchor = VAnchor.Stretch }; - printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), theme, maxHeight: 200) - { - HAnchor = HAnchor.Stretch, - Margin = elementMargin, - Name = "Select Make", - ListSource = OemSettings.Instance.AllOems, - TabStop = true - }; - - printerManufacturerSelector.SelectionChanged += ManufacturerDropList_SelectionChanged; - - printerMakeContainer = CreateSelectionContainer( - "Make".Localize() + ":", - "Select the printer manufacturer".Localize(), - printerManufacturerSelector); - - printerModelSelector = new BoundDropList(string.Format("- {0} -", "Select Model".Localize()), theme, maxHeight: 200) - { - Name = "Select Model", - HAnchor = HAnchor.Stretch, - Margin = elementMargin, - TabStop = true - }; - printerModelSelector.SelectionChanged += ModelDropList_SelectionChanged; - - printerModelContainer = CreateSelectionContainer( - "Model".Localize() + ":", - "Select the printer model".Localize(), - printerModelSelector); - - // Add inputs to main container - addPrinterColumn.AddChild(printerMakeContainer); - addPrinterColumn.AddChild(printerModelContainer); - addPrinterColumn.AddChild(CreatePrinterNameContainer()); - - RadioButton signInRadioButton = null; - if (userIsLoggedIn) { - contentRow.AddChild(addPrinterColumn); + contentRow.AddChild(printerPanel); } else { - contentRow.Padding = 10; - addPrinterColumn.Margin = new BorderDouble(28, 15, 15, 5); + contentRow.Padding = theme.DefaultContainerPadding; + printerPanel.Margin = new BorderDouble(left: 15, top: theme.DefaultContainerPadding); var commonMargin = new BorderDouble(4, 2); @@ -145,14 +99,13 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections createPrinterRadioButton.CheckedStateChanged += (s, e) => { - addPrinterColumn.Enabled = createPrinterRadioButton.Checked; + printerPanel.Enabled = createPrinterRadioButton.Checked; this.SetElementVisibility(); }; - contentRow.AddChild(addPrinterColumn); + contentRow.AddChild(printerPanel); } - nextButton = theme.CreateDialogButton("Next".Localize()); nextButton.Name = "Next Button"; nextButton.Click += (s, e) => UiThread.RunOnIdle(async () => { @@ -168,14 +121,14 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections } else { - bool controlsValid = this.ValidateControls(); - if (controlsValid) + bool controlsValid = printerPanel.ValidateControls(); + if (controlsValid + && printerPanel.SelectedPrinter is AddPrinterWidget.MakeModelInfo selectedPrinter) { - var printer = await ProfileManager.CreatePrinterAsync(activeMake, activeModel, activeName); + var printer = await ProfileManager.CreatePrinterAsync(selectedPrinter.Make, selectedPrinter.Model, printerPanel.NewPrinterName); if (printer == null) { - this.printerNameError.Text = "Error creating profile".Localize(); - this.printerNameError.Visible = true; + printerPanel.SetError("Error creating profile".Localize()); return; } @@ -191,53 +144,13 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections usingDefaultName = true; - if (printerManufacturerSelector.MenuItems.Count == 1) - { - printerManufacturerSelector.SelectedIndex = 0; - } - SetElementVisibility(); } private void SetElementVisibility() { - nextButton.Enabled = createPrinterRadioButton == null - || !createPrinterRadioButton.Checked - || (createPrinterRadioButton.Checked && (activeModel != null && this.activeMake != null)); - } - - private FlowLayoutWidget CreatePrinterNameContainer() - { - TextWidget printerNameLabel = new TextWidget("Name".Localize() + ":", 0, 0, 12) - { - TextColor = theme.TextColor, - HAnchor = HAnchor.Stretch, - Margin = new BorderDouble(0, 4, 0, 1) - }; - - printerNameInput = new MHTextEditWidget("", theme) - { - HAnchor = HAnchor.Stretch, - }; - printerNameInput.KeyPressed += (s, e) => this.usingDefaultName = false; - - printerNameError = new TextWidget("", 0, 0, 10) - { - TextColor = theme.TextColor, - HAnchor = HAnchor.Stretch, - Margin = new BorderDouble(top: 3) - }; - - var container = new FlowLayoutWidget(FlowDirection.TopToBottom) - { - Margin = new BorderDouble(0, 5), - HAnchor = HAnchor.Stretch - }; - container.AddChild(printerNameLabel); - container.AddChild(printerNameInput); - container.AddChild(printerNameError); - - return container; + nextButton.Enabled = signInRadioButton?.Checked == true + || printerPanel.SelectedPrinter != null; } private FlowLayoutWidget CreateSelectionContainer(string labelText, string validationMessage, DropDownList selector) @@ -273,74 +186,5 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections return container; } - - private void ManufacturerDropList_SelectionChanged(object sender, EventArgs e) - { - activeMake = ((DropDownList)sender).SelectedValue; - activeModel = null; - - // Select the dictionary containing the printerName->printerToken mappings for the current OEM - Dictionary printers; - if (!OemSettings.Instance.OemProfiles.TryGetValue(activeMake, out printers)) - { - // Fall back to an empty dictionary if no match - printers = new Dictionary(); - } - - // Models - sort dictionary results by key and assign to .ListSource - printerModelSelector.ListSource = printers.OrderBy(p => p.Key).Select(p => new KeyValuePair(p.Key, p.Value.ProfileToken)).ToList(); - if (printerModelSelector.MenuItems.Count == 1) - { - printerModelSelector.SelectedIndex = 0; - } - - contentRow.Invalidate(); - - SetElementVisibility(); - } - - private void ModelDropList_SelectionChanged(object sender, EventArgs e) - { - UiThread.RunOnIdle(() => - { - DropDownList dropList = (DropDownList)sender; - activeModel = dropList.SelectedLabel; - - SetElementVisibility(); - if (usingDefaultName) - { - // Use ManufacturerDropList.SelectedLabel instead of activeMake to ensure the mapped Unicode values are picked up - string mappedMakeText = printerManufacturerSelector.SelectedLabel; - - var existingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name); - printerNameInput.Text = agg_basics.GetNonCollidingName($"{mappedMakeText} {activeModel}", existingPrinterNames); - } - }); - } - - private bool ValidateControls() - { - if (!string.IsNullOrEmpty(printerNameInput.Text)) - { - activeName = printerNameInput.Text; - - if (this.activeMake == null || activeModel == null) - { - return false; - } - else - { - return true; - } - } - else - { - this.printerNameError.TextColor = Color.Red; - this.printerNameError.Text = "Printer name cannot be blank".Localize(); - this.printerNameError.Visible = true; - - return false; - } - } } } \ No newline at end of file From e83e081983c6abeafedf7538dc6216c7411f2381 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 14 May 2019 15:38:36 -0700 Subject: [PATCH 5/6] Remove one second delay to construct tree --- MatterControlLib/Library/Widgets/AddPrinterWidget.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs index ece305a79..aa0292f2f 100644 --- a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs +++ b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs @@ -185,7 +185,9 @@ namespace MatterHackers.MatterControl.PrintLibrary rootColumn.AddChild(rootNode); } - }, 1); + + this.Enabled = true; + }); var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { From def78f9d42fc13e12cb0d22b210aa98060d6e849 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 14 May 2019 15:41:53 -0700 Subject: [PATCH 6/6] Update Add Printer tests --- .../Library/Widgets/AddPrinterWidget.cs | 6 ++++- .../MatterControl/MatterControlUtilities.cs | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs index aa0292f2f..6c95b8906 100644 --- a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs +++ b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs @@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl.PrintLibrary this.theme = theme; this.nextButton = nextButton; this.ExistingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name).ToList(); + this.Name = "AddPrinterWidget"; + this.TreeLoaded = false; var searchIcon = AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16, theme.InvertIcons).AjustAlpha(0.3); @@ -186,7 +188,7 @@ namespace MatterHackers.MatterControl.PrintLibrary rootColumn.AddChild(rootNode); } - this.Enabled = true; + this.TreeLoaded = true; }); var container = new FlowLayoutWidget(FlowDirection.TopToBottom) @@ -391,6 +393,8 @@ namespace MatterHackers.MatterControl.PrintLibrary public string NewPrinterName => printerNameInput.Text; + public bool TreeLoaded { get; private set; } + public class MakeModelInfo { public string Make { get; set; } diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index c13533057..529709cdd 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -47,6 +47,7 @@ using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.PrinterCommunication.Io; using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.SettingsManagement; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.PrinterEmulator; @@ -357,7 +358,7 @@ namespace MatterHackers.MatterControl.Tests.Automation testRunner.EnsureWelcomePageClosed(); // Click 'Add Printer' if not on screen - if (!testRunner.NameExists("Select Make", 0.2)) + if (!testRunner.NameExists("AddPrinterWidget", 0.2)) { if (!testRunner.NameExists("Create Printer", 0.2)) { @@ -378,18 +379,23 @@ namespace MatterHackers.MatterControl.Tests.Automation } } - testRunner.ClickByName("Select Make"); - testRunner.WaitFor(() => testRunner.ChildExists()); - testRunner.Type(make); - testRunner.Type("{Enter}"); - testRunner.WaitFor(() => !testRunner.ChildExists()); + // Wait for the tree to load before filtering + testRunner.WaitFor(() => + { + var widget = testRunner.GetWidgetByName("AddPrinterWidget", out _) as AddPrinterWidget; + return widget.TreeLoaded; + }); - testRunner.ClickByName("Select Model"); - testRunner.WaitFor(() => testRunner.ChildExists()); + // Apply filter + testRunner.ClickByName("Search"); testRunner.Type(model); testRunner.Type("{Enter}"); - testRunner.WaitFor(() => !testRunner.ChildExists()); + // Click printer node + testRunner.Delay(); + testRunner.ClickByName($"Node{make}{model}"); + + // Continue to next page testRunner.ClickByName("Next Button"); testRunner.Delay();