Making feedrate and multiplier apply to current printer

issue: https://github.com/matterhackers/mattercontrol/issues/4793
This commit is contained in:
LarsBrubaker 2020-07-01 21:59:06 -07:00
parent 6017e7b30d
commit 6ef6503b94
6 changed files with 44 additions and 48 deletions

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterControl.Printing;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
@ -39,9 +40,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public ExtrusionMultiplierStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
ExtrusionRatio = printer.Settings.GetValue<double>(SettingsKey.extrusion_ratio);
}
public double ExtrusionRatio { get; set; } = 1;
public double ExtrusionRatio { get; set; }
public override string DebugInfo
{

View file

@ -40,9 +40,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public FeedRateMultiplierStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
{
FeedRateRatio = printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio);
}
public static double FeedRateRatio { get; set; } = 1;
public double FeedRateRatio { get; set; }
public override string DebugInfo => $"Last Destination = {lastDestination}";

View file

@ -2395,8 +2395,8 @@ Make sure that your printer is turned on. Some printers will appear to be connec
}
accumulatedStream = waitForTempStream = new WaitForTempStream(Printer, accumulatedStream);
accumulatedStream = new ExtrusionMultiplierStream(Printer, accumulatedStream);
accumulatedStream = new FeedRateMultiplierStream(Printer, accumulatedStream);
accumulatedStream = ExtrusionMultiplierStream = new ExtrusionMultiplierStream(Printer, accumulatedStream);
accumulatedStream = FeedRateMultiplierStream = new FeedRateMultiplierStream(Printer, accumulatedStream);
accumulatedStream = new RequestTemperaturesStream(Printer, accumulatedStream);
if (Printer.Settings.GetValue<bool>(SettingsKey.emulate_endstops))
@ -2772,6 +2772,9 @@ Make sure that your printer is turned on. Some printers will appear to be connec
public PrintTask ActivePrintTask { get; set; }
public ExtrusionMultiplierStream ExtrusionMultiplierStream { get; private set; }
public FeedRateMultiplierStream FeedRateMultiplierStream { get; private set; }
public void TurnOffPartCoolingFan()
{
// turn off all the part cooling fans

View file

@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
Name = "Feed Rate Slider",
Margin = new BorderDouble(5, 0),
Value = FeedRateMultiplierStream.FeedRateRatio,
Value = printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio),
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Center,
TotalWidthInPixels = sliderWidth,
@ -90,16 +90,16 @@ namespace MatterHackers.MatterControl.PrinterControls
feedRateRatioSlider.SliderReleased += (s, e) =>
{
// Update state for runtime use
FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
printer.Connection.FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
// Persist data for future use
printer.Settings.SetValue(
SettingsKey.feedrate_ratio,
FeedRateMultiplierStream.FeedRateRatio.ToString());
printer.Connection.FeedRateMultiplierStream.FeedRateRatio.ToString());
};
settingsRow.AddChild(feedRateRatioSlider);
feedRateValue = new MHNumberEdit(Math.Round(FeedRateMultiplierStream.FeedRateRatio, 2), theme, allowDecimals: true, minValue: minFeedRateRatio, maxValue: maxFeedRateRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
feedRateValue = new MHNumberEdit(Math.Round(printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio), 2), theme, allowDecimals: true, minValue: minFeedRateRatio, maxValue: maxFeedRateRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
{
Name = "Feed Rate NumberEdit",
SelectAllOnFocus = true,
@ -111,12 +111,12 @@ namespace MatterHackers.MatterControl.PrinterControls
feedRateRatioSlider.Value = feedRateValue.ActuallNumberEdit.Value;
// Update state for runtime use
FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
printer.Connection.FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
// Persist data for future use
printer.Settings.SetValue(
SettingsKey.feedrate_ratio,
FeedRateMultiplierStream.FeedRateRatio.ToString());
printer.Connection.FeedRateMultiplierStream.FeedRateRatio.ToString());
};
settingsRow.AddChild(feedRateValue);
}
@ -137,7 +137,7 @@ namespace MatterHackers.MatterControl.PrinterControls
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Center,
Margin = new BorderDouble(5, 0),
Value = ExtrusionMultiplierStream.ExtrusionRatio
Value = printer.Settings.GetValue<double>(SettingsKey.extrusion_ratio)
};
theme.ApplySliderStyle(extrusionRatioSlider);
extrusionRatioSlider.ValueChanged += (sender, e) =>
@ -147,16 +147,16 @@ namespace MatterHackers.MatterControl.PrinterControls
extrusionRatioSlider.SliderReleased += (s, e) =>
{
// Update state for runtime use
ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
// Persist data for future use
printer.Settings.SetValue(
SettingsKey.extrusion_ratio,
ExtrusionMultiplierStream.ExtrusionRatio.ToString());
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio.ToString());
};
settingsRow.AddChild(extrusionRatioSlider);
extrusionValue = new MHNumberEdit(Math.Round(ExtrusionMultiplierStream.ExtrusionRatio, 2), theme, allowDecimals: true, minValue: minExtrutionRatio, maxValue: maxExtrusionRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
extrusionValue = new MHNumberEdit(Math.Round(printer.Settings.GetValue<double>(SettingsKey.extrusion_ratio), 2), theme, allowDecimals: true, minValue: minExtrutionRatio, maxValue: maxExtrusionRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
{
Name = "Extrusion Multiplier NumberEdit",
SelectAllOnFocus = true,
@ -168,12 +168,12 @@ namespace MatterHackers.MatterControl.PrinterControls
extrusionRatioSlider.Value = extrusionValue.ActuallNumberEdit.Value;
// Update state for runtime use
ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
// Persist data for future use
printer.Settings.SetValue(
SettingsKey.extrusion_ratio,
ExtrusionMultiplierStream.ExtrusionRatio.ToString());
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio.ToString());
};
settingsRow.AddChild(extrusionValue);
}

View file

@ -418,19 +418,8 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.StartPrint();
var container = testRunner.GetWidgetByName("ManualPrinterControls.ControlsContainer", out _, 5);
// Scroll the widget into view
var scrollable = container.Parents<ManualPrinterControls>().First() as ScrollableWidget;
var width = scrollable.Width;
// Workaround needed to scroll to the bottom of the Controls panel
// scrollable.ScrollPosition = new Vector2();
scrollable.ScrollPosition = new Vector2(0, 30);
// Workaround to force layout to fix problems with size of Tuning Widgets after setting ScrollPosition manually
scrollable.Width = width - 1;
scrollable.Width = width;
testRunner.ScrollIntoView("Extrusion Multiplier NumberEdit");
testRunner.ScrollIntoView("Feed Rate NumberEdit");
// Tuning values should default to 1 when missing
ConfirmExpectedSpeeds(testRunner, 1, 1, "Initial case");
@ -463,7 +452,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
// Restart the print
testRunner.StartPrint();
testRunner.Delay(2);
testRunner.Delay(1);
// Values should match entered values
ConfirmExpectedSpeeds(testRunner, targetExtrusionRate, targetFeedRate, "After print restarted");
@ -492,10 +481,6 @@ namespace MatterHackers.MatterControl.Tests.Automation
{
testRunner.WaitForName("Cancel Wizard Button");
// Set custom adjustment values
FeedRateMultiplierStream.FeedRateRatio = initialFeedRate;
ExtrusionMultiplierStream.ExtrusionRatio = initialExtrusionRate;
// Then validate that they are picked up
using (var emulator = testRunner.LaunchAndConnectToPrinterEmulator())
{
@ -507,6 +492,10 @@ namespace MatterHackers.MatterControl.Tests.Automation
var printer = testRunner.FirstPrinter();
// Set custom adjustment values
printer.Connection.FeedRateMultiplierStream.FeedRateRatio = initialFeedRate;
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio = initialExtrusionRate;
var printFinishedResetEvent = new AutoResetEvent(false);
printer.Connection.PrintFinished += (s, e) => printFinishedResetEvent.Set();
@ -681,25 +670,26 @@ namespace MatterHackers.MatterControl.Tests.Automation
private static void ConfirmExpectedSpeeds(AutomationRunner testRunner, double targetExtrusionRate, double targetFeedRate, string scope)
{
SystemWindow systemWindow;
SolidSlider slider;
// Assert the UI has the expected values
slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out systemWindow, 5) as SolidSlider;
slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out _) as SolidSlider;
testRunner.WaitFor(() => targetExtrusionRate == slider.Value);
Assert.AreEqual(targetExtrusionRate, slider.Value, $"Unexpected Extrusion Rate Slider Value - {scope}");
slider = testRunner.GetWidgetByName("Feed Rate Slider", out systemWindow, 5) as SolidSlider;
slider = testRunner.GetWidgetByName("Feed Rate Slider", out _) as SolidSlider;
testRunner.WaitFor(() => targetFeedRate == slider.Value);
Assert.AreEqual(targetFeedRate, slider.Value, $"Unexpected Feed Rate Slider Value - {scope}");
// Assert the changes took effect on the model
testRunner.WaitFor(() => targetExtrusionRate == ExtrusionMultiplierStream.ExtrusionRatio);
Assert.AreEqual(targetExtrusionRate, ExtrusionMultiplierStream.ExtrusionRatio, $"Unexpected Extrusion Rate - {scope}");
var printer = testRunner.FirstPrinter();
testRunner.WaitFor(() => targetFeedRate == FeedRateMultiplierStream.FeedRateRatio);
Assert.AreEqual(targetFeedRate, FeedRateMultiplierStream.FeedRateRatio, $"Unexpected Feed Rate - {scope}");
// Assert the changes took effect on the model
testRunner.WaitFor(() => targetExtrusionRate == printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio);
Assert.AreEqual(targetExtrusionRate, printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio, $"Unexpected Extrusion Rate - {scope}");
testRunner.WaitFor(() => targetFeedRate == printer.Connection.FeedRateMultiplierStream.FeedRateRatio);
Assert.AreEqual(targetFeedRate, printer.Connection.FeedRateMultiplierStream.FeedRateRatio, $"Unexpected Feed Rate - {scope}");
}
}
}

View file

@ -689,16 +689,16 @@ namespace MatterControl.Tests.MatterControl
{
string line;
Assert.AreEqual(1, (int)FeedRateMultiplierStream.FeedRateRatio, "FeedRateRatio should default to 1");
PrinterConfig printer = null;
var gcodeStream = new FeedRateMultiplierStream(printer, new TestGCodeStream(printer, new string[] { "G1 X10 F1000", "G1 Y5 F1000" }));
Assert.AreEqual(1, (int)gcodeStream.FeedRateRatio, "FeedRateRatio should default to 1");
line = gcodeStream.ReadLine();
Assert.AreEqual("G1 X10 F1000", line, "FeedRate should remain unchanged when FeedRateRatio is 1.0");
FeedRateMultiplierStream.FeedRateRatio = 2;
gcodeStream.FeedRateRatio = 2;
line = gcodeStream.ReadLine();
Assert.AreEqual("G1 Y5 F2000", line, "FeedRate should scale from F1000 to F2000 when FeedRateRatio is 2x");
@ -709,18 +709,18 @@ namespace MatterControl.Tests.MatterControl
{
string line;
Assert.AreEqual(1, (int)ExtrusionMultiplierStream.ExtrusionRatio, "ExtrusionRatio should default to 1");
PrinterConfig printer = null;
var gcodeStream = new ExtrusionMultiplierStream(printer, new TestGCodeStream(printer, new string[] { "G1 E10", "G1 E0 ; Move back to 0", "G1 E12" }));
Assert.AreEqual(1, (int)gcodeStream.ExtrusionRatio, "ExtrusionRatio should default to 1");
line = gcodeStream.ReadLine();
// Move back to E0
gcodeStream.ReadLine();
Assert.AreEqual("G1 E10", line, "ExtrusionMultiplier should remain unchanged when FeedRateRatio is 1.0");
ExtrusionMultiplierStream.ExtrusionRatio = 2;
gcodeStream.ExtrusionRatio = 2;
line = gcodeStream.ReadLine();