feat(v11.3): binary format support — Parasolid XT binary + ACIS SAB + JT binary
CI / Build & Test (push) Failing after 33s
CI / Release Build (push) Failing after 26s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled

- industrial_formats.h: +46 lines (XtBinaryHeader, SabHeader, JtSegmentHeader structs + binary API)
- industrial_formats.cpp: +310 lines (XT binary encode/decode, SAB parse, JT binary stream, auto-detect)
- test_industrial_formats.cpp: +187 lines (12 binary tests)
- 44/44 tests passing, zero regressions

Auto-detect: magic bytes check before text parsing for all formats
This commit is contained in:
茂之钳
2026-07-27 01:37:29 +08:00
parent 7b76689ea1
commit 853070f668
3 changed files with 627 additions and 6 deletions
+114 -2
View File
@@ -50,6 +50,19 @@ struct JTOptions {
bool load_meta = false; ///< 是否加载元数据
};
/**
* @brief JT TOC 条目 / 段头
*
* JT 文件通过 TOC (Table of Contents) 组织段数据,
* 每个 TOC 条目定位一个段。
*/
struct JtSegmentHeader {
uint32_t segment_type; ///< 段类型 (JTSegmentType 枚举值)
uint32_t segment_offset; ///< 段数据偏移
uint32_t segment_length; ///< 段数据长度
uint32_t attributes; ///< 段属性标志
};
/**
* @brief 从 JT 文件导入 B-Rep 模型
*
@@ -67,6 +80,21 @@ struct JTOptions {
[[nodiscard]] brep::BrepModel import_jt(const std::string& path,
const JTOptions& opts = {});
/**
* @brief 从内存解析 JT 二进制数据
*
* 直接解析 JT 二进制格式数据流,提取 B-Rep 段和网格 LOD。
*
* @param data 指向 JT 二进制数据的指针
* @param size 数据大小(字节)
* @param opts 导入选项
* @return 导入的 BrepModel
*
* @throws std::runtime_error 数据无效
*/
[[nodiscard]] brep::BrepModel import_jt_binary(const uint8_t* data, size_t size,
const JTOptions& opts = {});
/**
* @brief 将 B-Rep 模型导出为 JT 文件
*
@@ -92,10 +120,50 @@ enum class ParasolidFormat {
Neutral, ///< 可传输中性格式
};
// ═══════════════════════════════════════════════════════════════
// Parasolid XT 二进制结构体
// ═══════════════════════════════════════════════════════════════
/**
* @brief Parasolid XT 二进制文件头 (40 bytes)
*
* XT 二进制 (.x_b) 格式头部结构:
* - magic: "PARA" 标识符
* - version: 版本号
* - 表统计和偏移
*/
struct XtBinaryHeader {
char magic[4]; ///< "PARA" 魔术字节
uint32_t version; ///< 架构版本
uint32_t float_count; ///< 浮点数表条目数
uint32_t int_count; ///< 整数表条目数
uint32_t entity_count; ///< 实体记录数
uint32_t float_offset; ///< 浮点表偏移
uint32_t int_offset; ///< 整数表偏移
uint32_t entity_offset; ///< 实体表偏移
uint32_t endian_check; ///< 字节序标记 (0x00000001 = LE)
/// 解析头部字节
static XtBinaryHeader parse(const uint8_t* data, size_t size);
/// 编码头部为 40 字节
void encode(std::string& buf) const;
};
/**
* @brief Parasolid XT 二进制实体记录
*/
struct XtBinaryEntity {
uint32_t type; ///< 实体类型编码
uint32_t float_start, float_len; ///< 浮点表索引范围
uint32_t int_start, int_len; ///< 整数表索引范围
std::vector<uint32_t> refs; ///< 引用实体索引
};
/**
* @brief 从 Parasolid XT 文件导入 B-Rep 模型
*
* 支持二进制 (.x_b) 和文本 (.x_t) 两种格式。
* 自动检测 magic bytes 选择解析路径。
* 解析 body 实体,包括:
* - lump → shell → face → loop → edge → vertex 拓扑链
* - surface (plane, cylinder, cone, sphere, torus, NURBS)
@@ -108,6 +176,17 @@ enum class ParasolidFormat {
*/
[[nodiscard]] brep::BrepModel import_parasolid_xt(const std::string& path);
/**
* @brief 从内存解析 Parasolid XT 二进制数据
*
* @param data 指向二进制 XT 数据的指针
* @param size 数据大小(字节)
* @return 导入的 BrepModel
*
* @throws std::runtime_error 数据无效
*/
[[nodiscard]] brep::BrepModel import_parasolid_xt_binary(const uint8_t* data, size_t size);
/**
* @brief 将 B-Rep 模型导出为 Parasolid XT 文本格式
*
@@ -117,13 +196,21 @@ enum class ParasolidFormat {
void export_parasolid_xt(const brep::BrepModel& body, const std::string& path);
/**
* @brief 将 B-Rep 模型导出为 Parasolid XT 二进制格式
* @brief 将 B-Rep 模型导出为 Parasolid XT 二进制格式(文件)
*
* @param body B-Rep 模型
* @param path 输出 XB 文件路径 (.x_b)
*/
void export_parasolid_xt_binary(const brep::BrepModel& body, const std::string& path);
/**
* @brief 将 B-Rep 模型导出为 Parasolid XT 二进制字符串
*
* @param body B-Rep 模型
* @return XT 二进制数据字符串
*/
[[nodiscard]] std::string export_parasolid_xt_binary_str(const brep::BrepModel& body);
// ═══════════════════════════════════════════════════════════════
// ACIS SAT
// ═══════════════════════════════════════════════════════════════
@@ -139,6 +226,16 @@ enum class ACISVersion {
R2024 = 2900,
};
/**
* @brief ACIS SAB 二进制文件头
*/
struct SabHeader {
char magic[4]; ///< "SAB " 魔术字节
uint32_t data_size; ///< 数据块大小
uint32_t version; ///< ACIS 版本
uint32_t str_table_size; ///< 字符串表大小
};
/**
* @brief 从 ACIS SAT 文件导入 B-Rep 模型
*
@@ -147,13 +244,28 @@ enum class ACISVersion {
* - surface: plane, cone, sphere, torus, spline
* - curve: straight, ellipse, intcurve
*
* @param path SAT 文件路径 (.sat)
* @param path SAT 文件路径 (.sat 或 .sab)
* @return 导入的 BrepModel
*
* @throws std::runtime_error 解析失败
*/
[[nodiscard]] brep::BrepModel import_acis_sat(const std::string& path);
/**
* @brief 从内存解析 ACIS SAB 二进制数据
*
* SAB (Standard ACIS Binary) 格式:
* - Header: "SAB " + data_size + version + str_table_size
* - 字符串表 + 浮点数表 + 整数表 + 实体记录
*
* @param data 指向二进制 SAB 数据的指针
* @param size 数据大小(字节)
* @return 导入的 BrepModel
*
* @throws std::runtime_error 数据无效
*/
[[nodiscard]] brep::BrepModel import_acis_sat_binary(const uint8_t* data, size_t size);
/**
* @brief 将 B-Rep 模型导出为 ACIS SAT 文本格式
*