brep_kernel/io/parasolid/mod.rs
1//! Parasolid XT (transmit file) import.
2//!
3//! Written from the published *Parasolid XT Format Reference*; section
4//! numbers in this module are that reference's (July 2022 edition).
5//!
6//! * [`parse_xt_text`] reads a text part (`.x_t`, `.xmt_txt`) into its node
7//! graph: the header, the token stream, and each node laid out by the base
8//! schema (`schema`) as edited by the file's embedded schema deltas.
9//! * [`import_parasolid`] and [`import_parasolid_report`] read its bodies
10//! into solids by translating each to Part 21 for the STEP importer
11//! (`to_step`), with names and colours.
12
13mod geometry;
14mod import;
15mod reader;
16mod schema;
17mod to_step;
18
19
20pub use import::{import_parasolid, import_parasolid_report, ParasolidImportReport};
21pub use reader::{parse_xt_text, Node, NodeLayout, Value, XtFile};
22pub use schema::{Count as XtFieldCount, FieldDef as XtFieldDef, Kind as XtFieldKind};
23
24/// Whether `text` is a Parasolid text part: it starts with the transmit
25/// header's preamble (§3.1), or, written without a header, with the part
26/// data's `T<length> : TRANSMIT FILE` banner (§3.2). Only the start counts,
27/// so a STEP file that mentions Parasolid in its own header is not one.
28pub fn is_xt_text(text: &str) -> bool {
29 let start = text.trim_start_matches(['\u{feff}', ' ', '\t', '\r', '\n']);
30 if start.starts_with("**ABCDEFGHIJKLMNOPQRSTUVWXYZ") {
31 return start.lines().nth(1).is_some_and(|line| line.starts_with("**PARASOLID"));
32 }
33 let Some(rest) = start.strip_prefix('T') else { return false };
34 let digits = rest.bytes().take_while(u8::is_ascii_digit).count();
35 digits > 0 && rest[digits..].trim_start().starts_with(": TRANSMIT FILE")
36}