2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
2015-08-03 15:48:36 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2014-06-06 16:05:18 -07:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Newtonsoft.Json.Converters;
|
2015-08-01 14:44:53 -07:00
|
|
|
|
using System.Collections.Generic;
|
2016-02-22 10:14:07 -08:00
|
|
|
|
using System;
|
2016-10-19 13:48:51 -07:00
|
|
|
|
using System.Linq;
|
2014-06-06 16:05:18 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class PrintLevelingData
|
|
|
|
|
|
{
|
2016-07-19 13:28:10 -07:00
|
|
|
|
private PrinterSettings printerProfile;
|
2016-04-27 19:12:15 -07:00
|
|
|
|
|
2016-10-11 14:56:36 -07:00
|
|
|
|
public List<Vector3> SampledPositions = new List<Vector3>()
|
|
|
|
|
|
{
|
|
|
|
|
|
new Vector3(),new Vector3(),new Vector3()
|
|
|
|
|
|
};
|
2015-08-01 14:44:53 -07:00
|
|
|
|
|
|
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2017-05-19 14:39:57 -07:00
|
|
|
|
public enum LevelingSystem { Probe3Points, Probe7PointRadial, Probe13PointRadial, Probe3x3Mesh }
|
2015-08-01 14:44:53 -07:00
|
|
|
|
|
2016-07-19 13:28:10 -07:00
|
|
|
|
public PrintLevelingData(PrinterSettings printerProfile)
|
2016-04-27 19:12:15 -07:00
|
|
|
|
{
|
2016-07-19 13:28:10 -07:00
|
|
|
|
this.printerProfile = printerProfile;
|
2016-04-27 19:12:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
public LevelingSystem CurrentPrinterLevelingSystem
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-12-23 13:15:51 -08:00
|
|
|
|
get
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-07-19 13:28:10 -07:00
|
|
|
|
switch (printerProfile.GetValue("print_leveling_solution"))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-03 15:48:36 -07:00
|
|
|
|
case "7 Point Disk":
|
|
|
|
|
|
return LevelingSystem.Probe7PointRadial;
|
|
|
|
|
|
|
2015-08-05 11:12:01 -07:00
|
|
|
|
case "13 Point Disk":
|
|
|
|
|
|
return LevelingSystem.Probe13PointRadial;
|
|
|
|
|
|
|
2017-05-19 14:39:57 -07:00
|
|
|
|
case "3x3 Mesh":
|
|
|
|
|
|
return LevelingSystem.Probe3x3Mesh;
|
|
|
|
|
|
|
2015-08-03 15:48:36 -07:00
|
|
|
|
case "3 Point Plane":
|
|
|
|
|
|
default:
|
|
|
|
|
|
return LevelingSystem.Probe3Points;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-16 10:42:25 -08:00
|
|
|
|
internal static PrintLevelingData Create(PrinterSettings printerProfile, string jsonData, string depricatedPositionsCsv3ByXYZ = "")
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(jsonData))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-27 19:12:15 -07:00
|
|
|
|
var deserialized = JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
|
2016-07-19 13:28:10 -07:00
|
|
|
|
deserialized.printerProfile = printerProfile;
|
2016-04-27 19:12:15 -07:00
|
|
|
|
|
|
|
|
|
|
return deserialized;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2016-04-18 11:31:31 -07:00
|
|
|
|
else if (!string.IsNullOrEmpty(depricatedPositionsCsv3ByXYZ))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-27 19:12:15 -07:00
|
|
|
|
var item = new PrintLevelingData(ActiveSliceSettings.Instance);
|
2016-07-19 13:28:10 -07:00
|
|
|
|
item.printerProfile = printerProfile;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
item.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);
|
2016-04-27 19:12:15 -07:00
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
return item;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-27 19:12:15 -07:00
|
|
|
|
return new PrintLevelingData(ActiveSliceSettings.Instance)
|
|
|
|
|
|
{
|
2016-07-19 13:28:10 -07:00
|
|
|
|
printerProfile = printerProfile
|
2016-04-27 19:12:15 -07:00
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the 9 {3 * (x, y, z)} positions that were probed during the print leveling setup.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private void ParseDepricatedPrintLevelingMeasuredPositions(string depricatedPositionsCsv3ByXYZ)
|
|
|
|
|
|
{
|
2016-10-11 14:56:36 -07:00
|
|
|
|
SampledPositions = new List<Vector3>(3);
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
if (depricatedPositionsCsv3ByXYZ != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] lines = depricatedPositionsCsv3ByXYZ.Split(',');
|
|
|
|
|
|
if (lines.Length == 9)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
|
{
|
2016-10-11 14:56:36 -07:00
|
|
|
|
Vector3 position = new Vector3();
|
|
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
position.X = double.Parse(lines[0 * 3 + i]);
|
|
|
|
|
|
position.Y = double.Parse(lines[1 * 3 + i]);
|
|
|
|
|
|
position.Z = double.Parse(lines[2 * 3 + i]);
|
2016-10-11 14:56:36 -07:00
|
|
|
|
|
|
|
|
|
|
SampledPositions.Add(position);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-02-22 10:14:07 -08:00
|
|
|
|
|
2016-09-27 12:47:15 -07:00
|
|
|
|
public bool HasBeenRunAndEnabled()
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
2016-09-27 12:47:15 -07:00
|
|
|
|
if(!ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-19 13:48:51 -07:00
|
|
|
|
var positionCounts = from x in SampledPositions
|
|
|
|
|
|
group x by x into g
|
|
|
|
|
|
let count = g.Count()
|
|
|
|
|
|
orderby count descending
|
|
|
|
|
|
select new { Value = g.Key, Count = count };
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var x in positionCounts)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(x.Count > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-22 10:14:07 -08:00
|
|
|
|
switch (CurrentPrinterLevelingSystem)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PrintLevelingData.LevelingSystem.Probe3Points:
|
2016-10-11 14:56:36 -07:00
|
|
|
|
if (SampledPositions.Count != 3) // different criteria for what is not initialized
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PrintLevelingData.LevelingSystem.Probe7PointRadial:
|
|
|
|
|
|
if (SampledPositions.Count != 7) // different criteria for what is not initialized
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PrintLevelingData.LevelingSystem.Probe13PointRadial:
|
|
|
|
|
|
if (SampledPositions.Count != 13) // different criteria for what is not initialized
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2017-05-19 14:39:57 -07:00
|
|
|
|
case LevelingSystem.Probe3x3Mesh:
|
|
|
|
|
|
if (SampledPositions.Count != 9) // different criteria for what is not initialized
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2016-02-22 10:14:07 -08:00
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2017-06-07 15:56:02 -07:00
|
|
|
|
|
|
|
|
|
|
public bool SamplesAreSame(List<Vector3> sampledPositions)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sampledPositions.Count == SampledPositions.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < sampledPositions.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sampledPositions[i] != SampledPositions[i])
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|