Multiplier streams must acquire and track dependant settings
- Correct whitespace
This commit is contained in:
parent
fd38803330
commit
b665091e18
4 changed files with 145 additions and 73 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2015, Lars Brubaker
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -27,56 +27,77 @@ 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.UI;
|
||||
using MatterHackers.GCodeVisualizer;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
||||
{
|
||||
public class ExtrusionMultiplyerStream : GCodeStreamProxy
|
||||
{
|
||||
private double currentActualExtrusionPosition = 0;
|
||||
private double previousGcodeRequestedExtrusionPosition = 0;
|
||||
public class ExtrusionMultiplyerStream : GCodeStreamProxy
|
||||
{
|
||||
private double currentActualExtrusionPosition = 0;
|
||||
private double previousGcodeRequestedExtrusionPosition = 0;
|
||||
|
||||
public ExtrusionMultiplyerStream(GCodeStream internalStream)
|
||||
: base(internalStream)
|
||||
{
|
||||
}
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public double ExtrusionRatio { get; set; } = 1;
|
||||
public ExtrusionMultiplyerStream(GCodeStream internalStream)
|
||||
: base(internalStream)
|
||||
{
|
||||
this.ExtrusionRatio = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.extrusion_ratio);
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
return ApplyExtrusionMultiplier(internalStream.ReadLine());
|
||||
}
|
||||
ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
var eventArgs = e as StringEventArgs;
|
||||
if (eventArgs?.Data == SettingsKey.extrusion_ratio)
|
||||
{
|
||||
this.ExtrusionRatio = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.extrusion_ratio);
|
||||
}
|
||||
}, ref unregisterEvents);
|
||||
}
|
||||
|
||||
private string ApplyExtrusionMultiplier(string lineBeingSent)
|
||||
{
|
||||
if (lineBeingSent != null)
|
||||
{
|
||||
if (LineIsMovement(lineBeingSent))
|
||||
{
|
||||
double gcodeRequestedExtrusionPosition = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition))
|
||||
{
|
||||
double delta = gcodeRequestedExtrusionPosition - previousGcodeRequestedExtrusionPosition;
|
||||
double newActualExtruderPosition = currentActualExtrusionPosition + delta * ExtrusionRatio;
|
||||
lineBeingSent = GCodeFile.ReplaceNumberAfter('E', lineBeingSent, newActualExtruderPosition);
|
||||
previousGcodeRequestedExtrusionPosition = gcodeRequestedExtrusionPosition;
|
||||
currentActualExtrusionPosition = newActualExtruderPosition;
|
||||
}
|
||||
}
|
||||
else if (lineBeingSent.StartsWith("G92"))
|
||||
{
|
||||
double gcodeRequestedExtrusionPosition = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition))
|
||||
{
|
||||
previousGcodeRequestedExtrusionPosition = gcodeRequestedExtrusionPosition;
|
||||
currentActualExtrusionPosition = gcodeRequestedExtrusionPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
public double ExtrusionRatio { get; set; }
|
||||
|
||||
return lineBeingSent;
|
||||
}
|
||||
}
|
||||
public override string ReadLine()
|
||||
{
|
||||
return ApplyExtrusionMultiplier(internalStream.ReadLine());
|
||||
}
|
||||
|
||||
private string ApplyExtrusionMultiplier(string lineBeingSent)
|
||||
{
|
||||
if (lineBeingSent != null)
|
||||
{
|
||||
if (LineIsMovement(lineBeingSent))
|
||||
{
|
||||
double gcodeRequestedExtrusionPosition = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition))
|
||||
{
|
||||
double delta = gcodeRequestedExtrusionPosition - previousGcodeRequestedExtrusionPosition;
|
||||
double newActualExtruderPosition = currentActualExtrusionPosition + delta * ExtrusionRatio;
|
||||
lineBeingSent = GCodeFile.ReplaceNumberAfter('E', lineBeingSent, newActualExtruderPosition);
|
||||
previousGcodeRequestedExtrusionPosition = gcodeRequestedExtrusionPosition;
|
||||
currentActualExtrusionPosition = newActualExtruderPosition;
|
||||
}
|
||||
}
|
||||
else if (lineBeingSent.StartsWith("G92"))
|
||||
{
|
||||
double gcodeRequestedExtrusionPosition = 0;
|
||||
if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition))
|
||||
{
|
||||
previousGcodeRequestedExtrusionPosition = gcodeRequestedExtrusionPosition;
|
||||
currentActualExtrusionPosition = gcodeRequestedExtrusionPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lineBeingSent;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
unregisterEvents?.Invoke(null, null);
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2015, Lars Brubaker
|
||||
Copyright (c) 2017, Lars Brubaker, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -27,8 +27,9 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using MatterHackers.GCodeVisualizer;
|
||||
using MatterHackers.VectorMath;
|
||||
using System;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
||||
{
|
||||
|
|
@ -37,12 +38,24 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
protected PrinterMove lastDestination = new PrinterMove();
|
||||
public PrinterMove LastDestination { get { return lastDestination; } }
|
||||
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public FeedRateMultiplyerStream(GCodeStream internalStream)
|
||||
: base(internalStream)
|
||||
{
|
||||
this.FeedRateRatio = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.feedrate_ratio);
|
||||
|
||||
ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
var eventArgs = e as StringEventArgs;
|
||||
if (eventArgs?.Data == SettingsKey.feedrate_ratio)
|
||||
{
|
||||
this.FeedRateRatio = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.feedrate_ratio);
|
||||
}
|
||||
}, ref unregisterEvents);
|
||||
}
|
||||
|
||||
public double FeedRateRatio { get; set; } = 1;
|
||||
public double FeedRateRatio { get; set; }
|
||||
|
||||
public override void SetPrinterPosition(PrinterMove position)
|
||||
{
|
||||
|
|
@ -69,5 +82,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
|||
|
||||
return lineToSend;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
unregisterEvents?.Invoke(null, null);
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,40 +27,41 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.GCodeVisualizer;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
||||
{
|
||||
public class GCodeFileStream : GCodeStream
|
||||
{
|
||||
public GCodeFile FileStreaming { get; private set; }
|
||||
private int printerCommandQueueLineIndex = -1;
|
||||
public class GCodeFileStream : GCodeStream
|
||||
{
|
||||
public GCodeFile FileStreaming { get; private set; }
|
||||
private int printerCommandQueueLineIndex = -1;
|
||||
|
||||
public GCodeFileStream(GCodeFile fileStreaming, int startLine = 0)
|
||||
{
|
||||
this.FileStreaming = fileStreaming;
|
||||
printerCommandQueueLineIndex = startLine;
|
||||
}
|
||||
public GCodeFileStream(GCodeFile fileStreaming, int startLine = 0)
|
||||
{
|
||||
this.FileStreaming = fileStreaming;
|
||||
printerCommandQueueLineIndex = startLine;
|
||||
}
|
||||
|
||||
public int LineIndex { get { return printerCommandQueueLineIndex; } }
|
||||
public int LineIndex { get { return printerCommandQueueLineIndex; } }
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
if (printerCommandQueueLineIndex < FileStreaming.LineCount)
|
||||
{
|
||||
return FileStreaming.Instruction(printerCommandQueueLineIndex++).Line;
|
||||
}
|
||||
public override string ReadLine()
|
||||
{
|
||||
if (printerCommandQueueLineIndex < FileStreaming.LineCount)
|
||||
{
|
||||
return FileStreaming.Instruction(printerCommandQueueLineIndex++).Line;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void SetPrinterPosition(PrinterMove position)
|
||||
{
|
||||
}
|
||||
}
|
||||
public override void SetPrinterPosition(PrinterMove position)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using MatterHackers.GCodeVisualizer;
|
||||
using MatterHackers.MatterControl.PrinterCommunication.Io;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.MatterControl.Tests.Automation;
|
||||
|
|
@ -40,7 +41,7 @@ using NUnit.Framework;
|
|||
namespace MatterControl.Tests.MatterControl
|
||||
{
|
||||
[TestFixture]
|
||||
public class GCodeMaxLengthStreamTests
|
||||
public class GCodeStreamTests
|
||||
{
|
||||
[Test, Category("GCodeStream")]
|
||||
public void MaxLengthStreamTests()
|
||||
|
|
@ -417,6 +418,36 @@ namespace MatterControl.Tests.MatterControl
|
|||
Assert.AreEqual(expectedLine, actualLine, "Unexpected response from PauseHandlingStream");
|
||||
}
|
||||
}
|
||||
|
||||
[Test, Category("GCodeStream")]
|
||||
public void FeedRateStreamTracksSettings()
|
||||
{
|
||||
StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
|
||||
|
||||
var gcodeStream = new FeedRateMultiplyerStream(new TestGCodeStream(new string[0]));
|
||||
|
||||
Assert.AreEqual(1, gcodeStream.FeedRateRatio, "FeedRateRatio should default to 1");
|
||||
|
||||
ActiveSliceSettings.Instance.SetValue(SettingsKey.feedrate_ratio, "0.3");
|
||||
|
||||
Assert.AreEqual(0.3, gcodeStream.FeedRateRatio, "FeedRateRatio should remain synced with PrinterSettings");
|
||||
}
|
||||
|
||||
[Test, Category("GCodeStream")]
|
||||
public void ExtrusionRateStreamTracksSettings()
|
||||
{
|
||||
StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
|
||||
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
|
||||
|
||||
var gcodeStream = new ExtrusionMultiplyerStream(new TestGCodeStream(new string[0]));
|
||||
|
||||
Assert.AreEqual(1, gcodeStream.ExtrusionRatio, "ExtrusionRatio should default to 1");
|
||||
|
||||
ActiveSliceSettings.Instance.SetValue(SettingsKey.extrusion_ratio, "0.3");
|
||||
|
||||
Assert.AreEqual(0.3, gcodeStream.ExtrusionRatio, "ExtrusionRatio should remain synced with PrinterSettings");
|
||||
}
|
||||
}
|
||||
|
||||
public class TestGCodeStream : GCodeStream
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue