diff --git a/CustomWidgets/FlowSpacers.cs b/CustomWidgets/FlowSpacers.cs index 2101543a0..d7fb513b1 100644 --- a/CustomWidgets/FlowSpacers.cs +++ b/CustomWidgets/FlowSpacers.cs @@ -50,10 +50,10 @@ namespace MatterHackers.MatterControl.CustomWidgets public class HorizontalLine : GuiWidget { - public HorizontalLine(int alpha = 255, int height = 1) + public HorizontalLine(int alpha = 255, int height = 1, ThemeConfig theme = null) : base(1, height) { - BackgroundColor = ApplicationController.Instance.Theme.GetBorderColor(alpha); + BackgroundColor = (theme ?? ApplicationController.Instance.Theme).GetBorderColor(alpha); HAnchor = HAnchor.Stretch; } } diff --git a/EeProm/EePromMarlinWindow.cs b/EeProm/EePromMarlinWindow.cs index 1410dacf1..d149ba26d 100644 --- a/EeProm/EePromMarlinWindow.cs +++ b/EeProm/EePromMarlinWindow.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2014, Lars Brubaker +Copyright (c) 2018, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -33,11 +33,13 @@ using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; +using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.EeProm { - public partial class EePromMarlinWindow : CloseOnDisconnectWindow + public class MarlinEEPromPage : EEPromPage { private EePromMarlinSettings currentEePromSettings; @@ -82,65 +84,28 @@ namespace MatterHackers.MatterControl.EeProm private EventHandler unregisterEvents; - private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); private double maxWidthOfLeftStuff = 0; private List leftStuffToSize = new List(); private int currentTabIndex = 0; - public EePromMarlinWindow(PrinterConnection printerConnection) - : base(printerConnection, 650 * GuiWidget.DeviceScale, 480 * GuiWidget.DeviceScale) + public MarlinEEPromPage(PrinterConfig printer) + : base(printer) { AlwaysOnTopOfMain = true; - Title = "Marlin Firmware EEPROM Settings".Localize(); + this.WindowTitle = "Marlin Firmware EEPROM Settings".Localize(); - currentEePromSettings = new EePromMarlinSettings(printerConnection); + currentEePromSettings = new EePromMarlinSettings(printer.Connection); currentEePromSettings.eventAdded += SetUiToPrinterSettings; - GuiWidget mainContainer = new GuiWidget(); - mainContainer.AnchorAll(); - mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - mainContainer.Padding = new BorderDouble(3, 0); - - // space filling color - GuiWidget spaceFiller = new GuiWidget(0, 500); - spaceFiller.VAnchor = VAnchor.Bottom; - spaceFiller.HAnchor = HAnchor.Stretch; - spaceFiller.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; - spaceFiller.Padding = new BorderDouble(top: 3); - mainContainer.AddChild(spaceFiller); - - double topBarHeight = 0; - // the top button bar - { - FlowLayoutWidget topButtonBar = new FlowLayoutWidget(); - topButtonBar.HAnchor = HAnchor.Stretch; - topButtonBar.VAnchor = VAnchor.Fit | VAnchor.Top; - topButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - - topButtonBar.Margin = new BorderDouble(0, 3); - - Button buttonSetToFactorySettings = textImageButtonFactory.Generate("Reset to Factory Defaults".Localize()); - topButtonBar.AddChild(buttonSetToFactorySettings); - - buttonSetToFactorySettings.Click += (sender, e) => - { - currentEePromSettings.SetPrinterToFactorySettings(); - currentEePromSettings.Update(); - }; - - mainContainer.AddChild(topButtonBar); - - topBarHeight = topButtonBar.Height; - } + var mainContainer = contentRow; // the center content - FlowLayoutWidget conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom); - conterContent.VAnchor = VAnchor.Fit | VAnchor.Top; - conterContent.HAnchor = HAnchor.Stretch; - conterContent.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; - conterContent.Padding = new BorderDouble(top: 3); - conterContent.Margin = new BorderDouble(top: topBarHeight); + var conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + VAnchor = VAnchor.Fit | VAnchor.Top, + HAnchor = HAnchor.Stretch + }; conterContent.AddChild(Create4FieldSet("Steps per mm".Localize() + ":", "X:", ref stepsPerMmX, @@ -186,22 +151,12 @@ namespace MatterHackers.MatterControl.EeProm conterContent.AddChild(CreateField("Maximum Z jerk [mm/s]".Localize() + ":", ref maxZJerk)); conterContent.AddChild(CreateField("Maximum E jerk [mm/s]".Localize() + ":", ref maxEJerk)); - GuiWidget topBottomSpacer = new GuiWidget(1, 1); - topBottomSpacer.VAnchor = VAnchor.Stretch; - conterContent.AddChild(topBottomSpacer); - mainContainer.AddChild(conterContent); // the bottom button bar { - FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget(); - bottomButtonBar.HAnchor = Agg.UI.HAnchor.MaxFitOrStretch; - bottomButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - bottomButtonBar.Margin = new BorderDouble(0, 3); - - Button buttonSave = textImageButtonFactory.Generate("Save to EEProm".Localize()); - bottomButtonBar.AddChild(buttonSave); - buttonSave.Click += (sender, e) => + var buttonSave = theme.CreateDialogButton("Save to EEProm".Localize()); + buttonSave.Click += (s, e) => { UiThread.RunOnIdle(() => { @@ -210,15 +165,28 @@ namespace MatterHackers.MatterControl.EeProm Close(); }); }; + this.AddPageAction(buttonSave); - CreateSpacer(bottomButtonBar); - - // put in the import button -#if true + var exportButton = theme.CreateDialogButton("Export".Localize()); + exportButton.Click += (s, e) => { - Button buttonImport = textImageButtonFactory.Generate("Import".Localize() + "..."); - buttonImport.Margin = new BorderDouble(0, 3); - buttonImport.Click += (sender, e) => + UiThread.RunOnIdle(this.ExportSettings, .1); + }; + this.AddPageAction(exportButton); + } + + printer.Connection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents); + + // and ask the printer to send the settings + currentEePromSettings.Update(); + + if (headerRow is OverflowBar overflowBar) + { + overflowBar.ExtendOverflowMenu = (popupMenu) => + { + var menuItem = popupMenu.CreateMenuItem("Import".Localize()); + menuItem.Name = "Import Menu Item"; + menuItem.Click += (s, e) => { UiThread.RunOnIdle(() => { @@ -228,77 +196,72 @@ namespace MatterHackers.MatterControl.EeProm ActionButtonLabel = "Import EEPROM Settings".Localize(), Title = "Import EEPROM".Localize(), }, - (openParams) => - { - if (!string.IsNullOrEmpty(openParams.FileName)) - { - currentEePromSettings.Import(openParams.FileName); - SetUiToPrinterSettings(null, null); - } - }); - }); - }; - bottomButtonBar.AddChild(buttonImport); - } - - // put in the export button - { - Button buttonExport = textImageButtonFactory.Generate("Export".Localize() + "..."); - buttonExport.Margin = new BorderDouble(0, 3); - buttonExport.Click += (sender, e) => - { - UiThread.RunOnIdle(() => - { - string defaultFileNameNoPath = "eeprom_settings.ini"; - AggContext.FileDialogs.SaveFileDialog( - new SaveFileDialogParams("EEPROM Settings|*.ini") + (openParams) => { - ActionButtonLabel = "Export EEPROM Settings".Localize(), - Title = "Export EEPROM".Localize(), - FileName = defaultFileNameNoPath - }, - (saveParams) => + if (!string.IsNullOrEmpty(openParams.FileName)) { - if (!string.IsNullOrEmpty(saveParams.FileName) - && saveParams.FileName != defaultFileNameNoPath) - { - currentEePromSettings.Export(saveParams.FileName); - } - }); - }); + currentEePromSettings.Import(openParams.FileName); + SetUiToPrinterSettings(null, null); + } + }); + }, .1); }; - bottomButtonBar.AddChild(buttonExport); - } -#endif - Button buttonAbort = textImageButtonFactory.Generate("Close".Localize()); - bottomButtonBar.AddChild(buttonAbort); - buttonAbort.Click += buttonAbort_Click; + // put in the export button + menuItem = popupMenu.CreateMenuItem("Export".Localize()); + menuItem.Name = "Export Menu Item"; + menuItem.Click += (s, e) => + { + UiThread.RunOnIdle(this.ExportSettings, .1); + }; - mainContainer.AddChild(bottomButtonBar); + popupMenu.CreateHorizontalLine(); + + menuItem = popupMenu.CreateMenuItem("Reset to Factory Defaults".Localize()); + menuItem.Click += (s, e) => + { + currentEePromSettings.SetPrinterToFactorySettings(); + currentEePromSettings.Update(); + }; + }; } - printerConnection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents); - - AddChild(mainContainer); - - ShowAsSystemWindow(); - - // and ask the printer to send the settings - currentEePromSettings.Update(); - foreach (GuiWidget widget in leftStuffToSize) { widget.Width = maxWidthOfLeftStuff; } } + private void ExportSettings() + { + string defaultFileName = $"eeprom_settings_{base.GetSanitizedPrinterName()}.ini"; + AggContext.FileDialogs.SaveFileDialog( + new SaveFileDialogParams("EEPROM Settings|*.ini") + { + ActionButtonLabel = "Export EEPROM Settings".Localize(), + Title = "Export EEPROM".Localize(), + FileName = defaultFileName + }, + (saveParams) => + { + if (!string.IsNullOrEmpty(saveParams.FileName) + && saveParams.FileName != defaultFileName) + { + currentEePromSettings.Export(saveParams.FileName); + } + }); + } + private GuiWidget CreateMHNumEdit(ref MHNumberEdit numberEditToCreate) { - numberEditToCreate = new MHNumberEdit(0, pixelWidth: 80, allowNegatives: true, allowDecimals: true); - numberEditToCreate.SelectAllOnFocus = true; - numberEditToCreate.VAnchor = Agg.UI.VAnchor.Center; - numberEditToCreate.Margin = new BorderDouble(3, 0); + numberEditToCreate = new MHNumberEdit(0, pixelWidth: 80, allowNegatives: true, allowDecimals: true) + { + SelectAllOnFocus = true, + VAnchor = VAnchor.Center, + Margin = new BorderDouble(3, 0), + TabIndex = GetNextTabIndex() + }; + return numberEditToCreate; } @@ -329,11 +292,15 @@ namespace MatterHackers.MatterControl.EeProm private GuiWidget CreateTextField(string label) { - GuiWidget textWidget = new TextWidget(label, textColor: ActiveTheme.Instance.PrimaryTextColor); - textWidget.VAnchor = VAnchor.Center; - textWidget.HAnchor = HAnchor.Right; - GuiWidget container = new GuiWidget(textWidget.Height, 24); + var textWidget = new TextWidget(label, pointSize: theme.FontSize10, textColor: ActiveTheme.Instance.PrimaryTextColor) + { + VAnchor = VAnchor.Center, + HAnchor = HAnchor.Right + }; + + var container = new GuiWidget(textWidget.Height, 24); container.AddChild(textWidget); + return container; } @@ -343,48 +310,43 @@ namespace MatterHackers.MatterControl.EeProm string field3Label, ref MHNumberEdit field3, string field4Label, ref MHNumberEdit field4) { - FlowLayoutWidget row = new FlowLayoutWidget(); - row.Margin = new BorderDouble(3); - row.HAnchor = Agg.UI.HAnchor.Stretch; + var row = new FlowLayoutWidget + { + Margin = 3, + HAnchor = HAnchor.Stretch + }; - TextWidget labelWidget = new TextWidget(label, textColor: ActiveTheme.Instance.PrimaryTextColor); - labelWidget.VAnchor = VAnchor.Center; + var labelWidget = new TextWidget(label, pointSize: theme.FontSize10, textColor: ActiveTheme.Instance.PrimaryTextColor); maxWidthOfLeftStuff = Math.Max(maxWidthOfLeftStuff, labelWidget.Width); - GuiWidget holder = new GuiWidget(labelWidget.Width, labelWidget.Height); - holder.Margin = new BorderDouble(3, 0); + + var holder = new GuiWidget(labelWidget.Width, labelWidget.Height) + { + Margin = new BorderDouble(3, 0), + VAnchor = VAnchor.Fit | VAnchor.Center + }; holder.AddChild(labelWidget); leftStuffToSize.Add(holder); row.AddChild(holder); - { - row.AddChild(CreateTextField(field1Label)); - GuiWidget nextTabIndex = CreateMHNumEdit(ref field1); - nextTabIndex.TabIndex = GetNextTabIndex(); - row.AddChild(nextTabIndex); - } + row.AddChild(CreateTextField(field1Label)); + row.AddChild(CreateMHNumEdit(ref field1)); if (field2Label != null) { row.AddChild(CreateTextField(field2Label)); - GuiWidget nextTabIndex = CreateMHNumEdit(ref field2); - nextTabIndex.TabIndex = GetNextTabIndex(); - row.AddChild(nextTabIndex); + row.AddChild(CreateMHNumEdit(ref field2)); } if (field3Label != null) { row.AddChild(CreateTextField(field3Label)); - GuiWidget nextTabIndex = CreateMHNumEdit(ref field3); - nextTabIndex.TabIndex = GetNextTabIndex(); - row.AddChild(nextTabIndex); + row.AddChild(CreateMHNumEdit(ref field3)); } if (field4Label != null) { row.AddChild(CreateTextField(field4Label)); - GuiWidget nextTabIndex = CreateMHNumEdit(ref field4); - nextTabIndex.TabIndex = GetNextTabIndex(); - row.AddChild(nextTabIndex); + row.AddChild(CreateMHNumEdit(ref field4)); } return row; @@ -395,22 +357,9 @@ namespace MatterHackers.MatterControl.EeProm return currentTabIndex++; } - private static void CreateSpacer(FlowLayoutWidget buttonBar) - { - GuiWidget spacer = new GuiWidget(1, 1); - spacer.HAnchor = Agg.UI.HAnchor.Stretch; - buttonBar.AddChild(spacer); - } - - private void buttonAbort_Click(object sender, EventArgs e) - { - UiThread.RunOnIdle(Close); - } - public override void OnClosed(ClosedEventArgs e) { unregisterEvents?.Invoke(this, null); - base.OnClosed(e); } diff --git a/EeProm/EePromRepetierStorage.cs b/EeProm/EePromRepetierStorage.cs index a08837737..9cb163b7f 100644 --- a/EeProm/EePromRepetierStorage.cs +++ b/EeProm/EePromRepetierStorage.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2014, Lars Brubaker +Copyright (c) 2018, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -27,22 +27,19 @@ 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.MatterControl.PrinterCommunication; using System; using System.Collections.Generic; using System.IO; +using MatterHackers.Agg; +using MatterHackers.MatterControl.PrinterCommunication; namespace MatterHackers.MatterControl.EeProm { - public delegate void OnEePromRepetierAdded(EePromRepetierParameter param); - public class EePromRepetierStorage { public Dictionary eePromSettingsList; - public event EventHandler eventAdded = null; + public event EventHandler SettingAdded = null; public EePromRepetierStorage() { @@ -84,7 +81,7 @@ namespace MatterHackers.MatterControl.EeProm return; } - EePromRepetierParameter parameter = new EePromRepetierParameter(line); + var parameter = new EePromRepetierParameter(line); lock (eePromSettingsList) { if (eePromSettingsList.ContainsKey(parameter.position)) @@ -95,7 +92,7 @@ namespace MatterHackers.MatterControl.EeProm eePromSettingsList.Add(parameter.position, parameter); } - eventAdded(this, parameter); + this.SettingAdded?.Invoke(this, parameter); } public void AskPrinterForSettings(PrinterConnection printerConnection) @@ -111,8 +108,7 @@ namespace MatterHackers.MatterControl.EeProm { foreach (EePromRepetierParameter p in eePromSettingsList.Values) { - string data = "{0}|{1}".FormatWith(p.description, p.value); - sw.WriteLine(data); + sw.WriteLine("{0}|{1}", p.description, p.value); } } } @@ -120,10 +116,8 @@ namespace MatterHackers.MatterControl.EeProm internal void Import(string fileName) { - // read all the lines - string[] allLines = File.ReadAllLines(fileName); // find all the descriptions we can - foreach (string line in allLines) + foreach (string line in File.ReadAllLines(fileName)) { if (line.Contains("|")) { @@ -134,13 +128,13 @@ namespace MatterHackers.MatterControl.EeProm { if (keyValue.Value.Description == descriptionValue[0]) { - if(keyValue.Value.Value != descriptionValue[1]) + if (keyValue.Value.Value != descriptionValue[1]) { // push in the value keyValue.Value.Value = descriptionValue[1]; keyValue.Value.MarkChanged(); break; - } + } } } } diff --git a/EeProm/EePromRepetierWindow.cs b/EeProm/EePromRepetierWindow.cs index 7b552dee4..c81e50892 100644 --- a/EeProm/EePromRepetierWindow.cs +++ b/EeProm/EePromRepetierWindow.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2014, Lars Brubaker +Copyright (c) 2018, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -30,203 +30,195 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.SlicerConfiguration; namespace MatterHackers.MatterControl.EeProm { - public class CloseOnDisconnectWindow : SystemWindow + public class EEPromPage : DialogPage { - private EventHandler unregisterEvents; + private static Regex nameSanitizer = new Regex("[^_a-zA-Z0-9-]", RegexOptions.Compiled); - public CloseOnDisconnectWindow(PrinterConnection printerConnection, double width, double height) - : base(width, height) + private EventHandler unregisterEvents; + protected PrinterConfig printer; + + public EEPromPage(PrinterConfig printer) + : base(useOverflowBar: true) { - printerConnection.CommunicationStateChanged.RegisterEvent((s, e) => + this.HeaderText = "EEProm Settings".Localize(); + this.WindowSize = new VectorMath.Vector2(663, 575); + headerRow.Margin = this.headerRow.Margin.Clone(bottom: 0); + + + this.printer = printer; + + // Close window if printer is disconnected + printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => { - if(!printerConnection.IsConnected) + if(!printer.Connection.IsConnected) { - this.CloseOnIdle(); + this.WizardWindow.CloseOnIdle(); } }, ref unregisterEvents); } public override void OnClosed(ClosedEventArgs e) { - if (unregisterEvents != null) - { - unregisterEvents(this, null); - } + unregisterEvents?.Invoke(this, null); base.OnClosed(e); } + + protected string GetSanitizedPrinterName() + { + // TODO: Determine best file name sanitization implementation: this, MakeValidFileName, something else? + string printerName = printer.Settings.GetValue(SettingsKey.printer_name).Replace(" ", "_"); + return nameSanitizer.Replace(printerName, ""); + } } - public class EePromRepetierWindow : CloseOnDisconnectWindow + public class RepetierEEPromPage : EEPromPage { - protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); - private EePromRepetierStorage currentEePromSettings; - private FlowLayoutWidget settingsColmun; + private FlowLayoutWidget settingsColumn; private EventHandler unregisterEvents; - public EePromRepetierWindow(PrinterConnection printerConnection) - : base(printerConnection, 650 * GuiWidget.DeviceScale, 480 * GuiWidget.DeviceScale) + public RepetierEEPromPage(PrinterConfig printer) + : base(printer) { AlwaysOnTopOfMain = true; - BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; + + this.WindowTitle = "Firmware EEPROM Settings".Localize(); currentEePromSettings = new EePromRepetierStorage(); - FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); - topToBottom.VAnchor = Agg.UI.VAnchor.Stretch; - topToBottom.HAnchor = Agg.UI.HAnchor.Stretch; - topToBottom.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - topToBottom.Padding = new BorderDouble(3, 0); + var topToBottom = contentRow; + + var row = new FlowLayoutWidget + { + HAnchor = HAnchor.Stretch, + }; - FlowLayoutWidget row = new FlowLayoutWidget(); - row.HAnchor = Agg.UI.HAnchor.Stretch; - row.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; GuiWidget descriptionWidget = AddDescription("Description".Localize()); descriptionWidget.Margin = new BorderDouble(left: 3); row.AddChild(descriptionWidget); CreateSpacer(row); - GuiWidget valueText = new TextWidget("Value".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor); - valueText.VAnchor = Agg.UI.VAnchor.Center; - valueText.Margin = new BorderDouble(left: 5, right: 60); - row.AddChild(valueText); + row.AddChild(new TextWidget("Value".Localize(), pointSize: theme.FontSize10, textColor: ActiveTheme.Instance.PrimaryTextColor) + { + VAnchor = VAnchor.Center, + Margin = new BorderDouble(left: 5, right: 60) + }); topToBottom.AddChild(row); { - ScrollableWidget settingsAreaScrollBox = new ScrollableWidget(true); + var settingsAreaScrollBox = new ScrollableWidget(true); settingsAreaScrollBox.ScrollArea.HAnchor |= HAnchor.Stretch; settingsAreaScrollBox.AnchorAll(); settingsAreaScrollBox.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; topToBottom.AddChild(settingsAreaScrollBox); - settingsColmun = new FlowLayoutWidget(FlowDirection.TopToBottom); - settingsColmun.HAnchor = HAnchor.MaxFitOrStretch; - - settingsAreaScrollBox.AddChild(settingsColmun); - } - - FlowLayoutWidget buttonBar = new FlowLayoutWidget(); - buttonBar.HAnchor = Agg.UI.HAnchor.MaxFitOrStretch; - buttonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - - // put in the save button - { - Button buttonSave = textImageButtonFactory.Generate("Save To EEPROM".Localize()); - buttonSave.Margin = new BorderDouble(0, 3); - buttonSave.Click += (sender, e) => + settingsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom) { - UiThread.RunOnIdle(() => - { - currentEePromSettings.Save(printerConnection); - currentEePromSettings.Clear(); - currentEePromSettings.eventAdded -= NewSettingReadFromPrinter; - Close(); - }); + HAnchor = HAnchor.MaxFitOrStretch }; - buttonBar.AddChild(buttonSave); + settingsAreaScrollBox.AddChild(settingsColumn); } - CreateSpacer(buttonBar); - // put in the import button + if (headerRow is OverflowBar overflowBar) { - Button buttonImport = textImageButtonFactory.Generate("Import".Localize() + "..."); - buttonImport.Margin = new BorderDouble(0, 3); - buttonImport.Click += (sender, e) => + overflowBar.ExtendOverflowMenu = (popupMenu) => { - UiThread.RunOnIdle(() => + var menuItem = popupMenu.CreateMenuItem("Import".Localize()); + menuItem.Name = "Import Menu Item"; + menuItem.Click += (s, e) => { - AggContext.FileDialogs.OpenFileDialog( - new OpenFileDialogParams("EEPROM Settings|*.ini") - { - ActionButtonLabel = "Import EEPROM Settings".Localize(), - Title = "Import EEPROM".Localize(), - }, + UiThread.RunOnIdle(() => + { + AggContext.FileDialogs.OpenFileDialog( + new OpenFileDialogParams("EEPROM Settings|*.ini") + { + ActionButtonLabel = "Import EEPROM Settings".Localize(), + Title = "Import EEPROM".Localize(), + }, (openParams) => { if (!string.IsNullOrEmpty(openParams.FileName)) { currentEePromSettings.Import(openParams.FileName); RebuildUi(); - } - }); - }); - }; - buttonBar.AddChild(buttonImport); - } - - // put in the export button - { - Button buttonExport = textImageButtonFactory.Generate("Export".Localize() + "..."); - buttonExport.Margin = new BorderDouble(0, 3); - buttonExport.Click += (sender, e) => - { - UiThread.RunOnIdle(() => - { - AggContext.FileDialogs.SaveFileDialog( - new SaveFileDialogParams("EEPROM Settings|*.ini") - { - ActionButtonLabel = "Export EEPROM Settings".Localize(), - Title = "Export EEPROM".Localize(), - FileName = "eeprom_settings.ini" - }, - (saveParams) => - { - if (!string.IsNullOrEmpty(saveParams.FileName)) - { - currentEePromSettings.Export(saveParams.FileName); } }); - }); - }; - buttonBar.AddChild(buttonExport); - } + }, .1); + }; - // put in the cancel button - { - Button buttonCancel = textImageButtonFactory.Generate("Close".Localize()); - buttonCancel.Margin = new BorderDouble(10, 3, 0, 3); - buttonCancel.Click += (sender, e) => - { - UiThread.RunOnIdle(() => + menuItem = popupMenu.CreateMenuItem("Export".Localize()); + menuItem.Name = "Export Menu Item"; + menuItem.Click += (s, e) => { - currentEePromSettings.Clear(); - currentEePromSettings.eventAdded -= NewSettingReadFromPrinter; - Close(); - }); + UiThread.RunOnIdle(this.ExportSettings, .1); + }; }; - buttonBar.AddChild(buttonCancel); } - topToBottom.AddChild(buttonBar); + // put in the save button + var buttonSave = theme.CreateDialogButton("Save To EEPROM".Localize()); + buttonSave.Click += (s, e) => + { + UiThread.RunOnIdle(() => + { + currentEePromSettings.Save(printer.Connection); + currentEePromSettings.Clear(); + this.WizardWindow.Close(); + }); + }; + this.AddPageAction(buttonSave); - this.AddChild(topToBottom); - - Title = "Firmware EEPROM Settings".Localize(); - - ShowAsSystemWindow(); + var exportButton = theme.CreateDialogButton("Export".Localize()); + exportButton.Click += (s, e) => + { + UiThread.RunOnIdle(this.ExportSettings, .1); + }; + this.AddPageAction(exportButton); currentEePromSettings.Clear(); - printerConnection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents); - currentEePromSettings.eventAdded += NewSettingReadFromPrinter; - currentEePromSettings.AskPrinterForSettings(printerConnection); + printer.Connection.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents); + currentEePromSettings.SettingAdded += NewSettingReadFromPrinter; + currentEePromSettings.AskPrinterForSettings(printer.Connection); #if SIMULATE_CONNECTION UiThread.RunOnIdle(AddSimulatedItems); #endif } + private void ExportSettings() + { + string defaultFileName = $"eeprom_settings_{base.GetSanitizedPrinterName()}.ini"; + + AggContext.FileDialogs.SaveFileDialog( + new SaveFileDialogParams("EEPROM Settings|*.ini") + { + ActionButtonLabel = "Export EEPROM Settings".Localize(), + Title = "Export EEPROM".Localize(), + FileName = defaultFileName + }, + (saveParams) => + { + if (!string.IsNullOrEmpty(saveParams.FileName)) + { + currentEePromSettings.Export(saveParams.FileName); + } + }); + } + #if SIMULATE_CONNECTION int count; void AddSimulatedItems(object state) @@ -243,25 +235,27 @@ namespace MatterHackers.MatterControl.EeProm private static void CreateSpacer(FlowLayoutWidget buttonBar) { - GuiWidget spacer = new GuiWidget(1, 1); - spacer.HAnchor = Agg.UI.HAnchor.Stretch; - buttonBar.AddChild(spacer); + buttonBar.AddChild(new GuiWidget(1, 1) + { + HAnchor = HAnchor.Stretch + }); } public override void OnClosed(ClosedEventArgs e) { - if (unregisterEvents != null) + if (currentEePromSettings != null) { - unregisterEvents(this, null); + currentEePromSettings.SettingAdded -= NewSettingReadFromPrinter; } + + unregisterEvents?.Invoke(this, null); base.OnClosed(e); } bool waitingForUiUpdate = false; private void NewSettingReadFromPrinter(object sender, EventArgs e) { - EePromRepetierParameter newSetting = e as EePromRepetierParameter; - if (newSetting != null) + if (e is EePromRepetierParameter newSetting) { if (!waitingForUiUpdate) { @@ -275,45 +269,49 @@ namespace MatterHackers.MatterControl.EeProm private void RebuildUi() { - List tempList = new List(); + var tempList = new List(); lock (currentEePromSettings.eePromSettingsList) { - foreach (KeyValuePair keyValue in currentEePromSettings.eePromSettingsList) + foreach (var keyValue in currentEePromSettings.eePromSettingsList) { tempList.Add(keyValue.Value); } } - settingsColmun.CloseAllChildren(); + settingsColumn.CloseAllChildren(); foreach (EePromRepetierParameter newSetting in tempList) { if (newSetting != null) { - FlowLayoutWidget row = new FlowLayoutWidget(); - row.HAnchor = Agg.UI.HAnchor.MaxFitOrStretch; + var row = new FlowLayoutWidget + { + HAnchor = HAnchor.MaxFitOrStretch, + Padding = new BorderDouble(5, 0) + }; row.AddChild(AddDescription(newSetting.Description)); - row.Padding = new BorderDouble(5, 0); - if ((settingsColmun.Children.Count % 2) == 1) + + if ((settingsColumn.Children.Count % 2) == 1) { row.BackgroundColor = new Color(0, 0, 0, 30); } CreateSpacer(row); - double currentValue; - double.TryParse(newSetting.Value, out currentValue); - MHNumberEdit valueEdit = new MHNumberEdit(currentValue, pixelWidth: 80 * GuiWidget.DeviceScale, allowNegatives: true, allowDecimals: true); - valueEdit.SelectAllOnFocus = true; - valueEdit.TabIndex = currentTabIndex++; - valueEdit.VAnchor = Agg.UI.VAnchor.Center; - valueEdit.ActuallNumberEdit.EditComplete += (sender, e) => + double.TryParse(newSetting.Value, out double currentValue); + var valueEdit = new MHNumberEdit(currentValue, pixelWidth: 80 * GuiWidget.DeviceScale, allowNegatives: true, allowDecimals: true) + { + SelectAllOnFocus = true, + TabIndex = currentTabIndex++, + VAnchor = VAnchor.Center + }; + valueEdit.ActuallNumberEdit.EditComplete += (s, e) => { newSetting.Value = valueEdit.ActuallNumberEdit.Value.ToString(); }; row.AddChild(valueEdit); - settingsColmun.AddChild(row); + settingsColumn.AddChild(row); } } waitingForUiUpdate = false; @@ -321,10 +319,11 @@ namespace MatterHackers.MatterControl.EeProm private GuiWidget AddDescription(string description) { - GuiWidget holder = new GuiWidget(340, 40); - TextWidget textWidget = new TextWidget(description, textColor: ActiveTheme.Instance.PrimaryTextColor); - textWidget.VAnchor = Agg.UI.VAnchor.Center; - holder.AddChild(textWidget); + var holder = new GuiWidget(340, 40); + holder.AddChild(new TextWidget(description, pointSize: theme.DefaultFontSize, textColor: ActiveTheme.Instance.PrimaryTextColor) + { + VAnchor = VAnchor.Center + }); return holder; } diff --git a/PartPreviewWindow/PopupMenu.cs b/PartPreviewWindow/PopupMenu.cs index ec7f10cdb..b6f28967f 100644 --- a/PartPreviewWindow/PopupMenu.cs +++ b/PartPreviewWindow/PopupMenu.cs @@ -60,10 +60,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public HorizontalLine CreateHorizontalLine() { - var line = new HorizontalLine(40) + var line = new HorizontalLine(70, theme: ApplicationController.Instance.MenuTheme) { Margin = new BorderDouble(theme.MenuGutterWidth - 8, 1, 8, 1), - BackgroundColor = theme.GetBorderColor(40) }; this.AddChild(line); diff --git a/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs b/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs index aec3579ef..c5b10ef97 100644 --- a/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs +++ b/PartPreviewWindow/View3D/PrinterBar/OverflowBar.cs @@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { var totalX = widget.Width + widget.Margin.Width; - withinLimits &= (accumulatedX + totalX) < maxRight; + withinLimits &= (accumulatedX + totalX) <= maxRight; // Widget is visible when no previous sibling has been rejected and its right edge is less than maxRight widget.Visible = withinLimits; // widget.Position.X + widget.Width < maxRight; diff --git a/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs b/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs index 57a079b5b..d38712ee1 100644 --- a/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs +++ b/PartPreviewWindow/View3D/PrinterBar/PrinterActionsBar.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2017, Lars Brubaker, John Lewin +Copyright (c) 2018, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; -using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -42,7 +41,6 @@ using MatterHackers.MatterControl.EeProm; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.PrintHistory; using MatterHackers.MatterControl.SlicerConfiguration; -using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { @@ -50,8 +48,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { private PrinterConfig printer; private EventHandler unregisterEvents; - private static EePromMarlinWindow openEePromMarlinWidget = null; - private static EePromRepetierWindow openEePromRepetierWidget = null; + private static MarlinEEPromPage marlinEEPromPage = null; + private static RepetierEEPromPage repetierEEPromPage = null; private string noEepromMappingMessage = "Oops! There is no eeprom mapping for your printer's firmware.".Localize() + "\n\n" + "You may need to wait a minute for your printer to finish initializing.".Localize(); private string noEepromMappingTitle = "Warning - No EEProm Mapping".Localize(); @@ -178,7 +176,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.OverflowButton.Name = "Printer Overflow Menu"; this.ExtendOverflowMenu = (popupMenu) => { - this.GeneratePrinterOverflowMenu(popupMenu, theme); + this.GeneratePrinterOverflowMenu(popupMenu, ApplicationController.Instance.MenuTheme); }; printer.ViewState.ViewModeChanged += (s, e) => @@ -326,38 +324,47 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { UiThread.RunOnIdle(() => { -#if false // This is to force the creation of the repetier window for testing when we don't have repetier firmware. - new MatterHackers.MatterControl.EeProm.EePromRepetierWidget(); -#else - switch (printer.Connection.FirmwareType) + var firmwareType = printer.Connection.FirmwareType; + + // Force Repetier firmware for testing when we don't have repetier firmware + if (false) + { + firmwareType = FirmwareTypes.Repetier; + } + + switch (firmwareType) { case FirmwareTypes.Repetier: - if (openEePromRepetierWidget != null) + if (repetierEEPromPage != null) { - openEePromRepetierWidget.BringToFront(); + repetierEEPromPage.WizardWindow.BringToFront(); } else { - openEePromRepetierWidget = new EePromRepetierWindow(printer.Connection); - openEePromRepetierWidget.Closed += (RepetierWidget, RepetierEvent) => + repetierEEPromPage = new RepetierEEPromPage(printer); + repetierEEPromPage.Closed += (s, e) => { - openEePromRepetierWidget = null; + repetierEEPromPage = null; }; + + DialogWindow.Show(repetierEEPromPage); } break; case FirmwareTypes.Marlin: - if (openEePromMarlinWidget != null) + if (marlinEEPromPage != null) { - openEePromMarlinWidget.BringToFront(); + marlinEEPromPage.WizardWindow.BringToFront(); } else { - openEePromMarlinWidget = new EePromMarlinWindow(printer.Connection); - openEePromMarlinWidget.Closed += (marlinWidget, marlinEvent) => + marlinEEPromPage = new MarlinEEPromPage(printer); + marlinEEPromPage.Closed += (s, e) => { - openEePromMarlinWidget = null; + marlinEEPromPage = null; }; + + DialogWindow.Show(marlinEEPromPage); } break; @@ -366,7 +373,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow StyledMessageBox.ShowMessageBox(noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); break; } -#endif }); } } diff --git a/SetupWizard/DialogPage.cs b/SetupWizard/DialogPage.cs index 4aa1820ce..4eff02d65 100644 --- a/SetupWizard/DialogPage.cs +++ b/SetupWizard/DialogPage.cs @@ -33,17 +33,18 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl { public class DialogPage : FlowLayoutWidget { - protected FlowLayoutWidget headerRow; + protected GuiWidget headerRow; protected FlowLayoutWidget contentRow; protected FlowLayoutWidget footerRow; - private WrappedTextWidget headerLabel; + private TextWidget headerLabel; private GuiWidget cancelButton; public Vector2 WindowSize { get; set; } @@ -55,7 +56,7 @@ namespace MatterHackers.MatterControl protected ThemeConfig theme; - public DialogPage(string cancelButtonText = null) + public DialogPage(string cancelButtonText = null, bool useOverflowBar = false) : base (FlowDirection.TopToBottom) { theme = ApplicationController.Instance.Theme; @@ -75,17 +76,32 @@ namespace MatterHackers.MatterControl cancelButton.Name = "Cancel Wizard Button"; // Create the header row for the widget - headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight) + if (useOverflowBar) { - Name = "HeaderRow", - Margin = new BorderDouble(0, 3, 0, 0), - Padding = new BorderDouble(0, 12), - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit - }; + headerRow = new OverflowBar(theme) + { + Name = "HeaderRow", + Margin = new BorderDouble(0, 3, 0, 0), + Padding = new BorderDouble(0, 12), + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit + }; + } + else + { + headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight) + { + Name = "HeaderRow", + Margin = new BorderDouble(0, 3, 0, 0), + Padding = new BorderDouble(0, 12), + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit + }; + } + this.AddChild(headerRow); - headerLabel = new WrappedTextWidget("Setup Wizard".Localize(), pointSize: 24, textColor: theme.Colors.PrimaryAccentColor) + headerLabel = new TextWidget("Setup Wizard".Localize(), pointSize: 24, textColor: theme.Colors.PrimaryAccentColor) { HAnchor = HAnchor.Stretch }; @@ -114,7 +130,7 @@ namespace MatterHackers.MatterControl #if !__ANDROID__ headerRow.Padding = new BorderDouble(0, 3, 0, 3); - headerLabel.TextWidget.PointSize = 14; + headerLabel.PointSize = 14; headerLabel.TextColor = theme.Colors.PrimaryTextColor; contentRow.Padding = new BorderDouble(5); diff --git a/SetupWizard/DialogWindow.cs b/SetupWizard/DialogWindow.cs index c733db330..4de46c811 100644 --- a/SetupWizard/DialogWindow.cs +++ b/SetupWizard/DialogWindow.cs @@ -49,7 +49,9 @@ namespace MatterHackers.MatterControl this.AlwaysOnTopOfMain = true; this.MinimumSize = new Vector2(200, 200); this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - this.Padding = new BorderDouble(ApplicationController.Instance.Theme.DefaultContainerPadding); + + var defaultPadding = ApplicationController.Instance.Theme.DefaultContainerPadding; + this.Padding = new BorderDouble(defaultPadding, defaultPadding, defaultPadding, 2); } public static void Close(Type type)