cadkit_core/model.rs
1//! Format-neutral drawing model.
2//!
3//! Every reader (DWG, DGN, DXF) produces a [`Document`]. The model keeps the
4//! common CAD semantics typed and pushes format-specific details into
5//! [`Props`] under a format prefix (`dgn.`, `dwg.`, `dxf.`), so nothing a
6//! reader understood is thrown away.
7//!
8//! Conventions:
9//! - Coordinates are in drawing units (see [`Units`]); DGN UORs are already
10//! converted to master units.
11//! - **Every point and vector is in world coordinates (WCS).** Readers convert
12//! DWG/DXF object coordinates (OCS) to WCS; there is no OCS in this model.
13//! - Planar entities carry a `normal` that defines their plane. Angles
14//! (arc start/end, text/insert rotation, hatch pattern angle) are radians,
15//! counter-clockwise about that normal, measured from the plane's X axis as
16//! given by the DXF arbitrary-axis algorithm (`geom_ops::arbitrary_axes`).
17//! For `normal = +Z` this is the ordinary world X axis.
18//! - Ordered point lists (polyline vertices, face corners, hatch edges) are in
19//! outline order. Readers fix format quirks such as DXF `SOLID` storing
20//! corners 3 and 4 swapped.
21//! - Entities reference layers, blocks, linetypes and text styles by name.
22
23use std::collections::BTreeMap;
24
25use serde::{Deserialize, Serialize};
26
27use crate::geom::{Point3, Vec3};
28
29/// Format-specific extra data, keyed `"<format>.<name>"` (e.g. `"dgn.level_id"`).
30pub type Props = BTreeMap<String, Value>;
31
32/// A complete drawing.
33#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
34pub struct Document {
35 /// Where the data came from.
36 pub source: SourceInfo,
37 /// Unit of all coordinates in this document.
38 pub units: Units,
39 /// Layers (DWG/DXF layers, DGN levels).
40 pub layers: Vec<Layer>,
41 /// Linetype definitions.
42 pub linetypes: Vec<Linetype>,
43 /// Text style definitions.
44 pub text_styles: Vec<TextStyle>,
45 /// Block definitions (DWG/DXF blocks, DGN shared cell definitions).
46 pub blocks: Vec<Block>,
47 /// Model spaces, layouts and sheets that hold the drawn entities.
48 pub models: Vec<Model>,
49 /// Document-level extras (header variables, file properties).
50 pub props: Props,
51 /// Recoverable problems met while reading. A non-empty list does not mean failure.
52 pub warnings: Vec<Warning>,
53}
54
55/// Origin of a [`Document`].
56#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
57pub struct SourceInfo {
58 /// File format family.
59 pub format: Format,
60 /// Format version as written in the file, e.g. `"AC1032"`, `"V8"`, `"V7"`.
61 pub version: String,
62 /// Producing application if recorded, e.g. `"MicroStation v8.11.9.578"`.
63 pub application: Option<String>,
64 /// Code page used for 8-bit strings, e.g. `"windows-1254"`.
65 pub codepage: Option<String>,
66}
67
68/// File format family.
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
70#[serde(rename_all = "snake_case")]
71pub enum Format {
72 /// Not known (e.g. a document built in memory).
73 #[default]
74 Unknown,
75 /// AutoCAD DWG.
76 Dwg,
77 /// AutoCAD DXF (ASCII or binary).
78 Dxf,
79 /// MicroStation DGN V7 (ISFF).
80 DgnV7,
81 /// MicroStation DGN V8 (OLE compound file).
82 DgnV8,
83 /// CityGML 2.0; GML 3.1.1 tabanlı XML uygulama şeması.
84 CityGml,
85}
86
87/// Drawing units.
88#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
89pub struct Units {
90 /// Named unit of the coordinates.
91 pub unit: LengthUnit,
92 /// Size of one drawing unit in meters, when known. Authoritative over `unit`
93 /// for non-standard DGN master units.
94 pub meters_per_unit: Option<f64>,
95}
96
97/// Length unit. Mirrors the DWG `$INSUNITS` set.
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
99#[serde(rename_all = "snake_case")]
100#[allow(missing_docs)]
101pub enum LengthUnit {
102 #[default]
103 Unitless,
104 Inch,
105 Foot,
106 Mile,
107 Millimeter,
108 Centimeter,
109 Meter,
110 Kilometer,
111 Microinch,
112 Mil,
113 Yard,
114 Angstrom,
115 Nanometer,
116 Micrometer,
117 Decimeter,
118 Decameter,
119 Hectometer,
120 Gigameter,
121 AstronomicalUnit,
122 LightYear,
123 Parsec,
124 UsSurveyFoot,
125 /// A unit that is not in this list; see [`Units::meters_per_unit`].
126 Custom,
127}
128
129/// A layer (DGN: level).
130#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
131pub struct Layer {
132 /// Unique name.
133 pub name: String,
134 /// Native identifier (DWG handle, DGN level id).
135 pub id: Option<u64>,
136 /// Default color of entities on this layer.
137 pub color: Color,
138 /// Default linetype name.
139 pub linetype: Option<String>,
140 /// Default lineweight.
141 pub lineweight: Lineweight,
142 /// Layer is on / displayed.
143 pub visible: bool,
144 /// Layer is frozen.
145 pub frozen: bool,
146 /// Layer is locked.
147 pub locked: bool,
148 /// Layer is plotted.
149 pub plottable: bool,
150 /// Free-text description.
151 pub description: Option<String>,
152 /// Format-specific extras.
153 pub props: Props,
154}
155
156/// A linetype definition.
157#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
158pub struct Linetype {
159 /// Unique name.
160 pub name: String,
161 /// Description text.
162 pub description: Option<String>,
163 /// Dash pattern in drawing units: positive = dash, negative = gap, zero = dot.
164 pub pattern: Vec<f64>,
165 /// Format-specific extras.
166 pub props: Props,
167}
168
169/// A text style definition.
170#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
171pub struct TextStyle {
172 /// Unique name.
173 pub name: String,
174 /// Font file or font name.
175 pub font: Option<String>,
176 /// Fixed text height, 0 when variable.
177 pub height: f64,
178 /// Width factor (1.0 = normal).
179 pub width_factor: f64,
180 /// Oblique angle in radians.
181 pub oblique: f64,
182 /// Format-specific extras.
183 pub props: Props,
184}
185
186/// A block definition (DGN: shared cell definition).
187#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
188pub struct Block {
189 /// Unique name.
190 pub name: String,
191 /// Native identifier.
192 pub id: Option<u64>,
193 /// Insertion base point.
194 pub base_point: Point3,
195 /// Entities in block coordinates.
196 pub entities: Vec<Entity>,
197 /// Block is an external reference.
198 pub is_xref: bool,
199 /// Path of the external reference.
200 pub xref_path: Option<String>,
201 /// Description text.
202 pub description: Option<String>,
203 /// Format-specific extras.
204 pub props: Props,
205}
206
207/// A space that holds drawn entities: model space, a paper-space layout or a DGN model.
208#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
209pub struct Model {
210 /// Display name.
211 pub name: String,
212 /// Native identifier.
213 pub id: Option<u64>,
214 /// Kind of space.
215 pub kind: ModelKind,
216 /// Model stores 3D geometry.
217 pub is_3d: bool,
218 /// Entities in drawing order.
219 pub entities: Vec<Entity>,
220 /// Format-specific extras.
221 pub props: Props,
222}
223
224/// Kind of [`Model`].
225#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
226#[serde(rename_all = "snake_case")]
227pub enum ModelKind {
228 /// Design / model space.
229 #[default]
230 Model,
231 /// Paper-space layout (DWG/DXF).
232 Layout,
233 /// Sheet model (DGN).
234 Sheet,
235}
236
237/// One drawn object.
238#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
239pub struct Entity {
240 /// Native identifier (DWG handle, DGN element id).
241 pub id: Option<u64>,
242 /// Layer name; `None` means the default layer.
243 pub layer: Option<String>,
244 /// Color.
245 pub color: Color,
246 /// Linetype name; `None` means by layer.
247 pub linetype: Option<String>,
248 /// Lineweight.
249 pub lineweight: Lineweight,
250 /// Entity is displayed.
251 pub visible: bool,
252 /// Geometry and type-specific data.
253 pub kind: EntityKind,
254 /// Attached non-graphic data: DWG attributes, DGN tags, item-type properties.
255 pub attributes: Vec<Attribute>,
256 /// Format-specific extras.
257 pub props: Props,
258 /// Original record bytes, kept only when [`crate::ReadOptions::keep_raw`] is set.
259 #[serde(default, skip_serializing_if = "Option::is_none")]
260 pub raw: Option<Raw>,
261}
262
263impl Entity {
264 /// An entity with default symbology.
265 pub fn new(kind: EntityKind) -> Self {
266 Self {
267 id: None,
268 layer: None,
269 color: Color::ByLayer,
270 linetype: None,
271 lineweight: Lineweight::ByLayer,
272 visible: true,
273 kind,
274 attributes: Vec::new(),
275 props: Props::new(),
276 raw: None,
277 }
278 }
279}
280
281/// Geometry and type-specific data of an [`Entity`].
282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
283#[serde(tag = "type", rename_all = "snake_case")]
284pub enum EntityKind {
285 /// A point.
286 Point {
287 /// Location.
288 position: Point3,
289 },
290 /// A straight segment.
291 Line {
292 /// Start point.
293 start: Point3,
294 /// End point.
295 end: Point3,
296 },
297 /// Connected segments, optionally with arc segments (bulge) and widths.
298 /// Covers DWG LWPOLYLINE/POLYLINE and DGN line string / shape.
299 Polyline {
300 /// Vertices in order.
301 vertices: Vec<Vertex>,
302 /// Last vertex connects back to the first.
303 closed: bool,
304 /// Plane normal; bulge arcs turn counter-clockwise about it. `+Z` for plain 2D data
305 /// and for non-planar 3D polylines (which have no bulges).
306 normal: Vec3,
307 },
308 /// A full circle.
309 Circle {
310 /// Center.
311 center: Point3,
312 /// Radius.
313 radius: f64,
314 /// Plane normal.
315 normal: Vec3,
316 },
317 /// A circular arc from `start_angle` counter-clockwise to `end_angle`.
318 Arc {
319 /// Center.
320 center: Point3,
321 /// Radius.
322 radius: f64,
323 /// Start angle in radians.
324 start_angle: f64,
325 /// End angle in radians.
326 end_angle: f64,
327 /// Plane normal.
328 normal: Vec3,
329 },
330 /// An ellipse or elliptical arc.
331 Ellipse {
332 /// Center.
333 center: Point3,
334 /// Vector from the center to the end of the major axis (its length is the semi-major axis).
335 major_axis: Vec3,
336 /// Minor / major axis ratio, in (0, 1].
337 ratio: f64,
338 /// Start parameter in radians (0 for a full ellipse).
339 start_param: f64,
340 /// End parameter in radians (2π for a full ellipse).
341 end_param: f64,
342 /// Plane normal.
343 normal: Vec3,
344 },
345 /// A B-spline / NURBS curve.
346 Spline {
347 /// Degree.
348 degree: u32,
349 /// Knot vector (may be empty when only fit points are known).
350 knots: Vec<f64>,
351 /// Control points.
352 control_points: Vec<Point3>,
353 /// Weights; empty for non-rational curves.
354 weights: Vec<f64>,
355 /// Fit points, if stored.
356 fit_points: Vec<Point3>,
357 /// Curve is closed / periodic.
358 closed: bool,
359 },
360 /// Single-line text.
361 Text {
362 /// Anchor point implied by `halign`/`valign`: the baseline start for left/baseline
363 /// text, otherwise the justification point (DXF/DWG second alignment point, group 11).
364 /// For `Aligned`/`Fit` text: the baseline start.
365 position: Point3,
366 /// Baseline end for `Aligned`/`Fit` text; `None` for every other alignment.
367 end_point: Option<Point3>,
368 /// Character height.
369 height: f64,
370 /// Rotation in radians.
371 rotation: f64,
372 /// Width factor (1.0 = normal).
373 width_factor: f64,
374 /// Oblique angle in radians.
375 oblique: f64,
376 /// Decoded text.
377 value: String,
378 /// Text style name.
379 style: Option<String>,
380 /// Horizontal alignment.
381 halign: HAlign,
382 /// Vertical alignment.
383 valign: VAlign,
384 /// Plane normal.
385 normal: Vec3,
386 },
387 /// Multi-line, formatted text. DGN text nodes map to this when they only hold text.
388 MText {
389 /// Insertion point.
390 position: Point3,
391 /// Character height.
392 height: f64,
393 /// Reference rectangle width, 0 when unconstrained.
394 width: f64,
395 /// Rotation in radians.
396 rotation: f64,
397 /// Text including format codes as stored.
398 value: String,
399 /// Text with format codes removed, lines separated by `\n`.
400 plain: String,
401 /// Text style name.
402 style: Option<String>,
403 /// Attachment point.
404 attachment: Attachment,
405 /// Line spacing factor.
406 line_spacing: f64,
407 /// Plane normal.
408 normal: Vec3,
409 },
410 /// A placed block (DWG INSERT, DGN shared cell instance).
411 /// Attribute values live in [`Entity::attributes`].
412 Insert {
413 /// Block name.
414 block: String,
415 /// Insertion point.
416 position: Point3,
417 /// Scale factors.
418 scale: Vec3,
419 /// Rotation in radians.
420 rotation: f64,
421 /// Plane normal.
422 normal: Vec3,
423 /// Array columns (1 = no array).
424 columns: u32,
425 /// Array rows (1 = no array).
426 rows: u32,
427 /// Column spacing.
428 column_spacing: f64,
429 /// Row spacing.
430 row_spacing: f64,
431 },
432 /// A filled or patterned area.
433 Hatch {
434 /// Boundary loops; the first is usually the outer one.
435 loops: Vec<HatchLoop>,
436 /// Solid fill.
437 solid: bool,
438 /// Pattern name, if patterned.
439 pattern: Option<String>,
440 /// Pattern scale.
441 pattern_scale: f64,
442 /// Pattern angle in radians.
443 pattern_angle: f64,
444 /// Plane normal.
445 normal: Vec3,
446 },
447 /// A dimension annotation.
448 Dimension {
449 /// Kind of dimension.
450 dimension_type: DimensionType,
451 /// Definition points in format order (see `props` for their roles).
452 points: Vec<Point3>,
453 /// Text middle point.
454 text_position: Option<Point3>,
455 /// Measured value in drawing units (or radians for angular).
456 measurement: Option<f64>,
457 /// Text override.
458 text: Option<String>,
459 /// Anonymous block holding the rendered dimension, if any.
460 block: Option<String>,
461 /// Dimension style name.
462 style: Option<String>,
463 },
464 /// A planar 3- or 4-sided face (DWG SOLID/TRACE/3DFACE).
465 Face {
466 /// Corner points (3 or 4).
467 points: Vec<Point3>,
468 /// The face is filled (SOLID/TRACE) rather than a wire face.
469 filled: bool,
470 },
471 /// Çizim birimlerinde, WCS koordinatlı düzlemsel ve delikli yüzey.
472 /// Halkalar ilk noktayı son noktada tekrar ederek kapatılır.
473 Polygon {
474 /// Yüzeyin dış sınırı; en az dört konum içerir.
475 exterior: Vec<Point3>,
476 /// Dış sınırın içindeki boşlukların kapalı halkaları.
477 interiors: Vec<Vec<Point3>>,
478 },
479 /// A leader line.
480 Leader {
481 /// Vertices from arrow tip to the end.
482 vertices: Vec<Point3>,
483 /// Draws an arrowhead at the first vertex.
484 arrowhead: bool,
485 },
486 /// A raster image reference (DWG IMAGE, DGN raster attachment).
487 Image {
488 /// Image file path as stored.
489 path: Option<String>,
490 /// Lower-left corner.
491 position: Point3,
492 /// Vector along the image bottom edge, covering the full width.
493 u_vector: Vec3,
494 /// Vector along the image left edge, covering the full height.
495 v_vector: Vec3,
496 /// Pixel size, when known.
497 size_px: Option<[u32; 2]>,
498 },
499 /// A paper-space viewport.
500 Viewport {
501 /// Center on the sheet.
502 center: Point3,
503 /// Width on the sheet.
504 width: f64,
505 /// Height on the sheet.
506 height: f64,
507 /// Model-space point shown at the center.
508 view_center: Point3,
509 /// Model-space height shown.
510 view_height: f64,
511 },
512 /// A polygon mesh or polyface.
513 Mesh {
514 /// Vertex positions.
515 vertices: Vec<Point3>,
516 /// Faces as vertex indices (0-based).
517 faces: Vec<Vec<u32>>,
518 },
519 /// Entities that belong together: DGN complex chains/shapes, cells, text nodes, groups.
520 /// Children are in the same coordinate space as the group.
521 Group {
522 /// What kind of grouping this is.
523 group_kind: GroupKind,
524 /// Name (cell name, group name).
525 name: Option<String>,
526 /// Origin (cell origin, text node origin).
527 origin: Option<Point3>,
528 /// Member entities.
529 children: Vec<Entity>,
530 },
531 /// A record the reader recognized but does not model; see `props` / `raw`.
532 Unknown {
533 /// Native type name or code, e.g. `"dgn.type_94"` or `"dwg.ACAD_TABLE"`.
534 type_name: String,
535 },
536}
537
538/// Polyline vertex.
539#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
540pub struct Vertex {
541 /// Position.
542 pub position: Point3,
543 /// Bulge of the segment that starts here: tan(included angle / 4), 0 = straight.
544 pub bulge: f64,
545 /// Start width of the segment that starts here.
546 pub start_width: f64,
547 /// End width of the segment that starts here.
548 pub end_width: f64,
549}
550
551impl Vertex {
552 /// A straight, zero-width vertex.
553 pub fn at(position: Point3) -> Self {
554 Self {
555 position,
556 ..Self::default()
557 }
558 }
559}
560
561/// Horizontal text alignment.
562#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
563#[serde(rename_all = "snake_case")]
564#[allow(missing_docs)]
565pub enum HAlign {
566 #[default]
567 Left,
568 Center,
569 Right,
570 Aligned,
571 Middle,
572 Fit,
573}
574
575/// Vertical text alignment.
576#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
577#[serde(rename_all = "snake_case")]
578#[allow(missing_docs)]
579pub enum VAlign {
580 #[default]
581 Baseline,
582 Bottom,
583 Middle,
584 Top,
585}
586
587/// Multi-line text attachment point.
588#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
589#[serde(rename_all = "snake_case")]
590#[allow(missing_docs)]
591pub enum Attachment {
592 #[default]
593 TopLeft,
594 TopCenter,
595 TopRight,
596 MiddleLeft,
597 MiddleCenter,
598 MiddleRight,
599 BottomLeft,
600 BottomCenter,
601 BottomRight,
602}
603
604/// Dimension kind.
605#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
606#[serde(rename_all = "snake_case")]
607#[allow(missing_docs)]
608pub enum DimensionType {
609 #[default]
610 Linear,
611 Aligned,
612 Angular,
613 Angular3Point,
614 Diameter,
615 Radius,
616 Ordinate,
617 ArcLength,
618 Other,
619}
620
621/// What a [`EntityKind::Group`] represents.
622#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
623#[serde(rename_all = "snake_case")]
624pub enum GroupKind {
625 /// DGN complex chain (open).
626 ComplexChain,
627 /// DGN complex shape (closed).
628 ComplexShape,
629 /// DGN text node.
630 TextNode,
631 /// DGN cell (children inline, already placed).
632 Cell,
633 /// Any other grouping.
634 #[default]
635 Other,
636}
637
638/// One hatch boundary loop.
639#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
640pub struct HatchLoop {
641 /// Edges in order.
642 pub edges: Vec<HatchEdge>,
643 /// Loop is the outermost boundary.
644 pub external: bool,
645}
646
647/// A hatch boundary edge.
648#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
649#[serde(tag = "type", rename_all = "snake_case")]
650#[allow(missing_docs)]
651pub enum HatchEdge {
652 Line {
653 start: Point3,
654 end: Point3,
655 },
656 Arc {
657 center: Point3,
658 radius: f64,
659 start_angle: f64,
660 end_angle: f64,
661 ccw: bool,
662 },
663 Ellipse {
664 center: Point3,
665 major_axis: Vec3,
666 ratio: f64,
667 start_param: f64,
668 end_param: f64,
669 ccw: bool,
670 },
671 Spline {
672 degree: u32,
673 knots: Vec<f64>,
674 control_points: Vec<Point3>,
675 weights: Vec<f64>,
676 },
677 Polyline {
678 vertices: Vec<Vertex>,
679 closed: bool,
680 },
681}
682
683/// Color.
684#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
685#[serde(tag = "type", rename_all = "snake_case")]
686pub enum Color {
687 /// Use the layer color.
688 #[default]
689 ByLayer,
690 /// Use the color of the inserting block reference.
691 ByBlock,
692 /// AutoCAD Color Index 1..=255. DGN palette indices are resolved to [`Color::Rgb`]
693 /// by the DGN reader; the original index goes to `props["dgn.color_index"]`.
694 Aci {
695 /// Index.
696 index: u8,
697 },
698 /// True color.
699 Rgb {
700 /// Red.
701 r: u8,
702 /// Green.
703 g: u8,
704 /// Blue.
705 b: u8,
706 },
707}
708
709/// Line weight.
710#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
711#[serde(tag = "type", content = "value", rename_all = "snake_case")]
712pub enum Lineweight {
713 /// Use the layer lineweight.
714 #[default]
715 ByLayer,
716 /// Use the block reference lineweight.
717 ByBlock,
718 /// Application default.
719 Default,
720 /// Explicit width in millimeters. DGN weight steps are converted; the original goes to props.
721 Millimeters(f64),
722}
723
724/// Non-graphic data attached to an entity (DWG ATTRIB, DGN tag, item-type property).
725#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
726pub struct Attribute {
727 /// Tag / property name.
728 pub tag: String,
729 /// Value.
730 pub value: Value,
731 /// Owning tag set / item type / definition name.
732 pub set: Option<String>,
733 /// Where the attribute text is displayed, if it is displayed.
734 pub position: Option<Point3>,
735 /// The attribute is not displayed.
736 pub invisible: bool,
737 /// Layer of the attribute's own record when the format stores one (a DGN tag
738 /// element has its own level). `None` uses the owning entity's layer.
739 #[serde(default, skip_serializing_if = "Option::is_none")]
740 pub layer: Option<String>,
741 /// How the value text is drawn at `position`; `None` when unknown or not drawn.
742 #[serde(default, skip_serializing_if = "Option::is_none")]
743 pub display: Option<AttributeDisplay>,
744 /// Format-specific data with no neutral field (e.g. `dgn.color_index`, `dgn.weight`).
745 #[serde(default, skip_serializing_if = "Props::is_empty")]
746 pub props: Props,
747}
748
749/// Text presentation of a displayed attribute value.
750#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
751pub struct AttributeDisplay {
752 /// Text height, in drawing units.
753 pub height: f64,
754 /// Character width, in drawing units (DGN stores it separately from the height).
755 pub width: f64,
756 /// Text style (DGN font) name; `None` leaves the choice to the writer's default.
757 pub style: Option<String>,
758 /// Horizontal alignment of the text about `Attribute::position`.
759 pub halign: HAlign,
760 /// Vertical alignment of the text about `Attribute::position`.
761 pub valign: VAlign,
762 /// Rotation about the drawing Z axis, in radians.
763 pub rotation: f64,
764}
765
766/// A loosely typed value for attributes and props.
767#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
768#[serde(untagged)]
769pub enum Value {
770 /// No value.
771 #[default]
772 Null,
773 /// Boolean.
774 Bool(bool),
775 /// Integer.
776 Int(i64),
777 /// Floating point.
778 Float(f64),
779 /// Text.
780 Text(String),
781 /// Ordered list.
782 List(Vec<Value>),
783 /// Binary data.
784 Bytes(Vec<u8>),
785}
786
787impl From<bool> for Value {
788 fn from(v: bool) -> Self {
789 Value::Bool(v)
790 }
791}
792impl From<i64> for Value {
793 fn from(v: i64) -> Self {
794 Value::Int(v)
795 }
796}
797impl From<u32> for Value {
798 fn from(v: u32) -> Self {
799 Value::Int(i64::from(v))
800 }
801}
802impl From<f64> for Value {
803 fn from(v: f64) -> Self {
804 Value::Float(v)
805 }
806}
807impl From<String> for Value {
808 fn from(v: String) -> Self {
809 Value::Text(v)
810 }
811}
812impl From<&str> for Value {
813 fn from(v: &str) -> Self {
814 Value::Text(v.to_owned())
815 }
816}
817
818/// Original bytes of a record, for lossless inspection.
819#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
820pub struct Raw {
821 /// Native type code (DGN element type, DWG object type).
822 pub type_code: u32,
823 /// Record bytes exactly as stored (after decompression).
824 pub bytes: Vec<u8>,
825}
826
827/// A recoverable problem found while reading.
828#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
829pub struct Warning {
830 /// Stable machine-readable code, e.g. `"dgn.unknown_element"`.
831 pub code: String,
832 /// Human-readable explanation.
833 pub message: String,
834 /// Byte offset in the decoded stream, when meaningful.
835 pub offset: Option<u64>,
836 /// Native id of the affected object, when known.
837 pub object: Option<u64>,
838}