Skip to content

Commit

Permalink
fix KISSlicer version 2 a 1.6.3 parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Maisak authored and Anton Maisak committed Nov 22, 2019
1 parent cc83030 commit 22df725
Show file tree
Hide file tree
Showing 4 changed files with 4,521,095 additions and 21 deletions.
52 changes: 32 additions & 20 deletions src/Gcode.Utils/SlicerParser/KisSlicerParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public class KisSlicerParser : SlicerParserBase<KisSlicerInfo>
public override KisSlicerInfo GetSlicerInfo(string[] fileContent)
{
var name = fileContent.FirstOrDefault(x => x.StartsWith("; KISSlicer "));
if (name == null)
{
return null;
}
if (name == null) return null;

var res = new KisSlicerInfo
{
Expand All @@ -25,22 +22,29 @@ public override KisSlicerInfo GetSlicerInfo(string[] fileContent)
Edition = name.Split(';')[1]?.Split('-')[1]?.Trim() ?? string.Empty
};

if (string.IsNullOrWhiteSpace(res.Name))
{
return null;
}
if (string.IsNullOrWhiteSpace(res.Name)) return null;

var buildTimeStr = fileContent.FirstOrDefault(x => x.StartsWith("; Estimated Build Time:"));
if (buildTimeStr != null)
{
res.EstimatedBuildTime = Convert.ToDecimal(buildTimeStr.Trim().Split(':')?[1]?.Split(new[] { "minutes" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim().Replace(".",","));
}
var buildTimeStr = fileContent.FirstOrDefault(x =>
x.StartsWith("; Estimated Build Time:") ||
x.StartsWith("; Estimated-in-GUI Build Time")
);

var buildCostStr = fileContent.FirstOrDefault(x => x.StartsWith("; Estimated Build Cost:"));
if (buildCostStr != null)
{
res.EstimatedBuildCost = Convert.ToDecimal(buildCostStr.Split('$')?[1]?.Trim().Replace(".",","));
}
if (buildTimeStr != null) res.EstimatedBuildTime =
Convert.ToDecimal(
buildTimeStr
.Trim()
.Split(':')?[1]?
.Split(new[] { "minutes" }, StringSplitOptions.RemoveEmptyEntries)[0]
.Trim()
.Replace(".",",")
);

var buildCostStr = fileContent.FirstOrDefault(x =>
x.StartsWith("; Estimated Build Cost:") ||
x.StartsWith("; Estimated-in-GUI Build Cost")
);

if (buildCostStr != null) res.EstimatedBuildCost = Convert.ToDecimal(buildCostStr.Split('$')?[1]?.Trim().Replace(".",","));

var totalEstimatedPreCoolMinutes = fileContent.FirstOrDefault(x => x.StartsWith("; Total estimated (pre-cool) minutes:"));
if (totalEstimatedPreCoolMinutes != null)
Expand All @@ -51,7 +55,11 @@ public override KisSlicerInfo GetSlicerInfo(string[] fileContent)
var filamentUsageExist = fileContent.FirstOrDefault(x => x.StartsWith("; Filament used per extruder:")) != null;
if (filamentUsageExist)
{
var filamentUsageExt1 = fileContent.FirstOrDefault(x => x.StartsWith("; Ext 1 = "));
var filamentUsageExt1 = fileContent.FirstOrDefault(x =>
x.StartsWith("; Ext 1 = ") ||
x.StartsWith("; Ext #1 =")
);

if (filamentUsageExt1 != null)
{
filamentUsageExt1 = filamentUsageExt1.TrimString();
Expand All @@ -73,7 +81,11 @@ public override KisSlicerInfo GetSlicerInfo(string[] fileContent)
);
}

var filamentUsageExt2 = fileContent.FirstOrDefault(x => x.StartsWith("; Ext 2 = "));
var filamentUsageExt2 = fileContent.FirstOrDefault(x =>
x.StartsWith("; Ext 2 = ") ||
x.StartsWith("; Ext #2 =")
);

if (filamentUsageExt2 != null)
{
res.FilamentUsedExtruder2 = Convert.ToDecimal(
Expand Down
Loading

0 comments on commit 22df725

Please sign in to comment.