From 0b4fad709c8f43ce1e1f62b0ac1967d2a5f85a4d Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 16 Dec 2014 16:35:56 -0800 Subject: [PATCH] Made it so we only heat up the extruders that will be printing. Including checking for support and raft extruders. --- PrinterCommunication/ActivePrinterProfile.cs | 3 +- SlicerConfiguration/ActiveSliceSettings.cs | 32 ++++++++++++ .../SlicerMapping/MappingClasses.cs | 51 +++++++++++++------ SlicerConfiguration/SlicingQueue.cs | 34 +++++++++++-- 4 files changed, 100 insertions(+), 20 deletions(-) diff --git a/PrinterCommunication/ActivePrinterProfile.cs b/PrinterCommunication/ActivePrinterProfile.cs index 1a6282cd4..652657a2d 100644 --- a/PrinterCommunication/ActivePrinterProfile.cs +++ b/PrinterCommunication/ActivePrinterProfile.cs @@ -186,7 +186,8 @@ namespace MatterHackers.MatterControl public int GetMaterialSetting(int extruderPosition) { int i = 0; - if (ActivePrinter != null) + if (extruderPosition > 0 + && ActivePrinter != null) { string materialSettings = ActivePrinter.MaterialCollectionIds; string[] materialSettingsList; diff --git a/SlicerConfiguration/ActiveSliceSettings.cs b/SlicerConfiguration/ActiveSliceSettings.cs index 3b22c1040..7e5af5d0f 100644 --- a/SlicerConfiguration/ActiveSliceSettings.cs +++ b/SlicerConfiguration/ActiveSliceSettings.cs @@ -248,6 +248,38 @@ namespace MatterHackers.MatterControl.SlicerConfiguration return GetActiveValue("has_heated_bed") == "1"; } + public bool SupportEnabled + { + get + { + return GetActiveValue("support_material") == "1"; + } + } + + public int SupportExtruder + { + get + { + return int.Parse(GetActiveValue("support_material_extruder")); + } + } + + public bool RaftEnabled + { + get + { + return GetActiveValue("create_raft") == "1"; + } + } + + public int RaftExtruder + { + get + { + return int.Parse(GetActiveValue("raft_extruder")); + } + } + public Dictionary DefaultSettings { get diff --git a/SlicerConfiguration/SlicerMapping/MappingClasses.cs b/SlicerConfiguration/SlicerMapping/MappingClasses.cs index cce08dd37..c81d8acbc 100644 --- a/SlicerConfiguration/SlicerMapping/MappingClasses.cs +++ b/SlicerConfiguration/SlicerMapping/MappingClasses.cs @@ -100,14 +100,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration get { StringBuilder newStartGCode = new StringBuilder(); - foreach (string line in PreStartGCode()) + foreach (string line in PreStartGCode(SlicingQueue.extrudersUsed)) { newStartGCode.Append(line + "\n"); } newStartGCode.Append(GCodeProcessing.ReplaceMacroValues(base.MappedValue)); - foreach (string line in PostStartGCode()) + foreach (string line in PostStartGCode(SlicingQueue.extrudersUsed)) { newStartGCode.Append("\n"); newStartGCode.Append(line); @@ -128,7 +128,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration this.replaceCRs = replaceCRs; } - public List PreStartGCode() + public List PreStartGCode(List extrudersUsed) { string startGCode = ActiveSliceSettings.Instance.GetActiveValue("start_gcode"); string[] preStartGCodeLines = startGCode.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries); @@ -153,22 +153,39 @@ namespace MatterHackers.MatterControl.SlicerConfiguration for (int i = 0; i < numberOfHeatedExtruders; i++) { - string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", i + 1); - if (materialTemperature != "0") + if (extrudersUsed.Count > i + && extrudersUsed[i]) { - string setTempString = "M104 T{0} S{1}".FormatWith(i, materialTemperature); - AddDefaultIfNotPresent(preStartGCode, setTempString, preStartGCodeLines, string.Format("wait for extruder {0} temperature", i + 1)); + string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", i); + if (materialTemperature != "0") + { + string setTempString = "M104 T{0} S{1}".FormatWith(i, materialTemperature); + AddDefaultIfNotPresent(preStartGCode, setTempString, preStartGCodeLines, string.Format("start heating extruder {0}", i)); + } } } - // make sure we are on extruder 0 - AddDefaultIfNotPresent(preStartGCode, "T0", preStartGCodeLines, "set the active extruder to 0"); + SwitchToFirstActiveExtruder(extrudersUsed, preStartGCodeLines, preStartGCode); preStartGCode.Add("; settings from start_gcode"); return preStartGCode; } - public List PostStartGCode() + private void SwitchToFirstActiveExtruder(List extrudersUsed, string[] preStartGCodeLines, List preStartGCode) + { + // make sure we are on the first active extruder + for (int i = 0; i < extrudersUsed.Count; i++) + { + if (extrudersUsed[i]) + { + // set the active extruder to the first one that will be printing + AddDefaultIfNotPresent(preStartGCode, "T{0}".FormatWith(i), preStartGCodeLines, "set the active extruder to {0}".FormatWith(i)); + break; // then break so we don't set it to a different ones + } + } + } + + public List PostStartGCode(List extrudersUsed) { string startGCode = ActiveSliceSettings.Instance.GetActiveValue("start_gcode"); string[] postStartGCodeLines = startGCode.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries); @@ -184,15 +201,19 @@ namespace MatterHackers.MatterControl.SlicerConfiguration for (int i = 0; i < numberOfHeatedExtruders; i++) { - string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature",i+1); - if (materialTemperature != "0") + if (extrudersUsed.Count > i + && extrudersUsed[i]) { - string setTempString = "M109 T{0} S{1}".FormatWith(i, materialTemperature); - AddDefaultIfNotPresent(postStartGCode, setTempString, postStartGCodeLines, string.Format("wait for extruder {0} temperature", i+1) ); + string materialTemperature = ActiveSliceSettings.Instance.GetMaterialValue("temperature", i + 1); + if (materialTemperature != "0") + { + string setTempString = "M109 T{0} S{1}".FormatWith(i, materialTemperature); + AddDefaultIfNotPresent(postStartGCode, setTempString, postStartGCodeLines, string.Format("wait for extruder {0} to reach temperature", i)); + } } } - AddDefaultIfNotPresent(postStartGCode, "T0", postStartGCodeLines, "set the active extruder to 0"); + SwitchToFirstActiveExtruder(extrudersUsed, postStartGCodeLines, postStartGCode); AddDefaultIfNotPresent(postStartGCode, "G90", postStartGCodeLines, "use absolute coordinates"); postStartGCode.Add(string.Format("{0} ; {1}", "G92 E0", "reset the expected extruder position")); AddDefaultIfNotPresent(postStartGCode, "M82", postStartGCodeLines, "use absolute distance for extrusion"); diff --git a/SlicerConfiguration/SlicingQueue.cs b/SlicerConfiguration/SlicingQueue.cs index 1ff36af75..ac8a51552 100644 --- a/SlicerConfiguration/SlicingQueue.cs +++ b/SlicerConfiguration/SlicingQueue.cs @@ -158,13 +158,37 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } + public static List extrudersUsed = new List(); + public static string[] GetStlFileLocations(string fileToSlice) { + extrudersUsed.Clear(); + int extruderCount = ActiveSliceSettings.Instance.ExtruderCount; + for(int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++) + { + extrudersUsed.Add(false); + } + + // If we have support enabled and and are using an extruder other than 0 for it + if (ActiveSliceSettings.Instance.SupportEnabled) + { + int supportExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.ExtruderCount - 1, ActiveSliceSettings.Instance.SupportExtruder - 1)); + extrudersUsed[supportExtruder] = true; + } + + // If we have raft enabled and are using an extruder other than 0 for it + if (ActiveSliceSettings.Instance.RaftEnabled) + { + int raftExtruder = Math.Max(0, Math.Min(ActiveSliceSettings.Instance.ExtruderCount - 1, ActiveSliceSettings.Instance.RaftExtruder - 1)); + extrudersUsed[raftExtruder] = true; + } + switch (Path.GetExtension(fileToSlice).ToUpper()) { case ".STL": case ".GCODE": + extrudersUsed.Add(true); return new string[] { fileToSlice }; case ".AMF": @@ -175,19 +199,21 @@ namespace MatterHackers.MatterControl.SlicerConfiguration extruderMeshGroups.Add(new MeshGroup()); } int maxExtruderIndex = 0; - foreach (MeshGroup meshGroup in meshGroups) - { + foreach(MeshGroup meshGroup in meshGroups) + { foreach (Mesh mesh in meshGroup.Meshes) { MeshMaterialData material = MeshMaterialData.Get(mesh); - int extruderIndex = Math.Max(0, material.MaterialIndex-1); + int extruderIndex = Math.Max(0, material.MaterialIndex - 1); maxExtruderIndex = Math.Max(maxExtruderIndex, extruderIndex); - if(extruderIndex >= extruderCount) + if (extruderIndex >= extruderCount) { + extrudersUsed[0] = true; extruderMeshGroups[0].Meshes.Add(mesh); } else { + extrudersUsed[extruderIndex] = true; extruderMeshGroups[extruderIndex].Meshes.Add(mesh); } }