Skip to main content

cadmpeg_codec_inventor/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Reads Autodesk Inventor IPT and IAM documents into [`cadmpeg_ir::CadIr`].
3//!
4//! [`InventorCodec`] detects Inventor documents from the compound-file
5//! directory structure. It does not classify unrelated CFB files as Inventor.
6//!
7//! <!-- generated: capability inventor -->
8//! Support: L3 ([ladder](https://github.com/cadmpeg/cadmpeg/blob/main/docs/format-support.md#autodesk-inventor-ipt-and-iam)).
9//! <!-- /generated: capability inventor -->
10
11mod annotation;
12mod assembly;
13mod compact_matrix;
14mod container;
15mod coverage;
16mod database;
17mod decode;
18mod design;
19mod dialect;
20mod drawing;
21mod external_reference;
22mod feature;
23#[doc(hidden)]
24pub mod fuzz;
25mod kernel;
26/// Byte-offset constants generated from `docs/layouts/inventor.toml`.
27mod layout;
28mod loss;
29mod materials;
30mod native;
31mod pmdc;
32mod presentation;
33mod property_set;
34mod protein;
35mod reader;
36mod record_identity;
37mod record_issue;
38mod records;
39mod rse;
40mod sketch;
41mod validate;
42
43use cadmpeg_container::compound::CompoundPrefixProbe;
44use cadmpeg_core::decode::{DecodeContext, View};
45use cadmpeg_core::CodecError;
46use cadmpeg_ir::codec::{CodecBackend, Confidence, Decoded, FormatId};
47use cadmpeg_ir::ContainerSummary;
48use cadmpeg_ir::{report::check::Finding, CadIr};
49
50fn issue_detail(error: CodecError) -> Result<String, CodecError> {
51    if matches!(&error, CodecError::ResourceLimit(_)) {
52        Err(error)
53    } else {
54        Ok(error.to_string())
55    }
56}
57
58/// Read-only Autodesk Inventor IPT and IAM codec.
59#[derive(Debug, Default, Clone, Copy)]
60pub struct InventorCodec;
61
62impl CodecBackend for InventorCodec {
63    const FORMAT: FormatId = FormatId::new(dialect::FORMAT);
64
65    fn validate_native(
66        ctx: &DecodeContext<'_>,
67        ir: &CadIr,
68        _source: Option<&cadmpeg_ir::SourceFidelity>,
69    ) -> Result<Vec<Finding>, CodecError> {
70        validate::validate_native(ctx, ir)
71    }
72
73    fn detect_impl(
74        &self,
75        ctx: &cadmpeg_core::decode::DecodeContext<'_>,
76        prefix: cadmpeg_core::decode::View<'_>,
77    ) -> Result<Confidence, cadmpeg_core::CodecError> {
78        let prefix = prefix.window();
79        let probe = CompoundPrefixProbe::inspect(ctx, View::over_retained(prefix))?;
80        let CompoundPrefixProbe::DirectoryEvidence(paths) = probe else {
81            return Ok(Confidence::No);
82        };
83        if container::has_inventor_evidence(&paths) {
84            Ok(Confidence::High)
85        } else {
86            Ok(Confidence::No)
87        }
88    }
89
90    fn inspect_impl(
91        &self,
92        ctx: &DecodeContext<'_>,
93        root: View<'_>,
94    ) -> Result<ContainerSummary, CodecError> {
95        container::InventorContainer::open(ctx, root)?.summary()
96    }
97
98    fn decode_impl(&self, ctx: &DecodeContext<'_>, root: View<'_>) -> Result<Decoded, CodecError> {
99        decode::decode(ctx, root)
100    }
101}
102
103#[cfg(test)]
104mod golden_tests;
105#[cfg(test)]
106mod test_support;
107
108#[cfg(test)]
109mod integration_tests;