From 53bf874759d7cff6f09ce517c9a3a52cd4d8c1b9 Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Wed, 10 Jun 2020 20:49:55 +0300 Subject: [PATCH 1/5] MSTest.TestAdapter 2.1.2 --- tools/TestSuite/Gcode.Test/Gcode.Test.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/TestSuite/Gcode.Test/Gcode.Test.csproj b/tools/TestSuite/Gcode.Test/Gcode.Test.csproj index cbc9154..2f6329c 100644 --- a/tools/TestSuite/Gcode.Test/Gcode.Test.csproj +++ b/tools/TestSuite/Gcode.Test/Gcode.Test.csproj @@ -15,8 +15,8 @@ - - + + From 64679dde03a852a0a702be3ba5cc9cd93a99a41f Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Wed, 10 Jun 2020 21:07:43 +0300 Subject: [PATCH 2/5] - Small Refactoring and Code quality improvements - Added Resources --- src/Gcode.Utils/Gcode.Utils.csproj | 15 ++ src/Gcode.Utils/GcodeCrc.cs | 33 ++--- src/Gcode.Utils/GcodeException.cs | 11 ++ src/Gcode.Utils/GcodeParser.cs | 40 ++---- src/Gcode.Utils/Resources.Designer.cs | 99 +++++++++++++ src/Gcode.Utils/Resources.resx | 132 ++++++++++++++++++ .../SlicerParser/KisSlicerParser.cs | 1 - 7 files changed, 283 insertions(+), 48 deletions(-) create mode 100644 src/Gcode.Utils/GcodeException.cs create mode 100644 src/Gcode.Utils/Resources.Designer.cs create mode 100644 src/Gcode.Utils/Resources.resx diff --git a/src/Gcode.Utils/Gcode.Utils.csproj b/src/Gcode.Utils/Gcode.Utils.csproj index cdbb576..8c5e7e0 100644 --- a/src/Gcode.Utils/Gcode.Utils.csproj +++ b/src/Gcode.Utils/Gcode.Utils.csproj @@ -48,4 +48,19 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + diff --git a/src/Gcode.Utils/GcodeCrc.cs b/src/Gcode.Utils/GcodeCrc.cs index 42e5d4b..a0ab6b4 100644 --- a/src/Gcode.Utils/GcodeCrc.cs +++ b/src/Gcode.Utils/GcodeCrc.cs @@ -1,5 +1,4 @@ -using System; -using Gcode.Utils.Entity; +using Gcode.Utils.Entity; namespace Gcode.Utils { @@ -26,30 +25,26 @@ public static class GcodeCrc /// public static int FrameCrc(this GcodeCommandFrame gcodeCommandFrame) { - if (gcodeCommandFrame.N <= 0) throw new Exception("Frame line number expected (>0)"); - - var f = gcodeCommandFrame.ToString(); - var check = 0; - - foreach (var ch in f) check ^= ch & 0xff; - - check ^= 32; - - return check; + if (gcodeCommandFrame.N <= 0) throw new GcodeException(Resources.FrameLineNumExpected); + return SetCheckSum(gcodeCommandFrame.ToString()); } // ReSharper disable once UnusedMember.Global public static int FrameCrc(this string gcodeCommandFrame) { var gcode = GcodeParser.ToGCode(gcodeCommandFrame); - if (gcode.N <= 0) throw new Exception("Frame line number expected (>0)"); - - var f = gcodeCommandFrame; + if (gcode.N <= 0) throw new GcodeException(Resources.FrameLineNumExpected); + return SetCheckSum(gcodeCommandFrame); + } + /// + /// Set CheckSum. + /// + /// + /// + private static int SetCheckSum(string rawFrame) + { var check = 0; - - foreach (var ch in f) check ^= ch & 0xff; - + foreach (var ch in rawFrame) check ^= ch & 0xff; check ^= 32; - return check; } } diff --git a/src/Gcode.Utils/GcodeException.cs b/src/Gcode.Utils/GcodeException.cs new file mode 100644 index 0000000..6d202ee --- /dev/null +++ b/src/Gcode.Utils/GcodeException.cs @@ -0,0 +1,11 @@ +using System; + +namespace Gcode.Utils +{ + /// + /// GcodeException. + /// + public class GcodeException : Exception { + public GcodeException(string message): base (message: message) {} + } +} diff --git a/src/Gcode.Utils/GcodeParser.cs b/src/Gcode.Utils/GcodeParser.cs index 05880bd..2939dcf 100644 --- a/src/Gcode.Utils/GcodeParser.cs +++ b/src/Gcode.Utils/GcodeParser.cs @@ -14,10 +14,8 @@ namespace Gcode.Utils /// public static class GcodeParser { - #region private private static readonly CultureInfo Culture = CultureInfo.InvariantCulture; private static string _rawFrame; - private const string CommentChar = ";"; /// /// To Gcode CommandFrame /// @@ -27,31 +25,21 @@ private static GcodeCommandFrame ToGcodeCommandFrame(IEnumerable)) continue; - //объект назначения - var obj = gcodeCommandFrame; - //значение поля - var fieldValue = value; //свойства поля кадра fileldInfoType = fileldInfoType.GetGenericArguments()[0]; //указание значения сегмента кадра - fieldInfo.SetValue(obj, Convert.ChangeType(fieldValue, fileldInfoType, Culture)); + fieldInfo.SetValue(gcodeCommandFrame, Convert.ChangeType(frameSegment.Value, fileldInfoType, Culture)); } return gcodeCommandFrame; } - #endregion /// /// To GCode /// @@ -80,7 +68,7 @@ public static GcodeCommandFrame ToGCode(string raw) //содержит комментарий if (_rawFrame.ContainsGcodeComment()) { - var r = _rawFrame.Split(CommentChar); + var r = _rawFrame.Split(Resources.CommentChar); if (r.Length == 2) { _rawFrame = r[0].Trim(); @@ -122,27 +110,23 @@ public static string ToStringCommand(this GcodeCommandFrame gcodeCommandFrame, b var isNotEmpty = !string.IsNullOrWhiteSpace(objProp.Value?.Trim()); if (!isNotEmpty) continue; - if (objProp.Key != "Comment") + if (objProp.Key != Resources.CommentTag) { var commandKey = objProp.Key; if (addedLines == 0) commandSeparator = string.Empty; - if (objProp.Key == "CheckSum" && !string.IsNullOrWhiteSpace(objProp.Value)) commandKey = "*"; + if (objProp.Key == Resources.CheckSumTag && !string.IsNullOrWhiteSpace(objProp.Value)) commandKey = "*"; var cmdFrameSegmentStr = $"{commandSeparator}{commandKey}{objProp.Value}"; cmdSegmentStringBuilder.Append(cmdFrameSegmentStr); addedLines++; } - else - { - if (!ignoreComments) commentString = objProp.Value; - } + else if (!ignoreComments) commentString = objProp.Value; } - var res = !string.IsNullOrWhiteSpace(commentString) ? $"{cmdSegmentStringBuilder} ;{commentString}" : cmdSegmentStringBuilder.ToString(); - return res.Trim(); + return (!string.IsNullOrWhiteSpace(commentString) ? $"{cmdSegmentStringBuilder} ;{commentString}" : cmdSegmentStringBuilder.ToString()).Trim(); } /// /// ToJson @@ -154,7 +138,7 @@ public static string GcodeToJson(this string raw) const string objJsonStart = "{"; const string objJsonEnd = "}"; - if (_rawFrame.IsGcodeComment() || _rawFrame.IsNullOrErrorFrame()) return $"{{Comment:{raw.Replace(";", null).Replace("\r", null).Trim()}}}"; + if (_rawFrame.IsGcodeComment() || _rawFrame.IsNullOrErrorFrame()) return $"{{{Resources.CommentTag}:{raw.Replace(";", null).Replace("\r", null).Trim()}}}"; var commentString = string.Empty; @@ -162,7 +146,7 @@ public static string GcodeToJson(this string raw) { var arr = _rawFrame.Split(";"); _rawFrame = arr[0].Trim(); - commentString = $",\"Comment\":\"{arr[1].Trim().Replace("\r", null)}\""; + commentString = $",\"{Resources.CommentTag}\":\"{arr[1].Trim().Replace("\r", null)}\""; } var segments = _rawFrame.ToKeyValuePair(); @@ -254,7 +238,7 @@ public static string NormalizeGcodeRawFrame(this string raw) public static bool ContainsGcodeComment(this string raw) { _rawFrame = raw.Trim(); - return !_rawFrame.StartsWith(CommentChar) && _rawFrame.Contains(CommentChar); + return !_rawFrame.StartsWith(Resources.CommentChar) && _rawFrame.Contains(Resources.CommentChar); } /// /// IsComment @@ -264,7 +248,7 @@ public static bool ContainsGcodeComment(this string raw) public static bool IsGcodeComment(this string raw) { _rawFrame = raw.Trim(); - return !_rawFrame.IsNullOrErrorFrame() && _rawFrame.StartsWith(CommentChar); + return !_rawFrame.IsNullOrErrorFrame() && _rawFrame.StartsWith(Resources.CommentChar); } /// /// Is Null Or Error Frame @@ -284,7 +268,7 @@ public static bool IsNullOrErrorFrame(this string raw) public static bool IsEmptyComment(this string raw) { _rawFrame = raw.Trim(); - return _rawFrame.Length == 1 && _rawFrame == CommentChar; + return _rawFrame.Length == 1 && _rawFrame == Resources.CommentChar; } /// diff --git a/src/Gcode.Utils/Resources.Designer.cs b/src/Gcode.Utils/Resources.Designer.cs new file mode 100644 index 0000000..c3c8582 --- /dev/null +++ b/src/Gcode.Utils/Resources.Designer.cs @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Gcode.Utils { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Gcode.Utils.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to CheckSum. + /// + internal static string CheckSumTag { + get { + return ResourceManager.GetString("CheckSumTag", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ;. + /// + internal static string CommentChar { + get { + return ResourceManager.GetString("CommentChar", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Comment. + /// + internal static string CommentTag { + get { + return ResourceManager.GetString("CommentTag", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Frame line number expected (>0). + /// + internal static string FrameLineNumExpected { + get { + return ResourceManager.GetString("FrameLineNumExpected", resourceCulture); + } + } + } +} diff --git a/src/Gcode.Utils/Resources.resx b/src/Gcode.Utils/Resources.resx new file mode 100644 index 0000000..f7d31f7 --- /dev/null +++ b/src/Gcode.Utils/Resources.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + CheckSum + + + ; + + + Comment + + + Frame line number expected (>0) + + \ No newline at end of file diff --git a/src/Gcode.Utils/SlicerParser/KisSlicerParser.cs b/src/Gcode.Utils/SlicerParser/KisSlicerParser.cs index e33e4de..681547f 100644 --- a/src/Gcode.Utils/SlicerParser/KisSlicerParser.cs +++ b/src/Gcode.Utils/SlicerParser/KisSlicerParser.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Gcode.Utils.Entity; using Gcode.Utils.Entity.Slicer; using LibBase.Extensions; From 7492d84aa664c4152999ba67d2c2caa613c69396 Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Wed, 10 Jun 2020 21:10:40 +0300 Subject: [PATCH 3/5] fix PrusaSlicerParserTest1 --- .../Parser/PrusaSlicerParserTests.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs b/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs index 9c3b184..0043ca2 100644 --- a/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs +++ b/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs @@ -12,18 +12,16 @@ public class PrusaSlicerParserTests public void PrusaSlicerParserTest1() { string[] src = TestSuiteDataSource.GetDataSourceArray(@"prusa_slicer\2.2.0-rc4\test_rc.gcode"); - if (src?.Length > 0) - { - var parser = new PrusaSlicerParser(); - var res = parser.GetSlicerInfo(src); - Assert.IsNotNull(res); - Assert.IsTrue(res.Edition == string.Empty); - Assert.IsTrue(res.Version == "2.2.0-rc4+win64"); - Assert.IsTrue(res.FilamentUsedExtruder1 == (decimal)0.8); - Assert.IsTrue(res.FilamentUsedExtruder2 == null); - Assert.IsTrue(res.FilamentDiameter == (decimal)1.75); - Assert.IsTrue(res.EstimatedBuildTime == (decimal)6.32); - } + var parser = new PrusaSlicerParser(); + Assert.IsNotNull(parser); + var res = parser.GetSlicerInfo(src); + Assert.IsNotNull(res); + Assert.IsTrue(res.Edition == string.Empty); + Assert.IsTrue(res.Version == "2.2.0-rc4+win64"); + Assert.IsTrue(res.FilamentUsedExtruder1 == (decimal)0.8); + Assert.IsTrue(res.FilamentUsedExtruder2 == null); + Assert.IsTrue(res.FilamentDiameter == (decimal)1.75); + Assert.IsTrue(res.EstimatedBuildTime == (decimal)6.32); } } } From 1413ec6025dadd519547208113cffe40e8bec983 Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Wed, 10 Jun 2020 21:13:33 +0300 Subject: [PATCH 4/5] 0.2.21 --- 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 8c5e7e0..d947616 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.20 + 0.2.0.21 - 0.2.20 - 0.2.0.20 + 0.2.21 + 0.2.0.21 LICENSE logo.png From fc040fa1b541e5338495720afd6d50377997c01b Mon Sep 17 00:00:00 2001 From: Anton Maisak Date: Wed, 10 Jun 2020 21:15:58 +0300 Subject: [PATCH 5/5] Prusa Slicer -> Manual Test Execution --- tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs b/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs index 0043ca2..56a6971 100644 --- a/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs +++ b/tools/TestSuite/Gcode.Test/Parser/PrusaSlicerParserTests.cs @@ -5,7 +5,7 @@ namespace Gcode.Test.Parser { [TestClass] - // [Ignore("Run this tests manually")] + [Ignore("Run this tests manually")] public class PrusaSlicerParserTests { [TestMethod]