diff --git a/Cargo.lock b/Cargo.lock index 73ce848..f85e118 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,12 +75,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "anymap" -version = "1.0.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1f8f5a6f3d50d89e3797d7593a50f96bb2aaa20ca0cc7be1fb673232c91d72" - [[package]] name = "anymap2" version = "0.13.0" @@ -1938,11 +1932,10 @@ dependencies = [ [[package]] name = "yewdux" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f3154e906048f189b77b241ec4956cb1cf341637dc89a4d0a24701e5a762bb" +checksum = "8030a7de50678c07c038dcb96a42f1e8a7c4cc5610451fbee0c676aa7df42967" dependencies = [ - "anymap", "log", "serde", "serde_json", @@ -1956,9 +1949,9 @@ dependencies = [ [[package]] name = "yewdux-macros" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0701f8edd01519c953a9fcd3b88a2650a4351911f7492744e117d59f39f156c" +checksum = "e7ac6ccd84a49bbce44610d44eb6686a1266337d0cd3aeadb5564ab76a2819f0" dependencies = [ "darling", "proc-macro-error", diff --git a/cli/src/main.rs b/cli/src/main.rs index fed4399..b03dac1 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -86,6 +86,11 @@ struct Opt { /// /// Workaround for parsers that don't accept comments on the same line newline_before_comment: Option, + #[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, } fn main() -> io::Result<()> { @@ -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.", diff --git a/lib/src/converter/mod.rs b/lib/src/converter/mod.rs index 7bd175e..ff36bf7 100644 --- a/lib/src/converter/mod.rs +++ b/lib/src/converter/mod.rs @@ -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; 2], + /// Set extra attribute to add when printing node name + pub extra_attribute_name: Option, } const fn zero_origin() -> [Option; 2] { @@ -45,6 +47,7 @@ impl Default for ConversionConfig { feedrate: 300.0, dpi: 96.0, origin: zero_origin(), + extra_attribute_name : None, } } } @@ -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); } @@ -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 { 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 } diff --git a/lib/src/converter/visit.rs b/lib/src/converter/visit.rs index 9d834c0..eedfd81 100644 --- a/lib/src/converter/visit.rs +++ b/lib/src/converter/visit.rs @@ -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) { diff --git a/web/Cargo.toml b/web/Cargo.toml index b371b52..b87ed3c 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -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"] } diff --git a/web/src/state.rs b/web/src/state.rs index 452eaf6..dd98aa4 100644 --- a/web/src/state.rs +++ b/web/src/state.rs @@ -52,6 +52,7 @@ impl<'a> TryInto for &'a FormState { self.origin[0].clone().transpose()?, self.origin[1].clone().transpose()?, ], + extra_attribute_name: None, }, machine: MachineConfig { supported_functionality: SupportedFunctionality {