Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ struct Opt {
/// Useful to print the label of layer on SVG generated by Inkscape
extra_attribute_name: Option<String>,
#[arg(long)]
/// Z height for rapid travel moves (pen/tool raised position)
z_travel: Option<f64>,
#[arg(long)]
/// Z height for drawing moves (pen/tool lowered position)
z_path: Option<f64>,
#[arg(long)]
/// Z height at maximum emphasis (deepest/most pressure, for thick strokes)
z_emphasis: Option<f64>,
#[arg(long)]
/// Stroke width in mm at which z_emphasis is fully applied; interpolates below
emphasis_stroke_width: Option<f64>,
#[arg(long)]
/// Reorder paths to minimize travel time
optimize_path_order: Option<bool>,
/// CSS selector to filter which SVG elements are converted.
Expand Down Expand Up @@ -202,6 +214,19 @@ fn main() -> io::Result<()> {
settings.postprocess.newline_before_comment = newline_before_comment;
}

if let Some(z_travel) = opt.z_travel {
settings.machine.z_travel = Some(z_travel);
}
if let Some(z_path) = opt.z_path {
settings.machine.z_path = Some(z_path);
}
if let Some(z_emphasis) = opt.z_emphasis {
settings.machine.z_emphasis = Some(z_emphasis);
}
if let Some(esw) = opt.emphasis_stroke_width {
settings.machine.emphasis_stroke_width = Some(esw);
}

settings.conversion.inner.extra_attribute_name = opt.extra_attribute_name;
if let Some(optimize_path_order) = opt.optimize_path_order {
settings.conversion.inner.optimize_path_order = optimize_path_order;
Expand Down Expand Up @@ -322,6 +347,10 @@ fn main() -> io::Result<()> {
tool_off_action,
program_begin_sequence,
program_end_sequence,
settings.machine.z_travel,
settings.machine.z_path,
settings.machine.z_emphasis,
settings.machine.emphasis_stroke_width,
)
} else {
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
Expand Down
12 changes: 12 additions & 0 deletions g_code/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ pub struct MachineConfig {
pub tool_off_sequence: Option<String>,
pub begin_sequence: Option<String>,
pub end_sequence: Option<String>,
/// Z coordinate for rapid travel moves (pen/tool raised position)
#[cfg_attr(feature = "serde", serde(default))]
pub z_travel: Option<f64>,
/// Z coordinate for drawing moves (pen/tool lowered)
#[cfg_attr(feature = "serde", serde(default))]
pub z_path: Option<f64>,
/// Z coordinate at maximum emphasis (deepest/most pressure, for thick strokes)
#[cfg_attr(feature = "serde", serde(default))]
pub z_emphasis: Option<f64>,
/// Stroke width in mm at which zemphasis is fully applied; interpolates below
#[cfg_attr(feature = "serde", serde(default))]
pub emphasis_stroke_width: Option<f64>,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down
12 changes: 12 additions & 0 deletions g_code/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub struct Machine<'input> {
program_end_sequence: Snippet<'input>,
/// Empty snippet used to provide the same iterator type when a sequence must be empty
empty_snippet: Snippet<'input>,
pub z_travel: Option<f64>,
pub z_path: Option<f64>,
pub z_emphasis: Option<f64>,
pub emphasis_stroke_width: Option<f64>,
}

impl<'input> Machine<'input> {
Expand All @@ -42,6 +46,10 @@ impl<'input> Machine<'input> {
tool_off_sequence: Option<Snippet<'input>>,
program_begin_sequence: Option<Snippet<'input>>,
program_end_sequence: Option<Snippet<'input>>,
z_travel: Option<f64>,
z_path: Option<f64>,
z_emphasis: Option<f64>,
emphasis_stroke_width: Option<f64>,
) -> Self {
let empty_snippet = snippet_parser("").expect("empty string is a valid snippet");
Self {
Expand All @@ -53,6 +61,10 @@ impl<'input> Machine<'input> {
empty_snippet,
tool_state: Default::default(),
distance_mode: Default::default(),
z_travel,
z_path,
z_emphasis,
emphasis_stroke_width,
}
}

Expand Down
8 changes: 8 additions & 0 deletions g_code/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ fn get_actual(
None,
None,
None,
None,
None,
None,
None,
);
svg_to_gcode(&document, &gcode_config, options, machine)
}
Expand Down Expand Up @@ -278,6 +282,10 @@ fn issue_105_optimize_path_order_does_not_shrink_output() {
None,
None,
None,
None,
None,
None,
None,
);
let normal = svg_to_gcode(
&document,
Expand Down
Loading