diff --git a/include/vde/foundation/industrial_formats.h b/include/vde/foundation/industrial_formats.h index e587d406e..bdb024e73 100644 --- a/include/vde/foundation/industrial_formats.h +++ b/include/vde/foundation/industrial_formats.h @@ -192,16 +192,18 @@ struct XtBinaryEntity { * * @param body B-Rep 模型 * @param path 输出 XT 文件路径 + * @return 写出成功返回 true;文件无法创建/写入时返回 false */ -void export_parasolid_xt(const brep::BrepModel& body, const std::string& path); +bool export_parasolid_xt(const brep::BrepModel& body, const std::string& path); /** * @brief 将 B-Rep 模型导出为 Parasolid XT 二进制格式(文件) * * @param body B-Rep 模型 * @param path 输出 XB 文件路径 (.x_b) + * @return 写出成功返回 true;文件无法创建/写入时返回 false */ -void export_parasolid_xt_binary(const brep::BrepModel& body, const std::string& path); +bool export_parasolid_xt_binary(const brep::BrepModel& body, const std::string& path); /** * @brief 将 B-Rep 模型导出为 Parasolid XT 二进制字符串 @@ -272,8 +274,9 @@ struct SabHeader { * @param body B-Rep 模型 * @param path 输出 SAT 文件路径 * @param version ACIS 版本号 + * @return 写出成功返回 true;文件无法创建/写入时返回 false */ -void export_acis_sat(const brep::BrepModel& body, const std::string& path, +bool export_acis_sat(const brep::BrepModel& body, const std::string& path, ACISVersion version = ACISVersion::V27); // ═══════════════════════════════════════════════════════════════ @@ -359,9 +362,9 @@ enum class IfcEntityType { * @param bodies B-Rep 模型列表 * @param path 输出 IFC 文件路径 (.ifc) * - * @throws std::runtime_error 写入失败 + * @return 写出成功返回 true;文件无法创建/写入时返回 false */ -void export_ifc(const std::vector& bodies, const std::string& path); +bool export_ifc(const std::vector& bodies, const std::string& path); // ═══════════════════════════════════════════════════════════════ // STEP AP242 @@ -417,8 +420,9 @@ struct StepAP242Options { * @param bodies B-Rep 体列表 * @param annotations PMI 标注 * @param opts 导出选项 + * @return 写出成功返回 true;文件无法创建/写入时返回 false */ -void export_step_ap242_file(const std::string& path, +bool export_step_ap242_file(const std::string& path, const std::vector& bodies, const std::vector& annotations = {}, const StepAP242Options& opts = {}); @@ -476,7 +480,8 @@ struct StepAP242ImportResult { * * @param path 输出 PDF 文件路径 * @param body B-Rep 模型 + * @return 写出成功返回 true;文件无法创建/写入时返回 false */ -void export_pdf3d_file(const std::string& path, const brep::BrepModel& body); +bool export_pdf3d_file(const std::string& path, const brep::BrepModel& body); } // namespace vde::io diff --git a/src/foundation/industrial_formats.cpp b/src/foundation/industrial_formats.cpp index 6b8ebadf3..0f701caab 100644 --- a/src/foundation/industrial_formats.cpp +++ b/src/foundation/industrial_formats.cpp @@ -50,10 +50,11 @@ static std::string read_file_bytes(const std::string& path) { return data; } -static void write_file_bytes(const std::string& path, const std::string& data) { +static bool write_file_bytes(const std::string& path, const std::string& data) { std::ofstream f(path, std::ios::binary); - if (!f) throw std::runtime_error("Cannot write file: " + path); + if (!f) return false; f.write(data.data(), static_cast(data.size())); + return f.good(); } static uint32_t read_u32_le(const uint8_t* p) { @@ -919,14 +920,14 @@ BrepModel import_parasolid_xt(const std::string& path) { return parser.parse(); } -void export_parasolid_xt(const BrepModel& body, const std::string& path) { +bool export_parasolid_xt(const BrepModel& body, const std::string& path) { std::string data = parasolid::build_xt_text(body); - write_file_bytes(path, data); + return write_file_bytes(path, data); } -void export_parasolid_xt_binary(const BrepModel& body, const std::string& path) { +bool export_parasolid_xt_binary(const BrepModel& body, const std::string& path) { std::string data = build_xt_binary_data(body); - write_file_bytes(path, data); + return write_file_bytes(path, data); } std::string export_parasolid_xt_binary_str(const BrepModel& body) { @@ -1533,9 +1534,9 @@ BrepModel import_acis_sat(const std::string& path) { return parser.parse(); } -void export_acis_sat(const BrepModel& body, const std::string& path, ACISVersion version) { +bool export_acis_sat(const BrepModel& body, const std::string& path, ACISVersion version) { std::string data = acis::build_sat_text(body, version); - write_file_bytes(path, data); + return write_file_bytes(path, data); } // ── ACIS SAB 二进制导入(公开 API)── @@ -2558,7 +2559,7 @@ public: } // namespace -void export_ifc(const std::vector& bodies, const std::string& path) { +bool export_ifc(const std::vector& bodies, const std::string& path) { IFCWriter w; w.header(); @@ -2577,7 +2578,7 @@ void export_ifc(const std::vector& bodies, const std::string& path) { } w.footer(); - write_file_bytes(path, w.ss.str()); + return write_file_bytes(path, w.ss.str()); } // ═══════════════════════════════════════════════════════════════ @@ -2981,12 +2982,12 @@ std::string export_step_ap242(const std::vector& bodies, return w.ss.str(); } -void export_step_ap242_file(const std::string& path, +bool export_step_ap242_file(const std::string& path, const std::vector& bodies, const std::vector& annotations, const StepAP242Options& opts) { std::string data = export_step_ap242(bodies, annotations, opts); - write_file_bytes(path, data); + return write_file_bytes(path, data); } // ═══════════════════════════════════════════════════════════════ @@ -3546,12 +3547,13 @@ std::vector export_pdf3d(const BrepModel& body) { return build_pdf3d(body); } -void export_pdf3d_file(const std::string& path, const BrepModel& body) { +bool export_pdf3d_file(const std::string& path, const BrepModel& body) { auto data = export_pdf3d(body); std::ofstream f(path, std::ios::binary); - if (!f) throw std::runtime_error("Cannot write PDF file: " + path); + if (!f) return false; f.write(reinterpret_cast(data.data()), static_cast(data.size())); + return f.good(); } } // namespace vde::io