From 2034c86c3ecf5c83164bb3e806e971b139c8fb2f Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 15 Mar 2022 17:51:28 -0700 Subject: [PATCH] Starting work on new materials selection dialog --- .../ApplicationView/AppViewState.cs | 4 +- .../CustomWidgets/InlineStringEdit.cs | 3 +- .../Library/Widgets/AddMaterialDialog.cs | 147 +++++++ .../Library/Widgets/AddMaterialWidget.cs | 361 ++++++++++++++++++ .../Library/Widgets/AddPrinterWidget.cs | 5 +- .../Library/Widgets/CloneSettingsPage.cs | 2 +- .../Library/Widgets/ContainerTreeNode.cs | 4 +- .../Widgets/HardwarePage/PrintersTabPage.cs | 4 +- .../Library/Widgets/HardwareTreeView.cs | 3 +- .../Library/Widgets/LibraryWidget.cs | 6 +- .../Library/Widgets/PrintLibraryWidget.cs | 3 +- .../Library/Widgets/SearchableTreePanel.cs | 2 +- .../PartPreviewWindow/MainViewWidget.cs | 2 +- .../PartPreviewWindow/SearchPanel.cs | 2 +- .../View3D/PrinterBar/OverflowBar.cs | 2 +- .../PartPreviewWindow/ViewToolBarControls.cs | 2 +- .../SetupStepMakeModelName.cs | 2 +- MatterControlLib/SetupWizard/HelpTreePanel.cs | 2 +- .../SetupWizard/Printer/OpenPrinterPage.cs | 2 +- .../Printer/SelectPrinterProfilePage.cs | 2 +- .../PresetSelectorWidget.cs | 43 ++- .../SliceSettingsWidget.cs | 2 +- StaticData/Translations/Master.txt | 6 + .../MatterControl/MatterControlUtilities.cs | 2 +- 24 files changed, 568 insertions(+), 45 deletions(-) create mode 100644 MatterControlLib/Library/Widgets/AddMaterialDialog.cs create mode 100644 MatterControlLib/Library/Widgets/AddMaterialWidget.cs diff --git a/MatterControlLib/ApplicationView/AppViewState.cs b/MatterControlLib/ApplicationView/AppViewState.cs index 704255096..09c66d238 100644 --- a/MatterControlLib/ApplicationView/AppViewState.cs +++ b/MatterControlLib/ApplicationView/AppViewState.cs @@ -28,10 +28,10 @@ either expressed or implied, of the FreeBSD Project. */ +using MatterHackers.MatterControl.Library.Widgets; + namespace MatterHackers.MatterControl { - using MatterHackers.MatterControl.PrintLibrary; - public class AppViewState { public PrintLibraryWidget.ListViewModes LibraryViewMode { get; set; } = PrintLibraryWidget.ListViewModes.IconListView; diff --git a/MatterControlLib/CustomWidgets/InlineStringEdit.cs b/MatterControlLib/CustomWidgets/InlineStringEdit.cs index 7d940f3f4..6bb1236b0 100644 --- a/MatterControlLib/CustomWidgets/InlineStringEdit.cs +++ b/MatterControlLib/CustomWidgets/InlineStringEdit.cs @@ -34,8 +34,7 @@ using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using MatterHackers.Localizations; -using MatterHackers.MatterControl.PartPreviewWindow; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.CustomWidgets diff --git a/MatterControlLib/Library/Widgets/AddMaterialDialog.cs b/MatterControlLib/Library/Widgets/AddMaterialDialog.cs new file mode 100644 index 000000000..de94e7f1d --- /dev/null +++ b/MatterControlLib/Library/Widgets/AddMaterialDialog.cs @@ -0,0 +1,147 @@ +/* +Copyright (c) 2022, John Lewin, Lars Brubaker +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 MatterHackers.Agg; +using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.SlicerConfiguration; +using System; + +namespace MatterHackers.MatterControl.Library.Widgets +{ + public class AddMaterialDialog : DialogPage + { + private readonly RadioButton createPrinterRadioButton = null; + private readonly AddMaterialWidget materialPanel; + private readonly TextButton nextButton; + + public AddMaterialDialog(Action addMaterial) + { + bool userIsLoggedIn = !ApplicationController.GuestUserActive?.Invoke() ?? false; + + this.HeaderText = this.WindowTitle = "Printer Setup".Localize(); + this.WindowSize = new VectorMath.Vector2(800 * GuiWidget.DeviceScale, 600 * GuiWidget.DeviceScale); + + contentRow.BackgroundColor = theme.SectionBackgroundColor; + nextButton = theme.CreateDialogButton("Next".Localize()); + + materialPanel = new AddMaterialWidget(nextButton, theme, (enabled) => + { + nextButton.Enabled = enabled; + }) + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Stretch + }; + + if (userIsLoggedIn) + { + contentRow.AddChild(materialPanel); + contentRow.Padding = 0; + } + else + { + contentRow.Padding = theme.DefaultContainerPadding; + materialPanel.Margin = new BorderDouble(left: 15, top: theme.DefaultContainerPadding); + + var commonMargin = new BorderDouble(4, 2); + + // Create export button for each plugin + createPrinterRadioButton = new RadioButton(new RadioButtonViewText("Create a new printer", theme.TextColor)) + { + HAnchor = HAnchor.Left, + Margin = commonMargin, + Cursor = Cursors.Hand, + Name = "Create Printer Radio Button", + Checked = true + }; + contentRow.AddChild(createPrinterRadioButton); + + createPrinterRadioButton.CheckedStateChanged += (s, e) => + { + materialPanel.Enabled = createPrinterRadioButton.Checked; + this.SetElementVisibility(); + }; + + contentRow.AddChild(materialPanel); + } + + nextButton.Name = "Next Button"; + nextButton.Click += (s, e) => UiThread.RunOnIdle(async () => + { + bool controlsValid = materialPanel.ValidateControls(); + if (controlsValid + && materialPanel.SelectedPrinter is AddPrinterWidget.MakeModelInfo selectedPrinter) + { + var printer = await ProfileManager.CreatePrinterAsync(selectedPrinter.Make, selectedPrinter.Model, materialPanel.NewPrinterName); + if (printer == null) + { + materialPanel.SetError("Error creating profile".Localize()); + return; + } + + UiThread.RunOnIdle(() => + { + DialogWindow.ChangeToPage(AppContext.Platform.GetConnectDevicePage(printer) as DialogPage); + }); + } + }); + + var printerNotListedButton = theme.CreateDialogButton("Define New".Localize()); + printerNotListedButton.ToolTipText = "Select this option only if your printer does not appear in the list".Localize(); + + printerNotListedButton.Click += async (s, e) => + { + var printer = await ProfileManager.CreatePrinterAsync("Other", "Other", "Custom Printer"); + if (printer == null) + { + materialPanel.SetError("Error creating profile".Localize()); + return; + } + + UiThread.RunOnIdle(() => + { + DialogWindow.ChangeToPage(new SetupCustomPrinter(printer) as DialogPage); + }); + }; + + this.AddPageAction(printerNotListedButton, false); + this.AddPageAction(nextButton); + + SetElementVisibility(); + } + + private void SetElementVisibility() + { + nextButton.Enabled = materialPanel.SelectedPrinter != null; + } + } +} \ No newline at end of file diff --git a/MatterControlLib/Library/Widgets/AddMaterialWidget.cs b/MatterControlLib/Library/Widgets/AddMaterialWidget.cs new file mode 100644 index 000000000..1de71e283 --- /dev/null +++ b/MatterControlLib/Library/Widgets/AddMaterialWidget.cs @@ -0,0 +1,361 @@ +/* +Copyright (c) 2022, John Lewin, Lars Brubaker +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 MatterHackers.Agg; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.Library.Widgets.HardwarePage; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using System; +using System.Collections.Generic; +using System.Linq; +using static MatterHackers.MatterControl.Library.Widgets.AddPrinterWidget; + +namespace MatterHackers.MatterControl.Library.Widgets +{ + public class AddMaterialWidget : SearchableTreePanel + { + private SectionWidget nameSection; + private Action nextButtonEnabled; + private FlowLayoutWidget printerInfo; + private MHTextEditWidget printerNameInput; + private bool usingDefaultName = true; + + public AddMaterialWidget(GuiWidget nextButton, ThemeConfig theme, Action nextButtonEnabled) + : base(theme) + { + this.nextButtonEnabled = nextButtonEnabled; + this.ExistingPrinterNames = new HashSet(ProfileManager.Instance.ActiveProfiles.Select(p => p.Name)); + this.Name = "AddPrinterWidget"; + + horizontalSplitter.Panel2.Padding = theme.DefaultContainerPadding; + + treeView.AfterSelect += this.TreeView_AfterSelect; + + treeView.NodeMouseDoubleClick += (s, e) => + { + if (e is MouseEventArgs mouseEvent + && mouseEvent.Button == MouseButtons.Left + && mouseEvent.Clicks == 2 + && treeView?.SelectedNode is TreeNode treeNode) + { + nextButton.InvokeClick(); + } + }; + + 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) => + { + var image = OemSettings.Instance.GetIcon(oem.Key, theme); + + SetImage(rootNode, image); + }; + + contentPanel.AddChild(rootNode); + } + + this.TreeLoaded = true; + }); + + var container = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Stretch, + Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0) + }; + + 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)); + + nameSection = new SectionWidget("New Printer Name".Localize(), container, theme, expandingContent: false) + { + HAnchor = HAnchor.Stretch, + Padding = theme.ToolbarPadding, + Enabled = false + }; + theme.ApplyBoxStyle(nameSection); + + // Reset right margin + nameSection.Margin = nameSection.Margin.Clone(right: theme.DefaultContainerPadding); + + printerInfo = new FlowLayoutWidget() + { + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Stretch + }; + + nameSection.BackgroundColor = theme.MinimalShade; + nameSection.Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(left: 0); + panel2Column.AddChild(nameSection); + + panel2Column.AddChild(PrinterNameError = new TextWidget("", 0, 0, 10) + { + TextColor = Color.Red, + HAnchor = HAnchor.Stretch, + Margin = new BorderDouble(top: 3) + }); + + // Padding allows space for scrollbar + printerInfo.Padding = new BorderDouble(right: theme.DefaultContainerPadding + 2); + + panel2Column.AddChild(printerInfo); + + horizontalSplitter.Panel2.Padding = horizontalSplitter.Panel2.Padding.Clone(right: 0, bottom: 0); + + 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 HashSet ExistingPrinterNames { get; private set; } + + public string NewPrinterName => printerNameInput.Text; + + public TextWidget PrinterNameError { get; private set; } + + public MakeModelInfo SelectedPrinter { get; private set; } + + public bool ValidateControls() + { + bool selectionValid = this.SelectedPrinter is 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; + + nextButtonEnabled(allValid); + + if (allValid) + { + this.ClearError(); + } + + return allValid; + } + + internal void SetError(string errorMessage) + { + this.PrinterNameError.Text = errorMessage; + this.PrinterNameError.Visible = true; + } + + protected override bool FilterTree(TreeNode context, string filter, bool parentVisible, List matches) + { + // Filter against make/model for printers or make for top level nodes + string itemText = (context.Tag as MakeModelInfo)?.ToString() ?? context.Text; + + bool hasFilterText = itemText.IndexOf(filter, StringComparison.OrdinalIgnoreCase) != -1; + context.Visible = hasFilterText || parentVisible; + + if (context.Visible + && context.NodeParent != null) + { + context.NodeParent.Visible = true; + context.NodeParent.Expanded = true; + context.Expanded = true; + } + + if (context.NodeParent != null + && hasFilterText) + { + matches.Add(context); + } + + bool childMatched = false; + + foreach (var child in context.Nodes) + { + childMatched |= FilterTree(child, filter, hasFilterText || parentVisible, matches); + } + + bool hasMatch = childMatched || hasFilterText; + + if (hasMatch) + { + context.Visible = context.Expanded = true; + } + + return hasMatch; + } + + private static void SetImage(TreeNode node, ImageBuffer image) + { + node.Image = image; + + // Push to children + foreach (var child in node.Nodes) + { + SetImage(child, image); + } + } + + private void ClearError() + { + this.PrinterNameError.Text = ""; + this.PrinterNameError.Visible = true; + } + + private TreeNode CreateTreeNode(KeyValuePair> make) + { + var treeNode = new TreeNode(theme) + { + Text = make.Key, + }; + + string currentGroup = ""; + + var context = treeNode; + + foreach (var printer in make.Value.OrderBy(p => p.Key)) + { + if (make.Key == "Pulse" + && currentGroup != printer.Key[0] + " Series") + { + currentGroup = printer.Key[0] + " Series"; + + treeNode.Nodes.Add(context = new TreeNode(theme, nodeParent: treeNode) + { + Text = currentGroup, + }); + } + + context.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 TreeView_AfterSelect(object sender, TreeNode 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); + + this.SelectedPrinter = treeView.SelectedNode.Tag as MakeModelInfo; + + printerInfo.CloseChildren(); + + if (this.SelectedPrinter != null + && OemSettings.Instance.OemPrinters.TryGetValue($"{SelectedPrinter.Make}-{ SelectedPrinter.Model}", out StorePrinterID storePrinterID)) + { + printerInfo.AddChild( + new PrinterDetails( + new PrinterInfo() + { + Make = SelectedPrinter.Make, + Model = SelectedPrinter.Model, + }, + theme, + false) + { + ShowProducts = false, + ShowHeadingRow = false, + StoreID = storePrinterID?.SID, + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Stretch + }); + } + + nextButtonEnabled(treeView.SelectedNode != null + && !string.IsNullOrWhiteSpace(printerNameInput.Text)); + } + }); + } + else + { + nextButtonEnabled(false); + } + } + } +} \ No newline at end of file diff --git a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs index c2de3df55..898a7d495 100644 --- a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs +++ b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2019, John Lewin +Copyright (c) 2022, John Lewin, Lars Brubaker All rights reserved. Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ using MatterHackers.MatterControl.Library.Widgets.HardwarePage; using MatterHackers.MatterControl.SettingsManagement; using MatterHackers.MatterControl.SlicerConfiguration; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public class AddPrinterWidget : SearchableTreePanel { @@ -81,6 +81,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { continue; } + var rootNode = this.CreateTreeNode(oem); rootNode.Expandable = true; rootNode.TreeView = treeView; diff --git a/MatterControlLib/Library/Widgets/CloneSettingsPage.cs b/MatterControlLib/Library/Widgets/CloneSettingsPage.cs index c5bc524eb..9a5020d44 100644 --- a/MatterControlLib/Library/Widgets/CloneSettingsPage.cs +++ b/MatterControlLib/Library/Widgets/CloneSettingsPage.cs @@ -37,7 +37,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.SlicerConfiguration; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public class CloneSettingsPage : DialogPage { diff --git a/MatterControlLib/Library/Widgets/ContainerTreeNode.cs b/MatterControlLib/Library/Widgets/ContainerTreeNode.cs index 58acbca05..7c31e3038 100644 --- a/MatterControlLib/Library/Widgets/ContainerTreeNode.cs +++ b/MatterControlLib/Library/Widgets/ContainerTreeNode.cs @@ -28,11 +28,9 @@ either expressed or implied, of the FreeBSD Project. */ -using System; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.Library; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public class ContainerTreeNode : TreeNode { diff --git a/MatterControlLib/Library/Widgets/HardwarePage/PrintersTabPage.cs b/MatterControlLib/Library/Widgets/HardwarePage/PrintersTabPage.cs index 16cfea42f..e9b743361 100644 --- a/MatterControlLib/Library/Widgets/HardwarePage/PrintersTabPage.cs +++ b/MatterControlLib/Library/Widgets/HardwarePage/PrintersTabPage.cs @@ -34,9 +34,9 @@ using MatterHackers.MatterControl.Library.Widgets.HardwarePage; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.SlicerConfiguration; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { - public class PrintersTabPage : FlowLayoutWidget + public class PrintersTabPage : FlowLayoutWidget { public PrintersTabPage(ThemeConfig theme) : base (FlowDirection.TopToBottom) diff --git a/MatterControlLib/Library/Widgets/HardwareTreeView.cs b/MatterControlLib/Library/Widgets/HardwareTreeView.cs index 287164413..9b1b1ef52 100644 --- a/MatterControlLib/Library/Widgets/HardwareTreeView.cs +++ b/MatterControlLib/Library/Widgets/HardwareTreeView.cs @@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.IO; using System.Linq; using MatterHackers.Agg; @@ -41,7 +40,7 @@ using MatterHackers.MatterControl.PrinterControls.PrinterConnections; using MatterHackers.MatterControl.SettingsManagement; using MatterHackers.MatterControl.SlicerConfiguration; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public class HardwareTreeView : TreeView { diff --git a/MatterControlLib/Library/Widgets/LibraryWidget.cs b/MatterControlLib/Library/Widgets/LibraryWidget.cs index 41a433cf4..138c9ab5d 100644 --- a/MatterControlLib/Library/Widgets/LibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/LibraryWidget.cs @@ -32,7 +32,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; using System.Threading.Tasks; using MatterHackers.Agg; @@ -41,13 +40,12 @@ using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.Library; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.PrintQueue; -using static MatterHackers.MatterControl.PrintLibrary.PrintLibraryWidget; +using static MatterHackers.MatterControl.Library.Widgets.PrintLibraryWidget; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public class LibraryWidget : GuiWidget { diff --git a/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs b/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs index 22a43a6af..0cda5329b 100644 --- a/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs @@ -38,11 +38,10 @@ using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.Library; using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrintQueue; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public class PrintLibraryWidget : GuiWidget, IIgnoredPopupChild { diff --git a/MatterControlLib/Library/Widgets/SearchableTreePanel.cs b/MatterControlLib/Library/Widgets/SearchableTreePanel.cs index dc81bb5f1..d6be44ef8 100644 --- a/MatterControlLib/Library/Widgets/SearchableTreePanel.cs +++ b/MatterControlLib/Library/Widgets/SearchableTreePanel.cs @@ -37,7 +37,7 @@ using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using MatterHackers.MatterControl.CustomWidgets; -namespace MatterHackers.MatterControl.PrintLibrary +namespace MatterHackers.MatterControl.Library.Widgets { public abstract class SearchableTreePanel : FlowLayoutWidget { diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index 36f9004c2..c0d74d045 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -43,8 +43,8 @@ using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.MatterControl.PartPreviewWindow.PlusTab; -using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; diff --git a/MatterControlLib/PartPreviewWindow/SearchPanel.cs b/MatterControlLib/PartPreviewWindow/SearchPanel.cs index 31d9d6af7..03b985546 100644 --- a/MatterControlLib/PartPreviewWindow/SearchPanel.cs +++ b/MatterControlLib/PartPreviewWindow/SearchPanel.cs @@ -36,7 +36,7 @@ using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs index 63211fbb6..63d239673 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs @@ -38,7 +38,7 @@ using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; namespace MatterHackers.MatterControl.PartPreviewWindow { diff --git a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs index 6a3a2e333..114d27d50 100644 --- a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs +++ b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs @@ -41,7 +41,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.Library; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; diff --git a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index 96abbafd1..919ad280f 100644 --- a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -31,7 +31,7 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections diff --git a/MatterControlLib/SetupWizard/HelpTreePanel.cs b/MatterControlLib/SetupWizard/HelpTreePanel.cs index 0ac404a7f..fa3c243bf 100644 --- a/MatterControlLib/SetupWizard/HelpTreePanel.cs +++ b/MatterControlLib/SetupWizard/HelpTreePanel.cs @@ -38,7 +38,7 @@ using MatterHackers.Agg.Image; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; namespace MatterHackers.MatterControl { diff --git a/MatterControlLib/SetupWizard/Printer/OpenPrinterPage.cs b/MatterControlLib/SetupWizard/Printer/OpenPrinterPage.cs index b1d071765..11d611a35 100644 --- a/MatterControlLib/SetupWizard/Printer/OpenPrinterPage.cs +++ b/MatterControlLib/SetupWizard/Printer/OpenPrinterPage.cs @@ -34,7 +34,7 @@ using MatterHackers.Agg.UI; using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl diff --git a/MatterControlLib/SetupWizard/Printer/SelectPrinterProfilePage.cs b/MatterControlLib/SetupWizard/Printer/SelectPrinterProfilePage.cs index 6afbbbda2..9b7f69614 100644 --- a/MatterControlLib/SetupWizard/Printer/SelectPrinterProfilePage.cs +++ b/MatterControlLib/SetupWizard/Printer/SelectPrinterProfilePage.cs @@ -29,7 +29,7 @@ either expressed or implied, of the FreeBSD Project. using System; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintLibrary; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl diff --git a/MatterControlLib/SlicerConfiguration/PresetSelectorWidget.cs b/MatterControlLib/SlicerConfiguration/PresetSelectorWidget.cs index 623bd963e..17a70d691 100644 --- a/MatterControlLib/SlicerConfiguration/PresetSelectorWidget.cs +++ b/MatterControlLib/SlicerConfiguration/PresetSelectorWidget.cs @@ -38,6 +38,7 @@ using MatterHackers.Agg.VertexSource; using MatterHackers.ImageProcessing; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.SlicerConfiguration @@ -261,30 +262,39 @@ namespace MatterHackers.MatterControl.SlicerConfiguration menuItem.Selected += MenuItem_Selected; } + var addString = layerType == NamedSettingsLayers.Material ? "New Material".Localize() : "New Quality Setting".Localize(); + + MenuItem addNewPreset = dropDownList.AddItem( StaticData.Instance.LoadIcon("icon_plus.png", 16, 16), - "Add New Setting".Localize() + "...", + addString + "...", "new", pointSize: theme.DefaultFontSize); + addNewPreset.Selected += (s, e) => { - var newLayer = new PrinterSettingsLayer(); - if (layerType == NamedSettingsLayers.Quality) + if (layerType == NamedSettingsLayers.Material) { - newLayer.Name = "Quality" + printer.Settings.QualityLayers.Count; - printer.Settings.QualityLayers.Add(newLayer); - printer.Settings.ActiveQualityKey = newLayer.LayerID; + var window = DialogWindow.Show(new AddMaterialDialog((newMaterial) => + { + newMaterial.Name = "Material" + printer.Settings.MaterialLayers.Count; + printer.Settings.MaterialLayers.Add(newMaterial); + printer.Settings.ActiveMaterialKey = newMaterial.LayerID; + + RebuildDropDownList(); + })); } else { - newLayer.Name = "Material" + printer.Settings.MaterialLayers.Count; - printer.Settings.MaterialLayers.Add(newLayer); - printer.Settings.ActiveMaterialKey = newLayer.LayerID; + var newLayer = new PrinterSettingsLayer(); + newLayer.Name = "Quality" + printer.Settings.QualityLayers.Count; + printer.Settings.QualityLayers.Add(newLayer); + printer.Settings.ActiveQualityKey = newLayer.LayerID; + + RebuildDropDownList(); + + editButton.InvokeClick(); } - - RebuildDropDownList(); - - editButton.InvokeClick(); }; try @@ -350,7 +360,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return dropDownList; } - private void MenuItem_Selected(object sender, EventArgs e) + private void CopyPlateToPrinter(object sceneContext, PrinterConfig printer) + { + throw new NotImplementedException(); + } + + private void MenuItem_Selected(object sender, EventArgs e) { // When a preset is selected store the current values of all known settings to compare against after applying the preset Dictionary settingBeforeChange = new Dictionary(); diff --git a/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs b/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs index edc3ad7a7..04273c2ac 100644 --- a/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs +++ b/MatterControlLib/SlicerConfiguration/SliceSettingsWidget.cs @@ -35,8 +35,8 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.Library.Widgets; using MatterHackers.MatterControl.PartPreviewWindow; -using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.SlicerConfiguration diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index f46248a57..4046083f5 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -2953,12 +2953,18 @@ Translated:Networked Printing English:New Design Translated:New Design +English:New Material +Translated:New Material + English:New Password Translated:New Password English:New Printer Name Translated:New Printer Name +English:New Quality Setting +Translated:New Quality Setting + English:New updates are ready to install Translated:New updates are ready to install diff --git a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs index 9deb81550..d7b1bc64a 100644 --- a/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs +++ b/Tests/MatterControl.Tests/MatterControl/MatterControlUtilities.cs @@ -45,11 +45,11 @@ using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.DesignTools.Operations; using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.Library.Widgets; 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;