Fixing some errors with exporting gcode to a folder when the STL not present.

This commit is contained in:
larsbrubaker 2014-03-05 13:45:07 -08:00
parent 9238fbdf97
commit 26d2730516
3 changed files with 91 additions and 68 deletions

View file

@ -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;

View file

@ -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));

View file

@ -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;
}
}
}