2026-07-26 18:41:28 +08:00
|
|
|
|
#pragma once
|
2026-07-26 21:34:44 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file industrial_formats.h
|
|
|
|
|
|
* @brief 工业 CAD 格式导入导出
|
|
|
|
|
|
*
|
|
|
|
|
|
* 支持的格式:
|
|
|
|
|
|
* - JT (ISO 14306) — Siemens PLM 轻量化/精确几何
|
|
|
|
|
|
* - Parasolid XT — Siemens 内核原生格式
|
|
|
|
|
|
* - ACIS SAT — Dassault Spatial 内核原生格式
|
|
|
|
|
|
* - IFC (ISO 16739) — BIM 交换格式
|
|
|
|
|
|
* - STEP AP242 — 带 PMI 的产品制造信息
|
|
|
|
|
|
* - PDF 3D — 嵌入式 U3D/PRC
|
|
|
|
|
|
*
|
|
|
|
|
|
* @ingroup foundation
|
|
|
|
|
|
*/
|
2026-07-26 18:41:28 +08:00
|
|
|
|
#include "vde/brep/brep.h"
|
2026-07-26 21:34:44 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
2026-07-26 18:41:28 +08:00
|
|
|
|
namespace vde::io {
|
2026-07-26 21:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
// JT (ISO 14306)
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief JT 文件段类型
|
|
|
|
|
|
*
|
|
|
|
|
|
* JT 文件由 LSG (Logical Scene Graph) 组织,包含多个段。
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum class JTSegmentType : uint8_t {
|
|
|
|
|
|
LogicalSceneGraph = 1, ///< LSG 根段
|
|
|
|
|
|
Part = 2, ///< 零件段
|
|
|
|
|
|
Instance = 3, ///< 实例引用段
|
|
|
|
|
|
MeshLOD = 4, ///< 网格 LOD 段
|
|
|
|
|
|
Brep = 5, ///< B-Rep 精确几何段
|
|
|
|
|
|
MetaData = 6, ///< 元数据段
|
|
|
|
|
|
PMI = 7, ///< PMI 标注段
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief JT 导入选项
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct JTOptions {
|
|
|
|
|
|
bool load_brep = true; ///< 是否加载精确 B-Rep 几何
|
|
|
|
|
|
bool load_mesh = true; ///< 是否加载三角网格
|
|
|
|
|
|
int max_lod = 3; ///< 最大 LOD 级别
|
|
|
|
|
|
bool load_pmi = false; ///< 是否加载 PMI 标注
|
|
|
|
|
|
bool load_meta = false; ///< 是否加载元数据
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 从 JT 文件导入 B-Rep 模型
|
|
|
|
|
|
*
|
|
|
|
|
|
* 解析 ISO 14306 JT 文件格式,提取 B-Rep 段中的精确几何或
|
|
|
|
|
|
* 将网格 LOD 转换为 BrepModel。
|
|
|
|
|
|
*
|
|
|
|
|
|
* JT 文件结构:TOC → Segment → Part/Mesh/B-Rep
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param path JT 文件路径 (.jt)
|
|
|
|
|
|
* @param opts 导入选项
|
|
|
|
|
|
* @return 导入的 BrepModel
|
|
|
|
|
|
*
|
|
|
|
|
|
* @throws std::runtime_error 文件无效或无法解析
|
|
|
|
|
|
*/
|
|
|
|
|
|
[[nodiscard]] brep::BrepModel import_jt(const std::string& path,
|
|
|
|
|
|
const JTOptions& opts = {});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 JT 文件
|
|
|
|
|
|
*
|
|
|
|
|
|
* 写入包含 B-Rep 段和网格 LOD 的 JT 文件。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param body B-Rep 模型
|
|
|
|
|
|
* @param path 输出 JT 文件路径
|
|
|
|
|
|
*
|
|
|
|
|
|
* @throws std::runtime_error 写入失败
|
|
|
|
|
|
*/
|
2026-07-26 18:41:28 +08:00
|
|
|
|
void export_jt(const brep::BrepModel& body, const std::string& path);
|
2026-07-26 21:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
// Parasolid XT
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Parasolid XT 格式类型
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum class ParasolidFormat {
|
|
|
|
|
|
Binary, ///< 二进制 X_B / X_T 格式
|
|
|
|
|
|
Text, ///< 文本格式 (ASCII)
|
|
|
|
|
|
Neutral, ///< 可传输中性格式
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 从 Parasolid XT 文件导入 B-Rep 模型
|
|
|
|
|
|
*
|
|
|
|
|
|
* 支持二进制 (.x_b) 和文本 (.x_t) 两种格式。
|
|
|
|
|
|
* 解析 body 实体,包括:
|
|
|
|
|
|
* - lump → shell → face → loop → edge → vertex 拓扑链
|
|
|
|
|
|
* - surface (plane, cylinder, cone, sphere, torus, NURBS)
|
|
|
|
|
|
* - curve (line, circle, ellipse, NURBS)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param path XT 文件路径 (.x_t / .x_b)
|
|
|
|
|
|
* @return 导入的 BrepModel
|
|
|
|
|
|
*
|
|
|
|
|
|
* @throws std::runtime_error 解析失败
|
|
|
|
|
|
*/
|
2026-07-26 18:41:28 +08:00
|
|
|
|
[[nodiscard]] brep::BrepModel import_parasolid_xt(const std::string& path);
|
2026-07-26 21:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 Parasolid XT 文本格式
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param body B-Rep 模型
|
|
|
|
|
|
* @param path 输出 XT 文件路径
|
|
|
|
|
|
*/
|
2026-07-26 18:41:28 +08:00
|
|
|
|
void export_parasolid_xt(const brep::BrepModel& body, const std::string& path);
|
2026-07-26 21:34:44 +08:00
|
|
|
|
|
2026-07-27 01:10:58 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @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);
|
|
|
|
|
|
|
2026-07-26 21:34:44 +08:00
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
// ACIS SAT
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief ACIS SAT 版本
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum class ACISVersion {
|
|
|
|
|
|
V7 = 700,
|
|
|
|
|
|
V16 = 1600,
|
|
|
|
|
|
V21 = 2100,
|
|
|
|
|
|
V27 = 2700,
|
|
|
|
|
|
R2024 = 2900,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 从 ACIS SAT 文件导入 B-Rep 模型
|
|
|
|
|
|
*
|
|
|
|
|
|
* 解析 SAT (Save As Text) 格式,支持:
|
|
|
|
|
|
* - body → lump → shell → face → loop → coedge → edge → vertex
|
|
|
|
|
|
* - surface: plane, cone, sphere, torus, spline
|
|
|
|
|
|
* - curve: straight, ellipse, intcurve
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param path SAT 文件路径 (.sat)
|
|
|
|
|
|
* @return 导入的 BrepModel
|
|
|
|
|
|
*
|
|
|
|
|
|
* @throws std::runtime_error 解析失败
|
|
|
|
|
|
*/
|
2026-07-26 18:41:28 +08:00
|
|
|
|
[[nodiscard]] brep::BrepModel import_acis_sat(const std::string& path);
|
2026-07-26 21:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 ACIS SAT 文本格式
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param body B-Rep 模型
|
|
|
|
|
|
* @param path 输出 SAT 文件路径
|
|
|
|
|
|
* @param version ACIS 版本号
|
|
|
|
|
|
*/
|
|
|
|
|
|
void export_acis_sat(const brep::BrepModel& body, const std::string& path,
|
|
|
|
|
|
ACISVersion version = ACISVersion::V27);
|
|
|
|
|
|
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
// IFC (ISO 16739)
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief IFC 实体类型(常用)
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum class IfcEntityType {
|
|
|
|
|
|
Unknown,
|
|
|
|
|
|
IfcProject,
|
|
|
|
|
|
IfcSite,
|
|
|
|
|
|
IfcBuilding,
|
|
|
|
|
|
IfcBuildingStorey,
|
|
|
|
|
|
IfcWall,
|
|
|
|
|
|
IfcSlab,
|
|
|
|
|
|
IfcBeam,
|
|
|
|
|
|
IfcColumn,
|
|
|
|
|
|
IfcDoor,
|
|
|
|
|
|
IfcWindow,
|
|
|
|
|
|
IfcRoof,
|
|
|
|
|
|
IfcStair,
|
|
|
|
|
|
IfcRailing,
|
|
|
|
|
|
IfcPlate,
|
|
|
|
|
|
IfcMember,
|
|
|
|
|
|
IfcBuildingElementProxy,
|
|
|
|
|
|
IfcProductDefinitionShape,
|
|
|
|
|
|
IfcShapeRepresentation,
|
|
|
|
|
|
IfcExtrudedAreaSolid,
|
|
|
|
|
|
IfcFacetedBrep,
|
|
|
|
|
|
IfcPolyLoop,
|
|
|
|
|
|
IfcFaceOuterBound,
|
|
|
|
|
|
IfcFace,
|
|
|
|
|
|
IfcClosedShell,
|
|
|
|
|
|
IfcCartesianPoint,
|
|
|
|
|
|
IfcDirection,
|
|
|
|
|
|
IfcAxis2Placement3D,
|
|
|
|
|
|
IfcLocalPlacement,
|
|
|
|
|
|
IfcPolyline,
|
|
|
|
|
|
IfcArbitraryClosedProfileDef,
|
|
|
|
|
|
IfcRectangleProfileDef,
|
|
|
|
|
|
IfcCircleProfileDef,
|
|
|
|
|
|
IfcMaterial,
|
|
|
|
|
|
IfcRelAssociatesMaterial,
|
|
|
|
|
|
IfcOwnerHistory,
|
|
|
|
|
|
IfcPerson,
|
|
|
|
|
|
IfcOrganization,
|
|
|
|
|
|
IfcApplication,
|
|
|
|
|
|
IfcUnitAssignment,
|
|
|
|
|
|
IfcSIUnit,
|
|
|
|
|
|
IfcGeometricRepresentationContext,
|
|
|
|
|
|
IfcGeometricRepresentationSubContext,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 从 IFC 文件导入 B-Rep 模型列表
|
|
|
|
|
|
*
|
|
|
|
|
|
* 解析 IFC-SPF (ISO 10303-21) 格式,提取 IfcProduct 实体:
|
|
|
|
|
|
* - IfcWall, IfcSlab, IfcBeam, IfcColumn
|
|
|
|
|
|
* - IfcDoor, IfcWindow, IfcPlate, IfcMember
|
|
|
|
|
|
* - 支持 IfcExtrudedAreaSolid 和 IfcFacetedBrep
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param path IFC 文件路径 (.ifc)
|
|
|
|
|
|
* @return 导入的 BrepModel 列表(每个产品一个元素)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @throws std::runtime_error 解析失败
|
|
|
|
|
|
*/
|
|
|
|
|
|
[[nodiscard]] std::vector<brep::BrepModel> import_ifc(const std::string& path);
|
|
|
|
|
|
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
// STEP AP242
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief STEP AP242 PMI 标注类型
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct StepPMIAnnotation {
|
|
|
|
|
|
std::string type; ///< 标注类型(linear_dimension, angular_dimension, etc.)
|
|
|
|
|
|
std::string id; ///< 标注 ID
|
|
|
|
|
|
std::string description; ///< 描述文本
|
|
|
|
|
|
double nominal_value = 0.0; ///< 名义尺寸
|
|
|
|
|
|
double upper_tolerance = 0.0; ///< 上偏差
|
|
|
|
|
|
double lower_tolerance = 0.0; ///< 下偏差
|
|
|
|
|
|
std::string datum_system; ///< 基准系统引用
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief STEP AP242 导出选项
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct StepAP242Options {
|
|
|
|
|
|
bool include_pmi = true; ///< 是否包含 PMI 标注
|
|
|
|
|
|
bool include_tolerance = true; ///< 是否包含公差信息
|
|
|
|
|
|
bool include_material = true; ///< 是否包含材料信息
|
|
|
|
|
|
bool include_validation = true; ///< 是否包含验证属性
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 STEP AP242 字符串
|
|
|
|
|
|
*
|
|
|
|
|
|
* 在 AP214 基础上扩展,新增:
|
|
|
|
|
|
* - PRODUCT_MANUFACTURING_INFORMATION (PMI)
|
|
|
|
|
|
* - DIMENSIONAL_CHARACTERISTIC_REPRESENTATION
|
|
|
|
|
|
* - SHAPE_DIMENSION_REPRESENTATION
|
|
|
|
|
|
* - GEOMETRIC_TOLERANCE
|
|
|
|
|
|
* - DATUM_SYSTEM
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param bodies B-Rep 体列表
|
|
|
|
|
|
* @param annotations PMI 标注列表(可为空)
|
|
|
|
|
|
* @param opts 导出选项
|
|
|
|
|
|
* @return STEP AP242 格式字符串
|
|
|
|
|
|
*/
|
|
|
|
|
|
[[nodiscard]] std::string export_step_ap242(
|
|
|
|
|
|
const std::vector<brep::BrepModel>& bodies,
|
|
|
|
|
|
const std::vector<StepPMIAnnotation>& annotations = {},
|
|
|
|
|
|
const StepAP242Options& opts = {});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 STEP AP242 文件
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param path 输出文件路径 (.stp / .step)
|
|
|
|
|
|
* @param bodies B-Rep 体列表
|
|
|
|
|
|
* @param annotations PMI 标注
|
|
|
|
|
|
* @param opts 导出选项
|
|
|
|
|
|
*/
|
|
|
|
|
|
void export_step_ap242_file(const std::string& path,
|
|
|
|
|
|
const std::vector<brep::BrepModel>& bodies,
|
|
|
|
|
|
const std::vector<StepPMIAnnotation>& annotations = {},
|
|
|
|
|
|
const StepAP242Options& opts = {});
|
|
|
|
|
|
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
// PDF 3D
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 PDF 3D (U3D 嵌入)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 生成包含 U3D 模型嵌入的 PDF 文件。
|
|
|
|
|
|
* U3D 是 ECMA-363 标准,支持精确几何和三角网格。
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param body B-Rep 模型
|
|
|
|
|
|
* @return PDF 文件二进制数据
|
|
|
|
|
|
*/
|
2026-07-26 18:41:28 +08:00
|
|
|
|
[[nodiscard]] std::vector<uint8_t> export_pdf3d(const brep::BrepModel& body);
|
2026-07-26 21:34:44 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将 B-Rep 模型导出为 PDF 3D 文件
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param path 输出 PDF 文件路径
|
|
|
|
|
|
* @param body B-Rep 模型
|
|
|
|
|
|
*/
|
|
|
|
|
|
void export_pdf3d_file(const std::string& path, const brep::BrepModel& body);
|
|
|
|
|
|
|
2026-07-26 18:41:28 +08:00
|
|
|
|
} // namespace vde::io
|