-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/zbottom warn if negative z on z bottom (#56)
- Loading branch information
Showing
55 changed files
with
353 additions
and
186 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
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,48 @@ | ||
using GSendShared; | ||
using GSendShared.Abstractions; | ||
|
||
namespace GSendAnalyzer.Analyzers | ||
{ | ||
internal class AnalyzeZ : IGCodeAnalyzer | ||
{ | ||
private const int MinimumLayerCount = 2; | ||
|
||
public int Order => Int32.MinValue; | ||
|
||
public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses) | ||
{ | ||
ArgumentNullException.ThrowIfNull(gCodeAnalyses); | ||
|
||
|
||
decimal homeZ = gCodeAnalyses.AllCommands.Count > 0 ? gCodeAnalyses.AllCommands.Max(c => c.CurrentZ) : 0; | ||
|
||
List<IGCodeCommand> homeZCommands = gCodeAnalyses.AllCommands.Where(c => c.CurrentZ < homeZ).ToList(); | ||
decimal safeZ = homeZCommands.Count > 0 ? homeZCommands.Max(c => c.CurrentZ) : 0; | ||
|
||
List<IGCodeCommand> layerCommands = gCodeAnalyses.AllSpecificCommands(Constants.CharZ).Where(c => | ||
c.CommandValue < safeZ && | ||
( | ||
!c.Attributes.HasFlag(CommandAttributes.SafeZ) && | ||
!c.Attributes.HasFlag(CommandAttributes.HomeZ) && | ||
!c.Attributes.HasFlag(CommandAttributes.StartProgram) | ||
) | ||
) | ||
.DistinctBy(c => c.CurrentZ) | ||
.OrderByDescending(c => c.CurrentZ) | ||
.ToList(); | ||
|
||
if (layerCommands.Count > MinimumLayerCount) | ||
{ | ||
if (layerCommands[0].CommandValue > 0) | ||
{ | ||
gCodeAnalyses.ZBottom = layerCommands[0].CommandValue > layerCommands[^1].CommandValue; | ||
|
||
if (gCodeAnalyses.ZBottom.HasValue && gCodeAnalyses.ZBottom.Value && layerCommands.Exists(c => c.CommandValue < 0) && gCodeAnalyses is GCodeAnalyses analysis) | ||
analysis.AddWarning(GSend.Language.Resources.WarnBitBelowSpoilboard); | ||
} | ||
else | ||
gCodeAnalyses.ZBottom = layerCommands[0].CommandValue < layerCommands[^1].CommandValue; | ||
} | ||
} | ||
} | ||
} |
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,81 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
using GSendAnalyzer.Analyzers; | ||
using GSendAnalyzer.Internal; | ||
|
||
using GSendShared; | ||
|
||
using GSendTests.Mocks; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GSendTests.GSendAnalyzerTests | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
[TestClass] | ||
public sealed class AnalyzeZTests | ||
{ | ||
private const string GCodeZTop = "G0Z30.000\r\nG1Z-2.000F250.0\r\nG1Z-4.000F250.0\r\nG1Z-6.000F250.0\r\nG1Z-8.000F250.0\r\nG1Z-10.000F250.0\r\nG1Z-12.000F250.0\r\nG1Z-14.000F250.0\r\nG1Z-16.000F250.0\r\nG1Z-18.000F250.0\r\nG0Z22.000"; | ||
private const string GCodeZBottom = "G0Z30.000\r\nG1Z14.300F250.0\r\nG1Z12.300F250.0\r\nG1Z10.300F250.0\r\nG1Z8.300F250.0\r\nG1Z6.300F250.0\r\nG1Z4.300F250.0\r\nG1Z2.300F250.0\r\nG1Z0.300F250.0\r\nG1Z-1.700F250.0"; | ||
private const string GCodeZUndetermined = "G0Z30.000\r\nG1Z-2.000F250.0\r\nG1Z-4.000F250.0"; | ||
|
||
[TestMethod] | ||
public void Construct_ValidInstance_Success() | ||
{ | ||
AnalyzeZ sut = new(); | ||
Assert.IsNotNull(sut); | ||
Assert.AreEqual(Int32.MinValue, sut.Order); | ||
} | ||
|
||
[TestMethod] | ||
public void Validate_ZTop_Success() | ||
{ | ||
AnalyzeZ sut = new(); | ||
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms()); | ||
IGCodeAnalyses analyses = gCodeParser.Parse(GCodeZTop); | ||
|
||
sut.Analyze(String.Empty, analyses); | ||
|
||
Assert.IsFalse(analyses.ZBottom); | ||
} | ||
|
||
[TestMethod] | ||
public void Validate_ZBottom_Success() | ||
{ | ||
AnalyzeZ sut = new(); | ||
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms()); | ||
IGCodeAnalyses analyses = gCodeParser.Parse(GCodeZBottom); | ||
|
||
sut.Analyze(String.Empty, analyses); | ||
|
||
Assert.IsTrue(analyses.ZBottom); | ||
} | ||
|
||
[TestMethod] | ||
public void Validate_ZUndetermined_Success() | ||
{ | ||
AnalyzeZ sut = new(); | ||
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms()); | ||
IGCodeAnalyses analyses = gCodeParser.Parse(GCodeZUndetermined); | ||
|
||
sut.Analyze(String.Empty, analyses); | ||
|
||
Assert.IsNull(analyses.ZBottom); | ||
} | ||
|
||
[TestMethod] | ||
public void Validate_ZBottom_GoesBelowBed_CreatesWarning_Success() | ||
{ | ||
AnalyzeZ sut = new(); | ||
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms()); | ||
IGCodeAnalyses analyses = gCodeParser.Parse(GCodeZBottom); | ||
|
||
sut.Analyze(String.Empty, analyses); | ||
|
||
Assert.IsTrue(analyses.ZBottom); | ||
Assert.AreEqual(1, analyses.Warnings.Count); | ||
Assert.AreEqual("Validate the bit does not go below the spoilboard when using Z Bottom and having a negative Z value", analyses.Warnings[0]); | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.