Browse Source

Add pen querying

Kevin Lee 4 months ago
parent
commit
d7a776caee
5 changed files with 89 additions and 7 deletions
  1. 10 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 15 7
      README.md
  4. 14 0
      src/ezcad/pen.rs
  5. 49 0
      src/main.rs

+ 10 - 0
Cargo.lock

@@ -255,6 +255,15 @@ version = "0.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
 
+[[package]]
+name = "human-repr"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f58b778a5761513caf593693f8951c97a5b610841e754788400f32102eefdff1"
+dependencies = [
+ "serde",
+]
+
 [[package]]
 name = "humantime"
 version = "2.1.0"
@@ -330,6 +339,7 @@ dependencies = [
  "clap-verbosity-flag",
  "diff-struct",
  "env_logger",
+ "human-repr",
  "itertools",
  "log",
  "modular-bitfield",

+ 1 - 0
Cargo.toml

@@ -19,6 +19,7 @@ clap = { version = "4.4.11", features = ["derive"] }
 clap-verbosity-flag = "2.1.1"
 diff-struct = "0.5.3"
 env_logger = "0.10.1"
+human-repr = { version = "1.1.0", features = ["serde"] }
 itertools = "0.12.0"
 log = "0.4.20"
 modular-bitfield = "0.11.2"

+ 15 - 7
README.md

@@ -3,19 +3,27 @@
 This tool parses and patches Minilase EZCAD save files with values specified in a YAML config file.
 The EZCAD format as implemented in this crate was reverse engineered from sample files, so not all formats or options are supported.
 
+TODO:
+
+* Write settings to output file by default
+* Figure out some sort of formula to sweep power density
+
 ## Usage
 
 ``` text
 Usage: minilase.exe [OPTIONS] --input <INPUT>
 
 Options:
-  -i, --input <INPUT>    Input file to parse
-  -d, --diff <DIFF>      File to diff input against
-  -o, --output <OUTPUT>  Output file to write to
-  -c, --config <CONFIG>  Configuration file
-  -v, --verbose...       Increase logging verbosity
-  -q, --quiet...         Decrease logging verbosity
-  -h, --help             Print help
+  -i, --input <INPUT>                Input file to parse
+  -d, --diff <DIFF>                  File to diff input against
+  -o, --output <OUTPUT>              Output file to write to
+  -c, --config <CONFIG>              Configuration file
+  -p, --pen <PEN>                    Print pen info
+  -l, --object-layer <OBJECT_LAYER>  Layer of object to print info
+  -b, --object <OBJECT>              Print object info
+  -v, --verbose...                   Increase logging verbosity
+  -q, --quiet...                     Decrease logging verbosity
+  -h, --help                         Print help
 ```
 
 ## Configuration File

+ 14 - 0
src/ezcad/pen.rs

@@ -7,6 +7,7 @@ use std::{
 
 use binrw::{BinRead, BinWrite, BinWriterExt, FilePtr64};
 use diff::Diff;
+use human_repr::HumanCount;
 use log::{error, warn};
 
 use crate::{
@@ -171,6 +172,19 @@ impl Pen {
     }
 }
 
+impl std::fmt::Display for Pen {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(
+            f,
+            "Speed: {}mm/s, Frequency: {}, Power: {}%, Pulse Width: {}ns",
+            self.speed,
+            self.frequency.human_count("Hz"),
+            self.power,
+            self.pulse_width
+        )
+    }
+}
+
 // Custom Debug implementation to only print known fields
 #[cfg(not(feature = "default-debug"))]
 impl Debug for Pen {

+ 49 - 0
src/main.rs

@@ -35,6 +35,18 @@ struct Cli {
     #[arg(short, long)]
     config: Option<PathBuf>,
 
+    /// Print pen info
+    #[arg(short, long)]
+    pen: Option<Vec<usize>>,
+
+    // /// Layer of object to print info
+    // #[arg(short = 'l', long, requires = "object")]
+    // object_layer: Option<usize>,
+
+    // /// Print object info
+    // #[arg(short = 'b', long)]
+    // object: Option<usize>,
+
     #[command(flatten)]
     verbose: Verbosity<InfoLevel>,
 }
@@ -101,6 +113,43 @@ fn main() {
         }
     }
 
+    // Process pen query
+    cli.pen.map(|index| {
+        for pen in index {
+            info!(
+                "Pen #{}: {}",
+                pen,
+                file.pens_offset
+                    .data
+                    .pens
+                    .get(pen)
+                    .expect("Invalid pen index")
+            );
+        }
+    });
+
+    // Process object query
+    // cli.object.map(|obj_index| {
+    //     let layer_index: usize = cli.object_layer.unwrap_or(0);
+    //     let layer: &Layer = file
+    //         .layers_offset
+    //         .get(layer_index)
+    //         .expect("Invalid layer index");
+    //     let object: &Object = layer.objects.get(obj_index).expect("Invalid object index");
+    //     info!("Layer {}, Object {}: {:?}", layer_index, obj_index, object);
+    //     let pen_index: u32 = object.get_pen();
+    //     trace!(
+    //         "Pen #{}: {}",
+    //         pen_index,
+    //         file.pens_offset
+    //             .data
+    //             .pens
+    //             .get(pen_index as usize)
+    //             .expect("Invalid pen index in object")
+    //     );
+    //     // TODO: object info
+    // });
+
     // Process diff
     cli.diff.map(|diff| {
         info!("Processing diff file '{}'", diff.to_string_lossy());