Skip to content

Commit

Permalink
Merge pull request #26 from avmaisak/kisslicer-fixes
Browse files Browse the repository at this point in the history
Kisslicer fixes
  • Loading branch information
avmaisak authored Nov 22, 2019
2 parents cc83030 + 01136b0 commit 45b7ea4
Show file tree
Hide file tree
Showing 5 changed files with 4,521,098 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/Gcode.Utils/Gcode.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<PackageTags>gcode 3d-printing reprap reprap-3d-printer marlin marlin-firmware repitier repitier-firmware json json-parsing gcode-json cura kisslicer slic3r simplify3d</PackageTags>
<RepositoryType>git</RepositoryType>
<Copyright>Anton Maisak</Copyright>
<AssemblyVersion>0.2.0.11</AssemblyVersion>
<AssemblyVersion>0.2.0.12</AssemblyVersion>
<PackageReleaseNotes></PackageReleaseNotes>
<Version>0.2.11</Version>
<FileVersion>0.2.0.11</FileVersion>
<Version>0.2.12</Version>
<FileVersion>0.2.0.12</FileVersion>
<PackageIconUrl>https://raw.githubusercontent.com/avmaisak/Gcode/master/misc/design/logo/logo.png</PackageIconUrl>
</PropertyGroup>

Expand Down
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 45b7ea4

Please sign in to comment.