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
|
|
|
|
|
|
{
|
2018-04-04 13:45:10 -07:00
|
|
|
|
#region JSON data
|
2018-04-02 18:20:39 -07:00
|
|
|
|
public List<Vector3> SampledPositions = new List<Vector3>();
|
2018-03-30 14:48:55 -07:00
|
|
|
|
public LevelingSystem LevelingSystem;
|
2018-05-02 10:59:08 -07:00
|
|
|
|
public DateTime CreationDate;
|
2018-04-04 13:45:10 -07:00
|
|
|
|
public double BedTemperature;
|
2018-10-19 15:46:36 -07:00
|
|
|
|
public bool IssuedLevelingTempWarning;
|
2018-04-04 13:45:10 -07:00
|
|
|
|
#endregion
|
2015-08-01 14:44:53 -07:00
|
|
|
|
|
2018-03-30 14:48:55 -07:00
|
|
|
|
public PrintLevelingData()
|
2016-04-27 19:12:15 -07:00
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2016-02-22 10:14:07 -08:00
|
|
|
|
|
2018-04-05 13:55:23 -07:00
|
|
|
|
public static bool NeedsToBeRun(PrinterConfig printer)
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
|
|
|
|
|
|
|
|
|
|
|
|
var required = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print);
|
|
|
|
|
|
if (required && levelingData == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// need but don't have data
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-05 09:24:57 -07:00
|
|
|
|
var enabled = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled);
|
|
|
|
|
|
|
2018-04-04 13:45:10 -07:00
|
|
|
|
// check if leveling is turned on
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if (required && !enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
// need but not turned on
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!required && !enabled)
|
2016-09-27 12:47:15 -07:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-04 13:45:10 -07:00
|
|
|
|
// check that there are no duplicate points
|
2018-04-05 13:55:23 -07:00
|
|
|
|
var positionCounts = from x in levelingData.SampledPositions
|
2016-10-19 13:48:51 -07:00
|
|
|
|
group x by x into g
|
|
|
|
|
|
let count = g.Count()
|
|
|
|
|
|
orderby count descending
|
|
|
|
|
|
select new { Value = g.Key, Count = count };
|
2018-05-24 09:11:45 -07:00
|
|
|
|
|
2016-10-19 13:48:51 -07:00
|
|
|
|
foreach (var x in positionCounts)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(x.Count > 1)
|
|
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2016-10-19 13:48:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-04 13:45:10 -07:00
|
|
|
|
// check that the solution last measured is the currently selected solution
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if(printer.Settings.GetValue<LevelingSystem>(SettingsKey.print_leveling_solution) != levelingData.LevelingSystem)
|
2018-04-03 18:17:27 -07:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2018-04-03 18:17:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-04 13:45:10 -07:00
|
|
|
|
// check that the bed temperature at probe time was close enough to the current print bed temp
|
2018-05-24 22:46:34 -07:00
|
|
|
|
double requiredLevelingTemp = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed) ?
|
2018-04-04 13:45:10 -07:00
|
|
|
|
printer.Settings.GetValue<double>(SettingsKey.bed_temperature)
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
|
2018-05-24 09:11:45 -07:00
|
|
|
|
// check that the number of points sampled is correct for the solution
|
2018-04-05 13:55:23 -07:00
|
|
|
|
switch (levelingData.LevelingSystem)
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
2018-03-30 14:48:55 -07:00
|
|
|
|
case LevelingSystem.Probe3Points:
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if (levelingData.SampledPositions.Count != 3) // different criteria for what is not initialized
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2016-02-22 10:14:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-03-30 14:48:55 -07:00
|
|
|
|
case LevelingSystem.Probe7PointRadial:
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if (levelingData.SampledPositions.Count != 7) // different criteria for what is not initialized
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2016-02-22 10:14:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-03-30 14:48:55 -07:00
|
|
|
|
case LevelingSystem.Probe13PointRadial:
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if (levelingData.SampledPositions.Count != 13) // different criteria for what is not initialized
|
2018-04-28 16:59:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LevelingSystem.Probe100PointRadial:
|
|
|
|
|
|
if (levelingData.SampledPositions.Count != 100) // different criteria for what is not initialized
|
2016-02-22 10:14:07 -08:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2016-02-22 10:14:07 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2017-05-19 14:39:57 -07:00
|
|
|
|
case LevelingSystem.Probe3x3Mesh:
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if (levelingData.SampledPositions.Count != 9) // different criteria for what is not initialized
|
2017-05-19 14:39:57 -07:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2017-05-19 14:39:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-04-04 13:45:10 -07:00
|
|
|
|
case LevelingSystem.Probe5x5Mesh:
|
2018-04-05 13:55:23 -07:00
|
|
|
|
if (levelingData.SampledPositions.Count != 25) // different criteria for what is not initialized
|
2018-04-04 13:45:10 -07:00
|
|
|
|
{
|
2018-04-05 13:55:23 -07:00
|
|
|
|
return true;
|
2018-04-04 13:45:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-04-27 18:28:49 -07:00
|
|
|
|
case LevelingSystem.Probe10x10Mesh:
|
|
|
|
|
|
if (levelingData.SampledPositions.Count != 100) // different criteria for what is not initialized
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-08-27 14:57:55 -07:00
|
|
|
|
case LevelingSystem.ProbeCustom:
|
|
|
|
|
|
if (levelingData.SampledPositions.Count != LevelWizardCustom.ParseLevelingSamplePoints(printer).Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2016-02-22 10:14:07 -08:00
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-19 15:46:36 -07:00
|
|
|
|
return false;
|
2016-02-22 10:14:07 -08:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|