Refactoring leveling system
This commit is contained in:
parent
f78db090ef
commit
34970a6462
14 changed files with 74 additions and 89 deletions
|
|
@ -41,6 +41,7 @@ using MatterHackers.Agg.Platform;
|
|||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||
using MatterHackers.MatterControl.ContactForm;
|
||||
using MatterHackers.MatterControl.SettingsManagement;
|
||||
using MatterHackers.MeshVisualizer;
|
||||
|
|
@ -765,6 +766,26 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
// this way we can use the common pattern without errer
|
||||
return (T)(object)this.GetValue(settingsKey);
|
||||
}
|
||||
else if(typeof(T) == typeof(LevelingSystem))
|
||||
{
|
||||
switch(this.GetValue(settingsKey))
|
||||
{
|
||||
case "3 Point Plane":
|
||||
return (T)(object)(LevelingSystem.Probe3Points);
|
||||
case "7 Point Disk":
|
||||
return (T)(object)(LevelingSystem.Probe7PointRadial);
|
||||
case "13 Point Disk":
|
||||
return (T)(object)(LevelingSystem.Probe13PointRadial);
|
||||
case "3x3 Mesh":
|
||||
return (T)(object)(LevelingSystem.Probe3x3Mesh);
|
||||
default:
|
||||
#if DEBUG
|
||||
throw new NotImplementedException();
|
||||
#endif
|
||||
}
|
||||
|
||||
return (T)(object)(LevelingSystem.Probe3Points);
|
||||
}
|
||||
else if (typeof(T) == typeof(bool))
|
||||
{
|
||||
return (T)(object)(this.GetValue(settingsKey) == "1");
|
||||
|
|
|
|||
|
|
@ -299,22 +299,19 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
printerSettings.SetValue(SettingsKey.printer_name, name);
|
||||
}
|
||||
|
||||
private PrintLevelingData printLevelingData = null;
|
||||
public PrintLevelingData GetPrintLevelingData()
|
||||
{
|
||||
PrintLevelingData printLevelingData = null;
|
||||
var jsonData = printerSettings.GetValue(SettingsKey.print_leveling_data);
|
||||
if (!string.IsNullOrEmpty(jsonData))
|
||||
{
|
||||
printLevelingData = JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
|
||||
}
|
||||
|
||||
// if it is still null
|
||||
if (printLevelingData == null)
|
||||
{
|
||||
var jsonData = printerSettings.GetValue(SettingsKey.print_leveling_data);
|
||||
if (!string.IsNullOrEmpty(jsonData))
|
||||
{
|
||||
printLevelingData = JsonConvert.DeserializeObject<PrintLevelingData>(jsonData);
|
||||
}
|
||||
|
||||
// if it is still null
|
||||
if (printLevelingData == null)
|
||||
{
|
||||
printLevelingData = new PrintLevelingData();
|
||||
}
|
||||
printLevelingData = new PrintLevelingData();
|
||||
}
|
||||
|
||||
return printLevelingData;
|
||||
|
|
@ -326,7 +323,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
printerSettings.SetValue(SettingsKey.baby_step_z_offset, "0");
|
||||
}
|
||||
printLevelingData = data;
|
||||
|
||||
printerSettings.SetValue(SettingsKey.print_leveling_data, JsonConvert.SerializeObject(data));
|
||||
}
|
||||
|
||||
|
|
@ -340,27 +337,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
printerSettings.SetValue(SettingsKey.print_leveling_enabled, doLeveling ? "1" : "0");
|
||||
|
||||
if (doLeveling)
|
||||
{
|
||||
UpdateLevelSettings();
|
||||
}
|
||||
|
||||
printerSettings.PrintLevelingEnabledChanged?.CallEvents(this, null);
|
||||
}
|
||||
|
||||
public void UpdateLevelSettings()
|
||||
{
|
||||
PrintLevelingData levelingData = this.GetPrintLevelingData();
|
||||
if (levelingData.SampledPositions.Count > 2)
|
||||
{
|
||||
PrintLevelingPlane.Instance.SetPrintLevelingEquation(
|
||||
levelingData.SampledPositions[0],
|
||||
levelingData.SampledPositions[1],
|
||||
levelingData.SampledPositions[2],
|
||||
printerSettings.GetValue<Vector2>(SettingsKey.print_center));
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 ExtruderOffset(int extruderIndex)
|
||||
{
|
||||
string currentOffsets = printerSettings.GetValue("extruder_offset");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue