cadmpeg_codec_creo/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2//! Inspect and structurally decode PTC Creo Parametric and Pro/ENGINEER `.prt`
3//! files stored in the PSB container.
4//!
5//! [`CreoCodec`] is the normal public decode API. A hidden `fuzz` module
6//! exposes parser probes. Context-taking probes propagate errors and discard
7//! successful parser values; primitive probes return `()`. [`CreoCodec`]
8//! implements [`cadmpeg_ir::codec::Codec`]:
9//! it detects the `#UGC:1` and `#UGC:2` UGC signatures, inspects named sections,
10//! and decodes the geometry, topology, sketches, and design records supported
11//! for that layout.
12//!
13//! <!-- generated: capability creo -->
14//! Support: L1 ([ladder](https://github.com/cadmpeg/cadmpeg/blob/main/docs/format-support.md#creo-parametric-prt)).
15//! <!-- /generated: capability creo -->
16//!
17//! # Quick start
18//!
19//! Use [`cadmpeg_ir::Codec::inspect`] to enumerate sections and read container
20//! diagnostics:
21//!
22//! ```no_run
23//! use std::fs::File;
24//!
25//! use cadmpeg_codec_creo::CreoCodec;
26//! use cadmpeg_ir::codec::Codec;
27//! use cadmpeg_core::decode::InspectOptions;
28//!
29//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
30//! let mut input = File::open("part.prt")?;
31//! let summary = CreoCodec.inspect(&mut input, &InspectOptions::default())?;
32//! println!("{} sections", summary.entries.len());
33//! # Ok(())
34//! # }
35//! ```
36//!
37//! Use [`cadmpeg_ir::Codec::decode`] for a [`cadmpeg_ir::document::CadIr`] document and
38//! its [`cadmpeg_ir::report::decode::DecodeReport`].
39//!
40//! # Format model
41//!
42//! A PSB file begins with a `#UGC:1` or `#UGC:2` ASCII signature and header.
43//! Legacy persistence uses a `P_OBJECT` body with optional named sections;
44//! later persistence uses a table of contents and named binary sections.
45//! Detection uses the signature because Siemens NX also uses `.prt`.
46//!
47//! # Decode scope
48//!
49//! Decode transfers complete model-space planes, selected cylinders, placed
50//! cones, tori, and spheres when positional or feature construction establishes
51//! model space, interpolation and NURBS-related carriers with complete control
52//! bodies, reference lines, circles, and ellipses, connected topology with
53//! analytic intersections and pcurves, `SolidPrimdata` triangle strips, a root
54//! product identity occurrence, placed section sketches, and typed features,
55//! parameters, and expressions. It preserves PSB geometry sections as
56//! [`cadmpeg_ir::unknown::UnknownRecord`] values. The crate is read-only.
57//!
58//! Surface prototype parameters describe family templates rather than placed
59//! instances. Other per-instance coordinates, curve families, face bindings,
60//! and feature evaluation remain incomplete. The decode report identifies
61//! these losses.
62
63mod assembly;
64mod axis;
65mod compress;
66mod container;
67mod coverage;
68mod curve;
69mod datum;
70mod decode;
71mod dialect;
72mod double_xar;
73mod feature;
74mod identity;
75mod interpolation_grid;
76mod lane_refusal;
77/// Byte-offset constants generated from `docs/layouts/creo.toml`.
78mod layout;
79mod legacy;
80mod legacy_family;
81mod legacy_feature;
82mod legacy_geometry;
83mod loop_array;
84mod loss;
85mod placement;
86mod primdata;
87mod psb;
88mod reference;
89mod scalar;
90mod surface;
91mod topology;
92mod vecmath;
93
94#[doc(hidden)]
95pub mod fuzz;
96
97use cadmpeg_core::decode::{DecodeContext, View};
98use cadmpeg_core::CodecError;
99use cadmpeg_ir::codec::{CodecBackend, Confidence, Decoded, FormatId};
100use cadmpeg_ir::ContainerSummary;
101
102/// Codec for Creo Parametric and Pro/ENGINEER PSB `.prt` files.
103#[derive(Debug, Default, Clone, Copy)]
104pub struct CreoCodec;
105
106impl CodecBackend for CreoCodec {
107 const FORMAT: FormatId = FormatId::new(dialect::FORMAT);
108
109 fn detect_impl(
110 &self,
111 _ctx: &cadmpeg_core::decode::DecodeContext<'_>,
112 prefix: cadmpeg_core::decode::View<'_>,
113 ) -> Result<Confidence, cadmpeg_core::CodecError> {
114 let prefix = prefix.window();
115 // UGC signatures identify the Creo/Pro-E PSB container and
116 // distinguish it from a Siemens NX `.prt` sharing the extension.
117 if container::looks_like_creo(prefix) {
118 Ok(Confidence::High)
119 } else {
120 Ok(Confidence::No)
121 }
122 }
123
124 fn inspect_impl(
125 &self,
126 ctx: &DecodeContext<'_>,
127 root: View<'_>,
128 ) -> Result<ContainerSummary, CodecError> {
129 let scan = container::scan_bytes(ctx, root.window())?;
130 let classification = dialect::classify(&scan)?;
131 Ok(container::summarize(&scan, classification))
132 }
133
134 fn decode_impl(&self, ctx: &DecodeContext<'_>, root: View<'_>) -> Result<Decoded, CodecError> {
135 decode::decode(ctx, root)
136 }
137}
138
139#[cfg(test)]
140mod golden_tests;
141#[cfg(test)]
142mod integration_tests;
143#[cfg(test)]
144mod test_support;