Made the library actually copy gcode to the library folder

Working on adding support for reporting errors when enabled
Made PrintActiveItem check for error conditions.
This commit is contained in:
Lars Brubaker 2015-04-15 10:08:36 -07:00
parent e00d12959b
commit 6d7b0280bb
3 changed files with 83 additions and 46 deletions

View file

@ -299,6 +299,13 @@ namespace MatterHackers.MatterControl
showWindow = true;
}
public enum ReportSeverity2 { Warning, Error }
public void ReportException(Exception e, string key, string value, ReportSeverity2 warningLevel = ReportSeverity2.Warning)
{
// do nothing
}
private event EventHandler unregisterEvent;
public static MatterControlApplication Instance

View file

@ -373,7 +373,24 @@ namespace MatterHackers.MatterControl.PrintLibrary
else // it is not a mesh so just add it
{
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
LibraryData.Instance.AddItem(printItemWrapper);
if (false)
{
LibraryData.Instance.AddItem(printItemWrapper);
}
else // save a copy to the library and update this to point at it
{
string sourceFileName = printItem.FileLocation;
string newFileName = Path.ChangeExtension(Path.GetRandomFileName(), Path.GetExtension(printItem.FileLocation));
string destFileName = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, newFileName);
File.Copy(sourceFileName, destFileName, true);
printItemWrapper.FileLocation = destFileName;
printItemWrapper.PrintItem.Commit();
// let the queue know that the item has changed so it load the correct part
LibraryData.Instance.AddItem(printItemWrapper);
}
}
}

View file

@ -47,6 +47,7 @@ using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
@ -1236,63 +1237,75 @@ namespace MatterHackers.MatterControl.PrinterCommunication
public void PrintActivePart()
{
PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);
if (levelingData.needsPrintLeveling
&& levelingData.sampledPosition0.z == 0
&& levelingData.sampledPosition1.z == 0
&& levelingData.sampledPosition2.z == 0)
try
{
LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.InitialStartupCalibration);
return;
}
string pathAndFile = PrinterConnectionAndCommunication.Instance.ActivePrintItem.FileLocation;
if (ActiveSliceSettings.Instance.HasSdCardReader()
&& pathAndFile == QueueData.SdCardFileName)
{
PrinterConnectionAndCommunication.Instance.StartSdCardPrint();
}
else if (ActiveSliceSettings.Instance.IsValid())
{
if (File.Exists(pathAndFile))
PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter);
if (levelingData != null
&& levelingData.needsPrintLeveling
&& levelingData.sampledPosition0.z == 0
&& levelingData.sampledPosition1.z == 0
&& levelingData.sampledPosition2.z == 0)
{
// clear the output cache prior to starting a print
PrinterOutputCache.Instance.Clear();
LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.InitialStartupCalibration);
return;
}
string hideGCodeWarning = ApplicationSettings.Instance.get("HideGCodeWarning");
if (Path.GetExtension(pathAndFile).ToUpper() == ".GCODE" && hideGCodeWarning == null)
if (PrinterConnectionAndCommunication.Instance.ActivePrintItem != null)
{
string pathAndFile = PrinterConnectionAndCommunication.Instance.ActivePrintItem.FileLocation;
if (ActiveSliceSettings.Instance.HasSdCardReader()
&& pathAndFile == QueueData.SdCardFileName)
{
CheckBox hideGCodeWarningCheckBox = new CheckBox(doNotShowAgainMessage);
hideGCodeWarningCheckBox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
hideGCodeWarningCheckBox.Margin = new BorderDouble(top: 6, left: 6);
hideGCodeWarningCheckBox.HAnchor = Agg.UI.HAnchor.ParentLeft;
hideGCodeWarningCheckBox.Click += (sender, e) =>
PrinterConnectionAndCommunication.Instance.StartSdCardPrint();
}
else if (ActiveSliceSettings.Instance.IsValid())
{
if (File.Exists(pathAndFile))
{
if (hideGCodeWarningCheckBox.Checked)
// clear the output cache prior to starting a print
PrinterOutputCache.Instance.Clear();
string hideGCodeWarning = ApplicationSettings.Instance.get("HideGCodeWarning");
if (Path.GetExtension(pathAndFile).ToUpper() == ".GCODE" && hideGCodeWarning == null)
{
ApplicationSettings.Instance.set("HideGCodeWarning", "true");
CheckBox hideGCodeWarningCheckBox = new CheckBox(doNotShowAgainMessage);
hideGCodeWarningCheckBox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
hideGCodeWarningCheckBox.Margin = new BorderDouble(top: 6, left: 6);
hideGCodeWarningCheckBox.HAnchor = Agg.UI.HAnchor.ParentLeft;
hideGCodeWarningCheckBox.Click += (sender, e) =>
{
if (hideGCodeWarningCheckBox.Checked)
{
ApplicationSettings.Instance.set("HideGCodeWarning", "true");
}
else
{
ApplicationSettings.Instance.set("HideGCodeWarning", null);
}
};
StyledMessageBox.ShowMessageBox(onConfirmPrint, gcodeWarningMessage, "Warning - GCode file".Localize(), new GuiWidget[] { new VerticalSpacer(), hideGCodeWarningCheckBox }, StyledMessageBox.MessageType.YES_NO);
}
else
{
ApplicationSettings.Instance.set("HideGCodeWarning", null);
PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint;
PrintItemWrapper partToPrint = PrinterConnectionAndCommunication.Instance.ActivePrintItem;
SlicingQueue.Instance.QueuePartForSlicing(partToPrint);
partToPrint.SlicingDone.RegisterEvent(partToPrint_SliceDone, ref unregisterEvents);
}
};
StyledMessageBox.ShowMessageBox(onConfirmPrint, gcodeWarningMessage, "Warning - GCode file".Localize(), new GuiWidget[] { new VerticalSpacer(), hideGCodeWarningCheckBox }, StyledMessageBox.MessageType.YES_NO);
}
else
{
PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint;
PrintItemWrapper partToPrint = PrinterConnectionAndCommunication.Instance.ActivePrintItem;
SlicingQueue.Instance.QueuePartForSlicing(partToPrint);
partToPrint.SlicingDone.RegisterEvent(partToPrint_SliceDone, ref unregisterEvents);
}
else
{
string message = String.Format(removeFromQueueMessage, pathAndFile);
StyledMessageBox.ShowMessageBox(onRemoveMessageConfirm, message, itemNotFoundMessage, StyledMessageBox.MessageType.YES_NO);
}
}
}
else
{
string message = String.Format(removeFromQueueMessage, pathAndFile);
StyledMessageBox.ShowMessageBox(onRemoveMessageConfirm, message, itemNotFoundMessage, StyledMessageBox.MessageType.YES_NO);
}
}
catch (Exception e)
{
// Let's track this issue if possible.
MatterControlApplication.Instance.ReportException(e, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
}
}