Skip to content

Commit

Permalink
Merge pull request #29 from avmaisak/prusa-slicer
Browse files Browse the repository at this point in the history
Added Prusa Slicer Parser
  • Loading branch information
avmaisak authored Jan 3, 2020
2 parents 288e886 + 49728e1 commit 7d50c28
Show file tree
Hide file tree
Showing 20 changed files with 544,958 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gcode.Utils.Entity.Base;

namespace Gcode.Utils.Entity
namespace Gcode.Utils.Entity.Slicer
{
public class CuraSlicerInfo: SlicerInfoBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gcode.Utils.Entity.Base;

namespace Gcode.Utils.Entity
namespace Gcode.Utils.Entity.Slicer
{
/// <summary>
/// Gcode, generated by Kisslicer information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gcode.Utils.Entity.Base;

namespace Gcode.Utils.Entity
namespace Gcode.Utils.Entity.Slicer
{
/// <summary>
/// Simplify3D(R) info.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gcode.Utils.Entity.Base;

namespace Gcode.Utils.Entity
namespace Gcode.Utils.Entity.Slicer
{
public class Slic3RInfo: SlicerInfoBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/Gcode.Utils/Gcode.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Copyright>Anton Maisak</Copyright>
<AssemblyVersion>0.2.0.12</AssemblyVersion>
<PackageReleaseNotes></PackageReleaseNotes>
<Version>0.2.12</Version>
<Version>0.2.13</Version>
<FileVersion>0.2.0.12</FileVersion>
<PackageIconUrl>https://raw.githubusercontent.com/avmaisak/Gcode/master/misc/design/logo/logo.png</PackageIconUrl>
</PropertyGroup>
Expand Down
6 changes: 2 additions & 4 deletions src/Gcode.Utils/GcodeCrc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public static int FrameCrc(this GcodeCommandFrame gcodeCommandFrame)

var f = gcodeCommandFrame.ToString();
var check = 0;
foreach (var ch in f)
{
check ^= ch & 0xff;
}

foreach (var ch in f) check ^= ch & 0xff;

check ^= 32;

Expand Down
1 change: 1 addition & 0 deletions src/Gcode.Utils/SlicerParser/CuraParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Gcode.Utils.Entity;
using Gcode.Utils.Entity.Slicer;

namespace Gcode.Utils.SlicerParser
{
Expand Down
1 change: 1 addition & 0 deletions src/Gcode.Utils/SlicerParser/KisSlicerParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Gcode.Utils.Entity;
using Gcode.Utils.Entity.Slicer;
using LibBase.Extensions;

namespace Gcode.Utils.SlicerParser
Expand Down
68 changes: 68 additions & 0 deletions src/Gcode.Utils/SlicerParser/PrusaSlicerParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Linq;
using Gcode.Utils.Entity.Slicer;

namespace Gcode.Utils.SlicerParser
{
public class PrusaSlicerParser: SlicerParserBase<Slic3RInfo>
{
public override Slic3RInfo GetSlicerInfo(string[] fileContent)
{
var name = fileContent.FirstOrDefault(x => x.StartsWith("; generated by PrusaSlicer "));

if (name?.Split(' ')[3] == null) return null;

var res = new Slic3RInfo
{
Name = name.Split(' ')[3],
Version = name.Split(' ')[4],
// no edition provided by Slic3r
Edition = string.Empty,
};

var filamentUsed = fileContent.Where(x => x.StartsWith("; filament used [mm] = ")).ToArray();
if (filamentUsed.Length == 1 && filamentUsed[0] != null)
{
// filament used
res.FilamentUsedExtruder1 = Convert.ToDecimal(filamentUsed[0].Split('=')[1]?.Split(' ')[1]?.Replace("[mm]", "").Replace(".", ","));
}

if (filamentUsed.Length == 2 && filamentUsed[1] != null)
{
// filament used
res.FilamentUsedExtruder2 = Convert.ToDecimal(filamentUsed[1].Split('=')[1]?.Split(' ')[1]?.Replace("[mm]", "").Replace(".", ","));
}

var filamentDiameter = fileContent.FirstOrDefault(x => x.StartsWith("; filament_diameter"));

if (!string.IsNullOrWhiteSpace(filamentDiameter))
{
var diameter = filamentDiameter.Split('=')?[1];
if (string.IsNullOrWhiteSpace(diameter))
{
res.FilamentDiameter = null;
}
else
{
if (diameter.Contains(",")) diameter = diameter.Split(',')[0];
res.FilamentDiameter = Convert.ToDecimal(diameter.Replace(".", ","));
}

}

if (res.FilamentUsedExtruder1 != null && res.FilamentUsedExtruder1 > 0 && res.FilamentDiameter != null && res.FilamentDiameter > 0)
{
// обьем = сечение * длину
res.FilamentUsedExtruder1Volume = res.FilamentDiameter * res.FilamentUsedExtruder1;
}

if (res.FilamentUsedExtruder2 != null && res.FilamentUsedExtruder2 > 0 && res.FilamentDiameter != null && res.FilamentDiameter > 0)
{
// обьем = сечение * длину
res.FilamentUsedExtruder2Volume = res.FilamentDiameter * res.FilamentUsedExtruder2;
}

return res;
}
}
}
1 change: 1 addition & 0 deletions src/Gcode.Utils/SlicerParser/Simplify3dParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Gcode.Utils.Entity;
using Gcode.Utils.Entity.Slicer;

namespace Gcode.Utils.SlicerParser
{
Expand Down
1 change: 1 addition & 0 deletions src/Gcode.Utils/SlicerParser/Slic3RParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Gcode.Utils.Entity;
using Gcode.Utils.Entity.Slicer;

namespace Gcode.Utils.SlicerParser
{
Expand Down
Loading

0 comments on commit 7d50c28

Please sign in to comment.