From cb0b5f75514b3d9985b82ba71cb7111957d6d61a Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Mon, 17 Feb 2020 10:04:08 +0300 Subject: [PATCH 1/2] Prusa Slicer. Added estimated printing time parse --- .../SlicerParser/PrusaSlicerParser.cs | 25 ++++++++++++++++--- .../Parser/PrusaSlicerParserTests.cs | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Gcode.Utils/SlicerParser/PrusaSlicerParser.cs b/src/Gcode.Utils/SlicerParser/PrusaSlicerParser.cs index 8520050..2bc6416 100644 --- a/src/Gcode.Utils/SlicerParser/PrusaSlicerParser.cs +++ b/src/Gcode.Utils/SlicerParser/PrusaSlicerParser.cs @@ -70,15 +70,34 @@ public override Slic3RInfo GetSlicerInfo(string[] fileContent) } 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; + + // estimated printing time + var buildTimeStr = fileContent.FirstOrDefault(x => x.StartsWith("; estimated printing time")); + + if (!string.IsNullOrWhiteSpace(buildTimeStr)) + { + var buildTime = buildTimeStr.Split('=')[1]?.Trim(); + if (!string.IsNullOrWhiteSpace(buildTime)) + { + var resArr = buildTime.Split(' '); + var hours = 0; + var minutes = 0; + var seconds = 0; + + if (resArr.Where(x => x.Contains("h"))?.Count() > 0) hours = Convert.ToInt32(resArr?.FirstOrDefault(x => x.Contains("h"))?.Split('h')?[0] ?? "0"); + if (resArr.Where(x => x.Contains("m"))?.Count() > 0) minutes = Convert.ToInt32(resArr?.FirstOrDefault(x => x.Contains("m"))?.Split('m')?[0] ?? "0"); + if (resArr.Where(x => x.Contains("s"))?.Count() > 0) seconds = Convert.ToInt32(resArr?.FirstOrDefault(x => x.Contains("s"))?.Split('s')?[0] ?? "0"); + + var spanDuration = new TimeSpan(0, hours, minutes, seconds); + res.EstimatedBuildTime = Math.Round(Convert.ToDecimal(spanDuration.TotalMinutes), 2); + } } return res; diff --git a/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs b/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs index 81dbb37..613b8e9 100644 --- a/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs +++ b/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs @@ -23,6 +23,7 @@ public void PrusaSlicerParserTest1() Assert.IsTrue(res.FilamentUsedExtruder1 == (decimal)11773.6); Assert.IsTrue(res.FilamentDiameter == (decimal)1.75); Assert.IsTrue(res.FilamentUsedExtruder1Volume == (decimal)20603.800); + Assert.IsTrue(res.EstimatedBuildTime == (decimal)321.17); } } [TestMethod] @@ -39,6 +40,7 @@ public void PrusaSlicerParserTest2() Assert.IsTrue(res.FilamentUsedExtruder1 == (decimal)912.1); Assert.IsTrue(res.FilamentDiameter == (decimal)1.75); Assert.IsTrue(res.FilamentUsedExtruder1Volume == (decimal)1596.175); + Assert.IsTrue(res.EstimatedBuildTime == (decimal)37.35); } } [TestMethod] @@ -55,6 +57,7 @@ public void PrusaSlicerParserTest3() Assert.IsTrue(res.FilamentUsedExtruder1 == (decimal)10604.9); Assert.IsTrue(res.FilamentUsedExtruder2 == (decimal)62.3); Assert.IsTrue(res.FilamentDiameter == (decimal)1.75); + Assert.IsTrue(res.EstimatedBuildTime == (decimal)123.25); } } } From 9db32af6d4d426def7e4830b65de835196537218 Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Mon, 17 Feb 2020 10:04:54 +0300 Subject: [PATCH 2/2] version bump --- src/Gcode.Utils/Gcode.Utils.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Gcode.Utils/Gcode.Utils.csproj b/src/Gcode.Utils/Gcode.Utils.csproj index 6ddf54c..cc34922 100644 --- a/src/Gcode.Utils/Gcode.Utils.csproj +++ b/src/Gcode.Utils/Gcode.Utils.csproj @@ -13,10 +13,10 @@ gcode 3d-printing reprap reprap-3d-printer marlin marlin-firmware repitier repitier-firmware json json-parsing gcode-json cura kisslicer slic3r simplify3d git Anton Maisak - 0.2.0.16 + 0.2.0.17 - 0.2.16 - 0.2.0.16 + 0.2.17 + 0.2.0.17 LICENSE logo.png