2018-01-05 12:44:57 -08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-03 11:48:08 -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;
|
2015-07-29 13:23:38 -07:00
|
|
|
|
GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref extruderDelta);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
double feedRate = 0;
|
2015-07-29 13:23:38 -07:00
|
|
|
|
GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
string newLine = "G1 ";
|
|
|
|
|
|
|
2015-08-01 15:50:39 -07:00
|
|
|
|
if (lineBeingSent.Contains("X") || lineBeingSent.Contains("Y") || lineBeingSent.Contains("Z"))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
Vector3 outPosition = PrintLevelingPlane.Instance.ApplyLeveling(currentDestination);
|
|
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|