fix: unify IO return types — all write/export/save return bool
export_jt, write_obj, export_step_file, export_iges_file, export_pmi_step_ap242_file: void → bool Return false on file open failure, true on success Also fix duplicate using namespace in advanced_intersection.cpp
This commit is contained in:
@@ -82,6 +82,6 @@ namespace vde::brep {
|
||||
*
|
||||
* @see export_iges 获取字符串输出
|
||||
*/
|
||||
void export_iges_file(const std::string& filepath, const std::vector<BrepModel>& bodies);
|
||||
bool export_iges_file(const std::string& filepath, const std::vector<BrepModel>& bodies);
|
||||
|
||||
} // namespace vde::brep
|
||||
|
||||
@@ -263,7 +263,7 @@ int attach_pmi(BrepModel& body, const PMIAnnotation& annotation,
|
||||
* @param body B-Rep model
|
||||
* @param pmi_model PMI annotations and views
|
||||
*/
|
||||
void export_pmi_step_ap242_file(const std::string& filepath,
|
||||
bool export_pmi_step_ap242_file(const std::string& filepath,
|
||||
const BrepModel& body, const PMIModel& pmi_model);
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,6 +72,6 @@ namespace vde::brep {
|
||||
*
|
||||
* @see export_step 获取字符串输出
|
||||
*/
|
||||
void export_step_file(const std::string& filepath, const std::vector<BrepModel>& bodies);
|
||||
bool export_step_file(const std::string& filepath, const std::vector<BrepModel>& bodies);
|
||||
|
||||
} // namespace vde::brep
|
||||
|
||||
@@ -105,7 +105,7 @@ struct JtSegmentHeader {
|
||||
*
|
||||
* @throws std::runtime_error 写入失败
|
||||
*/
|
||||
void export_jt(const brep::BrepModel& body, const std::string& path);
|
||||
bool export_jt(const brep::BrepModel& body, const std::string& path);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// Parasolid XT
|
||||
|
||||
@@ -105,6 +105,6 @@ ObjMeshData read_obj(const std::string& filepath);
|
||||
* @see read_obj
|
||||
* @ingroup foundation
|
||||
*/
|
||||
void write_obj(const std::string& filepath, const ObjMeshData& data);
|
||||
bool write_obj(const std::string& filepath, const ObjMeshData& data);
|
||||
|
||||
} // namespace vde::foundation
|
||||
|
||||
@@ -643,10 +643,11 @@ std::string export_iges(const std::vector<BrepModel>& bodies) {
|
||||
return writer.write(bodies);
|
||||
}
|
||||
|
||||
void export_iges_file(const std::string& filepath, const std::vector<BrepModel>& bodies) {
|
||||
bool export_iges_file(const std::string& filepath, const std::vector<BrepModel>& bodies) {
|
||||
std::ofstream out(filepath);
|
||||
if (!out) return;
|
||||
if (!out) return false;
|
||||
out << export_iges(bodies);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace vde::brep
|
||||
|
||||
@@ -302,15 +302,15 @@ std::string export_pmi_step_ap242(
|
||||
return base_step;
|
||||
}
|
||||
|
||||
void export_pmi_step_ap242_file(const std::string& filepath,
|
||||
bool export_pmi_step_ap242_file(const std::string& filepath,
|
||||
const BrepModel& body, const PMIModel& pmi_model) {
|
||||
|
||||
std::string step_content = export_pmi_step_ap242(body, pmi_model);
|
||||
std::ofstream out(filepath);
|
||||
if (out.is_open()) {
|
||||
out << step_content;
|
||||
out.close();
|
||||
}
|
||||
if (!out) return false;
|
||||
out << step_content;
|
||||
out.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
int auto_generate_pmi(const BrepModel& body, PMIModel& pmi_model,
|
||||
|
||||
@@ -430,10 +430,11 @@ std::string export_step(const std::vector<BrepModel>& bodies) {
|
||||
return writer.ss.str();
|
||||
}
|
||||
|
||||
void export_step_file(const std::string& filepath, const std::vector<BrepModel>& bodies) {
|
||||
bool export_step_file(const std::string& filepath, const std::vector<BrepModel>& bodies) {
|
||||
std::ofstream out(filepath);
|
||||
if (!out) return;
|
||||
if (!out) return false;
|
||||
out << export_step(bodies);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace vde::brep
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
namespace {
|
||||
|
||||
// ── 内部辅助函数 ──────────────────────────────────────────
|
||||
@@ -84,7 +86,6 @@ SSIResult robust_ssi(
|
||||
const NurbsSurface& surf_b,
|
||||
const SSIOptions& options)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto t_start = high_resolution_clock::now();
|
||||
|
||||
SSIResult result;
|
||||
@@ -424,7 +425,6 @@ SelfIntersectionResult self_intersection_detection(
|
||||
const NurbsSurface& surface,
|
||||
double tolerance)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto t_start = high_resolution_clock::now();
|
||||
|
||||
SelfIntersectionResult result;
|
||||
|
||||
@@ -438,9 +438,12 @@ BrepModel import_jt_binary(const uint8_t* data, size_t size, const JTOptions& op
|
||||
return parser.parse(opts);
|
||||
}
|
||||
|
||||
void export_jt(const BrepModel& body, const std::string& path) {
|
||||
bool export_jt(const BrepModel& body, const std::string& path) {
|
||||
std::string data = jt::build_jt_file(body);
|
||||
write_file_bytes(path, data);
|
||||
std::ofstream f(path, std::ios::binary);
|
||||
if (!f) return false;
|
||||
f.write(data.data(), static_cast<std::streamsize>(data.size()));
|
||||
return true;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -85,9 +85,9 @@ ObjMeshData read_obj(const std::string& filepath) {
|
||||
return data;
|
||||
}
|
||||
|
||||
void write_obj(const std::string& filepath, const ObjMeshData& data) {
|
||||
bool write_obj(const std::string& filepath, const ObjMeshData& data) {
|
||||
std::ofstream file(filepath);
|
||||
if (!file) return;
|
||||
if (!file) return false;
|
||||
|
||||
file.precision(12);
|
||||
|
||||
@@ -140,6 +140,7 @@ void write_obj(const std::string& filepath, const ObjMeshData& data) {
|
||||
}
|
||||
file << "\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace vde::foundation
|
||||
|
||||
Reference in New Issue
Block a user