From 43f7eb893b3f2b8aa3caa2674c340486929b968c Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 10 Apr 2018 14:05:56 -0700 Subject: [PATCH 1/6] Remove dead code --- DataStorage/Models.cs | 12 ------------ PrinterCommunication/PrinterConnection.cs | 2 -- 2 files changed, 14 deletions(-) diff --git a/DataStorage/Models.cs b/DataStorage/Models.cs index f7f3f77ad..f44e584d1 100644 --- a/DataStorage/Models.cs +++ b/DataStorage/Models.cs @@ -89,8 +89,6 @@ namespace MatterHackers.MatterControl.DataStorage isSaved = false; } - public event PropertyChangedEventHandler PropertyChanged; - [PrimaryKey, AutoIncrement] public int Id { get; set; } @@ -147,16 +145,6 @@ namespace MatterHackers.MatterControl.DataStorage return this.hashCode; } - protected void OnPropertyChanged(string name) - { - PropertyChangedEventHandler handler = PropertyChanged; - this.hashCode = 0; - if (handler != null) - { - handler(this, new PropertyChangedEventArgs(name)); - } - } - private void TryHandleInsert() { retryCount++; diff --git a/PrinterCommunication/PrinterConnection.cs b/PrinterCommunication/PrinterConnection.cs index ba3054ab3..f081abc2c 100644 --- a/PrinterCommunication/PrinterConnection.cs +++ b/PrinterCommunication/PrinterConnection.cs @@ -465,8 +465,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication { if (activePrintTask != null) { - TimeSpan printTimeSpan = DateTime.Now.Subtract(activePrintTask.PrintStart); - activePrintTask.PrintEnd = DateTime.Now; activePrintTask.PercentDone = 100; activePrintTask.PrintComplete = true; From a261990c86e34cb6aaf083a997ae20550e9809af Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 10 Apr 2018 14:42:13 -0700 Subject: [PATCH 2/6] Switch from DisableablePanel to conditionally disabled children - Issue MatterHackers/MCCentral#3032 Can't set target temps when not connected --- ActionBar/TemperatureWidgetBase.cs | 40 +++++++++++++------------- ActionBar/TemperatureWidgetBed.cs | 4 ++- ActionBar/TemperatureWidgetExtruder.cs | 23 ++++++++------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/ActionBar/TemperatureWidgetBase.cs b/ActionBar/TemperatureWidgetBase.cs index 64e3847f5..c8e013ebc 100644 --- a/ActionBar/TemperatureWidgetBase.cs +++ b/ActionBar/TemperatureWidgetBase.cs @@ -28,11 +28,11 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Collections.Generic; +using System.Linq; using MatterHackers.Agg; -using MatterHackers.Agg.ImageProcessing; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; -using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PartPreviewWindow; namespace MatterHackers.MatterControl.ActionBar @@ -52,12 +52,11 @@ namespace MatterHackers.MatterControl.ActionBar protected EventHandler unregisterEvents; protected PrinterConfig printer; + protected List alwaysEnabled; protected virtual int ActualTemperature { get; } protected virtual int TargetTemperature { get; } - private DisableablePanel disableablePanel; - public TemperatureWidgetBase(PrinterConfig printer, string textValue) { this.AlignToRightEdge = true; @@ -66,9 +65,11 @@ namespace MatterHackers.MatterControl.ActionBar this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit | VAnchor.Center; this.Cursor = Cursors.Hand; - + this.MakeScrollable = false; this.AlignToRightEdge = true; + alwaysEnabled = new List(); + var container = new FlowLayoutWidget() { HAnchor = HAnchor.Fit, @@ -106,11 +107,23 @@ namespace MatterHackers.MatterControl.ActionBar }; container.AddChild(DirectionIndicator); + + bool isEnabled = printer.Connection.IsConnected; + printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => { - if (disableablePanel != null) + if (isEnabled != printer.Connection.IsConnected) { - disableablePanel.Enabled = printer.Connection.IsConnected; + isEnabled = printer.Connection.IsConnected; + + var flowLayout = this.PopupContent.Children.OfType().FirstOrDefault(); + if (flowLayout != null) + { + foreach (var child in flowLayout.Children.Except(alwaysEnabled)) + { + child.Enabled = isEnabled; + } + } } }, ref unregisterEvents); @@ -140,19 +153,6 @@ namespace MatterHackers.MatterControl.ActionBar protected virtual void SetTargetTemperature(double targetTemp) { } - protected abstract GuiWidget GetPopupContent(); - - public override void OnLoad(EventArgs args) - { - // Wrap popup content in a DisableablePanel - disableablePanel = new DisableablePanel(this.GetPopupContent(), printer.Connection.IsConnected, alpha: 140); - - // Set as popup - this.PopupContent = disableablePanel; - - base.OnLoad(args); - } - public override void OnClosed(ClosedEventArgs e) { unregisterEvents?.Invoke(this, null); diff --git a/ActionBar/TemperatureWidgetBed.cs b/ActionBar/TemperatureWidgetBed.cs index 06ce6f396..e9e130159 100644 --- a/ActionBar/TemperatureWidgetBed.cs +++ b/ActionBar/TemperatureWidgetBed.cs @@ -56,13 +56,15 @@ namespace MatterHackers.MatterControl.ActionBar this.ImageWidget.Image = AggContext.StaticData.LoadIcon("bed.png", IconColor.Theme); + this.PopupContent = this.GetPopupContent(); + printer.Connection.BedTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents); } protected override int ActualTemperature => (int)printer.Connection.ActualBedTemperature; protected override int TargetTemperature => (int)printer.Connection.TargetBedTemperature; - protected override GuiWidget GetPopupContent() + private GuiWidget GetPopupContent() { var widget = new IgnoredPopupWidget() { diff --git a/ActionBar/TemperatureWidgetExtruder.cs b/ActionBar/TemperatureWidgetExtruder.cs index ab93e21d3..436e05dce 100644 --- a/ActionBar/TemperatureWidgetExtruder.cs +++ b/ActionBar/TemperatureWidgetExtruder.cs @@ -49,7 +49,7 @@ namespace MatterHackers.MatterControl.ActionBar internal ControlContentExtruder(PrinterConfig printer, int extruderIndex, ThemeConfig theme) : base(FlowDirection.TopToBottom) { - HAnchor = HAnchor.Stretch; + this.HAnchor = HAnchor.Stretch; this.printer = printer; @@ -184,21 +184,20 @@ namespace MatterHackers.MatterControl.ActionBar this.ToolTipText = "Current extruder temperature".Localize(); this.theme = theme; + this.PopupContent = this.GetPopupContent(); + printer.Connection.HotendTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents); } protected override int ActualTemperature => (int)printer.Connection.GetActualHotendTemperature(this.hotendIndex); protected override int TargetTemperature => (int)printer.Connection.GetTargetHotendTemperature(this.hotendIndex); - string TemperatureKey + private string TemperatureKey { - get - { - return "temperature" + ((this.hotendIndex > 0 && this.hotendIndex < 4) ? hotendIndex.ToString() : ""); - } + get => "temperature" + ((this.hotendIndex > 0 && this.hotendIndex < 4) ? hotendIndex.ToString() : ""); } - protected override GuiWidget GetPopupContent() + private GuiWidget GetPopupContent() { var widget = new IgnoredPopupWidget() { @@ -248,9 +247,11 @@ namespace MatterHackers.MatterControl.ActionBar var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All); // TODO: make this be for the correct extruder var settingsData = SettingsOrganizer.Instance.GetSettingsData(TemperatureKey); - var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, Color.Black, ApplicationController.Instance.Theme, ref tabIndex); + var temperatureRow = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, Color.Black, ApplicationController.Instance.Theme, ref tabIndex); + container.AddChild(temperatureRow); - container.AddChild(row); + // Add the temperature row to the always enabled list ensuring the field can be set when disconnected + alwaysEnabled.Add(temperatureRow); // add in the temp graph var graph = new DataViewGraph() @@ -269,9 +270,9 @@ namespace MatterHackers.MatterControl.ActionBar graph.AddData(this.ActualTemperature); }, 1, () => !HasBeenClosed); - var valueField = row.Descendants().FirstOrDefault(); + var valueField = temperatureRow.Descendants().FirstOrDefault(); valueField.Name = "Temperature Input"; - var settingsRow = row.DescendantsAndSelf().FirstOrDefault(); + var settingsRow = temperatureRow.DescendantsAndSelf().FirstOrDefault(); ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) => { if (e is StringEventArgs stringEvent) From c4bb2fb26e91a53dd0a785bc76fe5ca37f7d57b6 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 10 Apr 2018 16:55:01 -0700 Subject: [PATCH 3/6] Switch to conditionally disabled children for Bed - Issue MatterHackers/MCCentral#3032 Can't set target temps when not connected --- ActionBar/TemperatureWidgetBed.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ActionBar/TemperatureWidgetBed.cs b/ActionBar/TemperatureWidgetBed.cs index e9e130159..5beaa389f 100644 --- a/ActionBar/TemperatureWidgetBed.cs +++ b/ActionBar/TemperatureWidgetBed.cs @@ -115,9 +115,10 @@ namespace MatterHackers.MatterControl.ActionBar var settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All); var settingsData = SettingsOrganizer.Instance.GetSettingsData(SettingsKey.bed_temperature); - var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, Color.Black, ApplicationController.Instance.Theme, ref tabIndex); + var temperatureRow = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, Color.Black, ApplicationController.Instance.Theme, ref tabIndex); + container.AddChild(temperatureRow); - container.AddChild(row); + alwaysEnabled.Add(hotendRow); // add in the temp graph var graph = new DataViewGraph() @@ -138,8 +139,8 @@ namespace MatterHackers.MatterControl.ActionBar graph.AddData(this.ActualTemperature); }, 1, () => !HasBeenClosed); - var valueField = row.Descendants().FirstOrDefault(); - var settingsRow = row.DescendantsAndSelf().FirstOrDefault(); + var valueField = temperatureRow.Descendants().FirstOrDefault(); + var settingsRow = temperatureRow.DescendantsAndSelf().FirstOrDefault(); ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) => { if (e is StringEventArgs stringEvent) From 44e91e62b13680b42bcb5e0c32a73d4e0ff4f6d7 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 10 Apr 2018 16:56:21 -0700 Subject: [PATCH 4/6] Remove owner drawn borders, let caller add borders as desired --- CustomWidgets/DataViewGraph.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/CustomWidgets/DataViewGraph.cs b/CustomWidgets/DataViewGraph.cs index 4e3c374cf..af016bffd 100644 --- a/CustomWidgets/DataViewGraph.cs +++ b/CustomWidgets/DataViewGraph.cs @@ -88,8 +88,6 @@ namespace MatterHackers.MatterControl.CustomWidgets Color backgroundGridColor = Color.Gray; - graphics2D.Line(0, 0, Width, 0, backgroundGridColor); - graphics2D.Line(0, Height, Width, Height, backgroundGridColor); double pixelSkip = Height; for (int i = 0; i < Width / pixelSkip; i++) From ccff044db0a5e6c1fe8ff003532c7388b4ee5091 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 10 Apr 2018 16:57:34 -0700 Subject: [PATCH 5/6] Refactor to match settings styling - Issue MatterHackers/MCCentral#3093 Inconsistent row styling --- ActionBar/TemperatureWidgetExtruder.cs | 97 ++++++++++++++------------ 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/ActionBar/TemperatureWidgetExtruder.cs b/ActionBar/TemperatureWidgetExtruder.cs index 436e05dce..fa379a10b 100644 --- a/ActionBar/TemperatureWidgetExtruder.cs +++ b/ActionBar/TemperatureWidgetExtruder.cs @@ -50,7 +50,6 @@ namespace MatterHackers.MatterControl.ActionBar : base(FlowDirection.TopToBottom) { this.HAnchor = HAnchor.Stretch; - this.printer = printer; GuiWidget macroButtons = null; @@ -58,7 +57,33 @@ namespace MatterHackers.MatterControl.ActionBar if (extruderIndex == 0) { // add in load and unload buttons - macroButtons = GetExtruderMacros(extruderIndex, theme.MenuButtonFactory); + macroButtons = new FlowLayoutWidget() + { + Padding = theme.ToolbarPadding, + }; + + var loadFilament = new GCodeMacro() + { + GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "load_filament.txt")) + }; + + Button loadButton = theme.MenuButtonFactory.Generate("Load".Localize()); + loadButton.Margin = theme.ButtonSpacing; + loadButton.ToolTipText = "Load filament".Localize(); + loadButton.Click += (s, e) => loadFilament.Run(printer.Connection); + macroButtons.AddChild(loadButton); + + var unloadFilament = new GCodeMacro() + { + GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "unload_filament.txt")) + }; + + Button unloadButton = theme.MenuButtonFactory.Generate("Unload".Localize()); + unloadButton.Margin = theme.ButtonSpacing; + loadButton.ToolTipText = "Unload filament".Localize(); + unloadButton.Click += (s, e) => unloadFilament.Run(printer.Connection); + macroButtons.AddChild(unloadButton); + this.AddChild(new SettingsItem("Filament".Localize(), macroButtons, enforceGutter: false)); } @@ -66,12 +91,13 @@ namespace MatterHackers.MatterControl.ActionBar var buttonContainer = new FlowLayoutWidget() { HAnchor = HAnchor.Fit, - VAnchor = VAnchor.Fit + VAnchor = VAnchor.Fit, + Padding = theme.ToolbarPadding, }; var retractButton = theme.MenuButtonFactory.Generate("Retract".Localize()); + retractButton.Margin = theme.ButtonSpacing; retractButton.ToolTipText = "Retract filament".Localize(); - retractButton.Margin = new BorderDouble(8, 0); retractButton.Click += (s, e) => { printer.Connection.MoveExtruderRelative(moveAmount * -1, printer.Settings.EFeedRate(extruderIndex), extruderIndex); @@ -81,9 +107,9 @@ namespace MatterHackers.MatterControl.ActionBar int extruderButtonTopMargin = macroButtons == null ? 8 : 0; var extrudeButton = theme.MenuButtonFactory.Generate("Extrude".Localize()); + extrudeButton.Margin = theme.ButtonSpacing; extrudeButton.Name = "Extrude Button"; extrudeButton.ToolTipText = "Extrude filament".Localize(); - extrudeButton.Margin = new BorderDouble(0, 0, 0, extruderButtonTopMargin); extrudeButton.Click += (s, e) => { printer.Connection.MoveExtruderRelative(moveAmount, printer.Settings.EFeedRate(extruderIndex), extruderIndex); @@ -97,9 +123,9 @@ namespace MatterHackers.MatterControl.ActionBar var moveButtonsContainer = new FlowLayoutWidget() { - VAnchor = VAnchor.Fit, + VAnchor = VAnchor.Fit | VAnchor.Center, HAnchor = HAnchor.Fit, - Margin = new BorderDouble(0, 3) + Padding = theme.ToolbarPadding, }; RadioButton oneButton = theme.MicroButtonMenu.GenerateRadioButton("1"); @@ -145,26 +171,6 @@ namespace MatterHackers.MatterControl.ActionBar this.AddChild(new SettingsItem("Distance".Localize(), moveButtonsContainer, enforceGutter: false)); } - - private GuiWidget GetExtruderMacros(int extruderIndex, TextImageButtonFactory buttonFactory) - { - var row = new FlowLayoutWidget(); - - GCodeMacro loadFilament = new GCodeMacro(); - loadFilament.GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "load_filament.txt")); - Button loadButton = buttonFactory.Generate("Load".Localize()); - loadButton.Margin = new BorderDouble(0, 8, 8, 4); - loadButton.Click += (s, e) => loadFilament.Run(printer.Connection); - row.AddChild(loadButton); - - GCodeMacro unloadFilament = new GCodeMacro(); - unloadFilament.GCode = AggContext.StaticData.ReadAllText(Path.Combine("SliceSettings", "unload_filament.txt")); - Button unloadButton = buttonFactory.Generate("Unload".Localize()); - unloadButton.Click += (s, e) => unloadFilament.Run(printer.Connection); - row.AddChild(unloadButton); - - return row; - } } internal class TemperatureWidgetHotend : TemperatureWidgetBase @@ -296,35 +302,38 @@ namespace MatterHackers.MatterControl.ActionBar if (hotendIndex == 0) { // put in the material selector - var presetsSelector = new PresetSelectorWidget(printer, "Material".Localize(), Color.Transparent, NamedSettingsLayers.Material, true) - { - Margin = 0, - BackgroundColor = Color.Transparent, - HAnchor = HAnchor.Absolute, - Width = 150 - }; - + var presetsSelector = new PresetSelectorWidget(printer, "Material".Localize(), Color.Transparent, NamedSettingsLayers.Material, true); presetsSelector.DropDownList.Name = "Hotend Preset Selector"; - this.Width = 150; - - // HACK: remove undesired item - var label = presetsSelector.Children().FirstOrDefault(); - label.Close(); - var pulldownContainer = presetsSelector.FindNamedChildRecursive("Preset Pulldown Container"); if (pulldownContainer != null) { - pulldownContainer.Padding = 0; + pulldownContainer.Padding = theme.ToolbarPadding; + pulldownContainer.HAnchor = HAnchor.Fit; + pulldownContainer.Margin = 0; } - var dropList = presetsSelector.FindNamedChildRecursive("Material") as DropDownList; + var dropList = pulldownContainer.Children.OfType().FirstOrDefault(); if (dropList != null) { + dropList.Name = "Hotend Preset Selector"; + dropList.HAnchor = HAnchor.Fit; dropList.TextColor = Color.Black; + dropList.Margin = 0; } - container.AddChild(new SettingsItem("Material".Localize(), presetsSelector, enforceGutter: false)); + // Remove the pulldowncontainer from its parent and add it to our Material row + pulldownContainer.Parent.RemoveChild(pulldownContainer); + pulldownContainer.ClearRemovedFlag(); + container.AddChild( + new SettingsItem("Material".Localize(), pulldownContainer, enforceGutter: false) + { + Border = new BorderDouble(0, 1) + }); + + // Close the presetsSelector + presetsSelector.Close(); + } else // put in a temperature selector for the correct material { From 628b6725b672fdb41a5ae2ae1cfbec295a1632ce Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 10 Apr 2018 17:01:30 -0700 Subject: [PATCH 6/6] Honor user scaling factor - Issue MatterHackers/MCCentral#3095 Toggle switch has fixed sizing, ignore user scaling values --- PartPreviewWindow/RoundedToggleSwitch.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PartPreviewWindow/RoundedToggleSwitch.cs b/PartPreviewWindow/RoundedToggleSwitch.cs index 09e4a1d5d..0ea5f9ef0 100644 --- a/PartPreviewWindow/RoundedToggleSwitch.cs +++ b/PartPreviewWindow/RoundedToggleSwitch.cs @@ -51,8 +51,10 @@ namespace MatterHackers.MatterControl.CustomWidgets private double right; private RoundedRect backgroundBar; - private double toggleRadius = 10; - private double toggleRadiusPlusPadding = 11; + private double minWidth = 45 * DeviceScale; + private double barHeight = 12.6 * DeviceScale; + private double toggleRadius = 9 * DeviceScale; + private double toggleRadiusPlusPadding = 10 * DeviceScale; private bool _checked; public bool Checked @@ -77,7 +79,7 @@ namespace MatterHackers.MatterControl.CustomWidgets inactiveBarColor = theme.Colors.IsDarkTheme ? theme.Shade : theme.SlightShade; activeBarColor = new Color(theme.Colors.PrimaryAccentColor, (theme.Colors.IsDarkTheme ? 100 : 70)); - this.MinimumSize = new Vector2(50, theme.ButtonHeight); + this.MinimumSize = new Vector2(minWidth, theme.ButtonHeight); } public override void OnMouseDown(MouseEventArgs mouseEvent) @@ -179,9 +181,7 @@ namespace MatterHackers.MatterControl.CustomWidgets { centerY = this.LocalBounds.YCenter; - var barHeight = 14; - - int halfBarHeight = barHeight / 2; + var halfBarHeight = barHeight / 2; var diff = toggleRadiusPlusPadding - halfBarHeight;