Kevin Lee před 1 rokem
rodič
revize
259c2f40ef

+ 28 - 0
Cargo.lock

@@ -195,6 +195,7 @@ dependencies = [
  "clap-verbosity-flag",
  "env_logger",
  "log",
+ "modular-bitfield",
  "strum",
 ]
 
@@ -251,6 +252,27 @@ version = "2.6.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
 
+[[package]]
+name = "modular-bitfield"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a53d79ba8304ac1c4f9eb3b9d281f21f7be9d4626f72ce7df4ad8fbde4f38a74"
+dependencies = [
+ "modular-bitfield-impl",
+ "static_assertions",
+]
+
+[[package]]
+name = "modular-bitfield-impl"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a7d5f7076603ebc68de2dc6a650ec331a062a13abaa346975be747bbfa4b789"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
 [[package]]
 name = "owo-colors"
 version = "3.5.0"
@@ -323,6 +345,12 @@ version = "1.0.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
 
+[[package]]
+name = "static_assertions"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+
 [[package]]
 name = "strsim"
 version = "0.10.0"

+ 1 - 0
Cargo.toml

@@ -19,4 +19,5 @@ clap = { version = "4.4.11", features = ["derive"] }
 clap-verbosity-flag = "2.1.1"
 env_logger = "0.10.1"
 log = "0.4.20"
+modular-bitfield = "0.11.2"
 strum = { version = "0.25.0", features = ["derive"] }

+ 8 - 4
src/ezcad/objects/circle.rs

@@ -7,21 +7,25 @@ use crate::{
     types::{Field, Point, F64, U32},
 };
 
-use super::ObjBase;
+use super::ObjectBase;
 
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Circle {
-    pub base: ObjBase,
+    pub base: ObjectBase,
     #[brw(magic(6u32))] // Number of following fields in struct
     pub origin: FieldOf<Point>,
     pub radius: F64,
-    pub start_angle: F64,
+    pub start_angle: F64, // Radians
     pub clockwise: U32,
     _unknown_1: [Field; 2],
 }
 
 impl Display for Circle {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.base)
+        write!(
+            f,
+            "{} origin: {}, radius: {:.2}, start_angle: {:.2}, clockwise: {}",
+            self.base, *self.origin, *self.radius, *self.start_angle, *self.clockwise
+        )
     }
 }

+ 15 - 5
src/ezcad/objects/ellipse.rs

@@ -7,23 +7,33 @@ use crate::{
     types::{Field, Point, F64, U32},
 };
 
-use super::ObjBase;
+use super::ObjectBase;
 
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Ellipse {
-    pub base: ObjBase,
+    pub base: ObjectBase,
     #[brw(magic(8u32))] // Number of following fields in struct
     pub clockwise: U32,
     pub corner_a: FieldOf<Point>,
     pub corner_b: FieldOf<Point>,
-    pub start_angle: F64,
-    pub end_angle: F64,
+    pub start_angle: F64, // Radians
+    pub end_angle: F64,   // Radians
     _unknown_1: [Field; 2],
     pub open_curve: U32,
 }
 
 impl Display for Ellipse {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.base)
+        write!(
+            f,
+            "{} corners: {{{}, {}}}, start angle: {:.2}, end angle: {:.2}, clockwise: {}, open: {}",
+            self.base,
+            *self.corner_a,
+            *self.corner_b,
+            *self.start_angle,
+            *self.end_angle,
+            *self.clockwise,
+            *self.open_curve
+        )
     }
 }

+ 11 - 3
src/ezcad/objects/line.rs

@@ -4,7 +4,7 @@ use binrw::{BinRead, BinWrite};
 
 use crate::{array_of::ArrayOf, types::Point};
 
-use super::ObjBase;
+use super::ObjectBase;
 
 #[derive(BinRead, BinWrite, Debug)]
 pub enum LineType {
@@ -18,12 +18,20 @@ pub enum LineType {
 
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Lines {
-    pub base: ObjBase,
+    pub base: ObjectBase,
     pub lines: ArrayOf<LineType>,
 }
 
 impl Display for Lines {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.base)
+        write!(f, "{} ", self.base)?;
+        for line in self.lines.iter() {
+            match line {
+                LineType::Point(x) => write!(f, "point: {}", x)?,
+                LineType::Line { points } => todo!(),
+                LineType::Bezier { points } => todo!(),
+            }
+        }
+        Ok(())
     }
 }

+ 29 - 4
src/ezcad/objects/mod.rs

@@ -1,6 +1,10 @@
 use std::fmt::Display;
 
 use binrw::{BinRead, BinWrite};
+use modular_bitfield::{
+    bitfield,
+    specifiers::{B1, B14},
+};
 
 use crate::{
     field_of::FieldOf,
@@ -16,12 +20,23 @@ pub mod line;
 pub mod polygon;
 pub mod rectangle;
 
+#[bitfield(bits = 16)]
+#[derive(BinRead, BinWrite, Debug, Copy, Clone)]
+#[br(map = Self::from_bytes)]
+#[bw(map = |&x| Self::into_bytes(x))]
+pub struct ObjectFlags {
+    pub disabled: B1,
+    pub aspect_ratio_unlocked: B1,
+    #[skip]
+    __: B14,
+}
+
 #[derive(BinRead, BinWrite, Debug)]
 #[brw(magic(17u32))]
-pub struct ObjBase {
+pub struct ObjectBase {
     pub pen: U32,
     pub obj_type: FieldOf<ObjectType>,
-    pub flags: U16,
+    pub flags: FieldOf<ObjectFlags>,
     pub name: WString,
     pub count: U32,
     _unknown_1: Field,
@@ -34,9 +49,19 @@ pub struct ObjBase {
     _unknown_3: Field,
 }
 
-impl Display for ObjBase {
+impl Display for ObjectBase {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        f.write_fmt(format_args!("[{}]", self.obj_type))
+        write!(
+            f,
+            "[{} = disabled: {}, locked: {}, count: {}, origin: {}, z: {:.2}, a: {:.2}]",
+            *self.obj_type,
+            self.flags.disabled() != 0,
+            self.flags.aspect_ratio_unlocked() != 0,
+            *self.count,
+            *self.origin,
+            *self.z,
+            *self.a,
+        )
     }
 }
 

+ 15 - 3
src/ezcad/objects/polygon.rs

@@ -7,11 +7,11 @@ use crate::{
     types::{Field, Point, F64, U32},
 };
 
-use super::ObjBase;
+use super::ObjectBase;
 
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Polygon {
-    pub base: ObjBase,
+    pub base: ObjectBase,
     #[brw(magic(10u32))] // Number of following fields in struct
     pub invert_shape: U32,
     pub corner_a: FieldOf<Point>,
@@ -26,6 +26,18 @@ pub struct Polygon {
 
 impl Display for Polygon {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.base)
+        write!(
+            f,
+            "{} corners: {{{}, {}}}, offsets: ({:.2}, {:.2}, {:.2}, {:.2}), edges: {}, invert: {}",
+            self.base,
+            *self.corner_a,
+            *self.corner_b,
+            *self.offset_cx,
+            *self.offset_cy,
+            *self.offset_dx,
+            *self.offset_dy,
+            *self.edges,
+            *self.invert_shape
+        )
     }
 }

+ 13 - 3
src/ezcad/objects/rectangle.rs

@@ -7,11 +7,11 @@ use crate::{
     types::{Field, Point, F64},
 };
 
-use super::ObjBase;
+use super::ObjectBase;
 
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Rectangle {
-    pub base: ObjBase,
+    pub base: ObjectBase,
     #[brw(magic(8u32))] // Number of following fields in struct
     pub corner_a: FieldOf<Point>,
     pub corner_b: FieldOf<Point>,
@@ -24,6 +24,16 @@ pub struct Rectangle {
 
 impl Display for Rectangle {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", self.base)
+        write!(
+            f,
+            "{} corners: {{{}, {}}}, rounding: ({:.2}, {:.2}, {:.2}, {:.2})",
+            self.base,
+            *self.corner_a,
+            *self.corner_b,
+            *self.round_top_left,
+            *self.round_top_right,
+            *self.round_bottom_left,
+            *self.round_bottom_right
+        )
     }
 }

+ 1 - 1
src/ezcad/types.rs

@@ -70,7 +70,7 @@ pub struct Point {
 
 impl Display for Point {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "({}, {})", self.x, self.y)
+        write!(f, "({:.2}, {:.2})", self.x, self.y)
     }
 }