Add 'Print' menu action, implement Print for GCode and SD card GCode

- Fix and rename CloseShouldNotStopSDPrint test
- Fix product bugs regarding selecting and printing GCode
This commit is contained in:
John Lewin 2017-06-21 07:43:40 -07:00
parent aba13453a7
commit d9b28cdd86
5 changed files with 56 additions and 12 deletions

View file

@ -38,6 +38,7 @@ using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.CustomWidgets
@ -80,6 +81,17 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.ListContentView = new IconListView();
context.ContainerChanged += ActiveContainer_Changed;
context.ContainerReloaded += ActiveContainer_Reloaded;
bool printerConnected = false;
PrinterConnection.Instance.CommunicationStateChanged.RegisterEvent(async (s, e) =>
{
bool isConnected = PrinterConnection.Instance.PrinterIsConnected;
if (printerConnected != isConnected)
{
await DisplayContainerContent(ActiveContainer);
printerConnected = isConnected;
}
}, ref unregisterEvents);
}
public ILibraryContainer ActiveContainer => this.LibraryContext.ActiveContainer;

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.IO;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
@ -145,7 +146,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
&& ApplicationController.Instance.Library.IsContentFileType(stream.FileName));
bool isContainerLink = listViewItem.Model is ILibraryContainerLink;
if (isContentItem || isValidStream || isContainerLink)
bool isGCode = listViewItem.Model is FileSystemFileItem item && Path.GetExtension(item.FileName.ToUpper()) == ".GCODE"
|| listViewItem.Model is SDCardFileItem sdItem && Path.GetExtension(sdItem.Name.ToUpper()) == ".GCODE";
if (isContentItem || isValidStream || isContainerLink || isGCode)
{
if (this.IsSelected)
{

View file

@ -37,8 +37,10 @@ using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.SlicerConfiguration;
@ -370,17 +372,30 @@ namespace MatterHackers.MatterControl.PrintLibrary
{
menuActions.Add(new PrintItemAction()
{
Title = "Pin to Library",
Title = "Print",
AllowMultiple = false,
AllowContainers = true,
AllowContainers = false,
AllowProtected = true,
Action = (selectedLibraryItems, listView) =>
{
Console.WriteLine();
var firstItem = selectedLibraryItems.FirstOrDefault();
if (firstItem is SDCardFileItem sdcardItem)
{
ApplicationController.Instance.ActivePrintItem = new PrintItemWrapper(new PrintItem(sdcardItem.Name, QueueData.SdCardFileName));
}
else if (firstItem is FileSystemFileItem fileItem && Path.GetExtension(fileItem.FileName).ToUpper() == ".GCODE")
{
ApplicationController.Instance.ActivePrintItem = new PrintItemWrapper(new PrintItem(fileItem.Name, fileItem.Path));
}
else
{
//TODO: Otherwise add the selected items to the plate
}
ApplicationController.Instance.PrintActivePart();
}
});
// edit menu item
menuActions.Add(new PrintItemAction()
{