Merge pull request #3411 from larsbrubaker/design_tools
Find the filament diameter in our gcode files
This commit is contained in:
commit
4e34512041
2 changed files with 22 additions and 5 deletions
|
|
@ -141,7 +141,7 @@ namespace MatterControl.Printing
|
|||
|
||||
public static bool GetFirstNumberAfter(string stringToCheckAfter, string stringWithNumber, ref double readValue, int startIndex = 0, string stopCheckingString = ";")
|
||||
{
|
||||
int stringPos = stringWithNumber.IndexOf(stringToCheckAfter, startIndex);
|
||||
int stringPos = stringWithNumber.IndexOf(stringToCheckAfter, Math.Min(stringWithNumber.Length, startIndex));
|
||||
int stopPos = stringWithNumber.IndexOf(stopCheckingString);
|
||||
if (stringPos != -1
|
||||
&& (stopPos == -1 || stringPos < stopPos || string.IsNullOrEmpty(stopCheckingString)))
|
||||
|
|
|
|||
|
|
@ -882,22 +882,24 @@ namespace MatterControl.Printing
|
|||
{
|
||||
if (filamentDiameterCache == 0)
|
||||
{
|
||||
for (int i = 0; i < Math.Min(20, GCodeCommandQueue.Count); i++)
|
||||
// check the beginning of the file for the filament diameter
|
||||
for (int i = 0; i < Math.Min(100, GCodeCommandQueue.Count); i++)
|
||||
{
|
||||
if (GetFirstNumberAfter("filamentDiameter =", GCodeCommandQueue[i].Line, ref filamentDiameterCache))
|
||||
if(FindDiameter(i, ref filamentDiameterCache))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check the end of the file for the filament diameter
|
||||
if (filamentDiameterCache == 0)
|
||||
{
|
||||
// didn't find it, so look at the end of the file for filament_diameter =
|
||||
string lookFor = "; filament_diameter =";// 2.85
|
||||
for (int i = GCodeCommandQueue.Count - 1; i > Math.Max(0, GCodeCommandQueue.Count - 100); i--)
|
||||
{
|
||||
if (GetFirstNumberAfter(lookFor, GCodeCommandQueue[i].Line, ref filamentDiameterCache))
|
||||
if (FindDiameter(i, ref filamentDiameterCache))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -912,6 +914,21 @@ namespace MatterControl.Printing
|
|||
return filamentDiameterCache;
|
||||
}
|
||||
|
||||
private bool FindDiameter(int lineIndex, ref double filamentDiameterCache)
|
||||
{
|
||||
if (GetFirstNumberAfter("filamentDiameter = ", GCodeCommandQueue[lineIndex].Line, ref filamentDiameterCache, 0, ""))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GetFirstNumberAfter("; filament_diameter = ", GCodeCommandQueue[lineIndex].Line, ref filamentDiameterCache, 0, ""))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override double GetLayerHeight(int layerIndex)
|
||||
{
|
||||
if (layerHeights.Count > 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue