Extract CopyPlateToPrinter for reuse
This commit is contained in:
parent
68799abb23
commit
a159c6ed37
1 changed files with 70 additions and 57 deletions
|
|
@ -309,68 +309,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
if (ProfileManager.Instance.Profiles.Where(p => !p.MarkedForDelete).Count() <= 0)
|
||||
{
|
||||
//Launch window to prompt user to sign in
|
||||
UiThread.RunOnIdle(() => DialogWindow.Show(new SetupStepMakeModelName()));
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
var window = DialogWindow.Show(new SetupStepMakeModelName());
|
||||
window.Closed += (s2, e2) =>
|
||||
{
|
||||
if (ApplicationController.Instance.ActivePrinter is PrinterConfig printer
|
||||
&& printer.Settings.PrinterSelected)
|
||||
{
|
||||
ViewControls3D.CopyPlateToPrinter(sceneContext, printer);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
// If no active printer but profiles exist, show select printer
|
||||
// If printer exists, stash plate with undo operation, then load this scene onto the printer bed
|
||||
else if (ApplicationController.Instance.ActivePrinter is PrinterConfig printer && printer.Settings.PrinterSelected)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges);
|
||||
|
||||
// Clear bed to get new MCX on disk for this item
|
||||
printer.Bed.ClearPlate();
|
||||
|
||||
var editContext = sceneContext.EditContext;
|
||||
|
||||
await printer.Bed.LoadContent(editContext);
|
||||
|
||||
bool allInBounds = true;
|
||||
foreach (var item in printer.Bed.Scene.VisibleMeshes())
|
||||
{
|
||||
allInBounds &= printer.InsideBuildVolume(item);
|
||||
}
|
||||
|
||||
if(!allInBounds)
|
||||
{
|
||||
var bounds = printer.Bed.Scene.GetAxisAlignedBoundingBox();
|
||||
var boundsCenter = bounds.Center;
|
||||
// don't move the z of our stuff
|
||||
boundsCenter.Z = 0;
|
||||
|
||||
if (bounds.XSize <= printer.Bed.ViewerVolume.X
|
||||
&& bounds.YSize <= printer.Bed.ViewerVolume.Y)
|
||||
{
|
||||
// center the collection of stuff
|
||||
var bedCenter = new Vector3(printer.Bed.BedCenter);
|
||||
|
||||
foreach (var item in printer.Bed.Scene.Children)
|
||||
{
|
||||
item.Matrix *= Matrix4X4.CreateTranslation(-boundsCenter + bedCenter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// arrange the stuff the best we can
|
||||
await printer.Bed.Scene.AutoArrangeChildren(new Vector3(printer.Bed.BedCenter));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Switch to printer
|
||||
ApplicationController.Instance.AppView.TabControl.SelectedTabKey = printer.Settings.GetValue(SettingsKey.printer_name);
|
||||
|
||||
// Slice and print
|
||||
// Save any pending changes before starting print operation
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges);
|
||||
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
printer.Bed.EditContext,
|
||||
printer,
|
||||
null,
|
||||
CancellationToken.None);
|
||||
});
|
||||
ViewControls3D.CopyPlateToPrinter(sceneContext, printer);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -500,6 +456,63 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
Scene_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private static void CopyPlateToPrinter(BedConfig sceneContext, PrinterConfig printer)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), sceneContext.SaveChanges);
|
||||
|
||||
// Clear bed to get new MCX on disk for this item
|
||||
printer.Bed.ClearPlate();
|
||||
|
||||
await printer.Bed.LoadContent(sceneContext.EditContext);
|
||||
|
||||
bool allInBounds = true;
|
||||
foreach (var item in printer.Bed.Scene.VisibleMeshes())
|
||||
{
|
||||
allInBounds &= printer.InsideBuildVolume(item);
|
||||
}
|
||||
|
||||
if (!allInBounds)
|
||||
{
|
||||
var bounds = printer.Bed.Scene.GetAxisAlignedBoundingBox();
|
||||
var boundsCenter = bounds.Center;
|
||||
// don't move the z of our stuff
|
||||
boundsCenter.Z = 0;
|
||||
|
||||
if (bounds.XSize <= printer.Bed.ViewerVolume.X
|
||||
&& bounds.YSize <= printer.Bed.ViewerVolume.Y)
|
||||
{
|
||||
// center the collection of stuff
|
||||
var bedCenter = new Vector3(printer.Bed.BedCenter);
|
||||
|
||||
foreach (var item in printer.Bed.Scene.Children)
|
||||
{
|
||||
item.Matrix *= Matrix4X4.CreateTranslation(-boundsCenter + bedCenter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// arrange the stuff the best we can
|
||||
await printer.Bed.Scene.AutoArrangeChildren(new Vector3(printer.Bed.BedCenter));
|
||||
}
|
||||
}
|
||||
|
||||
// Switch to printer
|
||||
ApplicationController.Instance.AppView.TabControl.SelectedTabKey = printer.Settings.GetValue(SettingsKey.printer_name);
|
||||
|
||||
// Slice and print
|
||||
// Save any pending changes before starting print operation
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges);
|
||||
|
||||
await ApplicationController.Instance.PrintPart(
|
||||
printer.Bed.EditContext,
|
||||
printer,
|
||||
null,
|
||||
CancellationToken.None);
|
||||
});
|
||||
}
|
||||
|
||||
private void Scene_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
// Set enabled level based on operation rules
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue