Discard GCodeFileIsComplete logic

This commit is contained in:
John Lewin 2017-06-30 12:22:24 -07:00
parent 50957e856b
commit 7fdae3bfe5
3 changed files with 8 additions and 45 deletions

View file

@ -239,7 +239,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (File.Exists(printItem.FileLocation))
{
string gcodePathAndFileName = printItem.GetGCodePathAndFileName();
bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName);
if (printItem.SlicingHadError)
{
@ -250,7 +249,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
firstProcessingMessage = pressGenerateMessage;
}
if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete)
if (File.Exists(gcodePathAndFileName))
{
gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName));
}

View file

@ -278,42 +278,9 @@ namespace MatterHackers.MatterControl.PrintQueue
}
}
public bool IsGCodeFileComplete(string gcodePathAndFileName)
{
if (Path.GetExtension(FileLocation).ToUpper() == ".GCODE")
{
return true;
}
bool gCodeFileIsComplete = false;
if (File.Exists(gcodePathAndFileName))
{
string gcodeFileContents = "";
using (FileStream fileStream = new FileStream(gcodePathAndFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader gcodeStreamReader = new StreamReader(fileStream))
{
gcodeFileContents = gcodeStreamReader.ReadToEnd();
}
}
// check if there is a known line at the end of the file (this will let us know if slicer finished building the file).
if (gcodeFileContents.Contains("filament used ="))
{
gCodeFileIsComplete = true;
}
}
return gCodeFileIsComplete;
}
public void OnSlicingOutputMessage(EventArgs e)
{
StringEventArgs message = e as StringEventArgs;
if (SlicingOutputMessage != null)
{
SlicingOutputMessage(this, message);
}
SlicingOutputMessage?.Invoke(this, e as StringEventArgs);
}
}
}

View file

@ -348,14 +348,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
itemCurrentlySlicing = itemToSlice;
MatterHackers.MatterSlice.LogOutput.GetLogWrites += SendProgressToItem;
SliceFile(itemToSlice.FileLocation, gcodeFilePath, itemToSlice.IsGCodeFileComplete(gcodeFilePath), reporter);
SliceFile(itemToSlice.FileLocation, gcodeFilePath, reporter);
MatterHackers.MatterSlice.LogOutput.GetLogWrites -= SendProgressToItem;
itemCurrentlySlicing = null;
}
else
{
SliceFile(itemToSlice.FileLocation, gcodeFilePath, itemToSlice.IsGCodeFileComplete(gcodeFilePath), reporter);
SliceFile(itemToSlice.FileLocation, gcodeFilePath, reporter);
}
}
@ -382,30 +382,27 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
await Task.Run(() => SliceFile(
printItem.FileLocation,
gcodeFilePath,
printItem.IsGCodeFileComplete(gcodeFilePath),
progressReporter));
}
public static async Task SliceFileAsync(string sourceFile, string gcodeFilePath, bool gcodeFileIsComplete, IProgress<string> progressReporter)
public static async Task SliceFileAsync(string sourceFile, string gcodeFilePath, IProgress<string> progressReporter)
{
await Task.Run(() => SliceFile(sourceFile, gcodeFilePath, gcodeFileIsComplete, progressReporter));
await Task.Run(() => SliceFile(sourceFile, gcodeFilePath, progressReporter));
}
private static void SliceFile(string sourceFile, string gcodeFilePath, bool gcodeFileIsComplete, IProgress<string> progressReporter)
private static void SliceFile(string sourceFile, string gcodeFilePath, IProgress<string> progressReporter)
{
string mergeRules = "";
string[] stlFileLocations = GetStlFileLocations(sourceFile, ref mergeRules);
string fileToSlice = stlFileLocations[0];
// check that the STL file is currently on disk
if (File.Exists(fileToSlice))
{
string configFilePath = Path.Combine(
ApplicationDataStorage.Instance.GCodeOutputPath,
string.Format("config_{0}.ini", ActiveSliceSettings.Instance.GetLongHashCode().ToString()));
if (!File.Exists(gcodeFilePath) || !gcodeFileIsComplete)
if (!File.Exists(gcodeFilePath))
{
string commandArgs;