From 6774f5ff1705e6e1dc07e7b3d2a99d5872ca5d74 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Fri, 16 Oct 2015 13:39:50 -0700 Subject: [PATCH] Put print leveling configuration in its own section renamed it for clarity --- .../CalibrationSettingsView.cs | 351 ++++++++++++++++++ ConfigurationPage/PrinterConfigurationPage.cs | 9 +- .../PrinterSettings/PrinterSettingsView.cs | 23 +- MatterControl.csproj | 1 + StaticData/Translations/Master.txt | 9 + 5 files changed, 372 insertions(+), 21 deletions(-) create mode 100644 ConfigurationPage/CalibrationSettings/CalibrationSettingsView.cs diff --git a/ConfigurationPage/CalibrationSettings/CalibrationSettingsView.cs b/ConfigurationPage/CalibrationSettings/CalibrationSettingsView.cs new file mode 100644 index 000000000..f4303a31b --- /dev/null +++ b/ConfigurationPage/CalibrationSettings/CalibrationSettingsView.cs @@ -0,0 +1,351 @@ +using MatterHackers.Agg; +using MatterHackers.Agg.ImageProcessing; +using MatterHackers.Agg.PlatformAbstract; +using MatterHackers.Agg.UI; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.EeProm; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.SlicerConfiguration; +using System; +using System.IO; + +namespace MatterHackers.MatterControl.ConfigurationPage +{ + public class CalibrationSettingsWidget : SettingsViewBase + { + private DisableableWidget printLevelingContainer; + + private event EventHandler unregisterEvents; + + public CalibrationSettingsWidget() + : base("Calibration Settings".Localize()) + { + printLevelingContainer = new DisableableWidget(); + if (!ActiveSliceSettings.Instance.HasHardwareLeveling()) + { + printLevelingContainer.AddChild(GetAutoLevelControl()); + + mainContainer.AddChild(printLevelingContainer); + } + + mainContainer.AddChild(new HorizontalLine(separatorLineColor)); + + AddChild(mainContainer); + AddHandlers(); + SetVisibleControls(); + } + + private EditLevelingSettingsWindow editLevelingSettingsWindow; + private TextWidget printLevelingStatusLabel; + + private FlowLayoutWidget GetAutoLevelControl() + { + FlowLayoutWidget buttonRow = new FlowLayoutWidget(); + buttonRow.HAnchor = HAnchor.ParentLeftRight; + buttonRow.Margin = new BorderDouble(0, 4); + + TextWidget notificationSettingsLabel = new TextWidget("Software Print Leveling"); + notificationSettingsLabel.AutoExpandBoundsToText = true; + notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; + notificationSettingsLabel.VAnchor = VAnchor.ParentCenter; + + Button editButton = textImageButtonFactory.GenerateEditButton(); + editButton.VAnchor = Agg.UI.VAnchor.ParentCenter; + editButton.Click += (sender, e) => + { + UiThread.RunOnIdle(() => + { + if (editLevelingSettingsWindow == null) + { + editLevelingSettingsWindow = new EditLevelingSettingsWindow(); + editLevelingSettingsWindow.Closed += (sender2, e2) => + { + editLevelingSettingsWindow = null; + }; + } + else + { + editLevelingSettingsWindow.BringToFront(); + } + }); + }; + + Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); + runPrintLevelingButton.Margin = new BorderDouble(left: 6); + runPrintLevelingButton.VAnchor = VAnchor.ParentCenter; + runPrintLevelingButton.Click += (sender, e) => + { + UiThread.RunOnIdle(() => + { + LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration); + }); + }; + + Agg.Image.ImageBuffer levelingImage = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "leveling-24x24.png")); + if (!ActiveTheme.Instance.IsDarkTheme) + { + InvertLightness.DoInvertLightness(levelingImage); + } + + ImageWidget levelingIcon = new ImageWidget(levelingImage); + levelingIcon.Margin = new BorderDouble(right: 6); + + CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(ActivePrinterProfile.Instance.DoPrintLeveling); + printLevelingSwitch.VAnchor = VAnchor.ParentCenter; + printLevelingSwitch.Margin = new BorderDouble(left: 16); + printLevelingSwitch.CheckedStateChanged += (sender, e) => + { + ActivePrinterProfile.Instance.DoPrintLeveling = printLevelingSwitch.Checked; + }; + + printLevelingStatusLabel = new TextWidget(""); + printLevelingStatusLabel.AutoExpandBoundsToText = true; + printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; + printLevelingStatusLabel.VAnchor = VAnchor.ParentCenter; + + GuiWidget hSpacer = new GuiWidget(); + hSpacer.HAnchor = HAnchor.ParentLeftRight; + + ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) => + { + SetPrintLevelButtonVisiblity(); + printLevelingSwitch.Checked = ActivePrinterProfile.Instance.DoPrintLeveling; + }, ref unregisterEvents); + + buttonRow.AddChild(levelingIcon); + buttonRow.AddChild(printLevelingStatusLabel); + buttonRow.AddChild(editButton); + buttonRow.AddChild(new HorizontalSpacer()); + buttonRow.AddChild(runPrintLevelingButton); + buttonRow.AddChild(printLevelingSwitch); + + SetPrintLevelButtonVisiblity(); + return buttonRow; + } + + public override void OnClosed(EventArgs e) + { + if (unregisterEvents != null) + { + unregisterEvents(this, null); + } + base.OnClosed(e); + } + + private FlowLayoutWidget GetCameraControl() + { + FlowLayoutWidget buttonRow = new FlowLayoutWidget(); + buttonRow.HAnchor = HAnchor.ParentLeftRight; + buttonRow.Margin = new BorderDouble(0, 4); + + Agg.Image.ImageBuffer cameraIconImage = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "camera-24x24.png")); + if (!ActiveTheme.Instance.IsDarkTheme) + { + InvertLightness.DoInvertLightness(cameraIconImage); + } + + ImageWidget cameraIcon = new ImageWidget(cameraIconImage); + cameraIcon.Margin = new BorderDouble(right: 6); + + TextWidget cameraLabel = new TextWidget("Camera Monitoring"); + cameraLabel.AutoExpandBoundsToText = true; + cameraLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; + cameraLabel.VAnchor = VAnchor.ParentCenter; + +#if __ANDROID__ + + GuiWidget publishImageSwitchContainer = new FlowLayoutWidget(); + publishImageSwitchContainer.VAnchor = VAnchor.ParentCenter; + publishImageSwitchContainer.Margin = new BorderDouble(left: 16); + + CheckBox toggleSwitch = ImageButtonFactory.CreateToggleSwitch(PrinterSettings.Instance.get("PublishBedImage") == "true"); + toggleSwitch.CheckedStateChanged += (sender, e) => + { + CheckBox thisControl = sender as CheckBox; + PrinterSettings.Instance.set("PublishBedImage", thisControl.Checked ? "true" : "false"); + }; + publishImageSwitchContainer.AddChild(toggleSwitch); + + publishImageSwitchContainer.SetBoundsToEncloseChildren(); + + buttonRow.AddChild(publishImageSwitchContainer); +#endif + + return buttonRow; + } + + private static EePromMarlinWindow openEePromMarlinWidget = null; + private static EePromRepetierWindow openEePromRepetierWidget = 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(); + + private FlowLayoutWidget GetEEPromControl() + { + FlowLayoutWidget buttonRow = new FlowLayoutWidget(); + buttonRow.HAnchor = HAnchor.ParentLeftRight; + buttonRow.Margin = new BorderDouble(0, 4); + + TextWidget notificationSettingsLabel = new TextWidget("EEProm Settings".Localize()); + notificationSettingsLabel.AutoExpandBoundsToText = true; + notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; + notificationSettingsLabel.VAnchor = VAnchor.ParentCenter; + + Agg.Image.ImageBuffer eePromImage = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "leveling-24x24.png")); + if (!ActiveTheme.Instance.IsDarkTheme) + { + InvertLightness.DoInvertLightness(eePromImage); + } + ImageWidget eePromIcon = new ImageWidget(eePromImage); + eePromIcon.Margin = new BorderDouble(right: 6); + + Button configureEePromButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); + configureEePromButton.Click += new EventHandler(configureEePromButton_Click); + + //buttonRow.AddChild(eePromIcon); + buttonRow.AddChild(notificationSettingsLabel); + buttonRow.AddChild(new HorizontalSpacer()); + buttonRow.AddChild(configureEePromButton); + + return buttonRow; + } + + private void AddHandlers() + { + PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); + PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); + } + + private void openCameraPreview_Click(object sender, EventArgs e) + { + MatterControlApplication.Instance.OpenCameraPreview(); + } + + private void configureEePromButton_Click(object sender, EventArgs mouseEvent) + { + 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 (PrinterConnectionAndCommunication.Instance.FirmwareType) + { + case PrinterConnectionAndCommunication.FirmwareTypes.Repetier: + if (openEePromRepetierWidget != null) + { + openEePromRepetierWidget.BringToFront(); + } + else + { + openEePromRepetierWidget = new EePromRepetierWindow(); + openEePromRepetierWidget.Closed += (RepetierWidget, RepetierEvent) => + { + openEePromRepetierWidget = null; + }; + } + break; + + case PrinterConnectionAndCommunication.FirmwareTypes.Marlin: + if (openEePromMarlinWidget != null) + { + openEePromMarlinWidget.BringToFront(); + } + else + { + openEePromMarlinWidget = new EePromMarlinWindow(); + openEePromMarlinWidget.Closed += (marlinWidget, marlinEvent) => + { + openEePromMarlinWidget = null; + }; + } + break; + + default: + StyledMessageBox.ShowMessageBox(null, noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); + break; + } +#endif + }); + } + + private void openGcodeTerminalButton_Click(object sender, EventArgs mouseEvent) + { + UiThread.RunOnIdle(TerminalWindow.Show); + } + + private void onPrinterStatusChanged(object sender, EventArgs e) + { + SetVisibleControls(); + this.Invalidate(); + } + + private void SetPrintLevelButtonVisiblity() + { + if (ActivePrinterProfile.Instance.DoPrintLeveling) + { + printLevelingStatusLabel.Text = "Software Print Leveling (enabled)".Localize(); + } + else + { + printLevelingStatusLabel.Text = "Software Print Leveling (disabled)".Localize(); + } + } + + private void SetVisibleControls() + { + if (ActivePrinterProfile.Instance.ActivePrinter == null) + { + // no printer selected + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + //cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + } + else // we at least have a printer selected + { + //cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + switch (PrinterConnectionAndCommunication.Instance.CommunicationState) + { + case PrinterConnectionAndCommunication.CommunicationStates.Disconnecting: + case PrinterConnectionAndCommunication.CommunicationStates.ConnectionLost: + case PrinterConnectionAndCommunication.CommunicationStates.Disconnected: + case PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect: + case PrinterConnectionAndCommunication.CommunicationStates.FailedToConnect: + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + break; + + case PrinterConnectionAndCommunication.CommunicationStates.FinishedPrint: + case PrinterConnectionAndCommunication.CommunicationStates.Connected: + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + break; + + case PrinterConnectionAndCommunication.CommunicationStates.PrintingFromSd: + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + break; + + case PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint: + case PrinterConnectionAndCommunication.CommunicationStates.Printing: + switch (PrinterConnectionAndCommunication.Instance.PrintingState) + { + case PrinterConnectionAndCommunication.DetailedPrintingState.HomingAxis: + case PrinterConnectionAndCommunication.DetailedPrintingState.HeatingBed: + case PrinterConnectionAndCommunication.DetailedPrintingState.HeatingExtruder: + case PrinterConnectionAndCommunication.DetailedPrintingState.Printing: + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + break; + + default: + throw new NotImplementedException(); + } + break; + + case PrinterConnectionAndCommunication.CommunicationStates.Paused: + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + break; + + default: + throw new NotImplementedException(); + } + } + } + } +} \ No newline at end of file diff --git a/ConfigurationPage/PrinterConfigurationPage.cs b/ConfigurationPage/PrinterConfigurationPage.cs index 74b1c7587..b4e22f955 100644 --- a/ConfigurationPage/PrinterConfigurationPage.cs +++ b/ConfigurationPage/PrinterConfigurationPage.cs @@ -33,6 +33,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.ConfigurationPage; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; using System; using System.Collections.Generic; @@ -69,8 +70,12 @@ namespace MatterHackers.MatterControl mainLayoutContainer.VAnchor = Agg.UI.VAnchor.FitToChildren; mainLayoutContainer.Padding = new BorderDouble(top: 10); - HardwareSettingsWidget hardwareGroupbox = new HardwareSettingsWidget(); - mainLayoutContainer.AddChild(hardwareGroupbox); + if (!ActiveSliceSettings.Instance.HasHardwareLeveling()) + { + mainLayoutContainer.AddChild(new CalibrationSettingsWidget()); + } + + mainLayoutContainer.AddChild(new HardwareSettingsWidget()); CloudSettingsWidget cloudGroupbox = new CloudSettingsWidget(); mainLayoutContainer.AddChild(cloudGroupbox); diff --git a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs index 8c3eef945..aa8dfa264 100644 --- a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs +++ b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs @@ -20,26 +20,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage private DisableableWidget eePromControlsContainer; private DisableableWidget terminalCommunicationsContainer; - private DisableableWidget printLevelingContainer; private event EventHandler unregisterEvents; public HardwareSettingsWidget() - : base(LocalizedString.Get("Hardware Settings")) + : base("Hardware Settings".Localize()) { eePromControlsContainer = new DisableableWidget(); eePromControlsContainer.AddChild(GetEEPromControl()); terminalCommunicationsContainer = new DisableableWidget(); terminalCommunicationsContainer.AddChild(GetGcodeTerminalControl()); - printLevelingContainer = new DisableableWidget(); - if (!ActiveSliceSettings.Instance.HasHardwareLeveling()) - { - printLevelingContainer.AddChild(GetAutoLevelControl()); - - mainContainer.AddChild(printLevelingContainer); - } - mainContainer.AddChild(new HorizontalLine(separatorLineColor)); mainContainer.AddChild(eePromControlsContainer); mainContainer.AddChild(new HorizontalLine(separatorLineColor)); @@ -69,7 +60,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage buttonRow.HAnchor = HAnchor.ParentLeftRight; buttonRow.Margin = new BorderDouble(0, 4); - TextWidget notificationSettingsLabel = new TextWidget("Automatic Print Leveling"); + TextWidget notificationSettingsLabel = new TextWidget("Software Print Leveling"); notificationSettingsLabel.AutoExpandBoundsToText = true; notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; notificationSettingsLabel.VAnchor = VAnchor.ParentCenter; @@ -347,11 +338,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage { if (ActivePrinterProfile.Instance.DoPrintLeveling) { - printLevelingStatusLabel.Text = LocalizedString.Get("Automatic Print Leveling (enabled)"); + printLevelingStatusLabel.Text = "Software Print Leveling (enabled)".Localize(); } else { - printLevelingStatusLabel.Text = LocalizedString.Get("Automatic Print Leveling (disabled)"); + printLevelingStatusLabel.Text = "Software Print Leveling (disabled)".Localize(); } } @@ -362,7 +353,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage // no printer selected eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); - printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); //cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); } else // we at least have a printer selected @@ -376,20 +366,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage case PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect: case PrinterConnectionAndCommunication.CommunicationStates.FailedToConnect: eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); - printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); break; case PrinterConnectionAndCommunication.CommunicationStates.FinishedPrint: case PrinterConnectionAndCommunication.CommunicationStates.Connected: eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); - printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); break; case PrinterConnectionAndCommunication.CommunicationStates.PrintingFromSd: eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); - printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); break; @@ -402,7 +389,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage case PrinterConnectionAndCommunication.DetailedPrintingState.HeatingExtruder: case PrinterConnectionAndCommunication.DetailedPrintingState.Printing: eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); - printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); break; @@ -413,7 +399,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage case PrinterConnectionAndCommunication.CommunicationStates.Paused: eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); - printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); break; diff --git a/MatterControl.csproj b/MatterControl.csproj index 7fc9be1e1..b570dd6d8 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -147,6 +147,7 @@ + diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index b17694027..aac9d7fae 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3826,3 +3826,12 @@ Translated:Outside Perimeters English:Sample the bed at {0} points Translated:Sample the bed at {0} points +English:Software Print Leveling (disabled) +Translated:Software Print Leveling (disabled) + +English:Calibration Settings +Translated:Calibration Settings + +English:Software Print Leveling (enabled) +Translated:Software Print Leveling (enabled) +