#pragma once /** * @file format_io.h * @brief CAD 格式导入健壮性增强 * * 自动格式检测、容错解析、批量导入。 * * @ingroup foundation */ #include "vde/brep/brep.h" #include #include #include namespace vde::brep { // ═══════════════════════════════════════════════════════════ // Format detection // ═══════════════════════════════════════════════════════════ /// 检测到的 CAD 格式 enum class CadFormat { Unknown, STEP, IGES, STL_ASCII, STL_Binary, }; /** * @brief 自动检测 CAD 文件格式 * * 通过文件头签名和扩展名判断格式。 * * @param filepath 文件路径 * @return 检测到的格式,未知时返回 Unknown */ [[nodiscard]] CadFormat detect_format(const std::string& filepath); /** * @brief 自动检测内存中的 CAD 数据格式 * * @param data 数据内容 * @return 检测到的格式 */ [[nodiscard]] CadFormat detect_format_from_data(const std::string& data); // ═══════════════════════════════════════════════════════════ // Auto import // ═══════════════════════════════════════════════════════════ /** * @brief 智能导入:自动检测格式并导入 * * 支持 STEP, IGES 格式的自动识别和导入。 * 解析错误时不会崩溃,而是返回已成功解析的部分。 * * @param filepath 文件路径 * @return B-Rep 模型列表和格式信息,解析失败时返回空 */ [[nodiscard]] std::vector auto_import(const std::string& filepath); /** * @brief 从内存数据智能导入 * * @param data CAD 数据字符串 * @return B-Rep 模型列表 */ [[nodiscard]] std::vector auto_import_from_string(const std::string& data); // ═══════════════════════════════════════════════════════════ // Batch import with error recovery // ═══════════════════════════════════════════════════════════ /// 批量导入结果 struct BatchImportResult { int total_files = 0; int success_count = 0; int partial_count = 0; ///< 部分成功(有些实体失败) int fail_count = 0; std::vector errors; std::vector models; [[nodiscard]] std::string summary() const; }; /** * @brief 批量导入 CAD 文件 * * 对每个文件尝试自动检测格式并导入。 * 单个文件失败不影响后续文件。 * * @param filepaths 文件路径列表 * @return 批量导入结果 */ [[nodiscard]] BatchImportResult batch_import( const std::vector& filepaths); } // namespace vde::brep