-
-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new command processor for filtering out empty gcode lines (#2187)
- Loading branch information
Showing
18 changed files
with
172 additions
and
24 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...e/src/com/willwinder/universalgcodesender/gcode/processors/EmptyLineRemoverProcessor.java
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 @@ | ||
/* | ||
Copyright 2023 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.universalgcodesender.gcode.processors; | ||
|
||
import com.willwinder.universalgcodesender.gcode.GcodeState; | ||
import com.willwinder.universalgcodesender.gcode.util.GcodeParserException; | ||
import com.willwinder.universalgcodesender.i18n.Localization; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Removes empty lines from the gcode file | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
public class EmptyLineRemoverProcessor implements CommandProcessor { | ||
|
||
@Override | ||
public List<String> processCommand(String command, GcodeState state) throws GcodeParserException { | ||
if (StringUtils.trimToNull(command) == null) { | ||
return Collections.emptyList(); | ||
} | ||
return Collections.singletonList(command); | ||
} | ||
|
||
@Override | ||
public String getHelp() { | ||
return Localization.getString("sender.help.empty-line-remover"); | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
...t/com/willwinder/universalgcodesender/gcode/processors/EmptyLineRemoverProcessorTest.java
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,37 @@ | ||
package com.willwinder.universalgcodesender.gcode.processors; | ||
|
||
import com.willwinder.universalgcodesender.gcode.GcodeState; | ||
import com.willwinder.universalgcodesender.gcode.util.GcodeParserException; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class EmptyLineRemoverProcessorTest { | ||
@Test | ||
public void processCommandShouldNotRemoveEmptyLines() throws GcodeParserException { | ||
EmptyLineRemoverProcessor processor = new EmptyLineRemoverProcessor(); | ||
List<String> lines = processor.processCommand("test", new GcodeState()); | ||
assertEquals(1, lines.size()); | ||
} | ||
|
||
@Test | ||
public void processCommandShouldRemoveTrimmedEmptyLines() throws GcodeParserException { | ||
EmptyLineRemoverProcessor processor = new EmptyLineRemoverProcessor(); | ||
List<String> lines = processor.processCommand("", new GcodeState()); | ||
assertEquals(0, lines.size()); | ||
|
||
lines = processor.processCommand(" ", new GcodeState()); | ||
assertEquals(0, lines.size()); | ||
|
||
lines = processor.processCommand(" ", new GcodeState()); | ||
assertEquals(0, lines.size()); | ||
|
||
lines = processor.processCommand("\t", new GcodeState()); | ||
assertEquals(0, lines.size()); | ||
|
||
lines = processor.processCommand(null, new GcodeState()); | ||
assertEquals(0, lines.size()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
ugs-core/test/resources/gcode/fixtures/comments/comments.input.nc
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,5 @@ | ||
; Empty command with comment | ||
(Another empty command with comment) | ||
|
||
G0 ; Command with comment | ||
G1 (Another command with comment) |
5 changes: 5 additions & 0 deletions
5
ugs-core/test/resources/gcode/fixtures/comments/outComments/comments.parsed_output.nc
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,5 @@ | ||
|
||
|
||
|
||
G0 | ||
G1 |
6 changes: 6 additions & 0 deletions
6
ugs-core/test/resources/gcode/fixtures/comments/outComments/comments.stream_output.nc
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,6 @@ | ||
gsw_meta:5 | ||
; Empty command with comment¶¶¶¶1¶¶Empty command with comment | ||
(Another empty command with comment)¶¶¶¶2¶¶Another empty command with comment | ||
¶¶¶¶3¶¶ | ||
G0 ; Command with comment¶¶G0¶¶4¶¶Command with comment | ||
G1 (Another command with comment)¶¶G1¶¶5¶¶Another command with comment |
2 changes: 2 additions & 0 deletions
2
ugs-core/test/resources/gcode/fixtures/comments/outEmptyLines/comments.parsed_output.nc
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,2 @@ | ||
G0 | ||
G1 |
3 changes: 3 additions & 0 deletions
3
ugs-core/test/resources/gcode/fixtures/comments/outEmptyLines/comments.stream_output.nc
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,3 @@ | ||
gsw_meta:2 | ||
G0 ; Command with comment¶¶G0¶¶4¶¶Command with comment | ||
G1 (Another command with comment)¶¶G1¶¶5¶¶Another command with comment |
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