Skip to content

Commit

Permalink
Merge pull request #23 from avmaisak/dev
Browse files Browse the repository at this point in the history
added KisSlicerParser
  • Loading branch information
avmaisak authored Apr 23, 2019
2 parents 05f9801 + bd68a34 commit 03db5df
Show file tree
Hide file tree
Showing 9 changed files with 2,018,299 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/Gcode.Utils/Entity/KisslicerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Gcode.Utils.Entity
{
/// <summary>
/// Gcode, generated by Kisslicer information.
/// </summary>
public class KisSlicerInfo: SlicerInfo
{
}
}
49 changes: 49 additions & 0 deletions src/Gcode.Utils/Entity/SlicerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace Gcode.Utils.Entity
{
/// <summary>
/// Slicer info.
/// </summary>
public class SlicerInfo
{
/// <summary>
/// Slicer name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Slicer name.
/// </summary>
public string Version { get; set; }
/// <summary>
/// Slicer edition.
/// </summary>
public string Edition { get; set; }
/// <summary>
/// Estimated Build Time.
/// </summary>
public decimal? EstimatedBuildTime{ get; set; }
/// <summary>
/// Estimated Build Cost $.
/// </summary>
public decimal? EstimatedBuildCost{ get; set; }
/// <summary>
/// Filament used extruder 1 (mm)
/// </summary>
public decimal? FilamentUsedExtruder1 { get; set; }
/// <summary>
/// Filament used extruder 1 (cm^3)
/// </summary>
public decimal? FilamentUsedExtruder1Volume { get; set; }
/// <summary>
/// Filament used extruder 2 (mm)
/// </summary>
public decimal? FilamentUsedExtruder2 { get; set; }
/// <summary>
/// Filament used extruder 2 (cm^3)
/// </summary>
public decimal? FilamentUsedExtruder2Volume { get; set; }
/// <summary>
/// Total estimated (pre-cool) minutes.
/// </summary>
public decimal? TotalEstimatedPreCoolMinutes { get; set; }
}
}
10 changes: 5 additions & 5 deletions src/Gcode.Utils/Gcode.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
<PackageTags>csharp gcode 3d-printing reprap reprap-3d-printer marlin marlin-firmware repitier repitier-firmware json</PackageTags>
<RepositoryType>git</RepositoryType>
<Copyright>Anton Maisak</Copyright>
<AssemblyVersion>0.2.0.5</AssemblyVersion>
<AssemblyVersion>0.2.0.6</AssemblyVersion>
<PackageReleaseNotes>Gcode.Entity
Gcode.Common.Utils</PackageReleaseNotes>
<Version>0.2.5</Version>
<FileVersion>0.2.0.5</FileVersion>
<Version>0.2.6</Version>
<FileVersion>0.2.0.6</FileVersion>
<PackageIconUrl>https://raw.githubusercontent.com/avmaisak/Gcode/master/misc/design/logo/logo.png</PackageIconUrl>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibBase" Version="1.0.2" />
<PackageReference Include="LibBase" Version="1.0.3" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions src/Gcode.Utils/SlicerParser/KisSlicerParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Linq;
using Gcode.Utils.Entity;

namespace Gcode.Utils.SlicerParser
{
/// <summary>
/// KISSlicer Gcode parser.
/// </summary>
public class KisSlicerParser : SlicerParserBase<KisSlicerInfo>
{
public override KisSlicerInfo GetSlicerInfo(string[] fileContent)
{
var name = fileContent.FirstOrDefault(x => x.StartsWith("; KISSlicer "));
if (name == null)
{
return null;
}

var res = new KisSlicerInfo
{
Name = name.Split(';')[1]?.Split('-')[0]?.Trim() ?? string.Empty,
Version = fileContent.FirstOrDefault(x => x.StartsWith("; version"))?.Split(';')?[1]?.Trim() ?? string.Empty,
Edition = name.Split(';')[1]?.Split('-')[1]?.Trim() ?? string.Empty,
};

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

var buildCostStr = fileContent.FirstOrDefault(x => x.StartsWith("; Estimated 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)
{
res.TotalEstimatedPreCoolMinutes = Convert.ToDecimal(totalEstimatedPreCoolMinutes?.Split(':')?[1]?.Trim()?.Replace(".",","));
}

var filamentUsageExist = fileContent.FirstOrDefault(x => x.StartsWith("; Filament used per extruder:")) != null;
if (filamentUsageExist)
{
var filamentUsageExt1 = fileContent.FirstOrDefault(x => x.StartsWith("; Ext 1 = "));
if (filamentUsageExt1 != null)
{
res.FilamentUsedExtruder1 = Convert.ToDecimal(
filamentUsageExt1.Split('=')[1]?
.Split(')')[0]?
.Split(' ')[1]?
.Replace(".",",")?
.Trim()
);

res.FilamentUsedExtruder1Volume = Convert.ToDecimal(
filamentUsageExt1
.Split('=')[1]?
.Split('(')[1]?
.Split(' ')[0]?
.Replace(".",",")?
.Trim()
);
}

var filamentUsageExt2 = fileContent.FirstOrDefault(x => x.StartsWith("; Ext 2 = "));
if (filamentUsageExt2 != null)
{
res.FilamentUsedExtruder2 = Convert.ToDecimal(
filamentUsageExt2.Split('=')[1]?
.Split(')')[0]?
.Split(' ')[1]?
.Replace(".",",")?
.Trim()
);

res.FilamentUsedExtruder2Volume = Convert.ToDecimal(
filamentUsageExt2
.Split('=')[1]?
.Split('(')[1]?
.Split(' ')[0]?
.Replace(".",",")?
.Trim()
);
}
}

return res;
}
}
}
9 changes: 9 additions & 0 deletions src/Gcode.Utils/SlicerParser/SlicerParserBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Gcode.Utils.Entity;

namespace Gcode.Utils.SlicerParser
{
public abstract class SlicerParserBase<T> where T: SlicerInfo
{
public abstract T GetSlicerInfo(string[] fileContent);
}
}
Loading

0 comments on commit 03db5df

Please sign in to comment.