Skip to content

Commit 7064cf7

Browse files
Merge pull request #1 from ludwig-austermann/v0.3
V0.3
2 parents 419b3e6 + cdd1ed2 commit 7064cf7

7 files changed

Lines changed: 349 additions & 121 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/target
22
Cargo.lock
33
simple.gcode
4-
test_transformed.gcode
5-
test.gcode
4+
test_transformed.gcode

readme.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@ The application is programmed in rust with the [nannou library](https://nannou.c
2929
It furthermore supports a subcommand `transform`, which
3030
allows you to transform a file by translation and dilation.
3131

32+
## Keyboard commands and editing features
33+
3234
In the graphical app, a few keyboard commands are enabled. To increase a value corresponding to a <kbd>key</kbd>, just press <kbd>key</kbd> and to decrease press <kbd>shift</kbd> + <kbd>key</kbd>. For bigger steps combine these combination with a further <kbd>ctrl</kbd>.
3335

36+
Furthermore, I introduced in Version 0.3.0 the ability to extend existing g-code files. Simply press
37+
- <kbd>1</kbd> for `G1` mode
38+
- <kbd>2</kbd> for `G2` mode
39+
- <kbd>3</kbd> for `G3` mode
40+
- <kbd>0</kbd> to exit the modes
41+
42+
and choose the coordinate with a left mouse click. One also can now undo and redo these added commands with <kbd>Z</kbd> and <kbd>Y</kbd> and save these changes to a new file with <kbd>S</kbd>. <kbd>P</kbd> changes the penmode and <kbd>H</kbd> returns to to home.
43+
44+
Last but not least, right-clicking prints the mouse coordinates to console.
45+
3446
## Room to improve
3547

3648
While the app can be used for many purposes, it is in a early development phase. Tests are missing and not everything is programmed the clever way. If you want to improve it feel welcome to contribute.
@@ -39,5 +51,5 @@ TODO:
3951
- [ ] better loop management for hot reloading
4052
- [ ] more file maniplulation features
4153
- [ ] move in grid support
42-
- [ ] draw mode?
43-
- [ ] more debug options, e.g. show coordinates
54+
- [X] draw mode?
55+
- [ ] more debug options, e.g. show coordinates

src/main.rs

Lines changed: 260 additions & 12 deletions
Large diffs are not rendered by default.

src/old_parse.rs

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/parse.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum GCodeExpr<'a> {
1414

1515
/// without Comments, for faster and more memory efficient usecases
1616
#[allow(non_snake_case)]
17+
#[derive(Copy, Clone)]
1718
pub enum CommentlessGCodeExpr {
1819
Home,
1920
Move { X: f32, Y: f32 },
@@ -47,6 +48,21 @@ impl GCodeExpr<'_> {
4748
}
4849
}
4950

51+
impl CommentlessGCodeExpr {
52+
pub fn as_str(&self) -> String {
53+
match self {
54+
CommentlessGCodeExpr::Home => "G28".to_string(),
55+
CommentlessGCodeExpr::Move{X: x, Y: y} => format!("G1 X{} Y{}", x, y),
56+
CommentlessGCodeExpr::Arc{CLKW: clkw, X: x, Y: y, I: i, J: j} => if *clkw {
57+
format!("G2 X{} Y{} I{} J{}", x, y, i, j)
58+
} else {
59+
format!("G3 X{} Y{} I{} J{}", x, y, i, j)
60+
},
61+
CommentlessGCodeExpr::Pen(down) => if *down { "M280 P0 S50".to_string() } else { "M280 P0 S0".to_string() },
62+
}
63+
}
64+
}
65+
5066
#[derive(Parser)]
5167
#[grammar = "gcode.pest"]
5268
struct GCodeParser;
@@ -138,4 +154,15 @@ pub fn save(filename: &str, commands: Vec<(usize, GCodeExpr)>) {
138154
})
139155
//collect::<Vec<String>>().join("\n")
140156
).expect("Unable to save the gcode.");
157+
}
158+
159+
/// saves new commands on tope
160+
pub fn resave(filename: &str, commands: &Vec<CommentlessGCodeExpr>) {
161+
let oldfile = std::fs::read_to_string(filename).expect("unable to open the file.");
162+
std::fs::write(
163+
format!("{}_added.gcode", filename.strip_suffix(".gcode").expect("Expected gcode file")),
164+
format!("{}\n; added by gcodeplot\n{}", oldfile,
165+
commands.iter().map(|cmd| cmd.as_str()).collect::<Vec<String>>().join("\n")
166+
)
167+
).expect("Unable to save the gcode.");
141168
}

test.gcode

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
G28
2+
G1 X10 Y10
3+
G1 X20 Y28
4+
M280 P0 S50
5+
G3 X18 Y30 I-2 J0
6+
G1 X14 Y30
7+
G3 X10 Y26 I0 J-4
8+
G1 X10 Y21
9+
G3 X11 Y20 I1 J0
10+
G1 X15 Y20
11+
G3 X17 Y22 I0 J2
12+
G1 X17 Y18
13+
G3 X15 Y20 I-2 J0
14+
M280 P0 S0
15+
G1 X11 Y20
16+
M280 P0 S50
17+
G3 X10 Y19 I0 J-1
18+
G1 X10 Y14
19+
G3 X14 Y10 I4 J0
20+
G1 X18 Y10
21+
G3 X20 Y12 I0 J2

test_added.gcode

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
G28
2+
G1 X10 Y10
3+
G1 X20 Y28
4+
M280 P0 S50
5+
G3 X18 Y30 I-2 J0
6+
G1 X14 Y30
7+
G3 X10 Y26 I0 J-4
8+
G1 X10 Y21
9+
G3 X11 Y20 I1 J0
10+
G1 X15 Y20
11+
G3 X17 Y22 I0 J2
12+
G1 X17 Y18
13+
G3 X15 Y20 I-2 J0
14+
M280 P0 S0
15+
G1 X11 Y20
16+
M280 P0 S50
17+
G3 X10 Y19 I0 J-1
18+
G1 X10 Y14
19+
G3 X14 Y10 I4 J0
20+
G1 X18 Y10
21+
G3 X20 Y12 I0 J2
22+
; added by gcodeplot
23+
G1 X25 Y15
24+
G1 X30 Y10
25+
G2 X35 Y15 I5 J0
26+
G2 X30 Y20 I0 J5

0 commit comments

Comments
 (0)