-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from avmaisak/dev
added KisSlicerParser
- Loading branch information
Showing
9 changed files
with
2,018,299 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.