Add support for printing GCode

- Issue MatterHackers/MatterControl#3457
MC2 2.0.0.9727 Gcode files do not print
- Enable print from current bed plate
- Enable print from library selection
This commit is contained in:
John Lewin 2018-07-18 14:59:23 -07:00
parent 1aa28d8b1d
commit 45ff2d5e54
3 changed files with 53 additions and 4 deletions

View file

@ -189,6 +189,28 @@ namespace MatterHackers.MatterControl
return insertionGroup;
}
public async Task StashAndPrintGCode(ILibraryItem libraryItem)
{
// Clear plate
await this.ClearPlate();
// Add content
await this.LoadContent(
new EditContext()
{
SourceItem = libraryItem,
// No content store for GCode, otherwise PlatingHistory
ContentStore = this.EditContext.ContentStore
});
// Slice and print
await ApplicationController.Instance.PrintPart(
this.EditContext,
this.Printer,
null,
CancellationToken.None);
}
public async Task StashAndPrint(IEnumerable<ILibraryItem> selectedLibraryItems)
{
// Clear plate

View file

@ -525,7 +525,14 @@ namespace MatterHackers.MatterControl.PrintLibrary
printer.Connection.StartSdCardPrint(sdcardItem.Name.ToLower());
break;
case FileSystemFileItem fileItem when Path.GetExtension(fileItem.FileName).ToUpper() == ".GCODE":
//ApplicationController.Instance.ActivePrintItem = new PrintItemWrapper(new PrintItem(fileItem.Name, fileItem.Path));
if (printer != null)
{
UiThread.RunOnIdle(async () =>
{
await printer.Bed.StashAndPrintGCode(fileItem);
});
}
break;
default:
//TODO: Otherwise add the selected items to the plate and print the plate?
@ -559,9 +566,26 @@ namespace MatterHackers.MatterControl.PrintLibrary
Title = "Add to Plate".Localize(),
Action = (selectedLibraryItems, listView) =>
{
// TODO: Sort out the right way to have an ActivePrinter context that looks and behaves correctly
var activeContext = ApplicationController.Instance.DragDropData;
activeContext.SceneContext.AddToPlate(selectedLibraryItems);
var printer = activeContext.Printer;
if (listView.SelectedItems.Count == 1 &&
selectedLibraryItems.FirstOrDefault() is ILibraryAssetStream assetStream
&& assetStream.ContentType == "gcode")
{
// Drop handler for special case of GCode or similar (change loaded scene to new context)
printer.Bed.LoadContent(
new EditContext()
{
SourceItem = assetStream,
// No content store for GCode, otherwise PlatingHistory
ContentStore = printer.Bed.EditContext.ContentStore
}).ConfigureAwait(false);
}
else
{
activeContext.SceneContext.AddToPlate(selectedLibraryItems);
}
},
IsEnabled = (selectedListItems, listView) =>
{

View file

@ -35,6 +35,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
@ -145,7 +146,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
button.Click += (s, e) =>
{
if (!printer.Bed.Scene.Children.Any())
// Exit if the bed is not GCode and the bed has no items
if ((printer.Bed.EditContext.SourceItem as ILibraryAsset)?.ContentType != "gcode"
&& printer.Bed.Scene.Children.Count <= 0)
{
return;
}