From 6d7b0280bb1a48465d4d688c7dbc139f45a1ee53 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 15 Apr 2015 10:08:36 -0700 Subject: [PATCH] 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. --- MatterControlApplication.cs | 7 ++ PrintLibrary/LibraryData.cs | 19 +++- .../PrinterConnectionAndCommunication.cs | 103 ++++++++++-------- 3 files changed, 83 insertions(+), 46 deletions(-) diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index c10c4e96b..d58f25e88 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -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 diff --git a/PrintLibrary/LibraryData.cs b/PrintLibrary/LibraryData.cs index c8779be3a..55347bb93 100644 --- a/PrintLibrary/LibraryData.cs +++ b/PrintLibrary/LibraryData.cs @@ -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); + } } } diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index 9e0946bac..ae144e0da 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -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); } }