From 26d2730516b00d8fd3cbe430599e1100dcb2493f Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Wed, 5 Mar 2014 13:45:07 -0800 Subject: [PATCH] Fixing some errors with exporting gcode to a folder when the STL not present. --- PrintQueue/ExportToFolderProcess.cs | 25 ++++-- PrintQueue/PrintItemWrapper.cs | 18 +++-- SlicerConfiguration/SlicingQueue.cs | 116 ++++++++++++++-------------- 3 files changed, 91 insertions(+), 68 deletions(-) diff --git a/PrintQueue/ExportToFolderProcess.cs b/PrintQueue/ExportToFolderProcess.cs index 5ff047e95..0db651bad 100644 --- a/PrintQueue/ExportToFolderProcess.cs +++ b/PrintQueue/ExportToFolderProcess.cs @@ -102,7 +102,10 @@ namespace MatterHackers.MatterControl.PrintQueue sliceItem.Done -= new EventHandler(sliceItem_Done); sliceItem.SlicingOutputMessage -= printItemWrapper_SlicingOutputMessage; - savedGCodeFileNames.Add(sliceItem.GCodePathAndFileName); + if (File.Exists(sliceItem.FileLocation)) + { + savedGCodeFileNames.Add(sliceItem.GCodePathAndFileName); + } itemCountBeingWorkedOn++; if (itemCountBeingWorkedOn < allFilesToExport.Count) @@ -125,15 +128,23 @@ namespace MatterHackers.MatterControl.PrintQueue if (lines.Length > 0) { string filamentAmountLine = lines[lines.Length - 1]; + bool foundAmountInGCode = false; int startPos = filamentAmountLine.IndexOf("("); - int endPos = filamentAmountLine.IndexOf("cm3)"); - string value = filamentAmountLine.Substring(startPos + 1, endPos - (startPos + 1)); - double amountForThisFile; - if (double.TryParse(value, out amountForThisFile)) + if (startPos > 0) { - total += amountForThisFile; + int endPos = filamentAmountLine.IndexOf("cm3)", startPos); + if (endPos > 0) + { + string value = filamentAmountLine.Substring(startPos + 1, endPos - (startPos + 1)); + double amountForThisFile; + if (double.TryParse(value, out amountForThisFile)) + { + foundAmountInGCode = true; + total += amountForThisFile; + } + } } - else + if (!foundAmountInGCode) { GCodeFile gcodeFile = new GCodeFile(gcodeFileName); total += gcodeFile.GetFilamentCubicMm(ActiveSliceSettings.Instance.FillamentDiameter) / 1000; diff --git a/PrintQueue/PrintItemWrapper.cs b/PrintQueue/PrintItemWrapper.cs index 1e6b69313..e0daf3c85 100644 --- a/PrintQueue/PrintItemWrapper.cs +++ b/PrintQueue/PrintItemWrapper.cs @@ -51,15 +51,23 @@ namespace MatterHackers.MatterControl.PrintQueue if (doneSlicing) { string message = "Slicing Error"; - string gcodePathAndFileName = GetGCodePathAndFileName(); - if (gcodePathAndFileName != "" && File.Exists(gcodePathAndFileName)) + if (File.Exists(FileLocation)) { - FileInfo info = new FileInfo(gcodePathAndFileName); - if (info.Length > 10) + string gcodePathAndFileName = GetGCodePathAndFileName(); + if (gcodePathAndFileName != "" && File.Exists(gcodePathAndFileName)) { - message = "Ready to Print"; + FileInfo info = new FileInfo(gcodePathAndFileName); + // This is really just to make sure it is bigger than nothing. + if (info.Length > 10) + { + message = "Ready to Print"; + } } } + else + { + message = string.Format("File Not Found\n'{0}'", FileLocation); + } OnSlicingOutputMessage(new StringEventArgs(message)); diff --git a/SlicerConfiguration/SlicingQueue.cs b/SlicerConfiguration/SlicingQueue.cs index 6215c4ff5..fba4bd8c9 100644 --- a/SlicerConfiguration/SlicingQueue.cs +++ b/SlicerConfiguration/SlicingQueue.cs @@ -170,71 +170,75 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (PrinterCommunication.Instance.ActivePrintItem != null && listOfSlicingItems.Count > 0) { PrintItemWrapper itemToSlice = listOfSlicingItems[0]; - itemToSlice.CurrentlySlicing = true; - - string currentConfigurationFileAndPath = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, "config_" + ActiveSliceSettings.Instance.GetHashCode().ToString() + ".ini"); - ActiveSliceSettings.Instance.GenerateConfigFile(currentConfigurationFileAndPath); - - string gcodePathAndFileName = itemToSlice.GCodePathAndFileName; - bool gcodeFileIsComplete = itemToSlice.IsGCodeFileComplete(gcodePathAndFileName); - - if (!File.Exists(gcodePathAndFileName) || !gcodeFileIsComplete) + // check that the STL file is currently on disk + if (File.Exists(itemToSlice.FileLocation)) { - slicerProcess = new Process(); + itemToSlice.CurrentlySlicing = true; - switch (ActivePrinterProfile.Instance.ActiveSliceEngineType) + string currentConfigurationFileAndPath = Path.Combine(ApplicationDataStorage.Instance.GCodeOutputPath, "config_" + ActiveSliceSettings.Instance.GetHashCode().ToString() + ".ini"); + ActiveSliceSettings.Instance.GenerateConfigFile(currentConfigurationFileAndPath); + + string gcodePathAndFileName = itemToSlice.GCodePathAndFileName; + bool gcodeFileIsComplete = itemToSlice.IsGCodeFileComplete(gcodePathAndFileName); + + if (!File.Exists(gcodePathAndFileName) || !gcodeFileIsComplete) { - case ActivePrinterProfile.SlicingEngineTypes.Slic3r: - slicerProcess.StartInfo.Arguments = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; - break; + slicerProcess = new Process(); - case ActivePrinterProfile.SlicingEngineTypes.CuraEngine: - slicerProcess.StartInfo.Arguments = "-v -o \"" + gcodePathAndFileName + "\" " + CuraEngineMappings.GetCuraCommandLineSettings() + " \"" + itemToSlice.PartToSlicePathAndFileName + "\""; - //Debug.Write(slicerProcess.StartInfo.Arguments); - break; - - case ActivePrinterProfile.SlicingEngineTypes.MatterSlice: - slicerProcess.StartInfo.Arguments = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; - break; - } - - string slicerFullPath = getSlicerFullPath(); - - slicerProcess.StartInfo.CreateNoWindow = true; - slicerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - slicerProcess.StartInfo.RedirectStandardError = true; - slicerProcess.StartInfo.RedirectStandardOutput = true; - - slicerProcess.StartInfo.FileName = slicerFullPath; - slicerProcess.StartInfo.UseShellExecute = false; - - slicerProcess.OutputDataReceived += (sender, args) => - { - if (args.Data != null) + switch (ActivePrinterProfile.Instance.ActiveSliceEngineType) { - string message = args.Data; - message = message.Replace("=>", "").Trim(); - if (message.Contains(".gcode")) - { - message = "Saving intermediate file"; - } - message += "..."; - UiThread.RunOnIdle((state) => - { - itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); - }); + case ActivePrinterProfile.SlicingEngineTypes.Slic3r: + slicerProcess.StartInfo.Arguments = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; + break; + + case ActivePrinterProfile.SlicingEngineTypes.CuraEngine: + slicerProcess.StartInfo.Arguments = "-v -o \"" + gcodePathAndFileName + "\" " + CuraEngineMappings.GetCuraCommandLineSettings() + " \"" + itemToSlice.PartToSlicePathAndFileName + "\""; + //Debug.Write(slicerProcess.StartInfo.Arguments); + break; + + case ActivePrinterProfile.SlicingEngineTypes.MatterSlice: + slicerProcess.StartInfo.Arguments = "--load \"" + currentConfigurationFileAndPath + "\" --output \"" + gcodePathAndFileName + "\" \"" + itemToSlice.PartToSlicePathAndFileName + "\""; + break; } - }; - slicerProcess.Start(); + string slicerFullPath = getSlicerFullPath(); - slicerProcess.BeginOutputReadLine(); - string stdError = slicerProcess.StandardError.ReadToEnd(); + slicerProcess.StartInfo.CreateNoWindow = true; + slicerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + slicerProcess.StartInfo.RedirectStandardError = true; + slicerProcess.StartInfo.RedirectStandardOutput = true; - slicerProcess.WaitForExit(); - using (TimedLock.Lock(slicerProcess, "SlicingProcess")) - { - slicerProcess = null; + slicerProcess.StartInfo.FileName = slicerFullPath; + slicerProcess.StartInfo.UseShellExecute = false; + + slicerProcess.OutputDataReceived += (sender, args) => + { + if (args.Data != null) + { + string message = args.Data; + message = message.Replace("=>", "").Trim(); + if (message.Contains(".gcode")) + { + message = "Saving intermediate file"; + } + message += "..."; + UiThread.RunOnIdle((state) => + { + itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); + }); + } + }; + + slicerProcess.Start(); + + slicerProcess.BeginOutputReadLine(); + string stdError = slicerProcess.StandardError.ReadToEnd(); + + slicerProcess.WaitForExit(); + using (TimedLock.Lock(slicerProcess, "SlicingProcess")) + { + slicerProcess = null; + } } }