#[non_exhaustive]pub struct Document {
pub schema_version: SchemaVersion,
pub source: SourceInfo,
pub units: Units,
pub layers: Vec<Layer>,
pub linetypes: Vec<Linetype>,
pub text_styles: Vec<TextStyle>,
pub blocks: Vec<Block>,
pub models: Vec<Model>,
pub props: Props,
pub warnings: Vec<Warning>,
}Expand description
A complete drawing.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.schema_version: SchemaVersionVersion of this JSON layout; see SchemaVersion.
source: SourceInfoWhere the data came from.
units: UnitsUnit of all coordinates in this document.
layers: Vec<Layer>Layers (DWG/DXF layers, DGN levels).
linetypes: Vec<Linetype>Linetype definitions.
text_styles: Vec<TextStyle>Text style definitions.
blocks: Vec<Block>Block definitions (DWG/DXF blocks, DGN shared cell definitions).
models: Vec<Model>Model spaces, layouts and sheets that hold the drawn entities.
props: PropsDocument-level extras (header variables, file properties).
warnings: Vec<Warning>Recoverable problems met while reading. A non-empty list does not mean failure.
Implementations§
Source§impl Document
impl Document
Sourcepub fn transform(&mut self, tf: &Transform)
pub fn transform(&mut self, tf: &Transform)
Applies an affine Transform in-place to all design-space models (ModelKind::Model,
or all models if no ModelKind::Model exists).
Block definitions remain in block-local coordinates while EntityKind::Insert entities
absorb the world-space transform into their placement, scale, and rotation.
Sourcepub fn convert_units(&mut self, target: LengthUnit) -> Result<f64>
pub fn convert_units(&mut self, target: LengthUnit) -> Result<f64>
Converts all drawing coordinates, block definitions, linetype dash patterns, and fixed
text-style heights from Document::units to target, returning the applied scale factor.
Returns Error::Unsupported if either Document::units or target has no known
meter conversion scale (such as LengthUnit::Unitless).
Sourcepub fn explode_inserts(&mut self, max_depth: u32) -> WalkStats
pub fn explode_inserts(&mut self, max_depth: u32) -> WalkStats
Expands EntityKind::Insert block references in every model into world-space entities
up to max_depth, resolving ByBlock symbology and "0" layer inheritance.
Missing blocks, cyclic references, and inserts deeper than max_depth are kept intact.
Work is bounded by DEFAULT_MAX_WORK.
Sourcepub fn flatten_groups(&mut self)
pub fn flatten_groups(&mut self)
Flattens EntityKind::Group hierarchies into their parent entity lists across all models
and block definitions, propagating inherited layers and ByBlock symbology.
Sourcepub fn tessellate_curves(&mut self, tolerance: f64)
pub fn tessellate_curves(&mut self, tolerance: f64)
Converts curved entities (Circle, Arc, Ellipse, Spline, and bulged Polyline
segments) across all models and blocks into straight-segment EntityKind::Polylines
within chordal error tolerance.
Sourcepub fn retain_layers(&mut self, keep: impl FnMut(&str) -> bool)
pub fn retain_layers(&mut self, keep: impl FnMut(&str) -> bool)
Retains only layers and model entities whose effective layer name satisfies keep.
Sourcepub fn purge_unused(&mut self) -> PurgeStats
pub fn purge_unused(&mut self) -> PurgeStats
Removes unreferenced Block, crate::Layer (except "0"), crate::Linetype, and
crate::TextStyle table entries, returning counts of purged definitions.
Source§impl Document
impl Document
Sourcepub fn model_space(&self) -> Option<&Model>
pub fn model_space(&self) -> Option<&Model>
Returns the primary design model (ModelKind::Model), falling back to the first model.
Sourcepub fn model_space_mut(&mut self) -> &mut Model
pub fn model_space_mut(&mut self) -> &mut Model
Returns a mutable reference to the primary design model, creating "Model" if models is empty.
Sourcepub fn layouts(&self) -> impl Iterator<Item = &Model>
pub fn layouts(&self) -> impl Iterator<Item = &Model>
Iterates over paper-space layout and sheet models (kind != ModelKind::Model).
Sourcepub fn all_entities(&self) -> impl Iterator<Item = &Entity>
pub fn all_entities(&self) -> impl Iterator<Item = &Entity>
Iterates over top-level entities across all Document::models.
Sourcepub fn entities_on_layer<'a>(
&'a self,
layer: &'a str,
) -> impl Iterator<Item = &'a Entity> + 'a
pub fn entities_on_layer<'a>( &'a self, layer: &'a str, ) -> impl Iterator<Item = &'a Entity> + 'a
Iterates over top-level entities across all models whose effective layer matches layer
(treating None on an entity as layer "0").
Sourcepub fn layer(&self, name: &str) -> Option<&Layer>
pub fn layer(&self, name: &str) -> Option<&Layer>
Looks up a layer by exact name first, then ASCII case-insensitively.
Sourcepub fn block(&self, name: &str) -> Option<&Block>
pub fn block(&self, name: &str) -> Option<&Block>
Looks up a block definition by exact name first, then ASCII case-insensitively.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Total number of entities in Document::models, counting nested EntityKind::Group children.
Source§impl Document
impl Document
Sourcepub fn walk<'a, F>(&'a self, model_index: usize, max_depth: u32, f: F)
pub fn walk<'a, F>(&'a self, model_index: usize, max_depth: u32, f: F)
Visits the drawable entities of models[model_index] with their model-space transform.
Insertentities are expanded through the block table (name lookup, arrays, nesting up tomax_depth); the callback sees the block’s entities, not the insert. An insert whose block is missing, that would recurse into a block already being expanded (cycle), or that sits deeper thanmax_depthis reported itself.Dimensionentities that name an existing block are expanded the same way; others are reported as-is.Groupchildren are visited with the group’s transform; the group itself is not.- Entities with
visible == falseand entities on hidden or frozen layers are skipped (together with everything below them).
A missing model index visits nothing. The traversal is limited by the default work
budget (DEFAULT_MAX_WORK) so malicious block nesting cannot hang the caller.
Sourcepub fn walk_with<'a, F>(
&'a self,
model_index: usize,
options: &WalkOptions,
f: F,
) -> WalkStats
pub fn walk_with<'a, F>( &'a self, model_index: usize, options: &WalkOptions, f: F, ) -> WalkStats
Document::walk with explicit WalkOptions; reports whether the work budget cut
the traversal short.
Sourcepub fn walk_while<'a, F>(
&'a self,
model_index: usize,
options: &WalkOptions,
f: F,
) -> WalkStats
pub fn walk_while<'a, F>( &'a self, model_index: usize, options: &WalkOptions, f: F, ) -> WalkStats
Like Document::walk_with, but the callback returns false to stop the traversal
(reported as truncated).
Sourcepub fn walk_all_layers_while<'a, F>(
&'a self,
model_index: usize,
options: &WalkOptions,
f: F,
) -> WalkStats
pub fn walk_all_layers_while<'a, F>( &'a self, model_index: usize, options: &WalkOptions, f: F, ) -> WalkStats
Like Document::walk_while, but also visits entities on hidden (visible == false)
or frozen (frozen == true) layers. Entities with entity.visible == false remain skipped.
Sourcepub fn bbox(&self, model_index: usize) -> Option<BBox>
pub fn bbox(&self, model_index: usize) -> Option<BBox>
Bounding box (model-space XYZ) of everything Document::walk visits in
models[model_index], or None when there is no geometry.
Arcs, circles and ellipses use their exact extents, splines their sampled curve, polylines include bulge arcs. Text is approximated (glyph width 0.6 x height) because fonts are unknown; viewports and unknown records contribute nothing.
Sourcepub fn bbox_with(
&self,
model_index: usize,
options: &BBoxOptions,
) -> Option<BBox>
pub fn bbox_with( &self, model_index: usize, options: &BBoxOptions, ) -> Option<BBox>
Document::bbox with options; with include_images: false raster image frames are
ignored (their stored extent can dwarf the drawing, e.g. DGN raster frames).
Sourcepub fn bbox_all_layers_with(
&self,
model_index: usize,
options: &BBoxOptions,
) -> Option<BBox>
pub fn bbox_all_layers_with( &self, model_index: usize, options: &BBoxOptions, ) -> Option<BBox>
Like Document::bbox_with, including entities on hidden or frozen layers.