From 1ea416294862abe5aabc2d569bb0020282aeb588 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Tue, 4 Mar 2014 13:42:30 -0800 Subject: [PATCH 1/4] the interface in gcode changed and this is just to keep in synch with it. --- PrinterCommunication.cs | 24 ++++++++++++------------ PrinterControls/PrintLeveling.cs | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/PrinterCommunication.cs b/PrinterCommunication.cs index 771105bb1..bd6329279 100644 --- a/PrinterCommunication.cs +++ b/PrinterCommunication.cs @@ -823,18 +823,18 @@ namespace MatterHackers.MatterControl string lineToParse = foundStringEventArgs.LineToCheck; Vector3 positionRead = Vector3.Zero; - GCodeFile.GetFirstNumberAfter("X:", lineToParse, ref positionRead.x); - GCodeFile.GetFirstNumberAfter("Y:", lineToParse, ref positionRead.y); - GCodeFile.GetFirstNumberAfter("Z:", lineToParse, ref positionRead.z); + GCodeFile.GetFirstNumberAfter('X', lineToParse, ref positionRead.x); + GCodeFile.GetFirstNumberAfter('Y', lineToParse, ref positionRead.y); + GCodeFile.GetFirstNumberAfter('Z', lineToParse, ref positionRead.z); int xPosition = lineToParse.IndexOf('X'); int secondXPosition = lineToParse.IndexOf("Count", xPosition); if (secondXPosition != -1) { Vector3 currentPositionRead = Vector3.Zero; - GCodeFile.GetFirstNumberAfter("X:", lineToParse, ref currentPositionRead.x, secondXPosition - 1); - GCodeFile.GetFirstNumberAfter("Y:", lineToParse, ref currentPositionRead.y, secondXPosition - 1); - GCodeFile.GetFirstNumberAfter("Z:", lineToParse, ref currentPositionRead.z, secondXPosition - 1); + GCodeFile.GetFirstNumberAfter('X', lineToParse, ref currentPositionRead.x, secondXPosition - 1); + GCodeFile.GetFirstNumberAfter('Y', lineToParse, ref currentPositionRead.y, secondXPosition - 1); + GCodeFile.GetFirstNumberAfter('Z', lineToParse, ref currentPositionRead.z, secondXPosition - 1); lastReportedPosition = currentPositionRead; } @@ -1289,9 +1289,9 @@ namespace MatterHackers.MatterControl newDestination = Vector3.Zero; } - GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref newDestination.x); - GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref newDestination.y); - GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref newDestination.z); + GCodeFile.GetFirstNumberAfter('X', lineBeingSent, ref newDestination.x); + GCodeFile.GetFirstNumberAfter('Y', lineBeingSent, ref newDestination.y); + GCodeFile.GetFirstNumberAfter('Z', lineBeingSent, ref newDestination.z); if (movementMode == PrinterMachineInstruction.MovementTypes.Relative) { @@ -1318,7 +1318,7 @@ namespace MatterHackers.MatterControl lineBeingSent = lineBeingSent.ToUpper().Trim(); if (lineBeingSent.StartsWith("G0") || lineBeingSent.StartsWith("G1")) { - if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition)) + if (GCodeFile.GetFirstNumberAfter('E', lineBeingSent, ref gcodeRequestedExtrusionPosition)) { double delta = gcodeRequestedExtrusionPosition - previousGcodeRequestedExtrusionPosition; if (extruderMode == PrinterMachineInstruction.MovementTypes.Relative) @@ -1333,7 +1333,7 @@ namespace MatterHackers.MatterControl } else if (lineBeingSent.StartsWith("G92")) { - if (GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref gcodeRequestedExtrusionPosition)) + if (GCodeFile.GetFirstNumberAfter('E', lineBeingSent, ref gcodeRequestedExtrusionPosition)) { previousGcodeRequestedExtrusionPosition = gcodeRequestedExtrusionPosition; currentActualExtrusionPosition = gcodeRequestedExtrusionPosition; @@ -1351,7 +1351,7 @@ namespace MatterHackers.MatterControl if (lineBeingSent.StartsWith("G0") || lineBeingSent.StartsWith("G1")) { double feedRate = 0; - if (GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate)) + if (GCodeFile.GetFirstNumberAfter('F', lineBeingSent, ref feedRate)) { lineBeingSent = GCodeFile.ReplaceNumberAfter('F', lineBeingSent, feedRate * FeedRateRatio); } diff --git a/PrinterControls/PrintLeveling.cs b/PrinterControls/PrintLeveling.cs index 1e118182b..5c7de53bb 100644 --- a/PrinterControls/PrintLeveling.cs +++ b/PrinterControls/PrintLeveling.cs @@ -85,9 +85,9 @@ namespace MatterHackers.MatterControl && lineBeingSent[2] == ' ') { double extruderDelta = 0; - GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref extruderDelta); + GCodeFile.GetFirstNumberAfter('E', lineBeingSent, ref extruderDelta); double feedRate = 0; - GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref feedRate); + GCodeFile.GetFirstNumberAfter('F', lineBeingSent, ref feedRate); string newLine = "G1 "; @@ -97,9 +97,9 @@ namespace MatterHackers.MatterControl if (movementMode == PrinterMachineInstruction.MovementTypes.Relative) { Vector3 relativeMove = Vector3.Zero; - GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref relativeMove.x); - GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref relativeMove.y); - GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref relativeMove.z); + GCodeFile.GetFirstNumberAfter('X', lineBeingSent, ref relativeMove.x); + GCodeFile.GetFirstNumberAfter('Y', lineBeingSent, ref relativeMove.y); + GCodeFile.GetFirstNumberAfter('Z', lineBeingSent, ref relativeMove.z); outPosition = PrintLeveling.Instance.ApplyLevelingRotation(relativeMove); } From a035aed52eeef4d705cb80453b4559aaccd6b960 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Wed, 5 Mar 2014 12:00:37 -0800 Subject: [PATCH 2/4] Fixed a bug with export to folder not working if done a second time. Made the slicing queue report its status on the uithread. --- PrintQueue/PrintQueueMenu.cs | 74 ++++++----------------------- SlicerConfiguration/SlicingQueue.cs | 12 +++-- 2 files changed, 23 insertions(+), 63 deletions(-) diff --git a/PrintQueue/PrintQueueMenu.cs b/PrintQueue/PrintQueueMenu.cs index 36ce1daeb..f186488d2 100644 --- a/PrintQueue/PrintQueueMenu.cs +++ b/PrintQueue/PrintQueueMenu.cs @@ -22,9 +22,7 @@ namespace MatterHackers.MatterControl.PrintQueue public DropDownMenu MenuDropList; private TupleList> menuItems; - - ExportToFolderFeedbackWindow exportingWindow; - bool exportingWindowIsOpen = false; + ExportToFolderFeedbackWindow exportingWindow = null; public PrintQueueMenu() { @@ -66,7 +64,6 @@ namespace MatterHackers.MatterControl.PrintQueue {new LocalizedString(" Export to Zip").Translated, exportQueueToZipMenu_Click}, {"GCode", null}, {new LocalizedString(" Export to Folder").Translated, exportGCodeToFolderButton_Click}, - //{" Export to SD Card", exportToSDCardButton_Click}, {new LocalizedString("Extra").Translated, null}, {new LocalizedString(" Create Part Sheet").Translated, createPartsSheetsButton_Click}, }; @@ -142,31 +139,11 @@ namespace MatterHackers.MatterControl.PrintQueue return true; } - - private void OpenExportWindow(List parts) - { - if (this.exportingWindowIsOpen == false) - { - exportingWindow = new ExportToFolderFeedbackWindow(parts.Count, parts [0].Name, ActiveTheme.Instance.PrimaryBackgroundColor); - this.exportingWindowIsOpen = true; - exportingWindow.Closed += new EventHandler(ExportToFolderFeedbackWindow_Closed); - } - else - { - if (exportingWindow != null) - { - exportingWindow.BringToFront(); - } - } - } - - void ExportToFolderFeedbackWindow_Closed(object sender, EventArgs e) { - this.exportingWindowIsOpen = false; + this.exportingWindow = null; } - private void SelectLocationToExportGCode(object state) { SelectFolderDialogParams selectParams = new SelectFolderDialogParams("Select Location To Save Files"); @@ -179,8 +156,18 @@ namespace MatterHackers.MatterControl.PrintQueue List parts = PrintQueueControl.Instance.CreateReadOnlyPartList(); if (parts.Count > 0) { - OpenExportWindow (parts); - ExportToFolderProcess exportToFolderProcess = new ExportToFolderProcess(parts, path); + if (exportingWindow == null) + { + exportingWindow = new ExportToFolderFeedbackWindow(parts.Count, parts[0].Name, ActiveTheme.Instance.PrimaryBackgroundColor); + exportingWindow.Closed += new EventHandler(ExportToFolderFeedbackWindow_Closed); + exportingWindow.ShowAsSystemWindow(); + } + else + { + exportingWindow.BringToFront(); + } + + ExportToFolderProcess exportToFolderProcess = new ExportToFolderProcess(parts, path); exportToFolderProcess.StartingNextPart += exportingWindow.StartingNextPart; exportToFolderProcess.UpdatePartStatus += exportingWindow.UpdatePartStatus; exportToFolderProcess.DoneSaving += exportingWindow.DoneSaving; @@ -189,39 +176,6 @@ namespace MatterHackers.MatterControl.PrintQueue } } - bool exportToSDCardButton_Click() - { - UiThread.RunOnIdle(ExportToSDCardButtonOnIdle); - return true; - } - - void ExportToSDCardButtonOnIdle(object state) - { - if (!PrinterCommunication.Instance.PrinterIsConnected) - { - StyledMessageBox.ShowMessageBox("You must connect to a printer before you can export to the printers SD Card.", "You must connect to a printer"); - } - else - { - string message = string.Format("Do you want to save your entire queue to the printers SD Card? This can be a lengthy process"); - if (StyledMessageBox.ShowMessageBox(message, "Save to SD Card", StyledMessageBox.MessageType.YES_NO)) - { - List parts = PrintQueueControl.Instance.CreateReadOnlyPartList(); - if (parts.Count > 0) - { - ExportToSdCardFeedbackWindow exportingWindow = new ExportToSdCardFeedbackWindow(parts.Count, parts[0].Name, ActiveTheme.Instance.PrimaryBackgroundColor); - exportingWindow.ShowAsSystemWindow(); - - ExportToSdCardProcess exportToSdCardProcess = new ExportToSdCardProcess(parts); - exportToSdCardProcess.StartingNextPart += exportingWindow.StartingNextPart; - exportToSdCardProcess.UpdatePartStatus += exportingWindow.UpdatePartStatus; - exportToSdCardProcess.DoneSaving += exportingWindow.DoneSaving; - exportToSdCardProcess.Start(); - } - } - } - } - bool exportQueueToZipMenu_Click() { UiThread.RunOnIdle(ExportQueueToZipOnIdle); diff --git a/SlicerConfiguration/SlicingQueue.cs b/SlicerConfiguration/SlicingQueue.cs index 2660f9492..6215c4ff5 100644 --- a/SlicerConfiguration/SlicingQueue.cs +++ b/SlicerConfiguration/SlicingQueue.cs @@ -219,7 +219,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration message = "Saving intermediate file"; } message += "..."; - itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); + UiThread.RunOnIdle((state) => + { + itemToSlice.OnSlicingOutputMessage(new StringEventArgs(message)); + }); } }; @@ -235,8 +238,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } - itemToSlice.CurrentlySlicing = false; - itemToSlice.DoneSlicing = true; + UiThread.RunOnIdle((state) => + { + itemToSlice.CurrentlySlicing = false; + itemToSlice.DoneSlicing = true; + }); using (TimedLock.Lock(listOfSlicingItems, "CreateSlicedPartsThread()")) { From 5e96cc9b5db1b006f733f741c8c1c2f35728d290 Mon Sep 17 00:00:00 2001 From: Kevin Pope Date: Wed, 5 Mar 2014 12:16:52 -0800 Subject: [PATCH 3/4] Added named widget to ManualPrinterControls Added firmware check to PrinterCommunication Added event hook to MainSlidePanel for reload of Advanced Controls --- MainSlidePanel.cs | 17 +++++++++++++++- PrinterCommunication.cs | 25 +++++++++++++++++++++++- PrinterControls/ManualPrinterControls.cs | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/MainSlidePanel.cs b/MainSlidePanel.cs index 84f502ffc..7205a3b06 100644 --- a/MainSlidePanel.cs +++ b/MainSlidePanel.cs @@ -65,6 +65,7 @@ namespace MatterHackers.MatterControl public TabPage AboutTabPage; TextImageButtonFactory advancedControlsButtonFactory = new TextImageButtonFactory(); RGBA_Bytes unselectedTextColor = ActiveTheme.Instance.TabLabelUnselected; + public EventHandler AdvancedControlsLoaded; GuiWidget LeftPanel { @@ -211,6 +212,14 @@ namespace MatterHackers.MatterControl //Empty function used as placeholder } + void OnAdvancedControlsLoaded() + { + if (AdvancedControlsLoaded != null) + { + AdvancedControlsLoaded(this, null); + } + } + SliceSettingsWidget.UiState sliceSettingsUiState; void DoChangePanel(object state) { @@ -220,7 +229,9 @@ namespace MatterHackers.MatterControl // remove the advance control and replace it with new ones build for the selected printer int advancedControlsWidgetIndex = RightPanel.GetChildIndex(this.advancedControlsTabControl); RightPanel.RemoveChild(advancedControlsWidgetIndex); - this.advancedControlsTabControl = CreateNewAdvancedControlsTab(sliceSettingsUiState); + + this.advancedControlsTabControl = CreateNewAdvancedControlsTab(sliceSettingsUiState); + RightPanel.AddChild(this.advancedControlsTabControl, advancedControlsWidgetIndex); // set the selected tab back to the one it was before we replace the control @@ -231,6 +242,8 @@ namespace MatterHackers.MatterControl RectangleDouble localBounds = this.LocalBounds; this.LocalBounds = new RectangleDouble(0, 0, this.LocalBounds.Width - 1, 10); this.LocalBounds = localBounds; + OnAdvancedControlsLoaded(); + } TabControl CreateNewAdvancedControlsTab(SliceSettingsWidget.UiState sliceSettingsUiState) @@ -266,6 +279,8 @@ namespace MatterHackers.MatterControl advancedControls.AddTab(new SimpleTextTabWidget(new TabPage(sliceSettingsWidget, new LocalizedString("Slice Settings").Translated), 18, ActiveTheme.Instance.PrimaryTextColor, new RGBA_Bytes(), unselectedTextColor, new RGBA_Bytes())); + + return advancedControls; } diff --git a/PrinterCommunication.cs b/PrinterCommunication.cs index bd6329279..c32762163 100644 --- a/PrinterCommunication.cs +++ b/PrinterCommunication.cs @@ -106,6 +106,12 @@ namespace MatterHackers.MatterControl get { return firmwareType; } } + string firmwareVersion; + public string FirmwareVersion + { + get { return firmwareVersion; } + } + static PrinterCommunication globalInstance; string connectionFailureMessage = "Unknown Reason"; @@ -124,6 +130,7 @@ namespace MatterHackers.MatterControl public RootedObjectEventHandler ExtruderTemperatureRead = new RootedObjectEventHandler(); public RootedObjectEventHandler ExtruderTemperatureSet = new RootedObjectEventHandler(); public RootedObjectEventHandler FanSpeedSet = new RootedObjectEventHandler(); + public RootedObjectEventHandler FirmwareVersionRead = new RootedObjectEventHandler(); public RootedObjectEventHandler PrintFinished = new RootedObjectEventHandler(); public RootedObjectEventHandler PositionRead = new RootedObjectEventHandler(); public RootedObjectEventHandler ReadLine = new RootedObjectEventHandler(); @@ -531,7 +538,7 @@ namespace MatterHackers.MatterControl { return CommunicationState == CommunicationStates.Paused; } - } + } int NumberOfLinesInCurrentPrint { @@ -965,6 +972,16 @@ namespace MatterHackers.MatterControl firmwareType = FirmwareTypes.Sprinter; } } + string firmwareVersionReported = ""; + if (GCodeFile.GetFirstStringAfter("PROTOCOL_VERSION:", foundStringEventArgs.LineToCheck, " ", ref firmwareVersionReported)) + { + //Firmware version was detected and is different + if (firmwareVersionReported != "" && firmwareVersion != firmwareVersionReported) + { + firmwareVersion = firmwareVersionReported; + OnFirmwareVersionRead(null); + } + } } public void FoundStart(object sender, EventArgs e) @@ -1076,6 +1093,7 @@ namespace MatterHackers.MatterControl CommunicationState = CommunicationStates.AttemptingToConnect; this.stopTryingToConnect = false; firmwareType = FirmwareTypes.Unknown; + firmwareVersion = null; if (SerialPortIsAvailable(this.ActivePrinter.ComPort)) { @@ -1244,6 +1262,11 @@ namespace MatterHackers.MatterControl PrintFinished.CallEvents(this, new PrintItemWrapperEventArgs(this.ActivePrintItem)); } + void OnFirmwareVersionRead(EventArgs e) + { + FirmwareVersionRead.CallEvents(this, e); + } + void OnExtruderTemperatureRead(EventArgs e) { ExtruderTemperatureRead.CallEvents(this, e); diff --git a/PrinterControls/ManualPrinterControls.cs b/PrinterControls/ManualPrinterControls.cs index 79330bc5a..81753a280 100644 --- a/PrinterControls/ManualPrinterControls.cs +++ b/PrinterControls/ManualPrinterControls.cs @@ -198,6 +198,7 @@ namespace MatterHackers.MatterControl FlowLayoutWidget controlsTopToBottomLayout = new FlowLayoutWidget(FlowDirection.TopToBottom); controlsTopToBottomLayout.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; controlsTopToBottomLayout.VAnchor = Agg.UI.VAnchor.FitToChildren; + controlsTopToBottomLayout.Name = "ManualPrinterControls.ControlsContainer"; controlsTopToBottomLayout.Padding = new BorderDouble(3, 0); From 26d2730516b00d8fd3cbe430599e1100dcb2493f Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Wed, 5 Mar 2014 13:45:07 -0800 Subject: [PATCH 4/4] 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; + } } }