diff --git a/CustomWidgets/DisableableWidget.cs b/CustomWidgets/DisableableWidget.cs index 7ca13c9a1..09f592958 100644 --- a/CustomWidgets/DisableableWidget.cs +++ b/CustomWidgets/DisableableWidget.cs @@ -32,10 +32,13 @@ namespace MatterHackers.MatterControl.CustomWidgets return true; }); - disableOverlay.LocalBounds = new RectangleDouble(childBounds.Left, - childBounds.Bottom, - childBounds.Right, - childBounds.Top - disableOverlay.Margin.Top); + if (childBounds != RectangleDouble.ZeroIntersection) + { + disableOverlay.LocalBounds = new RectangleDouble(childBounds.Left, + childBounds.Bottom, + childBounds.Right, + childBounds.Top - disableOverlay.Margin.Top); + } } }; diff --git a/CustomWidgets/SolidSlider.cs b/CustomWidgets/SolidSlider.cs index 6073d0d51..e64760988 100644 --- a/CustomWidgets/SolidSlider.cs +++ b/CustomWidgets/SolidSlider.cs @@ -69,12 +69,6 @@ namespace MatterHackers.MatterControl TextColor = RGBA_Bytes.Black; TrackColor = new RGBA_Bytes(220, 220, 220); ThumbColor = ActiveTheme.Instance.SecondaryAccentColor; - - sliderWidget.ValueChanged += new EventHandler(sliderWidget_ValueChanged); - } - - private void sliderWidget_ValueChanged(object sender, EventArgs e) - { } private RectangleDouble GetTrackBounds() @@ -384,10 +378,7 @@ namespace MatterHackers.MatterControl if (oldValue != Value) { - if (ValueChanged != null) - { - ValueChanged(this, mouseEvent); - } + ValueChanged?.Invoke(this, mouseEvent); Invalidate(); } @@ -424,9 +415,10 @@ namespace MatterHackers.MatterControl { downOnThumb = false; base.OnMouseUp(mouseEvent); - if (valueOnMouseDown != Value && SliderReleased != null) + + if (valueOnMouseDown != Value) { - SliderReleased(this, mouseEvent); + SliderReleased?.Invoke(this, mouseEvent); } } } diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index bd4efab76..721b567ab 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -27,12 +27,19 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; using Gaming.Game; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.GCodeVisualizer; using MatterHackers.Localizations; -using MatterHackers.MatterControl.ActionBar; using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.DataStorage; @@ -43,16 +50,6 @@ using MatterHackers.SerialPortCommunication; using MatterHackers.SerialPortCommunication.FrostedSerial; using MatterHackers.VectorMath; using Microsoft.Win32.SafeHandles; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; namespace MatterHackers.MatterControl.PrinterCommunication { @@ -102,12 +99,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication public RootedObjectEventHandler ExtruderTemperatureSet = new RootedObjectEventHandler(); - public RootedObjectEventHandler ExtrusionRatioChanged = new RootedObjectEventHandler(); - public RootedObjectEventHandler FanSpeedSet = new RootedObjectEventHandler(); - public RootedObjectEventHandler FeedRateRatioChanged = new RootedObjectEventHandler(); - public RootedObjectEventHandler FirmwareVersionRead = new RootedObjectEventHandler(); public RootedObjectEventHandler PositionRead = new RootedObjectEventHandler(); @@ -168,8 +161,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication private int fanSpeed; - private FirmwareTypes firmwareType = FirmwareTypes.Unknown; - private bool firmwareUriGcodeSend = false; private int currentLineIndexToSend = 0; @@ -207,10 +198,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication private DetailedPrintingState printingStatePrivate; - private string printJobDisplayName = null; - - private bool printWasCanceled = false; - private FoundStringContainsCallbacks ReadLineContainsCallBacks = new FoundStringContainsCallbacks(); private FoundStringStartsWithCallbacks ReadLineStartCallBacks = new FoundStringStartsWithCallbacks(); @@ -248,6 +235,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication private double secondsSinceUpdateHistory = 0; + private EventHandler unregisterEvents; + + private double feedRateRatio = 1; + private PrinterConnectionAndCommunication() { MonitorPrinterTemperature = true; @@ -322,6 +313,16 @@ namespace MatterHackers.MatterControl.PrinterCommunication WriteLineStartCallBacks.AddCallbackToKey("M81", AtxPowerDownWasWritenToPrinter); WriteLineStartCallBacks.AddCallbackToKey("T", ExtruderIndexSet); + + ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) => + { + var eventArgs = e as StringEventArgs; + if (eventArgs?.Data == SettingsKey.feedrate_ratio) + { + feedRateRatio = ActiveSliceSettings.Instance.GetValue(SettingsKey.feedrate_ratio); + } + }, ref unregisterEvents); + } private void ExtruderIndexSet(object sender, EventArgs e) @@ -592,28 +593,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - public double ExtrusionRatio - { - get - { - if (extrusionMultiplyerStream7 != null) - { - return extrusionMultiplyerStream7.ExtrusionRatio; - } - - return 1; - } - set - { - if (extrusionMultiplyerStream7 != null - && value != extrusionMultiplyerStream7.ExtrusionRatio) - { - extrusionMultiplyerStream7.ExtrusionRatio = value; - ExtrusionRatioChanged.CallEvents(this, null); - } - } - } - public int FanSpeed0To255 { get { return fanSpeed; } @@ -628,42 +607,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - public double FeedRateRatio - { - get - { - if (feedrateMultiplyerStream8 != null) - { - return feedrateMultiplyerStream8.FeedRateRatio; - } - - return 1; - } - set - { - if (feedrateMultiplyerStream8 != null - && value != feedrateMultiplyerStream8.FeedRateRatio) - { - feedrateMultiplyerStream8.FeedRateRatio = value; - FeedRateRatioChanged.CallEvents(this, null); - } - } - } - - public FirmwareTypes FirmwareType - { - get { return firmwareType; } - } + public FirmwareTypes FirmwareType { get; private set; } = FirmwareTypes.Unknown; public string FirmwareVersion { get; private set; } public Vector3 LastReportedPosition { get { return lastReportedPosition.position; } } - public bool MonitorPrinterTemperature - { - get; - set; - } + public bool MonitorPrinterTemperature { get; set; } public double PercentComplete { @@ -880,15 +830,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - public string PrintJobName - { - get - { - return printJobDisplayName; - } - } + public string PrintJobName { get; private set; } = null; - public bool PrintWasCanceled { get { return printWasCanceled; } } + public bool PrintWasCanceled { get; set; } = false; public double RatioIntoCurrentLayer { @@ -959,9 +903,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication { if (loadedGCode.LineCount > 0) { - if (FeedRateRatio != 0) + if (feedRateRatio != 0) { - return (int)(loadedGCode.TotalSecondsInPrint / FeedRateRatio); + return (int)(loadedGCode.TotalSecondsInPrint / feedRateRatio); } return (int)(loadedGCode.TotalSecondsInPrint); @@ -1064,7 +1008,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication PrinterOutputCache.Instance.Clear(); //Attempt connecting to a specific printer this.stopTryingToConnect = false; - firmwareType = FirmwareTypes.Unknown; + this.FirmwareType = FirmwareTypes.Unknown; firmwareUriGcodeSend = false; // On Android, there will never be more than one serial port available for us to connect to. Override the current .ComPort value to account for @@ -1524,15 +1468,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication firmwareName = firmwareName.ToLower(); if (firmwareName.Contains("repetier")) { - firmwareType = FirmwareTypes.Repetier; + this.FirmwareType = FirmwareTypes.Repetier; } else if (firmwareName.Contains("marlin")) { - firmwareType = FirmwareTypes.Marlin; + this.FirmwareType = FirmwareTypes.Marlin; } else if (firmwareName.Contains("sprinter")) { - firmwareType = FirmwareTypes.Sprinter; + this.FirmwareType = FirmwareTypes.Sprinter; } } string firmwareVersionReported = ""; @@ -2056,10 +2000,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication } haveReportedError = false; - printWasCanceled = false; - ExtrusionRatio = 1; - FeedRateRatio = 1; - waitingForPosition.Stop(); + PrintWasCanceled = false; + waitingForPosition.Reset(); ClearQueuedGCode(); @@ -2159,7 +2101,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication InjectGCode(cancelGCode); } // let the process know we canceled not ended normally. - printWasCanceled = true; + this.PrintWasCanceled = true; if (markPrintCanceled && activePrintTask != null) { @@ -2345,7 +2287,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication }); CommunicationState = CommunicationStates.FinishedPrint; - printJobDisplayName = null; + this.PrintJobName = null; // never leave the extruder and the bed hot TurnOffBedAndExtruders(); @@ -2788,19 +2730,19 @@ namespace MatterHackers.MatterControl.PrinterCommunication currentLineIndexToSend++; } } - else if (printWasCanceled) + else if (this.PrintWasCanceled) { CommunicationState = CommunicationStates.Connected; // never leave the extruder and the bed hot ReleaseMotors(); TurnOffBedAndExtruders(); - printWasCanceled = false; + this.PrintWasCanceled = false; } else if(communicationState == CommunicationStates.Printing)// we finished printing normally { CommunicationState = CommunicationStates.FinishedPrint; - printJobDisplayName = null; + this.PrintJobName = null; // get us back to the no printing setting (this will clear the queued commands) CreateStreamProcessors(null, false); diff --git a/PrinterControls/ControlWidgets/AdjustmentControls.cs b/PrinterControls/ControlWidgets/AdjustmentControls.cs index eb112ac94..ace9a1fbd 100644 --- a/PrinterControls/ControlWidgets/AdjustmentControls.cs +++ b/PrinterControls/ControlWidgets/AdjustmentControls.cs @@ -31,7 +31,7 @@ using System; using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PrinterControls @@ -46,8 +46,8 @@ namespace MatterHackers.MatterControl.PrinterControls private readonly double minExtrutionRatio = .5; private readonly double maxExtrusionRatio = 3; - private readonly double minFeedRateRatio = .5; - private readonly double maxFeedRateRatio = 2; + private readonly double minFeedRateRatio = .25; + private readonly double maxFeedRateRatio = 3; private EventHandler unregisterEvents; @@ -94,23 +94,27 @@ namespace MatterHackers.MatterControl.PrinterControls }; row.AddChild(feedRateDescription); + double feedrateRatio = ActiveSliceSettings.Instance.GetValue(SettingsKey.feedrate_ratio); feedRateRatioSlider = new SolidSlider(new Vector2(), sliderThumbWidth, minFeedRateRatio, maxFeedRateRatio) { Name = "Feed Rate Slider", Margin = new BorderDouble(5, 0), - Value = PrinterConnectionAndCommunication.Instance.FeedRateRatio, + Value = feedrateRatio, HAnchor = HAnchor.ParentLeftRight, TotalWidthInPixels = sliderWidth, }; feedRateRatioSlider.View.BackgroundColor = new RGBA_Bytes(); feedRateRatioSlider.ValueChanged += (sender, e) => { - PrinterConnectionAndCommunication.Instance.FeedRateRatio = feedRateRatioSlider.Value; + feedRateValue.ActuallNumberEdit.Value = Math.Round(feedRateRatioSlider.Value, 2); + }; + feedRateRatioSlider.SliderReleased += (s, e) => + { + ActiveSliceSettings.Instance.SetValue(SettingsKey.feedrate_ratio, Math.Round(feedRateRatioSlider.Value, 2).ToString()); }; row.AddChild(feedRateRatioSlider); - var initialValue = Math.Round(PrinterConnectionAndCommunication.Instance.FeedRateRatio, 2); - feedRateValue = new MHNumberEdit(initialValue, allowDecimals: true, minValue: minFeedRateRatio, maxValue: maxFeedRateRatio, pixelWidth: 40 * GuiWidget.DeviceScale) + feedRateValue = new MHNumberEdit(Math.Round(feedrateRatio, 2), allowDecimals: true, minValue: minFeedRateRatio, maxValue: maxFeedRateRatio, pixelWidth: 40 * GuiWidget.DeviceScale) { Name = "Feed Rate NumberEdit", SelectAllOnFocus = true, @@ -121,6 +125,7 @@ namespace MatterHackers.MatterControl.PrinterControls feedRateValue.ActuallNumberEdit.EditComplete += (sender, e) => { feedRateRatioSlider.Value = feedRateValue.ActuallNumberEdit.Value; + ActiveSliceSettings.Instance.SetValue(SettingsKey.feedrate_ratio, Math.Round(feedRateRatioSlider.Value, 2).ToString()); }; row.AddChild(feedRateValue); @@ -152,22 +157,26 @@ namespace MatterHackers.MatterControl.PrinterControls }; row.AddChild(extrusionDescription); + double extrusionRatio = ActiveSliceSettings.Instance.GetValue(SettingsKey.extrusion_ratio); extrusionRatioSlider = new SolidSlider(new Vector2(), sliderThumbWidth, minExtrutionRatio, maxExtrusionRatio, Orientation.Horizontal) { Name = "Extrusion Multiplier Slider", TotalWidthInPixels = sliderWidth, HAnchor = HAnchor.ParentLeftRight, Margin = new BorderDouble(5, 0), - Value = PrinterConnectionAndCommunication.Instance.ExtrusionRatio + Value = extrusionRatio }; extrusionRatioSlider.View.BackgroundColor = new RGBA_Bytes(); extrusionRatioSlider.ValueChanged += (sender, e) => { - PrinterConnectionAndCommunication.Instance.ExtrusionRatio = extrusionRatioSlider.Value; + extrusionValue.ActuallNumberEdit.Value = Math.Round(extrusionRatioSlider.Value, 2); + }; + extrusionRatioSlider.SliderReleased += (s, e) => + { + ActiveSliceSettings.Instance.SetValue(SettingsKey.extrusion_ratio, Math.Round(extrusionRatioSlider.Value, 2).ToString()); }; - var initialValue = Math.Round(PrinterConnectionAndCommunication.Instance.ExtrusionRatio, 2); - extrusionValue = new MHNumberEdit(initialValue, allowDecimals: true, minValue: minExtrutionRatio, maxValue: maxExtrusionRatio, pixelWidth: 40 * GuiWidget.DeviceScale) + extrusionValue = new MHNumberEdit(Math.Round(extrusionRatio, 2), allowDecimals: true, minValue: minExtrutionRatio, maxValue: maxExtrusionRatio, pixelWidth: 40 * GuiWidget.DeviceScale) { Name = "Extrusion Multiplier NumberEdit", SelectAllOnFocus = true, @@ -178,6 +187,7 @@ namespace MatterHackers.MatterControl.PrinterControls extrusionValue.ActuallNumberEdit.EditComplete += (sender, e) => { extrusionRatioSlider.Value = extrusionValue.ActuallNumberEdit.Value; + ActiveSliceSettings.Instance.SetValue(SettingsKey.extrusion_ratio, Math.Round(extrusionRatioSlider.Value, 2).ToString()); }; row.AddChild(extrusionRatioSlider); row.AddChild(extrusionValue); @@ -195,16 +205,21 @@ namespace MatterHackers.MatterControl.PrinterControls this.AddChild(adjustmentControlsGroupBox); - PrinterConnectionAndCommunication.Instance.ExtrusionRatioChanged.RegisterEvent((s, e) => + ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) => { - extrusionRatioSlider.Value = PrinterConnectionAndCommunication.Instance.ExtrusionRatio; - extrusionValue.ActuallNumberEdit.Value = Math.Round(PrinterConnectionAndCommunication.Instance.ExtrusionRatio, 2); - }, ref unregisterEvents); - - PrinterConnectionAndCommunication.Instance.FeedRateRatioChanged.RegisterEvent((s, e) => - { - feedRateRatioSlider.Value = PrinterConnectionAndCommunication.Instance.FeedRateRatio; - feedRateValue.ActuallNumberEdit.Value = Math.Round(PrinterConnectionAndCommunication.Instance.FeedRateRatio, 2); + var eventArgs = e as StringEventArgs; + if (eventArgs?.Data == SettingsKey.extrusion_ratio) + { + double extrusionRatio = ActiveSliceSettings.Instance.GetValue(SettingsKey.extrusion_ratio); + extrusionRatioSlider.Value = extrusionRatio; + extrusionValue.ActuallNumberEdit.Value = Math.Round(extrusionRatio, 2); + } + else if (eventArgs?.Data == SettingsKey.feedrate_ratio) + { + double feedrateRatio = ActiveSliceSettings.Instance.GetValue(SettingsKey.feedrate_ratio); + feedRateRatioSlider.Value = feedrateRatio; + feedRateValue.ActuallNumberEdit.Value = Math.Round(feedrateRatio, 2); + } }, ref unregisterEvents); } diff --git a/SlicerConfiguration/Settings/PrinterSettings.cs b/SlicerConfiguration/Settings/PrinterSettings.cs index 0284dd92c..9dbf555c5 100644 --- a/SlicerConfiguration/Settings/PrinterSettings.cs +++ b/SlicerConfiguration/Settings/PrinterSettings.cs @@ -1042,7 +1042,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration var persistenceLayer = layer ?? UserLayer; - // If the setting exists and is set the requested value, exit without setting or saving + // If the setting exists and is set to the requested value, exit without setting or saving string existingValue; if (persistenceLayer.TryGetValue(settingsKey, out existingValue) && existingValue == settingsValue) { diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index 9a83f430c..67da8eeb8 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -116,6 +116,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public const string ip_port = nameof(ip_port); public const string first_layer_speed = nameof(first_layer_speed); public const string active_quality_key = nameof(active_quality_key); + public const string extrusion_ratio = nameof(extrusion_ratio); + public const string feedrate_ratio = nameof(feedrate_ratio); } public class SettingsHelpers diff --git a/SlicerConfiguration/SlicingQueue.cs b/SlicerConfiguration/SlicingQueue.cs index 811be725d..369d06408 100644 --- a/SlicerConfiguration/SlicingQueue.cs +++ b/SlicerConfiguration/SlicingQueue.cs @@ -463,7 +463,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration && File.Exists(currentConfigurationFileAndPath)) { // make sure we have not already written the settings onto this file - bool fileHaseSettings = false; + bool fileHasSettings = false; int bufferSize = 32000; using (Stream fileStream = File.OpenRead(gcodePathAndFileName)) { @@ -473,13 +473,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string fileEnd = System.Text.Encoding.UTF8.GetString(buffer); if (fileEnd.Contains("GCode settings used")) { - fileHaseSettings = true; + fileHasSettings = true; } } - if (!fileHaseSettings) + if (!fileHasSettings) { - using (StreamWriter gcodeWirter = File.AppendText(gcodePathAndFileName)) + using (StreamWriter gcodeWriter = File.AppendText(gcodePathAndFileName)) { string oemName = "MatterControl"; if (OemSettings.Instance.WindowTitleExtra != null && OemSettings.Instance.WindowTitleExtra.Trim().Length > 0) @@ -487,12 +487,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration oemName = oemName + " - {0}".FormatWith(OemSettings.Instance.WindowTitleExtra); } - gcodeWirter.WriteLine("; {0} Version {1} Build {2} : GCode settings used".FormatWith(oemName, VersionInfo.Instance.ReleaseVersion, VersionInfo.Instance.BuildVersion)); - gcodeWirter.WriteLine("; Date {0} Time {1}:{2:00}".FormatWith(DateTime.Now.Date, DateTime.Now.Hour, DateTime.Now.Minute)); + gcodeWriter.WriteLine("; {0} Version {1} Build {2} : GCode settings used".FormatWith(oemName, VersionInfo.Instance.ReleaseVersion, VersionInfo.Instance.BuildVersion)); + gcodeWriter.WriteLine("; Date {0} Time {1}:{2:00}".FormatWith(DateTime.Now.Date, DateTime.Now.Hour, DateTime.Now.Minute)); foreach (string line in File.ReadLines(currentConfigurationFileAndPath)) { - gcodeWirter.WriteLine("; {0}".FormatWith(line)); + gcodeWriter.WriteLine("; {0}".FormatWith(line)); } } } diff --git a/StaticData/SliceSettings/Properties.json b/StaticData/SliceSettings/Properties.json index d7b70861c..cedf186d9 100644 --- a/StaticData/SliceSettings/Properties.json +++ b/StaticData/SliceSettings/Properties.json @@ -2677,5 +2677,33 @@ "ShowIfSet": null, "ResetAtEndOfPrint": false, "DefaultValue": "0" + }, + { + "QuickMenuSettings": [ ], + "SetSettingsOnChange": [ ], + "SlicerConfigName": "feedrate_ratio", + "PresentationName": "Feedrate Ratio", + "HelpText": "Controls the speed of printer moves", + "DataEditType": "POSITIVE_DOUBLE", + "ExtraSettings": "", + "ShowAsOverride": true, + "ShowIfSet": null, + "ResetAtEndOfPrint": false, + "DefaultValue": "1", + "RebuildGCodeOnChange": false + }, + { + "QuickMenuSettings": [ ], + "SetSettingsOnChange": [ ], + "SlicerConfigName": "extrusion_ratio", + "PresentationName": "Extrusion Ratio", + "HelpText": "Controls the amount of extrusion", + "DataEditType": "POSITIVE_DOUBLE", + "ExtraSettings": "", + "ShowAsOverride": true, + "ShowIfSet": null, + "ResetAtEndOfPrint": false, + "DefaultValue": "1", + "RebuildGCodeOnChange": false } ] diff --git a/Tests/MatterControl.AutomationTests/PrintingTests.cs b/Tests/MatterControl.AutomationTests/PrintingTests.cs index 44a986282..4561d884f 100644 --- a/Tests/MatterControl.AutomationTests/PrintingTests.cs +++ b/Tests/MatterControl.AutomationTests/PrintingTests.cs @@ -114,8 +114,11 @@ namespace MatterHackers.MatterControl.Tests.Automation private EventHandler unregisterEvents; [Test, Apartment(ApartmentState.STA)] - public async Task TuningAdjustmentsResetToOne() + public async Task TuningAdjustmentsDefaultToOneAndPersist() { + double targetExtrusionRate = 1.5; + double targetFeedRate = 2; + AutomationTest testToRun = (testRunner) => { SystemWindow systemWindow; @@ -124,8 +127,6 @@ namespace MatterHackers.MatterControl.Tests.Automation using (var emulatorDisposable = testRunner.LaunchAndConnectToPrinterEmulator()) { - SolidSlider slider; - Assert.IsTrue(ProfileManager.Instance.ActiveProfile != null); testRunner.SwitchToSettingsAndControls(); @@ -140,9 +141,6 @@ namespace MatterHackers.MatterControl.Tests.Automation var scrollable = container.Parents().First().Parents().First(); var width = scrollable.Width; - double targetExtrusionRate = 1.5; - double targetFeedRate = 2; - // Workaround needed to scroll to the bottom of the Controls panel //scrollable.ScrollPosition = new Vector2(); scrollable.ScrollPosition = new Vector2(0, 30); @@ -151,71 +149,76 @@ namespace MatterHackers.MatterControl.Tests.Automation scrollable.Width = width - 1; scrollable.Width = width; - // Workaround for MatterHackers/MCCentral#1157 - wait for slicing to complete before setting tuning values - testRunner.Delay(5); + // Tuning values should default to 1 when missing + ConfirmExpectedSpeeds(testRunner, 1, 1); + testRunner.Delay(); testRunner.ClickByName("Extrusion Multiplier NumberEdit"); - testRunner.Delay(.2); testRunner.Type(targetExtrusionRate.ToString()); - testRunner.Delay(.2); testRunner.ClickByName("Feed Rate NumberEdit"); - testRunner.Delay(.2); testRunner.Type(targetFeedRate.ToString()); - testRunner.Delay(.2); - // Force focus away from the feed rate field + // Force focus away from the feed rate field, causing an persisted update testRunner.ClickByName("Controls Tab", 1); + testRunner.Delay(); - testRunner.Delay(.2); + ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate); - // Assert the changes took effect on the UI - slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out systemWindow, 5) as SolidSlider; - Assert.AreEqual(targetExtrusionRate, slider.Value); + // Wait for slicing to complete before setting target values + testRunner.Delay(() => PrinterConnectionAndCommunication.Instance.PrintingState == PrinterConnectionAndCommunication.DetailedPrintingState.Printing, 8); + testRunner.Delay(); - slider = testRunner.GetWidgetByName("Feed Rate Slider", out systemWindow, 5) as SolidSlider; - Assert.AreEqual(targetFeedRate, slider.Value); - - testRunner.Delay(.2); - - // Assert the changes took effect on the model - Assert.AreEqual(targetExtrusionRate, PrinterConnectionAndCommunication.Instance.ExtrusionRatio); - Assert.AreEqual(targetFeedRate, PrinterConnectionAndCommunication.Instance.FeedRateRatio); + ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate); + // Wait for printing to complete var resetEvent = new AutoResetEvent(false); - - // Release reset event on PrintFinished PrinterConnectionAndCommunication.Instance.PrintFinished.RegisterEvent((s, e) => resetEvent.Set(), ref unregisterEvents); - resetEvent.WaitOne(); - // Finish the print testRunner.WaitForName("Done Button", 30); testRunner.WaitForName("Print Again Button", 1); + // Values should match entered values + ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate); + // Restart the print testRunner.ClickByName("Print Again Button", 1); - testRunner.Delay(2); + // Values should match entered values + ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate); + testRunner.CancelPrint(); + testRunner.Delay(1); - // Assert we've reset to 1 - Assert.AreEqual(1, PrinterConnectionAndCommunication.Instance.FeedRateRatio); - Assert.AreEqual(1, PrinterConnectionAndCommunication.Instance.ExtrusionRatio); - - // Assert the changes took effect on the UI - slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out systemWindow, 5) as SolidSlider; - Assert.AreEqual(1, slider.Value); - - slider = testRunner.GetWidgetByName("Feed Rate Slider", out systemWindow, 5) as SolidSlider; - Assert.AreEqual(1, slider.Value); + // Values should match entered values + ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate); } return Task.FromResult(0); }; - await MatterControlUtilities.RunTest(testToRun, overrideHeight:900, maxTimeToRun: 90); + await MatterControlUtilities.RunTest(testToRun, overrideHeight:900, maxTimeToRun: 990); + } + + private static void ConfirmExpectedSpeeds(AutomationRunner testRunner, double targetExtrusionRate, double targetFeedRate) + { + SystemWindow systemWindow; + SolidSlider slider; + + // Assert the UI has the expected values + slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out systemWindow, 5) as SolidSlider; + Assert.AreEqual(targetExtrusionRate, slider.Value); + + slider = testRunner.GetWidgetByName("Feed Rate Slider", out systemWindow, 5) as SolidSlider; + Assert.AreEqual(targetFeedRate, slider.Value); + + testRunner.Delay(.2); + + // Assert the changes took effect on the model + Assert.AreEqual(targetExtrusionRate, ActiveSliceSettings.Instance.GetValue(SettingsKey.extrusion_ratio)); + Assert.AreEqual(targetFeedRate, ActiveSliceSettings.Instance.GetValue(SettingsKey.feedrate_ratio)); } } }