ソースを参照

Cleanup debug formatting

Kevin Lee 1 年間 前
コミット
d93882867e

+ 16 - 1
src/ezcad/objects/circle.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite};
 
 use crate::{
@@ -7,7 +9,7 @@ use crate::{
 
 use super::ObjectCore;
 
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 pub struct Circle {
     pub core: ObjectCore,
     #[brw(magic(6u32))] // Number of following fields in struct
@@ -17,3 +19,16 @@ pub struct Circle {
     pub clockwise: U32,
     _unknown_1: [Field; 2],
 }
+
+// Custom Debug implementation to only print known fields
+impl Debug for Circle {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("Circle")
+            .field("core", &self.core)
+            .field("origin", &self.origin)
+            .field("radius", &self.radius)
+            .field("start_angle", &self.start_angle)
+            .field("clockwise", &self.clockwise)
+            .finish()
+    }
+}

+ 18 - 1
src/ezcad/objects/ellipse.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite};
 
 use crate::{
@@ -7,7 +9,7 @@ use crate::{
 
 use super::ObjectCore;
 
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 pub struct Ellipse {
     pub core: ObjectCore,
     #[brw(magic(8u32))] // Number of following fields in struct
@@ -19,3 +21,18 @@ pub struct Ellipse {
     _unknown_1: [Field; 2],
     pub open_curve: U32,
 }
+
+// Custom Debug implementation to only print known fields
+impl Debug for Ellipse {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("Ellipse")
+            .field("core", &self.core)
+            .field("clockwise", &self.clockwise)
+            .field("corner_a", &self.corner_a)
+            .field("corner_b", &self.corner_b)
+            .field("start_angle", &self.start_angle)
+            .field("end_angle", &self.end_angle)
+            .field("open_curve", &self.open_curve)
+            .finish()
+    }
+}

+ 62 - 3
src/ezcad/objects/hatch.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite};
 use modular_bitfield::{
     bitfield,
@@ -36,7 +38,7 @@ pub struct HatchLine {
     lines: ArrayOf<Lines>,
 }
 
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 #[brw(magic(46u32))] // Number of fields in this struct
 pub struct HatchSettings1 {
     pub mark_contour: U32,
@@ -62,7 +64,29 @@ pub struct HatchSettings1 {
     _unknown_7: [Field; 3],
 }
 
-#[derive(BinRead, BinWrite, Debug)]
+// Custom Debug implementation to only print known fields
+impl Debug for HatchSettings1 {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("HatchSettings1")
+            .field("mark_contour", &self.mark_contour)
+            .field("pen", &self.pen)
+            .field("flags", &self.flags)
+            .field("edge_offset", &self.edge_offset)
+            .field("line_spacing", &self.line_spacing)
+            .field("start_offset", &self.start_offset)
+            .field("end_offset", &self.end_offset)
+            .field("angle", &self.angle)
+            .field("auto_rotate_angle", &self.auto_rotate_angle)
+            .field("line_reduction", &self.line_reduction)
+            .field("loop_count", &self.loop_count)
+            .field("loop_distance", &self.loop_distance)
+            .field("contour_first", &self.contour_first)
+            .field("count", &self.count)
+            .finish()
+    }
+}
+
+#[derive(BinRead, BinWrite)]
 #[brw(magic(15u32))] // Number of fields in this struct
 pub struct HatchSettings2 {
     pub count: U32,
@@ -81,7 +105,27 @@ pub struct HatchSettings2 {
     _unknown_2: [Field; 2],
 }
 
-#[derive(BinRead, BinWrite, Debug)]
+// Custom Debug implementation to only print known fields
+impl Debug for HatchSettings2 {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("HatchSettings2")
+            .field("count", &self.count)
+            .field("pen", &self.pen)
+            .field("flags", &self.flags)
+            .field("edge_offset", &self.edge_offset)
+            .field("line_spacing", &self.line_spacing)
+            .field("start_offset", &self.start_offset)
+            .field("end_offset", &self.end_offset)
+            .field("angle", &self.angle)
+            .field("auto_rotate_angle", &self.auto_rotate_angle)
+            .field("line_reduction", &self.line_reduction)
+            .field("loop_distance", &self.loop_distance)
+            .field("loop_count", &self.loop_count)
+            .finish()
+    }
+}
+
+#[derive(BinRead, BinWrite)]
 pub struct Hatch {
     pub core: ObjectCore,
     pub outline: ArrayOf<Object>,
@@ -97,3 +141,18 @@ pub struct Hatch {
     _unknown_6: [Field; 13],
     pub lines: ArrayOf<HatchLine>,
 }
+
+// Custom Debug implementation to only print known fields
+impl Debug for Hatch {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("Hatch")
+            .field("core", &self.core)
+            .field("outline", &self.outline)
+            .field("settings_1", &self.settings_1)
+            .field("settings_2", &self.settings_2)
+            .field("pen", &self.pen)
+            .field("name", &self.name)
+            .field("lines", &self.lines)
+            .finish()
+    }
+}

+ 21 - 1
src/ezcad/objects/mod.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite};
 use modular_bitfield::{
     bitfield,
@@ -33,7 +35,7 @@ pub struct ObjectFlags {
 }
 
 /// Core properties defined for all object types
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 #[brw(magic(17u32))]
 pub struct ObjectCore {
     pub pen: U32,
@@ -51,6 +53,24 @@ pub struct ObjectCore {
     _unknown_3: Field,
 }
 
+// Custom Debug implementation to only print known fields
+impl Debug for ObjectCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("ObjectCore")
+            .field("pen", &self.pen)
+            .field("obj_type", &self.obj_type)
+            .field("flags", &self.flags)
+            .field("name", &self.name)
+            .field("count", &self.count)
+            .field("io_control_enable_mask", &self.io_control_enable_mask)
+            .field("io_control_disable_mask", &self.io_control_disable_mask)
+            .field("origin", &self.origin)
+            .field("z", &self.z)
+            .field("a", &self.a)
+            .finish()
+    }
+}
+
 #[derive(BinRead, BinWrite, Debug)]
 pub enum Object {
     #[brw(magic = 1u32)]

+ 20 - 1
src/ezcad/objects/polygon.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite};
 
 use crate::{
@@ -7,7 +9,7 @@ use crate::{
 
 use super::ObjectCore;
 
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 pub struct Polygon {
     pub core: ObjectCore,
     #[brw(magic(10u32))] // Number of following fields in struct
@@ -21,3 +23,20 @@ pub struct Polygon {
     pub edges: U32,
     _unknown_1: [Field; 2],
 }
+
+// Custom Debug implementation to only print known fields
+impl Debug for Polygon {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("Polygon")
+            .field("core", &self.core)
+            .field("invert_shape", &self.invert_shape)
+            .field("corner_a", &self.corner_a)
+            .field("corner_b", &self.corner_b)
+            .field("offset_cx", &self.offset_cx)
+            .field("offset_cy", &self.offset_cy)
+            .field("offset_dx", &self.offset_dx)
+            .field("offset_dy", &self.offset_dy)
+            .field("edges", &self.edges)
+            .finish()
+    }
+}

+ 18 - 1
src/ezcad/objects/rectangle.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite};
 
 use crate::{
@@ -7,7 +9,7 @@ use crate::{
 
 use super::ObjectCore;
 
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 pub struct Rectangle {
     pub core: ObjectCore,
     #[brw(magic(8u32))] // Number of following fields in struct
@@ -19,3 +21,18 @@ pub struct Rectangle {
     pub round_top_left: F64,
     _unknown_1: [Field; 2],
 }
+
+// Custom Debug implementation to only print known fields
+impl Debug for Rectangle {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("Rectangle")
+            .field("core", &self.core)
+            .field("corner_a", &self.corner_a)
+            .field("corner_b", &self.corner_b)
+            .field("round_bottom_left", &self.round_bottom_left)
+            .field("round_bottom_right", &self.round_bottom_right)
+            .field("round_top_right", &self.round_top_right)
+            .field("round_top_left", &self.round_top_left)
+            .finish()
+    }
+}

+ 35 - 1
src/ezcad/pen.rs

@@ -1,3 +1,5 @@
+use std::fmt::Debug;
+
 use binrw::{BinRead, BinWrite, FilePtr64};
 
 use crate::{
@@ -45,7 +47,7 @@ pub struct Pens {
     pub pens: Vec<Pen>,
 }
 
-#[derive(BinRead, BinWrite, Debug)]
+#[derive(BinRead, BinWrite)]
 #[brw(magic(236u32))] // Number of fields within this struct
 pub struct Pen {
     pub color: FieldOf<Rgba>,
@@ -81,3 +83,35 @@ pub struct Pen {
     pub wobble_diameter_2: F64, // Only with wobble type ellipse
     _unknown_8: [Field; 26],
 }
+
+// Custom Debug implementation to only print known fields
+impl Debug for Pen {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("Pen")
+            .field("color", &self.color)
+            .field("name", &self.name)
+            .field("disabled", &self.disabled)
+            .field("use_default", &self.use_default)
+            .field("loop_count", &self.loop_count)
+            .field("speed", &self.speed)
+            .field("power", &self.power)
+            .field("frequency", &self.frequency)
+            .field("start_tc", &self.start_tc)
+            .field("end_tc", &self.end_tc)
+            .field("polygon_tc", &self.polygon_tc)
+            .field("jump_speed", &self.jump_speed)
+            .field("laser_off_tc", &self.laser_off_tc)
+            .field("wave", &self.wave)
+            .field("wobble_enable", &self.wobble_enable)
+            .field("wobble_diameter", &self.wobble_diameter)
+            .field("wobble_distance", &self.wobble_distance)
+            .field("min_jump_tc", &self.min_jump_tc)
+            .field("max_jump_tc", &self.max_jump_tc)
+            .field("jump_limit", &self.jump_limit)
+            .field("frequency_2", &self.frequency_2)
+            .field("wobble_type", &self.wobble_type)
+            .field("continue_mode", &self.continue_mode)
+            .field("wobble_diameter_2", &self.wobble_diameter_2)
+            .finish()
+    }
+}