Skip to main content

cadmpeg_codec_step/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2#![cfg_attr(test, allow(clippy::unwrap_used))]
3//! Reads and writes [`cadmpeg_ir::CadIr`] documents as ISO 10303-21 STEP Part
4//! 21 exchange structures for AP203, AP214, and AP242.
5//!
6//! Support level: [L9](https://github.com/cadmpeg/cadmpeg/blob/main/docs/format-support.md#support-ladder)
7//! for AP242 editions 1–3 and AP203 editions 1–2/AP214.
8//!
9//! [`write_step`] emits the application protocol selected by
10//! [`StepWriteOptions::schema`]. It writes product and representation context,
11//! connected exact shape, product occurrences, tessellation, presentation,
12//! and PMI when the target schema carries those domains.
13//!
14//! # Export workflow
15//!
16//! Construct or decode a [`cadmpeg_ir::CadIr`], choose the header metadata in
17//! [`StepWriteOptions`], then write to any [`std::io::Write`] sink:
18//!
19//! ```
20//! use cadmpeg_ir::examples::unit_cube;
21//! use cadmpeg_codec_step::{write_step, StepWriteOptions};
22//!
23//! let ir = unit_cube();
24//! let mut bytes = Vec::new();
25//! let report = write_step(&ir, &mut bytes, &StepWriteOptions::default())?;
26//!
27//! assert!(bytes.starts_with(b"ISO-10303-21;"));
28//! assert!(report.census.total() > 0);
29//! # Ok::<(), cadmpeg_codec_step::StepError>(())
30//! ```
31//!
32//! Review [`cadmpeg_ir::ExportReport::losses`] before retaining report-mode
33//! output. [`StepUnsupportedPolicy::Reject`] rejects all such losses before any
34//! output byte is written. Opaque records, source attributes, unsupported
35//! procedural definitions, and target-schema incompatibilities are reported or
36//! rejected rather than silently discarded. Body and face colors become
37//! per-face `STYLED_ITEM` presentation; direct geometry and tessellation
38//! bindings retain their native presentation targets.
39//!
40//! Coordinates are emitted unchanged under a millimetre length-unit context.
41//! Callers must convert non-millimetre geometry before export. Analytic curves
42//! and surfaces map to their corresponding STEP carriers. Rational and
43//! non-rational NURBS use the `*_WITH_KNOTS` entities.
44//!
45//! [`StepError`] reports [`StepError::Unsupported`] under
46//! [`StepUnsupportedPolicy::Reject`] before any output is written, and
47//! [`StepError::Io`] for output-sink failures. Because the writer streams the
48//! header and DATA section after acceptance, an I/O failure can leave partial
49//! output.
50
51mod archive;
52mod codec;
53mod error;
54mod export;
55mod geometry;
56mod ids;
57mod lex;
58#[allow(dead_code)] // Loss catalog is consumed by tests and the writer.
59mod loss;
60mod options;
61mod parse;
62mod reader;
63mod signature;
64#[allow(dead_code)] // String helpers are part of the internal parser layer.
65mod strings;
66mod writer;
67
68#[doc(hidden)]
69pub mod fuzz;
70
71pub use codec::StepCodec;
72pub use error::StepError;
73pub use export::write_step;
74pub use options::{StepSchema, StepUnsupportedPolicy, StepWriteOptions};
75
76#[cfg(test)]
77mod golden_tests;
78#[cfg(test)]
79mod integration_tests;
80#[cfg(test)]
81pub(crate) mod test_support;