Kevin Lee 1 سال پیش
والد
کامیت
162d514c1e
4فایلهای تغییر یافته به همراه16 افزوده شده و 26 حذف شده
  1. 1 1
      src/ezcad/file.rs
  2. 2 1
      src/ezcad/layer.rs
  3. 11 22
      src/ezcad/object.rs
  4. 2 2
      src/main.rs

+ 1 - 1
src/ezcad/file.rs

@@ -1,6 +1,6 @@
 use binrw::{BinRead, BinWrite, FilePtr64};
 
-use crate::{layer::Layer, pen::PenHeader, types::Rgba, array_of::ArrayOf};
+use crate::{array_of::ArrayOf, layer::Layer, pen::PenHeader};
 
 #[derive(BinRead, Debug)]
 pub struct Header {

+ 2 - 1
src/ezcad/layer.rs

@@ -1,8 +1,9 @@
 use binrw::{BinRead, BinWrite};
 
 use crate::{
+    array_of::ArrayOf,
     object::Object,
-    types::{Field, WString, F64, U16, U32}, array_of::ArrayOf,
+    types::{Field, WString, F64, U16, U32},
 };
 
 // #[derive(BinRead, BinWrite, Debug)]

+ 11 - 22
src/ezcad/object.rs

@@ -1,8 +1,9 @@
 use binrw::{BinRead, BinWrite};
 
 use crate::{
+    array_of::ArrayOf,
     field_of::FieldOf,
-    types::{Field, ObjectType, Point, WString, F64, U32, U16},
+    types::{Field, ObjectType, Point, WString, F64, U16, U32},
 };
 
 #[derive(BinRead, BinWrite, Debug)]
@@ -10,17 +11,9 @@ pub enum LineType {
     #[brw(magic = 0x0001u64)]
     Point(Point),
     #[brw(magic = 0x0100u64)]
-    Line {
-        count: u32,
-        #[br(count = count)]
-        points: Vec<Point>,
-    },
+    Line { points: ArrayOf<Point> },
     #[brw(magic = 0x0300u64)]
-    Bezier {
-        count: u32,
-        #[br(count = count)]
-        points: Vec<Point>,
-    },
+    Bezier { points: ArrayOf<Point> },
 }
 
 #[derive(BinRead, BinWrite, Debug)]
@@ -44,16 +37,13 @@ pub struct ObjBase {
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Lines {
     pub base: ObjBase,
-    count: u64,
-    #[br(count = count)]
-    pub lines: Vec<LineType>,
+    pub lines: ArrayOf<LineType>,
 }
 
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Rectangle {
     pub base: ObjBase,
-    #[br(assert(field_count == 8))]
-    field_count: u32,
+    #[brw(magic(8u32))] // Number of following fields in struct
     pub corner_a: FieldOf<Point>,
     pub corner_b: FieldOf<Point>,
     pub round_bottom_left: F64,
@@ -66,8 +56,7 @@ pub struct Rectangle {
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Circle {
     pub base: ObjBase,
-    #[br(assert(field_count == 6))]
-    field_count: u32,
+    #[brw(magic(6u32))] // Number of following fields in struct
     pub origin: FieldOf<Point>,
     pub radius: F64,
     pub start_angle: F64,
@@ -78,8 +67,7 @@ pub struct Circle {
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Ellipse {
     pub base: ObjBase,
-    #[br(assert(field_count == 8))]
-    field_count: u32,
+    #[brw(magic(8u32))] // Number of following fields in struct
     pub clockwise: U32,
     pub corner_a: FieldOf<Point>,
     pub corner_b: FieldOf<Point>,
@@ -92,8 +80,7 @@ pub struct Ellipse {
 #[derive(BinRead, BinWrite, Debug)]
 pub struct Polygon {
     pub base: ObjBase,
-    #[br(assert(field_count == 10))]
-    field_count: u32,
+    #[brw(magic(10u32))] // Number of following fields in struct
     pub invert_shape: U32,
     pub corner_a: FieldOf<Point>,
     pub corner_b: FieldOf<Point>,
@@ -119,4 +106,6 @@ pub enum Object {
     Ellipse(Ellipse),
     #[brw(magic = 6u32)]
     Polygon(Polygon),
+    // #[brw(magic = 32u32)]
+    // Hatch(Hatch),
 }

+ 2 - 2
src/main.rs

@@ -1,6 +1,7 @@
 use std::{
     fs::{self},
-    path::PathBuf, time::Instant,
+    path::PathBuf,
+    time::Instant,
 };
 
 use binrw::BinRead;
@@ -47,5 +48,4 @@ fn main() {
     // }
     dbg!(String::from(&file.pens_offset.start_offset.pens[0].name));
     // dbg!(&file.pens_offset.start_offset.pens[255].wobble_type);
-
 }