diff --git a/AboutPage/UpdateControlView.cs b/AboutPage/UpdateControlView.cs index 7a766806a..14df780b2 100644 --- a/AboutPage/UpdateControlView.cs +++ b/AboutPage/UpdateControlView.cs @@ -92,10 +92,7 @@ namespace MatterHackers.MatterControl public override void OnClosed(EventArgs e) { - if (unregisterEvents != null) - { - unregisterEvents(this, null); - } + unregisterEvents?.Invoke(this, null); base.OnClosed(e); } diff --git a/ActionBar/TemperatureWidgetBase.cs b/ActionBar/TemperatureWidgetBase.cs index 747e2ab61..fa71a7bcf 100644 --- a/ActionBar/TemperatureWidgetBase.cs +++ b/ActionBar/TemperatureWidgetBase.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2014, Kevin Pope +Copyright (c) 2017, Kevin Pope, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -27,24 +27,30 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Agg.VertexSource; using MatterHackers.Localizations; using MatterHackers.MatterControl.PrinterCommunication; -using System; namespace MatterHackers.MatterControl.ActionBar { internal class TemperatureWidgetBase : GuiWidget { - protected TextWidget currentTempIndicator; + private TextWidget currentTempIndicator; protected TextWidget temperatureTypeName; protected Button preheatButton; - protected TextImageButtonFactory whiteButtonFactory = new TextImageButtonFactory(); + protected TextImageButtonFactory whiteButtonFactory = new TextImageButtonFactory() + { + FixedHeight = 18 * GuiWidget.DeviceScale, + fontSize = 7, + normalFillColor = RGBA_Bytes.White, + normalTextColor = RGBA_Bytes.DarkGray, + }; - private RGBA_Bytes borderColor = new RGBA_Bytes(255, 255, 255); + private static RGBA_Bytes borderColor = new RGBA_Bytes(255, 255, 255); private int borderWidth = 2; public string IndicatorValue @@ -62,99 +68,73 @@ namespace MatterHackers.MatterControl.ActionBar } } - private EventHandler unregisterEvents; - public TemperatureWidgetBase(string textValue) : base(52 * GuiWidget.DeviceScale, 52 * GuiWidget.DeviceScale) { - whiteButtonFactory.FixedHeight = 18 * GuiWidget.DeviceScale; - whiteButtonFactory.fontSize = 7; - whiteButtonFactory.normalFillColor = RGBA_Bytes.White; - whiteButtonFactory.normalTextColor = RGBA_Bytes.DarkGray; - this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 200); this.Margin = new BorderDouble(0, 2) * GuiWidget.DeviceScale; - temperatureTypeName = new TextWidget("", pointSize: 8); - temperatureTypeName.AutoExpandBoundsToText = true; - temperatureTypeName.HAnchor = HAnchor.ParentCenter; - temperatureTypeName.VAnchor = VAnchor.ParentTop; - temperatureTypeName.Margin = new BorderDouble(0, 3); - temperatureTypeName.TextColor = ActiveTheme.Instance.SecondaryAccentColor; - temperatureTypeName.Visible = false; + temperatureTypeName = new TextWidget("", pointSize: 8) + { + AutoExpandBoundsToText = true, + HAnchor = HAnchor.ParentCenter, + VAnchor = VAnchor.ParentTop, + Margin = new BorderDouble(0, 3), + TextColor = ActiveTheme.Instance.SecondaryAccentColor, + Visible = false + }; + this.AddChild(temperatureTypeName); - currentTempIndicator = new TextWidget(textValue, pointSize: 11); - currentTempIndicator.TextColor = ActiveTheme.Instance.PrimaryAccentColor; - currentTempIndicator.HAnchor = HAnchor.ParentCenter; - currentTempIndicator.VAnchor = VAnchor.ParentCenter; - currentTempIndicator.AutoExpandBoundsToText = true; + currentTempIndicator = new TextWidget(textValue, pointSize: 11) + { + TextColor = ActiveTheme.Instance.PrimaryAccentColor, + HAnchor = HAnchor.ParentCenter, + VAnchor = VAnchor.ParentCenter, + AutoExpandBoundsToText = true + }; + this.AddChild(currentTempIndicator); - GuiWidget buttonContainer = new GuiWidget(); - buttonContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight; - buttonContainer.Height = 18 * GuiWidget.DeviceScale; + var buttonContainer = new GuiWidget() + { + HAnchor = Agg.UI.HAnchor.ParentLeftRight, + Height = 18 * GuiWidget.DeviceScale + }; + this.AddChild(buttonContainer); preheatButton = whiteButtonFactory.Generate("Preheat".Localize().ToUpper()); preheatButton.Cursor = Cursors.Hand; preheatButton.Visible = false; - + preheatButton.Click += (s, e) => SetTargetTemperature(); buttonContainer.AddChild(preheatButton); - - this.AddChild(temperatureTypeName); - this.AddChild(currentTempIndicator); - this.AddChild(buttonContainer); - - this.MouseEnterBounds += onEnterBounds; - this.MouseLeaveBounds += onLeaveBounds; - this.preheatButton.Click += onPreheatButtonClick; } - public override void OnClosed(EventArgs e) - { - if (unregisterEvents != null) - { - unregisterEvents(this, null); - } - base.OnClosed(e); - } - - public void ThemeChanged(object sender, EventArgs e) - { - this.currentTempIndicator.TextColor = ActiveTheme.Instance.PrimaryAccentColor; - this.Invalidate(); - } - - private void onEnterBounds(Object sender, EventArgs e) + public override void OnMouseEnterBounds(MouseEventArgs mouseEvent) { temperatureTypeName.Visible = true; if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected && !PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) { preheatButton.Visible = true; } + + base.OnMouseEnterBounds(mouseEvent); } - private void onLeaveBounds(Object sender, EventArgs e) + public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent) { temperatureTypeName.Visible = false; preheatButton.Visible = false; + + base.OnMouseLeaveBounds(mouseEvent); } public override void OnDraw(Graphics2D graphics2D) { base.OnDraw(graphics2D); - RectangleDouble Bounds = LocalBounds; - RoundedRect borderRect = new RoundedRect(this.LocalBounds, 0); - Stroke strokeRect = new Stroke(borderRect, borderWidth); - graphics2D.Render(strokeRect, borderColor); + var borderRect = new RoundedRect(this.LocalBounds, 0); + graphics2D.Render(new Stroke(borderRect, borderWidth), borderColor); } - private void onPreheatButtonClick(object sender, EventArgs e) - { - SetTargetTemperature(); - } - - protected virtual void SetTargetTemperature() - { - } + protected virtual void SetTargetTemperature() { } } } \ No newline at end of file diff --git a/ActionBar/TemperatureWidgetBed.cs b/ActionBar/TemperatureWidgetBed.cs index 87659a8be..a95bf5070 100644 --- a/ActionBar/TemperatureWidgetBed.cs +++ b/ActionBar/TemperatureWidgetBed.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2014, Kevin Pope +Copyright (c) 2017, Kevin Pope, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -27,40 +27,37 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; using MatterHackers.Localizations; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.SlicerConfiguration; -using System; namespace MatterHackers.MatterControl.ActionBar { internal class TemperatureWidgetBed : TemperatureWidgetBase { + private EventHandler unregisterEvents; + + private string sliceSettingsNote = "Note: Slice Settings are applied before the print actually starts. Changes while printing will not effect the active print.".Localize(); + private string waitingForBedToHeatMessage = "The bed is currently heating and its target temperature cannot be changed until it reaches {0}°C.\n\nYou can set the starting bed temperature in SETTINGS -> Filament -> Temperatures.\n\n{1}".Localize(); + private string waitingForBedToHeatTitle = "Waiting For Bed To Heat".Localize(); + //Not currently hooked up to anything public TemperatureWidgetBed() : base("150.3°") { temperatureTypeName.Text = "Print Bed"; - setToCurrentTemperature(); + DisplayCurrentTemperature(); ToolTipText = "Current bed temperature".Localize(); preheatButton.ToolTipText = "Preheat the Bed".Localize(); - PrinterConnectionAndCommunication.Instance.BedTemperatureRead.RegisterEvent(onTemperatureRead, ref unregisterEvents); + + PrinterConnectionAndCommunication.Instance.BedTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents); } - private EventHandler unregisterEvents; - - public override void OnClosed(EventArgs e) - { - if (unregisterEvents != null) - { - unregisterEvents(this, null); - } - base.OnClosed(e); - } - - private void setToCurrentTemperature() + private void DisplayCurrentTemperature() { string tempDirectionIndicator = ""; + if (PrinterConnectionAndCommunication.Instance.TargetBedTemperature > 0) { if ((int)(PrinterConnectionAndCommunication.Instance.TargetBedTemperature + 0.5) < (int)(PrinterConnectionAndCommunication.Instance.ActualBedTemperature + 0.5)) @@ -72,18 +69,10 @@ namespace MatterHackers.MatterControl.ActionBar tempDirectionIndicator = "↑"; } } + this.IndicatorValue = string.Format(" {0:0.#}°{1}", PrinterConnectionAndCommunication.Instance.ActualBedTemperature, tempDirectionIndicator); } - private void onTemperatureRead(Object sender, EventArgs e) - { - setToCurrentTemperature(); - } - - private string sliceSettingsNote = "Note: Slice Settings are applied before the print actually starts. Changes while printing will not effect the active print.".Localize(); - private string waitingForBedToHeatMessage = "The bed is currently heating and its target temperature cannot be changed until it reaches {0}°C.\n\nYou can set the starting bed temperature in SETTINGS -> Filament -> Temperatures.\n\n{1}".Localize(); - private string waitingForBedToHeatTitle = "Waiting For Bed To Heat".Localize(); - protected override void SetTargetTemperature() { double targetTemp = ActiveSliceSettings.Instance.GetValue(SettingsKey.bed_temperature); @@ -103,5 +92,11 @@ namespace MatterHackers.MatterControl.ActionBar } } } + + public override void OnClosed(EventArgs e) + { + unregisterEvents?.Invoke(this, null); + base.OnClosed(e); + } } } \ No newline at end of file diff --git a/ActionBar/TemperatureWidgetExtruder.cs b/ActionBar/TemperatureWidgetExtruder.cs index 3c09713fa..8da0eb2bf 100644 --- a/ActionBar/TemperatureWidgetExtruder.cs +++ b/ActionBar/TemperatureWidgetExtruder.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2016, Kevin Pope, John Lewin +Copyright (c) 2017, Kevin Pope, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -36,7 +36,8 @@ namespace MatterHackers.MatterControl.ActionBar { internal class TemperatureWidgetExtruder : TemperatureWidgetBase { - private int extruderNumber = 1; + // Extruder widget is hard-wired to extruder 0 + private const int extruderIndex = 0; private EventHandler unregisterEvents; private string sliceSettingsNote = "Note: Slice Settings are applied before the print actually starts. Changes while printing will not effect the active print.".Localize(); @@ -46,35 +47,29 @@ namespace MatterHackers.MatterControl.ActionBar : base("150.3°") { temperatureTypeName.Text = "Extruder"; - setToCurrentTemperature(); + DisplayCurrentTemperature(); ToolTipText = "Current extruder temperature".Localize(); preheatButton.ToolTipText = "Preheat the Extruder".Localize(); - PrinterConnectionAndCommunication.Instance.ExtruderTemperatureRead.RegisterEvent((s, e) => setToCurrentTemperature(), ref unregisterEvents); + PrinterConnectionAndCommunication.Instance.ExtruderTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents); } - public override void OnClosed(EventArgs e) - { - unregisterEvents?.Invoke(this, null); - base.OnClosed(e); - } - - private void setToCurrentTemperature() + private void DisplayCurrentTemperature() { string tempDirectionIndicator = ""; - if (PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1) > 0) + if (PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex) > 0) { - if ((int)(PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1) + 0.5) < (int)(PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderNumber - 1) + 0.5)) + if ((int)(PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex) + 0.5) < (int)(PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderIndex) + 0.5)) { tempDirectionIndicator = "↓"; } - else if ((int)(PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1) + 0.5) > (int)(PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderNumber - 1) + 0.5)) + else if ((int)(PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex) + 0.5) > (int)(PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderIndex) + 0.5)) { tempDirectionIndicator = "↑"; } } - this.IndicatorValue = string.Format(" {0:0.#}°{1}", PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderNumber - 1), tempDirectionIndicator); + this.IndicatorValue = string.Format(" {0:0.#}°{1}", PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderIndex), tempDirectionIndicator); } protected override void SetTargetTemperature() @@ -85,16 +80,22 @@ namespace MatterHackers.MatterControl.ActionBar double goalTemp = (int)(targetTemp + .5); if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting && PrinterConnectionAndCommunication.Instance.PrintingState == PrinterConnectionAndCommunication.DetailedPrintingState.HeatingExtruder - && goalTemp != PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1)) + && goalTemp != PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex)) { - string message = string.Format(waitingForExtruderToHeatMessage, PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1), sliceSettingsNote); + string message = string.Format(waitingForExtruderToHeatMessage, PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex), sliceSettingsNote); StyledMessageBox.ShowMessageBox(null, message, "Waiting For Extruder To Heat".Localize()); } else { - PrinterConnectionAndCommunication.Instance.SetTargetExtruderTemperature(extruderNumber - 1, (int)(targetTemp + .5)); + PrinterConnectionAndCommunication.Instance.SetTargetExtruderTemperature(extruderIndex, (int)(targetTemp + .5)); } } } + + public override void OnClosed(EventArgs e) + { + unregisterEvents?.Invoke(this, null); + base.OnClosed(e); + } } } \ No newline at end of file diff --git a/CustomWidgets/PrintingWindow.cs b/CustomWidgets/PrintingWindow.cs index d5040f76e..f4b26a87b 100644 --- a/CustomWidgets/PrintingWindow.cs +++ b/CustomWidgets/PrintingWindow.cs @@ -28,9 +28,10 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; using System.IO; +using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.PlatformAbstract; @@ -45,6 +46,66 @@ using static MatterHackers.MatterControl.JogControls; namespace MatterHackers.MatterControl.CustomWidgets { + public class ExtruderStatusWidget : FlowLayoutWidget + { + private int extruderIndex; + + int fontSize = 14; + + private TextWidget targetTemp; + private TextWidget actualTemp; + + public ExtruderStatusWidget(int extruderIndex) + { + this.extruderIndex = extruderIndex; + + var extruderName = new TextWidget($"{"Extruder".Localize()} {extruderIndex + 1}", pointSize: fontSize, textColor: ActiveTheme.Instance.PrimaryTextColor) + { + AutoExpandBoundsToText = true, + VAnchor = VAnchor.ParentCenter, + Margin = new BorderDouble(right: 8) + }; + + this.AddChild(extruderName); + + this.AddChild(new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "extruder_temp.png"))) + { + Margin = new BorderDouble(right: 8) + }); + + actualTemp = new TextWidget("", pointSize: fontSize, textColor: ActiveTheme.Instance.PrimaryTextColor) + { + AutoExpandBoundsToText = true, + VAnchor = VAnchor.ParentCenter, + Margin = new BorderDouble(right: 8) + }; + this.AddChild(actualTemp); + + this.AddChild(new VerticalLine() + { + BackgroundColor = new RGBA_Bytes(200, 200, 200, 30), + Margin = new BorderDouble(right: 8) + }); + + targetTemp = new TextWidget("", pointSize: fontSize, textColor: ActiveTheme.Instance.PrimaryTextColor) + { + AutoExpandBoundsToText = true, + VAnchor = VAnchor.ParentCenter, + Margin = new BorderDouble(right: 8) + }; + this.AddChild(targetTemp); + } + + public void UpdateTemperatures() + { + double targetValue = PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex); + double actualValue = PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(extruderIndex); + + this.actualTemp.Text = $"{actualValue:0.#}°"; + this.targetTemp.Text = $"{targetValue:0.#}°"; + } + } + public class ProgressDial : GuiWidget { private double completedRatio = 0; @@ -79,9 +140,6 @@ namespace MatterHackers.MatterControl.CustomWidgets } } - public string ExtruderTemp { get; internal set; } - public string BedTemp { get; internal set; } - private RGBA_Bytes PrimaryAccentColor = ActiveTheme.Instance.PrimaryAccentColor; private RGBA_Bytes PrimaryAccentShade = ActiveTheme.Instance.PrimaryAccentColor.AdjustLightness(0.7).GetAsRGBA_Bytes(); private double strokeWidth = 10; @@ -204,41 +262,31 @@ namespace MatterHackers.MatterControl.CustomWidgets }; */ - private static MoveButtonFactory buttonFactory = new MoveButtonFactory() + private MoveButtonFactory buttonFactory = new MoveButtonFactory() { FontSize = 13, }; - static ZAxisControls() + public ZAxisControls() : + base(FlowDirection.TopToBottom) { buttonFactory.Colors.Fill.Normal = ActiveTheme.Instance.PrimaryAccentColor; buttonFactory.Colors.Fill.Hover = ActiveTheme.Instance.PrimaryAccentColor; buttonFactory.BorderWidth = 0; buttonFactory.Colors.Text.Normal = ActiveTheme.Instance.PrimaryTextColor; - } - public ZAxisControls() : - base(FlowDirection.TopToBottom) - { this.AddChild(new TextWidget("Z+", pointSize: 15, textColor: ActiveTheme.Instance.PrimaryTextColor) { HAnchor = HAnchor.ParentCenter, Margin = new BorderDouble(bottom: 8) }); - Button button; - button = CreateButton(1); - button.Click += (s, e) => MoveZAxis(1.0); - this.AddChild(button); + this.AddChild(CreateZMoveButton(1)); - button = CreateButton(.1); - button.Click += (s, e) => MoveZAxis(0.1); - this.AddChild(button); + this.AddChild(CreateZMoveButton(.1)); - button = CreateButton(.02); - button.Click += (s, e) => MoveZAxis(0.02); - this.AddChild(button); + this.AddChild(CreateZMoveButton(.02)); this.AddChild(new ZTuningWidget() { @@ -246,17 +294,11 @@ namespace MatterHackers.MatterControl.CustomWidgets Margin = 10 }); - button = CreateButton(-.02); - button.Click += (s, e) => MoveZAxis(-0.02); - this.AddChild(button); + this.AddChild(CreateZMoveButton(-.02)); - button = CreateButton(-.1); - button.Click += (s, e) => MoveZAxis(-0.1); - this.AddChild(button); + this.AddChild(CreateZMoveButton(-.1)); - button = CreateButton(-1); - button.Click += (s, e) => MoveZAxis(1.0); - this.AddChild(button); + this.AddChild(CreateZMoveButton(-1)); this.AddChild(new TextWidget("Z-", pointSize: 15, textColor: ActiveTheme.Instance.PrimaryTextColor) { @@ -272,12 +314,7 @@ namespace MatterHackers.MatterControl.CustomWidgets this.VAnchor = VAnchor.FitToChildren | VAnchor.ParentTop; } - public void MoveZAxis(double moveAmount) - { - // Move by (moveAmount); - } - - private Button CreateButton(double moveAmount, bool centerText = true) + private Button CreateZMoveButton(double moveAmount, bool centerText = true) { var button = buttonFactory.GenerateMoveButton($"{Math.Abs(moveAmount):0.00} mm", PrinterConnectionAndCommunication.Axis.Z, MovementControls.ZSpeed); button.MoveAmount = moveAmount; @@ -290,7 +327,6 @@ namespace MatterHackers.MatterControl.CustomWidgets return button; } - } public class PrintingWindow : SystemWindow @@ -301,6 +337,10 @@ namespace MatterHackers.MatterControl.CustomWidgets private TextWidget printerName; private TextWidget partName; + private List extruderStatusWidgets; + + private EventHandler unregisterEvents; + AverageMillisecondTimer millisecondTimer = new AverageMillisecondTimer(); Stopwatch totalDrawTime = new Stopwatch(); @@ -310,6 +350,10 @@ namespace MatterHackers.MatterControl.CustomWidgets { fontSize = 15, invertImageLocation = false, + normalTextColor = ActiveTheme.Instance.PrimaryTextColor, + hoverTextColor = ActiveTheme.Instance.PrimaryTextColor, + disabledTextColor = ActiveTheme.Instance.PrimaryTextColor, + pressedTextColor = ActiveTheme.Instance.PrimaryTextColor, }; private Button CreateButton(string localizedText, bool centerText = true) @@ -354,7 +398,7 @@ namespace MatterHackers.MatterControl.CustomWidgets BackgroundColor = new RGBA_Bytes(200, 200, 200, 30) }; } - + public PrintingWindow(Action onCloseCallback, bool mockMode = false) : base(1280, 750) { @@ -416,7 +460,7 @@ namespace MatterHackers.MatterControl.CustomWidgets actionBar.AddChild(cancelButton); actionBar.AddChild(CreateVerticalLine()); - + var advancedButton = CreateButton("Advanced".Localize().ToUpper()); actionBar.AddChild(advancedButton); @@ -424,14 +468,14 @@ namespace MatterHackers.MatterControl.CustomWidgets { VAnchor = VAnchor.ParentBottomTop, HAnchor = HAnchor.ParentLeftRight, - Padding = new BorderDouble(50, 70), + Padding = new BorderDouble(50), BackgroundColor = new RGBA_Bytes(35, 40, 49), }; topToBottom.AddChild(bodyContainer); var bodyRow = new FlowLayoutWidget(FlowDirection.LeftToRight) { - VAnchor =VAnchor.ParentBottomTop, + VAnchor = VAnchor.ParentBottomTop, HAnchor = HAnchor.ParentLeftRight, //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20), }; @@ -457,7 +501,7 @@ namespace MatterHackers.MatterControl.CustomWidgets } var partThumbnail = new ImageWidget(imageBuffer) - { + { VAnchor = VAnchor.ParentCenter, Margin = new BorderDouble(right: 50) }; @@ -540,19 +584,22 @@ namespace MatterHackers.MatterControl.CustomWidgets bodyRow.AddChild(widget); } - var footerBar = new FlowLayoutWidget (FlowDirection.LeftToRight) + var footerBar = new FlowLayoutWidget(FlowDirection.LeftToRight) { VAnchor = VAnchor.ParentBottom | VAnchor.FitToChildren, HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren, - BackgroundColor = new RGBA_Bytes(35, 40, 49) + BackgroundColor = new RGBA_Bytes(35, 40, 49), + Margin = new BorderDouble(bottom: 30) }; topToBottom.AddChild (footerBar); - int extruderCount = 3; + int extruderCount = mockMode ? 3 : ActiveSliceSettings.Instance.GetValue(SettingsKey.extruder_count); + + extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(i)).ToList(); if (extruderCount == 1) { - footerBar.AddChild(new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "Extruder.png")))); + footerBar.AddChild(extruderStatusWidgets[0]); } else { @@ -562,15 +609,18 @@ namespace MatterHackers.MatterControl.CustomWidgets var columnB = new FlowLayoutWidget(FlowDirection.TopToBottom); footerBar.AddChild(columnB); + // Add each status widget into the scene, placing into the appropriate column for (var i = 0; i < extruderCount; i++) { + var widget = extruderStatusWidgets[i]; if (i % 2 == 0) { - columnA.AddChild(new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "Extruder.png")))); + widget.Margin = new BorderDouble(right: 20); + columnA.AddChild(widget); } else { - columnB.AddChild(new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "Extruder.png")))); + columnB.AddChild(widget); } } } @@ -586,76 +636,42 @@ namespace MatterHackers.MatterControl.CustomWidgets CheckOnPrinter(); } }); + + PrinterConnectionAndCommunication.Instance.ExtruderTemperatureRead.RegisterEvent((s, e) => + { + var eventArgs = e as TemperatureEventArgs; + if (eventArgs != null && eventArgs.Index0Based < extruderStatusWidgets.Count) + { + extruderStatusWidgets[eventArgs.Index0Based].UpdateTemperatures(); + } + }, ref unregisterEvents); } void CheckOnPrinter() { - //if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) - { - GetProgressInfo(); - UiThread.RunOnIdle(CheckOnPrinter, 1); - } - /* - else - { - UiThread.RunOnIdle(Close); - } - */ + GetProgressInfo(); + UiThread.RunOnIdle(CheckOnPrinter, 1); } private void GetProgressInfo() { - string timeString = ""; int secondsPrinted = PrinterConnectionAndCommunication.Instance.SecondsPrinted; int hoursPrinted = (int)(secondsPrinted / (60 * 60)); int minutesPrinted = (int)(secondsPrinted / 60 - hoursPrinted * 60); secondsPrinted = secondsPrinted % 60; - if (hoursPrinted > 0) - { - timeString = string.Format("{0}:{1:00}:{2:00}", - hoursPrinted, - minutesPrinted, - secondsPrinted); - } - else - { - timeString = string.Format("{0}:{1:00}", - minutesPrinted, - secondsPrinted); - } - - timeWidget.Text = timeString; - - //progressDial.SomeText = "{0}: {1} {2}: {3:.0}% {4}".FormatWith(timeTextString, timeString, progressString, PrinterConnectionAndCommunication.Instance.PercentComplete, completeString); - - bool hasHeatedBed = ActiveSliceSettings.Instance.GetValue("has_heated_bed"); - - progressDial.ExtruderTemp = "Extruder: {0:0.0}° | {1}°".FormatWith(PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(0), PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(0)); - progressDial.BedTemp = !hasHeatedBed ? "" : "Bed: {0:0.0}° | {1}°".FormatWith(PrinterConnectionAndCommunication.Instance.ActualBedTemperature, PrinterConnectionAndCommunication.Instance.TargetBedTemperature); + // TODO: Consider if the consistency of a common time format would look and feel better than changing formats based on elapsed duration + timeWidget.Text = (hoursPrinted <= 0) ? $"{minutesPrinted}:{1:00}" : $"{hoursPrinted}:{minutesPrinted:00}:{secondsPrinted:00}"; progressDial.LayerCount = PrinterConnectionAndCommunication.Instance.CurrentlyPrintingLayer; progressDial.LayerCompletedRatio = PrinterConnectionAndCommunication.Instance.RatioIntoCurrentLayer; progressDial.CompletedRatio = PrinterConnectionAndCommunication.Instance.PercentComplete / 100; - } - public override void OnDraw(Graphics2D graphics2D) - { - //totalDrawTime.Restart(); - base.OnDraw(graphics2D); - - //Vector2 center = new Vector2(Width/2, Height/2); - //RectangleDouble thermometerRect = new RectangleDouble(center.x - Width/6, center.y - Height/32, center.x + Width/6, center.y + Height/32); - //thermometerRect.Offset(0, -Height/4); - //graphics2D.Rectangle(thermometerRect, ActiveTheme.Instance.PrimaryAccentColor); - //RectangleDouble thermometerFill = new RectangleDouble(thermometerRect.Left, thermometerRect.Bottom, thermometerRect.Left + thermometerRect.Width * PrinterConnectionAndCommunication.Instance.PercentComplete / 100, thermometerRect.Top); - //graphics2D.FillRectangle(thermometerFill, ActiveTheme.Instance.PrimaryAccentColor); - - //totalDrawTime.Stop(); - - //millisecondTimer.Update((int)totalDrawTime.ElapsedMilliseconds); - - //millisecondTimer.Draw(graphics2D, this.Width * 3 / 4 - 15, this.Height - 120); + /* + bool hasHeatedBed = ActiveSliceSettings.Instance.GetValue("has_heated_bed"); + progressDial.ExtruderTemp = "Extruder: {0:0.0}° | {1}°".FormatWith(PrinterConnectionAndCommunication.Instance.GetActualExtruderTemperature(0), PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(0)); + progressDial.BedTemp = !hasHeatedBed ? "" : "Bed: {0:0.0}° | {1}°".FormatWith(PrinterConnectionAndCommunication.Instance.ActualBedTemperature, PrinterConnectionAndCommunication.Instance.TargetBedTemperature); + */ } public static bool IsShowing @@ -682,6 +698,8 @@ namespace MatterHackers.MatterControl.CustomWidgets public override void OnClosed(EventArgs e) { + unregisterEvents?.Invoke(this, null); + instance = null; base.OnClosed(e); onCloseCallback(); diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index 39b1097a5..090068da4 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -3079,43 +3079,26 @@ namespace MatterHackers.MatterControl.PrinterCommunication public class PrintItemWrapperEventArgs : EventArgs { - private PrintItemWrapper printItemWrapper; - public PrintItemWrapperEventArgs(PrintItemWrapper printItemWrapper) { - this.printItemWrapper = printItemWrapper; + this.PrintItemWrapper = printItemWrapper; } - public PrintItemWrapper PrintItemWrapper - { - get { return printItemWrapper; } - } + public PrintItemWrapper PrintItemWrapper { get; } } /// /// This is a class to pass temperatures to callbacks that expect them. - /// A call back can try and cast to this ( TemperatureEventArgs tempArgs = e as TemperatureEventArgs) - /// and then use the temperature if available. /// public class TemperatureEventArgs : EventArgs { - private int index0Based; - private double temperature; - public TemperatureEventArgs(int index0Based, double temperature) { - this.index0Based = index0Based; - this.temperature = temperature; + this.Index0Based = index0Based; + this.Temperature = temperature; } - public int Index0Based - { - get { return index0Based; } - } - - public double Temperature - { - get { return temperature; } - } + public int Index0Based { get; } + public double Temperature { get; } } } diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index f995c5e29..96c879330 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit f995c5e29ece6e2603117314fc8cc7d88d4cd89a +Subproject commit 96c879330d24238469b5f5a91df84d4842f0e527