cadmpeg_codec_catia/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2//! Reads CATIA V5 `.CATPart` files into [`cadmpeg_ir::CadIr`].
3//!
4//! [`CatiaCodec`] is the crate's only entry point. It implements the shared
5//! [`Codec`] interface: it detects the `V5_CFV2` file signature, inspects the
6//! catalogued logical streams, identifies the storage variant, and decodes the
7//! record families supported for that variant.
8//!
9//! Support level: [L2](https://github.com/cadmpeg/cadmpeg/blob/main/docs/format-support.md#support-ladder)
10//! on the cadmpeg support ladder for the standard-nested layout; other layouts
11//! are L1.
12//!
13//! # Decode a part
14//!
15//! ```
16//! use std::fs::File;
17//!
18//! use cadmpeg_codec_catia::CatiaCodec;
19//! use cadmpeg_ir::{CodecEntry, DecodeOptions};
20//!
21//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
22//! let mut input = File::open("part.CATPart")?;
23//! let decoded = CatiaCodec.decode(&mut input, &DecodeOptions::default())?;
24//! println!("{} surfaces", decoded.ir.model.surfaces.len());
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! Read `decoded.report.losses` before consuming model relationships. A partial
30//! decode preserves the native payload in an unknown record and reports the
31//! model layers that remain unresolved.
32//!
33//! Byte-level format semantics are documented in
34//! [`docs/formats/catia.md`](https://github.com/cadmpeg/cadmpeg/blob/main/docs/formats/catia.md).
35//!
36//! # Internal layout
37//!
38//! `wire` reads endian scalars and tag records; `solve` holds the pure topology
39//! solvers; `families/*` pair each record vocabulary with its decode route; and
40//! `assemble` lowers decoded records into the neutral IR. All of these are
41//! crate-private; nothing but `CatiaCodec` is part of the public API.
42
43pub(crate) mod analytic;
44pub(crate) mod assemble;
45pub(crate) mod catalog;
46pub(crate) mod container;
47pub(crate) mod decode;
48pub(crate) mod families;
49pub(crate) mod native;
50pub(crate) mod nurbs;
51pub(crate) mod object_graph;
52pub(crate) mod solve;
53pub(crate) mod value_block;
54pub(crate) mod variant;
55pub(crate) mod wire;
56
57#[cfg(feature = "fuzz")]
58pub mod fuzz;
59
60/// Maximum number of exact rational-quadratic spans materialized for one
61/// angular curve or surface direction from untrusted native parameters.
62pub(crate) const MAX_EXACT_ARC_SPANS: usize = 4_096;
63
64use cadmpeg_ir::codec::{Codec, CodecError, Confidence, ContainerSummary, DecodeResult};
65use cadmpeg_ir::decode::{DecodeContext, View};
66
67/// The CATIA V5 `.CATPart` codec.
68#[derive(Debug, Default, Clone, Copy)]
69pub struct CatiaCodec;
70
71impl Codec for CatiaCodec {
72 fn id(&self) -> &'static str {
73 "catia"
74 }
75
76 fn detect(&self, prefix: &[u8]) -> Confidence {
77 if container::looks_like_catia(prefix) {
78 Confidence::High
79 } else {
80 Confidence::No
81 }
82 }
83
84 fn inspect_impl(
85 &self,
86 _ctx: &DecodeContext<'_>,
87 root: View<'_>,
88 ) -> Result<ContainerSummary, CodecError> {
89 let scan = container::scan_bytes(root.window().to_vec());
90 Ok(container::summarize(&scan))
91 }
92
93 fn decode_impl(
94 &self,
95 ctx: &DecodeContext<'_>,
96 root: View<'_>,
97 ) -> Result<DecodeResult, CodecError> {
98 decode::decode(ctx, root)
99 }
100}
101
102#[cfg(test)]
103mod tests;