Skip to main content

cadmpeg_ir/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Format-neutral CAD documents and the codec interfaces that produce them.
3//!
4//! [`CadIr`] stores units, tolerances, and flat entity arenas connected by
5//! typed IDs. Its B-rep topology follows
6//! `body → region → shell → face → loop → coedge → edge → vertex`; topology
7//! references geometry carriers instead of nesting them. The document also
8//! carries neutral construction features, tessellation, appearance, source
9//! attributes, source-native namespaces, and uninterpreted [`UnknownRecord`]s.
10//!
11//! Start a hand-built document with [`CadIr::empty`], populate its arenas,
12//! call [`CadIr::finalize`] to establish canonical identity order, then call
13//! [`validate()`] to check structural and numeric invariants. Use
14//! [`CadIr::to_canonical_json`] and [`CadIr::from_json`] for the versioned JSON
15//! form, and [`diff()`] for identity-based structural comparison.
16//!
17//! Format crates implement [`Codec`]. Detection selects a codec from a byte
18//! prefix, inspection enumerates a container, and decoding returns a
19//! [`DecodeResult`]. Operation failures use [`CodecError`]. A successful decode
20//! reports partial transfer through [`DecodeReport`] and [`LossNote`].
21//!
22//! [`Annotations`] records source locations and fidelity by globally unique
23//! entity ID. An omitted exactness entry means byte-exact; explicit entries
24//! distinguish derived, inferred, and unknown values. Native namespaces and
25//! unknown records retain source-specific data outside the neutral model.
26//!
27//! Product components, occurrence instancing, and assembly joints have neutral arenas.
28//! Product prototypes and occurrence trees retain assembly identity and
29//! placement. Joint and mate constraints are reserved.
30
31pub mod annotations;
32pub mod appearance;
33pub mod attributes;
34pub mod be;
35pub mod bytes;
36pub mod codec;
37pub mod compression;
38pub mod cursor;
39pub mod decode;
40
41pub mod diff;
42pub mod document;
43pub mod drawings;
44pub mod eval;
45pub mod examples;
46pub mod features;
47pub mod geometry;
48pub mod hash;
49
50pub mod ids;
51pub mod le;
52pub mod math;
53pub mod native;
54pub mod pmi;
55pub mod presentation;
56pub mod product;
57pub mod products;
58mod provenance;
59pub mod read;
60pub mod report;
61pub mod semantic_annotations;
62pub mod sketches;
63pub mod source_fidelity;
64pub mod spreadsheets;
65pub mod subd;
66pub mod tessellation;
67pub mod topology;
68pub mod transform;
69pub mod units;
70pub mod validate;
71
72pub use annotations::{AnnotationBuilder, Annotations, ExactnessNote, Provenance};
73pub use codec::{
74    CadirEncoder, Codec, CodecEntry, CodecError, Confidence, ContainerEntry, ContainerSummary,
75    DecodeOptions, DecodeResult, Encoder, ReadSeek,
76};
77pub use diff::{diff, ArenaDiff, IrDiff, ModifiedEntity};
78pub use document::{CadIr, SourceMeta, IR_VERSION};
79pub use features::{
80    BodyRetentionMode, BodySelection, BodyTrimSide, CoilConstruction, CoilExtent, CoilPlacement,
81    CoilResult, CoilSection, CoilSectionPlacement, ConfigurationBodies, ConfigurationId,
82    CurveProjectionDirection, CurveProjectionDirectionState, DesignConfiguration, DesignParameter,
83    FaceMotion, Feature, FeatureDefinition, FeatureId, ParameterId, ParameterPmi, ParameterValue,
84    PmiDimensionSubtype, ScaleCenter, ScaleFactors, SketchSpace,
85};
86pub use native::{LossCount, Native, NativeConvertError, NativeNamespace, NativeRecord};
87pub use pmi::{
88    DatumReference, DimensionKind, GeometricToleranceKind, PmiAnnotation, PmiDefinition,
89    PmiQuantity, PmiTarget, PmiValue,
90};
91pub use presentation::{
92    CameraState, PresentationDocument, PresentationId, PresentationState, ViewPresentation,
93};
94pub use presentation::{PresentationItem, PresentationLayer};
95pub use product::{OccurrenceParent, Product, ProductOccurrence};
96pub use products::{
97    AssemblyJoint, Component, ComponentId, ComponentKind, ComponentReference, CopyOnChangePolicy,
98    ExternalDocumentReference, ExternalResolution, JointId, JointKind, JointLimits, JointOperand,
99    Occurrence, OccurrenceId,
100};
101/// Source location attached to a [`LossNote`].
102pub use provenance::Provenance as LossProvenance;
103pub use provenance::{Exactness, SourceObjectAssociation};
104pub use report::{
105    Check, DecodeReport, ExportReport, Finding, LossCategory, LossCode, LossNote, Severity,
106    StrictConsequence, ValidationReport,
107};
108pub use sketches::{
109    Sketch, SketchAxis, SketchConstraint, SketchConstraintDefinition, SketchConstraintId,
110    SketchCoordinateAxis, SketchDistanceMeasurement, SketchEntity, SketchEntityId, SketchEntityUse,
111    SketchGeometry, SketchId, SketchNativeOperand, SketchPlacement, SpatialSketch,
112    SpatialSketchEntity, SpatialSketchEntityId, SpatialSketchEntityUse, SpatialSketchGeometry,
113    SpatialSketchId, SpatialSketchProfile,
114};
115pub use source_fidelity::{RetainedSourceRecord, SourceFidelity, SOURCE_FIDELITY_VERSION};
116pub use spreadsheets::{Spreadsheet, SpreadsheetDimension, SpreadsheetId, SpreadsheetRange};
117pub use subd::{
118    SubdEdge, SubdEdgeTag, SubdEdgeUse, SubdFace, SubdScheme, SubdSurface, SubdVertex,
119    SubdVertexTag,
120};
121pub use unknown::{NativeUnknownRecord, UnknownRecord};
122pub use validate::{validate, validate_with_source_fidelity};
123
124pub mod unknown;
125
126/// Generate the JSON Schema for the current [`CadIr`] representation.
127pub fn cadir_json_schema() -> schemars::Schema {
128    schemars::schema_for!(CadIr)
129}
130
131#[cfg(test)]
132mod tests;