Skip to content

Commit

Permalink
options for line numbers and checksums, closes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Jun 1, 2023
1 parent 99cde4a commit 2d9fa03
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 73 deletions.
49 changes: 23 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 38 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ struct Opt {
/// Please check if your machine supports G2/G3 commands before enabling this.
#[structopt(long)]
circular_interpolation: Option<bool>,

#[structopt(long)]
/// Include line numbers at the beginning of each line
///
/// Useful for debugging/streaming g-code
line_numbers: Option<bool>,
#[structopt(long)]
/// Include checksums at the end of each line
///
/// Useful for streaming g-code
checksums: Option<bool>,
}

fn main() -> io::Result<()> {
Expand Down Expand Up @@ -128,6 +139,15 @@ fn main() -> io::Result<()> {
}
}
}

if let Some(line_numbers) = opt.line_numbers {
settings.postprocess.line_numbers = line_numbers;
}

if let Some(checksums) = opt.checksums {
settings.postprocess.checksums = checksums;
}

settings
};

Expand Down Expand Up @@ -253,8 +273,24 @@ fn main() -> io::Result<()> {
let program = svg2program(&document, &settings.conversion, options, machine);

if let Some(out_path) = opt.out {
format_gcode_io(&program, FormatOptions::default(), File::create(out_path)?)
format_gcode_io(
&program,
FormatOptions {
line_numbers: settings.postprocess.line_numbers,
checksums: settings.postprocess.checksums,
..Default::default()
},
File::create(out_path)?,
)
} else {
format_gcode_io(&program, FormatOptions::default(), std::io::stdout())
format_gcode_io(
&program,
FormatOptions {
line_numbers: settings.postprocess.line_numbers,
checksums: settings.postprocess.checksums,
..Default::default()
},
std::io::stdout(),
)
}
}
4 changes: 2 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "svg2gcode"
version = "0.1.1"
version = "0.1.2"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Convert paths in SVG files to GCode for a pen plotter, laser engraver, or other machine."
repository = "https://github.com/sameer/svg2gcode"
license = "MIT"

[dependencies]
g-code = { version = "0.3.4", features = ["serde"] }
g-code = { version = "0.3.5", features = ["serde"] }
lyon_geom = "1.0.4"
euclid = "0.22"
log = "0.4"
Expand Down
53 changes: 53 additions & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,57 @@ mod test {
"#;
serde_json::from_str::<Settings>(json).unwrap();
}

#[test]
#[cfg(feature = "serde")]
fn deserialize_v2_config_succeeds() {
let json = r#"
{
"conversion": {
"tolerance": 0.002,
"feedrate": 300.0,
"dpi": 96.0
},
"machine": {
"supported_functionality": {
"circular_interpolation": true
},
"tool_on_sequence": null,
"tool_off_sequence": null,
"begin_sequence": null,
"end_sequence": null
},
"postprocess": { }
}
"#;
serde_json::from_str::<Settings>(json).unwrap();
}

#[test]
#[cfg(feature = "serde")]
fn deserialize_v3_config_succeeds() {
let json = r#"
{
"conversion": {
"tolerance": 0.002,
"feedrate": 300.0,
"dpi": 96.0
},
"machine": {
"supported_functionality": {
"circular_interpolation": true
},
"tool_on_sequence": null,
"tool_off_sequence": null,
"begin_sequence": null,
"end_sequence": null
},
"postprocess": {
"checksums": false,
"line_numbers": false
}
}
"#;
serde_json::from_str::<Settings>(json).unwrap();
}
}
9 changes: 8 additions & 1 deletion lib/src/postprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ use serde::{Deserialize, Serialize};

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct PostprocessConfig {}
pub struct PostprocessConfig {
/// Convenience field for [g_code::emit::FormatOptions] field
#[cfg_attr(feature = "serde", serde(default))]
pub checksums: bool,
/// Convenience field for [g_code::emit::FormatOptions] field
#[cfg_attr(feature = "serde", serde(default))]
pub line_numbers: bool,
}
4 changes: 2 additions & 2 deletions web/src/forms/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ form_input! {
}
OriginX {
"Origin X",
"X-axis coordinate for the bottom left corner of the machine",
"X-axis coordinate for the lower left corner of the machine",
origin => 0,
settings.conversion.origin => 0,
}
OriginY {
"Origin Y",
"Y-axis coordinate for the bottom left corner of the machine",
"Y-axis coordinate for the lower left corner of the machine",
origin => 1,
settings.conversion.origin => 1,
}
Expand Down
Loading

0 comments on commit 2d9fa03

Please sign in to comment.