From a9f3cbf4c46c0abf4aabc86c79835620edb648b8 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 14 Jun 2016 11:28:13 -0700 Subject: [PATCH] Remove ActivePrinter variable from ConnectionWizard - Remove excess properties from PrinterInfo - Remove call to Parent.Close from onPrinterStatusChanged --- .../ConnectionWizardPage.cs | 38 ------------------- .../PrinterConnections/SetupStepBaudRate.cs | 13 ++++--- .../SetupStepComPortManual.cs | 1 - .../SetupStepMakeModelName.cs | 27 +++++++------ .../Settings/ActiveSliceSettings.cs | 6 --- .../Settings/SettingsProfile.cs | 7 +--- 6 files changed, 23 insertions(+), 69 deletions(-) diff --git a/PrinterControls/PrinterConnections/ConnectionWizardPage.cs b/PrinterControls/PrinterConnections/ConnectionWizardPage.cs index 8b7a8a999..b1c933787 100644 --- a/PrinterControls/PrinterConnections/ConnectionWizardPage.cs +++ b/PrinterControls/PrinterConnections/ConnectionWizardPage.cs @@ -10,47 +10,9 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { public class ConnectionWizardPage : WizardPage { - private PrinterInfo activePrinter; - public ConnectionWizardPage() : base("Cancel") { cancelButton.Click += (s, e) => PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); } - - public PrinterInfo ActivePrinter - { - get - { - if (activePrinter == null) - { - var settings = ActiveSliceSettings.Instance; - activePrinter = new PrinterInfo - { - AutoConnect = settings.DoAutoConnect(), - BaudRate = settings.BaudRate(), - ComPort = settings.ComPort(), - DriverType = settings.DriverType(), - Id = settings.ID, - Name = settings.Name() - }; - } - - return activePrinter; - } - } - - protected void SaveAndExit() - { - ActiveSliceSettings.Instance.RunInTransaction(settings => - { - settings.SetAutoConnect(ActivePrinter.AutoConnect); - settings.SetBaudRate(ActivePrinter.BaudRate); - settings.SetComPort(ActivePrinter.ComPort); - settings.SetDriverType(ActivePrinter.DriverType); - settings.SetName(ActivePrinter.Name); - }); - - UiThread.RunOnIdle(WizardWindow.Close); - } } } \ No newline at end of file diff --git a/PrinterControls/PrinterConnections/SetupStepBaudRate.cs b/PrinterControls/PrinterConnections/SetupStepBaudRate.cs index 33935ecd3..0a9aeaf0f 100644 --- a/PrinterControls/PrinterConnections/SetupStepBaudRate.cs +++ b/PrinterControls/PrinterConnections/SetupStepBaudRate.cs @@ -2,6 +2,7 @@ using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.SlicerConfiguration; using System; using System.Collections.Generic; @@ -104,7 +105,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections BaudRateButtonsList.Add(baudOption); baudOption.Margin = baudRateMargin; baudOption.TextColor = ActiveTheme.Instance.PrimaryTextColor; - if (this.ActivePrinter.BaudRate == baudRate) + if (ActiveSliceSettings.Instance.BaudRate() == baudRate) { baudOption.Checked = true; } @@ -123,12 +124,13 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections otherBaudRateInput.Visible = false; otherBaudRateInput.HAnchor = HAnchor.ParentLeftRight; - if (this.ActivePrinter.BaudRate != null) + string currentBaudRate = ActiveSliceSettings.Instance.BaudRate(); + if (currentBaudRate != null) { - if (!baudRates.Contains(this.ActivePrinter.BaudRate.ToString())) + if (!baudRates.Contains(currentBaudRate)) { otherBaudRateRadioButton.Checked = true; - otherBaudRateInput.Text = this.ActivePrinter.BaudRate.ToString(); + otherBaudRateInput.Text = currentBaudRate; otherBaudRateInput.Visible = true; } } @@ -191,8 +193,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { try { - int baudRateInt = Convert.ToInt32(baudRate); - this.ActivePrinter.BaudRate = baudRate; + ActiveSliceSettings.Instance.SetBaudRate(baudRate); return true; } catch diff --git a/PrinterControls/PrinterConnections/SetupStepComPortManual.cs b/PrinterControls/PrinterConnections/SetupStepComPortManual.cs index 83295cbe0..ef27dca4f 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortManual.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortManual.cs @@ -121,7 +121,6 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections printerComPortError.Text = "Connection succeeded".Localize() + "!"; nextButton.Visible = true; connectButton.Visible = false; - UiThread.RunOnIdle(Parent.Close); } else if (PrinterConnectionAndCommunication.Instance.CommunicationState != PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect) { diff --git a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index 4f1695828..f091946fa 100644 --- a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -32,6 +32,10 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private BoundDropList printerManufacturerSelector; private BoundDropList printerModelSelector; + string activeMake; + string activeModel; + string activeName; + public SetupStepMakeModelName() { printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), maxHeight: 200) @@ -51,7 +55,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections if (printerManufacturerSelector.MenuItems.Count == 1) { - ActivePrinter.Make = printerManufacturerSelector.SelectedValue; + activeMake = printerManufacturerSelector.SelectedValue; } printerModelSelector = new BoundDropList(string.Format("- {0} -", "Select Model".Localize()), maxHeight: 200) @@ -103,8 +107,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private void SetElementVisibility() { - printerModelContainer.Visible = (this.ActivePrinter.Make != null); - nextButton.Visible = (this.ActivePrinter.Model != null && this.ActivePrinter.Make != null); + nextButton.Visible = (activeModel != null && this.activeMake != null); } private FlowLayoutWidget createPrinterNameContainer() @@ -175,11 +178,11 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private void ManufacturerDropList_SelectionChanged(object sender, EventArgs e) { - ActivePrinter.Make = ((Agg.UI.DropDownList)sender).SelectedValue; - ActivePrinter.Model = null; + activeMake = ((Agg.UI.DropDownList)sender).SelectedValue; + activeModel = null; List printers; - if (!OemSettings.Instance.OemProfiles.TryGetValue(ActivePrinter.Make, out printers)) + if (!OemSettings.Instance.OemProfiles.TryGetValue(activeMake, out printers)) { printers = new List(); } @@ -196,15 +199,15 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections UiThread.RunOnIdle(() => { DropDownList dropList = (DropDownList) sender; - ActivePrinter.Model = dropList.SelectedLabel; + activeModel = dropList.SelectedLabel; SetElementVisibility(); if (usingDefaultName) { - // Use ManufacturerDropList.SelectedLabel instead of ActivePrinter.Make to ensure the mapped Unicode values are picked up + // Use ManufacturerDropList.SelectedLabel instead of activeMake to ensure the mapped Unicode values are picked up string mappedMakeText = printerManufacturerSelector.SelectedLabel; - string printerInputName = string.Format("{0} {1}", mappedMakeText, this.ActivePrinter.Model); + string printerInputName = string.Format("{0} {1}", mappedMakeText, activeModel); var names = ActiveSliceSettings.ProfileData.Profiles.Where(p => p.Name.StartsWith(printerInputName)).Select(p => p.Name).ToList(); if (!names.Contains(printerInputName)) { @@ -231,15 +234,15 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { if (!string.IsNullOrEmpty(printerNameInput.Text)) { - this.ActivePrinter.Name = printerNameInput.Text; + activeName = printerNameInput.Text; - if (this.ActivePrinter.Make == null || this.ActivePrinter.Model == null) + if (this.activeMake == null || activeModel == null) { return false; } else { - ActiveSliceSettings.AcquireNewProfile(ActivePrinter.Make, ActivePrinter.Model, ActivePrinter.Name); + ActiveSliceSettings.AcquireNewProfile(activeMake, activeModel, activeName); return true; } } diff --git a/SlicerConfiguration/Settings/ActiveSliceSettings.cs b/SlicerConfiguration/Settings/ActiveSliceSettings.cs index 409a47ad1..2b1923651 100644 --- a/SlicerConfiguration/Settings/ActiveSliceSettings.cs +++ b/SlicerConfiguration/Settings/ActiveSliceSettings.cs @@ -144,13 +144,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration var profile = new SettingsProfile(LayeredProfile.LoadFile(filePath)); ProfileData.Profiles.Add(new PrinterInfo() { - AutoConnect = profile.DoAutoConnect(), - BaudRate = profile.BaudRate(), - ComPort = profile.ComPort(), - DriverType = profile.DriverType(), Id = profile.ID, - Make = profile.Make, - Model = profile.Model, Name = profile.Name(), }); } diff --git a/SlicerConfiguration/Settings/SettingsProfile.cs b/SlicerConfiguration/Settings/SettingsProfile.cs index 78bca6975..5e854067e 100644 --- a/SlicerConfiguration/Settings/SettingsProfile.cs +++ b/SlicerConfiguration/Settings/SettingsProfile.cs @@ -1216,14 +1216,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public class PrinterInfo { - public string Make { get; set; } = "Unknown"; - public string Model { get; set; } = "Unknown"; - public string Name { get; set; } public string ComPort { get; set; } - public bool AutoConnect { get; set; } public string Id { get; set; } - public string BaudRate { get; set; } - public string DriverType { get; internal set; } + public string Name { get; set; } internal void Delete() {