Generate calibration gcode from in memory object3D
- Issue MatterHackers/MCCentral#5207 Calibration prints should shouldn't put models on the bed
This commit is contained in:
parent
df803eb9eb
commit
b4e22d560d
2 changed files with 51 additions and 14 deletions
|
|
@ -81,6 +81,27 @@ namespace MatterHackers.MatterControl
|
||||||
return GCodePath(printer);
|
return GCodePath(printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GCodeFilePath(PrinterConfig printer, IObject3D object3D)
|
||||||
|
{
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
// Write JSON
|
||||||
|
object3D.SaveTo(memoryStream);
|
||||||
|
|
||||||
|
// Reposition
|
||||||
|
memoryStream.Position = 0;
|
||||||
|
|
||||||
|
// Calculate
|
||||||
|
string fileHashCode = HashGenerator.ComputeSHA1(memoryStream);
|
||||||
|
|
||||||
|
ulong settingsHashCode = printer.Settings.GetGCodeCacheKey();
|
||||||
|
|
||||||
|
return Path.Combine(
|
||||||
|
ApplicationDataStorage.Instance.GCodeOutputPath,
|
||||||
|
$"{fileHashCode}_{ settingsHashCode}.gcode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal void Save(IObject3D scene)
|
internal void Save(IObject3D scene)
|
||||||
{
|
{
|
||||||
if (!this.FreezeGCode)
|
if (!this.FreezeGCode)
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,15 @@ either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
using MatterHackers.DataConverters3D;
|
using MatterHackers.DataConverters3D;
|
||||||
using MatterHackers.Localizations;
|
using MatterHackers.Localizations;
|
||||||
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
|
||||||
using MatterHackers.MatterControl.DesignTools;
|
using MatterHackers.MatterControl.DesignTools;
|
||||||
|
using MatterHackers.MatterControl.Library;
|
||||||
using MatterHackers.MatterControl.PrinterCommunication;
|
using MatterHackers.MatterControl.PrinterCommunication;
|
||||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||||
using MatterHackers.VectorMath;
|
using MatterHackers.VectorMath;
|
||||||
|
|
@ -68,11 +71,9 @@ namespace MatterHackers.MatterControl
|
||||||
startCalibrationPrint.Name = "Start Calibration Print";
|
startCalibrationPrint.Name = "Start Calibration Print";
|
||||||
startCalibrationPrint.Click += async (s, e) =>
|
startCalibrationPrint.Click += async (s, e) =>
|
||||||
{
|
{
|
||||||
// stash the current bed
|
var scene = new Object3D();
|
||||||
var scene = printer.Bed.Scene;
|
|
||||||
scene.Children.Modify((list) => list.Clear());
|
|
||||||
|
|
||||||
// create the item we are adding
|
// create the calibration objects
|
||||||
IObject3D item = CreateCalibrationObject(printer, xyCalibrationData);
|
IObject3D item = CreateCalibrationObject(printer, xyCalibrationData);
|
||||||
|
|
||||||
// add the calibration object to the bed
|
// add the calibration object to the bed
|
||||||
|
|
@ -82,26 +83,41 @@ namespace MatterHackers.MatterControl
|
||||||
var bedBounds = printer.Bed.Bounds;
|
var bedBounds = printer.Bed.Bounds;
|
||||||
var aabb = item.GetAxisAlignedBoundingBox();
|
var aabb = item.GetAxisAlignedBoundingBox();
|
||||||
item.Matrix *= Matrix4X4.CreateTranslation(bedBounds.Center.X - aabb.MinXYZ.X - aabb.XSize / 2, bedBounds.Center.Y - aabb.MinXYZ.Y - aabb.YSize / 2, -aabb.MinXYZ.Z);
|
item.Matrix *= Matrix4X4.CreateTranslation(bedBounds.Center.X - aabb.MinXYZ.X - aabb.XSize / 2, bedBounds.Center.Y - aabb.MinXYZ.Y - aabb.YSize / 2, -aabb.MinXYZ.Z);
|
||||||
// switch to 3D view
|
|
||||||
// register callbacks for print completion
|
// register callbacks for print completion
|
||||||
printer.Connection.Disposed += Connection_Disposed;
|
printer.Connection.Disposed += this.Connection_Disposed;
|
||||||
printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged;
|
printer.Connection.CommunicationStateChanged += this.Connection_CommunicationStateChanged;
|
||||||
|
|
||||||
this.MoveToNextPage();
|
this.MoveToNextPage();
|
||||||
|
|
||||||
// hide this window
|
// hide this window
|
||||||
this.DialogWindow.Visible = false;
|
this.DialogWindow.Visible = false;
|
||||||
|
|
||||||
// Save the bed that we have created before starting print operation
|
string gcodePath = EditContext.GCodeFilePath(printer, scene);
|
||||||
await printer.Bed.SaveChanges(null, CancellationToken.None);
|
|
||||||
|
|
||||||
// start the calibration print
|
printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
|
||||||
await ApplicationController.Instance.PrintPart(
|
|
||||||
printer.Bed.EditContext,
|
(bool slicingSucceeded, string finalGCodePath) = await ApplicationController.Instance.SliceItemLoadOutput(
|
||||||
printer,
|
printer,
|
||||||
null,
|
scene,
|
||||||
CancellationToken.None);
|
gcodePath);
|
||||||
|
|
||||||
|
// Only start print if slicing completed
|
||||||
|
if (slicingSucceeded)
|
||||||
|
{
|
||||||
|
await printer.Bed.LoadContent(new EditContext()
|
||||||
|
{
|
||||||
|
SourceItem = new FileSystemFileItem(gcodePath),
|
||||||
|
ContentStore = null // No content store for GCode
|
||||||
|
});
|
||||||
|
|
||||||
|
await printer.Connection.StartPrint(finalGCodePath, allowRecovery: false);
|
||||||
|
ApplicationController.Instance.MonitorPrintTask(printer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printer.Connection.CommunicationState = CommunicationStates.Connected;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
theme.ApplyPrimaryActionStyle(startCalibrationPrint);
|
theme.ApplyPrimaryActionStyle(startCalibrationPrint);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue