acadrust 0.2.9

A pure Rust library for reading and writing CAD files in DXF format (ASCII and Binary) and DWG format (Binary).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# acadrust 0.2.9


[![Crates.io](https://img.shields.io/crates/v/acadrust.svg)](https://crates.io/crates/acadrust)
[![Documentation](https://docs.rs/acadrust/badge.svg)](https://docs.rs/acadrust)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
[![Rust](https://img.shields.io/badge/rust-2021-orange.svg)](https://www.rust-lang.org/)

**A pure Rust library for reading and writing CAD files (DXF and DWG).**

acadrust provides comprehensive support for the DXF and DWG file formats with a focus on correctness, type safety, and completeness. Inspired by [ACadSharp](https://github.com/DomCR/ACadSharp), this library brings full-featured CAD file manipulation to the Rust ecosystem.

---

## ✨ Features


### Core Capabilities


- **πŸ“– Read & Write DXF** β€” Full support for both ASCII and Binary DXF formats
- **πŸ“ Read & Write DWG** β€” Native DWG binary input/output for R13 through R2018 (8 versions), 208/208 roundtrip-perfect
- **🧊 3D Solid Creation** β€” Read/Build ACIS-based 3DSOLID entities and write primitives (box, wedge, pyramid, cylinder, and custom B-Rep) with SAT text (R2000–R2007) and SAB binary (R2013+) encoding
- **πŸ”’ Type Safe** β€” Leverages Rust's type system with strongly-typed entities, tables, and objects
- **🌐 Encoding Support** β€” Automatic code page detection and character encoding for pre-2007 files (~40 code pages via `encoding_rs`)
- **πŸ›‘οΈ Failsafe Mode** β€” Optional error-tolerant parsing that collects diagnostics instead of aborting
- **πŸ“‹ Notifications** β€” Structured diagnostic system reporting unsupported elements, warnings, and errors
- **πŸ”— Handle Resolution** β€” Automatic owner handle assignment and handle tracking after read
- **❓ Unknown Entity Preservation** β€” Unrecognized entity types are preserved as `UnknownEntity` with common fields intact

### File Version Support


| Version Code | AutoCAD Version | DXF Read | DXF Write | DWG Read | DWG Write |
|-------------|-----------------|----------|-----------|----------|----------|
| AC1009 | R12 | βœ… | βœ… | β€” | β€” |
| AC1012 | R13 | βœ… | βœ… | βœ… | βœ… |
| AC1014 | R14 | βœ… | βœ… | βœ… | βœ… |
| AC1015 | 2000 | βœ… | βœ… | βœ… | βœ… |
| AC1018 | 2004 | βœ… | βœ… | βœ… | βœ… |
| AC1021 | 2007 | βœ… | βœ… | βœ… | βœ… |
| AC1024 | 2010 | βœ… | βœ… | βœ… | βœ… |
| AC1027 | 2013 | βœ… | βœ… | βœ… | βœ… |
| AC1032 | 2018+ | βœ… | βœ… | βœ… | βœ… |

### Supported Entity Types (41)


<details>
<summary>Click to expand full entity list</summary>

#### Basic Entities

- **Point** β€” Single point in 3D space
- **Line** β€” Line segment between two points
- **Circle** β€” Circle defined by center and radius
- **Arc** β€” Circular arc with start and end angles
- **Ellipse** β€” Ellipse or elliptical arc

#### Polylines

- **Polyline** β€” 2D polyline with optional bulge
- **Polyline2D** β€” Heavy 2D polyline with vertex entities
- **Polyline3D** β€” 3D polyline
- **LwPolyline** β€” Lightweight polyline (optimized 2D)
- **PolyfaceMesh** β€” 3D mesh defined by vertices and faces
- **PolygonMesh** β€” 3D polygon surface mesh (MΓ—N grid)

#### Text & Annotations

- **Text** β€” Single-line text
- **MText** β€” Multi-line formatted text
- **AttributeDefinition** β€” Block attribute template
- **AttributeEntity** β€” Block attribute instance
- **Tolerance** β€” Geometric tolerancing symbols

#### Dimensions & Leaders

- **Dimension** β€” Various dimension types (linear, angular, radial, etc.)
- **Leader** β€” Leader line with annotation
- **MultiLeader** β€” Modern multi-leader with advanced formatting
- **Table** β€” Table with cells, rows, and columns

#### Complex Entities

- **Spline** β€” NURBS curve
- **Hatch** β€” Filled region with pattern
- **Solid** β€” 2D filled polygon
- **Face3D** β€” 3D triangular/quadrilateral face
- **Mesh** β€” Subdivision mesh surface

#### Blocks & References

- **Block** / **BlockEnd** β€” Block definition markers
- **Insert** β€” Block reference (instance)
- **Seqend** β€” Sequence end marker for complex entities

#### Construction Geometry

- **Ray** β€” Semi-infinite line
- **XLine** β€” Infinite construction line

#### Advanced Entities

- **Viewport** β€” Paper space viewport
- **RasterImage** β€” Embedded or linked raster image
- **Solid3D** β€” 3D solid with ACIS data (read & **write** β€” SAT v7.0 text and SAB binary)
- **Region** β€” 2D region with ACIS data
- **Body** β€” 3D body with ACIS data
- **MLine** β€” Multi-line with style
- **Wipeout** β€” Masking region
- **Shape** β€” Shape reference
- **Underlay** β€” PDF/DWF/DGN underlay reference
- **Ole2Frame** β€” OLE 2.0 embedded object
- **UnknownEntity** β€” Preserves common fields for unrecognized entity types

</details>

### Table System


Complete support for all standard tables:

| Table | Description |
|-------|-------------|
| **Layer** | Drawing layers with color, linetype, and visibility |
| **LineType** | Line patterns and dash definitions |
| **TextStyle** | Font and text formatting settings |
| **DimStyle** | Dimension appearance and behavior |
| **BlockRecord** | Block definition registry |
| **AppId** | Application identifier registry |
| **View** | Named view configurations |
| **VPort** | Viewport configurations |
| **UCS** | User coordinate system definitions |

### Objects (Non-Graphical Elements)


- **Dictionary** / **DictionaryWithDefault** β€” Key-value storage for objects
- **DictionaryVariable** β€” Named variable in a dictionary
- **Group** β€” Named entity collections
- **Layout** β€” Model/paper space layout definitions
- **MLineStyle** β€” Multi-line style definitions
- **MultiLeaderStyle** β€” Multi-leader style definitions
- **TableStyle** β€” Table formatting styles
- **PlotSettings** β€” Print/plot configurations
- **Scale** β€” Annotation scale definitions
- **ImageDefinition** / **ImageDefinitionReactor** β€” Raster image definitions and reactors
- **XRecord** β€” Extended data records
- **SortEntitiesTable** β€” Entity draw order
- **VisualStyle** β€” 3D visual style definitions
- **Material** β€” Material definitions
- **GeoData** β€” Geolocation data
- **SpatialFilter** β€” Spatial clipping filter
- **RasterVariables** β€” Raster display settings
- **BookColor** β€” Color book (DBCOLOR) entries
- **PlaceHolder** β€” Placeholder objects
- **WipeoutVariables** β€” Wipeout display settings

### CLASSES Section


Full support for the CLASSES section β€” reading, storing, and writing DXF class definitions with all standard fields (class name, DXF name, application name, proxy flags, instance count).

### Extended Data (XData)


Full support for application-specific extended data:

- String, binary, and numeric values
- 3D points, directions, and displacements
- Layer references and database handles
- Nested data structures with control strings

### Reactors & Extension Dictionaries


Full support for entity/object reactor chains (group code 102 `{ACAD_REACTORS}`) and extension dictionaries (`{ACAD_XDICTIONARY}`), read and written for all entity and object types.

---

## πŸ“¦ Installation


Add acadrust to your `Cargo.toml`:

```toml
[dependencies]
acadrust = "0.2.9"
```

Or install via cargo:

```bash
cargo add acadrust
```

### Optional Features


| Feature | Description |
|---------|-------------|
| `serde` | Enables `Serialize` / `Deserialize` on all document types for JSON, YAML, etc. |

```toml
[dependencies]
acadrust = { version = "0.2.9", features = ["serde"] }
```

---

## πŸš€ Quick Start


### Reading a DXF File


```rust
use acadrust::{CadDocument, DxfReader};

fn main() -> acadrust::Result<()> {
    // Open and read a DXF file
    let doc = DxfReader::from_file("drawing.dxf")?.read()?;
    
    // Access document properties
    println!("Version: {:?}", doc.header().version);
    
    // Iterate over entities in model space
    for entity in doc.entities() {
        println!("Entity: {:?}", entity);
    }
    
    // Check parse notifications
    for note in doc.notifications.iter() {
        println!("[{:?}] {}", note.level, note.message);
    }
    
    Ok(())
}
```

### Reading with Failsafe Mode


```rust
use acadrust::{DxfReader};
use acadrust::io::dxf::DxfReaderConfiguration;

fn main() -> acadrust::Result<()> {
    let config = DxfReaderConfiguration { failsafe: true };
    let doc = DxfReader::from_file("drawing.dxf")?
        .with_configuration(config)
        .read()?;
    
    // Even if some sections had errors, the document is partially populated
    println!("Entities read: {}", doc.entities().len());
    println!("Notifications: {}", doc.notifications.len());
    
    Ok(())
}
```

### Writing a DXF File


```rust
use acadrust::{CadDocument, DxfWriter, Line, Layer, Vector3};

fn main() -> acadrust::Result<()> {
    // Create a new document
    let mut doc = CadDocument::new();
    
    // Add a layer
    let layer = Layer::new("MyLayer");
    doc.layers_mut().add(layer)?;
    
    // Create and add a line
    let line = Line {
        start: Vector3::new(0.0, 0.0, 0.0),
        end: Vector3::new(100.0, 100.0, 0.0),
        ..Default::default()
    };
    doc.add_entity(line);
    
    // Write to file
    DxfWriter::new(&doc).write_to_file("output.dxf")?;
    
    Ok(())
}
```

### Serialization (optional `serde` feature)


Serialize individual entities:

```rust
use acadrust::entities::Line;

let line = Line::from_coords(0.0, 0.0, 0.0, 100.0, 50.0, 0.0);
let json = serde_json::to_string_pretty(&line).unwrap();
println!("{json}");
```

Round-trip a full document:

```rust
use acadrust::{CadDocument, DxfReader};

fn main() -> acadrust::Result<()> {
    let doc = DxfReader::from_file("drawing.dxf")?.read()?;

    // Serialize the entire document to JSON
    let json = serde_json::to_string_pretty(&doc).unwrap();

    // Deserialize back
    let doc2: CadDocument = serde_json::from_str(&json).unwrap();
    println!("Entities: {}", doc2.entities().count());

    Ok(())
}
```

Extract entities as a JSON array for a web API:

```rust
use acadrust::{CadDocument, DxfReader};
use acadrust::entities::EntityType;

fn main() -> acadrust::Result<()> {
    let doc = DxfReader::from_file("drawing.dxf")?.read()?;
    let entities: Vec<&EntityType> = doc.entities().collect();
    let api_response = serde_json::to_string_pretty(&entities).unwrap();
    println!("{api_response}");
    Ok(())
}
```

All entities, tables, objects, and types implement `Serialize` and `Deserialize`
when the `serde` feature is enabled, making it easy to build web APIs, store
drawings in databases, or convert between formats.

See the full example: [`examples/serde_json.rs`](examples/serde_json.rs)

### Creating 3D Solids (ACIS)


acadrust includes a SAT/SAB builder for creating ACIS 3DSOLID entities from scratch.
The builder emits SAT v7.0 text for R2000–R2007 and SAB binary for R2013+.

```rust
use acadrust::{CadDocument, DwgWriter, DxfVersion, EntityType};
use acadrust::entities::Solid3D;
use acadrust::entities::acis::{SatDocument, SatPointer, Sense, Sidedness};

fn main() -> acadrust::Result<()> {
    // Start a new ACIS body
    let mut sat = SatDocument::new_body();
    let body_idx = SatPointer::new(0);

    // Geometry: 6 plane surfaces for a 10Γ—10Γ—10 box
    let surf_top    = sat.add_plane_surface([0.0, 0.0,  5.0], [0.0, 0.0,  1.0], [1.0, 0.0, 0.0]);
    let surf_bottom = sat.add_plane_surface([0.0, 0.0, -5.0], [0.0, 0.0, -1.0], [1.0, 0.0, 0.0]);
    // ... add remaining surfaces, curves, vertices, edges, coedges, loops, faces, shell, lump

    // Wrap in a Solid3D and write to DWG
    let mut solid = Solid3D::new();
    solid.set_sat_document(&sat);

    let mut doc = CadDocument::with_version(DxfVersion::AC1027); // R2013
    doc.add_entity(EntityType::Solid3D(solid))?;
    DwgWriter::write_to_file("box.dwg", &doc)?;

    Ok(())
}
```

Available surface/curve builders:

| Method | Description |
|--------|-------------|
| `add_plane_surface` | Infinite plane (origin, normal, u-axis) |
| `add_cone_surface` | Cone / cylinder (center, axis, major-axis, ratio, half-angle) |
| `add_sphere_surface` | Sphere (center, axis, radius) |
| `add_torus_surface` | Torus (center, axis, major/minor radii) |
| `add_straight_curve` | Infinite line (point, direction) |
| `add_ellipse_curve` | Ellipse / circle (center, normal, major-axis, ratio) |

See the full example: [`examples/write_3dsolid_dwg.rs`](examples/write_3dsolid_dwg.rs) β€” builds a box, wedge, pyramid, and cylinder.

### Reading a DWG File


```rust
use acadrust::io::dwg::DwgReader;

fn main() -> acadrust::Result<()> {
    let mut reader = DwgReader::from_file("drawing.dwg")?;
    let doc = reader.read()?;
    
    println!("Version: {:?}", doc.header().version);
    println!("Entities: {}", doc.entities().len());
    
    for entity in doc.entities() {
        println!("Entity: {:?}", entity);
    }
    
    Ok(())
}
```

### Writing a DWG File


```rust
use acadrust::{CadDocument, DwgWriter};
use acadrust::entities::*;
use acadrust::types::{Color, DxfVersion, Vector3};

fn main() -> acadrust::Result<()> {
    // Create a document (default: R2018)
    let mut doc = CadDocument::new();
    
    // Or target a specific version
    // let mut doc = CadDocument::with_version(DxfVersion::AC1015); // R2000
    
    // Add entities
    let mut line = Line::from_coords(0.0, 0.0, 0.0, 100.0, 50.0, 0.0);
    line.common.color = Color::RED;
    doc.add_entity(EntityType::Line(line))?;
    
    let mut circle = Circle::from_coords(50.0, 25.0, 0.0, 15.0);
    circle.common.color = Color::BLUE;
    doc.add_entity(EntityType::Circle(circle))?;
    
    // Write to DWG
    DwgWriter::write_to_file("output.dwg", &doc)?;
    
    // Or write to a Vec<u8>
    let bytes = DwgWriter::write_to_vec(&doc)?;
    
    Ok(())
}
```

### Working with Layers


```rust
use acadrust::{CadDocument, Layer, Color};

fn main() -> acadrust::Result<()> {
    let mut doc = CadDocument::new();
    
    // Create a custom layer
    let mut layer = Layer::new("Annotations");
    layer.color = Color::from_index(1); // Red
    layer.is_frozen = false;
    layer.is_locked = false;
    
    doc.layers_mut().add(layer)?;
    
    // Access existing layers
    if let Some(layer) = doc.layers().get("0") {
        println!("Default layer color: {:?}", layer.color);
    }
    
    Ok(())
}
```

### Creating Complex Entities


```rust
use acadrust::{CadDocument, LwPolyline, LwVertex, Vector2, Circle, Arc};

fn main() -> acadrust::Result<()> {
    let mut doc = CadDocument::new();
    
    // Create a rectangle using LwPolyline
    let mut polyline = LwPolyline::new();
    polyline.vertices = vec![
        LwVertex { position: Vector2::new(0.0, 0.0), ..Default::default() },
        LwVertex { position: Vector2::new(100.0, 0.0), ..Default::default() },
        LwVertex { position: Vector2::new(100.0, 50.0), ..Default::default() },
        LwVertex { position: Vector2::new(0.0, 50.0), ..Default::default() },
    ];
    polyline.is_closed = true;
    doc.add_entity(polyline);
    
    // Create a circle
    let circle = Circle {
        center: Vector3::new(50.0, 25.0, 0.0),
        radius: 10.0,
        ..Default::default()
    };
    doc.add_entity(circle);
    
    Ok(())
}
```

---

## πŸ—οΈ Architecture


acadrust uses a trait-based design for maximum flexibility and extensibility:

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       CadDocument                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Header    β”‚  β”‚    Tables    β”‚  β”‚      Entities       β”‚  β”‚
β”‚  β”‚  Variables  β”‚  β”‚              β”‚  β”‚                     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚ - Layers     β”‚  β”‚ - Lines, Circles    β”‚  β”‚
β”‚                   β”‚ - LineTypes  β”‚  β”‚ - Polylines, Arcs   β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚ - Styles     β”‚  β”‚ - Text, Dimensions  β”‚  β”‚
β”‚  β”‚   Blocks    β”‚  β”‚ - DimStyles  β”‚  β”‚ - Hatches, Splines  β”‚  β”‚
β”‚  β”‚             β”‚  β”‚ - VPorts     β”‚  β”‚ - 3D, Mesh, Images  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚            Objects               β”‚  β”‚  Notifications   β”‚  β”‚
β”‚  β”‚  Dictionaries, Groups, Styles,   β”‚  β”‚  Warnings, Errorsβ”‚  β”‚
β”‚  β”‚  Layouts, XRecords, Materials    β”‚  β”‚  Diagnostics     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚                      Classes                             β”‚β”‚
β”‚  β”‚  DXF class definitions (name, app, proxy flags, count)   β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Core Traits


| Trait | Purpose |
|-------|---------|
| `Entity` | Base trait for all graphical entities |
| `TableEntry` | Base trait for table entries (layers, styles, etc.) |
| `CadObject` | Common interface for all CAD objects |

### Key Types


| Type | Description |
|------|-------------|
| `CadDocument` | Central document container |
| `DxfReader` | DXF file reader (ASCII and binary) |
| `DxfWriter` | DXF file writer |
| `DwgReader` | DWG binary file reader |
| `DwgWriter` | DWG binary file writer |
| `DxfReaderConfiguration` | Reader options (failsafe mode) |
| `Handle` | Unique object identifier |
| `Vector2` / `Vector3` | 2D and 3D coordinate types |
| `Color` | CAD color (indexed or true color) |
| `LineWeight` | Line thickness enumeration |
| `Transform` | Transformation matrices |
| `NotificationCollection` | Parse diagnostics and warnings |

---

## βš™οΈ Dependencies


acadrust is built on a foundation of high-quality Rust crates:

| Crate | Purpose |
|-------|---------|
| `thiserror` / `anyhow` | Error handling |
| `nom` | Parser combinators for binary parsing |
| `byteorder` | Cross-platform byte order handling |
| `flate2` | Compression/decompression |
| `nalgebra` | Linear algebra and transformations |
| `indexmap` | Ordered hash maps |
| `rayon` | Parallel iterators |
| `encoding_rs` | Character encoding support |
| `bitflags` | Type-safe bitflags |
| `once_cell` | Lazy static initialization |
| `ahash` | Fast hashing |
| `serde` | Serialization/deserialization (optional) |

---

## πŸ§ͺ Testing


Run the test suite:

```bash
# Run all tests

cargo test

# Run with output

cargo test -- --nocapture

# Run specific test

cargo test test_read_minimal_dxf
```

### Generate DWG Samples


Generate a comprehensive matrix of every entity type Γ— every DWG version (R13–R2018) for verification in AutoCAD, IntelliCAD, or BricsCAD:

```bash
cargo run --example gen_all_entities_all_versions
```

This produces 216 DWG files in `target/entities_dwg/<VERSION>/` β€” 27 entity types across 8 versions.

### Roundtrip Data Integrity Test


Verify lossless write→read→write→read fidelity across all 26 entity types × 8 DWG versions (208 test cases):

```bash
cargo run --example test_roundtrip
```

All 208 roundtrips pass with **zero data drift** β€” 0 Trip1 field losses, 0 Trip2 divergence, 0 write failures.

Run benchmarks:

```bash
cargo bench
```

---

## ️ Roadmap


- [x] ASCII DXF read/write
- [x] Binary DXF read/write
- [x] Full entity, table, and object coverage
- [x] CLASSES section support
- [x] Character encoding / code page support
- [x] Failsafe (error-tolerant) reading mode
- [x] Unknown entity preservation
- [x] DWG binary write (R13, R14, R2000, R2004, R2007, R2010, R2013, R2018)
- [x] DWG binary read (R13 through R2018)
- [x] 208/208 roundtrip data integrity (0 field drift across all entity types Γ— all versions)
- [x] Optional serde support (`Serialize` / `Deserialize` for all types)
- [x] ACIS 3DSOLID read/write β€” SAT text (R2000–R2007) and SAB binary (R2013+) with builder API
- [ ] Geometric operations (offset, trim, extend)
- [ ] SVG/PDF export
- [ ] Spatial indexing for large drawings

---

## πŸ“„ License


This project is licensed under the Mozilla Public License 2.0 - see the [LICENSE](LICENSE) file for details.

---

## πŸ™ Acknowledgments


- [ACadSharp]https://github.com/DomCR/ACadSharp - The C# library that inspired this project
- The Rust community for excellent tooling and libraries

---

## πŸ“ž Support


- **Issues**: [GitHub Issues]https://github.com/hakanaktt/acadrust/issues
- **Discussions**: [GitHub Discussions]https://github.com/hakanaktt/acadrust/discussions

---

<p align="center">
  Made with ❀️ in Rust
</p>