Skip to main content

Document

Struct Document 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§schema_version: SchemaVersion

Version of this JSON layout; see SchemaVersion.

§source: SourceInfo

Where the data came from.

§units: Units

Unit 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: Props

Document-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

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn retain_layers(&mut self, keep: impl FnMut(&str) -> bool)

Retains only layers and model entities whose effective layer name satisfies keep.

Source

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

Source

pub fn new() -> Self

Creates an empty drawing document.

Source

pub fn model_space(&self) -> Option<&Model>

Returns the primary design model (ModelKind::Model), falling back to the first model.

Source

pub fn model_space_mut(&mut self) -> &mut Model

Returns a mutable reference to the primary design model, creating "Model" if models is empty.

Source

pub fn layouts(&self) -> impl Iterator<Item = &Model>

Iterates over paper-space layout and sheet models (kind != ModelKind::Model).

Source

pub fn all_entities(&self) -> impl Iterator<Item = &Entity>

Iterates over top-level entities across all Document::models.

Source

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").

Source

pub fn layer(&self, name: &str) -> Option<&Layer>

Looks up a layer by exact name first, then ASCII case-insensitively.

Source

pub fn block(&self, name: &str) -> Option<&Block>

Looks up a block definition by exact name first, then ASCII case-insensitively.

Source

pub fn entity_count(&self) -> usize

Total number of entities in Document::models, counting nested EntityKind::Group children.

Source§

impl Document

Source

pub fn walk<'a, F>(&'a self, model_index: usize, max_depth: u32, f: F)
where F: FnMut(&'a Entity, &WalkContext<'a>),

Visits the drawable entities of models[model_index] with their model-space transform.

  • Insert entities are expanded through the block table (name lookup, arrays, nesting up to max_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 than max_depth is reported itself.
  • Dimension entities that name an existing block are expanded the same way; others are reported as-is.
  • Group children are visited with the group’s transform; the group itself is not.
  • Entities with visible == false and 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.

Source

pub fn walk_with<'a, F>( &'a self, model_index: usize, options: &WalkOptions, f: F, ) -> WalkStats
where F: FnMut(&'a Entity, &WalkContext<'a>),

Document::walk with explicit WalkOptions; reports whether the work budget cut the traversal short.

Source

pub fn walk_while<'a, F>( &'a self, model_index: usize, options: &WalkOptions, f: F, ) -> WalkStats
where F: FnMut(&'a Entity, &WalkContext<'a>) -> bool,

Like Document::walk_with, but the callback returns false to stop the traversal (reported as truncated).

Source

pub fn walk_all_layers_while<'a, F>( &'a self, model_index: usize, options: &WalkOptions, f: F, ) -> WalkStats
where F: FnMut(&'a Entity, &WalkContext<'a>) -> bool,

Like Document::walk_while, but also visits entities on hidden (visible == false) or frozen (frozen == true) layers. Entities with entity.visible == false remain skipped.

Source

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.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Document

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Document

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Document

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Document

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.