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;
|
2014-06-06 16:05:18 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class PrintLevelingData
|
|
|
|
|
|
{
|
2015-12-23 13:15:51 -08:00
|
|
|
|
public List<Vector3> SampledPositions = new List<Vector3>();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private static bool activelyLoading = false;
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
private static Printer activePrinter = null;
|
|
|
|
|
|
|
|
|
|
|
|
private static PrintLevelingData instance = null;
|
|
|
|
|
|
|
|
|
|
|
|
private Vector3 probeOffset0Private;
|
|
|
|
|
|
|
|
|
|
|
|
private Vector3 probeOffset1Private;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
private Vector3 sampledPosition0Private;
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
private Vector3 sampledPosition1Private;
|
|
|
|
|
|
|
|
|
|
|
|
private Vector3 sampledPosition2Private;
|
|
|
|
|
|
|
|
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2015-08-05 11:12:01 -07:00
|
|
|
|
public enum LevelingSystem { Probe3Points, Probe2Points, Probe7PointRadial, Probe13PointRadial }
|
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
|
|
|
|
{
|
2015-08-03 15:48:36 -07:00
|
|
|
|
switch (ActiveSliceSettings.Instance.GetActiveValue("print_leveling_solution"))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-03 15:48:36 -07:00
|
|
|
|
case "2 Point Plane":
|
|
|
|
|
|
return LevelingSystem.Probe2Points;
|
|
|
|
|
|
|
|
|
|
|
|
case "7 Point Disk":
|
|
|
|
|
|
return LevelingSystem.Probe7PointRadial;
|
|
|
|
|
|
|
2015-08-05 11:12:01 -07:00
|
|
|
|
case "13 Point Disk":
|
|
|
|
|
|
return LevelingSystem.Probe13PointRadial;
|
|
|
|
|
|
|
2015-08-03 15:48:36 -07:00
|
|
|
|
case "3 Point Plane":
|
|
|
|
|
|
default:
|
|
|
|
|
|
return LevelingSystem.Probe3Points;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
public Vector3 ProbeOffset0
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
get { return probeOffset0Private; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
if (probeOffset0Private != value)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
probeOffset0Private = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
Commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
public Vector3 ProbeOffset1
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
get { return probeOffset1Private; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
if (probeOffset1Private != value)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
probeOffset1Private = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
Commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
public Vector3 SampledPosition0
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
get { return sampledPosition0Private; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
if (sampledPosition0Private != value)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
sampledPosition0Private = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
Commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
public Vector3 SampledPosition1
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
get { return sampledPosition1Private; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
if (sampledPosition1Private != value)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
sampledPosition1Private = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
Commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-01 14:44:53 -07:00
|
|
|
|
public Vector3 SampledPosition2
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
get { return sampledPosition2Private; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
if (sampledPosition2Private != value)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-08-01 14:44:53 -07:00
|
|
|
|
sampledPosition2Private = value;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
Commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static PrintLevelingData GetForPrinter(Printer printer)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (printer != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (activePrinter != printer)
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateFromJsonOrLegacy(printer.PrintLevelingJsonData, printer.PrintLevelingProbePositions);
|
|
|
|
|
|
activePrinter = printer;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-23 13:15:51 -08:00
|
|
|
|
public void Commit()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!activelyLoading)
|
|
|
|
|
|
{
|
|
|
|
|
|
string newLevelingInfo = Newtonsoft.Json.JsonConvert.SerializeObject(this);
|
|
|
|
|
|
|
|
|
|
|
|
// clear the legacy value
|
|
|
|
|
|
activePrinter.PrintLevelingProbePositions = "";
|
|
|
|
|
|
// set the new value
|
|
|
|
|
|
activePrinter.PrintLevelingJsonData = newLevelingInfo;
|
|
|
|
|
|
activePrinter.Commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private static void CreateFromJsonOrLegacy(string jsonData, string depricatedPositionsCsv3ByXYZ)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (jsonData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
activelyLoading = true;
|
2015-08-01 14:44:53 -07:00
|
|
|
|
instance = Newtonsoft.Json.JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
activelyLoading = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (depricatedPositionsCsv3ByXYZ != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
instance = new PrintLevelingData();
|
|
|
|
|
|
instance.ParseDepricatedPrintLevelingMeasuredPositions(depricatedPositionsCsv3ByXYZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
instance = new PrintLevelingData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (depricatedPositionsCsv3ByXYZ != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] lines = depricatedPositionsCsv3ByXYZ.Split(',');
|
|
|
|
|
|
if (lines.Length == 9)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sampledPosition0Private[i % 3] = double.Parse(lines[0 * 3 + i]);
|
|
|
|
|
|
sampledPosition1Private[i % 3] = double.Parse(lines[1 * 3 + i]);
|
|
|
|
|
|
sampledPosition2Private[i % 3] = double.Parse(lines[2 * 3 + i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-02-22 10:14:07 -08:00
|
|
|
|
|
|
|
|
|
|
public bool HasBeenRun()
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (CurrentPrinterLevelingSystem)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PrintLevelingData.LevelingSystem.Probe2Points:
|
|
|
|
|
|
case PrintLevelingData.LevelingSystem.Probe3Points:
|
|
|
|
|
|
if (SampledPosition0.z == 0
|
|
|
|
|
|
&& SampledPosition1.z == 0
|
|
|
|
|
|
&& SampledPosition2.z == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RunLevelingWizard()
|
|
|
|
|
|
{
|
|
|
|
|
|
LevelWizardBase.RuningState runningState = LevelWizardBase.RuningState.UserRequestedCalibration;
|
|
|
|
|
|
if (ActiveSliceSettings.Instance.LevelingRequiredToPrint)
|
|
|
|
|
|
{
|
|
|
|
|
|
// run in the first run state
|
|
|
|
|
|
runningState = LevelWizardBase.RuningState.InitialStartupCalibration;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LevelWizardBase.ShowPrintLevelWizard(runningState);
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|