Skip to content
Merged
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
15 changes: 4 additions & 11 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ struct Opt {
///
/// Workaround for parsers that don't accept comments on the same line
newline_before_comment: Option<bool>,
#[arg(long)]
/// When printing a node name , print a extra attribute
///
/// Useful to print the label of layer on SVG generated by Inkscape
extra_attribute_name: Option<String>,
}

fn main() -> io::Result<()> {
Expand Down Expand Up @@ -160,6 +165,8 @@ fn main() -> io::Result<()> {
settings.postprocess.newline_before_comment = newline_before_comment;
}

settings.conversion.extra_attribute_name = opt.extra_attribute_name ;

if let Version::Unknown(ref unknown) = settings.version {
error!(
"Your settings use an unknown version. Your version: {unknown}, latest: {}. See {} to download the latest CLI version.",
Expand Down
16 changes: 14 additions & 2 deletions lib/src/converter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct ConversionConfig {
/// Set the origin point in millimeters for this conversion
#[cfg_attr(feature = "serde", serde(default = "zero_origin"))]
pub origin: [Option<f64>; 2],
/// Set extra attribute to add when printing node name
pub extra_attribute_name: Option<String>,
}

const fn zero_origin() -> [Option<f64>; 2] {
Expand All @@ -45,6 +47,7 @@ impl Default for ConversionConfig {
feedrate: 300.0,
dpi: 96.0,
origin: zero_origin(),
extra_attribute_name : None,
}
}
}
Expand Down Expand Up @@ -80,7 +83,7 @@ impl<'a, T: Turtle> ConversionVisitor<'a, T> {
comment += name;
comment += " > ";
});
comment += &node_name(node);
comment += &node_name(node,&self._config.extra_attribute_name);

self.terrarium.turtle.comment(comment);
}
Expand Down Expand Up @@ -171,11 +174,20 @@ pub fn svg2program<'a, 'input: 'a>(
conversion_visitor.terrarium.turtle.inner.program
}

fn node_name(node: &Node) -> String {
fn node_name(node: &Node , attr_to_print : &Option<String> ) -> String {
let mut name = node.tag_name().name().to_string();
if let Some(id) = node.attribute("id") {
name += "#";
name += id;
if let Some(extra_attr_to_print) = attr_to_print {
for a_attr in node.attributes() {
if a_attr.name() == extra_attr_to_print {
name += " ( ";
name += a_attr.value() ;
name += " ) ";
}
}
}
}
name
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/converter/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl<'a, T: Turtle> XmlVisitor for ConversionVisitor<'a, T> {
}
}

self.name_stack.push(node_name(&node));
self.name_stack.push(node_name(&node,&self._config.extra_attribute_name));
}

fn visit_exit(&mut self, node: Node) {
Expand Down
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ thiserror = "1.0"
zip = { version = "0.6", default-features = false }

yew = { version = "0.21", features = ["csr"] }
yewdux = "0.10"
yewdux = "0.11"
web-sys = { version = "0.3", features = [] }
wasm-logger = "0.2"
gloo-file = { version = "0.3", features = ["futures"] }
Expand Down
1 change: 1 addition & 0 deletions web/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl<'a> TryInto<Settings> for &'a FormState {
self.origin[0].clone().transpose()?,
self.origin[1].clone().transpose()?,
],
extra_attribute_name: None,
},
machine: MachineConfig {
supported_functionality: SupportedFunctionality {
Expand Down
Loading