mattercontrol/original/MatterControlLib/PrinterControls/PrintLevelingPlane.cs

76 lines
1.8 KiB
C#
Raw Normal View History

using System;
using MatterControl.Printing;
2015-04-08 15:20:10 -07:00
using MatterHackers.VectorMath;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
public class PrintLevelingPlane
{
private Matrix4X4 bedLevelMatrix = Matrix4X4.Identity;
// private constructor
private PrintLevelingPlane()
{
}
static private PrintLevelingPlane instance;
static public PrintLevelingPlane Instance
{
get
{
if (instance == null)
{
instance = new PrintLevelingPlane();
}
return instance;
}
}
public Vector3 ApplyLeveling(Vector3 inPosition)
{
2019-01-11 16:49:34 -08:00
return Vector3Ex.TransformPosition(inPosition, bedLevelMatrix);
2015-04-08 15:20:10 -07:00
}
public Vector3 ApplyLevelingRotation(Vector3 inPosition)
{
2019-01-11 16:49:34 -08:00
return Vector3Ex.TransformVector(inPosition, bedLevelMatrix);
2015-04-08 15:20:10 -07:00
}
public string ApplyLeveling(Vector3 currentDestination, string lineBeingSent)
2015-04-08 15:20:10 -07:00
{
if ((lineBeingSent.StartsWith("G0") || lineBeingSent.StartsWith("G1"))
&& lineBeingSent.Length > 2
&& lineBeingSent[2] == ' ')
{
double extruderDelta = 0;
GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref extruderDelta);
2015-04-08 15:20:10 -07:00
double feedRate = 0;
GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate);
2015-04-08 15:20:10 -07:00
string newLine = "G1 ";
if (lineBeingSent.Contains("X") || lineBeingSent.Contains("Y") || lineBeingSent.Contains("Z"))
2015-04-08 15:20:10 -07:00
{
Vector3 outPosition = PrintLevelingPlane.Instance.ApplyLeveling(currentDestination);
newLine = newLine + String.Format("X{0:0.##} Y{1:0.##} Z{2:0.###}", outPosition.X, outPosition.Y, outPosition.Z);
2015-04-08 15:20:10 -07:00
}
if (extruderDelta != 0)
{
newLine = newLine + String.Format(" E{0:0.###}", extruderDelta);
}
if (feedRate != 0)
{
newLine = newLine + String.Format(" F{0:0.##}", feedRate);
}
lineBeingSent = newLine;
}
return lineBeingSent;
}
}
}