From bda5ac173ecd6cdc07fb61a52ad8a74ab6b64384 Mon Sep 17 00:00:00 2001 From: Kevin Pope Date: Tue, 23 Sep 2014 16:11:06 -0700 Subject: [PATCH] More work on configuration page. --- ApplicationView/MainApplicationWidget.cs | 22 +- .../ApplicationSettingsView.cs | 12 +- .../PrinterSettings/PrinterSettingsView.cs | 279 +++++++++++++++++- ConfigurationPage/SettingsViewBase.cs | 5 +- ControlElements/TextImageButtonFactory.cs | 8 + MatterControlApplication.cs | 4 +- PrinterControls/TemperatureIndicator.cs | 2 +- StaticData/Translations/Master.txt | 3 + 8 files changed, 299 insertions(+), 36 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 096aa7a9b..8dfb57d22 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -50,7 +50,13 @@ using MatterHackers.Localizations; namespace MatterHackers.MatterControl { - public class CompactApplicationView : GuiWidget + public abstract class ApplicationView : GuiWidget + { + public abstract void AddElements(); + + } + + public class CompactApplicationView : ApplicationView { CompactTabView widescreenPanel; QueueDataView queueDataView; @@ -60,7 +66,7 @@ namespace MatterHackers.MatterControl Initialize(); } - public void AddElements() + public override void AddElements() { this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; @@ -93,17 +99,17 @@ namespace MatterHackers.MatterControl this.AnchorAll(); } } - - public class ApplicationView : GuiWidget + + public class ResponsiveApplicationView : ApplicationView { WidescreenPanel widescreenPanel; - public ApplicationView() + public ResponsiveApplicationView() { AddElements(); Initialize(); } - public void AddElements() + public override void AddElements() { this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; @@ -143,7 +149,7 @@ namespace MatterHackers.MatterControl public SlicePresetsWindow EditMaterialPresetsWindow{ get; set;} public SlicePresetsWindow EditQualityPresetsWindow{ get; set;} - public CompactApplicationView MainView; + public ApplicationView MainView; event EventHandler unregisterEvents; @@ -180,7 +186,7 @@ namespace MatterHackers.MatterControl if (globalInstance == null) { globalInstance = new ApplicationController(); - globalInstance.MainView = new CompactApplicationView(); + globalInstance.MainView = new ResponsiveApplicationView(); } return globalInstance; } diff --git a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs index ad7586c0b..b2e844418 100644 --- a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs +++ b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs @@ -116,14 +116,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage settingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; settingsLabel.VAnchor = VAnchor.ParentTop; - GuiWidget optionsContainer = new GuiWidget(); + FlowLayoutWidget optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); + optionsContainer.Margin = new BorderDouble(bottom:6); StyledDropDownList releaseOptionsDropList = new StyledDropDownList("Development",maxHeight:200); releaseOptionsDropList.HAnchor = HAnchor.ParentLeftRight; - releaseOptionsDropList.VAnchor = Agg.UI.VAnchor.ParentTop; optionsContainer.AddChild(releaseOptionsDropList); - optionsContainer.Height = 50; optionsContainer.Width = 200; MenuItem releaseOptionsDropDownItem = releaseOptionsDropList.AddItem("Release", "release"); @@ -166,17 +165,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage FlowLayoutWidget controlsContainer = new FlowLayoutWidget(); controlsContainer.HAnchor = HAnchor.ParentLeftRight; - GuiWidget optionsContainer = new GuiWidget(); - optionsContainer.Width = 200; + FlowLayoutWidget optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); + optionsContainer.Margin = new BorderDouble(bottom: 6); LanguageSelector languageSelector = new LanguageSelector(); - languageSelector.Margin = new BorderDouble(0, 4); languageSelector.SelectionChanged += new EventHandler(LanguageDropList_SelectionChanged); languageSelector.HAnchor = HAnchor.ParentLeftRight; - languageSelector.VAnchor = Agg.UI.VAnchor.ParentTop; optionsContainer.AddChild(languageSelector); - optionsContainer.Height = 50; optionsContainer.Width = 200; restartButton = textImageButtonFactory.Generate("Restart"); diff --git a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs index 5fcfd40cd..dbb119519 100644 --- a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs +++ b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs @@ -20,59 +20,163 @@ namespace MatterHackers.MatterControl.ConfigurationPage Button configureAutoLevelButton; Button configureEePromButton; + DisableableWidget eePromControlsContainer; + DisableableWidget terminalCommunicationsContainer; + DisableableWidget printLevelingContainer; + + event EventHandler unregisterEvents; + public HardwareSettingsWidget() : base("Hardware Settings") - { - mainContainer.AddChild(GetAutoLevelControl()); + { + + eePromControlsContainer = new DisableableWidget(); + eePromControlsContainer.AddChild(GetEEPromControl()); + terminalCommunicationsContainer = new DisableableWidget(); + printLevelingContainer = new DisableableWidget(); + printLevelingContainer.AddChild(GetAutoLevelControl()); + + mainContainer.AddChild(printLevelingContainer); ; mainContainer.AddChild(new HorizontalLine(separatorLineColor)); - mainContainer.AddChild(GetEEPromControl()); + mainContainer.AddChild(eePromControlsContainer); AddChild(mainContainer); AddHandlers(); + SetVisibleControls(); } - + EditLevelingSettingsWindow editLevelingSettingsWindow; + Button enablePrintLevelingButton; + Button disablePrintLevelingButton; + TextWidget printLevelingStatusLabel; private FlowLayoutWidget GetAutoLevelControl() { FlowLayoutWidget buttonRow = new FlowLayoutWidget(); buttonRow.HAnchor = HAnchor.ParentLeftRight; - buttonRow.Margin = new BorderDouble(top: 4); + buttonRow.Margin = new BorderDouble(0,4); - configureEePromButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); - configureEePromButton.Margin = new BorderDouble(left: 6); - configureEePromButton.VAnchor = VAnchor.ParentCenter; + configureAutoLevelButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); + configureAutoLevelButton.Margin = new BorderDouble(left: 6); + configureAutoLevelButton.VAnchor = VAnchor.ParentCenter; TextWidget notificationSettingsLabel = new TextWidget("Automatic Print Leveling"); notificationSettingsLabel.AutoExpandBoundsToText = true; notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; notificationSettingsLabel.VAnchor = VAnchor.ParentCenter; - buttonRow.AddChild(notificationSettingsLabel); + Button editButton = textImageButtonFactory.GenerateEditButton(); + editButton.VAnchor = Agg.UI.VAnchor.ParentCenter; + editButton.Click += (sender, e) => + { + UiThread.RunOnIdle((state) => + { + 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((state) => + { + LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration); + }); + }; + + Agg.Image.ImageBuffer levelingImage = new Agg.Image.ImageBuffer(); + ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath,"Icons", "PrintStatusControls", "leveling-24x24.png"), levelingImage); + if (!ActiveTheme.Instance.IsDarkTheme) + { + InvertLightness.DoInvertLightness(levelingImage); + } + + ImageWidget levelingIcon = new ImageWidget(levelingImage); + levelingIcon.Margin = new BorderDouble (right: 6); + + enablePrintLevelingButton = textImageButtonFactory.Generate("Enable".Localize().ToUpper()); + enablePrintLevelingButton.Margin = new BorderDouble(left:6); + enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter; + enablePrintLevelingButton.Click += new ButtonBase.ButtonEventHandler(enablePrintLeveling_Click); + + disablePrintLevelingButton = textImageButtonFactory.Generate("Disable".Localize().ToUpper()); + disablePrintLevelingButton.Margin = new BorderDouble(left:6); + disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter; + disablePrintLevelingButton.Click += new ButtonBase.ButtonEventHandler(disablePrintLeveling_Click); + + 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(); + + }, ref unregisterEvents); + + buttonRow.AddChild(levelingIcon); + buttonRow.AddChild(printLevelingStatusLabel); + buttonRow.AddChild(editButton); buttonRow.AddChild(new HorizontalSpacer()); - buttonRow.AddChild(configureEePromButton); + buttonRow.AddChild(enablePrintLevelingButton); + buttonRow.AddChild(disablePrintLevelingButton); + buttonRow.AddChild(runPrintLevelingButton); + SetPrintLevelButtonVisiblity(); return buttonRow; } + static EePromMarlinWidget openEePromMarlinWidget = null; + static EePromRepetierWidget openEePromRepetierWidget = null; + string noEepromMappingMessage = "Oops! There is no eeprom mapping for your printer's firmware.".Localize(); + string noEepromMappingTitle = "Warning no eeprom mapping".Localize(); + string groupBoxTitle = "EEProm Settings".Localize(); private FlowLayoutWidget GetEEPromControl() { FlowLayoutWidget buttonRow = new FlowLayoutWidget(); buttonRow.HAnchor = HAnchor.ParentLeftRight; - buttonRow.Margin = new BorderDouble(top: 4); + buttonRow.Margin = new BorderDouble(0,4); - configureAutoLevelButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); - configureAutoLevelButton.Margin = new BorderDouble(left: 6); - configureAutoLevelButton.VAnchor = VAnchor.ParentCenter; TextWidget notificationSettingsLabel = new TextWidget("EEProm Settings"); notificationSettingsLabel.AutoExpandBoundsToText = true; notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor; notificationSettingsLabel.VAnchor = VAnchor.ParentCenter; + + Agg.Image.ImageBuffer eePromImage = new Agg.Image.ImageBuffer(); + ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), eePromImage); + if (!ActiveTheme.Instance.IsDarkTheme) + { + InvertLightness.DoInvertLightness(eePromImage); + } + ImageWidget eePromIcon = new ImageWidget(eePromImage); + eePromIcon.Margin = new BorderDouble(right: 6); + + configureEePromButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper()); + + //buttonRow.AddChild(eePromIcon); buttonRow.AddChild(notificationSettingsLabel); buttonRow.AddChild(new HorizontalSpacer()); - buttonRow.AddChild(configureAutoLevelButton); + buttonRow.AddChild(configureEePromButton); + return buttonRow; } @@ -80,13 +184,54 @@ namespace MatterHackers.MatterControl.ConfigurationPage { configureAutoLevelButton.Click += new ButtonBase.ButtonEventHandler(configureAutoLevelButton_Click); configureEePromButton.Click += new ButtonBase.ButtonEventHandler(configureEePromButton_Click); + PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); + PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); } void configureEePromButton_Click(object sender, MouseEventArgs mouseEvent) { UiThread.RunOnIdle((state) => { - //Do stuff +#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 EePromRepetierWidget(); + openEePromRepetierWidget.Closed += (RepetierWidget, RepetierEvent) => + { + openEePromRepetierWidget = null; + }; + } + break; + + case PrinterConnectionAndCommunication.FirmwareTypes.Marlin: + if (openEePromMarlinWidget != null) + { + openEePromMarlinWidget.BringToFront(); + } + else + { + openEePromMarlinWidget = new EePromMarlinWidget(); + openEePromMarlinWidget.Closed += (marlinWidget, marlinEvent) => + { + openEePromMarlinWidget = null; + }; + } + break; + + default: + StyledMessageBox.ShowMessageBox(noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); + break; + } +#endif }); } @@ -98,5 +243,107 @@ namespace MatterHackers.MatterControl.ConfigurationPage }); } + private void onPrinterStatusChanged(object sender, EventArgs e) + { + SetVisibleControls(); + this.Invalidate(); + } + + void enablePrintLeveling_Click(object sender, MouseEventArgs mouseEvent) + { + ActivePrinterProfile.Instance.DoPrintLeveling = true; + } + + void disablePrintLeveling_Click(object sender, MouseEventArgs mouseEvent) + { + ActivePrinterProfile.Instance.DoPrintLeveling = false; + } + + void SetPrintLevelButtonVisiblity() + { + enablePrintLevelingButton.Visible = !ActivePrinterProfile.Instance.DoPrintLeveling; + disablePrintLevelingButton.Visible = ActivePrinterProfile.Instance.DoPrintLeveling; + + if (ActivePrinterProfile.Instance.DoPrintLeveling) + { + printLevelingStatusLabel.Text = LocalizedString.Get("Automatic Print Leveling (enabled)"); + } + else + { + printLevelingStatusLabel.Text = LocalizedString.Get("Automatic Print Leveling (disabled)"); + } + } + + private void SetVisibleControls() + { + if (ActivePrinterProfile.Instance.ActivePrinter == null) + { + // 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 + { + //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: + 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; + + case PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint: + case PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrintToSd: + case PrinterConnectionAndCommunication.CommunicationStates.PrintingToSd: + case PrinterConnectionAndCommunication.CommunicationStates.Printing: + switch (PrinterConnectionAndCommunication.Instance.PrintingState) + { + case PrinterConnectionAndCommunication.DetailedPrintingState.HomingAxis: + case PrinterConnectionAndCommunication.DetailedPrintingState.HeatingBed: + case PrinterConnectionAndCommunication.DetailedPrintingState.HeatingExtruder: + case PrinterConnectionAndCommunication.DetailedPrintingState.Printing: + eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + break; + + default: + throw new NotImplementedException(); + } + break; + + case PrinterConnectionAndCommunication.CommunicationStates.Paused: + eePromControlsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + printLevelingContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled); + terminalCommunicationsContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled); + break; + + default: + throw new NotImplementedException(); + } + } + } + + } } \ No newline at end of file diff --git a/ConfigurationPage/SettingsViewBase.cs b/ConfigurationPage/SettingsViewBase.cs index 5418d07a1..210c3c1a2 100644 --- a/ConfigurationPage/SettingsViewBase.cs +++ b/ConfigurationPage/SettingsViewBase.cs @@ -37,11 +37,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage //this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; this.separatorLineColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 100); this.Margin = new BorderDouble(2, 4, 2, 0); - this.textImageButtonFactory.normalFillColor = RGBA_Bytes.White; + this.textImageButtonFactory.normalFillColor = RGBA_Bytes.Transparent; this.textImageButtonFactory.disabledFillColor = RGBA_Bytes.White; this.textImageButtonFactory.FixedHeight = TallButtonHeight; this.textImageButtonFactory.fontSize = 11; + this.textImageButtonFactory.borderWidth = 1; + this.textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200); + this.textImageButtonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200); this.textImageButtonFactory.disabledTextColor = RGBA_Bytes.DarkGray; this.textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor; diff --git a/ControlElements/TextImageButtonFactory.cs b/ControlElements/TextImageButtonFactory.cs index 6fa417784..a9ab83db0 100644 --- a/ControlElements/TextImageButtonFactory.cs +++ b/ControlElements/TextImageButtonFactory.cs @@ -193,6 +193,14 @@ namespace MatterHackers.MatterControl return buffer; } + public Button GenerateEditButton() + { + Button editButton = new Button(0, 0, new ButtonViewThreeImage(LoadUpButtonImage("icon_edit_white.png"), LoadUpButtonImage("icon_edit_gray.png"), LoadUpButtonImage("icon_edit_black.png"))); + editButton.Margin = new BorderDouble(2, -2, 2, 0); + editButton.VAnchor = Agg.UI.VAnchor.ParentTop; + return editButton; + } + public GuiWidget GenerateGroupBoxLabelWithEdit(string label, out Button editButton) { FlowLayoutWidget groupLableAndEditControl = new FlowLayoutWidget(); diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 5a8107ffb..c37de4b98 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -319,8 +319,8 @@ namespace MatterHackers.MatterControl width = Math.Max(int.Parse(sizes[0]), 600); height = Math.Max(int.Parse(sizes[1]), 600); } - - new MatterControlApplication(1024, 600); + + new MatterControlApplication(width, height); } public override void OnClosed(EventArgs e) diff --git a/PrinterControls/TemperatureIndicator.cs b/PrinterControls/TemperatureIndicator.cs index 48f619de1..5756e05e1 100644 --- a/PrinterControls/TemperatureIndicator.cs +++ b/PrinterControls/TemperatureIndicator.cs @@ -72,7 +72,7 @@ namespace MatterHackers.MatterControl void SetDisplayAttributes() { - this.textImageButtonFactory.normalFillColor = RGBA_Bytes.White; + this.textImageButtonFactory.normalFillColor = RGBA_Bytes.Transparent; this.textImageButtonFactory.FixedWidth = 38* TextWidget.GlobalPointSizeScaleRatio; this.textImageButtonFactory.FixedHeight = 20* TextWidget.GlobalPointSizeScaleRatio; diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 73dbd8bda..c6a7f1f0e 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -2597,3 +2597,6 @@ Translated:Layer Preview English:Enable Cloud Monitoring (disabled) Translated:Enable Cloud Monitoring (disabled) +English:Warning - Moving Too Low +Translated:Warning - Moving Too Low +