Re-capturing all the other changes made during leveling issues investigations
This commit is contained in:
parent
c06469af69
commit
d95d7ac58b
6 changed files with 142 additions and 28 deletions
|
|
@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.VectorMath;
|
||||
using MIConvexHull;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
|
|
@ -66,5 +67,72 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<(Vector3 v0, Vector3 v1, Vector3 v2)> GetLevelingTriangles()
|
||||
{
|
||||
// get the delaunay triangulation
|
||||
var zDictionary = new Dictionary<(double, double), double>();
|
||||
var vertices = new List<DefaultVertex>();
|
||||
|
||||
if (SampledPositions.Count > 2)
|
||||
{
|
||||
foreach (var sample in SampledPositions)
|
||||
{
|
||||
vertices.Add(new DefaultVertex()
|
||||
{
|
||||
Position = new double[] { sample.X, sample.Y }
|
||||
});
|
||||
var key = (sample.X, sample.Y);
|
||||
if (!zDictionary.ContainsKey(key))
|
||||
{
|
||||
zDictionary.Add(key, sample.Z);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vertices.Add(new DefaultVertex()
|
||||
{
|
||||
Position = new double[] { 0, 0 }
|
||||
});
|
||||
zDictionary.Add((0, 0), 0);
|
||||
|
||||
vertices.Add(new DefaultVertex()
|
||||
{
|
||||
Position = new double[] { 200, 0 }
|
||||
});
|
||||
zDictionary.Add((200, 0), 0);
|
||||
|
||||
vertices.Add(new DefaultVertex()
|
||||
{
|
||||
Position = new double[] { 100, 200 }
|
||||
});
|
||||
zDictionary.Add((100, 200), 0);
|
||||
}
|
||||
|
||||
int extraXPosition = -50000;
|
||||
vertices.Add(new DefaultVertex()
|
||||
{
|
||||
Position = new double[] { extraXPosition, vertices[0].Position[1] }
|
||||
});
|
||||
|
||||
var triangles = DelaunayTriangulation<DefaultVertex, DefaultTriangulationCell<DefaultVertex>>.Create(vertices, .001);
|
||||
|
||||
// make all the triangle planes for these triangles
|
||||
foreach (var triangle in triangles.Cells)
|
||||
{
|
||||
var p0 = triangle.Vertices[0].Position;
|
||||
var p1 = triangle.Vertices[1].Position;
|
||||
var p2 = triangle.Vertices[2].Position;
|
||||
if (p0[0] != extraXPosition && p1[0] != extraXPosition && p2[0] != extraXPosition)
|
||||
{
|
||||
var v0 = new Vector3(p0[0], p0[1], zDictionary[(p0[0], p0[1])]);
|
||||
var v1 = new Vector3(p1[0], p1[1], zDictionary[(p1[0], p1[1])]);
|
||||
var v2 = new Vector3(p2[0], p2[1], zDictionary[(p2[0], p2[1])]);
|
||||
// add all the regions
|
||||
yield return (v0, v1, v2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ using MatterHackers.Agg.UI;
|
|||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||
using MatterHackers.MatterControl.DesignTools;
|
||||
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
|
|
@ -445,6 +446,19 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
Error = "You are connected to the Emulator not an actual printer.".Localize(),
|
||||
ErrorLevel = ValidationErrorLevel.Warning,
|
||||
FixAction = new NamedAction()
|
||||
{
|
||||
Title = "Switch".Localize(),
|
||||
IsEnabled = () => !printer.Connection.Printing && !printer.Connection.Paused,
|
||||
Action = () => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
// make sure we are not connected or we can't change the port
|
||||
printer.Connection.Disable();
|
||||
|
||||
// User initiated connect attempt failed, show port selection dialog
|
||||
DialogWindow.Show(new SetupStepComPortOne(printer));
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,16 +148,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
|||
(destination.Y == double.PositiveInfinity) ? 0 : destination.Y,
|
||||
(destination.Z == double.PositiveInfinity) ? 0 : destination.Z);
|
||||
|
||||
// get the offset to the active extruder
|
||||
var extruderOffset = printer.Settings.Helpers.ExtruderOffset(printer.Connection.ActiveExtruderIndex);
|
||||
correctedPosition += extruderOffset;
|
||||
|
||||
// level it
|
||||
Vector3 outPosition = GetPositionWithZOffset(correctedPosition);
|
||||
|
||||
// take the extruder offset back out
|
||||
outPosition -= extruderOffset;
|
||||
|
||||
// Only output known positions
|
||||
if (destination.X != double.PositiveInfinity)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
};
|
||||
disconnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
if (printer.Connection.Printing)
|
||||
if (printer.Connection.Printing || printer.Connection.Paused)
|
||||
{
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
(bool disconnectCancel) =>
|
||||
|
|
|
|||
|
|
@ -860,6 +860,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
}));
|
||||
});
|
||||
var export = popupMenu.CreateMenuItem("Export".Localize(), StaticData.Instance.LoadIcon("cube_export.png", 16, 16, theme.InvertIcons));
|
||||
export.Click += (s, e) => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
ApplicationController.Instance.ExportLibraryItems(
|
||||
new[] { new InMemoryLibraryItem(sceneContext.Scene) },
|
||||
centerOnBed: false,
|
||||
printer: view3DWidget.Printer);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
|
@ -37,6 +38,7 @@ using MatterHackers.Localizations;
|
|||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
|
|
@ -116,7 +118,7 @@ namespace MatterHackers.MatterControl
|
|||
int linkCompatibleRow = row;
|
||||
int linkCompatibleAxis = axis;
|
||||
|
||||
MHNumberEdit valueEdit = new MHNumberEdit(positions[linkCompatibleRow][linkCompatibleAxis], theme, allowNegatives: true, allowDecimals: true, pixelWidth: 60 * GuiWidget.DeviceScale, tabIndex: tab_index++)
|
||||
var valueEdit = new MHNumberEdit(positions[linkCompatibleRow][linkCompatibleAxis], theme, allowNegatives: true, allowDecimals: true, pixelWidth: 60 * GuiWidget.DeviceScale, tabIndex: tab_index++)
|
||||
{
|
||||
Name = $"{axisName} Position {row}"
|
||||
};
|
||||
|
|
@ -151,7 +153,9 @@ namespace MatterHackers.MatterControl
|
|||
this.AddPageAction(savePresetsButton);
|
||||
|
||||
var exportButton = theme.CreateDialogButton("Export".Localize());
|
||||
exportButton.Click += (s, e) => {
|
||||
exportButton.ToolTipText = "Export as .csv, .json or .stl".Localize();
|
||||
exportButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(this.ExportSettings, .1);
|
||||
};
|
||||
this.AddPageAction(exportButton);
|
||||
|
|
@ -161,30 +165,57 @@ namespace MatterHackers.MatterControl
|
|||
private void ExportSettings()
|
||||
{
|
||||
AggContext.FileDialogs.SaveFileDialog(
|
||||
new SaveFileDialogParams("Bed Leveling Data|*.csv") {
|
||||
new SaveFileDialogParams("Bed Leveling Data|*.csv")
|
||||
{
|
||||
Title = "Export Bed Leveling Data".Localize(),
|
||||
FileName = $"{printer.Settings.GetValue(SettingsKey.printer_name)} Leveling Data"
|
||||
},
|
||||
(saveParams) => {
|
||||
try {
|
||||
if (!string.IsNullOrWhiteSpace(saveParams.FileName)) {
|
||||
// Export JSON data
|
||||
//File.WriteAllText(saveParams.FileName, printer.Settings.GetValue(SettingsKey.print_leveling_data));
|
||||
(saveParams) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(saveParams.FileName))
|
||||
{
|
||||
var levelingData = printer.Settings.Helpers.PrintLevelingData;
|
||||
|
||||
// Export CSV data
|
||||
PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;
|
||||
using (StreamWriter file =
|
||||
new StreamWriter(saveParams.FileName)) {
|
||||
for (int i = 0; i < levelingData.SampledPositions.Count; i++) {
|
||||
double x = levelingData.SampledPositions[i].X;
|
||||
double y = levelingData.SampledPositions[i].Y;
|
||||
double z = levelingData.SampledPositions[i].Z;
|
||||
file.WriteLine($"{x}, {y}, {z}");
|
||||
}
|
||||
switch (Path.GetExtension(saveParams.FileName).ToUpper())
|
||||
{
|
||||
case ".STL":
|
||||
// Export CSV data
|
||||
var mesh = new Mesh();
|
||||
foreach (var poly in levelingData.GetLevelingTriangles())
|
||||
{
|
||||
mesh.CreateFace(new Vector3[] { poly.v2, poly.v1, poly.v0 });
|
||||
}
|
||||
mesh.Save(saveParams.FileName, CancellationToken.None);
|
||||
break;
|
||||
|
||||
case ".JSON":
|
||||
// Export JSON data
|
||||
File.WriteAllText(saveParams.FileName, printer.Settings.GetValue(SettingsKey.print_leveling_data));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Export CSV data
|
||||
using (var file =
|
||||
new StreamWriter(saveParams.FileName))
|
||||
{
|
||||
for (int i = 0; i < levelingData.SampledPositions.Count; i++)
|
||||
{
|
||||
double x = levelingData.SampledPositions[i].X;
|
||||
double y = levelingData.SampledPositions[i].Y;
|
||||
double z = levelingData.SampledPositions[i].Z;
|
||||
file.WriteLine($"{x}, {y}, {z}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
UiThread.RunOnIdle(() => {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
StyledMessageBox.ShowMessageBox(e.Message, "Couldn't save file".Localize());
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue