Merge pull request #129 from larsbrubaker/development

Development
This commit is contained in:
Lars Brubaker 2014-12-16 16:40:16 -08:00
commit 1f53fb7632
4 changed files with 100 additions and 20 deletions

View file

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

View file

@ -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<string, DataStorage.SliceSetting> DefaultSettings
{
get

View file

@ -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<string> PreStartGCode()
public List<string> PreStartGCode(List<bool> 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<string> PostStartGCode()
private void SwitchToFirstActiveExtruder(List<bool> extrudersUsed, string[] preStartGCodeLines, List<string> 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<string> PostStartGCode(List<bool> 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");

View file

@ -158,13 +158,37 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
public static List<bool> extrudersUsed = new List<bool>();
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);
}
}